ipv6.h 11 KB

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