mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-08-24 23:25:58 +00:00
Either first or last packet can be queued. Fixed (err_t)NULL return value in etharp_query().
This commit is contained in:
parent
1204e461c8
commit
042b2a39d9
@ -643,8 +643,9 @@ err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
|||||||
struct eth_addr *srcaddr;
|
struct eth_addr *srcaddr;
|
||||||
struct etharp_hdr *hdr;
|
struct etharp_hdr *hdr;
|
||||||
struct pbuf *p;
|
struct pbuf *p;
|
||||||
err_t result;
|
err_t result = ERR_OK;
|
||||||
u8_t i;
|
u8_t i;
|
||||||
|
u8_t perform_arp_request = 1;
|
||||||
/* prevent warning if ARP_QUEUEING == 0 */
|
/* prevent warning if ARP_QUEUEING == 0 */
|
||||||
if (q);
|
if (q);
|
||||||
|
|
||||||
@ -659,8 +660,10 @@ err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
|||||||
}
|
}
|
||||||
else if (arp_table[i].state == ETHARP_STATE_STABLE) {
|
else if (arp_table[i].state == ETHARP_STATE_STABLE) {
|
||||||
DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("etharp_query: requested IP already stable as entry %u\n", i));
|
DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("etharp_query: requested IP already stable as entry %u\n", i));
|
||||||
/* TODO: user may wish to queue a packet on a stable entry. */
|
/* user may wish to queue a packet on a stable entry, so we proceed without ARP requesting */
|
||||||
return NULL;
|
/* TODO: even if the ARP entry is stable, we might do an ARP request anyway in some cases? */
|
||||||
|
perform_arp_request = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -672,7 +675,7 @@ err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
|||||||
/* bail out if no ARP entries are available */
|
/* bail out if no ARP entries are available */
|
||||||
if (i == ARP_TABLE_SIZE) {
|
if (i == ARP_TABLE_SIZE) {
|
||||||
DEBUGF(ETHARP_DEBUG | 2, ("etharp_query: no more ARP entries available.\n"));
|
DEBUGF(ETHARP_DEBUG | 2, ("etharp_query: no more ARP entries available.\n"));
|
||||||
return NULL;
|
return ERR_MEM;
|
||||||
}
|
}
|
||||||
DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_query: created ARP table entry %u.\n", i));
|
DEBUGF(ETHARP_DEBUG | DBG_TRACE, ("etharp_query: created ARP table entry %u.\n", i));
|
||||||
/* i is available, create ARP entry */
|
/* i is available, create ARP entry */
|
||||||
@ -680,12 +683,28 @@ err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
|||||||
arp_table[i].ctime = 0;
|
arp_table[i].ctime = 0;
|
||||||
arp_table[i].state = ETHARP_STATE_PENDING;
|
arp_table[i].state = ETHARP_STATE_PENDING;
|
||||||
#if ARP_QUEUEING
|
#if ARP_QUEUEING
|
||||||
|
/* free queued packet, as entry is now invalidated */
|
||||||
|
if (arp_table[i].p != NULL) {
|
||||||
|
pbuf_free(arp_table[i].p);
|
||||||
arp_table[i].p = NULL;
|
arp_table[i].p = NULL;
|
||||||
|
DEBUGF(ETHARP_DEBUG | DBG_TRACE | 3, ("etharp_query: dropped packet on ARP queue. Should not occur.\n"));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if ARP_QUEUEING
|
#if ARP_QUEUEING
|
||||||
/* any pbuf to queue and queue is empty? */
|
/* any pbuf to queue and queue is empty? */
|
||||||
if ((q != NULL) && (arp_table[i].p == NULL)) {
|
if (q != NULL) {
|
||||||
|
/* yield later packets over older packets? */
|
||||||
|
#if ARP_QUEUE_FIRST == 0
|
||||||
|
/* earlier queued packet on this entry? */
|
||||||
|
if (arp_table[i].p != NULL) {
|
||||||
|
pbuf_free(arp_table[i].p);
|
||||||
|
arp_table[i].p = NULL;
|
||||||
|
DEBUGF(ETHARP_DEBUG | DBG_TRACE | 3, ("etharp_query: dropped packet on ARP queue. Should not occur.\n"));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* packet can be queued? */
|
||||||
|
if (arp_table[i].p == NULL) {
|
||||||
/* copy PBUF_REF referenced payloads to PBUF_RAM */
|
/* copy PBUF_REF referenced payloads to PBUF_RAM */
|
||||||
q = pbuf_take(q);
|
q = pbuf_take(q);
|
||||||
/* remember pbuf to queue, if any */
|
/* remember pbuf to queue, if any */
|
||||||
@ -694,7 +713,11 @@ err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
|||||||
pbuf_ref(q);
|
pbuf_ref(q);
|
||||||
DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("etharp_query: queued packet %p on ARP entry %u.\n", (void *)q, i));
|
DEBUGF(ETHARP_DEBUG | DBG_TRACE | DBG_STATE, ("etharp_query: queued packet %p on ARP entry %u.\n", (void *)q, i));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
/* ARP request? */
|
||||||
|
if (perform_arp_request)
|
||||||
|
{
|
||||||
/* allocate a pbuf for the outgoing ARP request packet */
|
/* allocate a pbuf for the outgoing ARP request packet */
|
||||||
p = pbuf_alloc(PBUF_LINK, sizeof(struct etharp_hdr), PBUF_RAM);
|
p = pbuf_alloc(PBUF_LINK, sizeof(struct etharp_hdr), PBUF_RAM);
|
||||||
/* could allocate pbuf? */
|
/* could allocate pbuf? */
|
||||||
@ -731,5 +754,6 @@ err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q)
|
|||||||
result = ERR_MEM;
|
result = ERR_MEM;
|
||||||
DEBUGF(ETHARP_DEBUG | DBG_TRACE | 2, ("etharp_query: could not allocate pbuf for ARP request.\n"));
|
DEBUGF(ETHARP_DEBUG | DBG_TRACE | 2, ("etharp_query: could not allocate pbuf for ARP request.\n"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user