xref: /openbmc/linux/include/net/arp.h (revision a263b3093641fb1ec377582c90986a7fd0625184)
11da177e4SLinus Torvalds /* linux/net/inet/arp.h */
21da177e4SLinus Torvalds #ifndef _ARP_H
31da177e4SLinus Torvalds #define _ARP_H
41da177e4SLinus Torvalds 
51da177e4SLinus Torvalds #include <linux/if_arp.h>
61da177e4SLinus Torvalds #include <net/neighbour.h>
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds 
91da177e4SLinus Torvalds extern struct neigh_table arp_tbl;
101da177e4SLinus Torvalds 
11f610b74bSDavid S. Miller static inline u32 arp_hashfn(u32 key, const struct net_device *dev, u32 hash_rnd)
12f610b74bSDavid S. Miller {
13f610b74bSDavid S. Miller 	u32 val = key ^ dev->ifindex;
14f610b74bSDavid S. Miller 
15f610b74bSDavid S. Miller 	return val * hash_rnd;
16f610b74bSDavid S. Miller }
17f610b74bSDavid S. Miller 
18*a263b309SDavid S. Miller static inline struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev, u32 key)
193769cffbSDavid Miller {
20*a263b309SDavid S. Miller 	struct neigh_hash_table *nht = rcu_dereference_bh(arp_tbl.nht);
213769cffbSDavid Miller 	struct neighbour *n;
223769cffbSDavid Miller 	u32 hash_val;
233769cffbSDavid Miller 
24*a263b309SDavid S. Miller 	if (dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))
25*a263b309SDavid S. Miller 		key = 0;
26*a263b309SDavid S. Miller 
272c2aba6cSDavid S. Miller 	hash_val = arp_hashfn(key, dev, nht->hash_rnd[0]) >> (32 - nht->hash_shift);
283769cffbSDavid Miller 	for (n = rcu_dereference_bh(nht->hash_buckets[hash_val]);
293769cffbSDavid Miller 	     n != NULL;
303769cffbSDavid Miller 	     n = rcu_dereference_bh(n->next)) {
31*a263b309SDavid S. Miller 		if (n->dev == dev && *(u32 *)n->primary_key == key)
32*a263b309SDavid S. Miller 			return n;
33*a263b309SDavid S. Miller 	}
34*a263b309SDavid S. Miller 
35*a263b309SDavid S. Miller 	return NULL;
36*a263b309SDavid S. Miller }
37*a263b309SDavid S. Miller 
38*a263b309SDavid S. Miller static inline struct neighbour *__ipv4_neigh_lookup(struct net_device *dev, u32 key)
39*a263b309SDavid S. Miller {
40*a263b309SDavid S. Miller 	struct neighbour *n;
41*a263b309SDavid S. Miller 
42*a263b309SDavid S. Miller 	rcu_read_lock_bh();
43*a263b309SDavid S. Miller 	n = __ipv4_neigh_lookup_noref(dev, key);
44*a263b309SDavid S. Miller 	if (n && !atomic_inc_not_zero(&n->refcnt))
453769cffbSDavid Miller 		n = NULL;
463769cffbSDavid Miller 	rcu_read_unlock_bh();
473769cffbSDavid Miller 
483769cffbSDavid Miller 	return n;
493769cffbSDavid Miller }
503769cffbSDavid Miller 
511da177e4SLinus Torvalds extern void	arp_init(void);
521da177e4SLinus Torvalds extern int	arp_find(unsigned char *haddr, struct sk_buff *skb);
5332e569b7SPavel Emelyanov extern int	arp_ioctl(struct net *net, unsigned int cmd, void __user *arg);
54ed9bad06SAl Viro extern void     arp_send(int type, int ptype, __be32 dest_ip,
55ed9bad06SAl Viro 			 struct net_device *dev, __be32 src_ip,
56abfdf1c4SJan Engelhardt 			 const unsigned char *dest_hw,
57abfdf1c4SJan Engelhardt 			 const unsigned char *src_hw, const unsigned char *th);
58714e85beSAl Viro extern int	arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir);
591da177e4SLinus Torvalds extern void	arp_ifdown(struct net_device *dev);
601da177e4SLinus Torvalds 
61ed9bad06SAl Viro extern struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
62ed9bad06SAl Viro 				  struct net_device *dev, __be32 src_ip,
63abfdf1c4SJan Engelhardt 				  const unsigned char *dest_hw,
64abfdf1c4SJan Engelhardt 				  const unsigned char *src_hw,
65abfdf1c4SJan Engelhardt 				  const unsigned char *target_hw);
661da177e4SLinus Torvalds extern void arp_xmit(struct sk_buff *skb);
67545ecdc3SMaxim Levitsky int arp_invalidate(struct net_device *dev, __be32 ip);
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds #endif	/* _ARP_H */
70