ipv6.h 7.4 KB

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