ipv6.h 7.4 KB

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