From 80b62df0a97e4641ac7db53e1a6ea2e7f916dc2d Mon Sep 17 00:00:00 2001 From: sg Date: Thu, 12 Feb 2015 22:04:10 +0100 Subject: [PATCH] fixed bug #36403 "ip4_input() and ip6_input() always pass inp to higher layers": now the accepting netif is passed up, but the input netif is available through ip_current_input_netif() if required. --- CHANGELOG | 4 ++++ src/core/ipv4/ip4.c | 4 +++- src/core/ipv6/ip6.c | 2 ++ src/include/lwip/ip.h | 11 +++++++++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 70632877..492691d9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -167,6 +167,10 @@ HISTORY ++ Bugfixes: + * ip.h, ip4.c, ip6.c: fixed bug #36403 "ip4_input() and ip6_input() always pass + inp to higher layers": now the accepting netif is passed up, but the input + netif is available through ip_current_input_netif() if required. + 2015-02-11: patch by hichard * tcpip.c: fixed bug #43094 "The function tcpip_input() forget to handle IPv6" diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index 5a6b1185..a2551d65 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -553,7 +553,8 @@ ip_input(struct pbuf *p, struct netif *inp) ip_debug_print(p); LWIP_DEBUGF(IP_DEBUG, ("ip_input: p->len %"U16_F" p->tot_len %"U16_F"\n", p->len, p->tot_len)); - ip_data.current_netif = inp; + ip_data.current_netif = netif; + ip_data.current_input_netif = inp; ip_data.current_ip4_header = iphdr; ip_data.current_ip_header_tot_len = IPH_HL(iphdr) * 4; @@ -613,6 +614,7 @@ ip_input(struct pbuf *p, struct netif *inp) /* @todo: this is not really necessary... */ ip_data.current_netif = NULL; + ip_data.current_input_netif = NULL; ip_data.current_ip4_header = NULL; ip_data.current_ip_header_tot_len = 0; ip_addr_set_any(ip_current_src_addr()); diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index 854d746a..85a61804 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -397,6 +397,7 @@ ip6_input(struct pbuf *p, struct netif *inp) /* In netif, used in case we need to send ICMPv6 packets back. */ ip_data.current_netif = inp; + ip_data.current_input_netif = inp; /* match packet against an interface, i.e. is this packet for us? */ if (ip6_addr_ismulticast(ip6_current_dest_addr())) { @@ -708,6 +709,7 @@ options_done: ip6_input_cleanup: ip_data.current_netif = NULL; + ip_data.current_input_netif = NULL; ip_data.current_ip6_header = NULL; ip_data.current_ip_header_tot_len = 0; ip6_addr_set_any(&ip_data.current_iphdr_src.ip6); diff --git a/src/include/lwip/ip.h b/src/include/lwip/ip.h index 522e98da..350d51ba 100644 --- a/src/include/lwip/ip.h +++ b/src/include/lwip/ip.h @@ -116,8 +116,10 @@ struct ip_pcb { /* Global variables of this module, kept in a struct for efficient access using base+index. */ struct ip_globals { - /** The interface that provided the packet for the current callback invocation. */ + /** The interface that accepted the packet for the current callback invocation. */ struct netif *current_netif; + /** The interface that received the packet for the current callback invocation. */ + struct netif *current_input_netif; /** Header of the input packet currently being processed. */ const struct ip_hdr *current_ip4_header; #if LWIP_IPV6 @@ -134,10 +136,15 @@ struct ip_globals extern struct ip_globals ip_data; -/** Get the interface that received the current packet. +/** Get the interface that accepted the current packet. + * This may or may not be the receiving netif, depending on your netif/network setup. * This function must only be called from a receive callback (udp_recv, * raw_recv, tcp_accept). It will return NULL otherwise. */ #define ip_current_netif() (ip_data.current_netif) +/** Get the interface that received the current packet. + * This function must only be called from a receive callback (udp_recv, + * raw_recv, tcp_accept). It will return NULL otherwise. */ +#define ip_current_input_netif() (ip_data.current_input_netif) /** Get the IP header of the current packet. * This function must only be called from a receive callback (udp_recv, * raw_recv, tcp_accept). It will return NULL otherwise. */