42 |
* |
* |
43 |
*/ |
*/ |
44 |
|
|
45 |
|
/** |
46 |
|
* TODO: |
47 |
|
* - pbufs should be sent from the queue once an ARP entry state |
48 |
|
* goes from PENDING to STABLE. |
49 |
|
* - Non-PENDING entries MUST NOT have queued packets. |
50 |
|
*/ |
51 |
|
|
52 |
/* |
/* |
53 |
* TODO: |
* TODO: |
54 |
* |
* |
314 |
/** |
/** |
315 |
* Update (or insert) a IP/MAC address pair in the ARP cache. |
* Update (or insert) a IP/MAC address pair in the ARP cache. |
316 |
* |
* |
317 |
|
* If a pending entry is resolved, any queued packets will be sent |
318 |
|
* at this point. |
319 |
|
* |
320 |
* @param ipaddr IP address of the inserted ARP entry. |
* @param ipaddr IP address of the inserted ARP entry. |
321 |
* @param ethaddr Ethernet address of the inserted ARP entry. |
* @param ethaddr Ethernet address of the inserted ARP entry. |
322 |
* @param flags Defines behaviour: |
* @param flags Defines behaviour: |
355 |
arp_table[i].state = ETHARP_STATE_STABLE; |
arp_table[i].state = ETHARP_STATE_STABLE; |
356 |
/* fall-through to next if */ |
/* fall-through to next if */ |
357 |
} |
} |
358 |
/* stable entry? (possible just marked to become stable) */ |
/* stable entry? (possibly just marked to become stable) */ |
359 |
if (arp_table[i].state == ETHARP_STATE_STABLE) { |
if (arp_table[i].state == ETHARP_STATE_STABLE) { |
360 |
#if ARP_QUEUEING |
#if ARP_QUEUEING |
361 |
struct pbuf *p; |
struct pbuf *p; |
368 |
} |
} |
369 |
/* reset time stamp */ |
/* reset time stamp */ |
370 |
arp_table[i].ctime = 0; |
arp_table[i].ctime = 0; |
371 |
|
/* this is where we will send out queued packets! */ |
372 |
#if ARP_QUEUEING |
#if ARP_QUEUEING |
373 |
|
/* get the first packet on the queue (if any) */ |
374 |
p = arp_table[i].p; |
p = arp_table[i].p; |
375 |
/* queued packet present? */ |
/* queued packet present? */ |
376 |
if (p != NULL) { |
while (p != NULL) { |
377 |
/* NULL attached buffer immediately */ |
struct pbuf *q, *n; |
378 |
arp_table[i].p = NULL; |
/* search for second packet on queue (n) */ |
379 |
|
q = p; |
380 |
|
while (q->tot_len > q->len) { |
381 |
|
/* proceed to next pbuf of this packet */ |
382 |
|
LWIP_ASSERT("q->next ! NULL", q->next != NULL); |
383 |
|
q = q->next; |
384 |
|
} |
385 |
|
/* { q = last pbuf of first packet, q->tot_len = q->len } */ |
386 |
|
n = q->next; |
387 |
|
/* { n = first pbuf of 2nd packet, or NULL if no 2nd packet } */ |
388 |
|
/* terminate the first packet pbuf chain */ |
389 |
|
q->next = NULL; |
390 |
/* fill-in Ethernet header */ |
/* fill-in Ethernet header */ |
391 |
ethhdr = p->payload; |
ethhdr = p->payload; |
392 |
for (k = 0; k < netif->hwaddr_len; ++k) { |
for (k = 0; k < netif->hwaddr_len; ++k) { |
394 |
ethhdr->src.addr[k] = netif->hwaddr[k]; |
ethhdr->src.addr[k] = netif->hwaddr[k]; |
395 |
} |
} |
396 |
ethhdr->type = htons(ETHTYPE_IP); |
ethhdr->type = htons(ETHTYPE_IP); |
397 |
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: sending queued IP packet.\n")); |
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("update_arp_entry: sending queued IP packet %p.\n",(void *)p)); |
398 |
/* send the queued IP packet */ |
/* send the queued IP packet */ |
399 |
netif->linkoutput(netif, p); |
netif->linkoutput(netif, p); |
400 |
/* free the queued IP packet */ |
/* free the queued IP packet */ |
401 |
pbuf_free(p); |
pbuf_free(p); |
402 |
|
/* proceed to next packet on queue */ |
403 |
|
p = n; |
404 |
} |
} |
405 |
|
/* NULL attached buffer*/ |
406 |
|
arp_table[i].p = NULL; |
407 |
#endif |
#endif |
408 |
return NULL; |
return NULL; |
409 |
} |
} |
447 |
} |
} |
448 |
|
|
449 |
/** |
/** |
450 |
* Updates the ARP table using the given packet. |
* Updates the ARP table using the given IP packet. |
451 |
* |
* |
452 |
* Uses the incoming IP packet's source address to update the |
* Uses the incoming IP packet's source address to update the |
453 |
* ARP cache for the local network. The function does not alter |
* ARP cache for the local network. The function does not alter |