arp.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* linux/net/inet/arp.h */
  2. #ifndef _ARP_H
  3. #define _ARP_H
  4. #include <linux/if_arp.h>
  5. #include <net/neighbour.h>
  6. extern struct neigh_table arp_tbl;
  7. static inline u32 arp_hashfn(u32 key, const struct net_device *dev, u32 hash_rnd)
  8. {
  9. u32 val = key ^ dev->ifindex;
  10. return val * hash_rnd;
  11. }
  12. static inline struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev, u32 key)
  13. {
  14. struct neigh_hash_table *nht = rcu_dereference_bh(arp_tbl.nht);
  15. struct neighbour *n;
  16. u32 hash_val;
  17. hash_val = arp_hashfn(key, dev, nht->hash_rnd[0]) >> (32 - nht->hash_shift);
  18. for (n = rcu_dereference_bh(nht->hash_buckets[hash_val]);
  19. n != NULL;
  20. n = rcu_dereference_bh(n->next)) {
  21. if (n->dev == dev && *(u32 *)n->primary_key == key)
  22. return n;
  23. }
  24. return NULL;
  25. }
  26. static inline struct neighbour *__ipv4_neigh_lookup(struct net_device *dev, u32 key)
  27. {
  28. struct neighbour *n;
  29. rcu_read_lock_bh();
  30. n = __ipv4_neigh_lookup_noref(dev, key);
  31. if (n && !atomic_inc_not_zero(&n->refcnt))
  32. n = NULL;
  33. rcu_read_unlock_bh();
  34. return n;
  35. }
  36. extern void arp_init(void);
  37. extern int arp_find(unsigned char *haddr, struct sk_buff *skb);
  38. extern int arp_ioctl(struct net *net, unsigned int cmd, void __user *arg);
  39. extern void arp_send(int type, int ptype, __be32 dest_ip,
  40. struct net_device *dev, __be32 src_ip,
  41. const unsigned char *dest_hw,
  42. const unsigned char *src_hw, const unsigned char *th);
  43. extern int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir);
  44. extern void arp_ifdown(struct net_device *dev);
  45. extern struct sk_buff *arp_create(int type, int ptype, __be32 dest_ip,
  46. struct net_device *dev, __be32 src_ip,
  47. const unsigned char *dest_hw,
  48. const unsigned char *src_hw,
  49. const unsigned char *target_hw);
  50. extern void arp_xmit(struct sk_buff *skb);
  51. int arp_invalidate(struct net_device *dev, __be32 ip);
  52. #endif /* _ARP_H */