129 |
static struct pbuf *update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags); |
static struct pbuf *update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags); |
130 |
#if ARP_QUEUEING |
#if ARP_QUEUEING |
131 |
static struct pbuf *etharp_enqueue(s8_t i, struct pbuf *q); |
static struct pbuf *etharp_enqueue(s8_t i, struct pbuf *q); |
132 |
static struct pbuf *etharp_dequeue(s8_t i); |
static u8_t etharp_dequeue(s8_t i); |
133 |
#endif |
#endif |
134 |
/** |
/** |
135 |
* Initializes ARP module. |
* Initializes ARP module. |
231 |
/* clean up the recycled stable entry */ |
/* clean up the recycled stable entry */ |
232 |
if (arp_table[i].state == ETHARP_STATE_STABLE) { |
if (arp_table[i].state == ETHARP_STATE_STABLE) { |
233 |
#if ARP_QUEUEING |
#if ARP_QUEUEING |
|
struct pbuf *q; |
|
234 |
/* free packets on queue */ |
/* free packets on queue */ |
235 |
q = etharp_dequeue(i); |
etharp_dequeue(i); |
|
if (q != NULL) pbuf_free(q); |
|
236 |
#endif |
#endif |
237 |
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("find_arp_entry: recycling oldest stable entry %u\n", i)); |
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("find_arp_entry: recycling oldest stable entry %u\n", i)); |
238 |
arp_table[i].state = ETHARP_STATE_EMPTY; |
arp_table[i].state = ETHARP_STATE_EMPTY; |
243 |
} |
} |
244 |
|
|
245 |
#if ARP_QUEUEING |
#if ARP_QUEUEING |
246 |
|
/* |
247 |
|
* Enqueues a pbuf (chain) on an ARP entry. |
248 |
|
* |
249 |
|
* Places the pbuf (chain) on the queue (if space allows). The |
250 |
|
* caller may safely free the pbuf (chain) afterwards, as the |
251 |
|
* pbufs will be referenced by the queue and copies are made of |
252 |
|
* pbufs referencing external payloads. |
253 |
|
* |
254 |
|
* @ i the ARP entry index |
255 |
|
* @arg q the pbuf (chain) to be queued on the ARP entry |
256 |
|
* |
257 |
|
* @return Returns the new head of queue of the ARP entry. |
258 |
|
* |
259 |
|
*/ |
260 |
static struct pbuf * |
static struct pbuf * |
261 |
etharp_enqueue(s8_t i, struct pbuf *q) |
etharp_enqueue(s8_t i, struct pbuf *q) |
262 |
{ |
{ |
263 |
/* any pbuf to queue? */ |
/* any pbuf to queue? */ |
264 |
if (q != NULL) { |
if (q != NULL) { |
265 |
/* remove old packet on queue? */ |
/* queue later packet over earliers? TODO: Implement multiple pbuf queue */ |
266 |
#if ARP_QUEUE_FIRST == 0 |
#if ARP_QUEUE_FIRST == 0 |
267 |
struct pbuf *p; |
/* remove any pbufs on queue */ |
268 |
p = etharp_dequeue(i); |
u8_t deq = etharp_dequeue(i); |
269 |
if (p != NULL) pbuf_free(p); |
if (deq > 0) LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE | 3, ("etharp_query: dequeued %u pbufs from ARP entry %u. Should not occur.\n", deq, i)); |
|
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE | 3, ("etharp_query: dropped packet %p on ARP queue. Should not occur.\n", (void *)arp_table[i].p)); |
|
270 |
#endif |
#endif |
271 |
/* packet can be queued? */ |
/* packet can be queued? TODO: Implement multiple pbuf queue */ |
272 |
if (arp_table[i].p == NULL) { |
if (arp_table[i].p == NULL) { |
273 |
/* copy PBUF_REF referenced payloads into PBUF_RAM */ |
/* copy any PBUF_REF referenced payloads into PBUF_RAM */ |
274 |
q = pbuf_take(q); |
q = pbuf_take(q); |
275 |
/* remember pbuf to queue, if any */ |
/* add pbuf to queue */ |
276 |
arp_table[i].p = q; |
arp_table[i].p = q; |
277 |
/* pbufs are queued, increase the reference count */ |
/* pbuf (chain) now queued, increase the reference count */ |
278 |
pbuf_ref(q); |
pbuf_ref(q); |
279 |
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("etharp_query: queued packet %p on ARP entry %u.\n", (void *)q, i)); |
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("etharp_query: queued packet %p on ARP entry %u.\n", (void *)q, i)); |
280 |
} |
} |
282 |
return arp_table[i].p; |
return arp_table[i].p; |
283 |
} |
} |
284 |
|
|
285 |
static struct pbuf * |
/** |
286 |
|
* Dequeues any pbufs queued on an ARP entry |
287 |
|
* |
288 |
|
* @return number of pbufs removed from the queue |
289 |
|
* |
290 |
|
* TODO: decide what is a sensible return value? |
291 |
|
*/ |
292 |
|
static u8_t |
293 |
etharp_dequeue(s8_t i) |
etharp_dequeue(s8_t i) |
294 |
{ |
{ |
295 |
/* queued packets on a stable entry (work in progress) */ |
/* queued packets on a stable entry (work in progress) */ |
296 |
if (arp_table[i].p != NULL) { |
if (arp_table[i].p != NULL) { |
297 |
/* send the queued IP packets */ |
/* queue no longer references pbuf */ |
298 |
netif->linkoutput(netif, arp_table[i].p); |
pbuf_free(arp_table[i].p); |
|
LWIP_DEBUGF(ETHARP_DEBUG | DBG_TRACE | 3, |
|
|
("find_arp_entry: sent queued packet %p.\n", (void *)arp_table[i].p)); |
|
299 |
arp_table[i].p = NULL; |
arp_table[i].p = NULL; |
300 |
|
return 1; |
301 |
|
} else { |
302 |
|
return 0; |
303 |
} |
} |
|
return arp_table[i].p; |
|
304 |
} |
} |
305 |
#endif |
#endif |
306 |
|
|