if_inet6.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. /* inet6_dev.if_flags */
  19. #define IF_RA_OTHERCONF 0x80
  20. #define IF_RA_MANAGED 0x40
  21. #define IF_RA_RCVD 0x20
  22. #define IF_RS_SENT 0x10
  23. #define IF_READY 0x80000000
  24. /* prefix flags */
  25. #define IF_PREFIX_ONLINK 0x01
  26. #define IF_PREFIX_AUTOCONF 0x02
  27. enum {
  28. INET6_IFADDR_STATE_DAD,
  29. INET6_IFADDR_STATE_POSTDAD,
  30. INET6_IFADDR_STATE_UP,
  31. INET6_IFADDR_STATE_DEAD,
  32. };
  33. struct inet6_ifaddr {
  34. struct in6_addr addr;
  35. __u32 prefix_len;
  36. /* In seconds, relative to tstamp. Expiry is at tstamp + HZ * lft. */
  37. __u32 valid_lft;
  38. __u32 prefered_lft;
  39. atomic_t refcnt;
  40. spinlock_t lock;
  41. spinlock_t state_lock;
  42. int state;
  43. __u8 probes;
  44. __u8 flags;
  45. __u16 scope;
  46. unsigned long cstamp; /* created timestamp */
  47. unsigned long tstamp; /* updated timestamp */
  48. struct timer_list timer;
  49. struct inet6_dev *idev;
  50. struct rt6_info *rt;
  51. struct hlist_node addr_lst;
  52. struct list_head if_list;
  53. #ifdef CONFIG_IPV6_PRIVACY
  54. struct list_head tmp_list;
  55. struct inet6_ifaddr *ifpub;
  56. int regen_count;
  57. #endif
  58. struct rcu_head rcu;
  59. };
  60. struct ip6_sf_socklist {
  61. unsigned int sl_max;
  62. unsigned int sl_count;
  63. struct in6_addr sl_addr[0];
  64. };
  65. #define IP6_SFLSIZE(count) (sizeof(struct ip6_sf_socklist) + \
  66. (count) * sizeof(struct in6_addr))
  67. #define IP6_SFBLOCK 10 /* allocate this many at once */
  68. struct ipv6_mc_socklist {
  69. struct in6_addr addr;
  70. int ifindex;
  71. struct ipv6_mc_socklist __rcu *next;
  72. rwlock_t sflock;
  73. unsigned int sfmode; /* MCAST_{INCLUDE,EXCLUDE} */
  74. struct ip6_sf_socklist *sflist;
  75. struct rcu_head rcu;
  76. };
  77. struct ip6_sf_list {
  78. struct ip6_sf_list *sf_next;
  79. struct in6_addr sf_addr;
  80. unsigned long sf_count[2]; /* include/exclude counts */
  81. unsigned char sf_gsresp; /* include in g & s response? */
  82. unsigned char sf_oldin; /* change state */
  83. unsigned char sf_crcount; /* retrans. left to send */
  84. };
  85. #define MAF_TIMER_RUNNING 0x01
  86. #define MAF_LAST_REPORTER 0x02
  87. #define MAF_LOADED 0x04
  88. #define MAF_NOREPORT 0x08
  89. #define MAF_GSQUERY 0x10
  90. struct ifmcaddr6 {
  91. struct in6_addr mca_addr;
  92. struct inet6_dev *idev;
  93. struct ifmcaddr6 *next;
  94. struct ip6_sf_list *mca_sources;
  95. struct ip6_sf_list *mca_tomb;
  96. unsigned int mca_sfmode;
  97. unsigned char mca_crcount;
  98. unsigned long mca_sfcount[2];
  99. struct timer_list mca_timer;
  100. unsigned mca_flags;
  101. int mca_users;
  102. atomic_t mca_refcnt;
  103. spinlock_t mca_lock;
  104. unsigned long mca_cstamp;
  105. unsigned long mca_tstamp;
  106. };
  107. /* Anycast stuff */
  108. struct ipv6_ac_socklist {
  109. struct in6_addr acl_addr;
  110. int acl_ifindex;
  111. struct ipv6_ac_socklist *acl_next;
  112. };
  113. struct ifacaddr6 {
  114. struct in6_addr aca_addr;
  115. struct inet6_dev *aca_idev;
  116. struct rt6_info *aca_rt;
  117. struct ifacaddr6 *aca_next;
  118. int aca_users;
  119. atomic_t aca_refcnt;
  120. spinlock_t aca_lock;
  121. unsigned long aca_cstamp;
  122. unsigned long aca_tstamp;
  123. };
  124. #define IFA_HOST IPV6_ADDR_LOOPBACK
  125. #define IFA_LINK IPV6_ADDR_LINKLOCAL
  126. #define IFA_SITE IPV6_ADDR_SITELOCAL
  127. struct ipv6_devstat {
  128. struct proc_dir_entry *proc_dir_entry;
  129. DEFINE_SNMP_STAT(struct ipstats_mib, ipv6);
  130. DEFINE_SNMP_STAT_ATOMIC(struct icmpv6_mib_device, icmpv6dev);
  131. DEFINE_SNMP_STAT_ATOMIC(struct icmpv6msg_mib_device, icmpv6msgdev);
  132. };
  133. struct inet6_dev {
  134. struct net_device *dev;
  135. struct list_head addr_list;
  136. struct ifmcaddr6 *mc_list;
  137. struct ifmcaddr6 *mc_tomb;
  138. spinlock_t mc_lock;
  139. unsigned char mc_qrv;
  140. unsigned char mc_gq_running;
  141. unsigned char mc_ifc_count;
  142. unsigned long mc_v1_seen;
  143. unsigned long mc_maxdelay;
  144. struct timer_list mc_gq_timer; /* general query timer */
  145. struct timer_list mc_ifc_timer; /* interface change timer */
  146. struct ifacaddr6 *ac_list;
  147. rwlock_t lock;
  148. atomic_t refcnt;
  149. __u32 if_flags;
  150. int dead;
  151. #ifdef CONFIG_IPV6_PRIVACY
  152. u8 rndid[8];
  153. struct timer_list regen_timer;
  154. struct list_head tempaddr_list;
  155. #endif
  156. struct neigh_parms *nd_parms;
  157. struct inet6_dev *next;
  158. struct ipv6_devconf cnf;
  159. struct ipv6_devstat stats;
  160. unsigned long tstamp; /* ipv6InterfaceTable update timestamp */
  161. struct rcu_head rcu;
  162. };
  163. static inline void ipv6_eth_mc_map(const struct in6_addr *addr, char *buf)
  164. {
  165. /*
  166. * +-------+-------+-------+-------+-------+-------+
  167. * | 33 | 33 | DST13 | DST14 | DST15 | DST16 |
  168. * +-------+-------+-------+-------+-------+-------+
  169. */
  170. buf[0]= 0x33;
  171. buf[1]= 0x33;
  172. memcpy(buf + 2, &addr->s6_addr32[3], sizeof(__u32));
  173. }
  174. static inline void ipv6_tr_mc_map(const struct in6_addr *addr, char *buf)
  175. {
  176. /* All nodes FF01::1, FF02::1, FF02::1:FFxx:xxxx */
  177. if (((addr->s6_addr[0] == 0xFF) &&
  178. ((addr->s6_addr[1] == 0x01) || (addr->s6_addr[1] == 0x02)) &&
  179. (addr->s6_addr16[1] == 0) &&
  180. (addr->s6_addr32[1] == 0) &&
  181. (addr->s6_addr32[2] == 0) &&
  182. (addr->s6_addr16[6] == 0) &&
  183. (addr->s6_addr[15] == 1)) ||
  184. ((addr->s6_addr[0] == 0xFF) &&
  185. (addr->s6_addr[1] == 0x02) &&
  186. (addr->s6_addr16[1] == 0) &&
  187. (addr->s6_addr32[1] == 0) &&
  188. (addr->s6_addr16[4] == 0) &&
  189. (addr->s6_addr[10] == 0) &&
  190. (addr->s6_addr[11] == 1) &&
  191. (addr->s6_addr[12] == 0xff)))
  192. {
  193. buf[0]=0xC0;
  194. buf[1]=0x00;
  195. buf[2]=0x01;
  196. buf[3]=0x00;
  197. buf[4]=0x00;
  198. buf[5]=0x00;
  199. /* All routers FF0x::2 */
  200. } else if ((addr->s6_addr[0] ==0xff) &&
  201. ((addr->s6_addr[1] & 0xF0) == 0) &&
  202. (addr->s6_addr16[1] == 0) &&
  203. (addr->s6_addr32[1] == 0) &&
  204. (addr->s6_addr32[2] == 0) &&
  205. (addr->s6_addr16[6] == 0) &&
  206. (addr->s6_addr[15] == 2))
  207. {
  208. buf[0]=0xC0;
  209. buf[1]=0x00;
  210. buf[2]=0x02;
  211. buf[3]=0x00;
  212. buf[4]=0x00;
  213. buf[5]=0x00;
  214. } else {
  215. unsigned char i ;
  216. i = addr->s6_addr[15] & 7 ;
  217. buf[0]=0xC0;
  218. buf[1]=0x00;
  219. buf[2]=0x00;
  220. buf[3]=0x01 << i ;
  221. buf[4]=0x00;
  222. buf[5]=0x00;
  223. }
  224. }
  225. static inline void ipv6_arcnet_mc_map(const struct in6_addr *addr, char *buf)
  226. {
  227. buf[0] = 0x00;
  228. }
  229. static inline void ipv6_ib_mc_map(const struct in6_addr *addr,
  230. const unsigned char *broadcast, char *buf)
  231. {
  232. unsigned char scope = broadcast[5] & 0xF;
  233. buf[0] = 0; /* Reserved */
  234. buf[1] = 0xff; /* Multicast QPN */
  235. buf[2] = 0xff;
  236. buf[3] = 0xff;
  237. buf[4] = 0xff;
  238. buf[5] = 0x10 | scope; /* scope from broadcast address */
  239. buf[6] = 0x60; /* IPv6 signature */
  240. buf[7] = 0x1b;
  241. buf[8] = broadcast[8]; /* P_Key */
  242. buf[9] = broadcast[9];
  243. memcpy(buf + 10, addr->s6_addr + 6, 10);
  244. }
  245. static inline int ipv6_ipgre_mc_map(const struct in6_addr *addr,
  246. const unsigned char *broadcast, char *buf)
  247. {
  248. if ((broadcast[0] | broadcast[1] | broadcast[2] | broadcast[3]) != 0) {
  249. memcpy(buf, broadcast, 4);
  250. } else {
  251. /* v4mapped? */
  252. if ((addr->s6_addr32[0] | addr->s6_addr32[1] |
  253. (addr->s6_addr32[2] ^ htonl(0x0000ffff))) != 0)
  254. return -EINVAL;
  255. memcpy(buf, &addr->s6_addr32[3], 4);
  256. }
  257. return 0;
  258. }
  259. #endif