UbixOS V2 2.0

etharp.c
Go to the documentation of this file.
1
14 /*
15 * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
16 * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
17 * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
18 * All rights reserved.
19 *
20 * Redistribution and use in source and binary forms, with or without modification,
21 * are permitted provided that the following conditions are met:
22 *
23 * 1. Redistributions of source code must retain the above copyright notice,
24 * this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright notice,
26 * this list of conditions and the following disclaimer in the documentation
27 * and/or other materials provided with the distribution.
28 * 3. The name of the author may not be used to endorse or promote products
29 * derived from this software without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
32 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
33 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
34 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
36 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
39 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
40 * OF SUCH DAMAGE.
41 *
42 * This file is part of the lwIP TCP/IP stack.
43 *
44 */
45
46 #include "net/opt.h"
47
48 #if LWIP_ARP || LWIP_ETHERNET
49
50 #include "net/etharp.h"
51 #include "net/stats.h"
52 #include "net/snmp.h"
53 #include "net/dhcp.h"
54 #include "net/autoip.h"
55 #include "netif/ethernet.h"
56
57 #include <string.h>
58
59 #ifdef LWIP_HOOK_FILENAME
60 #include LWIP_HOOK_FILENAME
61 #endif
62
63 #if LWIP_IPV4 && LWIP_ARP /* don't build if not configured for use in lwipopts.h */
64
67 #define ARP_AGE_REREQUEST_USED_UNICAST (ARP_MAXAGE - 30)
68 #define ARP_AGE_REREQUEST_USED_BROADCAST (ARP_MAXAGE - 15)
69
77 #define ARP_MAXPENDING 5
78
80 enum etharp_state {
81 ETHARP_STATE_EMPTY = 0,
82 ETHARP_STATE_PENDING,
83 ETHARP_STATE_STABLE,
84 ETHARP_STATE_STABLE_REREQUESTING_1,
85 ETHARP_STATE_STABLE_REREQUESTING_2
86 #if ETHARP_SUPPORT_STATIC_ENTRIES
87 ,ETHARP_STATE_STATIC
88 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
89 };
90
91 struct etharp_entry {
92 #if ARP_QUEUEING
93
94 struct etharp_q_entry *q;
95 #else /* ARP_QUEUEING */
96
97 struct pbuf *q;
98 #endif /* ARP_QUEUEING */
99 ip4_addr_t ipaddr;
100 struct netif *netif;
101 struct eth_addr ethaddr;
102 u16_t ctime;
103 u8_t state;
104 };
105
106 static struct etharp_entry arp_table[ARP_TABLE_SIZE];
107
108 #if !LWIP_NETIF_HWADDRHINT
109 static u8_t etharp_cached_entry;
110 #endif /* !LWIP_NETIF_HWADDRHINT */
111
114 #define ETHARP_FLAG_TRY_HARD 1
115 #define ETHARP_FLAG_FIND_ONLY 2
116 #if ETHARP_SUPPORT_STATIC_ENTRIES
117 #define ETHARP_FLAG_STATIC_ENTRY 4
118 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
119
120 #if LWIP_NETIF_HWADDRHINT
121 #define ETHARP_SET_HINT(netif, hint) if (((netif) != NULL) && ((netif)->addr_hint != NULL)) \
122 *((netif)->addr_hint) = (hint);
123 #else /* LWIP_NETIF_HWADDRHINT */
124 #define ETHARP_SET_HINT(netif, hint) (etharp_cached_entry = (hint))
125 #endif /* LWIP_NETIF_HWADDRHINT */
126
127
128 /* Some checks, instead of etharp_init(): */
129 #if (LWIP_ARP && (ARP_TABLE_SIZE > 0x7f))
130 #error "ARP_TABLE_SIZE must fit in an s8_t, you have to reduce it in your lwipopts.h"
131 #endif
132
133
134 static err_t etharp_request_dst(struct netif *netif, const ip4_addr_t *ipaddr, const struct eth_addr* hw_dst_addr);
135 static err_t etharp_raw(struct netif *netif,
136 const struct eth_addr *ethsrc_addr, const struct eth_addr *ethdst_addr,
137 const struct eth_addr *hwsrc_addr, const ip4_addr_t *ipsrc_addr,
138 const struct eth_addr *hwdst_addr, const ip4_addr_t *ipdst_addr,
139 const u16_t opcode);
140
141 #if ARP_QUEUEING
142
147 static void
148 free_etharp_q(struct etharp_q_entry *q)
149 {
150 struct etharp_q_entry *r;
151 LWIP_ASSERT("q != NULL", q != NULL);
152 LWIP_ASSERT("q->p != NULL", q->p != NULL);
153 while (q) {
154 r = q;
155 q = q->next;
156 LWIP_ASSERT("r->p != NULL", (r->p != NULL));
157 pbuf_free(r->p);
158 memp_free(MEMP_ARP_QUEUE, r);
159 }
160 }
161 #else /* ARP_QUEUEING */
162
164 #define free_etharp_q(q) pbuf_free(q)
165
166 #endif /* ARP_QUEUEING */
167
169 static void
170 etharp_free_entry(int i)
171 {
172 /* remove from SNMP ARP index tree */
173 mib2_remove_arp_entry(arp_table[i].netif, &arp_table[i].ipaddr);
174 /* and empty packet queue */
175 if (arp_table[i].q != NULL) {
176 /* remove all queued packets */
177 LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_free_entry: freeing entry %"U16_F", packet queue %p.\n", (u16_t)i, (void *)(arp_table[i].q)));
178 free_etharp_q(arp_table[i].q);
179 arp_table[i].q = NULL;
180 }
181 /* recycle entry for re-use */
182 arp_table[i].state = ETHARP_STATE_EMPTY;
183 #ifdef LWIP_DEBUG
184 /* for debugging, clean out the complete entry */
185 arp_table[i].ctime = 0;
186 arp_table[i].netif = NULL;
187 ip4_addr_set_zero(&arp_table[i].ipaddr);
188 arp_table[i].ethaddr = ethzero;
189 #endif /* LWIP_DEBUG */
190 }
191
198 void
199 etharp_tmr(void)
200 {
201 u8_t i;
202
203 LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer\n"));
204 /* remove expired entries from the ARP table */
205 for (i = 0; i < ARP_TABLE_SIZE; ++i) {
206 u8_t state = arp_table[i].state;
207 if (state != ETHARP_STATE_EMPTY
208 #if ETHARP_SUPPORT_STATIC_ENTRIES
209 && (state != ETHARP_STATE_STATIC)
210 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
211 ) {
212 arp_table[i].ctime++;
213 if ((arp_table[i].ctime >= ARP_MAXAGE) ||
214 ((arp_table[i].state == ETHARP_STATE_PENDING) &&
215 (arp_table[i].ctime >= ARP_MAXPENDING))) {
216 /* pending or stable entry has become old! */
217 LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer: expired %s entry %"U16_F".\n",
218 arp_table[i].state >= ETHARP_STATE_STABLE ? "stable" : "pending", (u16_t)i));
219 /* clean up entries that have just been expired */
220 etharp_free_entry(i);
221 } else if (arp_table[i].state == ETHARP_STATE_STABLE_REREQUESTING_1) {
222 /* Don't send more than one request every 2 seconds. */
223 arp_table[i].state = ETHARP_STATE_STABLE_REREQUESTING_2;
224 } else if (arp_table[i].state == ETHARP_STATE_STABLE_REREQUESTING_2) {
225 /* Reset state to stable, so that the next transmitted packet will
226 re-send an ARP request. */
227 arp_table[i].state = ETHARP_STATE_STABLE;
228 } else if (arp_table[i].state == ETHARP_STATE_PENDING) {
229 /* still pending, resend an ARP query */
230 etharp_request(arp_table[i].netif, &arp_table[i].ipaddr);
231 }
232 }
233 }
234 }
235
257 static s8_t
258 etharp_find_entry(const ip4_addr_t *ipaddr, u8_t flags, struct netif* netif)
259 {
260 s8_t old_pending = ARP_TABLE_SIZE, old_stable = ARP_TABLE_SIZE;
261 s8_t empty = ARP_TABLE_SIZE;
262 u8_t i = 0;
263 /* oldest entry with packets on queue */
264 s8_t old_queue = ARP_TABLE_SIZE;
265 /* its age */
266 u16_t age_queue = 0, age_pending = 0, age_stable = 0;
267
268 LWIP_UNUSED_ARG(netif);
269
276 /* a) in a single search sweep, do all of this
277 * 1) remember the first empty entry (if any)
278 * 2) remember the oldest stable entry (if any)
279 * 3) remember the oldest pending entry without queued packets (if any)
280 * 4) remember the oldest pending entry with queued packets (if any)
281 * 5) search for a matching IP entry, either pending or stable
282 * until 5 matches, or all entries are searched for.
283 */
284
285 for (i = 0; i < ARP_TABLE_SIZE; ++i) {
286 u8_t state = arp_table[i].state;
287 /* no empty entry found yet and now we do find one? */
288 if ((empty == ARP_TABLE_SIZE) && (state == ETHARP_STATE_EMPTY)) {
289 LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_find_entry: found empty entry %"U16_F"\n", (u16_t)i));
290 /* remember first empty entry */
291 empty = i;
292 } else if (state != ETHARP_STATE_EMPTY) {
293 LWIP_ASSERT("state == ETHARP_STATE_PENDING || state >= ETHARP_STATE_STABLE",
294 state == ETHARP_STATE_PENDING || state >= ETHARP_STATE_STABLE);
295 /* if given, does IP address match IP address in ARP entry? */
296 if (ipaddr && ip4_addr_cmp(ipaddr, &arp_table[i].ipaddr)
297 #if ETHARP_TABLE_MATCH_NETIF
298 && ((netif == NULL) || (netif == arp_table[i].netif))
299 #endif /* ETHARP_TABLE_MATCH_NETIF */
300 ) {
301 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_find_entry: found matching entry %"U16_F"\n", (u16_t)i));
302 /* found exact IP address match, simply bail out */
303 return i;
304 }
305 /* pending entry? */
306 if (state == ETHARP_STATE_PENDING) {
307 /* pending with queued packets? */
308 if (arp_table[i].q != NULL) {
309 if (arp_table[i].ctime >= age_queue) {
310 old_queue = i;
311 age_queue = arp_table[i].ctime;
312 }
313 } else
314 /* pending without queued packets? */
315 {
316 if (arp_table[i].ctime >= age_pending) {
317 old_pending = i;
318 age_pending = arp_table[i].ctime;
319 }
320 }
321 /* stable entry? */
322 } else if (state >= ETHARP_STATE_STABLE) {
323 #if ETHARP_SUPPORT_STATIC_ENTRIES
324 /* don't record old_stable for static entries since they never expire */
325 if (state < ETHARP_STATE_STATIC)
326 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
327 {
328 /* remember entry with oldest stable entry in oldest, its age in maxtime */
329 if (arp_table[i].ctime >= age_stable) {
330 old_stable = i;
331 age_stable = arp_table[i].ctime;
332 }
333 }
334 }
335 }
336 }
337 /* { we have no match } => try to create a new entry */
338
339 /* don't create new entry, only search? */
340 if (((flags & ETHARP_FLAG_FIND_ONLY) != 0) ||
341 /* or no empty entry found and not allowed to recycle? */
342 ((empty == ARP_TABLE_SIZE) && ((flags & ETHARP_FLAG_TRY_HARD) == 0))) {
343 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_find_entry: no empty entry found and not allowed to recycle\n"));
344 return (s8_t)ERR_MEM;
345 }
346
347 /* b) choose the least destructive entry to recycle:
348 * 1) empty entry
349 * 2) oldest stable entry
350 * 3) oldest pending entry without queued packets
351 * 4) oldest pending entry with queued packets
352 *
353 * { ETHARP_FLAG_TRY_HARD is set at this point }
354 */
355
356 /* 1) empty entry available? */
357 if (empty < ARP_TABLE_SIZE) {
358 i = empty;
359 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_find_entry: selecting empty entry %"U16_F"\n", (u16_t)i));
360 } else {
361 /* 2) found recyclable stable entry? */
362 if (old_stable < ARP_TABLE_SIZE) {
363 /* recycle oldest stable*/
364 i = old_stable;
365 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_find_entry: selecting oldest stable entry %"U16_F"\n", (u16_t)i));
366 /* no queued packets should exist on stable entries */
367 LWIP_ASSERT("arp_table[i].q == NULL", arp_table[i].q == NULL);
368 /* 3) found recyclable pending entry without queued packets? */
369 } else if (old_pending < ARP_TABLE_SIZE) {
370 /* recycle oldest pending */
371 i = old_pending;
372 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_find_entry: selecting oldest pending entry %"U16_F" (without queue)\n", (u16_t)i));
373 /* 4) found recyclable pending entry with queued packets? */
374 } else if (old_queue < ARP_TABLE_SIZE) {
375 /* recycle oldest pending (queued packets are free in etharp_free_entry) */
376 i = old_queue;
377 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_find_entry: selecting oldest pending entry %"U16_F", freeing packet queue %p\n", (u16_t)i, (void *)(arp_table[i].q)));
378 /* no empty or recyclable entries found */
379 } else {
380 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_find_entry: no empty or recyclable entries found\n"));
381 return (s8_t)ERR_MEM;
382 }
383
384 /* { empty or recyclable entry found } */
385 LWIP_ASSERT("i < ARP_TABLE_SIZE", i < ARP_TABLE_SIZE);
386 etharp_free_entry(i);
387 }
388
389 LWIP_ASSERT("i < ARP_TABLE_SIZE", i < ARP_TABLE_SIZE);
390 LWIP_ASSERT("arp_table[i].state == ETHARP_STATE_EMPTY",
391 arp_table[i].state == ETHARP_STATE_EMPTY);
392
393 /* IP address given? */
394 if (ipaddr != NULL) {
395 /* set IP address */
396 ip4_addr_copy(arp_table[i].ipaddr, *ipaddr);
397 }
398 arp_table[i].ctime = 0;
399 #if ETHARP_TABLE_MATCH_NETIF
400 arp_table[i].netif = netif;
401 #endif /* ETHARP_TABLE_MATCH_NETIF*/
402 return (err_t)i;
403 }
404
423 static err_t
424 etharp_update_arp_entry(struct netif *netif, const ip4_addr_t *ipaddr, struct eth_addr *ethaddr, u8_t flags)
425 {
426 s8_t i;
427 LWIP_ASSERT("netif->hwaddr_len == ETH_HWADDR_LEN", netif->hwaddr_len == ETH_HWADDR_LEN);
428 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_update_arp_entry: %"U16_F".%"U16_F".%"U16_F".%"U16_F" - %02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F"\n",
429 ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr),
430 (u16_t)ethaddr->addr[0], (u16_t)ethaddr->addr[1], (u16_t)ethaddr->addr[2],
431 (u16_t)ethaddr->addr[3], (u16_t)ethaddr->addr[4], (u16_t)ethaddr->addr[5]));
432 /* non-unicast address? */
433 if (ip4_addr_isany(ipaddr) ||
434 ip4_addr_isbroadcast(ipaddr, netif) ||
435 ip4_addr_ismulticast(ipaddr)) {
436 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_update_arp_entry: will not add non-unicast IP address to ARP cache\n"));
437 return ERR_ARG;
438 }
439 /* find or create ARP entry */
440 i = etharp_find_entry(ipaddr, flags, netif);
441 /* bail out if no entry could be found */
442 if (i < 0) {
443 return (err_t)i;
444 }
445
446 #if ETHARP_SUPPORT_STATIC_ENTRIES
447 if (flags & ETHARP_FLAG_STATIC_ENTRY) {
448 /* record static type */
449 arp_table[i].state = ETHARP_STATE_STATIC;
450 } else if (arp_table[i].state == ETHARP_STATE_STATIC) {
451 /* found entry is a static type, don't overwrite it */
452 return ERR_VAL;
453 } else
454 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
455 {
456 /* mark it stable */
457 arp_table[i].state = ETHARP_STATE_STABLE;
458 }
459
460 /* record network interface */
461 arp_table[i].netif = netif;
462 /* insert in SNMP ARP index tree */
463 mib2_add_arp_entry(netif, &arp_table[i].ipaddr);
464
465 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_update_arp_entry: updating stable entry %"S16_F"\n", (s16_t)i));
466 /* update address */
467 ETHADDR32_COPY(&arp_table[i].ethaddr, ethaddr);
468 /* reset time stamp */
469 arp_table[i].ctime = 0;
470 /* this is where we will send out queued packets! */
471 #if ARP_QUEUEING
472 while (arp_table[i].q != NULL) {
473 struct pbuf *p;
474 /* remember remainder of queue */
475 struct etharp_q_entry *q = arp_table[i].q;
476 /* pop first item off the queue */
477 arp_table[i].q = q->next;
478 /* get the packet pointer */
479 p = q->p;
480 /* now queue entry can be freed */
481 memp_free(MEMP_ARP_QUEUE, q);
482 #else /* ARP_QUEUEING */
483 if (arp_table[i].q != NULL) {
484 struct pbuf *p = arp_table[i].q;
485 arp_table[i].q = NULL;
486 #endif /* ARP_QUEUEING */
487 /* send the queued IP packet */
488 ethernet_output(netif, p, (struct eth_addr*)(netif->hwaddr), ethaddr, ETHTYPE_IP);
489 /* free the queued IP packet */
490 pbuf_free(p);
491 }
492 return ERR_OK;
493 }
494
495 #if ETHARP_SUPPORT_STATIC_ENTRIES
496
504 err_t
505 etharp_add_static_entry(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr)
506 {
507 struct netif *netif;
508 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_add_static_entry: %"U16_F".%"U16_F".%"U16_F".%"U16_F" - %02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F":%02"X16_F"\n",
509 ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr),
510 (u16_t)ethaddr->addr[0], (u16_t)ethaddr->addr[1], (u16_t)ethaddr->addr[2],
511 (u16_t)ethaddr->addr[3], (u16_t)ethaddr->addr[4], (u16_t)ethaddr->addr[5]));
512
513 netif = ip4_route(ipaddr);
514 if (netif == NULL) {
515 return ERR_RTE;
516 }
517
518 return etharp_update_arp_entry(netif, ipaddr, ethaddr, ETHARP_FLAG_TRY_HARD | ETHARP_FLAG_STATIC_ENTRY);
519 }
520
529 err_t
530 etharp_remove_static_entry(const ip4_addr_t *ipaddr)
531 {
532 s8_t i;
533 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_remove_static_entry: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
534 ip4_addr1_16(ipaddr), ip4_addr2_16(ipaddr), ip4_addr3_16(ipaddr), ip4_addr4_16(ipaddr)));
535
536 /* find or create ARP entry */
537 i = etharp_find_entry(ipaddr, ETHARP_FLAG_FIND_ONLY, NULL);
538 /* bail out if no entry could be found */
539 if (i < 0) {
540 return (err_t)i;
541 }
542
543 if (arp_table[i].state != ETHARP_STATE_STATIC) {
544 /* entry wasn't a static entry, cannot remove it */
545 return ERR_ARG;
546 }
547 /* entry found, free it */
548 etharp_free_entry(i);
549 return ERR_OK;
550 }
551 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
552
558 void
559 etharp_cleanup_netif(struct netif *netif)
560 {
561 u8_t i;
562
563 for (i = 0; i < ARP_TABLE_SIZE; ++i) {
564 u8_t state = arp_table[i].state;
565 if ((state != ETHARP_STATE_EMPTY) && (arp_table[i].netif == netif)) {
566 etharp_free_entry(i);
567 }
568 }
569 }
570
582 s8_t
583 etharp_find_addr(struct netif *netif, const ip4_addr_t *ipaddr,
584 struct eth_addr **eth_ret, const ip4_addr_t **ip_ret)
585 {
586 s8_t i;
587
588 LWIP_ASSERT("eth_ret != NULL && ip_ret != NULL",
589 eth_ret != NULL && ip_ret != NULL);
590
591 LWIP_UNUSED_ARG(netif);
592
593 i = etharp_find_entry(ipaddr, ETHARP_FLAG_FIND_ONLY, netif);
594 if ((i >= 0) && (arp_table[i].state >= ETHARP_STATE_STABLE)) {
595 *eth_ret = &arp_table[i].ethaddr;
596 *ip_ret = &arp_table[i].ipaddr;
597 return i;
598 }
599 return -1;
600 }
601
611 u8_t
612 etharp_get_entry(u8_t i, ip4_addr_t **ipaddr, struct netif **netif, struct eth_addr **eth_ret)
613 {
614 LWIP_ASSERT("ipaddr != NULL", ipaddr != NULL);
615 LWIP_ASSERT("netif != NULL", netif != NULL);
616 LWIP_ASSERT("eth_ret != NULL", eth_ret != NULL);
617
618 if((i < ARP_TABLE_SIZE) && (arp_table[i].state >= ETHARP_STATE_STABLE)) {
619 *ipaddr = &arp_table[i].ipaddr;
620 *netif = arp_table[i].netif;
621 *eth_ret = &arp_table[i].ethaddr;
622 return 1;
623 } else {
624 return 0;
625 }
626 }
627
640 void
641 etharp_input(struct pbuf *p, struct netif *netif)
642 {
643 struct etharp_hdr *hdr;
644 /* these are aligned properly, whereas the ARP header fields might not be */
645 ip4_addr_t sipaddr, dipaddr;
646 u8_t for_us;
647
648 LWIP_ERROR("netif != NULL", (netif != NULL), return;);
649
650 hdr = (struct etharp_hdr *)p->payload;
651
652 /* RFC 826 "Packet Reception": */
653 if ((hdr->hwtype != PP_HTONS(HWTYPE_ETHERNET)) ||
654 (hdr->hwlen != ETH_HWADDR_LEN) ||
655 (hdr->protolen != sizeof(ip4_addr_t)) ||
656 (hdr->proto != PP_HTONS(ETHTYPE_IP))) {
657 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
658 ("etharp_input: packet dropped, wrong hw type, hwlen, proto, protolen or ethernet type (%"U16_F"/%"U16_F"/%"U16_F"/%"U16_F")\n",
659 hdr->hwtype, (u16_t)hdr->hwlen, hdr->proto, (u16_t)hdr->protolen));
660 ETHARP_STATS_INC(etharp.proterr);
661 ETHARP_STATS_INC(etharp.drop);
662 pbuf_free(p);
663 return;
664 }
665 ETHARP_STATS_INC(etharp.recv);
666
667 #if LWIP_AUTOIP
668 /* We have to check if a host already has configured our random
669 * created link local address and continuously check if there is
670 * a host with this IP-address so we can detect collisions */
671 autoip_arp_reply(netif, hdr);
672 #endif /* LWIP_AUTOIP */
673
674 /* Copy struct ip4_addr2 to aligned ip4_addr, to support compilers without
675 * structure packing (not using structure copy which breaks strict-aliasing rules). */
676 IPADDR2_COPY(&sipaddr, &hdr->sipaddr);
677 IPADDR2_COPY(&dipaddr, &hdr->dipaddr);
678
679 /* this interface is not configured? */
680 if (ip4_addr_isany_val(*netif_ip4_addr(netif))) {
681 for_us = 0;
682 } else {
683 /* ARP packet directed to us? */
684 for_us = (u8_t)ip4_addr_cmp(&dipaddr, netif_ip4_addr(netif));
685 }
686
687 /* ARP message directed to us?
688 -> add IP address in ARP cache; assume requester wants to talk to us,
689 can result in directly sending the queued packets for this host.
690 ARP message not directed to us?
691 -> update the source IP address in the cache, if present */
692 etharp_update_arp_entry(netif, &sipaddr, &(hdr->shwaddr),
693 for_us ? ETHARP_FLAG_TRY_HARD : ETHARP_FLAG_FIND_ONLY);
694
695 /* now act on the message itself */
696 switch (hdr->opcode) {
697 /* ARP request? */
698 case PP_HTONS(ARP_REQUEST):
699 /* ARP request. If it asked for our address, we send out a
700 * reply. In any case, we time-stamp any existing ARP entry,
701 * and possibly send out an IP packet that was queued on it. */
702
703 LWIP_DEBUGF (ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: incoming ARP request\n"));
704 /* ARP request for our address? */
705 if (for_us) {
706 /* send ARP response */
707 etharp_raw(netif,
708 (struct eth_addr *)netif->hwaddr, &hdr->shwaddr,
709 (struct eth_addr *)netif->hwaddr, netif_ip4_addr(netif),
710 &hdr->shwaddr, &sipaddr,
711 ARP_REPLY);
712 /* we are not configured? */
713 } else if (ip4_addr_isany_val(*netif_ip4_addr(netif))) {
714 /* { for_us == 0 and netif->ip_addr.addr == 0 } */
715 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: we are unconfigured, ARP request ignored.\n"));
716 /* request was not directed to us */
717 } else {
718 /* { for_us == 0 and netif->ip_addr.addr != 0 } */
719 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: ARP request was not for us.\n"));
720 }
721 break;
722 case PP_HTONS(ARP_REPLY):
723 /* ARP reply. We already updated the ARP cache earlier. */
724 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: incoming ARP reply\n"));
725 #if (LWIP_DHCP && DHCP_DOES_ARP_CHECK)
726 /* DHCP wants to know about ARP replies from any host with an
727 * IP address also offered to us by the DHCP server. We do not
728 * want to take a duplicate IP address on a single network.
729 * @todo How should we handle redundant (fail-over) interfaces? */
730 dhcp_arp_reply(netif, &sipaddr);
731 #endif /* (LWIP_DHCP && DHCP_DOES_ARP_CHECK) */
732 break;
733 default:
734 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_input: ARP unknown opcode type %"S16_F"\n", lwip_htons(hdr->opcode)));
735 ETHARP_STATS_INC(etharp.err);
736 break;
737 }
738 /* free ARP packet */
739 pbuf_free(p);
740 }
741
745 static err_t
746 etharp_output_to_arp_index(struct netif *netif, struct pbuf *q, u8_t arp_idx)
747 {
748 LWIP_ASSERT("arp_table[arp_idx].state >= ETHARP_STATE_STABLE",
749 arp_table[arp_idx].state >= ETHARP_STATE_STABLE);
750 /* if arp table entry is about to expire: re-request it,
751 but only if its state is ETHARP_STATE_STABLE to prevent flooding the
752 network with ARP requests if this address is used frequently. */
753 if (arp_table[arp_idx].state == ETHARP_STATE_STABLE) {
754 if (arp_table[arp_idx].ctime >= ARP_AGE_REREQUEST_USED_BROADCAST) {
755 /* issue a standard request using broadcast */
756 if (etharp_request(netif, &arp_table[arp_idx].ipaddr) == ERR_OK) {
757 arp_table[arp_idx].state = ETHARP_STATE_STABLE_REREQUESTING_1;
758 }
759 } else if (arp_table[arp_idx].ctime >= ARP_AGE_REREQUEST_USED_UNICAST) {
760 /* issue a unicast request (for 15 seconds) to prevent unnecessary broadcast */
761 if (etharp_request_dst(netif, &arp_table[arp_idx].ipaddr, &arp_table[arp_idx].ethaddr) == ERR_OK) {
762 arp_table[arp_idx].state = ETHARP_STATE_STABLE_REREQUESTING_1;
763 }
764 }
765 }
766
767 return ethernet_output(netif, q, (struct eth_addr*)(netif->hwaddr), &arp_table[arp_idx].ethaddr, ETHTYPE_IP);
768 }
769
788 err_t
789 etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr)
790 {
791 const struct eth_addr *dest;
792 struct eth_addr mcastaddr;
793 const ip4_addr_t *dst_addr = ipaddr;
794
795 LWIP_ASSERT("netif != NULL", netif != NULL);
796 LWIP_ASSERT("q != NULL", q != NULL);
797 LWIP_ASSERT("ipaddr != NULL", ipaddr != NULL);
798
799 /* Determine on destination hardware address. Broadcasts and multicasts
800 * are special, other IP addresses are looked up in the ARP table. */
801
802 /* broadcast destination IP address? */
803 if (ip4_addr_isbroadcast(ipaddr, netif)) {
804 /* broadcast on Ethernet also */
805 dest = (const struct eth_addr *)&ethbroadcast;
806 /* multicast destination IP address? */
807 } else if (ip4_addr_ismulticast(ipaddr)) {
808 /* Hash IP multicast address to MAC address.*/
809 mcastaddr.addr[0] = LL_IP4_MULTICAST_ADDR_0;
810 mcastaddr.addr[1] = LL_IP4_MULTICAST_ADDR_1;
811 mcastaddr.addr[2] = LL_IP4_MULTICAST_ADDR_2;
812 mcastaddr.addr[3] = ip4_addr2(ipaddr) & 0x7f;
813 mcastaddr.addr[4] = ip4_addr3(ipaddr);
814 mcastaddr.addr[5] = ip4_addr4(ipaddr);
815 /* destination Ethernet address is multicast */
816 dest = &mcastaddr;
817 /* unicast destination IP address? */
818 } else {
819 s8_t i;
820 /* outside local network? if so, this can neither be a global broadcast nor
821 a subnet broadcast. */
822 if (!ip4_addr_netcmp(ipaddr, netif_ip4_addr(netif), netif_ip4_netmask(netif)) &&
823 !ip4_addr_islinklocal(ipaddr)) {
824 #if LWIP_AUTOIP
825 struct ip_hdr *iphdr = LWIP_ALIGNMENT_CAST(struct ip_hdr*, q->payload);
826 /* According to RFC 3297, chapter 2.6.2 (Forwarding Rules), a packet with
827 a link-local source address must always be "directly to its destination
828 on the same physical link. The host MUST NOT send the packet to any
829 router for forwarding". */
830 if (!ip4_addr_islinklocal(&iphdr->src))
831 #endif /* LWIP_AUTOIP */
832 {
833 #ifdef LWIP_HOOK_ETHARP_GET_GW
834 /* For advanced routing, a single default gateway might not be enough, so get
835 the IP address of the gateway to handle the current destination address. */
836 dst_addr = LWIP_HOOK_ETHARP_GET_GW(netif, ipaddr);
837 if (dst_addr == NULL)
838 #endif /* LWIP_HOOK_ETHARP_GET_GW */
839 {
840 /* interface has default gateway? */
841 if (!ip4_addr_isany_val(*netif_ip4_gw(netif))) {
842 /* send to hardware address of default gateway IP address */
843 dst_addr = netif_ip4_gw(netif);
844 /* no default gateway available */
845 } else {
846 /* no route to destination error (default gateway missing) */
847 return ERR_RTE;
848 }
849 }
850 }
851 }
852 #if LWIP_NETIF_HWADDRHINT
853 if (netif->addr_hint != NULL) {
854 /* per-pcb cached entry was given */
855 u8_t etharp_cached_entry = *(netif->addr_hint);
856 if (etharp_cached_entry < ARP_TABLE_SIZE) {
857 #endif /* LWIP_NETIF_HWADDRHINT */
858 if ((arp_table[etharp_cached_entry].state >= ETHARP_STATE_STABLE) &&
859 #if ETHARP_TABLE_MATCH_NETIF
860 (arp_table[etharp_cached_entry].netif == netif) &&
861 #endif
862 (ip4_addr_cmp(dst_addr, &arp_table[etharp_cached_entry].ipaddr))) {
863 /* the per-pcb-cached entry is stable and the right one! */
864 ETHARP_STATS_INC(etharp.cachehit);
865 return etharp_output_to_arp_index(netif, q, etharp_cached_entry);
866 }
867 #if LWIP_NETIF_HWADDRHINT
868 }
869 }
870 #endif /* LWIP_NETIF_HWADDRHINT */
871
872 /* find stable entry: do this here since this is a critical path for
873 throughput and etharp_find_entry() is kind of slow */
874 for (i = 0; i < ARP_TABLE_SIZE; i++) {
875 if ((arp_table[i].state >= ETHARP_STATE_STABLE) &&
876 #if ETHARP_TABLE_MATCH_NETIF
877 (arp_table[i].netif == netif) &&
878 #endif
879 (ip4_addr_cmp(dst_addr, &arp_table[i].ipaddr))) {
880 /* found an existing, stable entry */
881 ETHARP_SET_HINT(netif, i);
882 return etharp_output_to_arp_index(netif, q, i);
883 }
884 }
885 /* no stable entry found, use the (slower) query function:
886 queue on destination Ethernet address belonging to ipaddr */
887 return etharp_query(netif, dst_addr, q);
888 }
889
890 /* continuation for multicast/broadcast destinations */
891 /* obtain source Ethernet address of the given interface */
892 /* send packet directly on the link */
893 return ethernet_output(netif, q, (struct eth_addr*)(netif->hwaddr), dest, ETHTYPE_IP);
894 }
895
929 err_t
930 etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q)
931 {
932 struct eth_addr * srcaddr = (struct eth_addr *)netif->hwaddr;
933 err_t result = ERR_MEM;
934 int is_new_entry = 0;
935 s8_t i; /* ARP entry index */
936
937 /* non-unicast address? */
938 if (ip4_addr_isbroadcast(ipaddr, netif) ||
939 ip4_addr_ismulticast(ipaddr) ||
940 ip4_addr_isany(ipaddr)) {
941 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: will not add non-unicast IP address to ARP cache\n"));
942 return ERR_ARG;
943 }
944
945 /* find entry in ARP cache, ask to create entry if queueing packet */
946 i = etharp_find_entry(ipaddr, ETHARP_FLAG_TRY_HARD, netif);
947
948 /* could not find or create entry? */
949 if (i < 0) {
950 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: could not create ARP entry\n"));
951 if (q) {
952 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: packet dropped\n"));
953 ETHARP_STATS_INC(etharp.memerr);
954 }
955 return (err_t)i;
956 }
957
958 /* mark a fresh entry as pending (we just sent a request) */
959 if (arp_table[i].state == ETHARP_STATE_EMPTY) {
960 is_new_entry = 1;
961 arp_table[i].state = ETHARP_STATE_PENDING;
962 /* record network interface for re-sending arp request in etharp_tmr */
963 arp_table[i].netif = netif;
964 }
965
966 /* { i is either a STABLE or (new or existing) PENDING entry } */
967 LWIP_ASSERT("arp_table[i].state == PENDING or STABLE",
968 ((arp_table[i].state == ETHARP_STATE_PENDING) ||
969 (arp_table[i].state >= ETHARP_STATE_STABLE)));
970
971 /* do we have a new entry? or an implicit query request? */
972 if (is_new_entry || (q == NULL)) {
973 /* try to resolve it; send out ARP request */
974 result = etharp_request(netif, ipaddr);
975 if (result != ERR_OK) {
976 /* ARP request couldn't be sent */
977 /* We don't re-send arp request in etharp_tmr, but we still queue packets,
978 since this failure could be temporary, and the next packet calling
979 etharp_query again could lead to sending the queued packets. */
980 }
981 if (q == NULL) {
982 return result;
983 }
984 }
985
986 /* packet given? */
987 LWIP_ASSERT("q != NULL", q != NULL);
988 /* stable entry? */
989 if (arp_table[i].state >= ETHARP_STATE_STABLE) {
990 /* we have a valid IP->Ethernet address mapping */
991 ETHARP_SET_HINT(netif, i);
992 /* send the packet */
993 result = ethernet_output(netif, q, srcaddr, &(arp_table[i].ethaddr), ETHTYPE_IP);
994 /* pending entry? (either just created or already pending */
995 } else if (arp_table[i].state == ETHARP_STATE_PENDING) {
996 /* entry is still pending, queue the given packet 'q' */
997 struct pbuf *p;
998 int copy_needed = 0;
999 /* IF q includes a PBUF_REF, PBUF_POOL or PBUF_RAM, we have no choice but
1000 * to copy the whole queue into a new PBUF_RAM (see bug #11400)
1001 * PBUF_ROMs can be left as they are, since ROM must not get changed. */
1002 p = q;
1003 while (p) {
1004 LWIP_ASSERT("no packet queues allowed!", (p->len != p->tot_len) || (p->next == 0));
1005 if (p->type != PBUF_ROM) {
1006 copy_needed = 1;
1007 break;
1008 }
1009 p = p->next;
1010 }
1011 if (copy_needed) {
1012 /* copy the whole packet into new pbufs */
1013 p = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM);
1014 if (p != NULL) {
1015 if (pbuf_copy(p, q) != ERR_OK) {
1016 pbuf_free(p);
1017 p = NULL;
1018 }
1019 }
1020 } else {
1021 /* referencing the old pbuf is enough */
1022 p = q;
1023 pbuf_ref(p);
1024 }
1025 /* packet could be taken over? */
1026 if (p != NULL) {
1027 /* queue packet ... */
1028 #if ARP_QUEUEING
1029 struct etharp_q_entry *new_entry;
1030 /* allocate a new arp queue entry */
1031 new_entry = (struct etharp_q_entry *)memp_malloc(MEMP_ARP_QUEUE);
1032 if (new_entry != NULL) {
1033 unsigned int qlen = 0;
1034 new_entry->next = 0;
1035 new_entry->p = p;
1036 if (arp_table[i].q != NULL) {
1037 /* queue was already existent, append the new entry to the end */
1038 struct etharp_q_entry *r;
1039 r = arp_table[i].q;
1040 qlen++;
1041 while (r->next != NULL) {
1042 r = r->next;
1043 qlen++;
1044 }
1045 r->next = new_entry;
1046 } else {
1047 /* queue did not exist, first item in queue */
1048 arp_table[i].q = new_entry;
1049 }
1050 #if ARP_QUEUE_LEN
1051 if (qlen >= ARP_QUEUE_LEN) {
1052 struct etharp_q_entry *old;
1053 old = arp_table[i].q;
1054 arp_table[i].q = arp_table[i].q->next;
1055 pbuf_free(old->p);
1056 memp_free(MEMP_ARP_QUEUE, old);
1057 }
1058 #endif
1059 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: queued packet %p on ARP entry %"S16_F"\n", (void *)q, (s16_t)i));
1060 result = ERR_OK;
1061 } else {
1062 /* the pool MEMP_ARP_QUEUE is empty */
1063 pbuf_free(p);
1064 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: could not queue a copy of PBUF_REF packet %p (out of memory)\n", (void *)q));
1065 result = ERR_MEM;
1066 }
1067 #else /* ARP_QUEUEING */
1068 /* always queue one packet per ARP request only, freeing a previously queued packet */
1069 if (arp_table[i].q != NULL) {
1070 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: dropped previously queued packet %p for ARP entry %"S16_F"\n", (void *)q, (s16_t)i));
1071 pbuf_free(arp_table[i].q);
1072 }
1073 arp_table[i].q = p;
1074 result = ERR_OK;
1075 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: queued packet %p on ARP entry %"S16_F"\n", (void *)q, (s16_t)i));
1076 #endif /* ARP_QUEUEING */
1077 } else {
1078 ETHARP_STATS_INC(etharp.memerr);
1079 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: could not queue a copy of PBUF_REF packet %p (out of memory)\n", (void *)q));
1080 result = ERR_MEM;
1081 }
1082 }
1083 return result;
1084 }
1085
1101 static err_t
1102 etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
1103 const struct eth_addr *ethdst_addr,
1104 const struct eth_addr *hwsrc_addr, const ip4_addr_t *ipsrc_addr,
1105 const struct eth_addr *hwdst_addr, const ip4_addr_t *ipdst_addr,
1106 const u16_t opcode)
1107 {
1108 struct pbuf *p;
1109 err_t result = ERR_OK;
1110 struct etharp_hdr *hdr;
1111
1112 LWIP_ASSERT("netif != NULL", netif != NULL);
1113
1114 /* allocate a pbuf for the outgoing ARP request packet */
1115 p = pbuf_alloc(PBUF_LINK, SIZEOF_ETHARP_HDR, PBUF_RAM);
1116 /* could allocate a pbuf for an ARP request? */
1117 if (p == NULL) {
1118 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS,
1119 ("etharp_raw: could not allocate pbuf for ARP request.\n"));
1120 ETHARP_STATS_INC(etharp.memerr);
1121 return ERR_MEM;
1122 }
1123 LWIP_ASSERT("check that first pbuf can hold struct etharp_hdr",
1124 (p->len >= SIZEOF_ETHARP_HDR));
1125
1126 hdr = (struct etharp_hdr *)p->payload;
1127 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_raw: sending raw ARP packet.\n"));
1128 hdr->opcode = lwip_htons(opcode);
1129
1130 LWIP_ASSERT("netif->hwaddr_len must be the same as ETH_HWADDR_LEN for etharp!",
1131 (netif->hwaddr_len == ETH_HWADDR_LEN));
1132
1133 /* Write the ARP MAC-Addresses */
1134 ETHADDR16_COPY(&hdr->shwaddr, hwsrc_addr);
1135 ETHADDR16_COPY(&hdr->dhwaddr, hwdst_addr);
1136 /* Copy struct ip4_addr2 to aligned ip4_addr, to support compilers without
1137 * structure packing. */
1138 IPADDR2_COPY(&hdr->sipaddr, ipsrc_addr);
1139 IPADDR2_COPY(&hdr->dipaddr, ipdst_addr);
1140
1141 hdr->hwtype = PP_HTONS(HWTYPE_ETHERNET);
1142 hdr->proto = PP_HTONS(ETHTYPE_IP);
1143 /* set hwlen and protolen */
1144 hdr->hwlen = ETH_HWADDR_LEN;
1145 hdr->protolen = sizeof(ip4_addr_t);
1146
1147 /* send ARP query */
1148 #if LWIP_AUTOIP
1149 /* If we are using Link-Local, all ARP packets that contain a Link-Local
1150 * 'sender IP address' MUST be sent using link-layer broadcast instead of
1151 * link-layer unicast. (See RFC3927 Section 2.5, last paragraph) */
1152 if(ip4_addr_islinklocal(ipsrc_addr)) {
1153 ethernet_output(netif, p, ethsrc_addr, &ethbroadcast, ETHTYPE_ARP);
1154 } else
1155 #endif /* LWIP_AUTOIP */
1156 {
1157 ethernet_output(netif, p, ethsrc_addr, ethdst_addr, ETHTYPE_ARP);
1158 }
1159
1160 ETHARP_STATS_INC(etharp.xmit);
1161 /* free ARP query packet */
1162 pbuf_free(p);
1163 p = NULL;
1164 /* could not allocate pbuf for ARP request */
1165
1166 return result;
1167 }
1168
1181 static err_t
1182 etharp_request_dst(struct netif *netif, const ip4_addr_t *ipaddr, const struct eth_addr* hw_dst_addr)
1183 {
1184 return etharp_raw(netif, (struct eth_addr *)netif->hwaddr, hw_dst_addr,
1185 (struct eth_addr *)netif->hwaddr, netif_ip4_addr(netif), &ethzero,
1186 ipaddr, ARP_REQUEST);
1187 }
1188
1198 err_t
1199 etharp_request(struct netif *netif, const ip4_addr_t *ipaddr)
1200 {
1201 LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_request: sending ARP request.\n"));
1202 return etharp_request_dst(netif, ipaddr, &ethbroadcast);
1203 }
1204 #endif /* LWIP_IPV4 && LWIP_ARP */
1205
1206 #endif /* LWIP_ARP || LWIP_ETHERNET */
ARP_MAXAGE
#define ARP_MAXAGE
Definition: lwipopts.h:93
S16_F
#define S16_F
Definition: arch.h:151
opt.h
pbuf::len
u16_t len
Definition: pbuf.h:159
PBUF_LINK
Definition: pbuf.h:85
s16_t
int16_t s16_t
Definition: arch.h:125
LWIP_ASSERT
#define LWIP_ASSERT(message, assertion)
Definition: debug.h:116
PBUF_ROM
Definition: pbuf.h:112
LWIP_ALIGNMENT_CAST
#define LWIP_ALIGNMENT_CAST(target_type, val)
Definition: arch.h:192
u16_t
uint16_t u16_t
Definition: arch.h:124
string.h
etharp_hdr
Definition: etharp.h:57
autoip.h
pbuf::tot_len
u16_t tot_len
Definition: pbuf.h:156
ETHARP_STATS_INC
#define ETHARP_STATS_INC(x)
Definition: stats.h:376
ETHARP_SUPPORT_STATIC_ENTRIES
#define ETHARP_SUPPORT_STATIC_ENTRIES
Definition: lwipopts.h:105
netif::state
void * state
Definition: netif.h:287
pbuf::next
struct pbuf * next
Definition: pbuf.h:144
pbuf_free
u8_t pbuf_free(struct pbuf *p)
Definition: pbuf.c:715
ETHARP_TABLE_MATCH_NETIF
#define ETHARP_TABLE_MATCH_NETIF
Definition: lwipopts.h:107
memp_malloc
void * memp_malloc(memp_t type)
Definition: memp.c:385
LWIP_DBG_TRACE
#define LWIP_DBG_TRACE
Definition: debug.h:83
X16_F
#define X16_F
Definition: arch.h:154
memp_free
void memp_free(memp_t type, void *mem)
Definition: memp.c:469
mib2_remove_arp_entry
#define mib2_remove_arp_entry(ni, ip)
Definition: snmp.h:182
ip_hdr
Definition: ip4.h:71
ETHARP_DEBUG
#define ETHARP_DEBUG
Definition: lwipopts.h:431
snmp.h
stats.h
ERR_MEM
Definition: err.h:65
LWIP_DBG_LEVEL_SERIOUS
#define LWIP_DBG_LEVEL_SERIOUS
Definition: debug.h:57
ARP_REPLY
Definition: etharp.h:84
netif::hwaddr
u8_t hwaddr[6U]
Definition: netif.h:311
LWIP_ERROR
#define LWIP_ERROR(message, expression, handler)
Definition: debug.h:135
LL_IP4_MULTICAST_ADDR_1
#define LL_IP4_MULTICAST_ADDR_1
Definition: ethernet.h:145
pbuf_alloc
struct pbuf * pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type)
Definition: pbuf.c:248
ARP_QUEUE_LEN
#define ARP_QUEUE_LEN
Definition: lwipopts.h:97
u8_t
uint8_t u8_t
Definition: arch.h:122
netif
Definition: netif.h:233
ARP_REQUEST
Definition: etharp.h:83
netif::hwaddr_len
u8_t hwaddr_len
Definition: netif.h:309
mib2_add_arp_entry
#define mib2_add_arp_entry(ni, ip)
Definition: snmp.h:181
pbuf_copy
err_t pbuf_copy(struct pbuf *p_to, const struct pbuf *p_from)
Definition: pbuf.c:949
ERR_ARG
Definition: err.h:96
LWIP_UNUSED_ARG
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:315
ethernet.h
lwip_htons
u16_t lwip_htons(u16_t n)
Definition: def.c:75
ETH_HWADDR_LEN
#define ETH_HWADDR_LEN
Definition: ethernet.h:50
s8_t
int8_t s8_t
Definition: arch.h:123
ETHADDR16_COPY
#define ETHADDR16_COPY(dst, src)
Definition: ethernet.h:161
pbuf_ref
void pbuf_ref(struct pbuf *p)
Definition: pbuf.c:821
PBUF_RAM
Definition: pbuf.h:108
U16_F
#define U16_F
Definition: arch.h:148
dhcp.h
SIZEOF_ETHARP_HDR
#define SIZEOF_ETHARP_HDR
Definition: etharp.h:73
ERR_OK
Definition: err.h:63
ETHADDR32_COPY
#define ETHADDR32_COPY(dst, src)
Definition: ethernet.h:155
err_t
s8_t err_t
Definition: err.h:57
eth_addr
Definition: ethernet.h:58
etharp.h
LL_IP4_MULTICAST_ADDR_2
#define LL_IP4_MULTICAST_ADDR_2
Definition: ethernet.h:146
ETHTYPE_IP
Definition: ethernet.h:110
LWIP_DBG_LEVEL_WARNING
#define LWIP_DBG_LEVEL_WARNING
Definition: debug.h:55
ARP_TABLE_SIZE
#define ARP_TABLE_SIZE
Definition: lwipopts.h:91
LL_IP4_MULTICAST_ADDR_0
#define LL_IP4_MULTICAST_ADDR_0
Definition: ethernet.h:144
pbuf::type
u8_t type
Definition: pbuf.h:162
HWTYPE_ETHERNET
Definition: etharp.h:77
ERR_RTE
Definition: err.h:71
ERR_VAL
Definition: err.h:75
pbuf
Definition: pbuf.h:142
LWIP_DEBUGF
#define LWIP_DEBUGF(debug, message)
Definition: debug.h:164
ETHTYPE_ARP
Definition: ethernet.h:112
pbuf::payload
void * payload
Definition: pbuf.h:147
PP_HTONS
#define PP_HTONS(x)
Definition: def.h:79
NULL
#define NULL
Definition: fat_string.h:17