if_inet6.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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_PREDAD,
  29. INET6_IFADDR_STATE_DAD,
  30. INET6_IFADDR_STATE_POSTDAD,
  31. INET6_IFADDR_STATE_ERRDAD,
  32. INET6_IFADDR_STATE_DEAD,
  33. };
  34. struct inet6_ifaddr {
  35. struct in6_addr addr;
  36. __u32 prefix_len;
  37. /* In seconds, relative to tstamp. Expiry is at tstamp + HZ * lft. */
  38. __u32 valid_lft;
  39. __u32 prefered_lft;
  40. atomic_t refcnt;
  41. spinlock_t lock;
  42. int state;
  43. __u32 flags;
  44. __u8 dad_probes;
  45. __u8 stable_privacy_retry;
  46. __u16 scope;
  47. unsigned long cstamp; /* created timestamp */
  48. unsigned long tstamp; /* updated timestamp */
  49. struct delayed_work dad_work;
  50. struct inet6_dev *idev;
  51. struct rt6_info *rt;
  52. struct hlist_node addr_lst;
  53. struct list_head if_list;
  54. struct list_head tmp_list;
  55. struct inet6_ifaddr *ifpub;
  56. int regen_count;
  57. bool tokenized;
  58. struct rcu_head rcu;
  59. struct in6_addr peer_addr;
  60. };
  61. struct ip6_sf_socklist {
  62. unsigned int sl_max;
  63. unsigned int sl_count;
  64. struct in6_addr sl_addr[0];
  65. };
  66. #define IP6_SFLSIZE(count) (sizeof(struct ip6_sf_socklist) + \
  67. (count) * sizeof(struct in6_addr))
  68. #define IP6_SFBLOCK 10 /* allocate this many at once */
  69. struct ipv6_mc_socklist {
  70. struct in6_addr addr;
  71. int ifindex;
  72. struct ipv6_mc_socklist __rcu *next;
  73. rwlock_t sflock;
  74. unsigned int sfmode; /* MCAST_{INCLUDE,EXCLUDE} */
  75. struct ip6_sf_socklist *sflist;
  76. struct rcu_head rcu;
  77. };
  78. struct ip6_sf_list {
  79. struct ip6_sf_list *sf_next;
  80. struct in6_addr sf_addr;
  81. unsigned long sf_count[2]; /* include/exclude counts */
  82. unsigned char sf_gsresp; /* include in g & s response? */
  83. unsigned char sf_oldin; /* change state */
  84. unsigned char sf_crcount; /* retrans. left to send */
  85. };
  86. #define MAF_TIMER_RUNNING 0x01
  87. #define MAF_LAST_REPORTER 0x02
  88. #define MAF_LOADED 0x04
  89. #define MAF_NOREPORT 0x08
  90. #define MAF_GSQUERY 0x10
  91. struct ifmcaddr6 {
  92. struct in6_addr mca_addr;
  93. struct inet6_dev *idev;
  94. struct ifmcaddr6 *next;
  95. struct ip6_sf_list *mca_sources;
  96. struct ip6_sf_list *mca_tomb;
  97. unsigned int mca_sfmode;
  98. unsigned char mca_crcount;
  99. unsigned long mca_sfcount[2];
  100. struct timer_list mca_timer;
  101. unsigned int mca_flags;
  102. int mca_users;
  103. atomic_t mca_refcnt;
  104. spinlock_t mca_lock;
  105. unsigned long mca_cstamp;
  106. unsigned long mca_tstamp;
  107. };
  108. /* Anycast stuff */
  109. struct ipv6_ac_socklist {
  110. struct in6_addr acl_addr;
  111. int acl_ifindex;
  112. struct ipv6_ac_socklist *acl_next;
  113. };
  114. struct ifacaddr6 {
  115. struct in6_addr aca_addr;
  116. struct inet6_dev *aca_idev;
  117. struct rt6_info *aca_rt;
  118. struct ifacaddr6 *aca_next;
  119. int aca_users;
  120. atomic_t aca_refcnt;
  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; /* Query Robustness Variable */
  140. unsigned char mc_gq_running;
  141. unsigned char mc_ifc_count;
  142. unsigned char mc_dad_count;
  143. unsigned long mc_v1_seen; /* Max time we stay in MLDv1 mode */
  144. unsigned long mc_qi; /* Query Interval */
  145. unsigned long mc_qri; /* Query Response Interval */
  146. unsigned long mc_maxdelay;
  147. struct timer_list mc_gq_timer; /* general query timer */
  148. struct timer_list mc_ifc_timer; /* interface change timer */
  149. struct timer_list mc_dad_timer; /* dad complete mc timer */
  150. struct ifacaddr6 *ac_list;
  151. rwlock_t lock;
  152. atomic_t refcnt;
  153. __u32 if_flags;
  154. int dead;
  155. u32 desync_factor;
  156. u8 rndid[8];
  157. struct list_head tempaddr_list;
  158. struct in6_addr token;
  159. struct neigh_parms *nd_parms;
  160. struct ipv6_devconf cnf;
  161. struct ipv6_devstat stats;
  162. struct timer_list rs_timer;
  163. __s32 rs_interval; /* in jiffies */
  164. __u8 rs_probes;
  165. __u8 addr_gen_mode;
  166. unsigned long tstamp; /* ipv6InterfaceTable update timestamp */
  167. struct rcu_head rcu;
  168. };
  169. static inline void ipv6_eth_mc_map(const struct in6_addr *addr, char *buf)
  170. {
  171. /*
  172. * +-------+-------+-------+-------+-------+-------+
  173. * | 33 | 33 | DST13 | DST14 | DST15 | DST16 |
  174. * +-------+-------+-------+-------+-------+-------+
  175. */
  176. buf[0]= 0x33;
  177. buf[1]= 0x33;
  178. memcpy(buf + 2, &addr->s6_addr32[3], sizeof(__u32));
  179. }
  180. static inline void ipv6_arcnet_mc_map(const struct in6_addr *addr, char *buf)
  181. {
  182. buf[0] = 0x00;
  183. }
  184. static inline void ipv6_ib_mc_map(const struct in6_addr *addr,
  185. const unsigned char *broadcast, char *buf)
  186. {
  187. unsigned char scope = broadcast[5] & 0xF;
  188. buf[0] = 0; /* Reserved */
  189. buf[1] = 0xff; /* Multicast QPN */
  190. buf[2] = 0xff;
  191. buf[3] = 0xff;
  192. buf[4] = 0xff;
  193. buf[5] = 0x10 | scope; /* scope from broadcast address */
  194. buf[6] = 0x60; /* IPv6 signature */
  195. buf[7] = 0x1b;
  196. buf[8] = broadcast[8]; /* P_Key */
  197. buf[9] = broadcast[9];
  198. memcpy(buf + 10, addr->s6_addr + 6, 10);
  199. }
  200. static inline int ipv6_ipgre_mc_map(const struct in6_addr *addr,
  201. const unsigned char *broadcast, char *buf)
  202. {
  203. if ((broadcast[0] | broadcast[1] | broadcast[2] | broadcast[3]) != 0) {
  204. memcpy(buf, broadcast, 4);
  205. } else {
  206. /* v4mapped? */
  207. if ((addr->s6_addr32[0] | addr->s6_addr32[1] |
  208. (addr->s6_addr32[2] ^ htonl(0x0000ffff))) != 0)
  209. return -EINVAL;
  210. memcpy(buf, &addr->s6_addr32[3], 4);
  211. }
  212. return 0;
  213. }
  214. #endif