From d3ee77e7b11bafcb8f6c88c5a6d3f353b6820cb7 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Wed, 14 Dec 2011 21:48:06 +0100 Subject: [PATCH] Merged from trunk: use a define to set/reset netif->addr_hint to prevent too many #ifdef's in the code --- src/core/ipv4/ip.c | 4 ++-- src/core/ipv6/ip6.c | 4 ++-- src/core/netif.c | 4 +--- src/core/raw.c | 8 ++------ src/core/udp.c | 16 ++++------------ src/include/lwip/netif.h | 6 ++++++ 6 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/core/ipv4/ip.c b/src/core/ipv4/ip.c index 3b07b45b..8e1a8370 100644 --- a/src/core/ipv4/ip.c +++ b/src/core/ipv4/ip.c @@ -859,9 +859,9 @@ ip_output_hinted(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, return ERR_RTE; } - netif->addr_hint = addr_hint; + NETIF_SET_HWADDRHINT(netif, addr_hint); err = ip_output_if(p, src, dest, ttl, tos, proto, netif); - netif->addr_hint = NULL; + NETIF_SET_HWADDRHINT(netif, NULL); return err; } diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index b945fc5d..ad59b725 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -341,9 +341,9 @@ ip_output_hinted(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, return ERR_RTE; } - netif->addr_hint = addr_hint; + LWIP_NETIF_HWADDRHINT(netif, addr_hint); err = ip_output_if(p, src, dest, ttl, tos, proto, netif); - netif->addr_hint = NULL; + LWIP_NETIF_HWADDRHINT(netif, NULL); return err; } diff --git a/src/core/netif.c b/src/core/netif.c index 07908cc5..4a02e77f 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -173,9 +173,7 @@ netif_add(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, netif->state = state; netif->num = netif_num++; netif->input = input; -#if LWIP_NETIF_HWADDRHINT - netif->addr_hint = NULL; -#endif /* LWIP_NETIF_HWADDRHINT*/ + NETIF_SET_HWADDRHINT(netif, NULL); #if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS netif->loop_cnt_current = 0; #endif /* ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS */ diff --git a/src/core/raw.c b/src/core/raw.c index 9fcb1003..a245cc55 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -263,13 +263,9 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, ip_addr_t *ipaddr) src_ip = &(pcb->local_ip); } -#if LWIP_NETIF_HWADDRHINT - netif->addr_hint = &(pcb->addr_hint); -#endif /* LWIP_NETIF_HWADDRHINT*/ + NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint); err = ip_output_if (q, src_ip, ipaddr, pcb->ttl, pcb->tos, pcb->protocol, netif); -#if LWIP_NETIF_HWADDRHINT - netif->addr_hint = NULL; -#endif /* LWIP_NETIF_HWADDRHINT*/ + NETIF_SET_HWADDRHINT(netif, NULL); /* did we chain a header earlier? */ if (q != p) { diff --git a/src/core/udp.c b/src/core/udp.c index f45dcae0..96d67e00 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -689,13 +689,9 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip, #endif /* CHECKSUM_GEN_UDP */ /* output to IP */ LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDPLITE,)\n")); -#if LWIP_NETIF_HWADDRHINT - netif->addr_hint = &(pcb->addr_hint); -#endif /* LWIP_NETIF_HWADDRHINT*/ + NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint); err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDPLITE, netif); -#if LWIP_NETIF_HWADDRHINT - netif->addr_hint = NULL; -#endif /* LWIP_NETIF_HWADDRHINT*/ + NETIF_SET_HWADDRHINT(netif, NULL); } else #endif /* LWIP_UDPLITE */ { /* UDP */ @@ -728,13 +724,9 @@ udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip, LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum)); LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,IP_PROTO_UDP,)\n")); /* output to IP */ -#if LWIP_NETIF_HWADDRHINT - netif->addr_hint = &(pcb->addr_hint); -#endif /* LWIP_NETIF_HWADDRHINT*/ + NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint); err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDP, netif); -#if LWIP_NETIF_HWADDRHINT - netif->addr_hint = NULL; -#endif /* LWIP_NETIF_HWADDRHINT*/ + NETIF_SET_HWADDRHINT(netif, NULL); } /* TODO: must this be increased even if error occured? */ snmp_inc_udpoutdatagrams(); diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index fbd72849..f7e49374 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -315,6 +315,12 @@ void netif_poll_all(void); #endif /* !LWIP_NETIF_LOOPBACK_MULTITHREADING */ #endif /* ENABLE_LOOPBACK */ +#if LWIP_NETIF_HWADDRHINT +#define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint)) +#else /* LWIP_NETIF_HWADDRHINT */ +#define NETIF_SET_HWADDRHINT(netif, hint) +#endif /* LWIP_NETIF_HWADDRHINT */ + #ifdef __cplusplus } #endif