ipv6.h 7.5 KB

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