ip4_canforward(): don't route multicast packets

Added LWIP_HOOK_IP4_CANFORWARD to still implement multicast routing.
See bug #52914

Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de>
This commit is contained in:
Simon Goldschmidt 2018-06-12 06:45:30 +02:00
parent 1fd145fbc9
commit 6ea2483546
2 changed files with 30 additions and 3 deletions

View File

@ -237,13 +237,19 @@ ip4_canforward(struct pbuf *p)
{
u32_t addr = lwip_htonl(ip4_addr_get_u32(ip4_current_dest_addr()));
#ifdef LWIP_HOOK_IP4_CANFORWARD
int ret = LWIP_HOOK_IP4_CANFORWARD(p, addr);
if (ret >= 0) {
return ret;
}
#endif /* LWIP_HOOK_IP4_CANFORWARD */
if (p->flags & PBUF_FLAG_LLBCAST) {
/* don't route link-layer broadcasts */
return 0;
}
if ((p->flags & PBUF_FLAG_LLMCAST) && !IP_MULTICAST(addr)) {
/* don't route link-layer multicasts unless the destination address is an IP
multicast address */
if ((p->flags & PBUF_FLAG_LLMCAST) || IP_MULTICAST(addr)) {
/* don't route link-layer multicasts (use LWIP_HOOK_IP4_CANFORWARD instead) */
return 0;
}
if (IP_EXPERIMENTAL(addr)) {

View File

@ -2886,6 +2886,27 @@
#define LWIP_HOOK_IP4_ROUTE_SRC(src, dest)
#endif
/**
* LWIP_HOOK_IP4_CANFORWARD(src, dest):
* Check if an IPv4 can be forwarded - called from:
* ip4_input() -> ip4_forward() -> ip4_canforward() (IPv4)
* - source address is available via ip4_current_src_addr()
* - calling an output function in this context (e.g. multicast router) is allowed
* Signature:\code{.c}
* int my_hook(struct pbuf *p, u32_t dest_addr_hostorder);
* \endcode
* Arguments:
* - p: packet to forward
* - dest: destination IPv4 address
* Returns values:
* - 1: forward
* - 0: don't forward
* - -1: no decision. In that case, ip4_canforward() continues as normal.
*/
#ifdef __DOXYGEN__
#define LWIP_HOOK_IP4_CANFORWARD(src, dest)
#endif
/**
* LWIP_HOOK_ETHARP_GET_GW(netif, dest):
* Called from etharp_output() (IPv4)