ipv6.h 8.8 KB

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