if_inet6.h 6.4 KB

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