1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* linux/net/inet/arp.h */ 3 #ifndef _ARP_H 4 #define _ARP_H 5 6 #include <linux/if_arp.h> 7 #include <linux/hash.h> 8 #include <net/neighbour.h> 9 10 static inline struct neigh_table *arp_table(struct net *net) 11 { 12 return net->neigh_tables[NEIGH_ARP_TABLE]; 13 } 14 15 static inline u32 arp_hashfn(const void *pkey, const struct net_device *dev, u32 *hash_rnd) 16 { 17 u32 key = *(const u32 *)pkey; 18 u32 val = key ^ hash32_ptr(dev); 19 20 return val * hash_rnd[0]; 21 } 22 23 #ifdef CONFIG_INET 24 static inline struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev, u32 key) 25 { 26 struct neigh_table *tbl = arp_table(dev_net(dev)); 27 28 if (dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT)) 29 key = INADDR_ANY; 30 31 return ___neigh_lookup_noref(tbl, neigh_key_eq32, arp_hashfn, &key, dev); 32 } 33 #else 34 static inline 35 struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev, u32 key) 36 { 37 return NULL; 38 } 39 #endif 40 41 static inline struct neighbour *__ipv4_neigh_lookup(struct net_device *dev, u32 key) 42 { 43 struct neighbour *n; 44 45 rcu_read_lock(); 46 n = __ipv4_neigh_lookup_noref(dev, key); 47 if (n && !refcount_inc_not_zero(&n->refcnt)) 48 n = NULL; 49 rcu_read_unlock(); 50 51 return n; 52 } 53 54 static inline struct neighbour *ipv4_neigh_lookup(struct net_device *dev, 55 const void *pkey) 56 { 57 struct neigh_table *tbl = arp_table(dev_net(dev)); 58 59 return neigh_lookup(tbl, pkey, dev); 60 } 61 62 static inline struct neighbour *ipv4_neigh_create(struct net_device *dev, 63 const void *pkey) 64 { 65 struct neigh_table *tbl = arp_table(dev_net(dev)); 66 67 return neigh_create(tbl, pkey, dev); 68 } 69 70 static inline void __ipv4_confirm_neigh(struct net_device *dev, u32 key) 71 { 72 struct neighbour *n; 73 74 rcu_read_lock(); 75 n = __ipv4_neigh_lookup_noref(dev, key); 76 neigh_confirm(n); 77 rcu_read_unlock(); 78 } 79 80 void arp_init(void); 81 int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg); 82 void arp_send(int type, int ptype, __be32 dest_ip, 83 struct net_device *dev, __be32 src_ip, 84 const unsigned char *dest_hw, 85 const unsigned char *src_hw, const unsigned char *th); 86 int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir); 87 void arp_ifdown(struct net_device *dev); 88 int arp_invalidate(struct net_device *dev, __be32 ip, bool force); 89 90 struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip, 91 struct net_device *dev, __be32 src_ip, 92 const unsigned char *dest_hw, 93 const unsigned char *src_hw, 94 const unsigned char *target_hw); 95 void arp_xmit(struct sk_buff *skb); 96 97 #endif /* _ARP_H */ 98