1 /* 2 * Copyright (c) 2016 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __ARP_H 8 #define __ARP_H 9 10 #if defined(CONFIG_NET_ARP) && defined(CONFIG_NET_NATIVE) 11 12 #include <sys/slist.h> 13 #include <net/ethernet.h> 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /** 20 * @brief Address resolution (ARP) library 21 * @defgroup arp ARP Library 22 * @ingroup networking 23 * @{ 24 */ 25 26 #define NET_ARP_HDR(pkt) ((struct net_arp_hdr *)net_pkt_data(pkt)) 27 28 struct net_arp_hdr { 29 uint16_t hwtype; /* HTYPE */ 30 uint16_t protocol; /* PTYPE */ 31 uint8_t hwlen; /* HLEN */ 32 uint8_t protolen; /* PLEN */ 33 uint16_t opcode; 34 struct net_eth_addr src_hwaddr; /* SHA */ 35 struct in_addr src_ipaddr; /* SPA */ 36 struct net_eth_addr dst_hwaddr; /* THA */ 37 struct in_addr dst_ipaddr; /* TPA */ 38 } __packed; 39 40 #define NET_ARP_HTYPE_ETH 1 41 #define NET_ARP_IPV4_PTYPE_SIZE 4 42 43 #define NET_ARP_REQUEST 1 44 #define NET_ARP_REPLY 2 45 46 struct net_pkt *net_arp_prepare(struct net_pkt *pkt, 47 struct in_addr *request_ip, 48 struct in_addr *current_ip); 49 enum net_verdict net_arp_input(struct net_pkt *pkt, 50 struct net_eth_hdr *eth_hdr); 51 52 struct arp_entry { 53 sys_snode_t node; 54 uint32_t req_start; 55 struct net_if *iface; 56 struct in_addr ip; 57 union { 58 struct net_pkt *pending; 59 struct net_eth_addr eth; 60 }; 61 }; 62 63 typedef void (*net_arp_cb_t)(struct arp_entry *entry, 64 void *user_data); 65 int net_arp_foreach(net_arp_cb_t cb, void *user_data); 66 67 void net_arp_clear_cache(struct net_if *iface); 68 void net_arp_init(void); 69 70 /** 71 * @} 72 */ 73 74 #ifdef __cplusplus 75 } 76 #endif 77 78 #else /* CONFIG_NET_ARP */ 79 #define net_arp_prepare(_kt, _u1, _u2) _kt 80 #define net_arp_input(...) NET_OK 81 #define net_arp_clear_cache(...) 82 #define net_arp_foreach(...) 0 83 #define net_arp_init(...) 84 85 #endif /* CONFIG_NET_ARP */ 86 87 #endif /* __ARP_H */ 88