ipv6.h 7.5 KB

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