if_inet6.h 6.7 KB

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