in6.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /* $OpenBSD: in6.h,v 1.83 2015/06/08 22:19:28 krw 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 __KAME_NETINET_IN_H_INCLUDED_
  62. #error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553"
  63. #endif
  64. #ifndef _NETINET6_IN6_H_
  65. #define _NETINET6_IN6_H_
  66. /*
  67. * Identification of the network protocol stack
  68. * for *BSD-current/release: http://www.kame.net/dev/cvsweb2.cgi/kame/COVERAGE
  69. * has the table of implementation/integration differences.
  70. */
  71. #define __KAME__
  72. /*
  73. * IPv6 address
  74. */
  75. struct in6_addr {
  76. union {
  77. u_int8_t __u6_addr8[16];
  78. u_int16_t __u6_addr16[8];
  79. u_int32_t __u6_addr32[4];
  80. } __u6_addr; /* 128-bit IP6 address */
  81. };
  82. #define s6_addr __u6_addr.__u6_addr8
  83. #ifdef _KERNEL /* XXX nonstandard */
  84. #define s6_addr8 __u6_addr.__u6_addr8
  85. #define s6_addr16 __u6_addr.__u6_addr16
  86. #define s6_addr32 __u6_addr.__u6_addr32
  87. #endif
  88. #ifndef INET6_ADDRSTRLEN
  89. #define INET6_ADDRSTRLEN 46
  90. #endif
  91. /*
  92. * Socket address for IPv6
  93. */
  94. #if __BSD_VISIBLE
  95. #define SIN6_LEN /* Indicates sockaddr_in6 has a sin6_len field */
  96. #endif /* __BSD_VISIBLE */
  97. struct sockaddr_in6 {
  98. u_int8_t sin6_len; /* length of this struct(sa_family_t)*/
  99. sa_family_t sin6_family; /* AF_INET6 (sa_family_t) */
  100. in_port_t sin6_port; /* Transport layer port # (in_port_t)*/
  101. u_int32_t sin6_flowinfo; /* IP6 flow information */
  102. struct in6_addr sin6_addr; /* IP6 address */
  103. u_int32_t sin6_scope_id; /* intface scope id */
  104. };
  105. /*
  106. * Local definition for masks
  107. */
  108. #ifdef _KERNEL /* XXX nonstandard */
  109. #define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}
  110. #define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \
  111. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
  112. #define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
  113. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
  114. #define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
  115. 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}
  116. #define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
  117. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}
  118. extern const struct sockaddr_in6 sa6_any;
  119. extern const struct in6_addr in6mask0;
  120. extern const struct in6_addr in6mask32;
  121. extern const struct in6_addr in6mask64;
  122. extern const struct in6_addr in6mask96;
  123. extern const struct in6_addr in6mask128;
  124. #endif /* _KERNEL */
  125. /* Both kernel and libc define these for use */
  126. extern const struct in6_addr in6addr_any;
  127. extern const struct in6_addr in6addr_loopback;
  128. extern const struct in6_addr in6addr_intfacelocal_allnodes;
  129. extern const struct in6_addr in6addr_linklocal_allnodes;
  130. extern const struct in6_addr in6addr_linklocal_allrouters;
  131. #if __BSD_VISIBLE
  132. /*
  133. * IPv6 route structure
  134. */
  135. struct route_in6 {
  136. struct rtentry *ro_rt;
  137. u_long ro_tableid; /* padded to long for alignment */
  138. struct sockaddr_in6 ro_dst;
  139. };
  140. /*
  141. * Definition of some useful macros to handle IP6 addresses
  142. */
  143. #define IN6ADDR_ANY_INIT \
  144. {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  145. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
  146. #define IN6ADDR_LOOPBACK_INIT \
  147. {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  148. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
  149. #define IN6ADDR_NODELOCAL_ALLNODES_INIT \
  150. {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  151. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
  152. #define IN6ADDR_INTFACELOCAL_ALLNODES_INIT \
  153. {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  154. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
  155. #define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
  156. {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  157. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
  158. #define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
  159. {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
  160. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
  161. #define IN6_ARE_ADDR_EQUAL(a, b) \
  162. (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
  163. #endif /* __BSD_VISIBLE */
  164. /*
  165. * Macros started with IPV6_ADDR is KAME local
  166. */
  167. #define __IPV6_ADDR_INT32_ONE htonl(1)
  168. #define __IPV6_ADDR_INT32_TWO htonl(2)
  169. #define __IPV6_ADDR_INT32_MNL htonl(0xff010000)
  170. #define __IPV6_ADDR_INT32_MLL htonl(0xff020000)
  171. #define __IPV6_ADDR_INT32_SMP htonl(0x0000ffff)
  172. #define __IPV6_ADDR_INT16_ULL htons(0xfe80)
  173. #define __IPV6_ADDR_INT16_USL htons(0xfec0)
  174. #define __IPV6_ADDR_INT16_MLL htons(0xff02)
  175. /*
  176. * Unspecified
  177. */
  178. #define IN6_IS_ADDR_UNSPECIFIED(a) \
  179. ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
  180. (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
  181. (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \
  182. (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0))
  183. /*
  184. * Loopback
  185. */
  186. #define IN6_IS_ADDR_LOOPBACK(a) \
  187. ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
  188. (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
  189. (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \
  190. (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == __IPV6_ADDR_INT32_ONE))
  191. /*
  192. * IPv4 compatible
  193. */
  194. #define IN6_IS_ADDR_V4COMPAT(a) \
  195. ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
  196. (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
  197. (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) && \
  198. (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != 0) && \
  199. (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != __IPV6_ADDR_INT32_ONE))
  200. /*
  201. * Mapped
  202. */
  203. #define IN6_IS_ADDR_V4MAPPED(a) \
  204. ((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \
  205. (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \
  206. (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == __IPV6_ADDR_INT32_SMP))
  207. /*
  208. * Unicast Scope
  209. * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).
  210. */
  211. #define IN6_IS_ADDR_LINKLOCAL(a) \
  212. (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
  213. #define IN6_IS_ADDR_SITELOCAL(a) \
  214. (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
  215. /*
  216. * Multicast
  217. */
  218. #define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
  219. #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
  220. #define __IPV6_ADDR_SCOPE_NODELOCAL 0x01
  221. #define __IPV6_ADDR_SCOPE_INTFACELOCAL 0x01
  222. #define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02
  223. #define __IPV6_ADDR_SCOPE_SITELOCAL 0x05
  224. #define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */
  225. #define __IPV6_ADDR_SCOPE_GLOBAL 0x0e
  226. #define IN6_IS_ADDR_MC_NODELOCAL(a) \
  227. (IN6_IS_ADDR_MULTICAST(a) && \
  228. (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL))
  229. #define IN6_IS_ADDR_MC_INTFACELOCAL(a) \
  230. (IN6_IS_ADDR_MULTICAST(a) && \
  231. (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_INTFACELOCAL))
  232. #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
  233. (IN6_IS_ADDR_MULTICAST(a) && \
  234. (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL))
  235. #define IN6_IS_ADDR_MC_SITELOCAL(a) \
  236. (IN6_IS_ADDR_MULTICAST(a) && \
  237. (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
  238. #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
  239. (IN6_IS_ADDR_MULTICAST(a) && \
  240. (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
  241. #define IN6_IS_ADDR_MC_GLOBAL(a) \
  242. (IN6_IS_ADDR_MULTICAST(a) && \
  243. (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL))
  244. #ifdef _KERNEL
  245. #define IN6_IS_SCOPE_LINKLOCAL(a) \
  246. ((IN6_IS_ADDR_LINKLOCAL(a)) || \
  247. (IN6_IS_ADDR_MC_LINKLOCAL(a)))
  248. #define IN6_IS_SCOPE_EMBED(a) \
  249. ((IN6_IS_ADDR_LINKLOCAL(a)) || \
  250. (IN6_IS_ADDR_MC_LINKLOCAL(a)) || \
  251. (IN6_IS_ADDR_MC_INTFACELOCAL(a)))
  252. #define IFA6_IS_DEPRECATED(a) \
  253. ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
  254. (u_int32_t)((time_second - (a)->ia6_updatetime)) > \
  255. (a)->ia6_lifetime.ia6t_pltime)
  256. #define IFA6_IS_INVALID(a) \
  257. ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \
  258. (u_int32_t)((time_second - (a)->ia6_updatetime)) > \
  259. (a)->ia6_lifetime.ia6t_vltime)
  260. #endif /* _KERNEL */
  261. /*
  262. * Options for use with [gs]etsockopt at the IPV6 level.
  263. * First word of comment is data type; bool is stored in int.
  264. */
  265. #define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */
  266. #define IPV6_MULTICAST_IF 9 /* u_char; set/get IP6 multicast i/f */
  267. #define IPV6_MULTICAST_HOPS 10 /* u_char; set/get IP6 multicast hops */
  268. #define IPV6_MULTICAST_LOOP 11 /* u_char; set/get IP6 multicast loopback */
  269. #define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */
  270. #define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */
  271. #define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */
  272. #if __BSD_VISIBLE
  273. #define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */
  274. #endif
  275. /* RFC2292 options */
  276. #ifdef _KERNEL
  277. #define IPV6_2292PKTINFO 19 /* bool; send/rcv if, src/dst addr */
  278. #define IPV6_2292HOPLIMIT 20 /* bool; hop limit */
  279. #define IPV6_2292NEXTHOP 21 /* bool; next hop addr */
  280. #define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */
  281. #define IPV6_2292DSTOPTS 23 /* bool; destination option */
  282. #define IPV6_2292RTHDR 24 /* bool; routing header */
  283. #define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */
  284. #endif
  285. #define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */
  286. #define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */
  287. /* new socket options introduced in RFC3542 */
  288. #define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */
  289. #define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */
  290. #define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */
  291. #define IPV6_RECVRTHDR 38 /* bool; recv routing header */
  292. #define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */
  293. #define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */
  294. #ifdef _KERNEL
  295. #define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */
  296. #endif
  297. #define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */
  298. #define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */
  299. #define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt),
  300. 4 bytes int; MTU notification (cmsg) */
  301. /* More new socket options introduced in RFC3542 */
  302. #define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */
  303. #define IPV6_HOPLIMIT 47 /* int; send hop limit */
  304. #define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */
  305. #define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */
  306. #define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */
  307. #define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */
  308. #define IPV6_AUTH_LEVEL 53 /* int; authentication used */
  309. #define IPV6_ESP_TRANS_LEVEL 54 /* int; transport encryption */
  310. #define IPV6_ESP_NETWORK_LEVEL 55 /* int; full-packet encryption */
  311. #if __BSD_VISIBLE
  312. #define IPSEC6_OUTSA 56 /* set the outbound SA for a socket */
  313. #endif
  314. #define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */
  315. #define IPV6_AUTOFLOWLABEL 59 /* bool; attach flowlabel automagically */
  316. #define IPV6_IPCOMP_LEVEL 60 /* int; compression */
  317. #define IPV6_TCLASS 61 /* int; send traffic class value */
  318. #define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */
  319. #define IPV6_PIPEX 63 /* bool; using PIPEX */
  320. #define IPV6_RECVDSTPORT 64 /* bool; receive IP dst port w/dgram */
  321. #define IPV6_RTABLE 0x1021 /* int; routing table, see SO_RTABLE */
  322. /* to define items, should talk with KAME guys first, for *BSD compatibility */
  323. #define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor */
  324. #define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */
  325. /*
  326. * Defaults and limits for options
  327. */
  328. #define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */
  329. #define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
  330. /*
  331. * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.
  332. */
  333. struct ipv6_mreq {
  334. struct in6_addr ipv6mr_multiaddr;
  335. unsigned int ipv6mr_interface;
  336. };
  337. /*
  338. * IPV6_PKTINFO: Packet information(RFC3542 sec 6)
  339. */
  340. struct in6_pktinfo {
  341. struct in6_addr ipi6_addr; /* src/dst IPv6 address */
  342. unsigned int ipi6_ifindex; /* send/recv interface index */
  343. };
  344. /*
  345. * Control structure for IPV6_RECVPATHMTU socket option.
  346. * XXX Not allowed here by POSIX, but required by RFC 3542, so go
  347. * XXX with the code on the pavement.
  348. */
  349. struct ip6_mtuinfo {
  350. struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */
  351. u_int32_t ip6m_mtu;
  352. };
  353. /*
  354. * Argument for IPV6_PORTRANGE:
  355. * - which range to search when port is unspecified at bind() or connect()
  356. */
  357. #define IPV6_PORTRANGE_DEFAULT 0 /* default range */
  358. #define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */
  359. #define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */
  360. #ifdef __BSD_VISIBLE
  361. #ifndef _SOCKLEN_T_DEFINED_
  362. #define _SOCKLEN_T_DEFINED_
  363. typedef __socklen_t socklen_t; /* length type for network syscalls */
  364. #endif
  365. #endif /* __BSD_VISIBLE */
  366. #ifdef _KERNEL
  367. extern u_char inet6ctlerrmap[];
  368. extern struct niqueue ip6intrq; /* IP6 packet input queue */
  369. extern struct in6_addr zeroin6_addr;
  370. struct mbuf;
  371. struct ifnet;
  372. struct cmsghdr;
  373. int in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t);
  374. void in6_proto_cksum_out(struct mbuf *, struct ifnet *);
  375. int in6_localaddr(struct in6_addr *);
  376. int in6_addrscope(struct in6_addr *);
  377. struct in6_ifaddr *in6_ifawithscope(struct ifnet *, struct in6_addr *, u_int);
  378. void in6_get_rand_ifid(struct ifnet *, struct in6_addr *);
  379. int in6_mask2len(struct in6_addr *, u_char *);
  380. struct inpcb;
  381. int in6_embedscope(struct in6_addr *, const struct sockaddr_in6 *,
  382. struct inpcb *, struct ifnet **);
  383. int in6_recoverscope(struct sockaddr_in6 *, const struct in6_addr *,
  384. struct ifnet *);
  385. void in6_clearscope(struct in6_addr *);
  386. struct sockaddr;
  387. struct sockaddr_in6;
  388. struct ifaddr;
  389. struct in6_ifaddr;
  390. /*
  391. * Convert between address family specific and general structs.
  392. * Inline functions check the source type and are stricter than
  393. * casts or defines.
  394. */
  395. static __inline struct sockaddr_in6 *
  396. satosin6(struct sockaddr *sa)
  397. {
  398. return ((struct sockaddr_in6 *)(sa));
  399. }
  400. static __inline struct sockaddr *
  401. sin6tosa(struct sockaddr_in6 *sin6)
  402. {
  403. return ((struct sockaddr *)(sin6));
  404. }
  405. static __inline struct in6_ifaddr *
  406. ifatoia6(struct ifaddr *ifa)
  407. {
  408. return ((struct in6_ifaddr *)(ifa));
  409. }
  410. #endif /* _KERNEL */
  411. #if __BSD_VISIBLE
  412. /*
  413. * Definitions for inet6 sysctl operations.
  414. *
  415. * Third level is protocol number.
  416. * Fourth level is desired variable within that protocol.
  417. */
  418. #define IPV6PROTO_MAXID (IPPROTO_DIVERT + 1) /* don't list to IPV6PROTO_MAX */
  419. #define CTL_IPV6PROTO_NAMES { \
  420. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  421. { 0, 0 }, \
  422. { "tcp6", CTLTYPE_NODE }, \
  423. { 0, 0 }, \
  424. { 0, 0 }, \
  425. { 0, 0 }, \
  426. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  427. { 0, 0 }, \
  428. { 0, 0 }, \
  429. { "udp6", CTLTYPE_NODE }, \
  430. { 0, 0 }, \
  431. { 0, 0 }, \
  432. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  433. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  434. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  435. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  436. { 0, 0 }, \
  437. { "ip6", CTLTYPE_NODE }, \
  438. { 0, 0 }, \
  439. { 0, 0 }, \
  440. { 0, 0 }, \
  441. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  442. { 0, 0 }, \
  443. { "ipsec6", CTLTYPE_NODE }, \
  444. { 0, 0 }, \
  445. { 0, 0 }, \
  446. { 0, 0 }, \
  447. { 0, 0 }, \
  448. { 0, 0 }, \
  449. { 0, 0 }, \
  450. { "icmp6", CTLTYPE_NODE }, \
  451. { 0, 0 }, \
  452. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  453. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  454. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  455. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  456. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  457. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  458. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  459. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  460. { 0, 0 }, \
  461. { 0, 0 }, \
  462. { 0, 0 }, \
  463. { "pim6", CTLTYPE_NODE }, \
  464. { 0, 0 }, \
  465. { 0, 0 }, \
  466. { 0, 0 }, \
  467. { 0, 0 }, \
  468. { 0, 0 }, \
  469. { 0, 0 }, \
  470. /*110*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  471. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  472. /*120*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  473. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  474. /*130*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  475. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  476. /*140*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  477. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  478. /*150*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  479. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  480. /*160*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  481. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  482. /*170*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  483. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  484. /*180*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  485. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  486. /*190*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  487. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  488. /*200*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  489. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  490. /*210*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  491. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  492. /*220*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  493. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  494. /*230*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  495. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  496. /*240*/ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  497. { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
  498. /*250*/ { 0, 0 }, \
  499. { 0, 0 }, \
  500. { 0, 0 }, \
  501. { 0, 0 }, \
  502. { 0, 0 }, \
  503. { 0, 0 }, \
  504. { 0, 0 }, \
  505. { 0, 0 }, \
  506. { "divert", CTLTYPE_NODE }, \
  507. }
  508. /*
  509. * Names for IP sysctl objects
  510. */
  511. #define IPV6CTL_FORWARDING 1 /* act as router */
  512. #define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/
  513. #define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */
  514. #define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */
  515. #define IPV6CTL_STATS 6 /* stats */
  516. #define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */
  517. #define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */
  518. #define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */
  519. #define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */
  520. #define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */
  521. #define IPV6CTL_ACCEPT_RTADV 12
  522. #define IPV6CTL_LOG_INTERVAL 14
  523. #define IPV6CTL_HDRNESTLIMIT 15
  524. #define IPV6CTL_DAD_COUNT 16
  525. #define IPV6CTL_AUTO_FLOWLABEL 17
  526. #define IPV6CTL_DEFMCASTHLIM 18
  527. #define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */
  528. #define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */
  529. #define IPV6CTL_V6ONLY 24
  530. /* 25 to 40: resrved */
  531. #define IPV6CTL_MAXFRAGS 41 /* max fragments */
  532. #define IPV6CTL_MFORWARDING 42
  533. #define IPV6CTL_MULTIPATH 43
  534. #define IPV6CTL_MCAST_PMTU 44 /* path MTU discovery for multicast */
  535. #define IPV6CTL_NEIGHBORGCTHRESH 45
  536. #define IPV6CTL_MAXIFPREFIXES 46
  537. #define IPV6CTL_MAXIFDEFROUTERS 47
  538. #define IPV6CTL_MAXDYNROUTES 48
  539. #define IPV6CTL_DAD_PENDING 49
  540. #define IPV6CTL_MTUDISCTIMEOUT 50
  541. #define IPV6CTL_IFQUEUE 51
  542. #define IPV6CTL_MRTMIF 52
  543. #define IPV6CTL_MRTMFC 53
  544. #define IPV6CTL_MAXID 54
  545. /* New entries should be added here from current IPV6CTL_MAXID value. */
  546. /* to define items, should talk with KAME guys first, for *BSD compatibility */
  547. #define IPV6CTL_NAMES { \
  548. { 0, 0 }, \
  549. { "forwarding", CTLTYPE_INT }, \
  550. { "redirect", CTLTYPE_INT }, \
  551. { "hlim", CTLTYPE_INT }, \
  552. { 0, 0 }, \
  553. { "forwsrcrt", CTLTYPE_INT }, \
  554. { 0, 0 }, \
  555. { 0, 0 }, \
  556. { "mrtproto", CTLTYPE_INT }, \
  557. { "maxfragpackets", CTLTYPE_INT }, \
  558. { "sourcecheck", CTLTYPE_INT }, \
  559. { "sourcecheck_logint", CTLTYPE_INT }, \
  560. { 0, 0 }, \
  561. { 0, 0 }, \
  562. { "log_interval", CTLTYPE_INT }, \
  563. { "hdrnestlimit", CTLTYPE_INT }, \
  564. { "dad_count", CTLTYPE_INT }, \
  565. { "auto_flowlabel", CTLTYPE_INT }, \
  566. { "defmcasthlim", CTLTYPE_INT }, \
  567. { 0, 0 }, \
  568. { 0, 0 }, \
  569. { "use_deprecated", CTLTYPE_INT }, \
  570. { "rr_prune", CTLTYPE_INT }, \
  571. { 0, 0 }, \
  572. { "v6only", CTLTYPE_INT }, \
  573. { 0, 0 }, \
  574. { 0, 0 }, \
  575. { 0, 0 }, \
  576. { 0, 0 }, \
  577. { 0, 0 }, \
  578. { 0, 0 }, \
  579. { 0, 0 }, \
  580. { 0, 0 }, \
  581. { 0, 0 }, \
  582. { 0, 0 }, \
  583. { 0, 0 }, \
  584. { 0, 0 }, \
  585. { 0, 0 }, \
  586. { 0, 0 }, \
  587. { 0, 0 }, \
  588. { 0, 0 }, \
  589. { "maxfrags", CTLTYPE_INT }, \
  590. { "mforwarding", CTLTYPE_INT }, \
  591. { "multipath", CTLTYPE_INT }, \
  592. { "multicast_mtudisc", CTLTYPE_INT }, \
  593. { "neighborgcthresh", CTLTYPE_INT }, \
  594. { "maxifprefixes", CTLTYPE_INT }, \
  595. { "maxifdefrouters", CTLTYPE_INT }, \
  596. { "maxdynroutes", CTLTYPE_INT }, \
  597. { "dad_pending", CTLTYPE_INT }, \
  598. { "mtudisctimeout", CTLTYPE_INT }, \
  599. { "ifq", CTLTYPE_NODE }, \
  600. { "mrtmif", CTLTYPE_STRUCT }, \
  601. { "mrtmfc", CTLTYPE_STRUCT }, \
  602. }
  603. #define IPV6CTL_VARS { \
  604. NULL, \
  605. &ip6_forwarding, \
  606. &ip6_sendredirects, \
  607. &ip6_defhlim, \
  608. NULL, \
  609. NULL, \
  610. NULL, \
  611. NULL, \
  612. NULL, \
  613. &ip6_maxfragpackets, \
  614. NULL, \
  615. NULL, \
  616. NULL, \
  617. NULL, \
  618. &ip6_log_interval, \
  619. &ip6_hdrnestlimit, \
  620. &ip6_dad_count, \
  621. &ip6_auto_flowlabel, \
  622. &ip6_defmcasthlim, \
  623. NULL, \
  624. NULL, \
  625. &ip6_use_deprecated, \
  626. &ip6_rr_prune, \
  627. NULL, \
  628. NULL, \
  629. NULL, \
  630. NULL, \
  631. NULL, \
  632. NULL, \
  633. NULL, \
  634. NULL, \
  635. NULL, \
  636. NULL, \
  637. NULL, \
  638. NULL, \
  639. NULL, \
  640. NULL, \
  641. NULL, \
  642. NULL, \
  643. NULL, \
  644. NULL, \
  645. &ip6_maxfrags, \
  646. &ip6_mforwarding, \
  647. &ip6_multipath, \
  648. &ip6_mcast_pmtu, \
  649. &ip6_neighborgcthresh, \
  650. &ip6_maxifprefixes, \
  651. &ip6_maxifdefrouters, \
  652. &ip6_maxdynroutes, \
  653. NULL, \
  654. NULL, \
  655. NULL, \
  656. NULL, \
  657. NULL, \
  658. }
  659. __BEGIN_DECLS
  660. struct cmsghdr;
  661. extern int inet6_opt_init(void *, socklen_t);
  662. extern int inet6_opt_append(void *, socklen_t, int, u_int8_t,
  663. socklen_t, u_int8_t, void **);
  664. extern int inet6_opt_finish(void *, socklen_t, int);
  665. extern int inet6_opt_set_val(void *, int, void *, socklen_t);
  666. extern int inet6_opt_next(void *, socklen_t, int, u_int8_t *,
  667. socklen_t *, void **);
  668. extern int inet6_opt_find(void *, socklen_t, int, u_int8_t,
  669. socklen_t *, void **);
  670. extern int inet6_opt_get_val(void *, int, void *, socklen_t);
  671. extern socklen_t inet6_rth_space(int, int);
  672. extern void *inet6_rth_init(void *, socklen_t, int, int);
  673. extern int inet6_rth_add(void *, const struct in6_addr *);
  674. extern int inet6_rth_reverse(const void *, void *);
  675. extern int inet6_rth_segments(const void *);
  676. extern struct in6_addr *inet6_rth_getaddr(const void *, int);
  677. __END_DECLS
  678. #endif /* __BSD_VISIBLE */
  679. #endif /* !_NETINET6_IN6_H_ */