arp.h 1.9 KB

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