|
AquilaOS documentation
How it works, and its code
|
ARP: finding the hardware (MAC) address of an IPv4 address on the link. More...
#include <core/system.h>#include <core/string.h>#include <net/byteorder.h>#include <net/inet.h>#include <sys/callout.h>#include <core/arch.h>#include <aquila/errno.h>Go to the source code of this file.
Data Structures | |
| struct | arp_entry |
| struct | arp_pending |
Macros | |
| #define | ARP_ENTRIES 32 |
| #define | ARP_EXPIRE (20 * 60 * 1000ULL) |
| #define | ARP_PENDING 8 |
| #define | ARP_HOLD 3 |
| #define | ARP_TRIES 3 |
Functions | |
| static void | arp_request (struct netif *netif, uint32_t ip) |
| Broadcasts a request: who has ip? | |
| static void | pending_drop (struct arp_pending *p) |
| Gives up on an address being asked for: its waiting packets are dropped. | |
| static void | arp_retry (void *arg) |
| Asks again for an address that hasn't answered, a second after the last request, or gives up after ARP_TRIES requests. | |
| int | arp_resolve (struct netif *netif, uint32_t ip, struct netbuf *nb) |
| Holds a packet until the hardware address of its next hop is known, and asks for it. | |
| static void | pending_flush (struct netif *netif, uint32_t ip, const uint8_t mac[6]) |
| Sends the packets that waited for an address, now that it is known. | |
| void | arp_update (struct netif *netif, uint32_t ip, const uint8_t mac[6]) |
| Records an address's hardware address, replacing the oldest entry if the table is full, and sends the packets that waited for it. | |
| int | arp_lookup (struct netif *netif, uint32_t ip, uint8_t mac[6]) |
| Looks up an address's hardware address. | |
| void | arp_input (struct netif *netif, struct netbuf *nb) |
| Takes in an ARP packet: the sender's address is recorded, and a request for our address is answered. | |
Variables | |
| static struct arp_entry | table [ARP_ENTRIES] |
| static uint32_t | clock |
| static struct arp_pending | pending [ARP_PENDING] |
| static const uint8_t | ether_broadcast [6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} |
ARP: finding the hardware (MAC) address of an IPv4 address on the link.
ARP answers the requests for our own address, and keeps a table of the other machines' hardware addresses, learned from their requests and replies and from the IPv4 packets they send us. A packet to an address that isn't in the table waits (up to ARP_HOLD packets per address) while ARP asks for it, ARP_TRIES times, a second apart. An entry that hasn't been heard from for ARP_EXPIRE is asked for again: the machine may have gone, or another may have taken its address.
Definition in file arp.c.
| #define ARP_ENTRIES 32 |
Definition at line 22 of file arp.c.
Referenced by arp_lookup(), and arp_update().
| #define ARP_EXPIRE (20 * 60 * 1000ULL) |
Definition at line 26 of file arp.c.
Referenced by arp_lookup().
| #define ARP_HOLD 3 |
Definition at line 40 of file arp.c.
Referenced by arp_resolve().
| #define ARP_PENDING 8 |
Definition at line 39 of file arp.c.
Referenced by arp_resolve(), and pending_flush().
| #define ARP_TRIES 3 |
Definition at line 41 of file arp.c.
Referenced by arp_retry().
Takes in an ARP packet: the sender's address is recorded, and a request for our address is answered.
| netif | the interface it came in on |
| nb | the packet; it is freed or turned into the reply |
Definition at line 244 of file arp.c.
References arp_input(), arp_update(), netbuf::data, ether_output(), ETHER_TYPE_ARP, ETHER_TYPE_IPV4, arp_hdr::hlen, htons, arp_hdr::htype, netif::ip, netbuf::len, netif::mac, memcpy(), netbuf_free(), ntohs, arp_hdr::op, arp_hdr::plen, arp_hdr::ptype, arp_hdr::sha, arp_hdr::spa, netif::stats, arp_hdr::tha, and arp_hdr::tpa.
Referenced by arp_input(), and ether_input().
Looks up an address's hardware address.
An entry that has expired is dropped, so that the address is asked for again.
| netif | the interface |
| ip | the IPv4 address |
| mac | set to the hardware address, if it is known |
Definition at line 218 of file arp.c.
References arch_rtime_ms(), ARP_ENTRIES, ARP_EXPIRE, arp_lookup(), arp_entry::heard, arp_entry::ip, arp_entry::mac, memcpy(), arp_entry::netif, NULL, and table().
Referenced by arp_lookup(), and ipv4_output().
Broadcasts a request: who has ip?
Definition at line 56 of file arp.c.
References arp_request(), ether_broadcast, ether_output(), ETHER_TYPE_ARP, ETHER_TYPE_IPV4, arp_hdr::hlen, htons, arp_hdr::htype, netif::ip, netif::mac, memcpy(), memset(), netbuf_alloc(), arp_hdr::op, arp_hdr::plen, arp_hdr::ptype, arp_hdr::sha, arp_hdr::spa, arp_hdr::tha, and arp_hdr::tpa.
Referenced by arp_request(), arp_resolve(), and arp_retry().
Holds a packet until the hardware address of its next hop is known, and asks for it.
If too many packets wait for that address, the oldest is dropped. The netbuf is ARP's from now on.
| netif | the interface to send it on |
| ip | the next hop's address |
| nb | the IPv4 packet |
Definition at line 118 of file arp.c.
References ARP_HOLD, ARP_PENDING, arp_request(), arp_resolve(), arp_retry(), arp_pending::held, arp_pending::ip, memmove(), net_callout_set(), netbuf_free(), arp_pending::netif, arp_pending::nheld, NULL, pending, arp_pending::retry, netif::stats, and arp_pending::tries.
Referenced by arp_resolve(), and ipv4_output().
|
static |
Asks again for an address that hasn't answered, a second after the last request, or gives up after ARP_TRIES requests.
Definition at line 94 of file arp.c.
References arp_request(), arp_retry(), ARP_TRIES, arp_pending::ip, net_callout_set(), arp_pending::netif, pending_drop(), arp_pending::retry, and arp_pending::tries.
Referenced by arp_resolve(), and arp_retry().
Records an address's hardware address, replacing the oldest entry if the table is full, and sends the packets that waited for it.
| netif | the interface it was heard on |
| ip | the IPv4 address |
| mac | its hardware address |
Definition at line 185 of file arp.c.
References arch_rtime_ms(), ARP_ENTRIES, arp_update(), clock, arp_entry::heard, arp_entry::ip, arp_entry::mac, memcpy(), arp_entry::netif, pending_flush(), table(), arp_entry::used, and used.
Referenced by arp_input(), arp_update(), and ipv4_input().
|
static |
Gives up on an address being asked for: its waiting packets are dropped.
Definition at line 80 of file arp.c.
References callout_stop(), arp_pending::held, netbuf_free(), arp_pending::netif, arp_pending::nheld, NULL, pending_drop(), arp_pending::retry, and netif::stats.
Referenced by arp_retry(), and pending_drop().
Sends the packets that waited for an address, now that it is known.
Definition at line 159 of file arp.c.
References ARP_PENDING, callout_stop(), ether_output(), ETHER_TYPE_IPV4, arp_pending::held, arp_pending::ip, arp_pending::netif, arp_pending::nheld, NULL, pending, pending_flush(), and arp_pending::retry.
Referenced by arp_update(), and pending_flush().
|
static |
Definition at line 37 of file arp.c.
Referenced by arp_update(), and sys_clock_gettime().
|
static |
Definition at line 53 of file arp.c.
Referenced by arp_request(), and ipv4_output().
|
static |
|
static |