diff --git a/CHANGELOG b/CHANGELOG index 3eadb446..ce0f6960 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,10 @@ HISTORY ++ New features: + 2009-05-05 Simon Goldschmidt, Jakob Stoklund Olesen + * ip.h, ip.c: Added ip_current_netif() & ip_current_header() to receive + extended info about the currently received packet. + 2009-04-27 Simon Goldschmidt * sys.h: Made SYS_LIGHTWEIGHT_PROT and sys_now() work with NO_SYS=1 diff --git a/src/core/ipv4/ip.c b/src/core/ipv4/ip.c index 93258f29..6ca24f5a 100644 --- a/src/core/ipv4/ip.c +++ b/src/core/ipv4/ip.c @@ -56,6 +56,45 @@ #include "lwip/stats.h" #include "arch/perf.h" +/** + * The interface that provided the packet for the current callback + * invocation. + */ +static struct netif *current_netif; + +/** + * Header of the input packet currently being processed. + */ +static const struct ip_hdr *current_header; + +/** + * 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. + * + * @param pcb Pointer to the pcb receiving a packet. + */ +struct netif * +ip_current_netif() +{ + return current_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. + * + * @param pcb Pointer to the pcb receiving a packet. + */ +const struct ip_hdr * +ip_current_header() +{ + return current_header; +} + /** * Finds the appropriate network interface for a given IP address. It * searches the list of network interfaces linearly. A match is found @@ -388,6 +427,9 @@ 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)); + current_netif = inp; + current_header = iphdr; + #if LWIP_RAW /* raw input did not eat the packet? */ if (raw_input(p, inp) == 0) @@ -440,6 +482,9 @@ ip_input(struct pbuf *p, struct netif *inp) } } + current_netif = NULL; + current_header = NULL; + return ERR_OK; } diff --git a/src/include/ipv4/lwip/ip.h b/src/include/ipv4/lwip/ip.h index f342af95..88364cf5 100644 --- a/src/include/ipv4/lwip/ip.h +++ b/src/include/ipv4/lwip/ip.h @@ -55,6 +55,8 @@ err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, err_t ip_output_hinted(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint); #endif /* LWIP_NETIF_HWADDRHINT */ +struct netif *ip_current_netif(); +const struct ip_hdr *ip_current_header(); #define IP_HLEN 20 diff --git a/src/include/ipv6/lwip/ip.h b/src/include/ipv6/lwip/ip.h index f6e59cc6..a01cfc65 100644 --- a/src/include/ipv6/lwip/ip.h +++ b/src/include/ipv6/lwip/ip.h @@ -114,6 +114,9 @@ err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t ttl, u8_t proto, struct netif *netif); +#define ip_current_netif() NULL +#define ip_current_header() NULL + #if IP_DEBUG void ip_debug_print(struct pbuf *p); #endif /* IP_DEBUG */