From 2d6c314c64c0c8e6c51f10dc5ea4970f1398c7b7 Mon Sep 17 00:00:00 2001 From: likewise Date: Thu, 22 Jan 2004 20:41:22 +0000 Subject: [PATCH] Corrected some comments. Strongened assertions. Preparation for gratuitous ARP sending. --- src/netif/etharp.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/netif/etharp.c b/src/netif/etharp.c index b1417898..b3e04483 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -372,20 +372,22 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e #if ARP_QUEUEING /* get the first packet on the queue (if any) */ p = arp_table[i].p; - /* queued packet present? */ + /* (another) queued packet present? */ while (p != NULL) { struct pbuf *q, *n; /* search for second packet on queue (n) */ q = p; while (q->tot_len > q->len) { - /* proceed to next pbuf of this packet */ - LWIP_ASSERT("q->next ! NULL", q->next != NULL); - q = q->next; + LWIP_ASSERT("q->next != NULL (while q->tot_len > q->len)", q->next != NULL); + /* proceed to next pbuf of this packet */ + q = q->next; } - /* { q = last pbuf of first packet, q->tot_len = q->len } */ + /* { q = last pbuf of this packet, q->tot_len == q->len } */ + LWIP_ASSERT("q->tot_len == q->len", q->tot_len == q->len); + /* remember next packet on queue */ n = q->next; - /* { n = first pbuf of 2nd packet, or NULL if no 2nd packet } */ - /* terminate the first packet pbuf chain */ + /* { n = first pbuf of next packet, or NULL if no next packet } */ + /* terminate this packet pbuf chain */ q->next = NULL; /* fill-in Ethernet header */ ethhdr = p->payload; @@ -394,7 +396,7 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e ethhdr->src.addr[k] = netif->hwaddr[k]; } ethhdr->type = htons(ETHTYPE_IP); - LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: sending queued IP packet %p.\n",(void *)p)); + LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: sending queued IP packet %p.\n", (void *)p)); /* send the queued IP packet */ netif->linkoutput(netif, p); /* free the queued IP packet */ @@ -405,10 +407,11 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e /* NULL attached buffer*/ arp_table[i].p = NULL; #endif + /* IP addresses should only occur once in the ARP entry, we are done */ return NULL; } - } /* if */ - } /* for */ + } /* if STABLE */ + } /* for all ARP entries */ /* no matching ARP entry was found */ LWIP_ASSERT("update_arp_entry: i == ARP_TABLE_SIZE", i == ARP_TABLE_SIZE); @@ -520,6 +523,8 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) /* ARP packet directed to us? */ for_us = ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr)); } + + /* first, let's answer */ switch (htons(hdr->opcode)) { /* ARP request? */ @@ -545,7 +550,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) ip_addr_set(&(hdr->dipaddr), &(hdr->sipaddr)); ip_addr_set(&(hdr->sipaddr), &(netif->ip_addr)); - for(i = 0; i < netif->hwaddr_len; ++i) { + for (i = 0; i < netif->hwaddr_len; ++i) { hdr->dhwaddr.addr[i] = hdr->shwaddr.addr[i]; hdr->shwaddr.addr[i] = ethaddr->addr[i]; hdr->ethhdr.dest.addr[i] = hdr->dhwaddr.addr[i]; @@ -571,7 +576,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) /* ARP reply. We insert or update the ARP table later. */ LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: incoming ARP reply\n")); #if (LWIP_DHCP && DHCP_DOES_ARP_CHECK) - /* DHCP needs to know about ARP replies to our address */ + /* DHCP wants to know about ARP replies to our wanna-have-address */ if (for_us) dhcp_arp_reply(netif, &hdr->sipaddr); #endif break; @@ -584,7 +589,7 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) /* insert IP address in ARP cache (assume requester wants to talk to us) * we might even send out a queued packet to this host */ update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), ARP_INSERT_FLAG); - /* request was not directed to us, but snoop anyway */ + /* request was not directed to us, but snoop for updates anyway */ } else { /* update or insert the source IP address in the cache */ update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), 0);