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