ipv6.h 8.9 KB

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