diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index 9a791f2c..5614561a 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -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)) { diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 7e4d36c6..f5409d98 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -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)