ipv6.h 8.0 KB

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