ipv6.h 8.3 KB

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