master
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
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 * $KAME: in6.h,v 1.89 2001/05/27 13:28:35 itojun Exp $
32 */
33
34/*-
35 * Copyright (c) 1982, 1986, 1990, 1993
36 * The Regents of the University of California. All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)in.h 8.3 (Berkeley) 1/3/94
63 */
64
65#ifndef __KAME_NETINET_IN_H_INCLUDED_
66#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553"
67#endif
68
69#ifndef _NETINET6_IN6_H_
70#define _NETINET6_IN6_H_
71
72/*
73 * Identification of the network protocol stack
74 * for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE
75 * has the table of implementation/integration differences.
76 */
77#define __KAME__
78#define __KAME_VERSION "FreeBSD"
79
80/*
81 * IPv6 port allocation rules should mirror the IPv4 rules and are controlled
82 * by the net.inet.ip.portrange sysctl tree. The following defines exist
83 * for compatibility with userland applications that need them.
84 */
85#if __BSD_VISIBLE
86#define IPV6PORT_RESERVED 1024
87#define IPV6PORT_ANONMIN 49152
88#define IPV6PORT_ANONMAX 65535
89#define IPV6PORT_RESERVEDMIN 600
90#define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1)
91#endif
92
93/*
94 * IPv6 address
95 */
96struct in6_addr {
97 union {
98 uint8_t __u6_addr8[16];
99 uint16_t __u6_addr16[8];
100 uint32_t __u6_addr32[4];
101 } __u6_addr; /* 128-bit IP6 address */
102};
103
104#define s6_addr __u6_addr.__u6_addr8
105#if __BSD_VISIBLE
106/*
107 * s6_addr is the only in6_addr element specified in RFCs 2553 and 3493,
108 * also in POSIX 1003.1-2017. The following three definitions were not
109 * exposed to user programs in FreeBSD before 14.1, or in other BSDs,
110 * and are thus less portable than s6_addr.
111 */
112#define s6_addr8 __u6_addr.__u6_addr8
113#define s6_addr16 __u6_addr.__u6_addr16
114#define s6_addr32 __u6_addr.__u6_addr32
115#endif
116
117#define INET6_ADDRSTRLEN 46
118
119/*
120 * XXX missing POSIX.1-2001 macro IPPROTO_IPV6.
121 */
122
123/*
124 * Socket address for IPv6
125 */
126#if __BSD_VISIBLE
127#define SIN6_LEN
128#endif
129
130struct sockaddr_in6 {
131 uint8_t sin6_len; /* length of this struct */
132 sa_family_t sin6_family; /* AF_INET6 */
133 in_port_t sin6_port; /* Transport layer port # */
134 uint32_t sin6_flowinfo; /* IP6 flow information */
135 struct in6_addr sin6_addr; /* IP6 address */
136 uint32_t sin6_scope_id; /* scope zone index */
137};
138
139/*
140 * Local definition for masks
141 */
142#ifdef _KERNEL /* XXX nonstandard */
143#define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}
144#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \
145 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
146#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
147 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
148#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
149 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}
150#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
151 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}
152#endif
153
154#ifdef _KERNEL
155extern const struct sockaddr_in6 sa6_any;
156
157extern const struct in6_addr in6mask0;
158extern const struct in6_addr in6mask32;
159extern const struct in6_addr in6mask64;
160extern const struct in6_addr in6mask96;
161extern const struct in6_addr in6mask128;
162#endif /* _KERNEL */
163
164/*
165 * Macros started with IPV6_ADDR is KAME local
166 */
167#ifdef _KERNEL /* XXX nonstandard */
168#if _BYTE_ORDER == _BIG_ENDIAN
169#define IPV6_ADDR_INT32_ONE 1
170#define IPV6_ADDR_INT32_TWO 2
171#define IPV6_ADDR_INT32_MNL 0xff010000
172#define IPV6_ADDR_INT32_MLL 0xff020000
173#define IPV6_ADDR_INT32_SMP 0x0000ffff
174#define IPV6_ADDR_INT16_ULL 0xfe80
175#define IPV6_ADDR_INT16_USL 0xfec0
176#define IPV6_ADDR_INT16_MLL 0xff02
177#elif _BYTE_ORDER == _LITTLE_ENDIAN
178#define IPV6_ADDR_INT32_ONE 0x01000000
179#define IPV6_ADDR_INT32_TWO 0x02000000
180#define IPV6_ADDR_INT32_MNL 0x000001ff
181#define IPV6_ADDR_INT32_MLL 0x000002ff
182#define IPV6_ADDR_INT32_SMP 0xffff0000
183#define IPV6_ADDR_INT16_ULL 0x80fe
184#define IPV6_ADDR_INT16_USL 0xc0fe
185#define IPV6_ADDR_INT16_MLL 0x02ff
186#endif
187#endif
188
189/*
190 * Definition of some useful macros to handle IP6 addresses
191 */
192#if __BSD_VISIBLE
193#define IN6ADDR_ANY_INIT \
194 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
196#define IN6ADDR_LOOPBACK_INIT \
197 {{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
198 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
199#define IN6ADDR_NODELOCAL_ALLNODES_INIT \
200 {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
202#define IN6ADDR_INTFACELOCAL_ALLNODES_INIT \
203 {{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
204 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
205#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
206 {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
208#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
209 {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
211#define IN6ADDR_LINKLOCAL_ALLV2ROUTERS_INIT \
212 {{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16 }}}
214#endif
215
216extern const struct in6_addr in6addr_any;
217extern const struct in6_addr in6addr_loopback;
218#if __BSD_VISIBLE
219extern const struct in6_addr in6addr_nodelocal_allnodes;
220extern const struct in6_addr in6addr_linklocal_allnodes;
221extern const struct in6_addr in6addr_linklocal_allrouters;
222extern const struct in6_addr in6addr_linklocal_allv2routers;
223#endif
224
225/*
226 * Equality
227 */
228#if __BSD_VISIBLE
229#define IN6_ARE_ADDR_EQUAL(a, b) \
230 (memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
231#endif
232
233/*
234 * Unspecified
235 */
236#define IN6_IS_ADDR_UNSPECIFIED(a) \
237 ((a)->__u6_addr.__u6_addr32[0] == 0 && \
238 (a)->__u6_addr.__u6_addr32[1] == 0 && \
239 (a)->__u6_addr.__u6_addr32[2] == 0 && \
240 (a)->__u6_addr.__u6_addr32[3] == 0)
241
242/*
243 * Loopback
244 */
245#define IN6_IS_ADDR_LOOPBACK(a) \
246 ((a)->__u6_addr.__u6_addr32[0] == 0 && \
247 (a)->__u6_addr.__u6_addr32[1] == 0 && \
248 (a)->__u6_addr.__u6_addr32[2] == 0 && \
249 (a)->__u6_addr.__u6_addr32[3] == ntohl(1))
250
251/*
252 * IPv4 compatible
253 */
254#define IN6_IS_ADDR_V4COMPAT(a) \
255 ((a)->__u6_addr.__u6_addr32[0] == 0 && \
256 (a)->__u6_addr.__u6_addr32[1] == 0 && \
257 (a)->__u6_addr.__u6_addr32[2] == 0 && \
258 (a)->__u6_addr.__u6_addr32[3] != 0 && \
259 (a)->__u6_addr.__u6_addr32[3] != ntohl(1))
260
261/*
262 * Mapped
263 */
264#define IN6_IS_ADDR_V4MAPPED(a) \
265 ((a)->__u6_addr.__u6_addr32[0] == 0 && \
266 (a)->__u6_addr.__u6_addr32[1] == 0 && \
267 (a)->__u6_addr.__u6_addr32[2] == ntohl(0x0000ffff))
268
269/*
270 * KAME Scope Values
271 */
272
273#ifdef _KERNEL /* XXX nonstandard */
274#define IPV6_ADDR_SCOPE_NODELOCAL 0x01
275#define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01
276#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02
277#define IPV6_ADDR_SCOPE_SITELOCAL 0x05
278#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */
279#define IPV6_ADDR_SCOPE_GLOBAL 0x0e
280#else
281#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01
282#define __IPV6_ADDR_SCOPE_INTFACELOCAL 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
288
289/*
290 * Unicast Scope
291 * Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).
292 */
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))
297
298/*
299 * Multicast
300 */
301#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
302
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
308
309/*
310 * Multicast Scope
311 */
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
348
349#ifdef _KERNEL /* nonstandard */
350/*
351 * KAME Scope
352 */
353#define IN6_IS_SCOPE_LINKLOCAL(a) \
354 ((IN6_IS_ADDR_LINKLOCAL(a)) || \
355 (IN6_IS_ADDR_MC_LINKLOCAL(a)))
356#define IN6_IS_SCOPE_EMBED(a) \
357 ((IN6_IS_ADDR_LINKLOCAL(a)) || \
358 (IN6_IS_ADDR_MC_LINKLOCAL(a)) || \
359 (IN6_IS_ADDR_MC_INTFACELOCAL(a)))
360
361#define IFA6_IS_DEPRECATED(a) \
362 ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
363 (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
364 (a)->ia6_lifetime.ia6t_pltime)
365#define IFA6_IS_INVALID(a) \
366 ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \
367 (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
368 (a)->ia6_lifetime.ia6t_vltime)
369#endif /* _KERNEL */
370
371/*
372 * IP6 route structure
373 */
374#if __BSD_VISIBLE
375struct nhop_object;
376struct route_in6 {
377 struct nhop_object *ro_nh;
378 struct llentry *ro_lle;
379 /*
380 * ro_prepend and ro_plen are only used for bpf to pass in a
381 * preformed header. They are not cacheable.
382 */
383 char *ro_prepend;
384 uint16_t ro_plen;
385 uint16_t ro_flags;
386 uint16_t ro_mtu; /* saved ro_rt mtu */
387 uint16_t spare;
388 struct sockaddr_in6 ro_dst;
389};
390#endif
391
392#ifdef _KERNEL
393#define MTAG_ABI_IPV6 1444287380 /* IPv6 ABI */
394#define IPV6_TAG_DIRECT 0 /* direct-dispatch IPv6 */
395#endif /* _KERNEL */
396
397/*
398 * Options for use with [gs]etsockopt at the IPV6 level.
399 * First word of comment is data type; bool is stored in int.
400 */
401/* no hdrincl */
402#if 0 /* the followings are relic in IPv4 and hence are disabled */
403#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */
404#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */
405#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */
406#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */
407#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */
408#endif
409#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */
410#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */
411#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */
412#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */
413#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */
414#define IPV6_JOIN_GROUP 12 /* ipv6_mreq; join a group membership */
415#define IPV6_LEAVE_GROUP 13 /* ipv6_mreq; leave a group membership */
416#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */
417#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */
418/* RFC2292 options */
419#ifdef _KERNEL
420#define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */
421#define IPV6_2292HOPLIMIT 20 /* bool; hop limit */
422#define IPV6_2292NEXTHOP 21 /* bool; next hop addr */
423#define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */
424#define IPV6_2292DSTOPTS 23 /* bool; destinaion option */
425#define IPV6_2292RTHDR 24 /* bool; routing header */
426#define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */
427#endif
428
429#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */
430#define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */
431#ifndef _KERNEL
432#define IPV6_BINDV6ONLY IPV6_V6ONLY
433#endif
434
435#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */
436 /* 29; unused; was IPV6_FAITH */
437#if 1 /* IPV6FIREWALL */
438#define IPV6_FW_ADD 30 /* add a firewall rule to chain */
439#define IPV6_FW_DEL 31 /* delete a firewall rule from chain */
440#define IPV6_FW_FLUSH 32 /* flush firewall rule chain */
441#define IPV6_FW_ZERO 33 /* clear single/all firewall counter(s) */
442#define IPV6_FW_GET 34 /* get entire firewall rule chain */
443#endif
444
445/* new socket options introduced in RFC3542 */
446#define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */
447
448#define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */
449#define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */
450#define IPV6_RECVRTHDR 38 /* bool; recv routing header */
451#define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */
452#define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */
453#ifdef _KERNEL
454#define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */
455#endif
456
457#define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */
458#define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */
459
460#define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt),
461 4 bytes int; MTU notification (cmsg) */
462#if 0 /*obsoleted during 2292bis -> 3542*/
463#define IPV6_REACHCONF 45 /* no data; ND reachability confirm
464 (cmsg only/not in of RFC3542) */
465#endif
466
467/* more new socket options introduced in RFC3542 */
468#define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */
469#define IPV6_HOPLIMIT 47 /* int; send hop limit */
470#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */
471#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */
472#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */
473#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */
474#if 0
475#define IPV6_PKTOPTIONS 52 /* buf/cmsghdr; set/get IPv6 options */
476 /* obsoleted by RFC3542 */
477#endif
478
479#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */
480
481#define IPV6_AUTOFLOWLABEL 59 /* bool; attach flowlabel automagically */
482
483#define IPV6_TCLASS 61 /* int; send traffic class value */
484#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */
485
486#define IPV6_PREFER_TEMPADDR 63 /* int; prefer temporary addresses as
487 * the source address.
488 */
489
490#define IPV6_BINDANY 64 /* bool: allow bind to any address */
491 /* unused; was IPV6_BIND_MULTI */
492 /* unused; was IPV6_RSS_LISTEN_BUCKET */
493#define IPV6_FLOWID 67 /* int; flowid of given socket */
494#define IPV6_FLOWTYPE 68 /* int; flowtype of given socket */
495#define IPV6_RSSBUCKETID 69 /* int; RSS bucket ID of given socket */
496#define IPV6_RECVFLOWID 70 /* bool; receive IP6 flowid/flowtype w/ datagram */
497#define IPV6_RECVRSSBUCKETID 71 /* bool; receive IP6 RSS bucket id w/ datagram */
498
499#define IPV6_ORIGDSTADDR 72 /* bool: allow getting dstaddr /port info */
500#define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR
501
502/*
503 * The following option is private; do not use it from user applications.
504 * It is deliberately defined to the same value as IP_MSFILTER.
505 */
506#define IPV6_MSFILTER 74 /* struct __msfilterreq;
507 * set/get multicast source filter list.
508 */
509
510/* The following option deals with the 802.1Q Ethernet Priority Code Point */
511#define IPV6_VLAN_PCP 75 /* int; set/get PCP used for packet, */
512 /* -1 use interface default */
513
514/* to define items, should talk with KAME guys first, for *BSD compatibility */
515
516#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */
517#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */
518#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */
519
520/*
521 * Defaults and limits for options
522 */
523#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */
524#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
525
526/*
527 * Limit for IPv6 multicast memberships
528 */
529#define IPV6_MAX_MEMBERSHIPS 4095
530
531/*
532 * Default resource limits for IPv6 multicast source filtering.
533 * These may be modified by sysctl.
534 */
535#define IPV6_MAX_GROUP_SRC_FILTER 512 /* sources per group */
536#define IPV6_MAX_SOCK_SRC_FILTER 128 /* sources per socket/group */
537
538/*
539 * Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.
540 */
541struct ipv6_mreq {
542 struct in6_addr ipv6mr_multiaddr;
543 unsigned int ipv6mr_interface;
544};
545
546/*
547 * IPV6_PKTINFO: Packet information(RFC2292 sec 5)
548 */
549struct in6_pktinfo {
550 struct in6_addr ipi6_addr; /* src/dst IPv6 address */
551 unsigned int ipi6_ifindex; /* send/recv interface index */
552};
553
554/*
555 * Control structure for IPV6_RECVPATHMTU socket option.
556 */
557struct ip6_mtuinfo {
558 struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */
559 uint32_t ip6m_mtu;
560};
561
562/*
563 * Argument for IPV6_PORTRANGE:
564 * - which range to search when port is unspecified at bind() or connect()
565 */
566#define IPV6_PORTRANGE_DEFAULT 0 /* default range */
567#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */
568#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */
569
570#if __BSD_VISIBLE
571/*
572 * Definitions for inet6 sysctl operations.
573 *
574 * Third level is protocol number.
575 * Fourth level is desired variable within that protocol.
576 */
577#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */
578
579/*
580 * Names for IP sysctl objects
581 */
582#define IPV6CTL_FORWARDING 1 /* act as router */
583#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/
584#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */
585#ifdef notyet
586#define IPV6CTL_DEFMTU 4 /* default MTU */
587#endif
588#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */
589#define IPV6CTL_STATS 6 /* stats */
590#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */
591#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */
592#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */
593#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */
594#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */
595#define IPV6CTL_ACCEPT_RTADV 12
596 /* 13; unused; was: IPV6CTL_KEEPFAITH */
597#define IPV6CTL_LOG_INTERVAL 14
598#define IPV6CTL_HDRNESTLIMIT 15
599#define IPV6CTL_DAD_COUNT 16
600#define IPV6CTL_AUTO_FLOWLABEL 17
601#define IPV6CTL_DEFMCASTHLIM 18
602#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */
603#define IPV6CTL_KAME_VERSION 20
604#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */
605#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */
606#if 0 /* obsolete */
607#define IPV6CTL_MAPPED_ADDR 23
608#endif
609#define IPV6CTL_V6ONLY 24
610/* IPV6CTL_RTEXPIRE 25 deprecated */
611/* IPV6CTL_RTMINEXPIRE 26 deprecated */
612/* IPV6CTL_RTMAXCACHE 27 deprecated */
613
614#define IPV6CTL_USETEMPADDR 32 /* use temporary addresses (RFC3041) */
615#define IPV6CTL_TEMPPLTIME 33 /* preferred lifetime for tmpaddrs */
616#define IPV6CTL_TEMPVLTIME 34 /* valid lifetime for tmpaddrs */
617#define IPV6CTL_AUTO_LINKLOCAL 35 /* automatic link-local addr assign */
618#define IPV6CTL_RIP6STATS 36 /* raw_ip6 stats */
619#define IPV6CTL_PREFER_TEMPADDR 37 /* prefer temporary addr as src */
620#define IPV6CTL_ADDRCTLPOLICY 38 /* get/set address selection policy */
621#define IPV6CTL_USE_DEFAULTZONE 39 /* use default scope zone */
622
623#define IPV6CTL_MAXFRAGS 41 /* max fragments */
624#if 0
625#define IPV6CTL_IFQ 42 /* ip6intrq node */
626#define IPV6CTL_ISATAPRTR 43 /* isatap router */
627#endif
628#define IPV6CTL_MCAST_PMTU 44 /* enable pMTU discovery for multicast? */
629
630/* New entries should be added here from current IPV6CTL_MAXID value. */
631/* to define items, should talk with KAME guys first, for *BSD compatibility */
632#define IPV6CTL_STEALTH 45
633
634#define ICMPV6CTL_ND6_ONLINKNSRFC4861 47
635#define IPV6CTL_NO_RADR 48 /* No defroute from RA */
636#define IPV6CTL_NORBIT_RAIF 49 /* Disable R-bit in NA on RA
637 * receiving IF. */
638#define IPV6CTL_RFC6204W3 50 /* Accept defroute even when forwarding
639 enabled */
640#define IPV6CTL_INTRQMAXLEN 51 /* max length of IPv6 netisr queue */
641#define IPV6CTL_INTRDQMAXLEN 52 /* max length of direct IPv6 netisr
642 * queue */
643#define IPV6CTL_MAXFRAGSPERPACKET 53 /* Max fragments per packet */
644#define IPV6CTL_MAXFRAGBUCKETSIZE 54 /* Max reassembly queues per bucket */
645#define IPV6CTL_MAXID 55
646#endif /* __BSD_VISIBLE */
647
648/*
649 * Since both netinet/ and netinet6/ call into netipsec/ and netpfil/,
650 * the protocol specific mbuf flags are shared between them.
651 */
652#define M_FASTFWD_OURS M_PROTO1 /* changed dst to local */
653#define M_IP6_NEXTHOP M_PROTO2 /* explicit ip nexthop */
654#define M_IP_NEXTHOP M_PROTO2 /* explicit ip nexthop */
655#define M_SKIP_FIREWALL M_PROTO3 /* skip firewall processing */
656#define M_AUTHIPHDR M_PROTO4
657#define M_DECRYPTED M_PROTO5
658#define M_LOOP M_PROTO6
659#define M_AUTHIPDGM M_PROTO7
660#define M_RTALERT_MLD M_PROTO8
661#define M_FRAGMENTED M_PROTO9 /* contained fragment header */
662
663#ifdef _KERNEL
664struct cmsghdr;
665struct ip6_hdr;
666
667int in6_cksum(struct mbuf *, uint8_t, uint32_t, uint32_t);
668int in6_cksum_partial(struct mbuf *, uint8_t, uint32_t, uint32_t, uint32_t);
669int in6_cksum_pseudo(struct ip6_hdr *, uint32_t, uint8_t, uint16_t);
670
671int in6_localaddr(struct in6_addr *);
672int in6_localip(struct in6_addr *);
673bool in6_localip_fib(struct in6_addr *, uint16_t);
674int in6_ifhasaddr(struct ifnet *, struct in6_addr *);
675int in6_addrscope(const struct in6_addr *);
676char *ip6_sprintf(char *, const struct in6_addr *);
677struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *);
678extern void in6_if_up(struct ifnet *);
679struct sockaddr;
680
681void in6_sin6_2_sin(struct sockaddr_in *sin,
682 struct sockaddr_in6 *sin6);
683void in6_sin_2_v4mapsin6(struct sockaddr_in *sin,
684 struct sockaddr_in6 *sin6);
685void in6_sin6_2_sin_in_sock(struct sockaddr *nam);
686void in6_sin_2_v4mapsin6_in_sock(struct sockaddr **nam);
687extern void addrsel_policy_init(void);
688
689#define satosin6(sa) ((struct sockaddr_in6 *)(sa))
690#define sin6tosa(sin6) ((struct sockaddr *)(sin6))
691#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa))
692
693#endif /* _KERNEL */
694
695#ifndef _SIZE_T_DECLARED
696typedef __size_t size_t;
697#define _SIZE_T_DECLARED
698#endif
699
700#ifndef _SOCKLEN_T_DECLARED
701typedef __socklen_t socklen_t;
702#define _SOCKLEN_T_DECLARED
703#endif
704
705#if __BSD_VISIBLE
706
707__BEGIN_DECLS
708struct cmsghdr;
709
710extern int inet6_option_space(int);
711extern int inet6_option_init(void *, struct cmsghdr **, int);
712extern int inet6_option_append(struct cmsghdr *, const uint8_t *,
713 int, int);
714extern uint8_t *inet6_option_alloc(struct cmsghdr *, int, int, int);
715extern int inet6_option_next(const struct cmsghdr *, uint8_t **);
716extern int inet6_option_find(const struct cmsghdr *, uint8_t **, int);
717
718extern size_t inet6_rthdr_space(int, int);
719extern struct cmsghdr *inet6_rthdr_init(void *, int);
720extern int inet6_rthdr_add(struct cmsghdr *, const struct in6_addr *,
721 unsigned int);
722extern int inet6_rthdr_lasthop(struct cmsghdr *, unsigned int);
723#if 0 /* not implemented yet */
724extern int inet6_rthdr_reverse(const struct cmsghdr *, struct cmsghdr *);
725#endif
726extern int inet6_rthdr_segments(const struct cmsghdr *);
727extern struct in6_addr *inet6_rthdr_getaddr(struct cmsghdr *, int);
728extern int inet6_rthdr_getflags(const struct cmsghdr *, int);
729
730extern int inet6_opt_init(void *, socklen_t);
731extern int inet6_opt_append(void *, socklen_t, int, uint8_t, socklen_t,
732 uint8_t, void **);
733extern int inet6_opt_finish(void *, socklen_t, int);
734extern int inet6_opt_set_val(void *, int, void *, socklen_t);
735
736extern int inet6_opt_next(void *, socklen_t, int, uint8_t *, socklen_t *,
737 void **);
738extern int inet6_opt_find(void *, socklen_t, int, uint8_t, socklen_t *,
739 void **);
740extern int inet6_opt_get_val(void *, int, void *, socklen_t);
741extern socklen_t inet6_rth_space(int, int);
742extern void *inet6_rth_init(void *, socklen_t, int, int);
743extern int inet6_rth_add(void *, const struct in6_addr *);
744extern int inet6_rth_reverse(const void *, void *);
745extern int inet6_rth_segments(const void *);
746extern struct in6_addr *inet6_rth_getaddr(const void *, int);
747__END_DECLS
748
749#endif /* __BSD_VISIBLE */
750
751#endif /* !_NETINET6_IN6_H_ */