ipv6.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. #ifndef _IPV6_H
  2. #define _IPV6_H
  3. #include <linux/in6.h>
  4. #include <asm/byteorder.h>
  5. /* The latest drafts declared increase in minimal mtu up to 1280. */
  6. #define IPV6_MIN_MTU 1280
  7. /*
  8. * Advanced API
  9. * source interface/address selection, source routing, etc...
  10. * *under construction*
  11. */
  12. struct in6_pktinfo {
  13. struct in6_addr ipi6_addr;
  14. int ipi6_ifindex;
  15. };
  16. struct in6_ifreq {
  17. struct in6_addr ifr6_addr;
  18. __u32 ifr6_prefixlen;
  19. int ifr6_ifindex;
  20. };
  21. #define IPV6_SRCRT_STRICT 0x01 /* this hop must be a neighbor */
  22. #define IPV6_SRCRT_TYPE_0 0 /* IPv6 type 0 Routing Header */
  23. #define IPV6_SRCRT_TYPE_2 2 /* IPv6 type 2 Routing Header */
  24. /*
  25. * routing header
  26. */
  27. struct ipv6_rt_hdr {
  28. __u8 nexthdr;
  29. __u8 hdrlen;
  30. __u8 type;
  31. __u8 segments_left;
  32. /*
  33. * type specific data
  34. * variable length field
  35. */
  36. };
  37. struct ipv6_opt_hdr {
  38. __u8 nexthdr;
  39. __u8 hdrlen;
  40. /*
  41. * TLV encoded option data follows.
  42. */
  43. };
  44. #define ipv6_destopt_hdr ipv6_opt_hdr
  45. #define ipv6_hopopt_hdr ipv6_opt_hdr
  46. #ifdef __KERNEL__
  47. #define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
  48. #endif
  49. /*
  50. * routing header type 0 (used in cmsghdr struct)
  51. */
  52. struct rt0_hdr {
  53. struct ipv6_rt_hdr rt_hdr;
  54. __u32 reserved;
  55. struct in6_addr addr[0];
  56. #define rt0_type rt_hdr.type
  57. };
  58. /*
  59. * routing header type 2
  60. */
  61. struct rt2_hdr {
  62. struct ipv6_rt_hdr rt_hdr;
  63. __u32 reserved;
  64. struct in6_addr addr;
  65. #define rt2_type rt_hdr.type
  66. };
  67. /*
  68. * home address option in destination options header
  69. */
  70. struct ipv6_destopt_hao {
  71. __u8 type;
  72. __u8 length;
  73. struct in6_addr addr;
  74. } __attribute__ ((__packed__));
  75. struct ipv6_auth_hdr {
  76. __u8 nexthdr;
  77. __u8 hdrlen; /* This one is measured in 32 bit units! */
  78. __be16 reserved;
  79. __be32 spi;
  80. __be32 seq_no; /* Sequence number */
  81. __u8 auth_data[0]; /* Length variable but >=4. Mind the 64 bit alignment! */
  82. };
  83. struct ipv6_esp_hdr {
  84. __be32 spi;
  85. __be32 seq_no; /* Sequence number */
  86. __u8 enc_data[0]; /* Length variable but >=8. Mind the 64 bit alignment! */
  87. };
  88. struct ipv6_comp_hdr {
  89. __u8 nexthdr;
  90. __u8 flags;
  91. __be16 cpi;
  92. };
  93. /*
  94. * IPv6 fixed header
  95. *
  96. * BEWARE, it is incorrect. The first 4 bits of flow_lbl
  97. * are glued to priority now, forming "class".
  98. */
  99. struct ipv6hdr {
  100. #if defined(__LITTLE_ENDIAN_BITFIELD)
  101. __u8 priority:4,
  102. version:4;
  103. #elif defined(__BIG_ENDIAN_BITFIELD)
  104. __u8 version:4,
  105. priority:4;
  106. #else
  107. #error "Please fix <asm/byteorder.h>"
  108. #endif
  109. __u8 flow_lbl[3];
  110. __be16 payload_len;
  111. __u8 nexthdr;
  112. __u8 hop_limit;
  113. struct in6_addr saddr;
  114. struct in6_addr daddr;
  115. };
  116. /*
  117. * This structure contains configuration options per IPv6 link.
  118. */
  119. struct ipv6_devconf {
  120. __s32 forwarding;
  121. __s32 hop_limit;
  122. __s32 mtu6;
  123. __s32 accept_ra;
  124. __s32 accept_redirects;
  125. __s32 autoconf;
  126. __s32 dad_transmits;
  127. __s32 rtr_solicits;
  128. __s32 rtr_solicit_interval;
  129. __s32 rtr_solicit_delay;
  130. __s32 force_mld_version;
  131. #ifdef CONFIG_IPV6_PRIVACY
  132. __s32 use_tempaddr;
  133. __s32 temp_valid_lft;
  134. __s32 temp_prefered_lft;
  135. __s32 regen_max_retry;
  136. __s32 max_desync_factor;
  137. #endif
  138. __s32 max_addresses;
  139. __s32 accept_ra_defrtr;
  140. __s32 accept_ra_pinfo;
  141. #ifdef CONFIG_IPV6_ROUTER_PREF
  142. __s32 accept_ra_rtr_pref;
  143. __s32 rtr_probe_interval;
  144. #ifdef CONFIG_IPV6_ROUTE_INFO
  145. __s32 accept_ra_rt_info_max_plen;
  146. #endif
  147. #endif
  148. __s32 proxy_ndp;
  149. __s32 accept_source_route;
  150. #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
  151. __s32 optimistic_dad;
  152. #endif
  153. void *sysctl;
  154. };
  155. /* index values for the variables in ipv6_devconf */
  156. enum {
  157. DEVCONF_FORWARDING = 0,
  158. DEVCONF_HOPLIMIT,
  159. DEVCONF_MTU6,
  160. DEVCONF_ACCEPT_RA,
  161. DEVCONF_ACCEPT_REDIRECTS,
  162. DEVCONF_AUTOCONF,
  163. DEVCONF_DAD_TRANSMITS,
  164. DEVCONF_RTR_SOLICITS,
  165. DEVCONF_RTR_SOLICIT_INTERVAL,
  166. DEVCONF_RTR_SOLICIT_DELAY,
  167. DEVCONF_USE_TEMPADDR,
  168. DEVCONF_TEMP_VALID_LFT,
  169. DEVCONF_TEMP_PREFERED_LFT,
  170. DEVCONF_REGEN_MAX_RETRY,
  171. DEVCONF_MAX_DESYNC_FACTOR,
  172. DEVCONF_MAX_ADDRESSES,
  173. DEVCONF_FORCE_MLD_VERSION,
  174. DEVCONF_ACCEPT_RA_DEFRTR,
  175. DEVCONF_ACCEPT_RA_PINFO,
  176. DEVCONF_ACCEPT_RA_RTR_PREF,
  177. DEVCONF_RTR_PROBE_INTERVAL,
  178. DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN,
  179. DEVCONF_PROXY_NDP,
  180. DEVCONF_OPTIMISTIC_DAD,
  181. DEVCONF_ACCEPT_SOURCE_ROUTE,
  182. DEVCONF_MAX
  183. };
  184. #ifdef __KERNEL__
  185. #include <linux/icmpv6.h>
  186. #include <linux/tcp.h>
  187. #include <linux/udp.h>
  188. #include <net/if_inet6.h> /* struct ipv6_mc_socklist */
  189. #include <net/inet_sock.h>
  190. static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)
  191. {
  192. return (struct ipv6hdr *)skb_network_header(skb);
  193. }
  194. static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb)
  195. {
  196. return (struct ipv6hdr *)skb_transport_header(skb);
  197. }
  198. /*
  199. This structure contains results of exthdrs parsing
  200. as offsets from skb->nh.
  201. */
  202. struct inet6_skb_parm {
  203. int iif;
  204. __u16 ra;
  205. __u16 hop;
  206. __u16 dst0;
  207. __u16 srcrt;
  208. __u16 dst1;
  209. __u16 lastopt;
  210. __u32 nhoff;
  211. __u16 flags;
  212. #ifdef CONFIG_IPV6_MIP6
  213. __u16 dsthao;
  214. #endif
  215. #define IP6SKB_XFRM_TRANSFORMED 1
  216. };
  217. #define IP6CB(skb) ((struct inet6_skb_parm*)((skb)->cb))
  218. static inline int inet6_iif(const struct sk_buff *skb)
  219. {
  220. return IP6CB(skb)->iif;
  221. }
  222. struct inet6_request_sock {
  223. struct in6_addr loc_addr;
  224. struct in6_addr rmt_addr;
  225. struct sk_buff *pktopts;
  226. int iif;
  227. };
  228. struct tcp6_request_sock {
  229. struct tcp_request_sock tcp6rsk_tcp;
  230. struct inet6_request_sock tcp6rsk_inet6;
  231. };
  232. /**
  233. * struct ipv6_pinfo - ipv6 private area
  234. *
  235. * In the struct sock hierarchy (tcp6_sock, upd6_sock, etc)
  236. * this _must_ be the last member, so that inet6_sk_generic
  237. * is able to calculate its offset from the base struct sock
  238. * by using the struct proto->slab_obj_size member. -acme
  239. */
  240. struct ipv6_pinfo {
  241. struct in6_addr saddr;
  242. struct in6_addr rcv_saddr;
  243. struct in6_addr daddr;
  244. struct in6_addr *daddr_cache;
  245. #ifdef CONFIG_IPV6_SUBTREES
  246. struct in6_addr *saddr_cache;
  247. #endif
  248. __be32 flow_label;
  249. __u32 frag_size;
  250. __s16 hop_limit;
  251. __s16 mcast_hops;
  252. int mcast_oif;
  253. /* pktoption flags */
  254. union {
  255. struct {
  256. __u16 srcrt:2,
  257. osrcrt:2,
  258. rxinfo:1,
  259. rxoinfo:1,
  260. rxhlim:1,
  261. rxohlim:1,
  262. hopopts:1,
  263. ohopopts:1,
  264. dstopts:1,
  265. odstopts:1,
  266. rxflow:1,
  267. rxtclass:1;
  268. } bits;
  269. __u16 all;
  270. } rxopt;
  271. /* sockopt flags */
  272. __u8 mc_loop:1,
  273. recverr:1,
  274. sndflow:1,
  275. pmtudisc:2,
  276. ipv6only:1;
  277. __u8 tclass;
  278. __u32 dst_cookie;
  279. struct ipv6_mc_socklist *ipv6_mc_list;
  280. struct ipv6_ac_socklist *ipv6_ac_list;
  281. struct ipv6_fl_socklist *ipv6_fl_list;
  282. struct ipv6_txoptions *opt;
  283. struct sk_buff *pktoptions;
  284. struct {
  285. struct ipv6_txoptions *opt;
  286. struct rt6_info *rt;
  287. int hop_limit;
  288. int tclass;
  289. } cork;
  290. };
  291. /* WARNING: don't change the layout of the members in {raw,udp,tcp}6_sock! */
  292. struct raw6_sock {
  293. /* inet_sock has to be the first member of raw6_sock */
  294. struct inet_sock inet;
  295. __u32 checksum; /* perform checksum */
  296. __u32 offset; /* checksum offset */
  297. struct icmp6_filter filter;
  298. /* ipv6_pinfo has to be the last member of raw6_sock, see inet6_sk_generic */
  299. struct ipv6_pinfo inet6;
  300. };
  301. struct udp6_sock {
  302. struct udp_sock udp;
  303. /* ipv6_pinfo has to be the last member of udp6_sock, see inet6_sk_generic */
  304. struct ipv6_pinfo inet6;
  305. };
  306. struct tcp6_sock {
  307. struct tcp_sock tcp;
  308. /* ipv6_pinfo has to be the last member of tcp6_sock, see inet6_sk_generic */
  309. struct ipv6_pinfo inet6;
  310. };
  311. extern int inet6_sk_rebuild_header(struct sock *sk);
  312. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  313. static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
  314. {
  315. return inet_sk(__sk)->pinet6;
  316. }
  317. static inline struct inet6_request_sock *
  318. inet6_rsk(const struct request_sock *rsk)
  319. {
  320. return (struct inet6_request_sock *)(((u8 *)rsk) +
  321. inet_rsk(rsk)->inet6_rsk_offset);
  322. }
  323. static inline u32 inet6_rsk_offset(struct request_sock *rsk)
  324. {
  325. return rsk->rsk_ops->obj_size - sizeof(struct inet6_request_sock);
  326. }
  327. static inline struct request_sock *inet6_reqsk_alloc(struct request_sock_ops *ops)
  328. {
  329. struct request_sock *req = reqsk_alloc(ops);
  330. if (req != NULL)
  331. inet_rsk(req)->inet6_rsk_offset = inet6_rsk_offset(req);
  332. return req;
  333. }
  334. static inline struct raw6_sock *raw6_sk(const struct sock *sk)
  335. {
  336. return (struct raw6_sock *)sk;
  337. }
  338. static inline void inet_sk_copy_descendant(struct sock *sk_to,
  339. const struct sock *sk_from)
  340. {
  341. int ancestor_size = sizeof(struct inet_sock);
  342. if (sk_from->sk_family == PF_INET6)
  343. ancestor_size += sizeof(struct ipv6_pinfo);
  344. __inet_sk_copy_descendant(sk_to, sk_from, ancestor_size);
  345. }
  346. #define __ipv6_only_sock(sk) (inet6_sk(sk)->ipv6only)
  347. #define ipv6_only_sock(sk) ((sk)->sk_family == PF_INET6 && __ipv6_only_sock(sk))
  348. struct inet6_timewait_sock {
  349. struct in6_addr tw_v6_daddr;
  350. struct in6_addr tw_v6_rcv_saddr;
  351. };
  352. struct tcp6_timewait_sock {
  353. struct tcp_timewait_sock tcp6tw_tcp;
  354. struct inet6_timewait_sock tcp6tw_inet6;
  355. };
  356. static inline u16 inet6_tw_offset(const struct proto *prot)
  357. {
  358. return prot->twsk_prot->twsk_obj_size -
  359. sizeof(struct inet6_timewait_sock);
  360. }
  361. static inline struct inet6_timewait_sock *inet6_twsk(const struct sock *sk)
  362. {
  363. return (struct inet6_timewait_sock *)(((u8 *)sk) +
  364. inet_twsk(sk)->tw_ipv6_offset);
  365. }
  366. static inline struct in6_addr *__inet6_rcv_saddr(const struct sock *sk)
  367. {
  368. return likely(sk->sk_state != TCP_TIME_WAIT) ?
  369. &inet6_sk(sk)->rcv_saddr : &inet6_twsk(sk)->tw_v6_rcv_saddr;
  370. }
  371. static inline struct in6_addr *inet6_rcv_saddr(const struct sock *sk)
  372. {
  373. return sk->sk_family == AF_INET6 ? __inet6_rcv_saddr(sk) : NULL;
  374. }
  375. static inline int inet_v6_ipv6only(const struct sock *sk)
  376. {
  377. return likely(sk->sk_state != TCP_TIME_WAIT) ?
  378. ipv6_only_sock(sk) : inet_twsk(sk)->tw_ipv6only;
  379. }
  380. #else
  381. #define __ipv6_only_sock(sk) 0
  382. #define ipv6_only_sock(sk) 0
  383. static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
  384. {
  385. return NULL;
  386. }
  387. static inline struct inet6_request_sock *
  388. inet6_rsk(const struct request_sock *rsk)
  389. {
  390. return NULL;
  391. }
  392. static inline struct raw6_sock *raw6_sk(const struct sock *sk)
  393. {
  394. return NULL;
  395. }
  396. #define __inet6_rcv_saddr(__sk) NULL
  397. #define inet6_rcv_saddr(__sk) NULL
  398. #define tcp_twsk_ipv6only(__sk) 0
  399. #define inet_v6_ipv6only(__sk) 0
  400. #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
  401. #define INET6_MATCH(__sk, __hash, __saddr, __daddr, __ports, __dif)\
  402. (((__sk)->sk_hash == (__hash)) && \
  403. ((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports)) && \
  404. ((__sk)->sk_family == AF_INET6) && \
  405. ipv6_addr_equal(&inet6_sk(__sk)->daddr, (__saddr)) && \
  406. ipv6_addr_equal(&inet6_sk(__sk)->rcv_saddr, (__daddr)) && \
  407. (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
  408. #endif /* __KERNEL__ */
  409. #endif /* _IPV6_H */