addrconf.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. #ifndef _ADDRCONF_H
  2. #define _ADDRCONF_H
  3. #define RETRANS_TIMER HZ
  4. #define MAX_RTR_SOLICITATIONS 3
  5. #define RTR_SOLICITATION_INTERVAL (4*HZ)
  6. #define ADDR_CHECK_FREQUENCY (120*HZ)
  7. struct prefix_info {
  8. __u8 type;
  9. __u8 length;
  10. __u8 prefix_len;
  11. #if defined(__BIG_ENDIAN_BITFIELD)
  12. __u8 onlink : 1,
  13.   autoconf : 1,
  14. reserved : 6;
  15. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  16. __u8 reserved : 6,
  17. autoconf : 1,
  18. onlink : 1;
  19. #else
  20. #error "Please fix <asm/byteorder.h>"
  21. #endif
  22. __u32 valid;
  23. __u32 prefered;
  24. __u32 reserved2;
  25. struct in6_addr prefix;
  26. };
  27. #ifdef __KERNEL__
  28. #include <linux/in6.h>
  29. #include <linux/netdevice.h>
  30. #include <net/if_inet6.h>
  31. #define IN6_ADDR_HSIZE 16
  32. extern void addrconf_init(void);
  33. extern void addrconf_cleanup(void);
  34. extern int         addrconf_notify(struct notifier_block *this, 
  35. unsigned long event, 
  36. void * data);
  37. extern int addrconf_add_ifaddr(void *arg);
  38. extern int addrconf_del_ifaddr(void *arg);
  39. extern int addrconf_set_dstaddr(void *arg);
  40. extern int ipv6_chk_addr(struct in6_addr *addr,
  41.       struct net_device *dev);
  42. extern struct inet6_ifaddr * ipv6_get_ifaddr(struct in6_addr *addr,
  43. struct net_device *dev);
  44. extern int ipv6_get_saddr(struct dst_entry *dst, 
  45.        struct in6_addr *daddr,
  46.        struct in6_addr *saddr);
  47. extern int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *);
  48. /*
  49.  * multicast prototypes (mcast.c)
  50.  */
  51. extern int ipv6_sock_mc_join(struct sock *sk, 
  52.   int ifindex, 
  53.   struct in6_addr *addr);
  54. extern int ipv6_sock_mc_drop(struct sock *sk,
  55.   int ifindex, 
  56.   struct in6_addr *addr);
  57. extern void ipv6_sock_mc_close(struct sock *sk);
  58. extern int inet6_mc_check(struct sock *sk, struct in6_addr *addr);
  59. extern int ipv6_dev_mc_inc(struct net_device *dev,
  60. struct in6_addr *addr);
  61. extern int ipv6_dev_mc_dec(struct net_device *dev,
  62. struct in6_addr *addr);
  63. extern void ipv6_mc_up(struct inet6_dev *idev);
  64. extern void ipv6_mc_down(struct inet6_dev *idev);
  65. extern void ipv6_mc_init_dev(struct inet6_dev *idev);
  66. extern void ipv6_mc_destroy_dev(struct inet6_dev *idev);
  67. extern void addrconf_dad_failure(struct inet6_ifaddr *ifp);
  68. extern int ipv6_chk_mcast_addr(struct net_device *dev,
  69.     struct in6_addr *addr);
  70. extern void addrconf_prefix_rcv(struct net_device *dev,
  71.     u8 *opt, int len);
  72. /* Device notifier */
  73. extern int register_inet6addr_notifier(struct notifier_block *nb);
  74. extern int unregister_inet6addr_notifier(struct notifier_block *nb);
  75. static inline struct inet6_dev *
  76. __in6_dev_get(struct net_device *dev)
  77. {
  78. return (struct inet6_dev *)dev->ip6_ptr;
  79. }
  80. extern rwlock_t addrconf_lock;
  81. static inline struct inet6_dev *
  82. in6_dev_get(struct net_device *dev)
  83. {
  84. struct inet6_dev *idev = NULL;
  85. read_lock(&addrconf_lock);
  86. idev = dev->ip6_ptr;
  87. if (idev)
  88. atomic_inc(&idev->refcnt);
  89. read_unlock(&addrconf_lock);
  90. return idev;
  91. }
  92. extern void in6_dev_finish_destroy(struct inet6_dev *idev);
  93. static inline void
  94. in6_dev_put(struct inet6_dev *idev)
  95. {
  96. if (atomic_dec_and_test(&idev->refcnt))
  97. in6_dev_finish_destroy(idev);
  98. }
  99. #define __in6_dev_put(idev)  atomic_dec(&(idev)->refcnt)
  100. #define in6_dev_hold(idev)   atomic_inc(&(idev)->refcnt)
  101. extern void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp);
  102. static inline void in6_ifa_put(struct inet6_ifaddr *ifp)
  103. {
  104. if (atomic_dec_and_test(&ifp->refcnt))
  105. inet6_ifa_finish_destroy(ifp);
  106. }
  107. #define __in6_ifa_put(idev)  atomic_dec(&(idev)->refcnt)
  108. #define in6_ifa_hold(idev)   atomic_inc(&(idev)->refcnt)
  109. extern void addrconf_forwarding_on(void);
  110. /*
  111.  * Hash function taken from net_alias.c
  112.  */
  113. static __inline__ u8 ipv6_addr_hash(struct in6_addr *addr)
  114. {
  115. __u32 word;
  116. /* 
  117.  * We perform the hash function over the last 64 bits of the address
  118.  * This will include the IEEE address token on links that support it.
  119.  */
  120. word = addr->s6_addr[2] ^ addr->s6_addr32[3];
  121. word  ^= (word>>16);
  122. word ^= (word >> 8);
  123. return ((word ^ (word >> 4)) & 0x0f);
  124. }
  125. /*
  126.  * compute link-local solicited-node multicast address
  127.  */
  128. static inline void addrconf_addr_solict_mult(struct in6_addr *addr,
  129.      struct in6_addr *solicited)
  130. {
  131. ipv6_addr_set(solicited,
  132.       __constant_htonl(0xFF020000), 0,
  133.       __constant_htonl(0x1),
  134.       __constant_htonl(0xFF000000) | addr->s6_addr32[3]);
  135. }
  136. static inline void ipv6_addr_all_nodes(struct in6_addr *addr)
  137. {
  138. ipv6_addr_set(addr,
  139.       __constant_htonl(0xFF020000), 0, 0,
  140.       __constant_htonl(0x1));
  141. }
  142. static inline void ipv6_addr_all_routers(struct in6_addr *addr)
  143. {
  144. ipv6_addr_set(addr,
  145.       __constant_htonl(0xFF020000), 0, 0,
  146.       __constant_htonl(0x2));
  147. }
  148. static inline int ipv6_addr_is_multicast(struct in6_addr *addr)
  149. {
  150. return (addr->s6_addr32[0] & __constant_htonl(0xFF000000)) == __constant_htonl(0xFF000000);
  151. }
  152. #endif
  153. #endif