From 1e65eb4936ad50ff70eabf5e05dfe936fcb1467f Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Fri, 17 Jan 2014 21:55:46 +0100 Subject: [PATCH] Added IPv6 loopback address to loopback-netif, fixed last commit --- CHANGELOG | 3 +++ src/core/ipv4/ip4.c | 4 ++-- src/core/ipv6/ip6.c | 8 ++++---- src/core/netif.c | 36 +++++++++++++++++++++++++++++++----- src/include/lwip/netif.h | 2 +- 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8b9e502c..1b54f4ab 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -80,6 +80,9 @@ HISTORY ++ Bugfixes: + 2014-01-17: Grant Erickson, Jay Logue, Simon Goldschmidt + * ipv6.c, netif.c: patch #7913 Enable Support for IPv6 Loopback + 2014-01-16: Stathis Voukelatos * netif.c: patch #7902 Fixed netif_poll() operation when LWIP_LOOPBACK_MAX_PBUFS > 0 diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index 4b38999c..04a36111 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -772,11 +772,11 @@ err_t ip_output_if_opt(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, if (ip_addr_cmp(dest, &netif->ip_addr)) { /* Packet to self, enqueue it for loopback */ LWIP_DEBUGF(IP_DEBUG, ("netif_loop_output()")); - return netif_loop_output(netif, p, dest); + return netif_loop_output(netif, p); } #if LWIP_IGMP if ((p->flags & PBUF_FLAG_MCASTLOOP) != 0) { - netif_loop_output(netif, p, dest); + netif_loop_output(netif, p); } #endif /* LWIP_IGMP */ #endif /* ENABLE_LOOPBACK */ diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index d188f6c5..5ab51848 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -803,13 +803,13 @@ ip6_output_if(struct pbuf *p, ip6_addr_t *src, ip6_addr_t *dest, #if ENABLE_LOOPBACK { - int i; + int i; for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && ip6_addr_cmp(dest, netif_ip6_addr(netif, i))) { - /* Packet to self, enqueue it for loopback */ - LWIP_DEBUGF(IP6_DEBUG, ("netif_loop_output()\n")); - return netif_loop_output(netif, p, dest); + /* Packet to self, enqueue it for loopback */ + LWIP_DEBUGF(IP6_DEBUG, ("netif_loop_output()\n")); + return netif_loop_output(netif, p); } } } diff --git a/src/core/netif.c b/src/core/netif.c index e8b0ee98..919d36f0 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -95,6 +95,10 @@ static err_t netif_null_output_ip6(struct netif *netif, struct pbuf *p, ip6_addr #endif #if LWIP_HAVE_LOOPIF +static err_t netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, ip_addr_t* addr); +static err_t netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, ip6_addr_t* addr); + + static struct netif loop_netif; /** @@ -114,7 +118,8 @@ netif_loopif_init(struct netif *netif) netif->name[0] = 'l'; netif->name[1] = 'o'; - netif->output = netif_loop_output; + netif->output = netif_loop_output_ipv4; + netif->output_ip6 = netif_loop_output_ipv6; return ERR_OK; } #endif /* LWIP_HAVE_LOOPIF */ @@ -133,6 +138,15 @@ netif_init(void) #else /* NO_SYS */ netif_add(&loop_netif, &loop_ipaddr, &loop_netmask, &loop_gw, NULL, netif_loopif_init, tcpip_input); #endif /* NO_SYS */ + +#if LWIP_IPV6 + loop_netif.ip6_addr[0].addr[0] = 0; + loop_netif.ip6_addr[0].addr[1] = 0; + loop_netif.ip6_addr[0].addr[2] = 0; + loop_netif.ip6_addr[0].addr[3] = PP_HTONL(0x00000001UL); + loop_netif.ip6_addr_state[0] = IP6_ADDR_VALID; +#endif /* LWIP_IPV6 */ + netif_set_up(&loop_netif); #endif /* LWIP_HAVE_LOOPIF */ @@ -661,13 +675,11 @@ void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_ * * @param netif the lwip network interface structure * @param p the (IP) packet to 'send' - * @param ipaddr the ip address to send the packet to (not used) * @return ERR_OK if the packet has been sent * ERR_MEM if the pbuf used to copy the packet couldn't be allocated */ err_t -netif_loop_output(struct netif *netif, struct pbuf *p, - ip_addr_t *ipaddr) +netif_loop_output(struct netif *netif, struct pbuf *p) { struct pbuf *r; err_t err; @@ -685,7 +697,6 @@ netif_loop_output(struct netif *netif, struct pbuf *p, #endif /* LWIP_HAVE_LOOPIF */ #endif /* LWIP_SNMP */ SYS_ARCH_DECL_PROTECT(lev); - LWIP_UNUSED_ARG(ipaddr); /* Allocate a new pbuf */ r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM); @@ -747,6 +758,21 @@ netif_loop_output(struct netif *netif, struct pbuf *p, return ERR_OK; } +static err_t +netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, ip_addr_t* addr) +{ + LWIP_UNUSED_ARG(addr); + return netif_loop_output(netif, p); +} + +static err_t +netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, ip6_addr_t* addr) +{ + LWIP_UNUSED_ARG(addr); + return netif_loop_output(netif, p); +} + + /** * Call netif_poll() in the main loop of your application. This is to prevent * reentering non-reentrant functions like tcp_input(). Packets passed to diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index 322d2d0e..b2c8d87a 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -359,7 +359,7 @@ void netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_ #endif /* LWIP_IGMP */ #if ENABLE_LOOPBACK -err_t netif_loop_output(struct netif *netif, struct pbuf *p, ip_addr_t *dest_ip); +err_t netif_loop_output(struct netif *netif, struct pbuf *p); void netif_poll(struct netif *netif); #if !LWIP_NETIF_LOOPBACK_MULTITHREADING void netif_poll_all(void);