ipv6.h 7.1 KB

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