PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

include/netinet6/in6.h

http://www.minix3.org/
C Header | 808 lines | 535 code | 78 blank | 195 comment | 49 complexity | 35a24a912927f1c7deecf5610dd2f455 MD5 | raw file
Possible License(s): MIT, WTFPL, AGPL-1.0, BSD-3-Clause, GPL-3.0, LGPL-2.0, JSON, 0BSD
  1. /* $NetBSD: in6.h,v 1.68 2009/09/11 22:06:29 dyoung Exp $ */
  2. /* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */
  3. /*
  4. * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the project nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. */
  31. /*
  32. * Copyright (c) 1982, 1986, 1990, 1993
  33. * The Regents of the University of California. All rights reserved.
  34. *
  35. * Redistribution and use in source and binary forms, with or without
  36. * modification, are permitted provided that the following conditions
  37. * are met:
  38. * 1. Redistributions of source code must retain the above copyright
  39. * notice, this list of conditions and the following disclaimer.
  40. * 2. Redistributions in binary form must reproduce the above copyright
  41. * notice, this list of conditions and the following disclaimer in the
  42. * documentation and/or other materials provided with the distribution.
  43. * 3. Neither the name of the University nor the names of its contributors
  44. * may be used to endorse or promote products derived from this software
  45. * without specific prior written permission.
  46. *
  47. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  48. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  51. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  52. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  53. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  54. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  55. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  56. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  57. * SUCH DAMAGE.
  58. *
  59. * @(#)in.h 8.3 (Berkeley) 1/3/94
  60. */
  61. #ifndef _NETINET6_IN6_H_
  62. #define _NETINET6_IN6_H_
  63. #ifndef __KAME_NETINET_IN_H_INCLUDED_
  64. #error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553"
  65. #endif
  66. #include <sys/socket.h>
  67. /*
  68. * Identification of the network protocol stack
  69. * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE
  70. * has the table of implementation/integration differences.
  71. */
  72. #define __KAME__
  73. #define __KAME_VERSION "NetBSD-current"
  74. /*
  75. * Local port number conventions:
  76. *
  77. * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root),
  78. * unless a kernel is compiled with IPNOPRIVPORTS defined.
  79. *
  80. * When a user does a bind(2) or connect(2) with a port number of zero,
  81. * a non-conflicting local port address is chosen.
  82. *
  83. * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although
  84. * that is settable by sysctl(3); net.inet.ip.anonportmin and
  85. * net.inet.ip.anonportmax respectively.
  86. *
  87. * A user may set the IPPROTO_IP option IP_PORTRANGE to change this
  88. * default assignment range.
  89. *
  90. * The value IP_PORTRANGE_DEFAULT causes the default behavior.
  91. *
  92. * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT,
  93. * and exists only for FreeBSD compatibility purposes.
  94. *
  95. * The value IP_PORTRANGE_LOW changes the range to the "low" are
  96. * that is (by convention) restricted to privileged processes.
  97. * This convention is based on "vouchsafe" principles only.
  98. * It is only secure if you trust the remote host to restrict these ports.
  99. * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX.
  100. */
  101. #if defined(_NETBSD_SOURCE)
  102. #define IPV6PORT_RESERVED 1024
  103. #define IPV6PORT_ANONMIN 49152
  104. #define IPV6PORT_ANONMAX 65535
  105. #define IPV6PORT_RESERVEDMIN 600
  106. #define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1)
  107. #endif
  108. /*
  109. * IPv6 address
  110. */
  111. struct in6_addr {
  112. union {
  113. __uint8_t __u6_addr8[16];
  114. __uint16_t __u6_addr16[8];
  115. uint32_t __u6_addr32[4];
  116. } __u6_addr; /* 128-bit IP6 address */
  117. };
  118. #define s6_addr __u6_addr.__u6_addr8
  119. #ifdef _KERNEL /* XXX nonstandard */
  120. #define s6_addr8 __u6_addr.__u6_addr8
  121. #define s6_addr16 __u6_addr.__u6_addr16
  122. #define s6_addr32 __u6_addr.__u6_addr32
  123. #endif
  124. #define INET6_ADDRSTRLEN 46
  125. /*
  126. * Socket address for IPv6
  127. */
  128. #if defined(_NETBSD_SOURCE)
  129. #define SIN6_LEN
  130. #endif
  131. struct sockaddr_in6 {
  132. #ifndef __minix
  133. uint8_t sin6_len; /* length of this struct(socklen_t)*/
  134. #endif /* !__minix */
  135. sa_family_t sin6_family; /* AF_INET6 (sa_family_t) */
  136. in_port_t sin6_port; /* Transport layer port */
  137. uint32_t sin6_flowinfo; /* IP6 flow information */
  138. struct in6_addr sin6_addr; /* IP6 address */
  139. uint32_t sin6_scope_id; /* scope zone index */
  140. };
  141. #ifndef __minix
  142. /*
  143. * Local definition for masks
  144. */
  145. #ifdef _KERNEL /* XXX nonstandard */
  146. #define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}
  147. #define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \
  148. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
  149. #define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
  150. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
  151. #define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
  152. 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}
  153. #define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
  154. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}
  155. #endif
  156. #ifdef _KERNEL
  157. extern const struct sockaddr_in6 sa6_any;
  158. extern const struct in6_addr in6mask0;
  159. extern const struct in6_addr in6mask32;
  160. extern const struct in6_addr in6mask64;
  161. extern const struct in6_addr in6mask96;
  162. extern const struct in6_addr in6mask128;
  163. #endif /* _KERNEL */
  164. /*
  165. * Macros started with IPV6_ADDR is KAME local
  166. */
  167. #ifdef _KERNEL /* XXX nonstandard */
  168. #if BYTE_ORDER == BIG_ENDIAN
  169. #define IPV6_ADDR_INT32_ONE 1
  170. #define IPV6_ADDR_INT32_TWO 2
  171. #define IPV6_ADDR_INT32_MNL 0xff010000
  172. #define IPV6_ADDR_INT32_MLL 0xff020000
  173. #define IPV6_ADDR_INT32_SMP 0x0000ffff
  174. #define IPV6_ADDR_INT16_ULL 0xfe80
  175. #define IPV6_ADDR_INT16_USL 0xfec0
  176. #define IPV6_ADDR_INT16_MLL 0xff02
  177. #elif BYTE_ORDER == LITTLE_ENDIAN
  178. #define IPV6_ADDR_INT32_ONE 0x01000000
  179. #define IPV6_ADDR_INT32_TWO 0x02000000
  180. #define IPV6_ADDR_INT32_MNL 0x000001ff
  181. #define IPV6_ADDR_INT32_MLL 0x000002ff
  182. #define IPV6_ADDR_INT32_SMP 0xffff0000
  183. #define IPV6_ADDR_INT16_ULL 0x80fe
  184. #define IPV6_ADDR_INT16_USL 0xc0fe
  185. #define IPV6_ADDR_INT16_MLL 0x02ff
  186. #endif
  187. #endif
  188. #endif /* !__minix */
  189. /*
  190. * Definition of some useful macros to handle IP6 addresses
  191. */
  192. #define IN6ADDR_ANY_INIT \
  193. {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  194. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
  195. #define IN6ADDR_LOOPBACK_INIT \
  196. {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  197. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
  198. #define IN6ADDR_NODELOCAL_ALLNODES_INIT \
  199. {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  200. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
  201. #define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
  202. {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  203. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
  204. #define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
  205. {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  206. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
  207. extern const struct in6_addr in6addr_any;
  208. extern const struct in6_addr in6addr_loopback;
  209. extern const struct in6_addr in6addr_nodelocal_allnodes;
  210. extern const struct in6_addr in6addr_linklocal_allnodes;
  211. extern const struct in6_addr in6addr_linklocal_allrouters;
  212. #define IN6_ARE_ADDR_EQUAL(a, b) \
  213. (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
  214. /*
  215. * Unspecified
  216. */
  217. #define IN6_IS_ADDR_UNSPECIFIED(a) \
  218. ((a)->__u6_addr.__u6_addr32[0] == 0 && \
  219. (a)->__u6_addr.__u6_addr32[1] == 0 && \
  220. (a)->__u6_addr.__u6_addr32[2] == 0 && \
  221. (a)->__u6_addr.__u6_addr32[3] == 0)
  222. /*
  223. * Loopback
  224. */
  225. #define IN6_IS_ADDR_LOOPBACK(a) \
  226. ((a)->__u6_addr.__u6_addr32[0] == 0 && \
  227. (a)->__u6_addr.__u6_addr32[1] == 0 && \
  228. (a)->__u6_addr.__u6_addr32[2] == 0 && \
  229. (a)->__u6_addr.__u6_addr32[3] == ntohl(1))
  230. /*
  231. * IPv4 compatible
  232. */
  233. #define IN6_IS_ADDR_V4COMPAT(a) \
  234. ((a)->__u6_addr.__u6_addr32[0] == 0 && \
  235. (a)->__u6_addr.__u6_addr32[1] == 0 && \
  236. (a)->__u6_addr.__u6_addr32[2] == 0 && \
  237. (a)->__u6_addr.__u6_addr32[3] != 0 && \
  238. (a)->__u6_addr.__u6_addr32[3] != ntohl(1))
  239. /*
  240. * Mapped
  241. */
  242. #define IN6_IS_ADDR_V4MAPPED(a) \
  243. ((a)->__u6_addr.__u6_addr32[0] == 0 && \
  244. (a)->__u6_addr.__u6_addr32[1] == 0 && \
  245. (a)->__u6_addr.__u6_addr32[2] == ntohl(0x0000ffff))
  246. /*
  247. * KAME Scope Values
  248. */
  249. #ifdef _KERNEL /* XXX nonstandard */
  250. #define IPV6_ADDR_SCOPE_NODELOCAL 0x01
  251. #define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01
  252. #define IPV6_ADDR_SCOPE_LINKLOCAL 0x02
  253. #define IPV6_ADDR_SCOPE_SITELOCAL 0x05
  254. #define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */
  255. #define IPV6_ADDR_SCOPE_GLOBAL 0x0e
  256. #else
  257. #define __IPV6_ADDR_SCOPE_NODELOCAL 0x01
  258. #define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02
  259. #define __IPV6_ADDR_SCOPE_SITELOCAL 0x05
  260. #define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */
  261. #define __IPV6_ADDR_SCOPE_GLOBAL 0x0e
  262. #endif
  263. /*
  264. * Unicast Scope
  265. * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).
  266. */
  267. #define IN6_IS_ADDR_LINKLOCAL(a) \
  268. (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
  269. #define IN6_IS_ADDR_SITELOCAL(a) \
  270. (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
  271. /*
  272. * Multicast
  273. */
  274. #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
  275. #ifdef _KERNEL /* XXX nonstandard */
  276. #define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
  277. #else
  278. #define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
  279. #endif
  280. /*
  281. * Multicast Scope
  282. */
  283. #ifdef _KERNEL /* refers nonstandard items */
  284. #define IN6_IS_ADDR_MC_NODELOCAL(a) \
  285. (IN6_IS_ADDR_MULTICAST(a) && \
  286. (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL))
  287. #define IN6_IS_ADDR_MC_INTFACELOCAL(a) \
  288. (IN6_IS_ADDR_MULTICAST(a) && \
  289. (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL))
  290. #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
  291. (IN6_IS_ADDR_MULTICAST(a) && \
  292. (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL))
  293. #define IN6_IS_ADDR_MC_SITELOCAL(a) \
  294. (IN6_IS_ADDR_MULTICAST(a) && \
  295. (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL))
  296. #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
  297. (IN6_IS_ADDR_MULTICAST(a) && \
  298. (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL))
  299. #define IN6_IS_ADDR_MC_GLOBAL(a) \
  300. (IN6_IS_ADDR_MULTICAST(a) && \
  301. (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL))
  302. #else
  303. #define IN6_IS_ADDR_MC_NODELOCAL(a) \
  304. (IN6_IS_ADDR_MULTICAST(a) && \
  305. (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL))
  306. #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
  307. (IN6_IS_ADDR_MULTICAST(a) && \
  308. (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL))
  309. #define IN6_IS_ADDR_MC_SITELOCAL(a) \
  310. (IN6_IS_ADDR_MULTICAST(a) && \
  311. (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
  312. #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
  313. (IN6_IS_ADDR_MULTICAST(a) && \
  314. (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
  315. #define IN6_IS_ADDR_MC_GLOBAL(a) \
  316. (IN6_IS_ADDR_MULTICAST(a) && \
  317. (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL))
  318. #endif
  319. #ifdef _KERNEL /* nonstandard */
  320. /*
  321. * KAME Scope
  322. */
  323. #define IN6_IS_SCOPE_LINKLOCAL(a) \
  324. ((IN6_IS_ADDR_LINKLOCAL(a)) || \
  325. (IN6_IS_ADDR_MC_LINKLOCAL(a)))
  326. #define IN6_IS_SCOPE_EMBEDDABLE(__a) \
  327. (IN6_IS_SCOPE_LINKLOCAL(__a) || IN6_IS_ADDR_MC_INTFACELOCAL(__a))
  328. #define IFA6_IS_DEPRECATED(a) \
  329. ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
  330. (u_int32_t)((time_second - (a)->ia6_updatetime)) > \
  331. (a)->ia6_lifetime.ia6t_pltime)
  332. #define IFA6_IS_INVALID(a) \
  333. ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \
  334. (u_int32_t)((time_second - (a)->ia6_updatetime)) > \
  335. (a)->ia6_lifetime.ia6t_vltime)
  336. #endif
  337. #ifndef __minix
  338. /*
  339. * Options for use with [gs]etsockopt at the IPV6 level.
  340. * First word of comment is data type; bool is stored in int.
  341. */
  342. /* no hdrincl */
  343. #if 0
  344. /* These are deprecated non-standard options which are no longer supported. */
  345. #define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */
  346. #define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */
  347. #define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */
  348. #define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */
  349. #define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */
  350. #endif
  351. #define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */
  352. #define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */
  353. #define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */
  354. #define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */
  355. #define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */
  356. #define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */
  357. #define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */
  358. #define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */
  359. #if defined(_NETBSD_SOURCE)
  360. #define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */
  361. #endif
  362. /* RFC2292 options */
  363. #ifdef _KERNEL
  364. #define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */
  365. #define IPV6_2292HOPLIMIT 20 /* bool; hop limit */
  366. #define IPV6_2292NEXTHOP 21 /* bool; next hop addr */
  367. #define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */
  368. #define IPV6_2292DSTOPTS 23 /* bool; destination option */
  369. #define IPV6_2292RTHDR 24 /* bool; routing header */
  370. #define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */
  371. #endif
  372. #define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */
  373. #define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */
  374. #if 1 /* IPSEC */
  375. #define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */
  376. #endif
  377. #define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */
  378. /* new socket options introduced in RFC3542 */
  379. #define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */
  380. #define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */
  381. #define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */
  382. #define IPV6_RECVRTHDR 38 /* bool; recv routing header */
  383. #define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */
  384. #define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */
  385. #ifdef _KERNEL
  386. #define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */
  387. #endif
  388. #define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */
  389. #define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */
  390. #define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt),
  391. 4 bytes int; MTU notification (cmsg) */
  392. /* more new socket options introduced in RFC3542 */
  393. #define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */
  394. #define IPV6_HOPLIMIT 47 /* int; send hop limit */
  395. #define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */
  396. #define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */
  397. #define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */
  398. #define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */
  399. #define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */
  400. #ifdef _KERNEL
  401. #define IPV6_OTCLASS 58 /* u_int8_t; send traffic class value */
  402. #endif
  403. #define IPV6_TCLASS 61 /* int; send traffic class value */
  404. #define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */
  405. /* to define items, should talk with KAME guys first, for *BSD compatibility */
  406. #define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */
  407. #define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */
  408. #define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */
  409. /*
  410. * Defaults and limits for options
  411. */
  412. #define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */
  413. #define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
  414. /*
  415. * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.
  416. */
  417. struct ipv6_mreq {
  418. struct in6_addr ipv6mr_multiaddr;
  419. unsigned int ipv6mr_interface;
  420. };
  421. /*
  422. * IPV6_PKTINFO: Packet information(RFC2292 sec 5)
  423. */
  424. struct in6_pktinfo {
  425. struct in6_addr ipi6_addr; /* src/dst IPv6 address */
  426. unsigned int ipi6_ifindex; /* send/recv interface index */
  427. };
  428. /*
  429. * Control structure for IPV6_RECVPATHMTU socket option.
  430. */
  431. struct ip6_mtuinfo {
  432. struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */
  433. uint32_t ip6m_mtu;
  434. };
  435. /*
  436. * Argument for IPV6_PORTRANGE:
  437. * - which range to search when port is unspecified at bind() or connect()
  438. */
  439. #define IPV6_PORTRANGE_DEFAULT 0 /* default range */
  440. #define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */
  441. #define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */
  442. #if defined(_NETBSD_SOURCE)
  443. /*
  444. * Definitions for inet6 sysctl operations.
  445. *
  446. * Third level is protocol number.
  447. * Fourth level is desired variable within that protocol.
  448. */
  449. #define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */
  450. #define CTL_IPV6PROTO_NAMES { \
  451. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  452. { 0, 0 }, \
  453. { "tcp6", CTLTYPE_NODE }, \
  454. { 0, 0 }, \
  455. { 0, 0 }, \
  456. { 0, 0 }, \
  457. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  458. { 0, 0 }, \
  459. { 0, 0 }, \
  460. { "udp6", CTLTYPE_NODE }, \
  461. { 0, 0 }, \
  462. { 0, 0 }, \
  463. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  464. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  465. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  466. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  467. { 0, 0 }, \
  468. { "ip6", CTLTYPE_NODE }, \
  469. { 0, 0 }, \
  470. { 0, 0 }, \
  471. { 0, 0 }, \
  472. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  473. { 0, 0 }, \
  474. { "ipsec6", CTLTYPE_NODE }, \
  475. { 0, 0 }, \
  476. { 0, 0 }, \
  477. { 0, 0 }, \
  478. { 0, 0 }, \
  479. { 0, 0 }, \
  480. { 0, 0 }, \
  481. { "icmp6", CTLTYPE_NODE }, \
  482. { 0, 0 }, \
  483. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  484. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  485. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  486. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  487. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  488. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  489. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  490. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  491. { 0, 0 }, \
  492. { 0, 0 }, \
  493. { 0, 0 }, \
  494. { "pim6", CTLTYPE_NODE }, \
  495. }
  496. /*
  497. * Names for IP sysctl objects
  498. */
  499. #define IPV6CTL_FORWARDING 1 /* act as router */
  500. #define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/
  501. #define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */
  502. #ifdef notyet
  503. #define IPV6CTL_DEFMTU 4 /* default MTU */
  504. #endif
  505. #define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */
  506. #define IPV6CTL_STATS 6 /* stats */
  507. #define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */
  508. #define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */
  509. #define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */
  510. #define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */
  511. #define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */
  512. #define IPV6CTL_ACCEPT_RTADV 12
  513. #define IPV6CTL_KEEPFAITH 13
  514. #define IPV6CTL_LOG_INTERVAL 14
  515. #define IPV6CTL_HDRNESTLIMIT 15
  516. #define IPV6CTL_DAD_COUNT 16
  517. #define IPV6CTL_AUTO_FLOWLABEL 17
  518. #define IPV6CTL_DEFMCASTHLIM 18
  519. #define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */
  520. #define IPV6CTL_KAME_VERSION 20
  521. #define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */
  522. #define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */
  523. /* 23: reserved */
  524. #define IPV6CTL_V6ONLY 24
  525. /* 25 to 27: reserved */
  526. #define IPV6CTL_ANONPORTMIN 28 /* minimum ephemeral port */
  527. #define IPV6CTL_ANONPORTMAX 29 /* maximum ephemeral port */
  528. #define IPV6CTL_LOWPORTMIN 30 /* minimum reserved port */
  529. #define IPV6CTL_LOWPORTMAX 31 /* maximum reserved port */
  530. /* 32 to 38: reserved */
  531. #define IPV6CTL_USE_DEFAULTZONE 39 /* use default scope zone */
  532. /* 40: reserved */
  533. #define IPV6CTL_MAXFRAGS 41 /* max fragments */
  534. #define IPV6CTL_IFQ 42 /* ip6intrq node */
  535. /* New entries should be added here from current IPV6CTL_MAXID value. */
  536. /* to define items, should talk with KAME guys first, for *BSD compatibility */
  537. #define IPV6CTL_MAXID 43
  538. #define IPV6CTL_NAMES { \
  539. { 0, 0 }, \
  540. { "forwarding", CTLTYPE_INT }, \
  541. { "redirect", CTLTYPE_INT }, \
  542. { "hlim", CTLTYPE_INT }, \
  543. { "mtu", CTLTYPE_INT }, \
  544. { "forwsrcrt", CTLTYPE_INT }, \
  545. { "stats", CTLTYPE_STRUCT }, \
  546. { 0, 0 }, \
  547. { "mrtproto", CTLTYPE_INT }, \
  548. { "maxfragpackets", CTLTYPE_INT }, \
  549. { "sourcecheck", CTLTYPE_INT }, \
  550. { "sourcecheck_logint", CTLTYPE_INT }, \
  551. { "accept_rtadv", CTLTYPE_INT }, \
  552. { "keepfaith", CTLTYPE_INT }, \
  553. { "log_interval", CTLTYPE_INT }, \
  554. { "hdrnestlimit", CTLTYPE_INT }, \
  555. { "dad_count", CTLTYPE_INT }, \
  556. { "auto_flowlabel", CTLTYPE_INT }, \
  557. { "defmcasthlim", CTLTYPE_INT }, \
  558. { "gifhlim", CTLTYPE_INT }, \
  559. { "kame_version", CTLTYPE_STRING }, \
  560. { "use_deprecated", CTLTYPE_INT }, \
  561. { "rr_prune", CTLTYPE_INT }, \
  562. { 0, 0 }, \
  563. { "v6only", CTLTYPE_INT }, \
  564. { 0, 0 }, \
  565. { 0, 0 }, \
  566. { 0, 0 }, \
  567. { "anonportmin", CTLTYPE_INT }, \
  568. { "anonportmax", CTLTYPE_INT }, \
  569. { "lowportmin", CTLTYPE_INT }, \
  570. { "lowportmax", CTLTYPE_INT }, \
  571. { 0, 0 }, \
  572. { 0, 0 }, \
  573. { 0, 0 }, \
  574. { 0, 0 }, \
  575. { 0, 0 }, \
  576. { 0, 0 }, \
  577. { 0, 0 }, \
  578. { 0, 0 }, \
  579. { 0, 0 }, \
  580. { "maxfrags", CTLTYPE_INT }, \
  581. { "ifq", CTLTYPE_NODE }, \
  582. }
  583. #endif /* _NETBSD_SOURCE */
  584. #ifdef _KERNEL
  585. struct cmsghdr;
  586. /*
  587. * in6_cksum_phdr:
  588. *
  589. * Compute significant parts of the IPv6 checksum pseudo-header
  590. * for use in a delayed TCP/UDP checksum calculation.
  591. *
  592. * Args:
  593. *
  594. * src Source IPv6 address
  595. * dst Destination IPv6 address
  596. * len htonl(proto-hdr-len)
  597. * nxt htonl(next-proto-number)
  598. *
  599. * NOTE: We expect the src and dst addresses to be 16-bit
  600. * aligned!
  601. */
  602. static __inline u_int16_t __unused
  603. in6_cksum_phdr(const struct in6_addr *src, const struct in6_addr *dst,
  604. u_int32_t len, u_int32_t nxt)
  605. {
  606. u_int32_t sum = 0;
  607. const u_int16_t *w;
  608. /*LINTED*/
  609. w = (const u_int16_t *) src;
  610. sum += w[0];
  611. if (!IN6_IS_SCOPE_LINKLOCAL(src))
  612. sum += w[1];
  613. sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
  614. sum += w[6]; sum += w[7];
  615. /*LINTED*/
  616. w = (const u_int16_t *) dst;
  617. sum += w[0];
  618. if (!IN6_IS_SCOPE_LINKLOCAL(dst))
  619. sum += w[1];
  620. sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
  621. sum += w[6]; sum += w[7];
  622. sum += (u_int16_t)(len >> 16) + (u_int16_t)(len /*& 0xffff*/);
  623. sum += (u_int16_t)(nxt >> 16) + (u_int16_t)(nxt /*& 0xffff*/);
  624. sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/);
  625. if (sum > 0xffff)
  626. sum -= 0xffff;
  627. return (sum);
  628. }
  629. struct mbuf;
  630. struct ifnet;
  631. int sockaddr_in6_cmp(const struct sockaddr *, const struct sockaddr *);
  632. struct sockaddr *sockaddr_in6_externalize(struct sockaddr *, socklen_t,
  633. const struct sockaddr *);
  634. int in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t);
  635. void in6_delayed_cksum(struct mbuf *);
  636. int in6_localaddr(const struct in6_addr *);
  637. int in6_addrscope(const struct in6_addr *);
  638. struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *);
  639. extern void in6_if_up(struct ifnet *);
  640. #ifndef __FreeBSD__
  641. extern int in6_src_sysctl(void *, size_t *, void *, size_t);
  642. #endif
  643. extern void addrsel_policy_init(void);
  644. extern u_char ip6_protox[];
  645. #define satosin6(sa) ((struct sockaddr_in6 *)(sa))
  646. #define satocsin6(sa) ((const struct sockaddr_in6 *)(sa))
  647. #define sin6tosa(sin6) ((struct sockaddr *)(sin6))
  648. #define sin6tocsa(sin6) ((const struct sockaddr *)(sin6))
  649. #define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa))
  650. static inline void
  651. sockaddr_in6_init1(struct sockaddr_in6 *sin6, const struct in6_addr *addr,
  652. in_port_t port, uint32_t flowinfo, uint32_t scope_id)
  653. {
  654. sin6->sin6_port = port;
  655. sin6->sin6_flowinfo = flowinfo;
  656. sin6->sin6_addr = *addr;
  657. sin6->sin6_scope_id = scope_id;
  658. }
  659. static inline void
  660. sockaddr_in6_init(struct sockaddr_in6 *sin6, const struct in6_addr *addr,
  661. in_port_t port, uint32_t flowinfo, uint32_t scope_id)
  662. {
  663. sin6->sin6_family = AF_INET6;
  664. sin6->sin6_len = sizeof(*sin6);
  665. sockaddr_in6_init1(sin6, addr, port, flowinfo, scope_id);
  666. }
  667. static inline struct sockaddr *
  668. sockaddr_in6_alloc(const struct in6_addr *addr, in_port_t port,
  669. uint32_t flowinfo, uint32_t scope_id, int flags)
  670. {
  671. struct sockaddr *sa;
  672. if ((sa = sockaddr_alloc(AF_INET6, sizeof(struct sockaddr_in6),
  673. flags)) == NULL)
  674. return NULL;
  675. sockaddr_in6_init1(satosin6(sa), addr, port, flowinfo, scope_id);
  676. return sa;
  677. }
  678. #endif /* _KERNEL */
  679. #if defined(_NETBSD_SOURCE)
  680. #include <machine/ansi.h>
  681. #ifdef _BSD_SIZE_T_
  682. typedef _BSD_SIZE_T_ size_t;
  683. #define _SIZE_T
  684. #undef _BSD_SIZE_T_
  685. #endif
  686. #include <sys/cdefs.h>
  687. __BEGIN_DECLS
  688. struct cmsghdr;
  689. void in6_sin6_2_sin(struct sockaddr_in *, struct sockaddr_in6 *);
  690. void in6_sin_2_v4mapsin6(struct sockaddr_in *, struct sockaddr_in6 *);
  691. void in6_sin6_2_sin_in_sock(struct sockaddr *);
  692. void in6_sin_2_v4mapsin6_in_sock(struct sockaddr **);
  693. extern int inet6_option_space(int);
  694. extern int inet6_option_init(void *, struct cmsghdr **, int);
  695. extern int inet6_option_append(struct cmsghdr *, const uint8_t *,
  696. int, int);
  697. extern uint8_t *inet6_option_alloc(struct cmsghdr *, int, int, int);
  698. extern int inet6_option_next(const struct cmsghdr *, uint8_t **);
  699. extern int inet6_option_find(const struct cmsghdr *, uint8_t **, int);
  700. extern size_t inet6_rthdr_space(int, int);
  701. extern struct cmsghdr *inet6_rthdr_init(void *, int);
  702. extern int inet6_rthdr_add(struct cmsghdr *, const struct in6_addr *,
  703. unsigned int);
  704. extern int inet6_rthdr_lasthop(struct cmsghdr *, unsigned int);
  705. #if 0 /* not implemented yet */
  706. extern int inet6_rthdr_reverse(const struct cmsghdr *, struct cmsghdr *);
  707. #endif
  708. extern int inet6_rthdr_segments(const struct cmsghdr *);
  709. extern struct in6_addr *inet6_rthdr_getaddr(struct cmsghdr *, int);
  710. extern int inet6_rthdr_getflags(const struct cmsghdr *, int);
  711. extern int inet6_opt_init(void *, socklen_t);
  712. extern int inet6_opt_append(void *, socklen_t, int, uint8_t,
  713. socklen_t, uint8_t, void **);
  714. extern int inet6_opt_finish(void *, socklen_t, int);
  715. extern int inet6_opt_set_val(void *, int, void *, socklen_t);
  716. extern int inet6_opt_next(void *, socklen_t, int, uint8_t *,
  717. socklen_t *, void **);
  718. extern int inet6_opt_find(void *, socklen_t, int, uint8_t,
  719. socklen_t *, void **);
  720. extern int inet6_opt_get_val(void *, int, void *, socklen_t);
  721. extern socklen_t inet6_rth_space(int, int);
  722. extern void *inet6_rth_init(void *, socklen_t, int, int);
  723. extern int inet6_rth_add(void *, const struct in6_addr *);
  724. extern int inet6_rth_reverse(const void *, void *);
  725. extern int inet6_rth_segments(const void *);
  726. extern struct in6_addr *inet6_rth_getaddr(const void *, int);
  727. __END_DECLS
  728. #endif /* _NETBSD_SOURCE */
  729. #endif /* !__minix */
  730. #endif /* !_NETINET6_IN6_H_ */