From 22e2540eb6ab23c1f389510f3247533329a88144 Mon Sep 17 00:00:00 2001 From: fbernon Date: Mon, 31 Dec 2007 13:22:03 +0000 Subject: [PATCH] autoip.c, etharp.c: ip_addr.h: Integrate patch #6348: "Broadcast ARP packets in autoip". The change in etharp_raw could be removed, since all calls to etharp_raw use ethbroadcast for the "ethdst_addr" parameter. But it could be wrong in the future. --- CHANGELOG | 8 +++++++- src/core/ipv4/autoip.c | 15 +++------------ src/include/ipv4/lwip/ip_addr.h | 2 ++ src/netif/etharp.c | 25 +++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 714a27b4..e65ce51d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,7 +19,13 @@ HISTORY ++ New features: - 2007-12-31 Frédéric Bernon, Tom Evans + 2007-12-31 Frédéric Bernon, Luca Ceresoli + * autoip.c, etharp.c: ip_addr.h: Integrate patch #6348: "Broadcast ARP packets + in autoip". The change in etharp_raw could be removed, since all calls to + etharp_raw use ethbroadcast for the "ethdst_addr" parameter. But it could be + wrong in the future. + + 2007-12-30 Frédéric Bernon, Tom Evans * ip.c: Fix bug #21846 "LwIP doesn't appear to perform any IP Source Address Filtering" reported by Tom Evans. diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index d9267f3a..7975ff1f 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -178,17 +178,8 @@ autoip_create_rand_addr(struct netif *netif, struct ip_addr *RandomIPAddr) static err_t autoip_arp_announce(struct netif *netif) { - struct eth_addr eth_addr_bc, eth_addr_zero; - u8_t k = netif->hwaddr_len; - - while(k > 0) { - k--; - eth_addr_bc.addr[k] = 0xFF; - eth_addr_zero.addr[k] = 0x00; - } - - return etharp_raw(netif, (struct eth_addr *)netif->hwaddr, ð_addr_bc, - (struct eth_addr *)netif->hwaddr, &netif->autoip->llipaddr, ð_addr_zero, + return etharp_raw(netif, (struct eth_addr *)netif->hwaddr, ðbroadcast, + (struct eth_addr *)netif->hwaddr, &netif->autoip->llipaddr, ðzero, &netif->autoip->llipaddr, ARP_REQUEST); } @@ -319,7 +310,7 @@ autoip_tmr() netif->autoip->lastconflict--; } - LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | 3, + LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_tmr() AutoIP-State: %"U16_F", ttw=%"U16_F"\n", (u16_t)(netif->autoip->state), netif->autoip->ttw)); diff --git a/src/include/ipv4/lwip/ip_addr.h b/src/include/ipv4/lwip/ip_addr.h index 0302277e..7f243363 100644 --- a/src/include/ipv4/lwip/ip_addr.h +++ b/src/include/ipv4/lwip/ip_addr.h @@ -147,6 +147,8 @@ u8_t ip_addr_isbroadcast(struct ip_addr *, struct netif *); #define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000UL)) == ntohl(0xe0000000UL)) +#define ip_addr_islinklocal(addr1) (((addr1)->addr & ntohl(0xffff0000UL)) == ntohl(0xa9fe0000UL)) + #define ip_addr_debug_print(debug, ipaddr) \ LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \ ipaddr ? (u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0, \ diff --git a/src/netif/etharp.c b/src/netif/etharp.c index dec48b52..4631a6a6 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -624,6 +624,9 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) struct ip_addr sipaddr, dipaddr; u8_t i; u8_t for_us; +#if LWIP_AUTOIP + u8_t * ethdst_hwaddr; +#endif /* LWIP_AUTOIP */ LWIP_ERROR("netif != NULL", (netif != NULL), return;); @@ -709,10 +712,20 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!", (netif->hwaddr_len == ETHARP_HWADDR_LEN)); i = ETHARP_HWADDR_LEN; +#if LWIP_AUTOIP + /* If we are using Link-Local, ARP packets must be broadcast on the + * link layer. (See RFC3927 Section 2.5) */ + ethdst_hwaddr = ((netif->autoip != NULL) && (netif->autoip->state != AUTOIP_STATE_OFF)) ? (u8_t*)(ethbroadcast.addr) : hdr->shwaddr.addr; +#endif /* LWIP_AUTOIP */ + while(i > 0) { i--; hdr->dhwaddr.addr[i] = hdr->shwaddr.addr[i]; +#if LWIP_AUTOIP + hdr->ethhdr.dest.addr[i] = ethdst_hwaddr[i]; +#else /* LWIP_AUTOIP */ hdr->ethhdr.dest.addr[i] = hdr->shwaddr.addr[i]; +#endif /* LWIP_AUTOIP */ hdr->shwaddr.addr[i] = ethaddr->addr[i]; hdr->ethhdr.src.addr[i] = ethaddr->addr[i]; } @@ -1025,6 +1038,9 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, err_t result = ERR_OK; u8_t k; /* ARP entry index */ struct etharp_hdr *hdr; +#if LWIP_AUTOIP + u8_t * ethdst_hwaddr; +#endif /* LWIP_AUTOIP */ /* allocate a pbuf for the outgoing ARP request packet */ p = pbuf_alloc(PBUF_LINK, sizeof(struct etharp_hdr), PBUF_RAM); @@ -1044,6 +1060,11 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!", (netif->hwaddr_len == ETHARP_HWADDR_LEN)); k = ETHARP_HWADDR_LEN; +#if LWIP_AUTOIP + /* If we are using Link-Local, ARP packets must be broadcast on the + * link layer. (See RFC3927 Section 2.5) */ + ethdst_hwaddr = ((netif->autoip != NULL) && (netif->autoip->state != AUTOIP_STATE_OFF)) ? (u8_t*)(ethbroadcast.addr) : ethdst_addr->addr; +#endif /* LWIP_AUTOIP */ /* Write MAC-Addresses (combined loop for both headers) */ while(k > 0) { k--; @@ -1051,7 +1072,11 @@ etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, hdr->shwaddr.addr[k] = hwsrc_addr->addr[k]; hdr->dhwaddr.addr[k] = hwdst_addr->addr[k]; /* Write the Ethernet MAC-Addresses */ +#if LWIP_AUTOIP + hdr->ethhdr.dest.addr[k] = ethdst_hwaddr[k]; +#else /* LWIP_AUTOIP */ hdr->ethhdr.dest.addr[k] = ethdst_addr->addr[k]; +#endif /* LWIP_AUTOIP */ hdr->ethhdr.src.addr[k] = ethsrc_addr->addr[k]; } hdr->sipaddr = *(struct ip_addr2 *)ipsrc_addr;