ipv6.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. #ifndef _IPV6_H
  2. #define _IPV6_H
  3. #include <uapi/linux/ipv6.h>
  4. #define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
  5. /*
  6. * This structure contains configuration options per IPv6 link.
  7. */
  8. struct ipv6_devconf {
  9. __s32 forwarding;
  10. __s32 hop_limit;
  11. __s32 mtu6;
  12. __s32 accept_ra;
  13. __s32 accept_redirects;
  14. __s32 autoconf;
  15. __s32 dad_transmits;
  16. __s32 rtr_solicits;
  17. __s32 rtr_solicit_interval;
  18. __s32 rtr_solicit_delay;
  19. __s32 force_mld_version;
  20. #ifdef CONFIG_IPV6_PRIVACY
  21. __s32 use_tempaddr;
  22. __s32 temp_valid_lft;
  23. __s32 temp_prefered_lft;
  24. __s32 regen_max_retry;
  25. __s32 max_desync_factor;
  26. #endif
  27. __s32 max_addresses;
  28. __s32 accept_ra_defrtr;
  29. __s32 accept_ra_pinfo;
  30. #ifdef CONFIG_IPV6_ROUTER_PREF
  31. __s32 accept_ra_rtr_pref;
  32. __s32 rtr_probe_interval;
  33. #ifdef CONFIG_IPV6_ROUTE_INFO
  34. __s32 accept_ra_rt_info_max_plen;
  35. #endif
  36. #endif
  37. __s32 proxy_ndp;
  38. __s32 accept_source_route;
  39. #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
  40. __s32 optimistic_dad;
  41. #endif
  42. #ifdef CONFIG_IPV6_MROUTE
  43. __s32 mc_forwarding;
  44. #endif
  45. __s32 disable_ipv6;
  46. __s32 accept_dad;
  47. __s32 force_tllao;
  48. __s32 ndisc_notify;
  49. void *sysctl;
  50. };
  51. struct ipv6_params {
  52. __s32 disable_ipv6;
  53. __s32 autoconf;
  54. };
  55. extern struct ipv6_params ipv6_defaults;
  56. #include <linux/icmpv6.h>
  57. #include <linux/tcp.h>
  58. #include <linux/udp.h>
  59. #include <net/inet_sock.h>
  60. static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)
  61. {
  62. return (struct ipv6hdr *)skb_network_header(skb);
  63. }
  64. static inline struct ipv6hdr *inner_ipv6_hdr(const struct sk_buff *skb)
  65. {
  66. return (struct ipv6hdr *)skb_inner_network_header(skb);
  67. }
  68. static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb)
  69. {
  70. return (struct ipv6hdr *)skb_transport_header(skb);
  71. }
  72. /*
  73. This structure contains results of exthdrs parsing
  74. as offsets from skb->nh.
  75. */
  76. struct inet6_skb_parm {
  77. int iif;
  78. __be16 ra;
  79. __u16 hop;
  80. __u16 dst0;
  81. __u16 srcrt;
  82. __u16 dst1;
  83. __u16 lastopt;
  84. __u16 nhoff;
  85. __u16 flags;
  86. #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
  87. __u16 dsthao;
  88. #endif
  89. __u16 frag_max_size;
  90. #define IP6SKB_XFRM_TRANSFORMED 1
  91. #define IP6SKB_FORWARDED 2
  92. #define IP6SKB_REROUTED 4
  93. #define IP6SKB_ROUTERALERT 8
  94. };
  95. #define IP6CB(skb) ((struct inet6_skb_parm*)((skb)->cb))
  96. #define IP6CBMTU(skb) ((struct ip6_mtuinfo *)((skb)->cb))
  97. static inline int inet6_iif(const struct sk_buff *skb)
  98. {
  99. return IP6CB(skb)->iif;
  100. }
  101. struct inet6_request_sock {
  102. struct in6_addr loc_addr;
  103. struct in6_addr rmt_addr;
  104. struct sk_buff *pktopts;
  105. int iif;
  106. };
  107. struct tcp6_request_sock {
  108. struct tcp_request_sock tcp6rsk_tcp;
  109. struct inet6_request_sock tcp6rsk_inet6;
  110. };
  111. struct ipv6_mc_socklist;
  112. struct ipv6_ac_socklist;
  113. struct ipv6_fl_socklist;
  114. /**
  115. * struct ipv6_pinfo - ipv6 private area
  116. *
  117. * In the struct sock hierarchy (tcp6_sock, upd6_sock, etc)
  118. * this _must_ be the last member, so that inet6_sk_generic
  119. * is able to calculate its offset from the base struct sock
  120. * by using the struct proto->slab_obj_size member. -acme
  121. */
  122. struct ipv6_pinfo {
  123. struct in6_addr saddr;
  124. struct in6_addr rcv_saddr;
  125. struct in6_addr daddr;
  126. struct in6_pktinfo sticky_pktinfo;
  127. const struct in6_addr *daddr_cache;
  128. #ifdef CONFIG_IPV6_SUBTREES
  129. const struct in6_addr *saddr_cache;
  130. #endif
  131. __be32 flow_label;
  132. __u32 frag_size;
  133. /*
  134. * Packed in 16bits.
  135. * Omit one shift by by putting the signed field at MSB.
  136. */
  137. #if defined(__BIG_ENDIAN_BITFIELD)
  138. __s16 hop_limit:9;
  139. __u16 __unused_1:7;
  140. #else
  141. __u16 __unused_1:7;
  142. __s16 hop_limit:9;
  143. #endif
  144. #if defined(__BIG_ENDIAN_BITFIELD)
  145. /* Packed in 16bits. */
  146. __s16 mcast_hops:9;
  147. __u16 __unused_2:6,
  148. mc_loop:1;
  149. #else
  150. __u16 mc_loop:1,
  151. __unused_2:6;
  152. __s16 mcast_hops:9;
  153. #endif
  154. int ucast_oif;
  155. int mcast_oif;
  156. /* pktoption flags */
  157. union {
  158. struct {
  159. __u16 srcrt:1,
  160. osrcrt:1,
  161. rxinfo:1,
  162. rxoinfo:1,
  163. rxhlim:1,
  164. rxohlim:1,
  165. hopopts:1,
  166. ohopopts:1,
  167. dstopts:1,
  168. odstopts:1,
  169. rxflow:1,
  170. rxtclass:1,
  171. rxpmtu:1,
  172. rxorigdstaddr:1;
  173. /* 2 bits hole */
  174. } bits;
  175. __u16 all;
  176. } rxopt;
  177. /* sockopt flags */
  178. __u16 recverr:1,
  179. sndflow:1,
  180. pmtudisc:2,
  181. ipv6only:1,
  182. srcprefs:3, /* 001: prefer temporary address
  183. * 010: prefer public address
  184. * 100: prefer care-of address
  185. */
  186. dontfrag:1;
  187. __u8 min_hopcount;
  188. __u8 tclass;
  189. __u8 rcv_tclass;
  190. __u32 dst_cookie;
  191. __u32 rx_dst_cookie;
  192. struct ipv6_mc_socklist __rcu *ipv6_mc_list;
  193. struct ipv6_ac_socklist *ipv6_ac_list;
  194. struct ipv6_fl_socklist __rcu *ipv6_fl_list;
  195. struct ipv6_txoptions *opt;
  196. struct sk_buff *pktoptions;
  197. struct sk_buff *rxpmtu;
  198. struct {
  199. struct ipv6_txoptions *opt;
  200. u8 hop_limit;
  201. u8 tclass;
  202. } cork;
  203. };
  204. /* WARNING: don't change the layout of the members in {raw,udp,tcp}6_sock! */
  205. struct raw6_sock {
  206. /* inet_sock has to be the first member of raw6_sock */
  207. struct inet_sock inet;
  208. __u32 checksum; /* perform checksum */
  209. __u32 offset; /* checksum offset */
  210. struct icmp6_filter filter;
  211. __u32 ip6mr_table;
  212. /* ipv6_pinfo has to be the last member of raw6_sock, see inet6_sk_generic */
  213. struct ipv6_pinfo inet6;
  214. };
  215. struct udp6_sock {
  216. struct udp_sock udp;
  217. /* ipv6_pinfo has to be the last member of udp6_sock, see inet6_sk_generic */
  218. struct ipv6_pinfo inet6;
  219. };
  220. struct tcp6_sock {
  221. struct tcp_sock tcp;
  222. /* ipv6_pinfo has to be the last member of tcp6_sock, see inet6_sk_generic */
  223. struct ipv6_pinfo inet6;
  224. };
  225. extern int inet6_sk_rebuild_header(struct sock *sk);
  226. struct inet6_timewait_sock {
  227. struct in6_addr tw_v6_daddr;
  228. struct in6_addr tw_v6_rcv_saddr;
  229. };
  230. struct tcp6_timewait_sock {
  231. struct tcp_timewait_sock tcp6tw_tcp;
  232. struct inet6_timewait_sock tcp6tw_inet6;
  233. };
  234. static inline struct inet6_timewait_sock *inet6_twsk(const struct sock *sk)
  235. {
  236. return (struct inet6_timewait_sock *)(((u8 *)sk) +
  237. inet_twsk(sk)->tw_ipv6_offset);
  238. }
  239. #if IS_ENABLED(CONFIG_IPV6)
  240. static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
  241. {
  242. return inet_sk(__sk)->pinet6;
  243. }
  244. static inline struct inet6_request_sock *
  245. inet6_rsk(const struct request_sock *rsk)
  246. {
  247. return (struct inet6_request_sock *)(((u8 *)rsk) +
  248. inet_rsk(rsk)->inet6_rsk_offset);
  249. }
  250. static inline u32 inet6_rsk_offset(struct request_sock *rsk)
  251. {
  252. return rsk->rsk_ops->obj_size - sizeof(struct inet6_request_sock);
  253. }
  254. static inline struct request_sock *inet6_reqsk_alloc(struct request_sock_ops *ops)
  255. {
  256. struct request_sock *req = reqsk_alloc(ops);
  257. if (req != NULL) {
  258. inet_rsk(req)->inet6_rsk_offset = inet6_rsk_offset(req);
  259. inet6_rsk(req)->pktopts = NULL;
  260. }
  261. return req;
  262. }
  263. static inline struct raw6_sock *raw6_sk(const struct sock *sk)
  264. {
  265. return (struct raw6_sock *)sk;
  266. }
  267. static inline void inet_sk_copy_descendant(struct sock *sk_to,
  268. const struct sock *sk_from)
  269. {
  270. int ancestor_size = sizeof(struct inet_sock);
  271. if (sk_from->sk_family == PF_INET6)
  272. ancestor_size += sizeof(struct ipv6_pinfo);
  273. __inet_sk_copy_descendant(sk_to, sk_from, ancestor_size);
  274. }
  275. #define __ipv6_only_sock(sk) (inet6_sk(sk)->ipv6only)
  276. #define ipv6_only_sock(sk) ((sk)->sk_family == PF_INET6 && __ipv6_only_sock(sk))
  277. static inline u16 inet6_tw_offset(const struct proto *prot)
  278. {
  279. return prot->twsk_prot->twsk_obj_size -
  280. sizeof(struct inet6_timewait_sock);
  281. }
  282. static inline struct in6_addr *__inet6_rcv_saddr(const struct sock *sk)
  283. {
  284. return likely(sk->sk_state != TCP_TIME_WAIT) ?
  285. &inet6_sk(sk)->rcv_saddr : &inet6_twsk(sk)->tw_v6_rcv_saddr;
  286. }
  287. static inline struct in6_addr *inet6_rcv_saddr(const struct sock *sk)
  288. {
  289. return sk->sk_family == AF_INET6 ? __inet6_rcv_saddr(sk) : NULL;
  290. }
  291. static inline int inet_v6_ipv6only(const struct sock *sk)
  292. {
  293. return likely(sk->sk_state != TCP_TIME_WAIT) ?
  294. ipv6_only_sock(sk) : inet_twsk(sk)->tw_ipv6only;
  295. }
  296. #else
  297. #define __ipv6_only_sock(sk) 0
  298. #define ipv6_only_sock(sk) 0
  299. static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
  300. {
  301. return NULL;
  302. }
  303. static inline struct inet6_request_sock *
  304. inet6_rsk(const struct request_sock *rsk)
  305. {
  306. return NULL;
  307. }
  308. static inline struct raw6_sock *raw6_sk(const struct sock *sk)
  309. {
  310. return NULL;
  311. }
  312. #define __inet6_rcv_saddr(__sk) NULL
  313. #define inet6_rcv_saddr(__sk) NULL
  314. #define tcp_twsk_ipv6only(__sk) 0
  315. #define inet_v6_ipv6only(__sk) 0
  316. #endif /* IS_ENABLED(CONFIG_IPV6) */
  317. #define INET6_MATCH(__sk, __net, __saddr, __daddr, __ports, __dif) \
  318. ((inet_sk(__sk)->inet_portpair == (__ports)) && \
  319. ((__sk)->sk_family == AF_INET6) && \
  320. ipv6_addr_equal(&inet6_sk(__sk)->daddr, (__saddr)) && \
  321. ipv6_addr_equal(&inet6_sk(__sk)->rcv_saddr, (__daddr)) && \
  322. (!(__sk)->sk_bound_dev_if || \
  323. ((__sk)->sk_bound_dev_if == (__dif))) && \
  324. net_eq(sock_net(__sk), (__net)))
  325. #define INET6_TW_MATCH(__sk, __net, __saddr, __daddr, __ports, __dif) \
  326. ((inet_twsk(__sk)->tw_portpair == (__ports)) && \
  327. ((__sk)->sk_family == AF_INET6) && \
  328. ipv6_addr_equal(&inet6_twsk(__sk)->tw_v6_daddr, (__saddr)) && \
  329. ipv6_addr_equal(&inet6_twsk(__sk)->tw_v6_rcv_saddr, (__daddr)) && \
  330. (!(__sk)->sk_bound_dev_if || \
  331. ((__sk)->sk_bound_dev_if == (__dif))) && \
  332. net_eq(sock_net(__sk), (__net)))
  333. #endif /* _IPV6_H */