if_inet6.h 6.4 KB

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