Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LwIP_raw_API_serverExample tiny-dtls
Core/lwIP/netif/etharp.c@0:0791c1fece8e, 2012-09-18 (annotated)
- Committer:
- RodColeman
- Date:
- Tue Sep 18 14:41:24 2012 +0000
- Revision:
- 0:0791c1fece8e
[mbed] converted /Eth_TCP_Wei_Server/lwip
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| RodColeman | 0:0791c1fece8e | 1 | /** |
| RodColeman | 0:0791c1fece8e | 2 | * @file |
| RodColeman | 0:0791c1fece8e | 3 | * Address Resolution Protocol module for IP over Ethernet |
| RodColeman | 0:0791c1fece8e | 4 | * |
| RodColeman | 0:0791c1fece8e | 5 | * Functionally, ARP is divided into two parts. The first maps an IP address |
| RodColeman | 0:0791c1fece8e | 6 | * to a physical address when sending a packet, and the second part answers |
| RodColeman | 0:0791c1fece8e | 7 | * requests from other machines for our physical address. |
| RodColeman | 0:0791c1fece8e | 8 | * |
| RodColeman | 0:0791c1fece8e | 9 | * This implementation complies with RFC 826 (Ethernet ARP). It supports |
| RodColeman | 0:0791c1fece8e | 10 | * Gratuitious ARP from RFC3220 (IP Mobility Support for IPv4) section 4.6 |
| RodColeman | 0:0791c1fece8e | 11 | * if an interface calls etharp_gratuitous(our_netif) upon address change. |
| RodColeman | 0:0791c1fece8e | 12 | */ |
| RodColeman | 0:0791c1fece8e | 13 | |
| RodColeman | 0:0791c1fece8e | 14 | /* |
| RodColeman | 0:0791c1fece8e | 15 | * Copyright (c) 2001-2003 Swedish Institute of Computer Science. |
| RodColeman | 0:0791c1fece8e | 16 | * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv> |
| RodColeman | 0:0791c1fece8e | 17 | * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands. |
| RodColeman | 0:0791c1fece8e | 18 | * All rights reserved. |
| RodColeman | 0:0791c1fece8e | 19 | * |
| RodColeman | 0:0791c1fece8e | 20 | * Redistribution and use in source and binary forms, with or without modification, |
| RodColeman | 0:0791c1fece8e | 21 | * are permitted provided that the following conditions are met: |
| RodColeman | 0:0791c1fece8e | 22 | * |
| RodColeman | 0:0791c1fece8e | 23 | * 1. Redistributions of source code must retain the above copyright notice, |
| RodColeman | 0:0791c1fece8e | 24 | * this list of conditions and the following disclaimer. |
| RodColeman | 0:0791c1fece8e | 25 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| RodColeman | 0:0791c1fece8e | 26 | * this list of conditions and the following disclaimer in the documentation |
| RodColeman | 0:0791c1fece8e | 27 | * and/or other materials provided with the distribution. |
| RodColeman | 0:0791c1fece8e | 28 | * 3. The name of the author may not be used to endorse or promote products |
| RodColeman | 0:0791c1fece8e | 29 | * derived from this software without specific prior written permission. |
| RodColeman | 0:0791c1fece8e | 30 | * |
| RodColeman | 0:0791c1fece8e | 31 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| RodColeman | 0:0791c1fece8e | 32 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| RodColeman | 0:0791c1fece8e | 33 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
| RodColeman | 0:0791c1fece8e | 34 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| RodColeman | 0:0791c1fece8e | 35 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
| RodColeman | 0:0791c1fece8e | 36 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| RodColeman | 0:0791c1fece8e | 37 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| RodColeman | 0:0791c1fece8e | 38 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| RodColeman | 0:0791c1fece8e | 39 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
| RodColeman | 0:0791c1fece8e | 40 | * OF SUCH DAMAGE. |
| RodColeman | 0:0791c1fece8e | 41 | * |
| RodColeman | 0:0791c1fece8e | 42 | * This file is part of the lwIP TCP/IP stack. |
| RodColeman | 0:0791c1fece8e | 43 | * |
| RodColeman | 0:0791c1fece8e | 44 | */ |
| RodColeman | 0:0791c1fece8e | 45 | |
| RodColeman | 0:0791c1fece8e | 46 | #include "lwip/opt.h" |
| RodColeman | 0:0791c1fece8e | 47 | |
| RodColeman | 0:0791c1fece8e | 48 | #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */ |
| RodColeman | 0:0791c1fece8e | 49 | |
| RodColeman | 0:0791c1fece8e | 50 | #include "lwip/inet.h" |
| RodColeman | 0:0791c1fece8e | 51 | #include "lwip/ip.h" |
| RodColeman | 0:0791c1fece8e | 52 | #include "lwip/stats.h" |
| RodColeman | 0:0791c1fece8e | 53 | #include "lwip/snmp.h" |
| RodColeman | 0:0791c1fece8e | 54 | #include "lwip/dhcp.h" |
| RodColeman | 0:0791c1fece8e | 55 | #include "lwip/autoip.h" |
| RodColeman | 0:0791c1fece8e | 56 | #include "netif/etharp.h" |
| RodColeman | 0:0791c1fece8e | 57 | |
| RodColeman | 0:0791c1fece8e | 58 | #if PPPOE_SUPPORT |
| RodColeman | 0:0791c1fece8e | 59 | #include "netif/ppp_oe.h" |
| RodColeman | 0:0791c1fece8e | 60 | #endif /* PPPOE_SUPPORT */ |
| RodColeman | 0:0791c1fece8e | 61 | |
| RodColeman | 0:0791c1fece8e | 62 | #include <string.h> |
| RodColeman | 0:0791c1fece8e | 63 | |
| RodColeman | 0:0791c1fece8e | 64 | /** the time an ARP entry stays valid after its last update, |
| RodColeman | 0:0791c1fece8e | 65 | * for ARP_TMR_INTERVAL = 5000, this is |
| RodColeman | 0:0791c1fece8e | 66 | * (240 * 5) seconds = 20 minutes. |
| RodColeman | 0:0791c1fece8e | 67 | */ |
| RodColeman | 0:0791c1fece8e | 68 | #define ARP_MAXAGE 240 |
| RodColeman | 0:0791c1fece8e | 69 | /** the time an ARP entry stays pending after first request, |
| RodColeman | 0:0791c1fece8e | 70 | * for ARP_TMR_INTERVAL = 5000, this is |
| RodColeman | 0:0791c1fece8e | 71 | * (2 * 5) seconds = 10 seconds. |
| RodColeman | 0:0791c1fece8e | 72 | * |
| RodColeman | 0:0791c1fece8e | 73 | * @internal Keep this number at least 2, otherwise it might |
| RodColeman | 0:0791c1fece8e | 74 | * run out instantly if the timeout occurs directly after a request. |
| RodColeman | 0:0791c1fece8e | 75 | */ |
| RodColeman | 0:0791c1fece8e | 76 | #define ARP_MAXPENDING 2 |
| RodColeman | 0:0791c1fece8e | 77 | |
| RodColeman | 0:0791c1fece8e | 78 | #define HWTYPE_ETHERNET 1 |
| RodColeman | 0:0791c1fece8e | 79 | |
| RodColeman | 0:0791c1fece8e | 80 | #define ARPH_HWLEN(hdr) (ntohs((hdr)->_hwlen_protolen) >> 8) |
| RodColeman | 0:0791c1fece8e | 81 | #define ARPH_PROTOLEN(hdr) (ntohs((hdr)->_hwlen_protolen) & 0xff) |
| RodColeman | 0:0791c1fece8e | 82 | |
| RodColeman | 0:0791c1fece8e | 83 | #define ARPH_HWLEN_SET(hdr, len) (hdr)->_hwlen_protolen = htons(ARPH_PROTOLEN(hdr) | ((len) << 8)) |
| RodColeman | 0:0791c1fece8e | 84 | #define ARPH_PROTOLEN_SET(hdr, len) (hdr)->_hwlen_protolen = htons((len) | (ARPH_HWLEN(hdr) << 8)) |
| RodColeman | 0:0791c1fece8e | 85 | |
| RodColeman | 0:0791c1fece8e | 86 | enum etharp_state { |
| RodColeman | 0:0791c1fece8e | 87 | ETHARP_STATE_EMPTY = 0, |
| RodColeman | 0:0791c1fece8e | 88 | ETHARP_STATE_PENDING, |
| RodColeman | 0:0791c1fece8e | 89 | ETHARP_STATE_STABLE |
| RodColeman | 0:0791c1fece8e | 90 | }; |
| RodColeman | 0:0791c1fece8e | 91 | |
| RodColeman | 0:0791c1fece8e | 92 | struct etharp_entry { |
| RodColeman | 0:0791c1fece8e | 93 | #if ARP_QUEUEING |
| RodColeman | 0:0791c1fece8e | 94 | /** |
| RodColeman | 0:0791c1fece8e | 95 | * Pointer to queue of pending outgoing packets on this ARP entry. |
| RodColeman | 0:0791c1fece8e | 96 | */ |
| RodColeman | 0:0791c1fece8e | 97 | struct etharp_q_entry *q; |
| RodColeman | 0:0791c1fece8e | 98 | #endif |
| RodColeman | 0:0791c1fece8e | 99 | struct ip_addr ipaddr; |
| RodColeman | 0:0791c1fece8e | 100 | struct eth_addr ethaddr; |
| RodColeman | 0:0791c1fece8e | 101 | enum etharp_state state; |
| RodColeman | 0:0791c1fece8e | 102 | u8_t ctime; |
| RodColeman | 0:0791c1fece8e | 103 | struct netif *netif; |
| RodColeman | 0:0791c1fece8e | 104 | }; |
| RodColeman | 0:0791c1fece8e | 105 | |
| RodColeman | 0:0791c1fece8e | 106 | const struct eth_addr ethbroadcast = {{0xff,0xff,0xff,0xff,0xff,0xff}}; |
| RodColeman | 0:0791c1fece8e | 107 | const struct eth_addr ethzero = {{0,0,0,0,0,0}}; |
| RodColeman | 0:0791c1fece8e | 108 | static struct etharp_entry arp_table[ARP_TABLE_SIZE] MEM_POSITION; |
| RodColeman | 0:0791c1fece8e | 109 | #if !LWIP_NETIF_HWADDRHINT |
| RodColeman | 0:0791c1fece8e | 110 | static u8_t etharp_cached_entry MEM_POSITION; |
| RodColeman | 0:0791c1fece8e | 111 | #endif |
| RodColeman | 0:0791c1fece8e | 112 | |
| RodColeman | 0:0791c1fece8e | 113 | /** |
| RodColeman | 0:0791c1fece8e | 114 | * Try hard to create a new entry - we want the IP address to appear in |
| RodColeman | 0:0791c1fece8e | 115 | * the cache (even if this means removing an active entry or so). */ |
| RodColeman | 0:0791c1fece8e | 116 | #define ETHARP_TRY_HARD 1 |
| RodColeman | 0:0791c1fece8e | 117 | #define ETHARP_FIND_ONLY 2 |
| RodColeman | 0:0791c1fece8e | 118 | |
| RodColeman | 0:0791c1fece8e | 119 | #if LWIP_NETIF_HWADDRHINT |
| RodColeman | 0:0791c1fece8e | 120 | #define NETIF_SET_HINT(netif, hint) if (((netif) != NULL) && ((netif)->addr_hint != NULL)) \ |
| RodColeman | 0:0791c1fece8e | 121 | *((netif)->addr_hint) = (hint); |
| RodColeman | 0:0791c1fece8e | 122 | static s8_t find_entry(struct ip_addr *ipaddr, u8_t flags, struct netif *netif); |
| RodColeman | 0:0791c1fece8e | 123 | #else /* LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 124 | static s8_t find_entry(struct ip_addr *ipaddr, u8_t flags); |
| RodColeman | 0:0791c1fece8e | 125 | #endif /* LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 126 | |
| RodColeman | 0:0791c1fece8e | 127 | static err_t update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags); |
| RodColeman | 0:0791c1fece8e | 128 | |
| RodColeman | 0:0791c1fece8e | 129 | |
| RodColeman | 0:0791c1fece8e | 130 | /* Some checks, instead of etharp_init(): */ |
| RodColeman | 0:0791c1fece8e | 131 | #if (LWIP_ARP && (ARP_TABLE_SIZE > 0x7f)) |
| RodColeman | 0:0791c1fece8e | 132 | #error "If you want to use ARP, ARP_TABLE_SIZE must fit in an s8_t, so, you have to reduce it in your lwipopts.h" |
| RodColeman | 0:0791c1fece8e | 133 | #endif |
| RodColeman | 0:0791c1fece8e | 134 | |
| RodColeman | 0:0791c1fece8e | 135 | |
| RodColeman | 0:0791c1fece8e | 136 | #if ARP_QUEUEING |
| RodColeman | 0:0791c1fece8e | 137 | /** |
| RodColeman | 0:0791c1fece8e | 138 | * Free a complete queue of etharp entries |
| RodColeman | 0:0791c1fece8e | 139 | * |
| RodColeman | 0:0791c1fece8e | 140 | * @param q a qeueue of etharp_q_entry's to free |
| RodColeman | 0:0791c1fece8e | 141 | */ |
| RodColeman | 0:0791c1fece8e | 142 | static void |
| RodColeman | 0:0791c1fece8e | 143 | free_etharp_q(struct etharp_q_entry *q) |
| RodColeman | 0:0791c1fece8e | 144 | { |
| RodColeman | 0:0791c1fece8e | 145 | struct etharp_q_entry *r; |
| RodColeman | 0:0791c1fece8e | 146 | LWIP_ASSERT("q != NULL", q != NULL); |
| RodColeman | 0:0791c1fece8e | 147 | LWIP_ASSERT("q->p != NULL", q->p != NULL); |
| RodColeman | 0:0791c1fece8e | 148 | while (q) { |
| RodColeman | 0:0791c1fece8e | 149 | r = q; |
| RodColeman | 0:0791c1fece8e | 150 | q = q->next; |
| RodColeman | 0:0791c1fece8e | 151 | LWIP_ASSERT("r->p != NULL", (r->p != NULL)); |
| RodColeman | 0:0791c1fece8e | 152 | pbuf_free(r->p); |
| RodColeman | 0:0791c1fece8e | 153 | memp_free(MEMP_ARP_QUEUE, r); |
| RodColeman | 0:0791c1fece8e | 154 | } |
| RodColeman | 0:0791c1fece8e | 155 | } |
| RodColeman | 0:0791c1fece8e | 156 | #endif |
| RodColeman | 0:0791c1fece8e | 157 | |
| RodColeman | 0:0791c1fece8e | 158 | /** |
| RodColeman | 0:0791c1fece8e | 159 | * Clears expired entries in the ARP table. |
| RodColeman | 0:0791c1fece8e | 160 | * |
| RodColeman | 0:0791c1fece8e | 161 | * This function should be called every ETHARP_TMR_INTERVAL microseconds (5 seconds), |
| RodColeman | 0:0791c1fece8e | 162 | * in order to expire entries in the ARP table. |
| RodColeman | 0:0791c1fece8e | 163 | */ |
| RodColeman | 0:0791c1fece8e | 164 | void |
| RodColeman | 0:0791c1fece8e | 165 | etharp_tmr(void) |
| RodColeman | 0:0791c1fece8e | 166 | { |
| RodColeman | 0:0791c1fece8e | 167 | u8_t i; |
| RodColeman | 0:0791c1fece8e | 168 | |
| RodColeman | 0:0791c1fece8e | 169 | LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer\n")); |
| RodColeman | 0:0791c1fece8e | 170 | /* remove expired entries from the ARP table */ |
| RodColeman | 0:0791c1fece8e | 171 | for (i = 0; i < ARP_TABLE_SIZE; ++i) { |
| RodColeman | 0:0791c1fece8e | 172 | arp_table[i].ctime++; |
| RodColeman | 0:0791c1fece8e | 173 | if (((arp_table[i].state == ETHARP_STATE_STABLE) && |
| RodColeman | 0:0791c1fece8e | 174 | (arp_table[i].ctime >= ARP_MAXAGE)) || |
| RodColeman | 0:0791c1fece8e | 175 | ((arp_table[i].state == ETHARP_STATE_PENDING) && |
| RodColeman | 0:0791c1fece8e | 176 | (arp_table[i].ctime >= ARP_MAXPENDING))) { |
| RodColeman | 0:0791c1fece8e | 177 | /* pending or stable entry has become old! */ |
| RodColeman | 0:0791c1fece8e | 178 | LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer: expired %s entry %"U16_F".\n", |
| RodColeman | 0:0791c1fece8e | 179 | arp_table[i].state == ETHARP_STATE_STABLE ? "stable" : "pending", (u16_t)i)); |
| RodColeman | 0:0791c1fece8e | 180 | /* clean up entries that have just been expired */ |
| RodColeman | 0:0791c1fece8e | 181 | /* remove from SNMP ARP index tree */ |
| RodColeman | 0:0791c1fece8e | 182 | snmp_delete_arpidx_tree(arp_table[i].netif, &arp_table[i].ipaddr); |
| RodColeman | 0:0791c1fece8e | 183 | #if ARP_QUEUEING |
| RodColeman | 0:0791c1fece8e | 184 | /* and empty packet queue */ |
| RodColeman | 0:0791c1fece8e | 185 | if (arp_table[i].q != NULL) { |
| RodColeman | 0:0791c1fece8e | 186 | /* remove all queued packets */ |
| RodColeman | 0:0791c1fece8e | 187 | LWIP_DEBUGF(ETHARP_DEBUG, ("etharp_timer: freeing entry %"U16_F", packet queue %p.\n", (u16_t)i, (void *)(arp_table[i].q))); |
| RodColeman | 0:0791c1fece8e | 188 | free_etharp_q(arp_table[i].q); |
| RodColeman | 0:0791c1fece8e | 189 | arp_table[i].q = NULL; |
| RodColeman | 0:0791c1fece8e | 190 | } |
| RodColeman | 0:0791c1fece8e | 191 | #endif |
| RodColeman | 0:0791c1fece8e | 192 | /* recycle entry for re-use */ |
| RodColeman | 0:0791c1fece8e | 193 | arp_table[i].state = ETHARP_STATE_EMPTY; |
| RodColeman | 0:0791c1fece8e | 194 | } |
| RodColeman | 0:0791c1fece8e | 195 | #if ARP_QUEUEING |
| RodColeman | 0:0791c1fece8e | 196 | /* still pending entry? (not expired) */ |
| RodColeman | 0:0791c1fece8e | 197 | if (arp_table[i].state == ETHARP_STATE_PENDING) { |
| RodColeman | 0:0791c1fece8e | 198 | /* resend an ARP query here? */ |
| RodColeman | 0:0791c1fece8e | 199 | } |
| RodColeman | 0:0791c1fece8e | 200 | #endif |
| RodColeman | 0:0791c1fece8e | 201 | } |
| RodColeman | 0:0791c1fece8e | 202 | } |
| RodColeman | 0:0791c1fece8e | 203 | |
| RodColeman | 0:0791c1fece8e | 204 | /** |
| RodColeman | 0:0791c1fece8e | 205 | * Search the ARP table for a matching or new entry. |
| RodColeman | 0:0791c1fece8e | 206 | * |
| RodColeman | 0:0791c1fece8e | 207 | * If an IP address is given, return a pending or stable ARP entry that matches |
| RodColeman | 0:0791c1fece8e | 208 | * the address. If no match is found, create a new entry with this address set, |
| RodColeman | 0:0791c1fece8e | 209 | * but in state ETHARP_EMPTY. The caller must check and possibly change the |
| RodColeman | 0:0791c1fece8e | 210 | * state of the returned entry. |
| RodColeman | 0:0791c1fece8e | 211 | * |
| RodColeman | 0:0791c1fece8e | 212 | * If ipaddr is NULL, return a initialized new entry in state ETHARP_EMPTY. |
| RodColeman | 0:0791c1fece8e | 213 | * |
| RodColeman | 0:0791c1fece8e | 214 | * In all cases, attempt to create new entries from an empty entry. If no |
| RodColeman | 0:0791c1fece8e | 215 | * empty entries are available and ETHARP_TRY_HARD flag is set, recycle |
| RodColeman | 0:0791c1fece8e | 216 | * old entries. Heuristic choose the least important entry for recycling. |
| RodColeman | 0:0791c1fece8e | 217 | * |
| RodColeman | 0:0791c1fece8e | 218 | * @param ipaddr IP address to find in ARP cache, or to add if not found. |
| RodColeman | 0:0791c1fece8e | 219 | * @param flags |
| RodColeman | 0:0791c1fece8e | 220 | * - ETHARP_TRY_HARD: Try hard to create a entry by allowing recycling of |
| RodColeman | 0:0791c1fece8e | 221 | * active (stable or pending) entries. |
| RodColeman | 0:0791c1fece8e | 222 | * |
| RodColeman | 0:0791c1fece8e | 223 | * @return The ARP entry index that matched or is created, ERR_MEM if no |
| RodColeman | 0:0791c1fece8e | 224 | * entry is found or could be recycled. |
| RodColeman | 0:0791c1fece8e | 225 | */ |
| RodColeman | 0:0791c1fece8e | 226 | static s8_t |
| RodColeman | 0:0791c1fece8e | 227 | #if LWIP_NETIF_HWADDRHINT |
| RodColeman | 0:0791c1fece8e | 228 | find_entry(struct ip_addr *ipaddr, u8_t flags, struct netif *netif) |
| RodColeman | 0:0791c1fece8e | 229 | #else /* LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 230 | find_entry(struct ip_addr *ipaddr, u8_t flags) |
| RodColeman | 0:0791c1fece8e | 231 | #endif /* LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 232 | { |
| RodColeman | 0:0791c1fece8e | 233 | s8_t old_pending = ARP_TABLE_SIZE, old_stable = ARP_TABLE_SIZE; |
| RodColeman | 0:0791c1fece8e | 234 | s8_t empty = ARP_TABLE_SIZE; |
| RodColeman | 0:0791c1fece8e | 235 | u8_t i = 0, age_pending = 0, age_stable = 0; |
| RodColeman | 0:0791c1fece8e | 236 | #if ARP_QUEUEING |
| RodColeman | 0:0791c1fece8e | 237 | /* oldest entry with packets on queue */ |
| RodColeman | 0:0791c1fece8e | 238 | s8_t old_queue = ARP_TABLE_SIZE; |
| RodColeman | 0:0791c1fece8e | 239 | /* its age */ |
| RodColeman | 0:0791c1fece8e | 240 | u8_t age_queue = 0; |
| RodColeman | 0:0791c1fece8e | 241 | #endif |
| RodColeman | 0:0791c1fece8e | 242 | |
| RodColeman | 0:0791c1fece8e | 243 | /* First, test if the last call to this function asked for the |
| RodColeman | 0:0791c1fece8e | 244 | * same address. If so, we're really fast! */ |
| RodColeman | 0:0791c1fece8e | 245 | if (ipaddr) { |
| RodColeman | 0:0791c1fece8e | 246 | /* ipaddr to search for was given */ |
| RodColeman | 0:0791c1fece8e | 247 | #if LWIP_NETIF_HWADDRHINT |
| RodColeman | 0:0791c1fece8e | 248 | if ((netif != NULL) && (netif->addr_hint != NULL)) { |
| RodColeman | 0:0791c1fece8e | 249 | /* per-pcb cached entry was given */ |
| RodColeman | 0:0791c1fece8e | 250 | u8_t per_pcb_cache = *(netif->addr_hint); |
| RodColeman | 0:0791c1fece8e | 251 | if ((per_pcb_cache < ARP_TABLE_SIZE) && arp_table[per_pcb_cache].state == ETHARP_STATE_STABLE) { |
| RodColeman | 0:0791c1fece8e | 252 | /* the per-pcb-cached entry is stable */ |
| RodColeman | 0:0791c1fece8e | 253 | if (ip_addr_cmp(ipaddr, &arp_table[per_pcb_cache].ipaddr)) { |
| RodColeman | 0:0791c1fece8e | 254 | /* per-pcb cached entry was the right one! */ |
| RodColeman | 0:0791c1fece8e | 255 | ETHARP_STATS_INC(etharp.cachehit); |
| RodColeman | 0:0791c1fece8e | 256 | return per_pcb_cache; |
| RodColeman | 0:0791c1fece8e | 257 | } |
| RodColeman | 0:0791c1fece8e | 258 | } |
| RodColeman | 0:0791c1fece8e | 259 | } |
| RodColeman | 0:0791c1fece8e | 260 | #else /* #if LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 261 | if (arp_table[etharp_cached_entry].state == ETHARP_STATE_STABLE) { |
| RodColeman | 0:0791c1fece8e | 262 | /* the cached entry is stable */ |
| RodColeman | 0:0791c1fece8e | 263 | if (ip_addr_cmp(ipaddr, &arp_table[etharp_cached_entry].ipaddr)) { |
| RodColeman | 0:0791c1fece8e | 264 | /* cached entry was the right one! */ |
| RodColeman | 0:0791c1fece8e | 265 | ETHARP_STATS_INC(etharp.cachehit); |
| RodColeman | 0:0791c1fece8e | 266 | return etharp_cached_entry; |
| RodColeman | 0:0791c1fece8e | 267 | } |
| RodColeman | 0:0791c1fece8e | 268 | } |
| RodColeman | 0:0791c1fece8e | 269 | #endif /* #if LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 270 | } |
| RodColeman | 0:0791c1fece8e | 271 | |
| RodColeman | 0:0791c1fece8e | 272 | /** |
| RodColeman | 0:0791c1fece8e | 273 | * a) do a search through the cache, remember candidates |
| RodColeman | 0:0791c1fece8e | 274 | * b) select candidate entry |
| RodColeman | 0:0791c1fece8e | 275 | * c) create new entry |
| RodColeman | 0:0791c1fece8e | 276 | */ |
| RodColeman | 0:0791c1fece8e | 277 | |
| RodColeman | 0:0791c1fece8e | 278 | /* a) in a single search sweep, do all of this |
| RodColeman | 0:0791c1fece8e | 279 | * 1) remember the first empty entry (if any) |
| RodColeman | 0:0791c1fece8e | 280 | * 2) remember the oldest stable entry (if any) |
| RodColeman | 0:0791c1fece8e | 281 | * 3) remember the oldest pending entry without queued packets (if any) |
| RodColeman | 0:0791c1fece8e | 282 | * 4) remember the oldest pending entry with queued packets (if any) |
| RodColeman | 0:0791c1fece8e | 283 | * 5) search for a matching IP entry, either pending or stable |
| RodColeman | 0:0791c1fece8e | 284 | * until 5 matches, or all entries are searched for. |
| RodColeman | 0:0791c1fece8e | 285 | */ |
| RodColeman | 0:0791c1fece8e | 286 | |
| RodColeman | 0:0791c1fece8e | 287 | for (i = 0; i < ARP_TABLE_SIZE; ++i) { |
| RodColeman | 0:0791c1fece8e | 288 | /* no empty entry found yet and now we do find one? */ |
| RodColeman | 0:0791c1fece8e | 289 | if ((empty == ARP_TABLE_SIZE) && (arp_table[i].state == ETHARP_STATE_EMPTY)) { |
| RodColeman | 0:0791c1fece8e | 290 | LWIP_DEBUGF(ETHARP_DEBUG, ("find_entry: found empty entry %"U16_F"\n", (u16_t)i)); |
| RodColeman | 0:0791c1fece8e | 291 | /* remember first empty entry */ |
| RodColeman | 0:0791c1fece8e | 292 | empty = i; |
| RodColeman | 0:0791c1fece8e | 293 | } |
| RodColeman | 0:0791c1fece8e | 294 | /* pending entry? */ |
| RodColeman | 0:0791c1fece8e | 295 | else if (arp_table[i].state == ETHARP_STATE_PENDING) { |
| RodColeman | 0:0791c1fece8e | 296 | /* if given, does IP address match IP address in ARP entry? */ |
| RodColeman | 0:0791c1fece8e | 297 | if (ipaddr && ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) { |
| RodColeman | 0:0791c1fece8e | 298 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("find_entry: found matching pending entry %"U16_F"\n", (u16_t)i)); |
| RodColeman | 0:0791c1fece8e | 299 | /* found exact IP address match, simply bail out */ |
| RodColeman | 0:0791c1fece8e | 300 | #if LWIP_NETIF_HWADDRHINT |
| RodColeman | 0:0791c1fece8e | 301 | NETIF_SET_HINT(netif, i); |
| RodColeman | 0:0791c1fece8e | 302 | #else /* #if LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 303 | etharp_cached_entry = i; |
| RodColeman | 0:0791c1fece8e | 304 | #endif /* #if LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 305 | return i; |
| RodColeman | 0:0791c1fece8e | 306 | #if ARP_QUEUEING |
| RodColeman | 0:0791c1fece8e | 307 | /* pending with queued packets? */ |
| RodColeman | 0:0791c1fece8e | 308 | } else if (arp_table[i].q != NULL) { |
| RodColeman | 0:0791c1fece8e | 309 | if (arp_table[i].ctime >= age_queue) { |
| RodColeman | 0:0791c1fece8e | 310 | old_queue = i; |
| RodColeman | 0:0791c1fece8e | 311 | age_queue = arp_table[i].ctime; |
| RodColeman | 0:0791c1fece8e | 312 | } |
| RodColeman | 0:0791c1fece8e | 313 | #endif |
| RodColeman | 0:0791c1fece8e | 314 | /* pending without queued packets? */ |
| RodColeman | 0:0791c1fece8e | 315 | } else { |
| RodColeman | 0:0791c1fece8e | 316 | if (arp_table[i].ctime >= age_pending) { |
| RodColeman | 0:0791c1fece8e | 317 | old_pending = i; |
| RodColeman | 0:0791c1fece8e | 318 | age_pending = arp_table[i].ctime; |
| RodColeman | 0:0791c1fece8e | 319 | } |
| RodColeman | 0:0791c1fece8e | 320 | } |
| RodColeman | 0:0791c1fece8e | 321 | } |
| RodColeman | 0:0791c1fece8e | 322 | /* stable entry? */ |
| RodColeman | 0:0791c1fece8e | 323 | else if (arp_table[i].state == ETHARP_STATE_STABLE) { |
| RodColeman | 0:0791c1fece8e | 324 | /* if given, does IP address match IP address in ARP entry? */ |
| RodColeman | 0:0791c1fece8e | 325 | if (ipaddr && ip_addr_cmp(ipaddr, &arp_table[i].ipaddr)) { |
| RodColeman | 0:0791c1fece8e | 326 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("find_entry: found matching stable entry %"U16_F"\n", (u16_t)i)); |
| RodColeman | 0:0791c1fece8e | 327 | /* found exact IP address match, simply bail out */ |
| RodColeman | 0:0791c1fece8e | 328 | #if LWIP_NETIF_HWADDRHINT |
| RodColeman | 0:0791c1fece8e | 329 | NETIF_SET_HINT(netif, i); |
| RodColeman | 0:0791c1fece8e | 330 | #else /* #if LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 331 | etharp_cached_entry = i; |
| RodColeman | 0:0791c1fece8e | 332 | #endif /* #if LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 333 | return i; |
| RodColeman | 0:0791c1fece8e | 334 | /* remember entry with oldest stable entry in oldest, its age in maxtime */ |
| RodColeman | 0:0791c1fece8e | 335 | } else if (arp_table[i].ctime >= age_stable) { |
| RodColeman | 0:0791c1fece8e | 336 | old_stable = i; |
| RodColeman | 0:0791c1fece8e | 337 | age_stable = arp_table[i].ctime; |
| RodColeman | 0:0791c1fece8e | 338 | } |
| RodColeman | 0:0791c1fece8e | 339 | } |
| RodColeman | 0:0791c1fece8e | 340 | } |
| RodColeman | 0:0791c1fece8e | 341 | /* { we have no match } => try to create a new entry */ |
| RodColeman | 0:0791c1fece8e | 342 | |
| RodColeman | 0:0791c1fece8e | 343 | /* no empty entry found and not allowed to recycle? */ |
| RodColeman | 0:0791c1fece8e | 344 | if (((empty == ARP_TABLE_SIZE) && ((flags & ETHARP_TRY_HARD) == 0)) |
| RodColeman | 0:0791c1fece8e | 345 | /* or don't create new entry, only search? */ |
| RodColeman | 0:0791c1fece8e | 346 | || ((flags & ETHARP_FIND_ONLY) != 0)) { |
| RodColeman | 0:0791c1fece8e | 347 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("find_entry: no empty entry found and not allowed to recycle\n")); |
| RodColeman | 0:0791c1fece8e | 348 | return (s8_t)ERR_MEM; |
| RodColeman | 0:0791c1fece8e | 349 | } |
| RodColeman | 0:0791c1fece8e | 350 | |
| RodColeman | 0:0791c1fece8e | 351 | /* b) choose the least destructive entry to recycle: |
| RodColeman | 0:0791c1fece8e | 352 | * 1) empty entry |
| RodColeman | 0:0791c1fece8e | 353 | * 2) oldest stable entry |
| RodColeman | 0:0791c1fece8e | 354 | * 3) oldest pending entry without queued packets |
| RodColeman | 0:0791c1fece8e | 355 | * 4) oldest pending entry with queued packets |
| RodColeman | 0:0791c1fece8e | 356 | * |
| RodColeman | 0:0791c1fece8e | 357 | * { ETHARP_TRY_HARD is set at this point } |
| RodColeman | 0:0791c1fece8e | 358 | */ |
| RodColeman | 0:0791c1fece8e | 359 | |
| RodColeman | 0:0791c1fece8e | 360 | /* 1) empty entry available? */ |
| RodColeman | 0:0791c1fece8e | 361 | if (empty < ARP_TABLE_SIZE) { |
| RodColeman | 0:0791c1fece8e | 362 | i = empty; |
| RodColeman | 0:0791c1fece8e | 363 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("find_entry: selecting empty entry %"U16_F"\n", (u16_t)i)); |
| RodColeman | 0:0791c1fece8e | 364 | } |
| RodColeman | 0:0791c1fece8e | 365 | /* 2) found recyclable stable entry? */ |
| RodColeman | 0:0791c1fece8e | 366 | else if (old_stable < ARP_TABLE_SIZE) { |
| RodColeman | 0:0791c1fece8e | 367 | /* recycle oldest stable*/ |
| RodColeman | 0:0791c1fece8e | 368 | i = old_stable; |
| RodColeman | 0:0791c1fece8e | 369 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("find_entry: selecting oldest stable entry %"U16_F"\n", (u16_t)i)); |
| RodColeman | 0:0791c1fece8e | 370 | #if ARP_QUEUEING |
| RodColeman | 0:0791c1fece8e | 371 | /* no queued packets should exist on stable entries */ |
| RodColeman | 0:0791c1fece8e | 372 | LWIP_ASSERT("arp_table[i].q == NULL", arp_table[i].q == NULL); |
| RodColeman | 0:0791c1fece8e | 373 | #endif |
| RodColeman | 0:0791c1fece8e | 374 | /* 3) found recyclable pending entry without queued packets? */ |
| RodColeman | 0:0791c1fece8e | 375 | } else if (old_pending < ARP_TABLE_SIZE) { |
| RodColeman | 0:0791c1fece8e | 376 | /* recycle oldest pending */ |
| RodColeman | 0:0791c1fece8e | 377 | i = old_pending; |
| RodColeman | 0:0791c1fece8e | 378 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("find_entry: selecting oldest pending entry %"U16_F" (without queue)\n", (u16_t)i)); |
| RodColeman | 0:0791c1fece8e | 379 | #if ARP_QUEUEING |
| RodColeman | 0:0791c1fece8e | 380 | /* 4) found recyclable pending entry with queued packets? */ |
| RodColeman | 0:0791c1fece8e | 381 | } else if (old_queue < ARP_TABLE_SIZE) { |
| RodColeman | 0:0791c1fece8e | 382 | /* recycle oldest pending */ |
| RodColeman | 0:0791c1fece8e | 383 | i = old_queue; |
| RodColeman | 0:0791c1fece8e | 384 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("find_entry: selecting oldest pending entry %"U16_F", freeing packet queue %p\n", (u16_t)i, (void *)(arp_table[i].q))); |
| RodColeman | 0:0791c1fece8e | 385 | free_etharp_q(arp_table[i].q); |
| RodColeman | 0:0791c1fece8e | 386 | arp_table[i].q = NULL; |
| RodColeman | 0:0791c1fece8e | 387 | #endif |
| RodColeman | 0:0791c1fece8e | 388 | /* no empty or recyclable entries found */ |
| RodColeman | 0:0791c1fece8e | 389 | } else { |
| RodColeman | 0:0791c1fece8e | 390 | return (s8_t)ERR_MEM; |
| RodColeman | 0:0791c1fece8e | 391 | } |
| RodColeman | 0:0791c1fece8e | 392 | |
| RodColeman | 0:0791c1fece8e | 393 | /* { empty or recyclable entry found } */ |
| RodColeman | 0:0791c1fece8e | 394 | LWIP_ASSERT("i < ARP_TABLE_SIZE", i < ARP_TABLE_SIZE); |
| RodColeman | 0:0791c1fece8e | 395 | |
| RodColeman | 0:0791c1fece8e | 396 | if (arp_table[i].state != ETHARP_STATE_EMPTY) |
| RodColeman | 0:0791c1fece8e | 397 | { |
| RodColeman | 0:0791c1fece8e | 398 | snmp_delete_arpidx_tree(arp_table[i].netif, &arp_table[i].ipaddr); |
| RodColeman | 0:0791c1fece8e | 399 | } |
| RodColeman | 0:0791c1fece8e | 400 | /* recycle entry (no-op for an already empty entry) */ |
| RodColeman | 0:0791c1fece8e | 401 | arp_table[i].state = ETHARP_STATE_EMPTY; |
| RodColeman | 0:0791c1fece8e | 402 | |
| RodColeman | 0:0791c1fece8e | 403 | /* IP address given? */ |
| RodColeman | 0:0791c1fece8e | 404 | if (ipaddr != NULL) { |
| RodColeman | 0:0791c1fece8e | 405 | /* set IP address */ |
| RodColeman | 0:0791c1fece8e | 406 | ip_addr_set(&arp_table[i].ipaddr, ipaddr); |
| RodColeman | 0:0791c1fece8e | 407 | } |
| RodColeman | 0:0791c1fece8e | 408 | arp_table[i].ctime = 0; |
| RodColeman | 0:0791c1fece8e | 409 | #if LWIP_NETIF_HWADDRHINT |
| RodColeman | 0:0791c1fece8e | 410 | NETIF_SET_HINT(netif, i); |
| RodColeman | 0:0791c1fece8e | 411 | #else /* #if LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 412 | etharp_cached_entry = i; |
| RodColeman | 0:0791c1fece8e | 413 | #endif /* #if LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 414 | return (err_t)i; |
| RodColeman | 0:0791c1fece8e | 415 | } |
| RodColeman | 0:0791c1fece8e | 416 | |
| RodColeman | 0:0791c1fece8e | 417 | /** |
| RodColeman | 0:0791c1fece8e | 418 | * Send an IP packet on the network using netif->linkoutput |
| RodColeman | 0:0791c1fece8e | 419 | * The ethernet header is filled in before sending. |
| RodColeman | 0:0791c1fece8e | 420 | * |
| RodColeman | 0:0791c1fece8e | 421 | * @params netif the lwIP network interface on which to send the packet |
| RodColeman | 0:0791c1fece8e | 422 | * @params p the packet to send, p->payload pointing to the (uninitialized) ethernet header |
| RodColeman | 0:0791c1fece8e | 423 | * @params src the source MAC address to be copied into the ethernet header |
| RodColeman | 0:0791c1fece8e | 424 | * @params dst the destination MAC address to be copied into the ethernet header |
| RodColeman | 0:0791c1fece8e | 425 | * @return ERR_OK if the packet was sent, any other err_t on failure |
| RodColeman | 0:0791c1fece8e | 426 | */ |
| RodColeman | 0:0791c1fece8e | 427 | static err_t |
| RodColeman | 0:0791c1fece8e | 428 | etharp_send_ip(struct netif *netif, struct pbuf *p, struct eth_addr *src, struct eth_addr *dst) |
| RodColeman | 0:0791c1fece8e | 429 | { |
| RodColeman | 0:0791c1fece8e | 430 | struct eth_hdr *ethhdr = (struct eth_hdr *)p->payload; |
| RodColeman | 0:0791c1fece8e | 431 | u8_t k; |
| RodColeman | 0:0791c1fece8e | 432 | |
| RodColeman | 0:0791c1fece8e | 433 | LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!", |
| RodColeman | 0:0791c1fece8e | 434 | (netif->hwaddr_len == ETHARP_HWADDR_LEN)); |
| RodColeman | 0:0791c1fece8e | 435 | k = ETHARP_HWADDR_LEN; |
| RodColeman | 0:0791c1fece8e | 436 | while(k > 0) { |
| RodColeman | 0:0791c1fece8e | 437 | k--; |
| RodColeman | 0:0791c1fece8e | 438 | ethhdr->dest.addr[k] = dst->addr[k]; |
| RodColeman | 0:0791c1fece8e | 439 | ethhdr->src.addr[k] = src->addr[k]; |
| RodColeman | 0:0791c1fece8e | 440 | } |
| RodColeman | 0:0791c1fece8e | 441 | ethhdr->type = htons(ETHTYPE_IP); |
| RodColeman | 0:0791c1fece8e | 442 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_send_ip: sending packet %p\n", (void *)p)); |
| RodColeman | 0:0791c1fece8e | 443 | /* send the packet */ |
| RodColeman | 0:0791c1fece8e | 444 | return netif->linkoutput(netif, p); |
| RodColeman | 0:0791c1fece8e | 445 | } |
| RodColeman | 0:0791c1fece8e | 446 | |
| RodColeman | 0:0791c1fece8e | 447 | /** |
| RodColeman | 0:0791c1fece8e | 448 | * Update (or insert) a IP/MAC address pair in the ARP cache. |
| RodColeman | 0:0791c1fece8e | 449 | * |
| RodColeman | 0:0791c1fece8e | 450 | * If a pending entry is resolved, any queued packets will be sent |
| RodColeman | 0:0791c1fece8e | 451 | * at this point. |
| RodColeman | 0:0791c1fece8e | 452 | * |
| RodColeman | 0:0791c1fece8e | 453 | * @param ipaddr IP address of the inserted ARP entry. |
| RodColeman | 0:0791c1fece8e | 454 | * @param ethaddr Ethernet address of the inserted ARP entry. |
| RodColeman | 0:0791c1fece8e | 455 | * @param flags Defines behaviour: |
| RodColeman | 0:0791c1fece8e | 456 | * - ETHARP_TRY_HARD Allows ARP to insert this as a new item. If not specified, |
| RodColeman | 0:0791c1fece8e | 457 | * only existing ARP entries will be updated. |
| RodColeman | 0:0791c1fece8e | 458 | * |
| RodColeman | 0:0791c1fece8e | 459 | * @return |
| RodColeman | 0:0791c1fece8e | 460 | * - ERR_OK Succesfully updated ARP cache. |
| RodColeman | 0:0791c1fece8e | 461 | * - ERR_MEM If we could not add a new ARP entry when ETHARP_TRY_HARD was set. |
| RodColeman | 0:0791c1fece8e | 462 | * - ERR_ARG Non-unicast address given, those will not appear in ARP cache. |
| RodColeman | 0:0791c1fece8e | 463 | * |
| RodColeman | 0:0791c1fece8e | 464 | * @see pbuf_free() |
| RodColeman | 0:0791c1fece8e | 465 | */ |
| RodColeman | 0:0791c1fece8e | 466 | static err_t |
| RodColeman | 0:0791c1fece8e | 467 | update_arp_entry(struct netif *netif, struct ip_addr *ipaddr, struct eth_addr *ethaddr, u8_t flags) |
| RodColeman | 0:0791c1fece8e | 468 | { |
| RodColeman | 0:0791c1fece8e | 469 | s8_t i; |
| RodColeman | 0:0791c1fece8e | 470 | u8_t k; |
| RodColeman | 0:0791c1fece8e | 471 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | 3, ("update_arp_entry()\n")); |
| RodColeman | 0:0791c1fece8e | 472 | LWIP_ASSERT("netif->hwaddr_len == ETHARP_HWADDR_LEN", netif->hwaddr_len == ETHARP_HWADDR_LEN); |
| RodColeman | 0:0791c1fece8e | 473 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("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", |
| RodColeman | 0:0791c1fece8e | 474 | ip4_addr1(ipaddr), ip4_addr2(ipaddr), ip4_addr3(ipaddr), ip4_addr4(ipaddr), |
| RodColeman | 0:0791c1fece8e | 475 | ethaddr->addr[0], ethaddr->addr[1], ethaddr->addr[2], |
| RodColeman | 0:0791c1fece8e | 476 | ethaddr->addr[3], ethaddr->addr[4], ethaddr->addr[5])); |
| RodColeman | 0:0791c1fece8e | 477 | /* non-unicast address? */ |
| RodColeman | 0:0791c1fece8e | 478 | if (ip_addr_isany(ipaddr) || |
| RodColeman | 0:0791c1fece8e | 479 | ip_addr_isbroadcast(ipaddr, netif) || |
| RodColeman | 0:0791c1fece8e | 480 | ip_addr_ismulticast(ipaddr)) { |
| RodColeman | 0:0791c1fece8e | 481 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("update_arp_entry: will not add non-unicast IP address to ARP cache\n")); |
| RodColeman | 0:0791c1fece8e | 482 | return ERR_ARG; |
| RodColeman | 0:0791c1fece8e | 483 | } |
| RodColeman | 0:0791c1fece8e | 484 | /* find or create ARP entry */ |
| RodColeman | 0:0791c1fece8e | 485 | #if LWIP_NETIF_HWADDRHINT |
| RodColeman | 0:0791c1fece8e | 486 | i = find_entry(ipaddr, flags, netif); |
| RodColeman | 0:0791c1fece8e | 487 | #else /* LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 488 | i = find_entry(ipaddr, flags); |
| RodColeman | 0:0791c1fece8e | 489 | #endif /* LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 490 | /* bail out if no entry could be found */ |
| RodColeman | 0:0791c1fece8e | 491 | if (i < 0) |
| RodColeman | 0:0791c1fece8e | 492 | return (err_t)i; |
| RodColeman | 0:0791c1fece8e | 493 | |
| RodColeman | 0:0791c1fece8e | 494 | /* mark it stable */ |
| RodColeman | 0:0791c1fece8e | 495 | arp_table[i].state = ETHARP_STATE_STABLE; |
| RodColeman | 0:0791c1fece8e | 496 | /* record network interface */ |
| RodColeman | 0:0791c1fece8e | 497 | arp_table[i].netif = netif; |
| RodColeman | 0:0791c1fece8e | 498 | |
| RodColeman | 0:0791c1fece8e | 499 | /* insert in SNMP ARP index tree */ |
| RodColeman | 0:0791c1fece8e | 500 | snmp_insert_arpidx_tree(netif, &arp_table[i].ipaddr); |
| RodColeman | 0:0791c1fece8e | 501 | |
| RodColeman | 0:0791c1fece8e | 502 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("update_arp_entry: updating stable entry %"S16_F"\n", (s16_t)i)); |
| RodColeman | 0:0791c1fece8e | 503 | /* update address */ |
| RodColeman | 0:0791c1fece8e | 504 | k = ETHARP_HWADDR_LEN; |
| RodColeman | 0:0791c1fece8e | 505 | while (k > 0) { |
| RodColeman | 0:0791c1fece8e | 506 | k--; |
| RodColeman | 0:0791c1fece8e | 507 | arp_table[i].ethaddr.addr[k] = ethaddr->addr[k]; |
| RodColeman | 0:0791c1fece8e | 508 | } |
| RodColeman | 0:0791c1fece8e | 509 | /* reset time stamp */ |
| RodColeman | 0:0791c1fece8e | 510 | arp_table[i].ctime = 0; |
| RodColeman | 0:0791c1fece8e | 511 | #if ARP_QUEUEING |
| RodColeman | 0:0791c1fece8e | 512 | /* this is where we will send out queued packets! */ |
| RodColeman | 0:0791c1fece8e | 513 | while (arp_table[i].q != NULL) { |
| RodColeman | 0:0791c1fece8e | 514 | struct pbuf *p; |
| RodColeman | 0:0791c1fece8e | 515 | /* remember remainder of queue */ |
| RodColeman | 0:0791c1fece8e | 516 | struct etharp_q_entry *q = arp_table[i].q; |
| RodColeman | 0:0791c1fece8e | 517 | /* pop first item off the queue */ |
| RodColeman | 0:0791c1fece8e | 518 | arp_table[i].q = q->next; |
| RodColeman | 0:0791c1fece8e | 519 | /* get the packet pointer */ |
| RodColeman | 0:0791c1fece8e | 520 | p = q->p; |
| RodColeman | 0:0791c1fece8e | 521 | /* now queue entry can be freed */ |
| RodColeman | 0:0791c1fece8e | 522 | memp_free(MEMP_ARP_QUEUE, q); |
| RodColeman | 0:0791c1fece8e | 523 | /* send the queued IP packet */ |
| RodColeman | 0:0791c1fece8e | 524 | etharp_send_ip(netif, p, (struct eth_addr*)(netif->hwaddr), ethaddr); |
| RodColeman | 0:0791c1fece8e | 525 | /* free the queued IP packet */ |
| RodColeman | 0:0791c1fece8e | 526 | pbuf_free(p); |
| RodColeman | 0:0791c1fece8e | 527 | } |
| RodColeman | 0:0791c1fece8e | 528 | #endif |
| RodColeman | 0:0791c1fece8e | 529 | return ERR_OK; |
| RodColeman | 0:0791c1fece8e | 530 | } |
| RodColeman | 0:0791c1fece8e | 531 | |
| RodColeman | 0:0791c1fece8e | 532 | /** |
| RodColeman | 0:0791c1fece8e | 533 | * Finds (stable) ethernet/IP address pair from ARP table |
| RodColeman | 0:0791c1fece8e | 534 | * using interface and IP address index. |
| RodColeman | 0:0791c1fece8e | 535 | * @note the addresses in the ARP table are in network order! |
| RodColeman | 0:0791c1fece8e | 536 | * |
| RodColeman | 0:0791c1fece8e | 537 | * @param netif points to interface index |
| RodColeman | 0:0791c1fece8e | 538 | * @param ipaddr points to the (network order) IP address index |
| RodColeman | 0:0791c1fece8e | 539 | * @param eth_ret points to return pointer |
| RodColeman | 0:0791c1fece8e | 540 | * @param ip_ret points to return pointer |
| RodColeman | 0:0791c1fece8e | 541 | * @return table index if found, -1 otherwise |
| RodColeman | 0:0791c1fece8e | 542 | */ |
| RodColeman | 0:0791c1fece8e | 543 | s8_t |
| RodColeman | 0:0791c1fece8e | 544 | etharp_find_addr(struct netif *netif, struct ip_addr *ipaddr, |
| RodColeman | 0:0791c1fece8e | 545 | struct eth_addr **eth_ret, struct ip_addr **ip_ret) |
| RodColeman | 0:0791c1fece8e | 546 | { |
| RodColeman | 0:0791c1fece8e | 547 | s8_t i; |
| RodColeman | 0:0791c1fece8e | 548 | |
| RodColeman | 0:0791c1fece8e | 549 | LWIP_UNUSED_ARG(netif); |
| RodColeman | 0:0791c1fece8e | 550 | |
| RodColeman | 0:0791c1fece8e | 551 | #if LWIP_NETIF_HWADDRHINT |
| RodColeman | 0:0791c1fece8e | 552 | i = find_entry(ipaddr, ETHARP_FIND_ONLY, NULL); |
| RodColeman | 0:0791c1fece8e | 553 | #else /* LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 554 | i = find_entry(ipaddr, ETHARP_FIND_ONLY); |
| RodColeman | 0:0791c1fece8e | 555 | #endif /* LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 556 | if((i >= 0) && arp_table[i].state == ETHARP_STATE_STABLE) { |
| RodColeman | 0:0791c1fece8e | 557 | *eth_ret = &arp_table[i].ethaddr; |
| RodColeman | 0:0791c1fece8e | 558 | *ip_ret = &arp_table[i].ipaddr; |
| RodColeman | 0:0791c1fece8e | 559 | return i; |
| RodColeman | 0:0791c1fece8e | 560 | } |
| RodColeman | 0:0791c1fece8e | 561 | return -1; |
| RodColeman | 0:0791c1fece8e | 562 | } |
| RodColeman | 0:0791c1fece8e | 563 | |
| RodColeman | 0:0791c1fece8e | 564 | /** |
| RodColeman | 0:0791c1fece8e | 565 | * Updates the ARP table using the given IP packet. |
| RodColeman | 0:0791c1fece8e | 566 | * |
| RodColeman | 0:0791c1fece8e | 567 | * Uses the incoming IP packet's source address to update the |
| RodColeman | 0:0791c1fece8e | 568 | * ARP cache for the local network. The function does not alter |
| RodColeman | 0:0791c1fece8e | 569 | * or free the packet. This function must be called before the |
| RodColeman | 0:0791c1fece8e | 570 | * packet p is passed to the IP layer. |
| RodColeman | 0:0791c1fece8e | 571 | * |
| RodColeman | 0:0791c1fece8e | 572 | * @param netif The lwIP network interface on which the IP packet pbuf arrived. |
| RodColeman | 0:0791c1fece8e | 573 | * @param p The IP packet that arrived on netif. |
| RodColeman | 0:0791c1fece8e | 574 | * |
| RodColeman | 0:0791c1fece8e | 575 | * @return NULL |
| RodColeman | 0:0791c1fece8e | 576 | * |
| RodColeman | 0:0791c1fece8e | 577 | * @see pbuf_free() |
| RodColeman | 0:0791c1fece8e | 578 | */ |
| RodColeman | 0:0791c1fece8e | 579 | void |
| RodColeman | 0:0791c1fece8e | 580 | etharp_ip_input(struct netif *netif, struct pbuf *p) |
| RodColeman | 0:0791c1fece8e | 581 | { |
| RodColeman | 0:0791c1fece8e | 582 | struct eth_hdr *ethhdr; |
| RodColeman | 0:0791c1fece8e | 583 | struct ip_hdr *iphdr; |
| RodColeman | 0:0791c1fece8e | 584 | LWIP_ERROR("netif != NULL", (netif != NULL), return;); |
| RodColeman | 0:0791c1fece8e | 585 | /* Only insert an entry if the source IP address of the |
| RodColeman | 0:0791c1fece8e | 586 | incoming IP packet comes from a host on the local network. */ |
| RodColeman | 0:0791c1fece8e | 587 | ethhdr = (struct eth_hdr *)p->payload; |
| RodColeman | 0:0791c1fece8e | 588 | iphdr = (struct ip_hdr *)((u8_t*)ethhdr + SIZEOF_ETH_HDR); |
| RodColeman | 0:0791c1fece8e | 589 | #if ETHARP_SUPPORT_VLAN |
| RodColeman | 0:0791c1fece8e | 590 | if (ethhdr->type == ETHTYPE_VLAN) { |
| RodColeman | 0:0791c1fece8e | 591 | iphdr = (struct ip_hdr *)((u8_t*)ethhdr + SIZEOF_ETH_HDR + SIZEOF_VLAN_HDR); |
| RodColeman | 0:0791c1fece8e | 592 | } |
| RodColeman | 0:0791c1fece8e | 593 | #endif /* ETHARP_SUPPORT_VLAN */ |
| RodColeman | 0:0791c1fece8e | 594 | |
| RodColeman | 0:0791c1fece8e | 595 | /* source is not on the local network? */ |
| RodColeman | 0:0791c1fece8e | 596 | if (!ip_addr_netcmp(&(iphdr->src), &(netif->ip_addr), &(netif->netmask))) { |
| RodColeman | 0:0791c1fece8e | 597 | /* do nothing */ |
| RodColeman | 0:0791c1fece8e | 598 | return; |
| RodColeman | 0:0791c1fece8e | 599 | } |
| RodColeman | 0:0791c1fece8e | 600 | |
| RodColeman | 0:0791c1fece8e | 601 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_ip_input: updating ETHARP table.\n")); |
| RodColeman | 0:0791c1fece8e | 602 | /* update ARP table */ |
| RodColeman | 0:0791c1fece8e | 603 | /* @todo We could use ETHARP_TRY_HARD if we think we are going to talk |
| RodColeman | 0:0791c1fece8e | 604 | * back soon (for example, if the destination IP address is ours. */ |
| RodColeman | 0:0791c1fece8e | 605 | update_arp_entry(netif, &(iphdr->src), &(ethhdr->src), 0); |
| RodColeman | 0:0791c1fece8e | 606 | } |
| RodColeman | 0:0791c1fece8e | 607 | |
| RodColeman | 0:0791c1fece8e | 608 | |
| RodColeman | 0:0791c1fece8e | 609 | /** |
| RodColeman | 0:0791c1fece8e | 610 | * Responds to ARP requests to us. Upon ARP replies to us, add entry to cache |
| RodColeman | 0:0791c1fece8e | 611 | * send out queued IP packets. Updates cache with snooped address pairs. |
| RodColeman | 0:0791c1fece8e | 612 | * |
| RodColeman | 0:0791c1fece8e | 613 | * Should be called for incoming ARP packets. The pbuf in the argument |
| RodColeman | 0:0791c1fece8e | 614 | * is freed by this function. |
| RodColeman | 0:0791c1fece8e | 615 | * |
| RodColeman | 0:0791c1fece8e | 616 | * @param netif The lwIP network interface on which the ARP packet pbuf arrived. |
| RodColeman | 0:0791c1fece8e | 617 | * @param ethaddr Ethernet address of netif. |
| RodColeman | 0:0791c1fece8e | 618 | * @param p The ARP packet that arrived on netif. Is freed by this function. |
| RodColeman | 0:0791c1fece8e | 619 | * |
| RodColeman | 0:0791c1fece8e | 620 | * @return NULL |
| RodColeman | 0:0791c1fece8e | 621 | * |
| RodColeman | 0:0791c1fece8e | 622 | * @see pbuf_free() |
| RodColeman | 0:0791c1fece8e | 623 | */ |
| RodColeman | 0:0791c1fece8e | 624 | void |
| RodColeman | 0:0791c1fece8e | 625 | etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr, struct pbuf *p) |
| RodColeman | 0:0791c1fece8e | 626 | { |
| RodColeman | 0:0791c1fece8e | 627 | struct etharp_hdr *hdr; |
| RodColeman | 0:0791c1fece8e | 628 | struct eth_hdr *ethhdr; |
| RodColeman | 0:0791c1fece8e | 629 | /* these are aligned properly, whereas the ARP header fields might not be */ |
| RodColeman | 0:0791c1fece8e | 630 | struct ip_addr sipaddr, dipaddr; |
| RodColeman | 0:0791c1fece8e | 631 | u8_t i; |
| RodColeman | 0:0791c1fece8e | 632 | u8_t for_us; |
| RodColeman | 0:0791c1fece8e | 633 | #if LWIP_AUTOIP |
| RodColeman | 0:0791c1fece8e | 634 | const u8_t * ethdst_hwaddr; |
| RodColeman | 0:0791c1fece8e | 635 | #endif /* LWIP_AUTOIP */ |
| RodColeman | 0:0791c1fece8e | 636 | |
| RodColeman | 0:0791c1fece8e | 637 | LWIP_ERROR("netif != NULL", (netif != NULL), return;); |
| RodColeman | 0:0791c1fece8e | 638 | |
| RodColeman | 0:0791c1fece8e | 639 | /* drop short ARP packets: we have to check for p->len instead of p->tot_len here |
| RodColeman | 0:0791c1fece8e | 640 | since a struct etharp_hdr is pointed to p->payload, so it musn't be chained! */ |
| RodColeman | 0:0791c1fece8e | 641 | if (p->len < SIZEOF_ETHARP_PACKET) { |
| RodColeman | 0:0791c1fece8e | 642 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | 1, ("etharp_arp_input: packet dropped, too short (%"S16_F"/%"S16_F")\n", p->tot_len, (s16_t)SIZEOF_ETHARP_PACKET)); |
| RodColeman | 0:0791c1fece8e | 643 | ETHARP_STATS_INC(etharp.lenerr); |
| RodColeman | 0:0791c1fece8e | 644 | ETHARP_STATS_INC(etharp.drop); |
| RodColeman | 0:0791c1fece8e | 645 | pbuf_free(p); |
| RodColeman | 0:0791c1fece8e | 646 | return; |
| RodColeman | 0:0791c1fece8e | 647 | } |
| RodColeman | 0:0791c1fece8e | 648 | |
| RodColeman | 0:0791c1fece8e | 649 | ethhdr = (struct eth_hdr *)p->payload; |
| RodColeman | 0:0791c1fece8e | 650 | hdr = (struct etharp_hdr *)((u8_t*)ethhdr + SIZEOF_ETH_HDR); |
| RodColeman | 0:0791c1fece8e | 651 | #if ETHARP_SUPPORT_VLAN |
| RodColeman | 0:0791c1fece8e | 652 | if (ethhdr->type == ETHTYPE_VLAN) { |
| RodColeman | 0:0791c1fece8e | 653 | hdr = (struct etharp_hdr *)(((u8_t*)ethhdr) + SIZEOF_ETH_HDR + SIZEOF_VLAN_HDR); |
| RodColeman | 0:0791c1fece8e | 654 | } |
| RodColeman | 0:0791c1fece8e | 655 | #endif /* ETHARP_SUPPORT_VLAN */ |
| RodColeman | 0:0791c1fece8e | 656 | |
| RodColeman | 0:0791c1fece8e | 657 | /* RFC 826 "Packet Reception": */ |
| RodColeman | 0:0791c1fece8e | 658 | if ((hdr->hwtype != htons(HWTYPE_ETHERNET)) || |
| RodColeman | 0:0791c1fece8e | 659 | (hdr->_hwlen_protolen != htons((ETHARP_HWADDR_LEN << 8) | sizeof(struct ip_addr))) || |
| RodColeman | 0:0791c1fece8e | 660 | (hdr->proto != htons(ETHTYPE_IP)) || |
| RodColeman | 0:0791c1fece8e | 661 | (ethhdr->type != htons(ETHTYPE_ARP))) { |
| RodColeman | 0:0791c1fece8e | 662 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | 1, |
| RodColeman | 0:0791c1fece8e | 663 | ("etharp_arp_input: packet dropped, wrong hw type, hwlen, proto, protolen or ethernet type (%"U16_F"/%"U16_F"/%"U16_F"/%"U16_F"/%"U16_F")\n", |
| RodColeman | 0:0791c1fece8e | 664 | hdr->hwtype, ARPH_HWLEN(hdr), hdr->proto, ARPH_PROTOLEN(hdr), ethhdr->type)); |
| RodColeman | 0:0791c1fece8e | 665 | ETHARP_STATS_INC(etharp.proterr); |
| RodColeman | 0:0791c1fece8e | 666 | ETHARP_STATS_INC(etharp.drop); |
| RodColeman | 0:0791c1fece8e | 667 | pbuf_free(p); |
| RodColeman | 0:0791c1fece8e | 668 | return; |
| RodColeman | 0:0791c1fece8e | 669 | } |
| RodColeman | 0:0791c1fece8e | 670 | ETHARP_STATS_INC(etharp.recv); |
| RodColeman | 0:0791c1fece8e | 671 | |
| RodColeman | 0:0791c1fece8e | 672 | #if LWIP_AUTOIP |
| RodColeman | 0:0791c1fece8e | 673 | /* We have to check if a host already has configured our random |
| RodColeman | 0:0791c1fece8e | 674 | * created link local address and continously check if there is |
| RodColeman | 0:0791c1fece8e | 675 | * a host with this IP-address so we can detect collisions */ |
| RodColeman | 0:0791c1fece8e | 676 | autoip_arp_reply(netif, hdr); |
| RodColeman | 0:0791c1fece8e | 677 | #endif /* LWIP_AUTOIP */ |
| RodColeman | 0:0791c1fece8e | 678 | |
| RodColeman | 0:0791c1fece8e | 679 | /* Copy struct ip_addr2 to aligned ip_addr, to support compilers without |
| RodColeman | 0:0791c1fece8e | 680 | * structure packing (not using structure copy which breaks strict-aliasing rules). */ |
| RodColeman | 0:0791c1fece8e | 681 | SMEMCPY(&sipaddr, &hdr->sipaddr, sizeof(sipaddr)); |
| RodColeman | 0:0791c1fece8e | 682 | SMEMCPY(&dipaddr, &hdr->dipaddr, sizeof(dipaddr)); |
| RodColeman | 0:0791c1fece8e | 683 | |
| RodColeman | 0:0791c1fece8e | 684 | /* this interface is not configured? */ |
| RodColeman | 0:0791c1fece8e | 685 | if (netif->ip_addr.addr == 0) { |
| RodColeman | 0:0791c1fece8e | 686 | for_us = 0; |
| RodColeman | 0:0791c1fece8e | 687 | } else { |
| RodColeman | 0:0791c1fece8e | 688 | /* ARP packet directed to us? */ |
| RodColeman | 0:0791c1fece8e | 689 | for_us = ip_addr_cmp(&dipaddr, &(netif->ip_addr)); |
| RodColeman | 0:0791c1fece8e | 690 | } |
| RodColeman | 0:0791c1fece8e | 691 | |
| RodColeman | 0:0791c1fece8e | 692 | /* ARP message directed to us? */ |
| RodColeman | 0:0791c1fece8e | 693 | if (for_us) { |
| RodColeman | 0:0791c1fece8e | 694 | /* add IP address in ARP cache; assume requester wants to talk to us. |
| RodColeman | 0:0791c1fece8e | 695 | * can result in directly sending the queued packets for this host. */ |
| RodColeman | 0:0791c1fece8e | 696 | update_arp_entry(netif, &sipaddr, &(hdr->shwaddr), ETHARP_TRY_HARD); |
| RodColeman | 0:0791c1fece8e | 697 | /* ARP message not directed to us? */ |
| RodColeman | 0:0791c1fece8e | 698 | } else { |
| RodColeman | 0:0791c1fece8e | 699 | /* update the source IP address in the cache, if present */ |
| RodColeman | 0:0791c1fece8e | 700 | update_arp_entry(netif, &sipaddr, &(hdr->shwaddr), 0); |
| RodColeman | 0:0791c1fece8e | 701 | } |
| RodColeman | 0:0791c1fece8e | 702 | |
| RodColeman | 0:0791c1fece8e | 703 | /* now act on the message itself */ |
| RodColeman | 0:0791c1fece8e | 704 | switch (htons(hdr->opcode)) { |
| RodColeman | 0:0791c1fece8e | 705 | /* ARP request? */ |
| RodColeman | 0:0791c1fece8e | 706 | case ARP_REQUEST: |
| RodColeman | 0:0791c1fece8e | 707 | /* ARP request. If it asked for our address, we send out a |
| RodColeman | 0:0791c1fece8e | 708 | * reply. In any case, we time-stamp any existing ARP entry, |
| RodColeman | 0:0791c1fece8e | 709 | * and possiby send out an IP packet that was queued on it. */ |
| RodColeman | 0:0791c1fece8e | 710 | |
| RodColeman | 0:0791c1fece8e | 711 | LWIP_DEBUGF (ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: incoming ARP request\n")); |
| RodColeman | 0:0791c1fece8e | 712 | /* ARP request for our address? */ |
| RodColeman | 0:0791c1fece8e | 713 | if (for_us) { |
| RodColeman | 0:0791c1fece8e | 714 | |
| RodColeman | 0:0791c1fece8e | 715 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: replying to ARP request for our IP address\n")); |
| RodColeman | 0:0791c1fece8e | 716 | /* Re-use pbuf to send ARP reply. |
| RodColeman | 0:0791c1fece8e | 717 | Since we are re-using an existing pbuf, we can't call etharp_raw since |
| RodColeman | 0:0791c1fece8e | 718 | that would allocate a new pbuf. */ |
| RodColeman | 0:0791c1fece8e | 719 | hdr->opcode = htons(ARP_REPLY); |
| RodColeman | 0:0791c1fece8e | 720 | |
| RodColeman | 0:0791c1fece8e | 721 | hdr->dipaddr = hdr->sipaddr; |
| RodColeman | 0:0791c1fece8e | 722 | SMEMCPY(&hdr->sipaddr, &netif->ip_addr, sizeof(hdr->sipaddr)); |
| RodColeman | 0:0791c1fece8e | 723 | |
| RodColeman | 0:0791c1fece8e | 724 | LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!", |
| RodColeman | 0:0791c1fece8e | 725 | (netif->hwaddr_len == ETHARP_HWADDR_LEN)); |
| RodColeman | 0:0791c1fece8e | 726 | i = ETHARP_HWADDR_LEN; |
| RodColeman | 0:0791c1fece8e | 727 | #if LWIP_AUTOIP |
| RodColeman | 0:0791c1fece8e | 728 | /* If we are using Link-Local, ARP packets must be broadcast on the |
| RodColeman | 0:0791c1fece8e | 729 | * link layer. (See RFC3927 Section 2.5) */ |
| RodColeman | 0:0791c1fece8e | 730 | ethdst_hwaddr = ((netif->autoip != NULL) && (netif->autoip->state != AUTOIP_STATE_OFF)) ? (u8_t*)(ethbroadcast.addr) : hdr->shwaddr.addr; |
| RodColeman | 0:0791c1fece8e | 731 | #endif /* LWIP_AUTOIP */ |
| RodColeman | 0:0791c1fece8e | 732 | |
| RodColeman | 0:0791c1fece8e | 733 | while(i > 0) { |
| RodColeman | 0:0791c1fece8e | 734 | i--; |
| RodColeman | 0:0791c1fece8e | 735 | hdr->dhwaddr.addr[i] = hdr->shwaddr.addr[i]; |
| RodColeman | 0:0791c1fece8e | 736 | #if LWIP_AUTOIP |
| RodColeman | 0:0791c1fece8e | 737 | ethhdr->dest.addr[i] = ethdst_hwaddr[i]; |
| RodColeman | 0:0791c1fece8e | 738 | #else /* LWIP_AUTOIP */ |
| RodColeman | 0:0791c1fece8e | 739 | ethhdr->dest.addr[i] = hdr->shwaddr.addr[i]; |
| RodColeman | 0:0791c1fece8e | 740 | #endif /* LWIP_AUTOIP */ |
| RodColeman | 0:0791c1fece8e | 741 | hdr->shwaddr.addr[i] = ethaddr->addr[i]; |
| RodColeman | 0:0791c1fece8e | 742 | ethhdr->src.addr[i] = ethaddr->addr[i]; |
| RodColeman | 0:0791c1fece8e | 743 | } |
| RodColeman | 0:0791c1fece8e | 744 | |
| RodColeman | 0:0791c1fece8e | 745 | /* hwtype, hwaddr_len, proto, protolen and the type in the ethernet header |
| RodColeman | 0:0791c1fece8e | 746 | are already correct, we tested that before */ |
| RodColeman | 0:0791c1fece8e | 747 | |
| RodColeman | 0:0791c1fece8e | 748 | /* return ARP reply */ |
| RodColeman | 0:0791c1fece8e | 749 | netif->linkoutput(netif, p); |
| RodColeman | 0:0791c1fece8e | 750 | /* we are not configured? */ |
| RodColeman | 0:0791c1fece8e | 751 | } else if (netif->ip_addr.addr == 0) { |
| RodColeman | 0:0791c1fece8e | 752 | /* { for_us == 0 and netif->ip_addr.addr == 0 } */ |
| RodColeman | 0:0791c1fece8e | 753 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: we are unconfigured, ARP request ignored.\n")); |
| RodColeman | 0:0791c1fece8e | 754 | /* request was not directed to us */ |
| RodColeman | 0:0791c1fece8e | 755 | } else { |
| RodColeman | 0:0791c1fece8e | 756 | /* { for_us == 0 and netif->ip_addr.addr != 0 } */ |
| RodColeman | 0:0791c1fece8e | 757 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: ARP request was not for us.\n")); |
| RodColeman | 0:0791c1fece8e | 758 | } |
| RodColeman | 0:0791c1fece8e | 759 | break; |
| RodColeman | 0:0791c1fece8e | 760 | case ARP_REPLY: |
| RodColeman | 0:0791c1fece8e | 761 | /* ARP reply. We already updated the ARP cache earlier. */ |
| RodColeman | 0:0791c1fece8e | 762 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: incoming ARP reply\n")); |
| RodColeman | 0:0791c1fece8e | 763 | #if (LWIP_DHCP && DHCP_DOES_ARP_CHECK) |
| RodColeman | 0:0791c1fece8e | 764 | /* DHCP wants to know about ARP replies from any host with an |
| RodColeman | 0:0791c1fece8e | 765 | * IP address also offered to us by the DHCP server. We do not |
| RodColeman | 0:0791c1fece8e | 766 | * want to take a duplicate IP address on a single network. |
| RodColeman | 0:0791c1fece8e | 767 | * @todo How should we handle redundant (fail-over) interfaces? */ |
| RodColeman | 0:0791c1fece8e | 768 | dhcp_arp_reply(netif, &sipaddr); |
| RodColeman | 0:0791c1fece8e | 769 | #endif |
| RodColeman | 0:0791c1fece8e | 770 | break; |
| RodColeman | 0:0791c1fece8e | 771 | default: |
| RodColeman | 0:0791c1fece8e | 772 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_arp_input: ARP unknown opcode type %"S16_F"\n", htons(hdr->opcode))); |
| RodColeman | 0:0791c1fece8e | 773 | ETHARP_STATS_INC(etharp.err); |
| RodColeman | 0:0791c1fece8e | 774 | break; |
| RodColeman | 0:0791c1fece8e | 775 | } |
| RodColeman | 0:0791c1fece8e | 776 | /* free ARP packet */ |
| RodColeman | 0:0791c1fece8e | 777 | pbuf_free(p); |
| RodColeman | 0:0791c1fece8e | 778 | } |
| RodColeman | 0:0791c1fece8e | 779 | |
| RodColeman | 0:0791c1fece8e | 780 | /** |
| RodColeman | 0:0791c1fece8e | 781 | * Resolve and fill-in Ethernet address header for outgoing IP packet. |
| RodColeman | 0:0791c1fece8e | 782 | * |
| RodColeman | 0:0791c1fece8e | 783 | * For IP multicast and broadcast, corresponding Ethernet addresses |
| RodColeman | 0:0791c1fece8e | 784 | * are selected and the packet is transmitted on the link. |
| RodColeman | 0:0791c1fece8e | 785 | * |
| RodColeman | 0:0791c1fece8e | 786 | * For unicast addresses, the packet is submitted to etharp_query(). In |
| RodColeman | 0:0791c1fece8e | 787 | * case the IP address is outside the local network, the IP address of |
| RodColeman | 0:0791c1fece8e | 788 | * the gateway is used. |
| RodColeman | 0:0791c1fece8e | 789 | * |
| RodColeman | 0:0791c1fece8e | 790 | * @param netif The lwIP network interface which the IP packet will be sent on. |
| RodColeman | 0:0791c1fece8e | 791 | * @param q The pbuf(s) containing the IP packet to be sent. |
| RodColeman | 0:0791c1fece8e | 792 | * @param ipaddr The IP address of the packet destination. |
| RodColeman | 0:0791c1fece8e | 793 | * |
| RodColeman | 0:0791c1fece8e | 794 | * @return |
| RodColeman | 0:0791c1fece8e | 795 | * - ERR_RTE No route to destination (no gateway to external networks), |
| RodColeman | 0:0791c1fece8e | 796 | * or the return type of either etharp_query() or etharp_send_ip(). |
| RodColeman | 0:0791c1fece8e | 797 | */ |
| RodColeman | 0:0791c1fece8e | 798 | err_t |
| RodColeman | 0:0791c1fece8e | 799 | etharp_output(struct netif *netif, struct pbuf *q, struct ip_addr *ipaddr) |
| RodColeman | 0:0791c1fece8e | 800 | { |
| RodColeman | 0:0791c1fece8e | 801 | struct eth_addr *dest, mcastaddr; |
| RodColeman | 0:0791c1fece8e | 802 | |
| RodColeman | 0:0791c1fece8e | 803 | /* make room for Ethernet header - should not fail */ |
| RodColeman | 0:0791c1fece8e | 804 | if (pbuf_header(q, sizeof(struct eth_hdr)) != 0) { |
| RodColeman | 0:0791c1fece8e | 805 | /* bail out */ |
| RodColeman | 0:0791c1fece8e | 806 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | 2, ("etharp_output: could not allocate room for header.\n")); |
| RodColeman | 0:0791c1fece8e | 807 | LINK_STATS_INC(link.lenerr); |
| RodColeman | 0:0791c1fece8e | 808 | return ERR_BUF; |
| RodColeman | 0:0791c1fece8e | 809 | } |
| RodColeman | 0:0791c1fece8e | 810 | |
| RodColeman | 0:0791c1fece8e | 811 | /* assume unresolved Ethernet address */ |
| RodColeman | 0:0791c1fece8e | 812 | dest = NULL; |
| RodColeman | 0:0791c1fece8e | 813 | /* Determine on destination hardware address. Broadcasts and multicasts |
| RodColeman | 0:0791c1fece8e | 814 | * are special, other IP addresses are looked up in the ARP table. */ |
| RodColeman | 0:0791c1fece8e | 815 | |
| RodColeman | 0:0791c1fece8e | 816 | /* broadcast destination IP address? */ |
| RodColeman | 0:0791c1fece8e | 817 | if (ip_addr_isbroadcast(ipaddr, netif)) { |
| RodColeman | 0:0791c1fece8e | 818 | /* broadcast on Ethernet also */ |
| RodColeman | 0:0791c1fece8e | 819 | dest = (struct eth_addr *)ðbroadcast; |
| RodColeman | 0:0791c1fece8e | 820 | /* multicast destination IP address? */ |
| RodColeman | 0:0791c1fece8e | 821 | } else if (ip_addr_ismulticast(ipaddr)) { |
| RodColeman | 0:0791c1fece8e | 822 | /* Hash IP multicast address to MAC address.*/ |
| RodColeman | 0:0791c1fece8e | 823 | mcastaddr.addr[0] = 0x01; |
| RodColeman | 0:0791c1fece8e | 824 | mcastaddr.addr[1] = 0x00; |
| RodColeman | 0:0791c1fece8e | 825 | mcastaddr.addr[2] = 0x5e; |
| RodColeman | 0:0791c1fece8e | 826 | mcastaddr.addr[3] = ip4_addr2(ipaddr) & 0x7f; |
| RodColeman | 0:0791c1fece8e | 827 | mcastaddr.addr[4] = ip4_addr3(ipaddr); |
| RodColeman | 0:0791c1fece8e | 828 | mcastaddr.addr[5] = ip4_addr4(ipaddr); |
| RodColeman | 0:0791c1fece8e | 829 | /* destination Ethernet address is multicast */ |
| RodColeman | 0:0791c1fece8e | 830 | dest = &mcastaddr; |
| RodColeman | 0:0791c1fece8e | 831 | /* unicast destination IP address? */ |
| RodColeman | 0:0791c1fece8e | 832 | } else { |
| RodColeman | 0:0791c1fece8e | 833 | /* outside local network? */ |
| RodColeman | 0:0791c1fece8e | 834 | if (!ip_addr_netcmp(ipaddr, &(netif->ip_addr), &(netif->netmask))) { |
| RodColeman | 0:0791c1fece8e | 835 | /* interface has default gateway? */ |
| RodColeman | 0:0791c1fece8e | 836 | if (netif->gw.addr != 0) { |
| RodColeman | 0:0791c1fece8e | 837 | /* send to hardware address of default gateway IP address */ |
| RodColeman | 0:0791c1fece8e | 838 | ipaddr = &(netif->gw); |
| RodColeman | 0:0791c1fece8e | 839 | /* no default gateway available */ |
| RodColeman | 0:0791c1fece8e | 840 | } else { |
| RodColeman | 0:0791c1fece8e | 841 | /* no route to destination error (default gateway missing) */ |
| RodColeman | 0:0791c1fece8e | 842 | return ERR_RTE; |
| RodColeman | 0:0791c1fece8e | 843 | } |
| RodColeman | 0:0791c1fece8e | 844 | } |
| RodColeman | 0:0791c1fece8e | 845 | /* queue on destination Ethernet address belonging to ipaddr */ |
| RodColeman | 0:0791c1fece8e | 846 | return etharp_query(netif, ipaddr, q); |
| RodColeman | 0:0791c1fece8e | 847 | } |
| RodColeman | 0:0791c1fece8e | 848 | |
| RodColeman | 0:0791c1fece8e | 849 | /* continuation for multicast/broadcast destinations */ |
| RodColeman | 0:0791c1fece8e | 850 | /* obtain source Ethernet address of the given interface */ |
| RodColeman | 0:0791c1fece8e | 851 | /* send packet directly on the link */ |
| RodColeman | 0:0791c1fece8e | 852 | return etharp_send_ip(netif, q, (struct eth_addr*)(netif->hwaddr), dest); |
| RodColeman | 0:0791c1fece8e | 853 | } |
| RodColeman | 0:0791c1fece8e | 854 | |
| RodColeman | 0:0791c1fece8e | 855 | /** |
| RodColeman | 0:0791c1fece8e | 856 | * Send an ARP request for the given IP address and/or queue a packet. |
| RodColeman | 0:0791c1fece8e | 857 | * |
| RodColeman | 0:0791c1fece8e | 858 | * If the IP address was not yet in the cache, a pending ARP cache entry |
| RodColeman | 0:0791c1fece8e | 859 | * is added and an ARP request is sent for the given address. The packet |
| RodColeman | 0:0791c1fece8e | 860 | * is queued on this entry. |
| RodColeman | 0:0791c1fece8e | 861 | * |
| RodColeman | 0:0791c1fece8e | 862 | * If the IP address was already pending in the cache, a new ARP request |
| RodColeman | 0:0791c1fece8e | 863 | * is sent for the given address. The packet is queued on this entry. |
| RodColeman | 0:0791c1fece8e | 864 | * |
| RodColeman | 0:0791c1fece8e | 865 | * If the IP address was already stable in the cache, and a packet is |
| RodColeman | 0:0791c1fece8e | 866 | * given, it is directly sent and no ARP request is sent out. |
| RodColeman | 0:0791c1fece8e | 867 | * |
| RodColeman | 0:0791c1fece8e | 868 | * If the IP address was already stable in the cache, and no packet is |
| RodColeman | 0:0791c1fece8e | 869 | * given, an ARP request is sent out. |
| RodColeman | 0:0791c1fece8e | 870 | * |
| RodColeman | 0:0791c1fece8e | 871 | * @param netif The lwIP network interface on which ipaddr |
| RodColeman | 0:0791c1fece8e | 872 | * must be queried for. |
| RodColeman | 0:0791c1fece8e | 873 | * @param ipaddr The IP address to be resolved. |
| RodColeman | 0:0791c1fece8e | 874 | * @param q If non-NULL, a pbuf that must be delivered to the IP address. |
| RodColeman | 0:0791c1fece8e | 875 | * q is not freed by this function. |
| RodColeman | 0:0791c1fece8e | 876 | * |
| RodColeman | 0:0791c1fece8e | 877 | * @note q must only be ONE packet, not a packet queue! |
| RodColeman | 0:0791c1fece8e | 878 | * |
| RodColeman | 0:0791c1fece8e | 879 | * @return |
| RodColeman | 0:0791c1fece8e | 880 | * - ERR_BUF Could not make room for Ethernet header. |
| RodColeman | 0:0791c1fece8e | 881 | * - ERR_MEM Hardware address unknown, and no more ARP entries available |
| RodColeman | 0:0791c1fece8e | 882 | * to query for address or queue the packet. |
| RodColeman | 0:0791c1fece8e | 883 | * - ERR_MEM Could not queue packet due to memory shortage. |
| RodColeman | 0:0791c1fece8e | 884 | * - ERR_RTE No route to destination (no gateway to external networks). |
| RodColeman | 0:0791c1fece8e | 885 | * - ERR_ARG Non-unicast address given, those will not appear in ARP cache. |
| RodColeman | 0:0791c1fece8e | 886 | * |
| RodColeman | 0:0791c1fece8e | 887 | */ |
| RodColeman | 0:0791c1fece8e | 888 | err_t |
| RodColeman | 0:0791c1fece8e | 889 | etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q) |
| RodColeman | 0:0791c1fece8e | 890 | { |
| RodColeman | 0:0791c1fece8e | 891 | struct eth_addr * srcaddr = (struct eth_addr *)netif->hwaddr; |
| RodColeman | 0:0791c1fece8e | 892 | err_t result = ERR_MEM; |
| RodColeman | 0:0791c1fece8e | 893 | s8_t i; /* ARP entry index */ |
| RodColeman | 0:0791c1fece8e | 894 | |
| RodColeman | 0:0791c1fece8e | 895 | /* non-unicast address? */ |
| RodColeman | 0:0791c1fece8e | 896 | if (ip_addr_isbroadcast(ipaddr, netif) || |
| RodColeman | 0:0791c1fece8e | 897 | ip_addr_ismulticast(ipaddr) || |
| RodColeman | 0:0791c1fece8e | 898 | ip_addr_isany(ipaddr)) { |
| RodColeman | 0:0791c1fece8e | 899 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: will not add non-unicast IP address to ARP cache\n")); |
| RodColeman | 0:0791c1fece8e | 900 | return ERR_ARG; |
| RodColeman | 0:0791c1fece8e | 901 | } |
| RodColeman | 0:0791c1fece8e | 902 | |
| RodColeman | 0:0791c1fece8e | 903 | /* find entry in ARP cache, ask to create entry if queueing packet */ |
| RodColeman | 0:0791c1fece8e | 904 | #if LWIP_NETIF_HWADDRHINT |
| RodColeman | 0:0791c1fece8e | 905 | i = find_entry(ipaddr, ETHARP_TRY_HARD, netif); |
| RodColeman | 0:0791c1fece8e | 906 | #else /* LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 907 | i = find_entry(ipaddr, ETHARP_TRY_HARD); |
| RodColeman | 0:0791c1fece8e | 908 | #endif /* LWIP_NETIF_HWADDRHINT */ |
| RodColeman | 0:0791c1fece8e | 909 | |
| RodColeman | 0:0791c1fece8e | 910 | /* could not find or create entry? */ |
| RodColeman | 0:0791c1fece8e | 911 | if (i < 0) { |
| RodColeman | 0:0791c1fece8e | 912 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: could not create ARP entry\n")); |
| RodColeman | 0:0791c1fece8e | 913 | if (q) { |
| RodColeman | 0:0791c1fece8e | 914 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: packet dropped\n")); |
| RodColeman | 0:0791c1fece8e | 915 | ETHARP_STATS_INC(etharp.memerr); |
| RodColeman | 0:0791c1fece8e | 916 | } |
| RodColeman | 0:0791c1fece8e | 917 | return (err_t)i; |
| RodColeman | 0:0791c1fece8e | 918 | } |
| RodColeman | 0:0791c1fece8e | 919 | |
| RodColeman | 0:0791c1fece8e | 920 | /* mark a fresh entry as pending (we just sent a request) */ |
| RodColeman | 0:0791c1fece8e | 921 | if (arp_table[i].state == ETHARP_STATE_EMPTY) { |
| RodColeman | 0:0791c1fece8e | 922 | arp_table[i].state = ETHARP_STATE_PENDING; |
| RodColeman | 0:0791c1fece8e | 923 | } |
| RodColeman | 0:0791c1fece8e | 924 | |
| RodColeman | 0:0791c1fece8e | 925 | /* { i is either a STABLE or (new or existing) PENDING entry } */ |
| RodColeman | 0:0791c1fece8e | 926 | LWIP_ASSERT("arp_table[i].state == PENDING or STABLE", |
| RodColeman | 0:0791c1fece8e | 927 | ((arp_table[i].state == ETHARP_STATE_PENDING) || |
| RodColeman | 0:0791c1fece8e | 928 | (arp_table[i].state == ETHARP_STATE_STABLE))); |
| RodColeman | 0:0791c1fece8e | 929 | |
| RodColeman | 0:0791c1fece8e | 930 | /* do we have a pending entry? or an implicit query request? */ |
| RodColeman | 0:0791c1fece8e | 931 | if ((arp_table[i].state == ETHARP_STATE_PENDING) || (q == NULL)) { |
| RodColeman | 0:0791c1fece8e | 932 | /* try to resolve it; send out ARP request */ |
| RodColeman | 0:0791c1fece8e | 933 | result = etharp_request(netif, ipaddr); |
| RodColeman | 0:0791c1fece8e | 934 | if (result != ERR_OK) { |
| RodColeman | 0:0791c1fece8e | 935 | /* ARP request couldn't be sent */ |
| RodColeman | 0:0791c1fece8e | 936 | /* We don't re-send arp request in etharp_tmr, but we still queue packets, |
| RodColeman | 0:0791c1fece8e | 937 | since this failure could be temporary, and the next packet calling |
| RodColeman | 0:0791c1fece8e | 938 | etharp_query again could lead to sending the queued packets. */ |
| RodColeman | 0:0791c1fece8e | 939 | } |
| RodColeman | 0:0791c1fece8e | 940 | } |
| RodColeman | 0:0791c1fece8e | 941 | |
| RodColeman | 0:0791c1fece8e | 942 | /* packet given? */ |
| RodColeman | 0:0791c1fece8e | 943 | if (q != NULL) { |
| RodColeman | 0:0791c1fece8e | 944 | /* stable entry? */ |
| RodColeman | 0:0791c1fece8e | 945 | if (arp_table[i].state == ETHARP_STATE_STABLE) { |
| RodColeman | 0:0791c1fece8e | 946 | /* we have a valid IP->Ethernet address mapping */ |
| RodColeman | 0:0791c1fece8e | 947 | /* send the packet */ |
| RodColeman | 0:0791c1fece8e | 948 | result = etharp_send_ip(netif, q, srcaddr, &(arp_table[i].ethaddr)); |
| RodColeman | 0:0791c1fece8e | 949 | /* pending entry? (either just created or already pending */ |
| RodColeman | 0:0791c1fece8e | 950 | } else if (arp_table[i].state == ETHARP_STATE_PENDING) { |
| RodColeman | 0:0791c1fece8e | 951 | #if ARP_QUEUEING /* queue the given q packet */ |
| RodColeman | 0:0791c1fece8e | 952 | struct pbuf *p; |
| RodColeman | 0:0791c1fece8e | 953 | int copy_needed = 0; |
| RodColeman | 0:0791c1fece8e | 954 | /* IF q includes a PBUF_REF, PBUF_POOL or PBUF_RAM, we have no choice but |
| RodColeman | 0:0791c1fece8e | 955 | * to copy the whole queue into a new PBUF_RAM (see bug #11400) |
| RodColeman | 0:0791c1fece8e | 956 | * PBUF_ROMs can be left as they are, since ROM must not get changed. */ |
| RodColeman | 0:0791c1fece8e | 957 | p = q; |
| RodColeman | 0:0791c1fece8e | 958 | while (p) { |
| RodColeman | 0:0791c1fece8e | 959 | LWIP_ASSERT("no packet queues allowed!", (p->len != p->tot_len) || (p->next == 0)); |
| RodColeman | 0:0791c1fece8e | 960 | if(p->type != PBUF_ROM) { |
| RodColeman | 0:0791c1fece8e | 961 | copy_needed = 1; |
| RodColeman | 0:0791c1fece8e | 962 | break; |
| RodColeman | 0:0791c1fece8e | 963 | } |
| RodColeman | 0:0791c1fece8e | 964 | p = p->next; |
| RodColeman | 0:0791c1fece8e | 965 | } |
| RodColeman | 0:0791c1fece8e | 966 | if(copy_needed) { |
| RodColeman | 0:0791c1fece8e | 967 | /* copy the whole packet into new pbufs */ |
| RodColeman | 0:0791c1fece8e | 968 | p = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM); |
| RodColeman | 0:0791c1fece8e | 969 | if(p != NULL) { |
| RodColeman | 0:0791c1fece8e | 970 | if (pbuf_copy(p, q) != ERR_OK) { |
| RodColeman | 0:0791c1fece8e | 971 | pbuf_free(p); |
| RodColeman | 0:0791c1fece8e | 972 | p = NULL; |
| RodColeman | 0:0791c1fece8e | 973 | } |
| RodColeman | 0:0791c1fece8e | 974 | } |
| RodColeman | 0:0791c1fece8e | 975 | } else { |
| RodColeman | 0:0791c1fece8e | 976 | /* referencing the old pbuf is enough */ |
| RodColeman | 0:0791c1fece8e | 977 | p = q; |
| RodColeman | 0:0791c1fece8e | 978 | pbuf_ref(p); |
| RodColeman | 0:0791c1fece8e | 979 | } |
| RodColeman | 0:0791c1fece8e | 980 | /* packet could be taken over? */ |
| RodColeman | 0:0791c1fece8e | 981 | if (p != NULL) { |
| RodColeman | 0:0791c1fece8e | 982 | /* queue packet ... */ |
| RodColeman | 0:0791c1fece8e | 983 | struct etharp_q_entry *new_entry; |
| RodColeman | 0:0791c1fece8e | 984 | /* allocate a new arp queue entry */ |
| RodColeman | 0:0791c1fece8e | 985 | new_entry = memp_malloc(MEMP_ARP_QUEUE); |
| RodColeman | 0:0791c1fece8e | 986 | if (new_entry != NULL) { |
| RodColeman | 0:0791c1fece8e | 987 | new_entry->next = 0; |
| RodColeman | 0:0791c1fece8e | 988 | new_entry->p = p; |
| RodColeman | 0:0791c1fece8e | 989 | if(arp_table[i].q != NULL) { |
| RodColeman | 0:0791c1fece8e | 990 | /* queue was already existent, append the new entry to the end */ |
| RodColeman | 0:0791c1fece8e | 991 | struct etharp_q_entry *r; |
| RodColeman | 0:0791c1fece8e | 992 | r = arp_table[i].q; |
| RodColeman | 0:0791c1fece8e | 993 | while (r->next != NULL) { |
| RodColeman | 0:0791c1fece8e | 994 | r = r->next; |
| RodColeman | 0:0791c1fece8e | 995 | } |
| RodColeman | 0:0791c1fece8e | 996 | r->next = new_entry; |
| RodColeman | 0:0791c1fece8e | 997 | } else { |
| RodColeman | 0:0791c1fece8e | 998 | /* queue did not exist, first item in queue */ |
| RodColeman | 0:0791c1fece8e | 999 | arp_table[i].q = new_entry; |
| RodColeman | 0:0791c1fece8e | 1000 | } |
| RodColeman | 0:0791c1fece8e | 1001 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: queued packet %p on ARP entry %"S16_F"\n", (void *)q, (s16_t)i)); |
| RodColeman | 0:0791c1fece8e | 1002 | result = ERR_OK; |
| RodColeman | 0:0791c1fece8e | 1003 | } else { |
| RodColeman | 0:0791c1fece8e | 1004 | /* the pool MEMP_ARP_QUEUE is empty */ |
| RodColeman | 0:0791c1fece8e | 1005 | pbuf_free(p); |
| RodColeman | 0:0791c1fece8e | 1006 | 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)); |
| RodColeman | 0:0791c1fece8e | 1007 | /* { result == ERR_MEM } through initialization */ |
| RodColeman | 0:0791c1fece8e | 1008 | } |
| RodColeman | 0:0791c1fece8e | 1009 | } else { |
| RodColeman | 0:0791c1fece8e | 1010 | ETHARP_STATS_INC(etharp.memerr); |
| RodColeman | 0:0791c1fece8e | 1011 | 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)); |
| RodColeman | 0:0791c1fece8e | 1012 | /* { result == ERR_MEM } through initialization */ |
| RodColeman | 0:0791c1fece8e | 1013 | } |
| RodColeman | 0:0791c1fece8e | 1014 | #else /* ARP_QUEUEING == 0 */ |
| RodColeman | 0:0791c1fece8e | 1015 | /* q && state == PENDING && ARP_QUEUEING == 0 => result = ERR_MEM */ |
| RodColeman | 0:0791c1fece8e | 1016 | /* { result == ERR_MEM } through initialization */ |
| RodColeman | 0:0791c1fece8e | 1017 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_query: Ethernet destination address unknown, queueing disabled, packet %p dropped\n", (void *)q)); |
| RodColeman | 0:0791c1fece8e | 1018 | #endif |
| RodColeman | 0:0791c1fece8e | 1019 | } |
| RodColeman | 0:0791c1fece8e | 1020 | } |
| RodColeman | 0:0791c1fece8e | 1021 | return result; |
| RodColeman | 0:0791c1fece8e | 1022 | } |
| RodColeman | 0:0791c1fece8e | 1023 | |
| RodColeman | 0:0791c1fece8e | 1024 | /** |
| RodColeman | 0:0791c1fece8e | 1025 | * Send a raw ARP packet (opcode and all addresses can be modified) |
| RodColeman | 0:0791c1fece8e | 1026 | * |
| RodColeman | 0:0791c1fece8e | 1027 | * @param netif the lwip network interface on which to send the ARP packet |
| RodColeman | 0:0791c1fece8e | 1028 | * @param ethsrc_addr the source MAC address for the ethernet header |
| RodColeman | 0:0791c1fece8e | 1029 | * @param ethdst_addr the destination MAC address for the ethernet header |
| RodColeman | 0:0791c1fece8e | 1030 | * @param hwsrc_addr the source MAC address for the ARP protocol header |
| RodColeman | 0:0791c1fece8e | 1031 | * @param ipsrc_addr the source IP address for the ARP protocol header |
| RodColeman | 0:0791c1fece8e | 1032 | * @param hwdst_addr the destination MAC address for the ARP protocol header |
| RodColeman | 0:0791c1fece8e | 1033 | * @param ipdst_addr the destination IP address for the ARP protocol header |
| RodColeman | 0:0791c1fece8e | 1034 | * @param opcode the type of the ARP packet |
| RodColeman | 0:0791c1fece8e | 1035 | * @return ERR_OK if the ARP packet has been sent |
| RodColeman | 0:0791c1fece8e | 1036 | * ERR_MEM if the ARP packet couldn't be allocated |
| RodColeman | 0:0791c1fece8e | 1037 | * any other err_t on failure |
| RodColeman | 0:0791c1fece8e | 1038 | */ |
| RodColeman | 0:0791c1fece8e | 1039 | #if !LWIP_AUTOIP |
| RodColeman | 0:0791c1fece8e | 1040 | static |
| RodColeman | 0:0791c1fece8e | 1041 | #endif /* LWIP_AUTOIP */ |
| RodColeman | 0:0791c1fece8e | 1042 | err_t |
| RodColeman | 0:0791c1fece8e | 1043 | etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, |
| RodColeman | 0:0791c1fece8e | 1044 | const struct eth_addr *ethdst_addr, |
| RodColeman | 0:0791c1fece8e | 1045 | const struct eth_addr *hwsrc_addr, const struct ip_addr *ipsrc_addr, |
| RodColeman | 0:0791c1fece8e | 1046 | const struct eth_addr *hwdst_addr, const struct ip_addr *ipdst_addr, |
| RodColeman | 0:0791c1fece8e | 1047 | const u16_t opcode) |
| RodColeman | 0:0791c1fece8e | 1048 | { |
| RodColeman | 0:0791c1fece8e | 1049 | struct pbuf *p; |
| RodColeman | 0:0791c1fece8e | 1050 | err_t result = ERR_OK; |
| RodColeman | 0:0791c1fece8e | 1051 | u8_t k; /* ARP entry index */ |
| RodColeman | 0:0791c1fece8e | 1052 | struct eth_hdr *ethhdr; |
| RodColeman | 0:0791c1fece8e | 1053 | struct etharp_hdr *hdr; |
| RodColeman | 0:0791c1fece8e | 1054 | #if LWIP_AUTOIP |
| RodColeman | 0:0791c1fece8e | 1055 | const u8_t * ethdst_hwaddr; |
| RodColeman | 0:0791c1fece8e | 1056 | #endif /* LWIP_AUTOIP */ |
| RodColeman | 0:0791c1fece8e | 1057 | |
| RodColeman | 0:0791c1fece8e | 1058 | /* allocate a pbuf for the outgoing ARP request packet */ |
| RodColeman | 0:0791c1fece8e | 1059 | p = pbuf_alloc(PBUF_RAW, SIZEOF_ETHARP_PACKET, PBUF_RAM); |
| RodColeman | 0:0791c1fece8e | 1060 | /* could allocate a pbuf for an ARP request? */ |
| RodColeman | 0:0791c1fece8e | 1061 | if (p == NULL) { |
| RodColeman | 0:0791c1fece8e | 1062 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | 2, ("etharp_raw: could not allocate pbuf for ARP request.\n")); |
| RodColeman | 0:0791c1fece8e | 1063 | ETHARP_STATS_INC(etharp.memerr); |
| RodColeman | 0:0791c1fece8e | 1064 | return ERR_MEM; |
| RodColeman | 0:0791c1fece8e | 1065 | } |
| RodColeman | 0:0791c1fece8e | 1066 | LWIP_ASSERT("check that first pbuf can hold struct etharp_hdr", |
| RodColeman | 0:0791c1fece8e | 1067 | (p->len >= SIZEOF_ETHARP_PACKET)); |
| RodColeman | 0:0791c1fece8e | 1068 | |
| RodColeman | 0:0791c1fece8e | 1069 | ethhdr = (struct eth_hdr *)p->payload; |
| RodColeman | 0:0791c1fece8e | 1070 | hdr = (struct etharp_hdr *)((u8_t*)ethhdr + SIZEOF_ETH_HDR); |
| RodColeman | 0:0791c1fece8e | 1071 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_raw: sending raw ARP packet.\n")); |
| RodColeman | 0:0791c1fece8e | 1072 | hdr->opcode = htons(opcode); |
| RodColeman | 0:0791c1fece8e | 1073 | |
| RodColeman | 0:0791c1fece8e | 1074 | LWIP_ASSERT("netif->hwaddr_len must be the same as ETHARP_HWADDR_LEN for etharp!", |
| RodColeman | 0:0791c1fece8e | 1075 | (netif->hwaddr_len == ETHARP_HWADDR_LEN)); |
| RodColeman | 0:0791c1fece8e | 1076 | k = ETHARP_HWADDR_LEN; |
| RodColeman | 0:0791c1fece8e | 1077 | #if LWIP_AUTOIP |
| RodColeman | 0:0791c1fece8e | 1078 | /* If we are using Link-Local, ARP packets must be broadcast on the |
| RodColeman | 0:0791c1fece8e | 1079 | * link layer. (See RFC3927 Section 2.5) */ |
| RodColeman | 0:0791c1fece8e | 1080 | ethdst_hwaddr = ((netif->autoip != NULL) && (netif->autoip->state != AUTOIP_STATE_OFF)) ? (u8_t*)(ethbroadcast.addr) : ethdst_addr->addr; |
| RodColeman | 0:0791c1fece8e | 1081 | #endif /* LWIP_AUTOIP */ |
| RodColeman | 0:0791c1fece8e | 1082 | /* Write MAC-Addresses (combined loop for both headers) */ |
| RodColeman | 0:0791c1fece8e | 1083 | while(k > 0) { |
| RodColeman | 0:0791c1fece8e | 1084 | k--; |
| RodColeman | 0:0791c1fece8e | 1085 | /* Write the ARP MAC-Addresses */ |
| RodColeman | 0:0791c1fece8e | 1086 | hdr->shwaddr.addr[k] = hwsrc_addr->addr[k]; |
| RodColeman | 0:0791c1fece8e | 1087 | hdr->dhwaddr.addr[k] = hwdst_addr->addr[k]; |
| RodColeman | 0:0791c1fece8e | 1088 | /* Write the Ethernet MAC-Addresses */ |
| RodColeman | 0:0791c1fece8e | 1089 | #if LWIP_AUTOIP |
| RodColeman | 0:0791c1fece8e | 1090 | ethhdr->dest.addr[k] = ethdst_hwaddr[k]; |
| RodColeman | 0:0791c1fece8e | 1091 | #else /* LWIP_AUTOIP */ |
| RodColeman | 0:0791c1fece8e | 1092 | ethhdr->dest.addr[k] = ethdst_addr->addr[k]; |
| RodColeman | 0:0791c1fece8e | 1093 | #endif /* LWIP_AUTOIP */ |
| RodColeman | 0:0791c1fece8e | 1094 | ethhdr->src.addr[k] = ethsrc_addr->addr[k]; |
| RodColeman | 0:0791c1fece8e | 1095 | } |
| RodColeman | 0:0791c1fece8e | 1096 | hdr->sipaddr = *(struct ip_addr2 *)ipsrc_addr; |
| RodColeman | 0:0791c1fece8e | 1097 | hdr->dipaddr = *(struct ip_addr2 *)ipdst_addr; |
| RodColeman | 0:0791c1fece8e | 1098 | |
| RodColeman | 0:0791c1fece8e | 1099 | hdr->hwtype = htons(HWTYPE_ETHERNET); |
| RodColeman | 0:0791c1fece8e | 1100 | hdr->proto = htons(ETHTYPE_IP); |
| RodColeman | 0:0791c1fece8e | 1101 | /* set hwlen and protolen together */ |
| RodColeman | 0:0791c1fece8e | 1102 | hdr->_hwlen_protolen = htons((ETHARP_HWADDR_LEN << 8) | sizeof(struct ip_addr)); |
| RodColeman | 0:0791c1fece8e | 1103 | |
| RodColeman | 0:0791c1fece8e | 1104 | ethhdr->type = htons(ETHTYPE_ARP); |
| RodColeman | 0:0791c1fece8e | 1105 | /* send ARP query */ |
| RodColeman | 0:0791c1fece8e | 1106 | result = netif->linkoutput(netif, p); |
| RodColeman | 0:0791c1fece8e | 1107 | ETHARP_STATS_INC(etharp.xmit); |
| RodColeman | 0:0791c1fece8e | 1108 | /* free ARP query packet */ |
| RodColeman | 0:0791c1fece8e | 1109 | pbuf_free(p); |
| RodColeman | 0:0791c1fece8e | 1110 | p = NULL; |
| RodColeman | 0:0791c1fece8e | 1111 | /* could not allocate pbuf for ARP request */ |
| RodColeman | 0:0791c1fece8e | 1112 | |
| RodColeman | 0:0791c1fece8e | 1113 | return result; |
| RodColeman | 0:0791c1fece8e | 1114 | } |
| RodColeman | 0:0791c1fece8e | 1115 | |
| RodColeman | 0:0791c1fece8e | 1116 | /** |
| RodColeman | 0:0791c1fece8e | 1117 | * Send an ARP request packet asking for ipaddr. |
| RodColeman | 0:0791c1fece8e | 1118 | * |
| RodColeman | 0:0791c1fece8e | 1119 | * @param netif the lwip network interface on which to send the request |
| RodColeman | 0:0791c1fece8e | 1120 | * @param ipaddr the IP address for which to ask |
| RodColeman | 0:0791c1fece8e | 1121 | * @return ERR_OK if the request has been sent |
| RodColeman | 0:0791c1fece8e | 1122 | * ERR_MEM if the ARP packet couldn't be allocated |
| RodColeman | 0:0791c1fece8e | 1123 | * any other err_t on failure |
| RodColeman | 0:0791c1fece8e | 1124 | */ |
| RodColeman | 0:0791c1fece8e | 1125 | err_t |
| RodColeman | 0:0791c1fece8e | 1126 | etharp_request(struct netif *netif, struct ip_addr *ipaddr) |
| RodColeman | 0:0791c1fece8e | 1127 | { |
| RodColeman | 0:0791c1fece8e | 1128 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, ("etharp_request: sending ARP request.\n")); |
| RodColeman | 0:0791c1fece8e | 1129 | return etharp_raw(netif, (struct eth_addr *)netif->hwaddr, ðbroadcast, |
| RodColeman | 0:0791c1fece8e | 1130 | (struct eth_addr *)netif->hwaddr, &netif->ip_addr, ðzero, |
| RodColeman | 0:0791c1fece8e | 1131 | ipaddr, ARP_REQUEST); |
| RodColeman | 0:0791c1fece8e | 1132 | } |
| RodColeman | 0:0791c1fece8e | 1133 | |
| RodColeman | 0:0791c1fece8e | 1134 | /** |
| RodColeman | 0:0791c1fece8e | 1135 | * Process received ethernet frames. Using this function instead of directly |
| RodColeman | 0:0791c1fece8e | 1136 | * calling ip_input and passing ARP frames through etharp in ethernetif_input, |
| RodColeman | 0:0791c1fece8e | 1137 | * the ARP cache is protected from concurrent access. |
| RodColeman | 0:0791c1fece8e | 1138 | * |
| RodColeman | 0:0791c1fece8e | 1139 | * @param p the recevied packet, p->payload pointing to the ethernet header |
| RodColeman | 0:0791c1fece8e | 1140 | * @param netif the network interface on which the packet was received |
| RodColeman | 0:0791c1fece8e | 1141 | */ |
| RodColeman | 0:0791c1fece8e | 1142 | err_t |
| RodColeman | 0:0791c1fece8e | 1143 | ethernet_input(struct pbuf *p, struct netif *netif) |
| RodColeman | 0:0791c1fece8e | 1144 | { |
| RodColeman | 0:0791c1fece8e | 1145 | struct eth_hdr* ethhdr; |
| RodColeman | 0:0791c1fece8e | 1146 | u16_t type; |
| RodColeman | 0:0791c1fece8e | 1147 | |
| RodColeman | 0:0791c1fece8e | 1148 | /* points to packet payload, which starts with an Ethernet header */ |
| RodColeman | 0:0791c1fece8e | 1149 | ethhdr = (struct eth_hdr *)p->payload; |
| RodColeman | 0:0791c1fece8e | 1150 | LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE, |
| RodColeman | 0:0791c1fece8e | 1151 | ("ethernet_input: dest:%02x:%02x:%02x:%02x:%02x:%02x, src:%02x:%02x:%02x:%02x:%02x:%02x, type:%2hx\n", |
| RodColeman | 0:0791c1fece8e | 1152 | (unsigned)ethhdr->dest.addr[0], (unsigned)ethhdr->dest.addr[1], (unsigned)ethhdr->dest.addr[2], |
| RodColeman | 0:0791c1fece8e | 1153 | (unsigned)ethhdr->dest.addr[3], (unsigned)ethhdr->dest.addr[4], (unsigned)ethhdr->dest.addr[5], |
| RodColeman | 0:0791c1fece8e | 1154 | (unsigned)ethhdr->src.addr[0], (unsigned)ethhdr->src.addr[1], (unsigned)ethhdr->src.addr[2], |
| RodColeman | 0:0791c1fece8e | 1155 | (unsigned)ethhdr->src.addr[3], (unsigned)ethhdr->src.addr[4], (unsigned)ethhdr->src.addr[5], |
| RodColeman | 0:0791c1fece8e | 1156 | (unsigned)htons(ethhdr->type))); |
| RodColeman | 0:0791c1fece8e | 1157 | |
| RodColeman | 0:0791c1fece8e | 1158 | type = htons(ethhdr->type); |
| RodColeman | 0:0791c1fece8e | 1159 | #if ETHARP_SUPPORT_VLAN |
| RodColeman | 0:0791c1fece8e | 1160 | if (type == ETHTYPE_VLAN) { |
| RodColeman | 0:0791c1fece8e | 1161 | struct eth_vlan_hdr *vlan = (struct eth_vlan_hdr*)(((char*)ethhdr) + SIZEOF_ETH_HDR); |
| RodColeman | 0:0791c1fece8e | 1162 | #ifdef ETHARP_VLAN_CHECK /* if not, allow all VLANs */ |
| RodColeman | 0:0791c1fece8e | 1163 | if (VLAN_ID(vlan) != ETHARP_VLAN_CHECK) { |
| RodColeman | 0:0791c1fece8e | 1164 | /* silently ignore this packet: not for our VLAN */ |
| RodColeman | 0:0791c1fece8e | 1165 | pbuf_free(p); |
| RodColeman | 0:0791c1fece8e | 1166 | return ERR_OK; |
| RodColeman | 0:0791c1fece8e | 1167 | } |
| RodColeman | 0:0791c1fece8e | 1168 | #endif /* ETHARP_VLAN_CHECK */ |
| RodColeman | 0:0791c1fece8e | 1169 | type = htons(vlan->tpid); |
| RodColeman | 0:0791c1fece8e | 1170 | } |
| RodColeman | 0:0791c1fece8e | 1171 | #endif /* ETHARP_SUPPORT_VLAN */ |
| RodColeman | 0:0791c1fece8e | 1172 | |
| RodColeman | 0:0791c1fece8e | 1173 | switch (type) { |
| RodColeman | 0:0791c1fece8e | 1174 | /* IP packet? */ |
| RodColeman | 0:0791c1fece8e | 1175 | case ETHTYPE_IP: |
| RodColeman | 0:0791c1fece8e | 1176 | #if ETHARP_TRUST_IP_MAC |
| RodColeman | 0:0791c1fece8e | 1177 | /* update ARP table */ |
| RodColeman | 0:0791c1fece8e | 1178 | etharp_ip_input(netif, p); |
| RodColeman | 0:0791c1fece8e | 1179 | #endif /* ETHARP_TRUST_IP_MAC */ |
| RodColeman | 0:0791c1fece8e | 1180 | /* skip Ethernet header */ |
| RodColeman | 0:0791c1fece8e | 1181 | if(pbuf_header(p, -(s16_t)SIZEOF_ETH_HDR)) { |
| RodColeman | 0:0791c1fece8e | 1182 | LWIP_ASSERT("Can't move over header in packet", 0); |
| RodColeman | 0:0791c1fece8e | 1183 | pbuf_free(p); |
| RodColeman | 0:0791c1fece8e | 1184 | p = NULL; |
| RodColeman | 0:0791c1fece8e | 1185 | } else { |
| RodColeman | 0:0791c1fece8e | 1186 | /* pass to IP layer */ |
| RodColeman | 0:0791c1fece8e | 1187 | ip_input(p, netif); |
| RodColeman | 0:0791c1fece8e | 1188 | } |
| RodColeman | 0:0791c1fece8e | 1189 | break; |
| RodColeman | 0:0791c1fece8e | 1190 | |
| RodColeman | 0:0791c1fece8e | 1191 | case ETHTYPE_ARP: |
| RodColeman | 0:0791c1fece8e | 1192 | /* pass p to ARP module */ |
| RodColeman | 0:0791c1fece8e | 1193 | etharp_arp_input(netif, (struct eth_addr*)(netif->hwaddr), p); |
| RodColeman | 0:0791c1fece8e | 1194 | break; |
| RodColeman | 0:0791c1fece8e | 1195 | |
| RodColeman | 0:0791c1fece8e | 1196 | #if PPPOE_SUPPORT |
| RodColeman | 0:0791c1fece8e | 1197 | case ETHTYPE_PPPOEDISC: /* PPP Over Ethernet Discovery Stage */ |
| RodColeman | 0:0791c1fece8e | 1198 | pppoe_disc_input(netif, p); |
| RodColeman | 0:0791c1fece8e | 1199 | break; |
| RodColeman | 0:0791c1fece8e | 1200 | |
| RodColeman | 0:0791c1fece8e | 1201 | case ETHTYPE_PPPOE: /* PPP Over Ethernet Session Stage */ |
| RodColeman | 0:0791c1fece8e | 1202 | pppoe_data_input(netif, p); |
| RodColeman | 0:0791c1fece8e | 1203 | break; |
| RodColeman | 0:0791c1fece8e | 1204 | #endif /* PPPOE_SUPPORT */ |
| RodColeman | 0:0791c1fece8e | 1205 | |
| RodColeman | 0:0791c1fece8e | 1206 | default: |
| RodColeman | 0:0791c1fece8e | 1207 | ETHARP_STATS_INC(etharp.proterr); |
| RodColeman | 0:0791c1fece8e | 1208 | ETHARP_STATS_INC(etharp.drop); |
| RodColeman | 0:0791c1fece8e | 1209 | pbuf_free(p); |
| RodColeman | 0:0791c1fece8e | 1210 | p = NULL; |
| RodColeman | 0:0791c1fece8e | 1211 | break; |
| RodColeman | 0:0791c1fece8e | 1212 | } |
| RodColeman | 0:0791c1fece8e | 1213 | |
| RodColeman | 0:0791c1fece8e | 1214 | /* This means the pbuf is freed or consumed, |
| RodColeman | 0:0791c1fece8e | 1215 | so the caller doesn't have to free it again */ |
| RodColeman | 0:0791c1fece8e | 1216 | return ERR_OK; |
| RodColeman | 0:0791c1fece8e | 1217 | } |
| RodColeman | 0:0791c1fece8e | 1218 | #endif /* LWIP_ARP */ |