vm: reduce noise in merged pagetable.c
[minix.git] / include / netinet6 / in6.h
bloba2fbf896d18417f2d6efda296f026c6458502102
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 $ */
4 /*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved.
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.
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.
34 * Copyright (c) 1982, 1986, 1990, 1993
35 * The Regents of the University of California. All rights reserved.
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.
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.
61 * @(#)in.h 8.3 (Berkeley) 1/3/94
64 #ifndef _NETINET6_IN6_H_
65 #define _NETINET6_IN6_H_
67 #ifndef __KAME_NETINET_IN_H_INCLUDED_
68 #error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553"
69 #endif
71 #include <sys/socket.h>
74 * Identification of the network protocol stack
75 * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE
76 * has the table of implementation/integration differences.
78 #define __KAME__
79 #define __KAME_VERSION "NetBSD-current"
82 * Local port number conventions:
84 * Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root),
85 * unless a kernel is compiled with IPNOPRIVPORTS defined.
87 * When a user does a bind(2) or connect(2) with a port number of zero,
88 * a non-conflicting local port address is chosen.
90 * The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although
91 * that is settable by sysctl(3); net.inet.ip.anonportmin and
92 * net.inet.ip.anonportmax respectively.
94 * A user may set the IPPROTO_IP option IP_PORTRANGE to change this
95 * default assignment range.
97 * The value IP_PORTRANGE_DEFAULT causes the default behavior.
99 * The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT,
100 * and exists only for FreeBSD compatibility purposes.
102 * The value IP_PORTRANGE_LOW changes the range to the "low" are
103 * that is (by convention) restricted to privileged processes.
104 * This convention is based on "vouchsafe" principles only.
105 * It is only secure if you trust the remote host to restrict these ports.
106 * The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX.
109 #if defined(_NETBSD_SOURCE)
110 #define IPV6PORT_RESERVED 1024
111 #define IPV6PORT_ANONMIN 49152
112 #define IPV6PORT_ANONMAX 65535
113 #define IPV6PORT_RESERVEDMIN 600
114 #define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1)
115 #endif
118 * IPv6 address
120 struct in6_addr {
121 union {
122 __uint8_t __u6_addr8[16];
123 __uint16_t __u6_addr16[8];
124 uint32_t __u6_addr32[4];
125 } __u6_addr; /* 128-bit IP6 address */
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
135 #define INET6_ADDRSTRLEN 46
138 * Socket address for IPv6
140 #if defined(_NETBSD_SOURCE)
141 #define SIN6_LEN
142 #endif
143 struct sockaddr_in6 {
144 #ifndef __minix
145 uint8_t sin6_len; /* length of this struct(socklen_t)*/
146 #endif /* !__minix */
147 sa_family_t sin6_family; /* AF_INET6 (sa_family_t) */
148 in_port_t sin6_port; /* Transport layer port */
149 uint32_t sin6_flowinfo; /* IP6 flow information */
150 struct in6_addr sin6_addr; /* IP6 address */
151 uint32_t sin6_scope_id; /* scope zone index */
154 #ifndef __minix
156 * Local definition for masks
158 #ifdef _KERNEL /* XXX nonstandard */
159 #define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}
160 #define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \
161 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
162 #define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
163 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
164 #define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
165 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}
166 #define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
167 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}
168 #endif
170 #ifdef _KERNEL
171 extern const struct sockaddr_in6 sa6_any;
173 extern const struct in6_addr in6mask0;
174 extern const struct in6_addr in6mask32;
175 extern const struct in6_addr in6mask64;
176 extern const struct in6_addr in6mask96;
177 extern const struct in6_addr in6mask128;
178 #endif /* _KERNEL */
181 * Macros started with IPV6_ADDR is KAME local
183 #ifdef _KERNEL /* XXX nonstandard */
184 #if BYTE_ORDER == BIG_ENDIAN
185 #define IPV6_ADDR_INT32_ONE 1
186 #define IPV6_ADDR_INT32_TWO 2
187 #define IPV6_ADDR_INT32_MNL 0xff010000
188 #define IPV6_ADDR_INT32_MLL 0xff020000
189 #define IPV6_ADDR_INT32_SMP 0x0000ffff
190 #define IPV6_ADDR_INT16_ULL 0xfe80
191 #define IPV6_ADDR_INT16_USL 0xfec0
192 #define IPV6_ADDR_INT16_MLL 0xff02
193 #elif BYTE_ORDER == LITTLE_ENDIAN
194 #define IPV6_ADDR_INT32_ONE 0x01000000
195 #define IPV6_ADDR_INT32_TWO 0x02000000
196 #define IPV6_ADDR_INT32_MNL 0x000001ff
197 #define IPV6_ADDR_INT32_MLL 0x000002ff
198 #define IPV6_ADDR_INT32_SMP 0xffff0000
199 #define IPV6_ADDR_INT16_ULL 0x80fe
200 #define IPV6_ADDR_INT16_USL 0xc0fe
201 #define IPV6_ADDR_INT16_MLL 0x02ff
202 #endif
203 #endif
204 #endif /* !__minix */
207 * Definition of some useful macros to handle IP6 addresses
209 #define IN6ADDR_ANY_INIT \
210 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
211 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
212 #define IN6ADDR_LOOPBACK_INIT \
213 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
215 #define IN6ADDR_NODELOCAL_ALLNODES_INIT \
216 {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
217 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
218 #define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
219 {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
221 #define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
222 {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
225 extern const struct in6_addr in6addr_any;
226 extern const struct in6_addr in6addr_loopback;
227 extern const struct in6_addr in6addr_nodelocal_allnodes;
228 extern const struct in6_addr in6addr_linklocal_allnodes;
229 extern const struct in6_addr in6addr_linklocal_allrouters;
231 #define IN6_ARE_ADDR_EQUAL(a, b) \
232 (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
235 * Unspecified
237 #define IN6_IS_ADDR_UNSPECIFIED(a) \
238 ((a)->__u6_addr.__u6_addr32[0] == 0 && \
239 (a)->__u6_addr.__u6_addr32[1] == 0 && \
240 (a)->__u6_addr.__u6_addr32[2] == 0 && \
241 (a)->__u6_addr.__u6_addr32[3] == 0)
244 * Loopback
246 #define IN6_IS_ADDR_LOOPBACK(a) \
247 ((a)->__u6_addr.__u6_addr32[0] == 0 && \
248 (a)->__u6_addr.__u6_addr32[1] == 0 && \
249 (a)->__u6_addr.__u6_addr32[2] == 0 && \
250 (a)->__u6_addr.__u6_addr32[3] == ntohl(1))
253 * IPv4 compatible
255 #define IN6_IS_ADDR_V4COMPAT(a) \
256 ((a)->__u6_addr.__u6_addr32[0] == 0 && \
257 (a)->__u6_addr.__u6_addr32[1] == 0 && \
258 (a)->__u6_addr.__u6_addr32[2] == 0 && \
259 (a)->__u6_addr.__u6_addr32[3] != 0 && \
260 (a)->__u6_addr.__u6_addr32[3] != ntohl(1))
263 * Mapped
265 #define IN6_IS_ADDR_V4MAPPED(a) \
266 ((a)->__u6_addr.__u6_addr32[0] == 0 && \
267 (a)->__u6_addr.__u6_addr32[1] == 0 && \
268 (a)->__u6_addr.__u6_addr32[2] == ntohl(0x0000ffff))
271 * KAME Scope Values
274 #ifdef _KERNEL /* XXX nonstandard */
275 #define IPV6_ADDR_SCOPE_NODELOCAL 0x01
276 #define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01
277 #define IPV6_ADDR_SCOPE_LINKLOCAL 0x02
278 #define IPV6_ADDR_SCOPE_SITELOCAL 0x05
279 #define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */
280 #define IPV6_ADDR_SCOPE_GLOBAL 0x0e
281 #else
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 #endif
290 * Unicast Scope
291 * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).
293 #define IN6_IS_ADDR_LINKLOCAL(a) \
294 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
295 #define IN6_IS_ADDR_SITELOCAL(a) \
296 (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
299 * Multicast
301 #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
303 #ifdef _KERNEL /* XXX nonstandard */
304 #define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
305 #else
306 #define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
307 #endif
310 * Multicast Scope
312 #ifdef _KERNEL /* refers nonstandard items */
313 #define IN6_IS_ADDR_MC_NODELOCAL(a) \
314 (IN6_IS_ADDR_MULTICAST(a) && \
315 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL))
316 #define IN6_IS_ADDR_MC_INTFACELOCAL(a) \
317 (IN6_IS_ADDR_MULTICAST(a) && \
318 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL))
319 #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
320 (IN6_IS_ADDR_MULTICAST(a) && \
321 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL))
322 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
323 (IN6_IS_ADDR_MULTICAST(a) && \
324 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL))
325 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
326 (IN6_IS_ADDR_MULTICAST(a) && \
327 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL))
328 #define IN6_IS_ADDR_MC_GLOBAL(a) \
329 (IN6_IS_ADDR_MULTICAST(a) && \
330 (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL))
331 #else
332 #define IN6_IS_ADDR_MC_NODELOCAL(a) \
333 (IN6_IS_ADDR_MULTICAST(a) && \
334 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL))
335 #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
336 (IN6_IS_ADDR_MULTICAST(a) && \
337 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL))
338 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
339 (IN6_IS_ADDR_MULTICAST(a) && \
340 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
341 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
342 (IN6_IS_ADDR_MULTICAST(a) && \
343 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
344 #define IN6_IS_ADDR_MC_GLOBAL(a) \
345 (IN6_IS_ADDR_MULTICAST(a) && \
346 (__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL))
347 #endif
349 #ifdef _KERNEL /* nonstandard */
351 * KAME Scope
353 #define IN6_IS_SCOPE_LINKLOCAL(a) \
354 ((IN6_IS_ADDR_LINKLOCAL(a)) || \
355 (IN6_IS_ADDR_MC_LINKLOCAL(a)))
357 #define IN6_IS_SCOPE_EMBEDDABLE(__a) \
358 (IN6_IS_SCOPE_LINKLOCAL(__a) || IN6_IS_ADDR_MC_INTFACELOCAL(__a))
360 #define IFA6_IS_DEPRECATED(a) \
361 ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
362 (u_int32_t)((time_second - (a)->ia6_updatetime)) > \
363 (a)->ia6_lifetime.ia6t_pltime)
364 #define IFA6_IS_INVALID(a) \
365 ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \
366 (u_int32_t)((time_second - (a)->ia6_updatetime)) > \
367 (a)->ia6_lifetime.ia6t_vltime)
368 #endif
370 #ifndef __minix
372 * Options for use with [gs]etsockopt at the IPV6 level.
373 * First word of comment is data type; bool is stored in int.
375 /* no hdrincl */
376 #if 0
377 /* These are deprecated non-standard options which are no longer supported. */
378 #define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */
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 #endif
384 #define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */
385 #define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */
386 #define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */
387 #define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */
388 #define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */
389 #define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */
390 #define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */
391 #define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */
392 #if defined(_NETBSD_SOURCE)
393 #define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */
394 #endif
395 /* RFC2292 options */
396 #ifdef _KERNEL
397 #define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */
398 #define IPV6_2292HOPLIMIT 20 /* bool; hop limit */
399 #define IPV6_2292NEXTHOP 21 /* bool; next hop addr */
400 #define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */
401 #define IPV6_2292DSTOPTS 23 /* bool; destination option */
402 #define IPV6_2292RTHDR 24 /* bool; routing header */
403 #define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */
404 #endif
405 #define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */
406 #define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */
408 #if 1 /* IPSEC */
409 #define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */
410 #endif
411 #define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */
413 /* new socket options introduced in RFC3542 */
414 #define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */
416 #define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */
417 #define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */
418 #define IPV6_RECVRTHDR 38 /* bool; recv routing header */
419 #define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */
420 #define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */
421 #ifdef _KERNEL
422 #define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */
423 #endif
424 #define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */
425 #define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */
426 #define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt),
427 4 bytes int; MTU notification (cmsg) */
429 /* more new socket options introduced in RFC3542 */
430 #define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */
431 #define IPV6_HOPLIMIT 47 /* int; send hop limit */
432 #define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */
433 #define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */
434 #define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */
435 #define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */
437 #define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */
438 #ifdef _KERNEL
439 #define IPV6_OTCLASS 58 /* u_int8_t; send traffic class value */
440 #endif
442 #define IPV6_TCLASS 61 /* int; send traffic class value */
443 #define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */
444 /* to define items, should talk with KAME guys first, for *BSD compatibility */
446 #define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */
447 #define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */
448 #define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */
451 * Defaults and limits for options
453 #define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */
454 #define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
457 * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.
459 struct ipv6_mreq {
460 struct in6_addr ipv6mr_multiaddr;
461 unsigned int ipv6mr_interface;
465 * IPV6_PKTINFO: Packet information(RFC2292 sec 5)
467 struct in6_pktinfo {
468 struct in6_addr ipi6_addr; /* src/dst IPv6 address */
469 unsigned int ipi6_ifindex; /* send/recv interface index */
473 * Control structure for IPV6_RECVPATHMTU socket option.
475 struct ip6_mtuinfo {
476 struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */
477 uint32_t ip6m_mtu;
481 * Argument for IPV6_PORTRANGE:
482 * - which range to search when port is unspecified at bind() or connect()
484 #define IPV6_PORTRANGE_DEFAULT 0 /* default range */
485 #define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */
486 #define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */
488 #if defined(_NETBSD_SOURCE)
490 * Definitions for inet6 sysctl operations.
492 * Third level is protocol number.
493 * Fourth level is desired variable within that protocol.
495 #define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */
497 #define CTL_IPV6PROTO_NAMES { \
498 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
499 { 0, 0 }, \
500 { "tcp6", CTLTYPE_NODE }, \
501 { 0, 0 }, \
502 { 0, 0 }, \
503 { 0, 0 }, \
504 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
505 { 0, 0 }, \
506 { 0, 0 }, \
507 { "udp6", CTLTYPE_NODE }, \
508 { 0, 0 }, \
509 { 0, 0 }, \
510 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 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 }, \
515 { "ip6", CTLTYPE_NODE }, \
516 { 0, 0 }, \
517 { 0, 0 }, \
518 { 0, 0 }, \
519 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
520 { 0, 0 }, \
521 { "ipsec6", CTLTYPE_NODE }, \
522 { 0, 0 }, \
523 { 0, 0 }, \
524 { 0, 0 }, \
525 { 0, 0 }, \
526 { 0, 0 }, \
527 { 0, 0 }, \
528 { "icmp6", CTLTYPE_NODE }, \
529 { 0, 0 }, \
530 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
531 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
532 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
533 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
534 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
535 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
536 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
537 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
538 { 0, 0 }, \
539 { 0, 0 }, \
540 { 0, 0 }, \
541 { "pim6", CTLTYPE_NODE }, \
545 * Names for IP sysctl objects
547 #define IPV6CTL_FORWARDING 1 /* act as router */
548 #define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/
549 #define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */
550 #ifdef notyet
551 #define IPV6CTL_DEFMTU 4 /* default MTU */
552 #endif
553 #define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */
554 #define IPV6CTL_STATS 6 /* stats */
555 #define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */
556 #define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */
557 #define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */
558 #define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */
559 #define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */
560 #define IPV6CTL_ACCEPT_RTADV 12
561 #define IPV6CTL_KEEPFAITH 13
562 #define IPV6CTL_LOG_INTERVAL 14
563 #define IPV6CTL_HDRNESTLIMIT 15
564 #define IPV6CTL_DAD_COUNT 16
565 #define IPV6CTL_AUTO_FLOWLABEL 17
566 #define IPV6CTL_DEFMCASTHLIM 18
567 #define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */
568 #define IPV6CTL_KAME_VERSION 20
569 #define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */
570 #define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */
571 /* 23: reserved */
572 #define IPV6CTL_V6ONLY 24
573 /* 25 to 27: reserved */
574 #define IPV6CTL_ANONPORTMIN 28 /* minimum ephemeral port */
575 #define IPV6CTL_ANONPORTMAX 29 /* maximum ephemeral port */
576 #define IPV6CTL_LOWPORTMIN 30 /* minimum reserved port */
577 #define IPV6CTL_LOWPORTMAX 31 /* maximum reserved port */
578 /* 32 to 38: reserved */
579 #define IPV6CTL_USE_DEFAULTZONE 39 /* use default scope zone */
580 /* 40: reserved */
581 #define IPV6CTL_MAXFRAGS 41 /* max fragments */
582 #define IPV6CTL_IFQ 42 /* ip6intrq node */
583 /* New entries should be added here from current IPV6CTL_MAXID value. */
584 /* to define items, should talk with KAME guys first, for *BSD compatibility */
585 #define IPV6CTL_MAXID 43
587 #define IPV6CTL_NAMES { \
588 { 0, 0 }, \
589 { "forwarding", CTLTYPE_INT }, \
590 { "redirect", CTLTYPE_INT }, \
591 { "hlim", CTLTYPE_INT }, \
592 { "mtu", CTLTYPE_INT }, \
593 { "forwsrcrt", CTLTYPE_INT }, \
594 { "stats", CTLTYPE_STRUCT }, \
595 { 0, 0 }, \
596 { "mrtproto", CTLTYPE_INT }, \
597 { "maxfragpackets", CTLTYPE_INT }, \
598 { "sourcecheck", CTLTYPE_INT }, \
599 { "sourcecheck_logint", CTLTYPE_INT }, \
600 { "accept_rtadv", CTLTYPE_INT }, \
601 { "keepfaith", CTLTYPE_INT }, \
602 { "log_interval", CTLTYPE_INT }, \
603 { "hdrnestlimit", CTLTYPE_INT }, \
604 { "dad_count", CTLTYPE_INT }, \
605 { "auto_flowlabel", CTLTYPE_INT }, \
606 { "defmcasthlim", CTLTYPE_INT }, \
607 { "gifhlim", CTLTYPE_INT }, \
608 { "kame_version", CTLTYPE_STRING }, \
609 { "use_deprecated", CTLTYPE_INT }, \
610 { "rr_prune", CTLTYPE_INT }, \
611 { 0, 0 }, \
612 { "v6only", CTLTYPE_INT }, \
613 { 0, 0 }, \
614 { 0, 0 }, \
615 { 0, 0 }, \
616 { "anonportmin", CTLTYPE_INT }, \
617 { "anonportmax", CTLTYPE_INT }, \
618 { "lowportmin", CTLTYPE_INT }, \
619 { "lowportmax", CTLTYPE_INT }, \
620 { 0, 0 }, \
621 { 0, 0 }, \
622 { 0, 0 }, \
623 { 0, 0 }, \
624 { 0, 0 }, \
625 { 0, 0 }, \
626 { 0, 0 }, \
627 { 0, 0 }, \
628 { 0, 0 }, \
629 { "maxfrags", CTLTYPE_INT }, \
630 { "ifq", CTLTYPE_NODE }, \
633 #endif /* _NETBSD_SOURCE */
635 #ifdef _KERNEL
636 struct cmsghdr;
639 * in6_cksum_phdr:
641 * Compute significant parts of the IPv6 checksum pseudo-header
642 * for use in a delayed TCP/UDP checksum calculation.
644 * Args:
646 * src Source IPv6 address
647 * dst Destination IPv6 address
648 * len htonl(proto-hdr-len)
649 * nxt htonl(next-proto-number)
651 * NOTE: We expect the src and dst addresses to be 16-bit
652 * aligned!
654 static __inline u_int16_t __unused
655 in6_cksum_phdr(const struct in6_addr *src, const struct in6_addr *dst,
656 u_int32_t len, u_int32_t nxt)
658 u_int32_t sum = 0;
659 const u_int16_t *w;
661 /*LINTED*/
662 w = (const u_int16_t *) src;
663 sum += w[0];
664 if (!IN6_IS_SCOPE_LINKLOCAL(src))
665 sum += w[1];
666 sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
667 sum += w[6]; sum += w[7];
669 /*LINTED*/
670 w = (const u_int16_t *) dst;
671 sum += w[0];
672 if (!IN6_IS_SCOPE_LINKLOCAL(dst))
673 sum += w[1];
674 sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
675 sum += w[6]; sum += w[7];
677 sum += (u_int16_t)(len >> 16) + (u_int16_t)(len /*& 0xffff*/);
679 sum += (u_int16_t)(nxt >> 16) + (u_int16_t)(nxt /*& 0xffff*/);
681 sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/);
683 if (sum > 0xffff)
684 sum -= 0xffff;
686 return (sum);
689 struct mbuf;
690 struct ifnet;
691 int sockaddr_in6_cmp(const struct sockaddr *, const struct sockaddr *);
692 struct sockaddr *sockaddr_in6_externalize(struct sockaddr *, socklen_t,
693 const struct sockaddr *);
694 int in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t);
695 void in6_delayed_cksum(struct mbuf *);
696 int in6_localaddr(const struct in6_addr *);
697 int in6_addrscope(const struct in6_addr *);
698 struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *);
699 extern void in6_if_up(struct ifnet *);
700 #ifndef __FreeBSD__
701 extern int in6_src_sysctl(void *, size_t *, void *, size_t);
702 #endif
703 extern void addrsel_policy_init(void);
704 extern u_char ip6_protox[];
706 #define satosin6(sa) ((struct sockaddr_in6 *)(sa))
707 #define satocsin6(sa) ((const struct sockaddr_in6 *)(sa))
708 #define sin6tosa(sin6) ((struct sockaddr *)(sin6))
709 #define sin6tocsa(sin6) ((const struct sockaddr *)(sin6))
710 #define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa))
712 static inline void
713 sockaddr_in6_init1(struct sockaddr_in6 *sin6, const struct in6_addr *addr,
714 in_port_t port, uint32_t flowinfo, uint32_t scope_id)
716 sin6->sin6_port = port;
717 sin6->sin6_flowinfo = flowinfo;
718 sin6->sin6_addr = *addr;
719 sin6->sin6_scope_id = scope_id;
722 static inline void
723 sockaddr_in6_init(struct sockaddr_in6 *sin6, const struct in6_addr *addr,
724 in_port_t port, uint32_t flowinfo, uint32_t scope_id)
726 sin6->sin6_family = AF_INET6;
727 sin6->sin6_len = sizeof(*sin6);
728 sockaddr_in6_init1(sin6, addr, port, flowinfo, scope_id);
731 static inline struct sockaddr *
732 sockaddr_in6_alloc(const struct in6_addr *addr, in_port_t port,
733 uint32_t flowinfo, uint32_t scope_id, int flags)
735 struct sockaddr *sa;
737 if ((sa = sockaddr_alloc(AF_INET6, sizeof(struct sockaddr_in6),
738 flags)) == NULL)
739 return NULL;
741 sockaddr_in6_init1(satosin6(sa), addr, port, flowinfo, scope_id);
743 return sa;
745 #endif /* _KERNEL */
747 #if defined(_NETBSD_SOURCE)
749 #include <machine/ansi.h>
751 #ifdef _BSD_SIZE_T_
752 typedef _BSD_SIZE_T_ size_t;
753 #define _SIZE_T
754 #undef _BSD_SIZE_T_
755 #endif
757 #include <sys/cdefs.h>
759 __BEGIN_DECLS
760 struct cmsghdr;
762 void in6_sin6_2_sin(struct sockaddr_in *, struct sockaddr_in6 *);
763 void in6_sin_2_v4mapsin6(struct sockaddr_in *, struct sockaddr_in6 *);
764 void in6_sin6_2_sin_in_sock(struct sockaddr *);
765 void in6_sin_2_v4mapsin6_in_sock(struct sockaddr **);
767 extern int inet6_option_space(int);
768 extern int inet6_option_init(void *, struct cmsghdr **, int);
769 extern int inet6_option_append(struct cmsghdr *, const uint8_t *,
770 int, int);
771 extern uint8_t *inet6_option_alloc(struct cmsghdr *, int, int, int);
772 extern int inet6_option_next(const struct cmsghdr *, uint8_t **);
773 extern int inet6_option_find(const struct cmsghdr *, uint8_t **, int);
775 extern size_t inet6_rthdr_space(int, int);
776 extern struct cmsghdr *inet6_rthdr_init(void *, int);
777 extern int inet6_rthdr_add(struct cmsghdr *, const struct in6_addr *,
778 unsigned int);
779 extern int inet6_rthdr_lasthop(struct cmsghdr *, unsigned int);
780 #if 0 /* not implemented yet */
781 extern int inet6_rthdr_reverse(const struct cmsghdr *, struct cmsghdr *);
782 #endif
783 extern int inet6_rthdr_segments(const struct cmsghdr *);
784 extern struct in6_addr *inet6_rthdr_getaddr(struct cmsghdr *, int);
785 extern int inet6_rthdr_getflags(const struct cmsghdr *, int);
787 extern int inet6_opt_init(void *, socklen_t);
788 extern int inet6_opt_append(void *, socklen_t, int, uint8_t,
789 socklen_t, uint8_t, void **);
790 extern int inet6_opt_finish(void *, socklen_t, int);
791 extern int inet6_opt_set_val(void *, int, void *, socklen_t);
793 extern int inet6_opt_next(void *, socklen_t, int, uint8_t *,
794 socklen_t *, void **);
795 extern int inet6_opt_find(void *, socklen_t, int, uint8_t,
796 socklen_t *, void **);
797 extern int inet6_opt_get_val(void *, int, void *, socklen_t);
798 extern socklen_t inet6_rth_space(int, int);
799 extern void *inet6_rth_init(void *, socklen_t, int, int);
800 extern int inet6_rth_add(void *, const struct in6_addr *);
801 extern int inet6_rth_reverse(const void *, void *);
802 extern int inet6_rth_segments(const void *);
803 extern struct in6_addr *inet6_rth_getaddr(const void *, int);
804 __END_DECLS
805 #endif /* _NETBSD_SOURCE */
806 #endif /* !__minix */
808 #endif /* !_NETINET6_IN6_H_ */