diff --git a/src/core/ipv4/etharp.c b/src/core/ipv4/etharp.c index d76b7f2b..b195e262 100644 --- a/src/core/ipv4/etharp.c +++ b/src/core/ipv4/etharp.c @@ -118,10 +118,10 @@ static u8_t etharp_cached_entry; #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */ #if LWIP_NETIF_HWADDRHINT -#define ETHARP_SET_HINT(netif, hint) if (((netif) != NULL) && ((netif)->addr_hint != NULL)) \ - *((netif)->addr_hint) = (hint); +#define ETHARP_SET_ADDRHINT(netif, addrhint) do { if (((netif) != NULL) && ((netif)->hints != NULL)) { \ + (netif)->hints->addr_hint = (addrhint); }} while(0) #else /* LWIP_NETIF_HWADDRHINT */ -#define ETHARP_SET_HINT(netif, hint) (etharp_cached_entry = (hint)) +#define ETHARP_SET_ADDRHINT(netif, addrhint) (etharp_cached_entry = (addrhint)) #endif /* LWIP_NETIF_HWADDRHINT */ @@ -850,9 +850,9 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr) } } #if LWIP_NETIF_HWADDRHINT - if (netif->addr_hint != NULL) { + if (netif->hints != NULL) { /* per-pcb cached entry was given */ - u8_t etharp_cached_entry = *(netif->addr_hint); + u8_t etharp_cached_entry = netif->hints->addr_hint; if (etharp_cached_entry < ARP_TABLE_SIZE) { #endif /* LWIP_NETIF_HWADDRHINT */ if ((arp_table[etharp_cached_entry].state >= ETHARP_STATE_STABLE) && @@ -878,7 +878,7 @@ etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr) #endif (ip4_addr_cmp(dst_addr, &arp_table[i].ipaddr))) { /* found an existing, stable entry */ - ETHARP_SET_HINT(netif, i); + ETHARP_SET_ADDRHINT(netif, i); return etharp_output_to_arp_index(netif, q, i); } } @@ -988,7 +988,7 @@ etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q) /* stable entry? */ if (arp_table[i].state >= ETHARP_STATE_STABLE) { /* we have a valid IP->Ethernet address mapping */ - ETHARP_SET_HINT(netif, i); + ETHARP_SET_ADDRHINT(netif, i); /* send the packet */ result = ethernet_output(netif, q, srcaddr, &(arp_table[i].ethaddr), ETHTYPE_IP); /* pending entry? (either just created or already pending */ diff --git a/src/core/ipv4/ip4.c b/src/core/ipv4/ip4.c index 23354525..cc592caa 100644 --- a/src/core/ipv4/ip4.c +++ b/src/core/ipv4/ip4.c @@ -1006,7 +1006,7 @@ ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, return ip4_output_if(p, src, dest, ttl, tos, proto, netif); } -#if LWIP_NETIF_HWADDRHINT +#if LWIP_NETIF_USE_HINTS /** Like ip_output, but takes and addr_hint pointer that is passed on to netif->addr_hint * before calling ip_output_if. * @@ -1019,7 +1019,7 @@ ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, * @param ttl the TTL value to be set in the IP header * @param tos the TOS value to be set in the IP header * @param proto the PROTOCOL to be set in the IP header - * @param addr_hint address hint pointer set to netif->addr_hint before + * @param netif_hint netif output hint pointer set to netif->hint before * calling ip_output_if() * * @return ERR_RTE if no route is found @@ -1027,7 +1027,7 @@ ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, */ err_t ip4_output_hinted(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, - u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint) + u8_t ttl, u8_t tos, u8_t proto, struct netif_hint *netif_hint) { struct netif *netif; err_t err; @@ -1041,13 +1041,13 @@ ip4_output_hinted(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, return ERR_RTE; } - NETIF_SET_HWADDRHINT(netif, addr_hint); + NETIF_SET_HINTS(netif, netif_hint); err = ip4_output_if(p, src, dest, ttl, tos, proto, netif); - NETIF_SET_HWADDRHINT(netif, NULL); + NETIF_RESET_HINTS(netif); return err; } -#endif /* LWIP_NETIF_HWADDRHINT*/ +#endif /* LWIP_NETIF_USE_HINTS*/ #if IP_DEBUG /* Print an IP header by using LWIP_DEBUGF diff --git a/src/core/ipv6/ip6.c b/src/core/ipv6/ip6.c index 39e282ef..f54dcb2f 100644 --- a/src/core/ipv6/ip6.c +++ b/src/core/ipv6/ip6.c @@ -1114,7 +1114,7 @@ ip6_output(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, } -#if LWIP_NETIF_HWADDRHINT +#if LWIP_NETIF_USE_HINTS /** Like ip6_output, but takes and addr_hint pointer that is passed on to netif->addr_hint * before calling ip6_output_if. * @@ -1128,7 +1128,7 @@ ip6_output(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, * @param hl the Hop Limit value to be set in the IPv6 header * @param tc the Traffic Class value to be set in the IPv6 header * @param nexth the Next Header to be set in the IPv6 header - * @param addr_hint address hint pointer set to netif->addr_hint before + * @param netif_hint netif output hint pointer set to netif->hint before * calling ip_output_if() * * @return ERR_RTE if no route is found @@ -1136,7 +1136,7 @@ ip6_output(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, */ err_t ip6_output_hinted(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, - u8_t hl, u8_t tc, u8_t nexth, u8_t *addr_hint) + u8_t hl, u8_t tc, u8_t nexth, struct netif_hint *netif_hint) { struct netif *netif; struct ip6_hdr *ip6hdr; @@ -1169,13 +1169,13 @@ ip6_output_hinted(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, return ERR_RTE; } - NETIF_SET_HWADDRHINT(netif, addr_hint); + NETIF_SET_HINTS(netif, netif_hint); err = ip6_output_if(p, src, dest, hl, tc, nexth, netif); - NETIF_SET_HWADDRHINT(netif, NULL); + NETIF_RESET_HINTS(netif); return err; } -#endif /* LWIP_NETIF_HWADDRHINT*/ +#endif /* LWIP_NETIF_USE_HINTS*/ #if LWIP_IPV6_MLD /** diff --git a/src/core/ipv6/nd6.c b/src/core/ipv6/nd6.c index 0122d99c..31a1f694 100644 --- a/src/core/ipv6/nd6.c +++ b/src/core/ipv6/nd6.c @@ -1907,9 +1907,9 @@ nd6_get_next_hop_entry(const ip6_addr_t *ip6addr, struct netif *netif) IP6_ADDR_ZONECHECK_NETIF(ip6addr, netif); #if LWIP_NETIF_HWADDRHINT - if (netif->addr_hint != NULL) { + if (netif->hints != NULL) { /* per-pcb cached entry was given */ - u8_t addr_hint = *(netif->addr_hint); + u8_t addr_hint = netif->hints->addr_hint; if (addr_hint < LWIP_ND6_NUM_DESTINATIONS) { nd6_cached_destination_index = addr_hint; } @@ -1968,9 +1968,9 @@ nd6_get_next_hop_entry(const ip6_addr_t *ip6addr, struct netif *netif) } #if LWIP_NETIF_HWADDRHINT - if (netif->addr_hint != NULL) { + if (netif->hints != NULL) { /* per-pcb cached entry was given */ - *(netif->addr_hint) = nd6_cached_destination_index; + netif->hints->addr_hint = nd6_cached_destination_index; } #endif /* LWIP_NETIF_HWADDRHINT */ diff --git a/src/core/netif.c b/src/core/netif.c index daaaebde..7b16e723 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -332,7 +332,7 @@ netif_add(struct netif *netif, netif->num = netif_num; netif->input = input; - NETIF_SET_HWADDRHINT(netif, NULL); + NETIF_RESET_HINTS(netif); #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 78e78c77..9f911140 100644 --- a/src/core/raw.c +++ b/src/core/raw.c @@ -412,9 +412,9 @@ raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, return ERR_VAL; } /* @todo multicast loop support, if at all desired for this scenario.. */ - NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint); + NETIF_SET_HINTS(netif, &pcb->netif_hints); err = ip_output_if_hdrincl(p, src_ip, dst_ip, netif); - NETIF_SET_HWADDRHINT(netif, NULL); + NETIF_RESET_HINTS(netif); return err; } @@ -485,9 +485,9 @@ raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, ttl = pcb->ttl; #endif /* LWIP_MULTICAST_TX_OPTIONS */ - NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint); + NETIF_SET_HINTS(netif, &pcb->netif_hints); err = ip_output_if(q, src_ip, dst_ip, ttl, pcb->tos, pcb->protocol, netif); - NETIF_SET_HWADDRHINT(netif, NULL); + NETIF_RESET_HINTS(netif); /* did we chain a header earlier? */ if (q != p) { diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c index 8791ead7..138a7be0 100644 --- a/src/core/tcp_out.c +++ b/src/core/tcp_out.c @@ -969,10 +969,10 @@ tcp_send_empty_ack(struct tcp_pcb *pcb) &pcb->local_ip, &pcb->remote_ip); } #endif - NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint)); + NETIF_SET_HINTS(netif, &(pcb->netif_hints)); err = ip_output_if(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, pcb->tos, IP_PROTO_TCP, netif); - NETIF_SET_HWADDRHINT(netif, NULL); + NETIF_RESET_HINTS(netif); } pbuf_free(p); @@ -1319,10 +1319,10 @@ tcp_output_segment(struct tcp_seg *seg, struct tcp_pcb *pcb, struct netif *netif #endif /* CHECKSUM_GEN_TCP */ TCP_STATS_INC(tcp.xmit); - NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint)); + NETIF_SET_HINTS(netif, &(pcb->netif_hints)); err = ip_output_if(seg->p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, pcb->tos, IP_PROTO_TCP, netif); - NETIF_SET_HWADDRHINT(netif, NULL); + NETIF_RESET_HINTS(netif); return err; } @@ -1573,9 +1573,9 @@ tcp_keepalive(struct tcp_pcb *pcb) TCP_STATS_INC(tcp.xmit); /* Send output to IP */ - NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint)); + NETIF_SET_HINTS(netif, &(pcb->netif_hints)); err = ip_output_if(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP, netif); - NETIF_SET_HWADDRHINT(netif, NULL); + NETIF_RESET_HINTS(netif); } pbuf_free(p); @@ -1666,10 +1666,10 @@ tcp_zero_window_probe(struct tcp_pcb *pcb) TCP_STATS_INC(tcp.xmit); /* Send output to IP */ - NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint)); + NETIF_SET_HINTS(netif, &(pcb->netif_hints)); err = ip_output_if(p, &pcb->local_ip, &pcb->remote_ip, pcb->ttl, 0, IP_PROTO_TCP, netif); - NETIF_SET_HWADDRHINT(netif, NULL); + NETIF_RESET_HINTS(netif); } pbuf_free(p); diff --git a/src/core/udp.c b/src/core/udp.c index 68c1d785..e402ff35 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -859,9 +859,9 @@ udp_sendto_if_src_chksum(struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *d LWIP_DEBUGF(UDP_DEBUG, ("udp_send: UDP checksum 0x%04"X16_F"\n", udphdr->chksum)); LWIP_DEBUGF(UDP_DEBUG, ("udp_send: ip_output_if (,,,,0x%02"X16_F",)\n", (u16_t)ip_proto)); /* output to IP */ - NETIF_SET_HWADDRHINT(netif, &(pcb->addr_hint)); + NETIF_SET_HINTS(netif, &(pcb->netif_hints)); err = ip_output_if_src(q, src_ip, dst_ip, ttl, pcb->tos, ip_proto, netif); - NETIF_SET_HWADDRHINT(netif, NULL); + NETIF_RESET_HINTS(netif); /* @todo: must this be increased even if error occurred? */ MIB2_STATS_INC(mib2.udpoutdatagrams); diff --git a/src/include/lwip/ip.h b/src/include/lwip/ip.h index 6dd29a63..08cfb1bc 100644 --- a/src/include/lwip/ip.h +++ b/src/include/lwip/ip.h @@ -63,11 +63,11 @@ extern "C" { #define LWIP_IP_CHECK_PBUF_REF_COUNT_FOR_TX(p) LWIP_ASSERT("p->ref == 1", (p)->ref == 1) #endif -#if LWIP_NETIF_HWADDRHINT -#define IP_PCB_ADDRHINT ;u8_t addr_hint -#else -#define IP_PCB_ADDRHINT -#endif /* LWIP_NETIF_HWADDRHINT */ +#if LWIP_NETIF_USE_HINTS +#define IP_PCB_NETIFHINT ;struct netif_hint netif_hints +#else /* LWIP_NETIF_USE_HINTS */ +#define IP_PCB_NETIFHINT +#endif /* LWIP_NETIF_USE_HINTS */ /** This is the common part of all PCB types. It needs to be at the beginning of a PCB type definition. It is located here so that @@ -84,7 +84,7 @@ extern "C" { /* Time To Live */ \ u8_t ttl \ /* link layer address resolution hint */ \ - IP_PCB_ADDRHINT + IP_PCB_NETIFHINT struct ip_pcb { /* Common members of all PCB types */ @@ -248,11 +248,11 @@ extern struct ip_globals ip_data; (IP_IS_V6(dest) ? \ ip6_output_if(p, ip_2_ip6(src), LWIP_IP_HDRINCL, 0, 0, 0, netif) : \ ip4_output_if(p, ip_2_ip4(src), LWIP_IP_HDRINCL, 0, 0, 0, netif)) -/** Output IP packet with addr_hint */ -#define ip_output_hinted(p, src, dest, ttl, tos, proto, addr_hint) \ +/** Output IP packet with netif_hint */ +#define ip_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) \ (IP_IS_V6(dest) ? \ - ip6_output_hinted(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, addr_hint) : \ - ip4_output_hinted(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, addr_hint)) + ip6_output_hinted(p, ip_2_ip6(src), ip_2_ip6(dest), ttl, tos, proto, netif_hint) : \ + ip4_output_hinted(p, ip_2_ip4(src), ip_2_ip4(dest), ttl, tos, proto, v)) /** * @ingroup ip * Get netif for address combination. See \ref ip6_route and \ref ip4_route @@ -280,8 +280,8 @@ err_t ip_input(struct pbuf *p, struct netif *inp); ip4_output_if(p, src, dest, ttl, tos, proto, netif) #define ip_output_if_src(p, src, dest, ttl, tos, proto, netif) \ ip4_output_if_src(p, src, dest, ttl, tos, proto, netif) -#define ip_output_hinted(p, src, dest, ttl, tos, proto, addr_hint) \ - ip4_output_hinted(p, src, dest, ttl, tos, proto, addr_hint) +#define ip_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) \ + ip4_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) #define ip_output_if_hdrincl(p, src, dest, netif) \ ip4_output_if(p, src, LWIP_IP_HDRINCL, 0, 0, 0, netif) #define ip_route(src, dest) \ @@ -300,8 +300,8 @@ err_t ip_input(struct pbuf *p, struct netif *inp); ip6_output_if(p, src, dest, ttl, tos, proto, netif) #define ip_output_if_src(p, src, dest, ttl, tos, proto, netif) \ ip6_output_if_src(p, src, dest, ttl, tos, proto, netif) -#define ip_output_hinted(p, src, dest, ttl, tos, proto, addr_hint) \ - ip6_output_hinted(p, src, dest, ttl, tos, proto, addr_hint) +#define ip_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) \ + ip6_output_hinted(p, src, dest, ttl, tos, proto, netif_hint) #define ip_output_if_hdrincl(p, src, dest, netif) \ ip6_output_if(p, src, LWIP_IP_HDRINCL, 0, 0, 0, netif) #define ip_route(src, dest) \ diff --git a/src/include/lwip/ip4.h b/src/include/lwip/ip4.h index 48246ecc..b3a0f6c0 100644 --- a/src/include/lwip/ip4.h +++ b/src/include/lwip/ip4.h @@ -75,10 +75,10 @@ err_t ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *des u8_t ttl, u8_t tos, u8_t proto, struct netif *netif); err_t ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, u8_t ttl, u8_t tos, u8_t proto, struct netif *netif); -#if LWIP_NETIF_HWADDRHINT +#if LWIP_NETIF_USE_HINTS err_t ip4_output_hinted(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, - u8_t ttl, u8_t tos, u8_t proto, u8_t *addr_hint); -#endif /* LWIP_NETIF_HWADDRHINT */ + u8_t ttl, u8_t tos, u8_t proto, struct netif_hint *netif_hint); +#endif /* LWIP_NETIF_USE_HINTS */ #if IP_OPTIONS_SEND err_t ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest, u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options, diff --git a/src/include/lwip/ip6.h b/src/include/lwip/ip6.h index 099b94fb..f894e063 100644 --- a/src/include/lwip/ip6.h +++ b/src/include/lwip/ip6.h @@ -66,10 +66,10 @@ err_t ip6_output_if(struct pbuf *p, const ip6_addr_t *src, const ip6_add u8_t hl, u8_t tc, u8_t nexth, struct netif *netif); err_t ip6_output_if_src(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, u8_t hl, u8_t tc, u8_t nexth, struct netif *netif); -#if LWIP_NETIF_HWADDRHINT +#if LWIP_NETIF_USE_HINTS err_t ip6_output_hinted(struct pbuf *p, const ip6_addr_t *src, const ip6_addr_t *dest, - u8_t hl, u8_t tc, u8_t nexth, u8_t *addr_hint); -#endif /* LWIP_NETIF_HWADDRHINT */ + u8_t hl, u8_t tc, u8_t nexth, struct netif_hint *netif_hint); +#endif /* LWIP_NETIF_USE_HINTS */ #if LWIP_IPV6_MLD err_t ip6_options_add_hbh_ra(struct pbuf * p, u8_t nexth, u8_t value); #endif /* LWIP_IPV6_MLD */ diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index c872d62f..ccdc53f4 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -225,6 +225,15 @@ u8_t netif_alloc_client_data_id(void); #define netif_get_client_data(netif, id) (netif)->client_data[(id)] #endif +#if LWIP_NETIF_HWADDRHINT +#define LWIP_NETIF_USE_HINTS 1 +struct netif_hint { + u8_t addr_hint; +}; +#else /* LWIP_NETIF_HWADDRHINT */ +#define LWIP_NETIF_USE_HINTS 0 +#endif /* LWIP_NETIF_HWADDRHINT */ + /** Generic data structure used for all lwIP network interfaces. * The following fields should be filled in by the initialization * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */ @@ -345,9 +354,9 @@ struct netif { filter table of the ethernet MAC. */ netif_mld_mac_filter_fn mld_mac_filter; #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ -#if LWIP_NETIF_HWADDRHINT - u8_t *addr_hint; -#endif /* LWIP_NETIF_HWADDRHINT */ +#if LWIP_NETIF_USE_HINTS + struct netif_hint *hints; +#endif /* LWIP_NETIF_USE_HINTS */ #if ENABLE_LOOPBACK /* List of packets to be queued for ourselves. */ struct pbuf *loop_first; @@ -501,9 +510,11 @@ err_t netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t #endif /* LWIP_IPV6 */ #if LWIP_NETIF_HWADDRHINT -#define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint)) +#define NETIF_SET_HINTS(netif, netifhint) (netif)->hints = (netifhint) +#define NETIF_RESET_HINTS(netif) (netif)->hints = NULL #else /* LWIP_NETIF_HWADDRHINT */ -#define NETIF_SET_HWADDRHINT(netif, hint) +#define NETIF_SET_HINTS(netif, netifhint) +#define NETIF_RESET_HINTS(netif) #endif /* LWIP_NETIF_HWADDRHINT */ u8_t netif_name_to_index(const char *name);