Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* linux/net/inet/arp.h */
0003 #ifndef _ARP_H
0004 #define _ARP_H
0005 
0006 #include <linux/if_arp.h>
0007 #include <linux/hash.h>
0008 #include <net/neighbour.h>
0009 
0010 
0011 extern struct neigh_table arp_tbl;
0012 
0013 static inline u32 arp_hashfn(const void *pkey, const struct net_device *dev, u32 *hash_rnd)
0014 {
0015     u32 key = *(const u32 *)pkey;
0016     u32 val = key ^ hash32_ptr(dev);
0017 
0018     return val * hash_rnd[0];
0019 }
0020 
0021 #ifdef CONFIG_INET
0022 static inline struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev, u32 key)
0023 {
0024     if (dev->flags & (IFF_LOOPBACK | IFF_POINTOPOINT))
0025         key = INADDR_ANY;
0026 
0027     return ___neigh_lookup_noref(&arp_tbl, neigh_key_eq32, arp_hashfn, &key, dev);
0028 }
0029 #else
0030 static inline
0031 struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev, u32 key)
0032 {
0033     return NULL;
0034 }
0035 #endif
0036 
0037 static inline struct neighbour *__ipv4_neigh_lookup(struct net_device *dev, u32 key)
0038 {
0039     struct neighbour *n;
0040 
0041     rcu_read_lock_bh();
0042     n = __ipv4_neigh_lookup_noref(dev, key);
0043     if (n && !refcount_inc_not_zero(&n->refcnt))
0044         n = NULL;
0045     rcu_read_unlock_bh();
0046 
0047     return n;
0048 }
0049 
0050 static inline void __ipv4_confirm_neigh(struct net_device *dev, u32 key)
0051 {
0052     struct neighbour *n;
0053 
0054     rcu_read_lock_bh();
0055     n = __ipv4_neigh_lookup_noref(dev, key);
0056     neigh_confirm(n);
0057     rcu_read_unlock_bh();
0058 }
0059 
0060 void arp_init(void);
0061 int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg);
0062 void arp_send(int type, int ptype, __be32 dest_ip,
0063           struct net_device *dev, __be32 src_ip,
0064           const unsigned char *dest_hw,
0065           const unsigned char *src_hw, const unsigned char *th);
0066 int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir);
0067 void arp_ifdown(struct net_device *dev);
0068 int arp_invalidate(struct net_device *dev, __be32 ip, bool force);
0069 
0070 struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
0071                struct net_device *dev, __be32 src_ip,
0072                const unsigned char *dest_hw,
0073                const unsigned char *src_hw,
0074                const unsigned char *target_hw);
0075 void arp_xmit(struct sk_buff *skb);
0076 
0077 #endif  /* _ARP_H */