1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /* linux/net/inet/arp.h */
31da177e4SLinus Torvalds #ifndef _ARP_H
41da177e4SLinus Torvalds #define _ARP_H
51da177e4SLinus Torvalds
61da177e4SLinus Torvalds #include <linux/if_arp.h>
7b14f243aSPavel Emelyanov #include <linux/hash.h>
81da177e4SLinus Torvalds #include <net/neighbour.h>
91da177e4SLinus Torvalds
101da177e4SLinus Torvalds
111da177e4SLinus Torvalds extern struct neigh_table arp_tbl;
121da177e4SLinus Torvalds
arp_hashfn(const void * pkey,const struct net_device * dev,u32 * hash_rnd)1360395a20SEric W. Biederman static inline u32 arp_hashfn(const void *pkey, const struct net_device *dev, u32 *hash_rnd)
14f610b74bSDavid S. Miller {
1560395a20SEric W. Biederman u32 key = *(const u32 *)pkey;
16b14f243aSPavel Emelyanov u32 val = key ^ hash32_ptr(dev);
17f610b74bSDavid S. Miller
1860395a20SEric W. Biederman return val * hash_rnd[0];
19f610b74bSDavid S. Miller }
20f610b74bSDavid S. Miller
219b3040a6SDavid Ahern #ifdef CONFIG_INET
__ipv4_neigh_lookup_noref(struct net_device * dev,u32 key)22a263b309SDavid S. Miller static inline struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev, u32 key)
233769cffbSDavid Miller {
24cd9ff4deSJim Westfall if (dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))
25cd9ff4deSJim Westfall key = INADDR_ANY;
26cd9ff4deSJim Westfall
2760395a20SEric W. Biederman return ___neigh_lookup_noref(&arp_tbl, neigh_key_eq32, arp_hashfn, &key, dev);
28a263b309SDavid S. Miller }
299b3040a6SDavid Ahern #else
309b3040a6SDavid Ahern static inline
__ipv4_neigh_lookup_noref(struct net_device * dev,u32 key)319b3040a6SDavid Ahern struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev, u32 key)
329b3040a6SDavid Ahern {
339b3040a6SDavid Ahern return NULL;
349b3040a6SDavid Ahern }
359b3040a6SDavid Ahern #endif
36a263b309SDavid S. Miller
__ipv4_neigh_lookup(struct net_device * dev,u32 key)37a263b309SDavid S. Miller static inline struct neighbour *__ipv4_neigh_lookup(struct net_device *dev, u32 key)
38a263b309SDavid S. Miller {
39a263b309SDavid S. Miller struct neighbour *n;
40a263b309SDavid S. Miller
41*09eed119SEric Dumazet rcu_read_lock();
42a263b309SDavid S. Miller n = __ipv4_neigh_lookup_noref(dev, key);
439f237430SReshetova, Elena if (n && !refcount_inc_not_zero(&n->refcnt))
443769cffbSDavid Miller n = NULL;
45*09eed119SEric Dumazet rcu_read_unlock();
463769cffbSDavid Miller
473769cffbSDavid Miller return n;
483769cffbSDavid Miller }
493769cffbSDavid Miller
__ipv4_confirm_neigh(struct net_device * dev,u32 key)5063fca65dSJulian Anastasov static inline void __ipv4_confirm_neigh(struct net_device *dev, u32 key)
5163fca65dSJulian Anastasov {
5263fca65dSJulian Anastasov struct neighbour *n;
5363fca65dSJulian Anastasov
54*09eed119SEric Dumazet rcu_read_lock();
5563fca65dSJulian Anastasov n = __ipv4_neigh_lookup_noref(dev, key);
561e84dc6bSYajun Deng neigh_confirm(n);
57*09eed119SEric Dumazet rcu_read_unlock();
5863fca65dSJulian Anastasov }
5963fca65dSJulian Anastasov
6090972b22SJoe Perches void arp_init(void);
6190972b22SJoe Perches int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg);
6290972b22SJoe Perches void arp_send(int type, int ptype, __be32 dest_ip,
63ed9bad06SAl Viro struct net_device *dev, __be32 src_ip,
64abfdf1c4SJan Engelhardt const unsigned char *dest_hw,
65abfdf1c4SJan Engelhardt const unsigned char *src_hw, const unsigned char *th);
6690972b22SJoe Perches int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir);
6790972b22SJoe Perches void arp_ifdown(struct net_device *dev);
680c51e12eSIdo Schimmel int arp_invalidate(struct net_device *dev, __be32 ip, bool force);
691da177e4SLinus Torvalds
7090972b22SJoe Perches struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
71ed9bad06SAl Viro struct net_device *dev, __be32 src_ip,
72abfdf1c4SJan Engelhardt const unsigned char *dest_hw,
73abfdf1c4SJan Engelhardt const unsigned char *src_hw,
74abfdf1c4SJan Engelhardt const unsigned char *target_hw);
7590972b22SJoe Perches void arp_xmit(struct sk_buff *skb);
761da177e4SLinus Torvalds
771da177e4SLinus Torvalds #endif /* _ARP_H */
78