/** * Handles every incoming ARP Packet, called by etharp_arp_input. * * @param netif network interface to use for autoip processing * @param hdr Incoming ARP packet */ void autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) { LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_arp_reply()\n")); if ((netif->autoip != NULL) && (netif->autoip->state != AUTOIP_STATE_OFF)) { /* when ip.src == llipaddr && hw.src != netif->hwaddr * * when probing ip.dst == llipaddr && hw.src != netif->hwaddr * we have a conflict and must solve it */ ip_addr_t sipaddr, dipaddr; struct eth_addr netifaddr; ETHADDR16_COPY(netifaddr.addr, netif->hwaddr); /* Copy struct ip_addr2 to aligned ip_addr, to support compilers without * structure packing (not using structure copy which breaks strict-aliasing rules). */ IPADDR2_COPY(&sipaddr, &hdr->sipaddr); IPADDR2_COPY(&dipaddr, &hdr->dipaddr); if ((netif->autoip->state == AUTOIP_STATE_PROBING) || ((netif->autoip->state == AUTOIP_STATE_ANNOUNCING) && (netif->autoip->sent_num == 0))) { /* RFC 3927 Section 2.2.1: * from beginning to after ANNOUNCE_WAIT * seconds we have a conflict if * ip.src == llipaddr OR * ip.dst == llipaddr && hw.src != own hwaddr */ if ((ip_addr_cmp(&sipaddr, &netif->autoip->llipaddr)) || (ip_addr_cmp(&dipaddr, &netif->autoip->llipaddr) && !eth_addr_cmp(&netifaddr, &hdr->shwaddr))) { LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING, ("autoip_arp_reply(): Probe Conflict detected\n")); /* Clear stored lladdr in case of conflict. As device should now * re-probe conflicted address. */ memset(&prev_llipaddr, 0, sizeof(ip_addr_t)); autoip_restart(netif); } } else { /* RFC 3927 Section 2.5: * in any state we have a conflict if * ip.src == llipaddr && hw.src != own hwaddr */ if (ip_addr_cmp(&sipaddr, &netif->autoip->llipaddr) && !eth_addr_cmp(&netifaddr, &hdr->shwaddr)) { LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING, ("autoip_arp_reply(): Conflicting ARP-Packet detected\n")); /* Clear stored lladdr in case of conflict. As device should now * re-probe conflicted address. * Clear stored address only if it was not announced */ if (netif->autoip->state != AUTOIP_STATE_BOUND) memset(&prev_llipaddr, 0, sizeof(ip_addr_t)); autoip_handle_arp_conflict(netif); } } } }
/** * Handles every incoming ARP Packet, called by etharp_arp_input. * * @param netif network interface to use for autoip processing * @param hdr Incoming ARP packet */ void autoip_arp_reply(struct netif *netif, struct etharp_hdr *hdr) { LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_arp_reply()\n")); if ((netif->autoip != NULL) && (netif->autoip->state != AUTOIP_STATE_OFF)) { /* when ip.src == llipaddr && hw.src != netif->hwaddr * * when probing ip.dst == llipaddr && hw.src != netif->hwaddr * we have a conflict and must solve it */ struct ip_addr sipaddr, dipaddr; struct eth_addr netifaddr; netifaddr.addr[0] = netif->hwaddr[0]; netifaddr.addr[1] = netif->hwaddr[1]; netifaddr.addr[2] = netif->hwaddr[2]; netifaddr.addr[3] = netif->hwaddr[3]; netifaddr.addr[4] = netif->hwaddr[4]; netifaddr.addr[5] = netif->hwaddr[5]; /* Copy struct ip_addr2 to aligned ip_addr, to support compilers without * structure packing (not using structure copy which breaks strict-aliasing rules). */ SMEMCPY(&sipaddr, &hdr->sipaddr, sizeof(sipaddr)); SMEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr)); if ((netif->autoip->state == AUTOIP_STATE_PROBING) || ((netif->autoip->state == AUTOIP_STATE_ANNOUNCING) && (netif->autoip->sent_num == 0))) { /* RFC 3927 Section 2.2.1: * from beginning to after ANNOUNCE_WAIT * seconds we have a conflict if * ip.src == llipaddr OR * ip.dst == llipaddr && hw.src != own hwaddr */ if ((ip_addr_cmp(&sipaddr, &netif->autoip->llipaddr)) || (ip_addr_cmp(&dipaddr, &netif->autoip->llipaddr) && !eth_addr_cmp(&netifaddr, &hdr->shwaddr))) { LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING, ("autoip_arp_reply(): Probe Conflict detected\n")); autoip_start(netif); } } else { /* RFC 3927 Section 2.5: * in any state we have a conflict if * ip.src == llipaddr && hw.src != own hwaddr */ if (ip_addr_cmp(&sipaddr, &netif->autoip->llipaddr) && !eth_addr_cmp(&netifaddr, &hdr->shwaddr)) { LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING, ("autoip_arp_reply(): Conflicting ARP-Packet detected\n")); autoip_handle_arp_conflict(netif); } } } }