ipv6.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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 /* Deprecated; will be removed */
  22. #define IPV6_SRCRT_TYPE_0 0 /* Deprecated; will be removed */
  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. /*
  76. * IPv6 fixed header
  77. *
  78. * BEWARE, it is incorrect. The first 4 bits of flow_lbl
  79. * are glued to priority now, forming "class".
  80. */
  81. struct ipv6hdr {
  82. #if defined(__LITTLE_ENDIAN_BITFIELD)
  83. __u8 priority:4,
  84. version:4;
  85. #elif defined(__BIG_ENDIAN_BITFIELD)
  86. __u8 version:4,
  87. priority:4;
  88. #else
  89. #error "Please fix <asm/byteorder.h>"
  90. #endif
  91. __u8 flow_lbl[3];
  92. __be16 payload_len;
  93. __u8 nexthdr;
  94. __u8 hop_limit;
  95. struct in6_addr saddr;
  96. struct in6_addr daddr;
  97. };
  98. /*
  99. * This structure contains configuration options per IPv6 link.
  100. */
  101. struct ipv6_devconf {
  102. __s32 forwarding;
  103. __s32 hop_limit;
  104. __s32 mtu6;
  105. __s32 accept_ra;
  106. __s32 accept_redirects;
  107. __s32 autoconf;
  108. __s32 dad_transmits;
  109. __s32 rtr_solicits;
  110. __s32 rtr_solicit_interval;
  111. __s32 rtr_solicit_delay;
  112. __s32 force_mld_version;
  113. #ifdef CONFIG_IPV6_PRIVACY
  114. __s32 use_tempaddr;
  115. __s32 temp_valid_lft;
  116. __s32 temp_prefered_lft;
  117. __s32 regen_max_retry;
  118. __s32 max_desync_factor;
  119. #endif
  120. __s32 max_addresses;
  121. __s32 accept_ra_defrtr;
  122. __s32 accept_ra_pinfo;
  123. #ifdef CONFIG_IPV6_ROUTER_PREF
  124. __s32 accept_ra_rtr_pref;
  125. __s32 rtr_probe_interval;
  126. #ifdef CONFIG_IPV6_ROUTE_INFO
  127. __s32 accept_ra_rt_info_max_plen;
  128. #endif
  129. #endif
  130. __s32 proxy_ndp;
  131. __s32 accept_source_route;
  132. #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
  133. __s32 optimistic_dad;
  134. #endif
  135. void *sysctl;
  136. };
  137. /* index values for the variables in ipv6_devconf */
  138. enum {
  139. DEVCONF_FORWARDING = 0,
  140. DEVCONF_HOPLIMIT,
  141. DEVCONF_MTU6,
  142. DEVCONF_ACCEPT_RA,
  143. DEVCONF_ACCEPT_REDIRECTS,
  144. DEVCONF_AUTOCONF,
  145. DEVCONF_DAD_TRANSMITS,
  146. DEVCONF_RTR_SOLICITS,
  147. DEVCONF_RTR_SOLICIT_INTERVAL,
  148. DEVCONF_RTR_SOLICIT_DELAY,
  149. DEVCONF_USE_TEMPADDR,
  150. DEVCONF_TEMP_VALID_LFT,
  151. DEVCONF_TEMP_PREFERED_LFT,
  152. DEVCONF_REGEN_MAX_RETRY,
  153. DEVCONF_MAX_DESYNC_FACTOR,
  154. DEVCONF_MAX_ADDRESSES,
  155. DEVCONF_FORCE_MLD_VERSION,
  156. DEVCONF_ACCEPT_RA_DEFRTR,
  157. DEVCONF_ACCEPT_RA_PINFO,
  158. DEVCONF_ACCEPT_RA_RTR_PREF,
  159. DEVCONF_RTR_PROBE_INTERVAL,
  160. DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN,
  161. DEVCONF_PROXY_NDP,
  162. DEVCONF_OPTIMISTIC_DAD,
  163. DEVCONF_ACCEPT_SOURCE_ROUTE,
  164. DEVCONF_MAX
  165. };
  166. #ifdef __KERNEL__
  167. #include <linux/icmpv6.h>
  168. #include <linux/tcp.h>
  169. #include <linux/udp.h>
  170. #include <net/inet_sock.h>
  171. static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)
  172. {
  173. return (struct ipv6hdr *)skb_network_header(skb);
  174. }
  175. static inline struct ipv6hdr *ipipv6_hdr(const struct sk_buff *skb)
  176. {
  177. return (struct ipv6hdr *)skb_transport_header(skb);
  178. }
  179. /*
  180. This structure contains results of exthdrs parsing
  181. as offsets from skb->nh.
  182. */
  183. struct inet6_skb_parm {
  184. int iif;
  185. __u16 ra;
  186. __u16 hop;
  187. __u16 dst0;
  188. __u16 srcrt;
  189. __u16 dst1;
  190. __u16 lastopt;
  191. __u32 nhoff;
  192. __u16 flags;
  193. #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
  194. __u16 dsthao;
  195. #endif
  196. #define IP6SKB_XFRM_TRANSFORMED 1
  197. };
  198. #define IP6CB(skb) ((struct inet6_skb_parm*)((skb)->cb))
  199. static inline int inet6_iif(const struct sk_buff *skb)
  200. {
  201. return IP6CB(skb)->iif;
  202. }
  203. struct inet6_request_sock {
  204. struct in6_addr loc_addr;
  205. struct in6_addr rmt_addr;
  206. struct sk_buff *pktopts;
  207. int iif;
  208. };
  209. struct tcp6_request_sock {
  210. struct tcp_request_sock tcp6rsk_tcp;
  211. struct inet6_request_sock tcp6rsk_inet6;
  212. };
  213. struct ipv6_mc_socklist;
  214. struct ipv6_ac_socklist;
  215. struct ipv6_fl_socklist;
  216. /**
  217. * struct ipv6_pinfo - ipv6 private area
  218. *
  219. * In the struct sock hierarchy (tcp6_sock, upd6_sock, etc)
  220. * this _must_ be the last member, so that inet6_sk_generic
  221. * is able to calculate its offset from the base struct sock
  222. * by using the struct proto->slab_obj_size member. -acme
  223. */
  224. struct ipv6_pinfo {
  225. struct in6_addr saddr;
  226. struct in6_addr rcv_saddr;
  227. struct in6_addr daddr;
  228. struct in6_addr *daddr_cache;
  229. #ifdef CONFIG_IPV6_SUBTREES
  230. struct in6_addr *saddr_cache;
  231. #endif
  232. __be32 flow_label;
  233. __u32 frag_size;
  234. /*
  235. * Packed in 16bits.
  236. * Omit one shift by by putting the signed field at MSB.
  237. */
  238. #if defined(__BIG_ENDIAN_BITFIELD)
  239. __s16 hop_limit:9;
  240. __u16 __unused_1:7;
  241. #else
  242. __u16 __unused_1:7;
  243. __s16 hop_limit:9;
  244. #endif
  245. #if defined(__BIG_ENDIAN_BITFIELD)
  246. /* Packed in 16bits. */
  247. __s16 mcast_hops:9;
  248. __u16 __unused_2:6,
  249. mc_loop:1;
  250. #else
  251. __u16 mc_loop:1,
  252. __unused_2:6;
  253. __s16 mcast_hops:9;
  254. #endif
  255. int mcast_oif;
  256. /* pktoption flags */
  257. union {
  258. struct {
  259. __u16 srcrt:1,
  260. osrcrt:1,
  261. rxinfo:1,
  262. rxoinfo:1,
  263. rxhlim:1,
  264. rxohlim:1,
  265. hopopts:1,
  266. ohopopts:1,
  267. dstopts:1,
  268. odstopts:1,
  269. rxflow:1,
  270. rxtclass:1;
  271. } bits;
  272. __u16 all;
  273. } rxopt;
  274. /* sockopt flags */
  275. __u8 recverr:1,
  276. sndflow:1,
  277. pmtudisc:2,
  278. ipv6only:1,
  279. srcprefs:3; /* 001: prefer temporary address
  280. * 010: prefer public address
  281. * 100: prefer care-of address
  282. */
  283. __u8 tclass;
  284. __u32 dst_cookie;
  285. struct ipv6_mc_socklist *ipv6_mc_list;
  286. struct ipv6_ac_socklist *ipv6_ac_list;
  287. struct ipv6_fl_socklist *ipv6_fl_list;
  288. struct ipv6_txoptions *opt;
  289. struct sk_buff *pktoptions;
  290. struct {
  291. struct ipv6_txoptions *opt;
  292. u8 hop_limit;
  293. u8 tclass;
  294. } cork;
  295. };
  296. /* WARNING: don't change the layout of the members in {raw,udp,tcp}6_sock! */
  297. struct raw6_sock {
  298. /* inet_sock has to be the first member of raw6_sock */
  299. struct inet_sock inet;
  300. __u32 checksum; /* perform checksum */
  301. __u32 offset; /* checksum offset */
  302. struct icmp6_filter filter;
  303. /* ipv6_pinfo has to be the last member of raw6_sock, see inet6_sk_generic */
  304. struct ipv6_pinfo inet6;
  305. };
  306. struct udp6_sock {
  307. struct udp_sock udp;
  308. /* ipv6_pinfo has to be the last member of udp6_sock, see inet6_sk_generic */
  309. struct ipv6_pinfo inet6;
  310. };
  311. struct tcp6_sock {
  312. struct tcp_sock tcp;
  313. /* ipv6_pinfo has to be the last member of tcp6_sock, see inet6_sk_generic */
  314. struct ipv6_pinfo inet6;
  315. };
  316. extern int inet6_sk_rebuild_header(struct sock *sk);
  317. #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
  318. static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
  319. {
  320. return inet_sk(__sk)->pinet6;
  321. }
  322. static inline struct inet6_request_sock *
  323. inet6_rsk(const struct request_sock *rsk)
  324. {
  325. return (struct inet6_request_sock *)(((u8 *)rsk) +
  326. inet_rsk(rsk)->inet6_rsk_offset);
  327. }
  328. static inline u32 inet6_rsk_offset(struct request_sock *rsk)
  329. {
  330. return rsk->rsk_ops->obj_size - sizeof(struct inet6_request_sock);
  331. }
  332. static inline struct request_sock *inet6_reqsk_alloc(struct request_sock_ops *ops)
  333. {
  334. struct request_sock *req = reqsk_alloc(ops);
  335. if (req != NULL)
  336. inet_rsk(req)->inet6_rsk_offset = inet6_rsk_offset(req);
  337. return req;
  338. }
  339. static inline struct raw6_sock *raw6_sk(const struct sock *sk)
  340. {
  341. return (struct raw6_sock *)sk;
  342. }
  343. static inline void inet_sk_copy_descendant(struct sock *sk_to,
  344. const struct sock *sk_from)
  345. {
  346. int ancestor_size = sizeof(struct inet_sock);
  347. if (sk_from->sk_family == PF_INET6)
  348. ancestor_size += sizeof(struct ipv6_pinfo);
  349. __inet_sk_copy_descendant(sk_to, sk_from, ancestor_size);
  350. }
  351. #define __ipv6_only_sock(sk) (inet6_sk(sk)->ipv6only)
  352. #define ipv6_only_sock(sk) ((sk)->sk_family == PF_INET6 && __ipv6_only_sock(sk))
  353. struct inet6_timewait_sock {
  354. struct in6_addr tw_v6_daddr;
  355. struct in6_addr tw_v6_rcv_saddr;
  356. };
  357. struct tcp6_timewait_sock {
  358. struct tcp_timewait_sock tcp6tw_tcp;
  359. struct inet6_timewait_sock tcp6tw_inet6;
  360. };
  361. static inline u16 inet6_tw_offset(const struct proto *prot)
  362. {
  363. return prot->twsk_prot->twsk_obj_size -
  364. sizeof(struct inet6_timewait_sock);
  365. }
  366. static inline struct inet6_timewait_sock *inet6_twsk(const struct sock *sk)
  367. {
  368. return (struct inet6_timewait_sock *)(((u8 *)sk) +
  369. inet_twsk(sk)->tw_ipv6_offset);
  370. }
  371. static inline struct in6_addr *__inet6_rcv_saddr(const struct sock *sk)
  372. {
  373. return likely(sk->sk_state != TCP_TIME_WAIT) ?
  374. &inet6_sk(sk)->rcv_saddr : &inet6_twsk(sk)->tw_v6_rcv_saddr;
  375. }
  376. static inline struct in6_addr *inet6_rcv_saddr(const struct sock *sk)
  377. {
  378. return sk->sk_family == AF_INET6 ? __inet6_rcv_saddr(sk) : NULL;
  379. }
  380. static inline int inet_v6_ipv6only(const struct sock *sk)
  381. {
  382. return likely(sk->sk_state != TCP_TIME_WAIT) ?
  383. ipv6_only_sock(sk) : inet_twsk(sk)->tw_ipv6only;
  384. }
  385. #else
  386. #define __ipv6_only_sock(sk) 0
  387. #define ipv6_only_sock(sk) 0
  388. static inline struct ipv6_pinfo * inet6_sk(const struct sock *__sk)
  389. {
  390. return NULL;
  391. }
  392. static inline struct inet6_request_sock *
  393. inet6_rsk(const struct request_sock *rsk)
  394. {
  395. return NULL;
  396. }
  397. static inline struct raw6_sock *raw6_sk(const struct sock *sk)
  398. {
  399. return NULL;
  400. }
  401. #define __inet6_rcv_saddr(__sk) NULL
  402. #define inet6_rcv_saddr(__sk) NULL
  403. #define tcp_twsk_ipv6only(__sk) 0
  404. #define inet_v6_ipv6only(__sk) 0
  405. #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
  406. #define INET6_MATCH(__sk, __net, __hash, __saddr, __daddr, __ports, __dif)\
  407. (((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net) && \
  408. ((*((__portpair *)&(inet_sk(__sk)->dport))) == (__ports)) && \
  409. ((__sk)->sk_family == AF_INET6) && \
  410. ipv6_addr_equal(&inet6_sk(__sk)->daddr, (__saddr)) && \
  411. ipv6_addr_equal(&inet6_sk(__sk)->rcv_saddr, (__daddr)) && \
  412. (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
  413. #define INET6_TW_MATCH(__sk, __net, __hash, __saddr, __daddr, __ports, __dif) \
  414. (((__sk)->sk_hash == (__hash)) && sock_net((__sk)) == (__net) && \
  415. (*((__portpair *)&(inet_twsk(__sk)->tw_dport)) == (__ports)) && \
  416. ((__sk)->sk_family == PF_INET6) && \
  417. (ipv6_addr_equal(&inet6_twsk(__sk)->tw_v6_daddr, (__saddr))) && \
  418. (ipv6_addr_equal(&inet6_twsk(__sk)->tw_v6_rcv_saddr, (__daddr))) && \
  419. (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
  420. #endif /* __KERNEL__ */
  421. #endif /* _IPV6_H */