ipv6.h 9.4 KB

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