if_inet6.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * inet6 interface/address list definitions
  3. * Linux INET6 implementation
  4. *
  5. * Authors:
  6. * Pedro Roque <roque@di.fc.ul.pt>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #ifndef _NET_IF_INET6_H
  15. #define _NET_IF_INET6_H
  16. #include <net/snmp.h>
  17. #include <linux/ipv6.h>
  18. #include <linux/refcount.h>
  19. /* inet6_dev.if_flags */
  20. #define IF_RA_OTHERCONF 0x80
  21. #define IF_RA_MANAGED 0x40
  22. #define IF_RA_RCVD 0x20
  23. #define IF_RS_SENT 0x10
  24. #define IF_READY 0x80000000
  25. #define IF_RS_VZW_SENT 0x01 /*add for VzW feature*/
  26. /* prefix flags */
  27. #define IF_PREFIX_ONLINK 0x01
  28. #define IF_PREFIX_AUTOCONF 0x02
  29. enum {
  30. INET6_IFADDR_STATE_PREDAD,
  31. INET6_IFADDR_STATE_DAD,
  32. INET6_IFADDR_STATE_POSTDAD,
  33. INET6_IFADDR_STATE_ERRDAD,
  34. INET6_IFADDR_STATE_DEAD,
  35. };
  36. struct inet6_ifaddr {
  37. struct in6_addr addr;
  38. __u32 prefix_len;
  39. /* In seconds, relative to tstamp. Expiry is at tstamp + HZ * lft. */
  40. __u32 valid_lft;
  41. __u32 prefered_lft;
  42. refcount_t refcnt;
  43. spinlock_t lock;
  44. int state;
  45. __u32 flags;
  46. __u8 dad_probes;
  47. __u8 stable_privacy_retry;
  48. __u16 scope;
  49. __u64 dad_nonce;
  50. unsigned long cstamp; /* created timestamp */
  51. unsigned long tstamp; /* updated timestamp */
  52. struct delayed_work dad_work;
  53. struct inet6_dev *idev;
  54. struct rt6_info *rt;
  55. struct hlist_node addr_lst;
  56. struct list_head if_list;
  57. struct list_head tmp_list;
  58. struct inet6_ifaddr *ifpub;
  59. int regen_count;
  60. bool tokenized;
  61. struct rcu_head rcu;
  62. struct in6_addr peer_addr;
  63. };
  64. struct ip6_sf_socklist {
  65. unsigned int sl_max;
  66. unsigned int sl_count;
  67. struct in6_addr sl_addr[0];
  68. };
  69. #define IP6_SFLSIZE(count) (sizeof(struct ip6_sf_socklist) + \
  70. (count) * sizeof(struct in6_addr))
  71. #define IP6_SFBLOCK 10 /* allocate this many at once */
  72. struct ipv6_mc_socklist {
  73. struct in6_addr addr;
  74. int ifindex;
  75. struct ipv6_mc_socklist __rcu *next;
  76. rwlock_t sflock;
  77. unsigned int sfmode; /* MCAST_{INCLUDE,EXCLUDE} */
  78. struct ip6_sf_socklist *sflist;
  79. struct rcu_head rcu;
  80. };
  81. struct ip6_sf_list {
  82. struct ip6_sf_list *sf_next;
  83. struct in6_addr sf_addr;
  84. unsigned long sf_count[2]; /* include/exclude counts */
  85. unsigned char sf_gsresp; /* include in g & s response? */
  86. unsigned char sf_oldin; /* change state */
  87. unsigned char sf_crcount; /* retrans. left to send */
  88. };
  89. #define MAF_TIMER_RUNNING 0x01
  90. #define MAF_LAST_REPORTER 0x02
  91. #define MAF_LOADED 0x04
  92. #define MAF_NOREPORT 0x08
  93. #define MAF_GSQUERY 0x10
  94. struct ifmcaddr6 {
  95. struct in6_addr mca_addr;
  96. struct inet6_dev *idev;
  97. struct ifmcaddr6 *next;
  98. struct ip6_sf_list *mca_sources;
  99. struct ip6_sf_list *mca_tomb;
  100. unsigned int mca_sfmode;
  101. unsigned char mca_crcount;
  102. unsigned long mca_sfcount[2];
  103. struct timer_list mca_timer;
  104. unsigned int mca_flags;
  105. int mca_users;
  106. refcount_t mca_refcnt;
  107. spinlock_t mca_lock;
  108. unsigned long mca_cstamp;
  109. unsigned long mca_tstamp;
  110. };
  111. /* Anycast stuff */
  112. struct ipv6_ac_socklist {
  113. struct in6_addr acl_addr;
  114. int acl_ifindex;
  115. struct ipv6_ac_socklist *acl_next;
  116. };
  117. struct ifacaddr6 {
  118. struct in6_addr aca_addr;
  119. struct inet6_dev *aca_idev;
  120. struct rt6_info *aca_rt;
  121. struct ifacaddr6 *aca_next;
  122. int aca_users;
  123. refcount_t aca_refcnt;
  124. unsigned long aca_cstamp;
  125. unsigned long aca_tstamp;
  126. };
  127. #define IFA_HOST IPV6_ADDR_LOOPBACK
  128. #define IFA_LINK IPV6_ADDR_LINKLOCAL
  129. #define IFA_SITE IPV6_ADDR_SITELOCAL
  130. struct ipv6_devstat {
  131. struct proc_dir_entry *proc_dir_entry;
  132. DEFINE_SNMP_STAT(struct ipstats_mib, ipv6);
  133. DEFINE_SNMP_STAT_ATOMIC(struct icmpv6_mib_device, icmpv6dev);
  134. DEFINE_SNMP_STAT_ATOMIC(struct icmpv6msg_mib_device, icmpv6msgdev);
  135. };
  136. struct inet6_dev {
  137. struct net_device *dev;
  138. struct list_head addr_list;
  139. struct ifmcaddr6 *mc_list;
  140. struct ifmcaddr6 *mc_tomb;
  141. spinlock_t mc_lock;
  142. unsigned char mc_qrv; /* Query Robustness Variable */
  143. unsigned char mc_gq_running;
  144. unsigned char mc_ifc_count;
  145. unsigned char mc_dad_count;
  146. unsigned long mc_v1_seen; /* Max time we stay in MLDv1 mode */
  147. unsigned long mc_qi; /* Query Interval */
  148. unsigned long mc_qri; /* Query Response Interval */
  149. unsigned long mc_maxdelay;
  150. struct timer_list mc_gq_timer; /* general query timer */
  151. struct timer_list mc_ifc_timer; /* interface change timer */
  152. struct timer_list mc_dad_timer; /* dad complete mc timer */
  153. struct ifacaddr6 *ac_list;
  154. rwlock_t lock;
  155. refcount_t refcnt;
  156. __u32 if_flags;
  157. int dead;
  158. u32 desync_factor;
  159. u8 rndid[8];
  160. struct list_head tempaddr_list;
  161. struct in6_addr token;
  162. struct neigh_parms *nd_parms;
  163. struct ipv6_devconf cnf;
  164. struct ipv6_devstat stats;
  165. struct timer_list rs_timer;
  166. __s32 rs_interval; /* in jiffies */
  167. __u8 rs_probes;
  168. unsigned long tstamp; /* ipv6InterfaceTable update timestamp */
  169. struct rcu_head rcu;
  170. };
  171. static inline void ipv6_eth_mc_map(const struct in6_addr *addr, char *buf)
  172. {
  173. /*
  174. * +-------+-------+-------+-------+-------+-------+
  175. * | 33 | 33 | DST13 | DST14 | DST15 | DST16 |
  176. * +-------+-------+-------+-------+-------+-------+
  177. */
  178. buf[0]= 0x33;
  179. buf[1]= 0x33;
  180. memcpy(buf + 2, &addr->s6_addr32[3], sizeof(__u32));
  181. }
  182. static inline void ipv6_arcnet_mc_map(const struct in6_addr *addr, char *buf)
  183. {
  184. buf[0] = 0x00;
  185. }
  186. static inline void ipv6_ib_mc_map(const struct in6_addr *addr,
  187. const unsigned char *broadcast, char *buf)
  188. {
  189. unsigned char scope = broadcast[5] & 0xF;
  190. buf[0] = 0; /* Reserved */
  191. buf[1] = 0xff; /* Multicast QPN */
  192. buf[2] = 0xff;
  193. buf[3] = 0xff;
  194. buf[4] = 0xff;
  195. buf[5] = 0x10 | scope; /* scope from broadcast address */
  196. buf[6] = 0x60; /* IPv6 signature */
  197. buf[7] = 0x1b;
  198. buf[8] = broadcast[8]; /* P_Key */
  199. buf[9] = broadcast[9];
  200. memcpy(buf + 10, addr->s6_addr + 6, 10);
  201. }
  202. static inline int ipv6_ipgre_mc_map(const struct in6_addr *addr,
  203. const unsigned char *broadcast, char *buf)
  204. {
  205. if ((broadcast[0] | broadcast[1] | broadcast[2] | broadcast[3]) != 0) {
  206. memcpy(buf, broadcast, 4);
  207. } else {
  208. /* v4mapped? */
  209. if ((addr->s6_addr32[0] | addr->s6_addr32[1] |
  210. (addr->s6_addr32[2] ^ htonl(0x0000ffff))) != 0)
  211. return -EINVAL;
  212. memcpy(buf, &addr->s6_addr32[3], 4);
  213. }
  214. return 0;
  215. }
  216. #endif