Corrected some comments. Strongened assertions. Preparation for gratuitous ARP sending.

This commit is contained in:
likewise 2004-01-22 20:41:22 +00:00
parent 9ac8e17203
commit 2d6c314c64

View File

@ -372,20 +372,22 @@ update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *e
#if ARP_QUEUEING #if ARP_QUEUEING
/* get the first packet on the queue (if any) */ /* get the first packet on the queue (if any) */
p = arp_table[i].p; p = arp_table[i].p;
/* queued packet present? */ /* (another) queued packet present? */
while (p != NULL) { while (p != NULL) {
struct pbuf *q, *n; struct pbuf *q, *n;
/* search for second packet on queue (n) */ /* search for second packet on queue (n) */
q = p; q = p;
while (q->tot_len > q->len) { while (q->tot_len > q->len) {
/* proceed to next pbuf of this packet */ LWIP_ASSERT("q->next != NULL (while q->tot_len > q->len)", q->next != NULL);
LWIP_ASSERT("q->next ! NULL", q->next != NULL); /* proceed to next pbuf of this packet */
q = q->next; 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 = q->next;
/* { n = first pbuf of 2nd packet, or NULL if no 2nd packet } */ /* { n = first pbuf of next packet, or NULL if no next packet } */
/* terminate the first packet pbuf chain */ /* terminate this packet pbuf chain */
q->next = NULL; q->next = NULL;
/* fill-in Ethernet header */ /* fill-in Ethernet header */
ethhdr = p->payload; 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->src.addr[k] = netif->hwaddr[k];
} }
ethhdr->type = htons(ETHTYPE_IP); 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 */ /* send the queued IP packet */
netif->linkoutput(netif, p); netif->linkoutput(netif, p);
/* free the queued IP packet */ /* 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*/ /* NULL attached buffer*/
arp_table[i].p = NULL; arp_table[i].p = NULL;
#endif #endif
/* IP addresses should only occur once in the ARP entry, we are done */
return NULL; return NULL;
} }
} /* if */ } /* if STABLE */
} /* for */ } /* for all ARP entries */
/* no matching ARP entry was found */ /* no matching ARP entry was found */
LWIP_ASSERT("update_arp_entry: i == ARP_TABLE_SIZE", i == ARP_TABLE_SIZE); LWIP_ASSERT("update_arp_entry: i == ARP_TABLE_SIZE", i == ARP_TABLE_SIZE);
@ -521,6 +524,8 @@ etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p)
for_us = ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr)); for_us = ip_addr_cmp(&(hdr->dipaddr), &(netif->ip_addr));
} }
/* first, let's answer */
switch (htons(hdr->opcode)) { switch (htons(hdr->opcode)) {
/* ARP request? */ /* ARP request? */
case ARP_REQUEST: case 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->dipaddr), &(hdr->sipaddr));
ip_addr_set(&(hdr->sipaddr), &(netif->ip_addr)); 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->dhwaddr.addr[i] = hdr->shwaddr.addr[i];
hdr->shwaddr.addr[i] = ethaddr->addr[i]; hdr->shwaddr.addr[i] = ethaddr->addr[i];
hdr->ethhdr.dest.addr[i] = hdr->dhwaddr.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. */ /* ARP reply. We insert or update the ARP table later. */
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: incoming ARP reply\n")); LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_arp_input: incoming ARP reply\n"));
#if (LWIP_DHCP && DHCP_DOES_ARP_CHECK) #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); if (for_us) dhcp_arp_reply(netif, &hdr->sipaddr);
#endif #endif
break; 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) /* insert IP address in ARP cache (assume requester wants to talk to us)
* we might even send out a queued packet to this host */ * we might even send out a queued packet to this host */
update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), ARP_INSERT_FLAG); 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 { } else {
/* update or insert the source IP address in the cache */ /* update or insert the source IP address in the cache */
update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), 0); update_arp_entry(netif, &(hdr->sipaddr), &(hdr->shwaddr), 0);