xref: /netbsd-src/sys/netinet6/in6.h (revision 9fbd88883c38d0c0fbfcbe66d76fe6b0fab3f9de)
1 /*	$NetBSD: in6.h,v 1.33 2001/12/21 08:54:54 itojun 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. All advertising materials mentioning features or use of this software
46  *    must display the following acknowledgement:
47  *	This product includes software developed by the University of
48  *	California, Berkeley and its contributors.
49  * 4. Neither the name of the University nor the names of its contributors
50  *    may be used to endorse or promote products derived from this software
51  *    without specific prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63  * SUCH DAMAGE.
64  *
65  *	@(#)in.h	8.3 (Berkeley) 1/3/94
66  */
67 
68 #ifndef __KAME_NETINET_IN_H_INCLUDED_
69 #error "do not include netinet6/in6.h directly, include netinet/in.h.  see RFC2553"
70 #endif
71 
72 #ifndef _NETINET6_IN6_H_
73 #define _NETINET6_IN6_H_
74 
75 /*
76  * Identification of the network protocol stack
77  * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE
78  * has the table of implementation/integration differences.
79  */
80 #define __KAME__
81 #define __KAME_VERSION		"NetBSD-current"
82 
83 /*
84  * Local port number conventions:
85  *
86  * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root),
87  * unless a kernel is compiled with IPNOPRIVPORTS defined.
88  *
89  * When a user does a bind(2) or connect(2) with a port number of zero,
90  * a non-conflicting local port address is chosen.
91  *
92  * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although
93  * that is settable by sysctl(3); net.inet.ip.anonportmin and
94  * net.inet.ip.anonportmax respectively.
95  *
96  * A user may set the IPPROTO_IP option IP_PORTRANGE to change this
97  * default assignment range.
98  *
99  * The value IP_PORTRANGE_DEFAULT causes the default behavior.
100  *
101  * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT,
102  * and exists only for FreeBSD compatibility purposes.
103  *
104  * The value IP_PORTRANGE_LOW changes the range to the "low" are
105  * that is (by convention) restricted to privileged processes.
106  * This convention is based on "vouchsafe" principles only.
107  * It is only secure if you trust the remote host to restrict these ports.
108  * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX.
109  */
110 
111 #define	IPV6PORT_RESERVED	1024
112 #define	IPV6PORT_ANONMIN	49152
113 #define	IPV6PORT_ANONMAX	65535
114 #define	IPV6PORT_RESERVEDMIN	600
115 #define	IPV6PORT_RESERVEDMAX	(IPV6PORT_RESERVED-1)
116 
117 /*
118  * IPv6 address
119  */
120 struct in6_addr {
121 	union {
122 		u_int8_t   __u6_addr8[16];
123 		u_int16_t  __u6_addr16[8];
124 		u_int32_t  __u6_addr32[4];
125 	} __u6_addr;			/* 128-bit IP6 address */
126 };
127 
128 #define s6_addr   __u6_addr.__u6_addr8
129 #ifdef _KERNEL	/* XXX nonstandard */
130 #define s6_addr8  __u6_addr.__u6_addr8
131 #define s6_addr16 __u6_addr.__u6_addr16
132 #define s6_addr32 __u6_addr.__u6_addr32
133 #endif
134 
135 #define INET6_ADDRSTRLEN	46
136 
137 /*
138  * Socket address for IPv6
139  */
140 #ifndef _XOPEN_SOURCE
141 #define SIN6_LEN
142 #endif
143 struct sockaddr_in6 {
144 	u_int8_t	sin6_len;	/* length of this struct(sa_family_t)*/
145 	sa_family_t	sin6_family;	/* AF_INET6 (sa_family_t) */
146 	u_int16_t	sin6_port;	/* Transport layer port # (in_port_t)*/
147 	u_int32_t	sin6_flowinfo;	/* IP6 flow information */
148 	struct in6_addr	sin6_addr;	/* IP6 address */
149 	u_int32_t	sin6_scope_id;	/* scope zone index */
150 };
151 
152 /*
153  * Local definition for masks
154  */
155 #ifdef _KERNEL	/* XXX nonstandard */
156 #define IN6MASK0	{{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}
157 #define IN6MASK32	{{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \
158 			    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
159 #define IN6MASK64	{{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
160 			    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
161 #define IN6MASK96	{{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
162 			    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}
163 #define IN6MASK128	{{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
164 			    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}
165 #endif
166 
167 #ifdef _KERNEL
168 extern const struct sockaddr_in6 sa6_any;
169 
170 extern const struct in6_addr in6mask0;
171 extern const struct in6_addr in6mask32;
172 extern const struct in6_addr in6mask64;
173 extern const struct in6_addr in6mask96;
174 extern const struct in6_addr in6mask128;
175 #endif /* _KERNEL */
176 
177 /*
178  * Macros started with IPV6_ADDR is KAME local
179  */
180 #ifdef _KERNEL	/* XXX nonstandard */
181 #if BYTE_ORDER == BIG_ENDIAN
182 #define IPV6_ADDR_INT32_ONE	1
183 #define IPV6_ADDR_INT32_TWO	2
184 #define IPV6_ADDR_INT32_MNL	0xff010000
185 #define IPV6_ADDR_INT32_MLL	0xff020000
186 #define IPV6_ADDR_INT32_SMP	0x0000ffff
187 #define IPV6_ADDR_INT16_ULL	0xfe80
188 #define IPV6_ADDR_INT16_USL	0xfec0
189 #define IPV6_ADDR_INT16_MLL	0xff02
190 #elif BYTE_ORDER == LITTLE_ENDIAN
191 #define IPV6_ADDR_INT32_ONE	0x01000000
192 #define IPV6_ADDR_INT32_TWO	0x02000000
193 #define IPV6_ADDR_INT32_MNL	0x000001ff
194 #define IPV6_ADDR_INT32_MLL	0x000002ff
195 #define IPV6_ADDR_INT32_SMP	0xffff0000
196 #define IPV6_ADDR_INT16_ULL	0x80fe
197 #define IPV6_ADDR_INT16_USL	0xc0fe
198 #define IPV6_ADDR_INT16_MLL	0x02ff
199 #endif
200 #endif
201 
202 /*
203  * Definition of some useful macros to handle IP6 addresses
204  */
205 #define IN6ADDR_ANY_INIT \
206 	{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
207 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
208 #define IN6ADDR_LOOPBACK_INIT \
209 	{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
210 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
211 #define IN6ADDR_NODELOCAL_ALLNODES_INIT \
212 	{{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
213 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
214 #define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
215 	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
216 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
217 #define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
218 	{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
219 	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
220 
221 extern const struct in6_addr in6addr_any;
222 extern const struct in6_addr in6addr_loopback;
223 extern const struct in6_addr in6addr_nodelocal_allnodes;
224 extern const struct in6_addr in6addr_linklocal_allnodes;
225 extern const struct in6_addr in6addr_linklocal_allrouters;
226 
227 /*
228  * Equality
229  * NOTE: Some of kernel programming environment (for example, openbsd/sparc)
230  * does not supply memcmp().  For userland memcmp() is preferred as it is
231  * in ANSI standard.
232  */
233 #ifdef _KERNEL
234 #define IN6_ARE_ADDR_EQUAL(a, b)			\
235     (bcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
236 #else
237 #define IN6_ARE_ADDR_EQUAL(a, b)			\
238     (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
239 #endif
240 
241 /*
242  * Unspecified
243  */
244 #define IN6_IS_ADDR_UNSPECIFIED(a)	\
245 	((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) &&	\
246 	 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) &&	\
247 	 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) &&	\
248 	 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == 0))
249 
250 /*
251  * Loopback
252  */
253 #define IN6_IS_ADDR_LOOPBACK(a)		\
254 	((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) &&	\
255 	 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) &&	\
256 	 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) &&	\
257 	 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) == ntohl(1)))
258 
259 /*
260  * IPv4 compatible
261  */
262 #define IN6_IS_ADDR_V4COMPAT(a)		\
263 	((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) &&	\
264 	 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) &&	\
265 	 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == 0) &&	\
266 	 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != 0) &&	\
267 	 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[12]) != ntohl(1)))
268 
269 /*
270  * Mapped
271  */
272 #define IN6_IS_ADDR_V4MAPPED(a)		      \
273 	((*(const u_int32_t *)(const void *)(&(a)->s6_addr[0]) == 0) &&	\
274 	 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[4]) == 0) &&	\
275 	 (*(const u_int32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff)))
276 
277 /*
278  * KAME Scope Values
279  */
280 
281 #ifdef _KERNEL	/* XXX nonstandard */
282 #define IPV6_ADDR_SCOPE_NODELOCAL	0x01
283 #define IPV6_ADDR_SCOPE_LINKLOCAL	0x02
284 #define IPV6_ADDR_SCOPE_SITELOCAL	0x05
285 #define IPV6_ADDR_SCOPE_ORGLOCAL	0x08	/* just used in this file */
286 #define IPV6_ADDR_SCOPE_GLOBAL		0x0e
287 #else
288 #define __IPV6_ADDR_SCOPE_NODELOCAL	0x01
289 #define __IPV6_ADDR_SCOPE_LINKLOCAL	0x02
290 #define __IPV6_ADDR_SCOPE_SITELOCAL	0x05
291 #define __IPV6_ADDR_SCOPE_ORGLOCAL	0x08	/* just used in this file */
292 #define __IPV6_ADDR_SCOPE_GLOBAL	0x0e
293 #endif
294 
295 /*
296  * Unicast Scope
297  * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).
298  */
299 #define IN6_IS_ADDR_LINKLOCAL(a)	\
300 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
301 #define IN6_IS_ADDR_SITELOCAL(a)	\
302 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
303 
304 /*
305  * Multicast
306  */
307 #define IN6_IS_ADDR_MULTICAST(a)	((a)->s6_addr[0] == 0xff)
308 
309 #ifdef _KERNEL	/* XXX nonstandard */
310 #define IPV6_ADDR_MC_SCOPE(a)		((a)->s6_addr[1] & 0x0f)
311 #else
312 #define __IPV6_ADDR_MC_SCOPE(a)		((a)->s6_addr[1] & 0x0f)
313 #endif
314 
315 /*
316  * Multicast Scope
317  */
318 #ifdef _KERNEL	/* refers nonstandard items */
319 #define IN6_IS_ADDR_MC_NODELOCAL(a)	\
320 	(IN6_IS_ADDR_MULTICAST(a) &&	\
321 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL))
322 #define IN6_IS_ADDR_MC_LINKLOCAL(a)	\
323 	(IN6_IS_ADDR_MULTICAST(a) &&	\
324 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL))
325 #define IN6_IS_ADDR_MC_SITELOCAL(a)	\
326 	(IN6_IS_ADDR_MULTICAST(a) && 	\
327 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL))
328 #define IN6_IS_ADDR_MC_ORGLOCAL(a)	\
329 	(IN6_IS_ADDR_MULTICAST(a) &&	\
330 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL))
331 #define IN6_IS_ADDR_MC_GLOBAL(a)	\
332 	(IN6_IS_ADDR_MULTICAST(a) &&	\
333 	 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL))
334 #else
335 #define IN6_IS_ADDR_MC_NODELOCAL(a)	\
336 	(IN6_IS_ADDR_MULTICAST(a) &&	\
337 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL))
338 #define IN6_IS_ADDR_MC_LINKLOCAL(a)	\
339 	(IN6_IS_ADDR_MULTICAST(a) &&	\
340 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL))
341 #define IN6_IS_ADDR_MC_SITELOCAL(a)	\
342 	(IN6_IS_ADDR_MULTICAST(a) && 	\
343 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
344 #define IN6_IS_ADDR_MC_ORGLOCAL(a)	\
345 	(IN6_IS_ADDR_MULTICAST(a) &&	\
346 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
347 #define IN6_IS_ADDR_MC_GLOBAL(a)	\
348 	(IN6_IS_ADDR_MULTICAST(a) &&	\
349 	 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL))
350 #endif
351 
352 #ifdef _KERNEL	/* nonstandard */
353 /*
354  * KAME Scope
355  */
356 #define IN6_IS_SCOPE_LINKLOCAL(a)	\
357 	((IN6_IS_ADDR_LINKLOCAL(a)) ||	\
358 	 (IN6_IS_ADDR_MC_LINKLOCAL(a)))
359 #endif
360 
361 /*
362  * IP6 route structure
363  */
364 #ifndef _XOPEN_SOURCE
365 struct route_in6 {
366 	struct	rtentry *ro_rt;
367 	struct	sockaddr_in6 ro_dst;
368 };
369 #endif
370 
371 /*
372  * Options for use with [gs]etsockopt at the IPV6 level.
373  * First word of comment is data type; bool is stored in int.
374  */
375 #define IPV6_OPTIONS		1  /* buf/ip6_opts; set/get IP6 options */
376 /* no hdrincl */
377 #define IPV6_SOCKOPT_RESERVED1	3  /* reserved for future use */
378 #define IPV6_UNICAST_HOPS	4  /* int; IP6 hops */
379 #define IPV6_RECVOPTS		5  /* bool; receive all IP6 opts w/dgram */
380 #define IPV6_RECVRETOPTS	6  /* bool; receive IP6 opts for response */
381 #define IPV6_RECVDSTADDR	7  /* bool; receive IP6 dst addr w/dgram */
382 #define IPV6_RETOPTS		8  /* ip6_opts; set/get IP6 options */
383 #define IPV6_MULTICAST_IF	9  /* u_int; set/get IP6 multicast i/f  */
384 #define IPV6_MULTICAST_HOPS	10 /* int; set/get IP6 multicast hops */
385 #define IPV6_MULTICAST_LOOP	11 /* u_int; set/get IP6 multicast loopback */
386 #define IPV6_JOIN_GROUP		12 /* ip6_mreq; join a group membership */
387 #define IPV6_LEAVE_GROUP	13 /* ip6_mreq; leave a group membership */
388 #define IPV6_PORTRANGE		14 /* int; range to choose for unspec port */
389 #define ICMP6_FILTER		18 /* icmp6_filter; icmp6 filter */
390 #define IPV6_PKTINFO		19 /* bool; send/rcv if, src/dst addr */
391 #define IPV6_HOPLIMIT		20 /* bool; hop limit */
392 #define IPV6_NEXTHOP		21 /* bool; next hop addr */
393 #define IPV6_HOPOPTS		22 /* bool; hop-by-hop option */
394 #define IPV6_DSTOPTS		23 /* bool; destination option */
395 #define IPV6_RTHDR		24 /* bool; routing header */
396 #define IPV6_PKTOPTIONS		25 /* buf/cmsghdr; set/get IPv6 options */
397 #define IPV6_CHECKSUM		26 /* int; checksum offset for raw socket */
398 #define IPV6_V6ONLY		27 /* bool; make AF_INET6 sockets v6 only */
399 
400 #if 1 /* IPSEC */
401 #define IPV6_IPSEC_POLICY	28 /* struct; get/set security policy */
402 #endif
403 #define IPV6_FAITH		29 /* bool; accept FAITH'ed connections */
404 /* to define items, should talk with KAME guys first, for *BSD compatibility */
405 
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 /*
411  * Defaults and limits for options
412  */
413 #define IPV6_DEFAULT_MULTICAST_HOPS 1	/* normally limit m'casts to 1 hop  */
414 #define IPV6_DEFAULT_MULTICAST_LOOP 1	/* normally hear sends if a member  */
415 
416 /*
417  * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.
418  */
419 struct ipv6_mreq {
420 	struct in6_addr	ipv6mr_multiaddr;
421 	unsigned int	ipv6mr_interface;
422 };
423 
424 /*
425  * IPV6_PKTINFO: Packet information(RFC2292 sec 5)
426  */
427 struct in6_pktinfo {
428 	struct in6_addr	ipi6_addr;	/* src/dst IPv6 address */
429 	unsigned int	ipi6_ifindex;	/* send/recv interface index */
430 };
431 
432 /*
433  * Argument for IPV6_PORTRANGE:
434  * - which range to search when port is unspecified at bind() or connect()
435  */
436 #define	IPV6_PORTRANGE_DEFAULT	0	/* default range */
437 #define	IPV6_PORTRANGE_HIGH	1	/* "high" - request firewall bypass */
438 #define	IPV6_PORTRANGE_LOW	2	/* "low" - vouchsafe security */
439 
440 #ifndef _XOPEN_SOURCE
441 /*
442  * Definitions for inet6 sysctl operations.
443  *
444  * Third level is protocol number.
445  * Fourth level is desired variable within that protocol.
446  */
447 #define IPV6PROTO_MAXID	(IPPROTO_PIM + 1)	/* don't list to IPV6PROTO_MAX */
448 
449 #define CTL_IPV6PROTO_NAMES { \
450 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
451 	{ 0, 0 }, \
452 	{ "tcp6", CTLTYPE_NODE }, \
453 	{ 0, 0 }, \
454 	{ 0, 0 }, \
455 	{ 0, 0 }, \
456 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
457 	{ 0, 0 }, \
458 	{ 0, 0 }, \
459 	{ "udp6", CTLTYPE_NODE }, \
460 	{ 0, 0 }, \
461 	{ 0, 0 }, \
462 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 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 }, \
467 	{ "ip6", CTLTYPE_NODE }, \
468 	{ 0, 0 }, \
469 	{ 0, 0 }, \
470 	{ 0, 0 }, \
471 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
472 	{ 0, 0 }, \
473 	{ "ipsec6", CTLTYPE_NODE }, \
474 	{ 0, 0 }, \
475 	{ 0, 0 }, \
476 	{ 0, 0 }, \
477 	{ 0, 0 }, \
478 	{ 0, 0 }, \
479 	{ 0, 0 }, \
480 	{ "icmp6", CTLTYPE_NODE }, \
481 	{ 0, 0 }, \
482 	{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 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 }, \
491 	{ 0, 0 }, \
492 	{ 0, 0 }, \
493 	{ "pim6", CTLTYPE_NODE }, \
494 }
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 /* New entries should be added here from current IPV6CTL_MAXID value. */
531 /* to define items, should talk with KAME guys first, for *BSD compatibility */
532 #define IPV6CTL_MAXID		32
533 
534 #define IPV6CTL_NAMES { \
535 	{ 0, 0 }, \
536 	{ "forwarding", CTLTYPE_INT }, \
537 	{ "redirect", CTLTYPE_INT }, \
538 	{ "hlim", CTLTYPE_INT }, \
539 	{ "mtu", CTLTYPE_INT }, \
540 	{ "forwsrcrt", CTLTYPE_INT }, \
541 	{ 0, 0 }, \
542 	{ 0, 0 }, \
543 	{ "mrtproto", CTLTYPE_INT }, \
544 	{ "maxfragpackets", CTLTYPE_INT }, \
545 	{ "sourcecheck", CTLTYPE_INT }, \
546 	{ "sourcecheck_logint", CTLTYPE_INT }, \
547 	{ "accept_rtadv", CTLTYPE_INT }, \
548 	{ "keepfaith", CTLTYPE_INT }, \
549 	{ "log_interval", CTLTYPE_INT }, \
550 	{ "hdrnestlimit", CTLTYPE_INT }, \
551 	{ "dad_count", CTLTYPE_INT }, \
552 	{ "auto_flowlabel", CTLTYPE_INT }, \
553 	{ "defmcasthlim", CTLTYPE_INT }, \
554 	{ "gifhlim", CTLTYPE_INT }, \
555 	{ "kame_version", CTLTYPE_STRING }, \
556 	{ "use_deprecated", CTLTYPE_INT }, \
557 	{ "rr_prune", CTLTYPE_INT }, \
558 	{ 0, 0 }, \
559 	{ "bindv6only", CTLTYPE_INT }, \
560 	{ 0, 0 }, \
561 	{ 0, 0 }, \
562 	{ 0, 0 }, \
563 	{ "anonportmin", CTLTYPE_INT }, \
564 	{ "anonportmax", CTLTYPE_INT }, \
565 	{ "lowportmin", CTLTYPE_INT }, \
566 	{ "lowportmax", CTLTYPE_INT }, \
567 }
568 
569 #endif /* !_XOPEN_SOURCE */
570 
571 #ifdef _KERNEL
572 struct cmsghdr;
573 
574 /*
575  * in6_cksum_phdr:
576  *
577  *	Compute significant parts of the IPv6 checksum pseudo-header
578  *	for use in a delayed TCP/UDP checksum calculation.
579  *
580  *	Args:
581  *
582  *		src		Source IPv6 address
583  *		dst		Destination IPv6 address
584  *		len		htonl(proto-hdr-len)
585  *		nxt		htonl(next-proto-number)
586  *
587  *	NOTE: We expect the src and dst addresses to be 16-bit
588  *	aligned!
589  */
590 static __inline u_int16_t __attribute__((__unused__))
591 in6_cksum_phdr(const struct in6_addr *src, const struct in6_addr *dst,
592     u_int32_t len, u_int32_t nxt)
593 {
594 	u_int32_t sum = 0;
595 	const u_int16_t *w;
596 
597 	/*LINTED*/
598 	w = (const u_int16_t *) src;
599 	sum += w[0];
600 	if (!IN6_IS_SCOPE_LINKLOCAL(src))
601 		sum += w[1];
602 	sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
603 	sum += w[6]; sum += w[7];
604 
605 	/*LINTED*/
606 	w = (const u_int16_t *) dst;
607 	sum += w[0];
608 	if (!IN6_IS_SCOPE_LINKLOCAL(dst))
609 		sum += w[1];
610 	sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
611 	sum += w[6]; sum += w[7];
612 
613 	sum += (u_int16_t)(len >> 16) + (u_int16_t)(len /*& 0xffff*/);
614 
615 	sum += (u_int16_t)(nxt >> 16) + (u_int16_t)(nxt /*& 0xffff*/);
616 
617 	sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/);
618 
619 	if (sum > 0xffff)
620 		sum -= 0xffff;
621 
622 	return (sum);
623 }
624 
625 int	in6_cksum __P((struct mbuf *, u_int8_t, u_int32_t, u_int32_t));
626 int	in6_localaddr __P((struct in6_addr *));
627 int	in6_addrscope __P((struct in6_addr *));
628 struct	in6_ifaddr *in6_ifawithscope __P((struct ifnet *, struct in6_addr *));
629 struct	in6_ifaddr *in6_ifawithifp __P((struct ifnet *, struct in6_addr *));
630 extern void in6_if_up __P((struct ifnet *));
631 extern	u_char	ip6_protox[];
632 
633 #define	satosin6(sa)	((struct sockaddr_in6 *)(sa))
634 #define	sin6tosa(sin6)	((struct sockaddr *)(sin6))
635 #define	ifatoia6(ifa)	((struct in6_ifaddr *)(ifa))
636 #endif /* _KERNEL */
637 
638 __BEGIN_DECLS
639 struct cmsghdr;
640 
641 extern int inet6_option_space __P((int));
642 extern int inet6_option_init __P((void *, struct cmsghdr **, int));
643 extern int inet6_option_append __P((struct cmsghdr *, const u_int8_t *,
644 	int, int));
645 extern u_int8_t *inet6_option_alloc __P((struct cmsghdr *, int, int, int));
646 extern int inet6_option_next __P((const struct cmsghdr *, u_int8_t **));
647 extern int inet6_option_find __P((const struct cmsghdr *, u_int8_t **, int));
648 
649 extern size_t inet6_rthdr_space __P((int, int));
650 extern struct cmsghdr *inet6_rthdr_init __P((void *, int));
651 extern int inet6_rthdr_add __P((struct cmsghdr *, const struct in6_addr *,
652 		unsigned int));
653 extern int inet6_rthdr_lasthop __P((struct cmsghdr *, unsigned int));
654 #if 0 /* not implemented yet */
655 extern int inet6_rthdr_reverse __P((const struct cmsghdr *, struct cmsghdr *));
656 #endif
657 extern int inet6_rthdr_segments __P((const struct cmsghdr *));
658 extern struct in6_addr *inet6_rthdr_getaddr __P((struct cmsghdr *, int));
659 extern int inet6_rthdr_getflags __P((const struct cmsghdr *, int));
660 __END_DECLS
661 
662 #endif /* !_NETINET6_IN6_H_ */
663