Make ifconfig(8) set and display preference numbers for IPv6
addresses. Make the kernel support SIOC[SG]IFADDRPREF for IPv6
interface addresses.
In in6ifa_ifpforlinklocal(), consult preference numbers before
making an otherwise arbitrary choice of in6_ifaddr. Otherwise,
preference numbers are *not* consulted by the kernel, but that will
be rather easy for somebody with a little bit of free time to fix.
Please note that setting the preference number for a link-local
IPv6 address does not work right, yet, but that ought to be fixed
soon.
In support of the changes above,
1 Add a method to struct domain for "externalizing" a sockaddr, and
provide an implementation for IPv6. Expect more work in this area: it
may be more proper to say that the IPv6 implementation "internalizes"
a sockaddr. Add sockaddr_externalize().
2 Add a subroutine, sofamily(), that returns a struct socket's address
family or AF_UNSPEC.
3 Make a lot of IPv4-specific code generic, and move it from
sys/netinet/ to sys/net/ for re-use by IPv6 parts of the kernel and
ifconfig(8).
2009-09-12 02:06:29 +04:00
|
|
|
/* $NetBSD: in6.h,v 1.68 2009/09/11 22:06:29 dyoung Exp $ */
|
2001-03-30 09:53:52 +04:00
|
|
|
/* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */
|
1999-07-04 01:24:45 +04:00
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
|
|
|
* All rights reserved.
|
2000-05-24 18:40:09 +04:00
|
|
|
*
|
1999-06-28 10:36:47 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the project nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
2000-05-24 18:40:09 +04:00
|
|
|
*
|
1999-06-28 10:36:47 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1982, 1986, 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1999-06-28 10:36:47 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)in.h 8.3 (Berkeley) 1/3/94
|
|
|
|
*/
|
|
|
|
|
2005-12-11 02:31:41 +03:00
|
|
|
#ifndef _NETINET6_IN6_H_
|
|
|
|
#define _NETINET6_IN6_H_
|
|
|
|
|
2000-02-09 03:54:55 +03:00
|
|
|
#ifndef __KAME_NETINET_IN_H_INCLUDED_
|
2001-03-30 09:53:52 +04:00
|
|
|
#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553"
|
2000-02-09 03:54:55 +03:00
|
|
|
#endif
|
|
|
|
|
2006-05-05 04:03:21 +04:00
|
|
|
#include <sys/socket.h>
|
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
/*
|
|
|
|
* Identification of the network protocol stack
|
2001-03-02 07:55:40 +03:00
|
|
|
* for *BSD-current/release: http://www.kame.net/dev/cvsweb.cgi/kame/COVERAGE
|
|
|
|
* has the table of implementation/integration differences.
|
1999-06-28 10:36:47 +04:00
|
|
|
*/
|
|
|
|
#define __KAME__
|
2001-03-02 07:52:54 +03:00
|
|
|
#define __KAME_VERSION "NetBSD-current"
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local port number conventions:
|
|
|
|
*
|
|
|
|
* Ports < IPPORT_RESERVED are reserved for privileged processes (e.g. root),
|
|
|
|
* unless a kernel is compiled with IPNOPRIVPORTS defined.
|
|
|
|
*
|
|
|
|
* When a user does a bind(2) or connect(2) with a port number of zero,
|
|
|
|
* a non-conflicting local port address is chosen.
|
|
|
|
*
|
2000-07-16 05:10:34 +04:00
|
|
|
* The default range is IPPORT_ANONMIN to IPPORT_ANONMAX, although
|
1999-06-28 10:36:47 +04:00
|
|
|
* that is settable by sysctl(3); net.inet.ip.anonportmin and
|
|
|
|
* net.inet.ip.anonportmax respectively.
|
|
|
|
*
|
|
|
|
* A user may set the IPPROTO_IP option IP_PORTRANGE to change this
|
|
|
|
* default assignment range.
|
|
|
|
*
|
|
|
|
* The value IP_PORTRANGE_DEFAULT causes the default behavior.
|
|
|
|
*
|
|
|
|
* The value IP_PORTRANGE_HIGH is the same as IP_PORTRANGE_DEFAULT,
|
|
|
|
* and exists only for FreeBSD compatibility purposes.
|
|
|
|
*
|
|
|
|
* The value IP_PORTRANGE_LOW changes the range to the "low" are
|
|
|
|
* that is (by convention) restricted to privileged processes.
|
|
|
|
* This convention is based on "vouchsafe" principles only.
|
|
|
|
* It is only secure if you trust the remote host to restrict these ports.
|
|
|
|
* The range is IPPORT_RESERVEDMIN to IPPORT_RESERVEDMAX.
|
|
|
|
*/
|
|
|
|
|
Add a new feature-test macro, _NETBSD_SOURCE. If this is defined
by the application, all NetBSD interfaces are made visible, even
if some other feature-test macro (like _POSIX_C_SOURCE) is defined.
<sys/featuretest.h> defined _NETBSD_SOURCE if none of _ANSI_SOURCE,
_POSIX_C_SOURCE and _XOPEN_SOURCE is defined, so as to preserve
existing behaviour.
This has two major advantages:
+ Programs that require non-POSIX facilities but define _POSIX_C_SOURCE
can trivially be overruled by putting -D_NETBSD_SOURCE in their CFLAGS.
+ It makes most of the #ifs simpler, in that they're all now ORs of the
various macros, rather than having checks for (!defined(_ANSI_SOURCE) ||
!defined(_POSIX_C_SOURCE) || !defined(_XOPEN_SOURCE)) all over the place.
I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them. In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.
Tested by building for vax, encouraged by thorpej, and uncontested in
tech-userlevel for a week.
2003-04-29 03:16:11 +04:00
|
|
|
#if defined(_NETBSD_SOURCE)
|
1999-06-28 10:36:47 +04:00
|
|
|
#define IPV6PORT_RESERVED 1024
|
|
|
|
#define IPV6PORT_ANONMIN 49152
|
|
|
|
#define IPV6PORT_ANONMAX 65535
|
|
|
|
#define IPV6PORT_RESERVEDMIN 600
|
|
|
|
#define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1)
|
2002-05-13 18:25:13 +04:00
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IPv6 address
|
|
|
|
*/
|
1999-07-03 18:04:57 +04:00
|
|
|
struct in6_addr {
|
1999-06-28 10:36:47 +04:00
|
|
|
union {
|
2002-05-13 19:20:30 +04:00
|
|
|
__uint8_t __u6_addr8[16];
|
|
|
|
__uint16_t __u6_addr16[8];
|
|
|
|
uint32_t __u6_addr32[4];
|
1999-07-03 18:04:57 +04:00
|
|
|
} __u6_addr; /* 128-bit IP6 address */
|
1999-06-28 10:36:47 +04:00
|
|
|
};
|
|
|
|
|
1999-07-03 18:04:57 +04:00
|
|
|
#define s6_addr __u6_addr.__u6_addr8
|
2001-10-16 08:17:54 +04:00
|
|
|
#ifdef _KERNEL /* XXX nonstandard */
|
1999-12-13 18:17:17 +03:00
|
|
|
#define s6_addr8 __u6_addr.__u6_addr8
|
|
|
|
#define s6_addr16 __u6_addr.__u6_addr16
|
|
|
|
#define s6_addr32 __u6_addr.__u6_addr32
|
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
#define INET6_ADDRSTRLEN 46
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Socket address for IPv6
|
|
|
|
*/
|
Add a new feature-test macro, _NETBSD_SOURCE. If this is defined
by the application, all NetBSD interfaces are made visible, even
if some other feature-test macro (like _POSIX_C_SOURCE) is defined.
<sys/featuretest.h> defined _NETBSD_SOURCE if none of _ANSI_SOURCE,
_POSIX_C_SOURCE and _XOPEN_SOURCE is defined, so as to preserve
existing behaviour.
This has two major advantages:
+ Programs that require non-POSIX facilities but define _POSIX_C_SOURCE
can trivially be overruled by putting -D_NETBSD_SOURCE in their CFLAGS.
+ It makes most of the #ifs simpler, in that they're all now ORs of the
various macros, rather than having checks for (!defined(_ANSI_SOURCE) ||
!defined(_POSIX_C_SOURCE) || !defined(_XOPEN_SOURCE)) all over the place.
I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them. In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.
Tested by building for vax, encouraged by thorpej, and uncontested in
tech-userlevel for a week.
2003-04-29 03:16:11 +04:00
|
|
|
#if defined(_NETBSD_SOURCE)
|
1999-06-28 10:36:47 +04:00
|
|
|
#define SIN6_LEN
|
1999-07-03 18:04:57 +04:00
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
struct sockaddr_in6 {
|
2002-05-13 19:20:30 +04:00
|
|
|
uint8_t sin6_len; /* length of this struct(socklen_t)*/
|
2000-06-26 19:48:19 +04:00
|
|
|
sa_family_t sin6_family; /* AF_INET6 (sa_family_t) */
|
2002-05-13 17:52:31 +04:00
|
|
|
in_port_t sin6_port; /* Transport layer port */
|
2002-05-13 19:20:30 +04:00
|
|
|
uint32_t sin6_flowinfo; /* IP6 flow information */
|
1999-06-28 10:36:47 +04:00
|
|
|
struct in6_addr sin6_addr; /* IP6 address */
|
2002-05-13 19:20:30 +04:00
|
|
|
uint32_t sin6_scope_id; /* scope zone index */
|
1999-06-28 10:36:47 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local definition for masks
|
|
|
|
*/
|
2001-10-16 08:17:54 +04:00
|
|
|
#ifdef _KERNEL /* XXX nonstandard */
|
1999-12-13 18:17:17 +03:00
|
|
|
#define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}
|
|
|
|
#define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
|
|
|
|
#define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
|
|
|
|
#define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}
|
|
|
|
#define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}
|
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
#ifdef _KERNEL
|
2001-02-11 09:49:49 +03:00
|
|
|
extern const struct sockaddr_in6 sa6_any;
|
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
extern const struct in6_addr in6mask0;
|
|
|
|
extern const struct in6_addr in6mask32;
|
|
|
|
extern const struct in6_addr in6mask64;
|
|
|
|
extern const struct in6_addr in6mask96;
|
|
|
|
extern const struct in6_addr in6mask128;
|
|
|
|
#endif /* _KERNEL */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros started with IPV6_ADDR is KAME local
|
|
|
|
*/
|
2001-10-16 08:17:54 +04:00
|
|
|
#ifdef _KERNEL /* XXX nonstandard */
|
1999-06-28 10:36:47 +04:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
|
|
|
#define IPV6_ADDR_INT32_ONE 1
|
|
|
|
#define IPV6_ADDR_INT32_TWO 2
|
|
|
|
#define IPV6_ADDR_INT32_MNL 0xff010000
|
|
|
|
#define IPV6_ADDR_INT32_MLL 0xff020000
|
|
|
|
#define IPV6_ADDR_INT32_SMP 0x0000ffff
|
|
|
|
#define IPV6_ADDR_INT16_ULL 0xfe80
|
|
|
|
#define IPV6_ADDR_INT16_USL 0xfec0
|
|
|
|
#define IPV6_ADDR_INT16_MLL 0xff02
|
|
|
|
#elif BYTE_ORDER == LITTLE_ENDIAN
|
|
|
|
#define IPV6_ADDR_INT32_ONE 0x01000000
|
|
|
|
#define IPV6_ADDR_INT32_TWO 0x02000000
|
|
|
|
#define IPV6_ADDR_INT32_MNL 0x000001ff
|
|
|
|
#define IPV6_ADDR_INT32_MLL 0x000002ff
|
|
|
|
#define IPV6_ADDR_INT32_SMP 0xffff0000
|
|
|
|
#define IPV6_ADDR_INT16_ULL 0x80fe
|
|
|
|
#define IPV6_ADDR_INT16_USL 0xc0fe
|
|
|
|
#define IPV6_ADDR_INT16_MLL 0x02ff
|
|
|
|
#endif
|
1999-12-13 18:17:17 +03:00
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Definition of some useful macros to handle IP6 addresses
|
|
|
|
*/
|
1999-12-13 18:17:17 +03:00
|
|
|
#define IN6ADDR_ANY_INIT \
|
|
|
|
{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
|
|
|
|
#define IN6ADDR_LOOPBACK_INIT \
|
|
|
|
{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
|
|
|
|
#define IN6ADDR_NODELOCAL_ALLNODES_INIT \
|
|
|
|
{{{ 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
|
|
|
|
#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
|
|
|
|
{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
|
1999-06-28 10:36:47 +04:00
|
|
|
#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
|
1999-12-13 18:17:17 +03:00
|
|
|
{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
extern const struct in6_addr in6addr_any;
|
|
|
|
extern const struct in6_addr in6addr_loopback;
|
|
|
|
extern const struct in6_addr in6addr_nodelocal_allnodes;
|
|
|
|
extern const struct in6_addr in6addr_linklocal_allnodes;
|
|
|
|
extern const struct in6_addr in6addr_linklocal_allrouters;
|
|
|
|
|
|
|
|
#define IN6_ARE_ADDR_EQUAL(a, b) \
|
2000-05-24 18:40:09 +04:00
|
|
|
(memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Unspecified
|
|
|
|
*/
|
|
|
|
#define IN6_IS_ADDR_UNSPECIFIED(a) \
|
2009-08-19 22:52:48 +04:00
|
|
|
((a)->__u6_addr.__u6_addr32[0] == 0 && \
|
|
|
|
(a)->__u6_addr.__u6_addr32[1] == 0 && \
|
|
|
|
(a)->__u6_addr.__u6_addr32[2] == 0 && \
|
|
|
|
(a)->__u6_addr.__u6_addr32[3] == 0)
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Loopback
|
|
|
|
*/
|
|
|
|
#define IN6_IS_ADDR_LOOPBACK(a) \
|
2009-08-19 22:52:48 +04:00
|
|
|
((a)->__u6_addr.__u6_addr32[0] == 0 && \
|
|
|
|
(a)->__u6_addr.__u6_addr32[1] == 0 && \
|
|
|
|
(a)->__u6_addr.__u6_addr32[2] == 0 && \
|
|
|
|
(a)->__u6_addr.__u6_addr32[3] == ntohl(1))
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IPv4 compatible
|
|
|
|
*/
|
|
|
|
#define IN6_IS_ADDR_V4COMPAT(a) \
|
2009-08-19 22:52:48 +04:00
|
|
|
((a)->__u6_addr.__u6_addr32[0] == 0 && \
|
|
|
|
(a)->__u6_addr.__u6_addr32[1] == 0 && \
|
|
|
|
(a)->__u6_addr.__u6_addr32[2] == 0 && \
|
|
|
|
(a)->__u6_addr.__u6_addr32[3] != 0 && \
|
|
|
|
(a)->__u6_addr.__u6_addr32[3] != ntohl(1))
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mapped
|
|
|
|
*/
|
|
|
|
#define IN6_IS_ADDR_V4MAPPED(a) \
|
2009-08-19 22:52:48 +04:00
|
|
|
((a)->__u6_addr.__u6_addr32[0] == 0 && \
|
|
|
|
(a)->__u6_addr.__u6_addr32[1] == 0 && \
|
|
|
|
(a)->__u6_addr.__u6_addr32[2] == ntohl(0x0000ffff))
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* KAME Scope Values
|
|
|
|
*/
|
|
|
|
|
2001-10-16 08:17:54 +04:00
|
|
|
#ifdef _KERNEL /* XXX nonstandard */
|
1999-06-28 10:36:47 +04:00
|
|
|
#define IPV6_ADDR_SCOPE_NODELOCAL 0x01
|
Better support of IPv6 scoped addresses.
- most of the kernel code will not care about the actual encoding of
scope zone IDs and won't touch "s6_addr16[1]" directly.
- similarly, most of the kernel code will not care about link-local
scoped addresses as a special case.
- scope boundary check will be stricter. For example, the current
*BSD code allows a packet with src=::1 and dst=(some global IPv6
address) to be sent outside of the node, if the application do:
s = socket(AF_INET6);
bind(s, "::1");
sendto(s, some_global_IPv6_addr);
This is clearly wrong, since ::1 is only meaningful within a single
node, but the current implementation of the *BSD kernel cannot
reject this attempt.
- and, while there, don't try to remove the ff02::/32 interface route
entry in in6_ifdetach() as it's already gone.
This also includes some level of support for the standard source
address selection algorithm defined in RFC3484, which will be
completed on in the future.
From the KAME project via JINMEI Tatuya.
Approved by core@.
2006-01-21 03:15:35 +03:00
|
|
|
#define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01
|
1999-06-28 10:36:47 +04:00
|
|
|
#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02
|
|
|
|
#define IPV6_ADDR_SCOPE_SITELOCAL 0x05
|
|
|
|
#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */
|
|
|
|
#define IPV6_ADDR_SCOPE_GLOBAL 0x0e
|
1999-12-13 18:17:17 +03:00
|
|
|
#else
|
|
|
|
#define __IPV6_ADDR_SCOPE_NODELOCAL 0x01
|
|
|
|
#define __IPV6_ADDR_SCOPE_LINKLOCAL 0x02
|
|
|
|
#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05
|
|
|
|
#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */
|
|
|
|
#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e
|
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Unicast Scope
|
1999-12-13 18:17:17 +03:00
|
|
|
* Note that we must check topmost 10 bits only, not 16 bits (see RFC2373).
|
1999-06-28 10:36:47 +04:00
|
|
|
*/
|
|
|
|
#define IN6_IS_ADDR_LINKLOCAL(a) \
|
1999-12-13 18:17:17 +03:00
|
|
|
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
|
1999-06-28 10:36:47 +04:00
|
|
|
#define IN6_IS_ADDR_SITELOCAL(a) \
|
1999-12-13 18:17:17 +03:00
|
|
|
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Multicast
|
|
|
|
*/
|
1999-12-13 18:17:17 +03:00
|
|
|
#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2001-10-16 08:17:54 +04:00
|
|
|
#ifdef _KERNEL /* XXX nonstandard */
|
1999-12-13 18:17:17 +03:00
|
|
|
#define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
|
|
|
|
#else
|
|
|
|
#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
|
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Multicast Scope
|
|
|
|
*/
|
2001-10-16 08:17:54 +04:00
|
|
|
#ifdef _KERNEL /* refers nonstandard items */
|
1999-06-28 10:36:47 +04:00
|
|
|
#define IN6_IS_ADDR_MC_NODELOCAL(a) \
|
|
|
|
(IN6_IS_ADDR_MULTICAST(a) && \
|
|
|
|
(IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL))
|
Better support of IPv6 scoped addresses.
- most of the kernel code will not care about the actual encoding of
scope zone IDs and won't touch "s6_addr16[1]" directly.
- similarly, most of the kernel code will not care about link-local
scoped addresses as a special case.
- scope boundary check will be stricter. For example, the current
*BSD code allows a packet with src=::1 and dst=(some global IPv6
address) to be sent outside of the node, if the application do:
s = socket(AF_INET6);
bind(s, "::1");
sendto(s, some_global_IPv6_addr);
This is clearly wrong, since ::1 is only meaningful within a single
node, but the current implementation of the *BSD kernel cannot
reject this attempt.
- and, while there, don't try to remove the ff02::/32 interface route
entry in in6_ifdetach() as it's already gone.
This also includes some level of support for the standard source
address selection algorithm defined in RFC3484, which will be
completed on in the future.
From the KAME project via JINMEI Tatuya.
Approved by core@.
2006-01-21 03:15:35 +03:00
|
|
|
#define IN6_IS_ADDR_MC_INTFACELOCAL(a) \
|
|
|
|
(IN6_IS_ADDR_MULTICAST(a) && \
|
|
|
|
(IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL))
|
1999-06-28 10:36:47 +04:00
|
|
|
#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
|
|
|
|
(IN6_IS_ADDR_MULTICAST(a) && \
|
|
|
|
(IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL))
|
|
|
|
#define IN6_IS_ADDR_MC_SITELOCAL(a) \
|
|
|
|
(IN6_IS_ADDR_MULTICAST(a) && \
|
|
|
|
(IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL))
|
|
|
|
#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
|
|
|
|
(IN6_IS_ADDR_MULTICAST(a) && \
|
|
|
|
(IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL))
|
|
|
|
#define IN6_IS_ADDR_MC_GLOBAL(a) \
|
|
|
|
(IN6_IS_ADDR_MULTICAST(a) && \
|
|
|
|
(IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL))
|
1999-12-13 18:17:17 +03:00
|
|
|
#else
|
|
|
|
#define IN6_IS_ADDR_MC_NODELOCAL(a) \
|
|
|
|
(IN6_IS_ADDR_MULTICAST(a) && \
|
|
|
|
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_NODELOCAL))
|
|
|
|
#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
|
|
|
|
(IN6_IS_ADDR_MULTICAST(a) && \
|
|
|
|
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_LINKLOCAL))
|
|
|
|
#define IN6_IS_ADDR_MC_SITELOCAL(a) \
|
|
|
|
(IN6_IS_ADDR_MULTICAST(a) && \
|
|
|
|
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
|
|
|
|
#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
|
|
|
|
(IN6_IS_ADDR_MULTICAST(a) && \
|
|
|
|
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
|
|
|
|
#define IN6_IS_ADDR_MC_GLOBAL(a) \
|
|
|
|
(IN6_IS_ADDR_MULTICAST(a) && \
|
|
|
|
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL))
|
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2001-10-16 08:17:54 +04:00
|
|
|
#ifdef _KERNEL /* nonstandard */
|
1999-06-28 10:36:47 +04:00
|
|
|
/*
|
|
|
|
* KAME Scope
|
|
|
|
*/
|
|
|
|
#define IN6_IS_SCOPE_LINKLOCAL(a) \
|
|
|
|
((IN6_IS_ADDR_LINKLOCAL(a)) || \
|
|
|
|
(IN6_IS_ADDR_MC_LINKLOCAL(a)))
|
2002-06-09 01:22:29 +04:00
|
|
|
|
2006-03-30 01:29:59 +04:00
|
|
|
#define IN6_IS_SCOPE_EMBEDDABLE(__a) \
|
|
|
|
(IN6_IS_SCOPE_LINKLOCAL(__a) || IN6_IS_ADDR_MC_INTFACELOCAL(__a))
|
|
|
|
|
2002-06-09 01:22:29 +04:00
|
|
|
#define IFA6_IS_DEPRECATED(a) \
|
|
|
|
((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
|
2006-06-08 02:33:33 +04:00
|
|
|
(u_int32_t)((time_second - (a)->ia6_updatetime)) > \
|
2002-06-09 01:22:29 +04:00
|
|
|
(a)->ia6_lifetime.ia6t_pltime)
|
|
|
|
#define IFA6_IS_INVALID(a) \
|
|
|
|
((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \
|
2006-06-08 02:33:33 +04:00
|
|
|
(u_int32_t)((time_second - (a)->ia6_updatetime)) > \
|
2002-06-09 01:22:29 +04:00
|
|
|
(a)->ia6_lifetime.ia6t_vltime)
|
1999-12-13 18:17:17 +03:00
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Options for use with [gs]etsockopt at the IPV6 level.
|
|
|
|
* First word of comment is data type; bool is stored in int.
|
|
|
|
*/
|
|
|
|
/* no hdrincl */
|
2006-10-31 03:29:30 +03:00
|
|
|
#if 0
|
|
|
|
/* These are deprecated non-standard options which are no longer supported. */
|
|
|
|
#define IPV6_OPTIONS 1 /* buf/ip6_opts; set/get IP6 options */
|
1999-06-28 10:36:47 +04:00
|
|
|
#define IPV6_RECVOPTS 5 /* bool; receive all IP6 opts w/dgram */
|
|
|
|
#define IPV6_RECVRETOPTS 6 /* bool; receive IP6 opts for response */
|
|
|
|
#define IPV6_RECVDSTADDR 7 /* bool; receive IP6 dst addr w/dgram */
|
|
|
|
#define IPV6_RETOPTS 8 /* ip6_opts; set/get IP6 options */
|
2006-10-31 03:29:30 +03:00
|
|
|
#endif
|
|
|
|
#define IPV6_SOCKOPT_RESERVED1 3 /* reserved for future use */
|
|
|
|
#define IPV6_UNICAST_HOPS 4 /* int; IP6 hops */
|
2001-07-24 04:44:36 +04:00
|
|
|
#define IPV6_MULTICAST_IF 9 /* u_int; set/get IP6 multicast i/f */
|
|
|
|
#define IPV6_MULTICAST_HOPS 10 /* int; set/get IP6 multicast hops */
|
|
|
|
#define IPV6_MULTICAST_LOOP 11 /* u_int; set/get IP6 multicast loopback */
|
1999-06-28 10:36:47 +04:00
|
|
|
#define IPV6_JOIN_GROUP 12 /* ip6_mreq; join a group membership */
|
|
|
|
#define IPV6_LEAVE_GROUP 13 /* ip6_mreq; leave a group membership */
|
|
|
|
#define IPV6_PORTRANGE 14 /* int; range to choose for unspec port */
|
Add a new feature-test macro, _NETBSD_SOURCE. If this is defined
by the application, all NetBSD interfaces are made visible, even
if some other feature-test macro (like _POSIX_C_SOURCE) is defined.
<sys/featuretest.h> defined _NETBSD_SOURCE if none of _ANSI_SOURCE,
_POSIX_C_SOURCE and _XOPEN_SOURCE is defined, so as to preserve
existing behaviour.
This has two major advantages:
+ Programs that require non-POSIX facilities but define _POSIX_C_SOURCE
can trivially be overruled by putting -D_NETBSD_SOURCE in their CFLAGS.
+ It makes most of the #ifs simpler, in that they're all now ORs of the
various macros, rather than having checks for (!defined(_ANSI_SOURCE) ||
!defined(_POSIX_C_SOURCE) || !defined(_XOPEN_SOURCE)) all over the place.
I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them. In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.
Tested by building for vax, encouraged by thorpej, and uncontested in
tech-userlevel for a week.
2003-04-29 03:16:11 +04:00
|
|
|
#if defined(_NETBSD_SOURCE)
|
1999-06-28 10:36:47 +04:00
|
|
|
#define ICMP6_FILTER 18 /* icmp6_filter; icmp6 filter */
|
2002-05-13 18:15:34 +04:00
|
|
|
#endif
|
2006-05-05 04:03:21 +04:00
|
|
|
/* RFC2292 options */
|
|
|
|
#ifdef _KERNEL
|
|
|
|
#define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */
|
|
|
|
#define IPV6_2292HOPLIMIT 20 /* bool; hop limit */
|
|
|
|
#define IPV6_2292NEXTHOP 21 /* bool; next hop addr */
|
|
|
|
#define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */
|
2007-02-15 19:28:37 +03:00
|
|
|
#define IPV6_2292DSTOPTS 23 /* bool; destination option */
|
2006-05-05 04:03:21 +04:00
|
|
|
#define IPV6_2292RTHDR 24 /* bool; routing header */
|
|
|
|
#define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */
|
|
|
|
#endif
|
1999-06-28 10:36:47 +04:00
|
|
|
#define IPV6_CHECKSUM 26 /* int; checksum offset for raw socket */
|
2001-10-18 11:44:33 +04:00
|
|
|
#define IPV6_V6ONLY 27 /* bool; make AF_INET6 sockets v6 only */
|
1999-06-28 10:36:47 +04:00
|
|
|
|
2001-10-24 10:36:37 +04:00
|
|
|
#if 1 /* IPSEC */
|
1999-06-28 10:36:47 +04:00
|
|
|
#define IPV6_IPSEC_POLICY 28 /* struct; get/set security policy */
|
|
|
|
#endif
|
1999-12-13 18:17:17 +03:00
|
|
|
#define IPV6_FAITH 29 /* bool; accept FAITH'ed connections */
|
2006-05-05 04:03:21 +04:00
|
|
|
|
|
|
|
/* new socket options introduced in RFC3542 */
|
|
|
|
#define IPV6_RTHDRDSTOPTS 35 /* ip6_dest; send dst option before rthdr */
|
|
|
|
|
|
|
|
#define IPV6_RECVPKTINFO 36 /* bool; recv if, dst addr */
|
|
|
|
#define IPV6_RECVHOPLIMIT 37 /* bool; recv hop limit */
|
|
|
|
#define IPV6_RECVRTHDR 38 /* bool; recv routing header */
|
|
|
|
#define IPV6_RECVHOPOPTS 39 /* bool; recv hop-by-hop option */
|
|
|
|
#define IPV6_RECVDSTOPTS 40 /* bool; recv dst option after rthdr */
|
|
|
|
#ifdef _KERNEL
|
|
|
|
#define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */
|
|
|
|
#endif
|
2004-06-11 08:10:10 +04:00
|
|
|
#define IPV6_USE_MIN_MTU 42 /* bool; send packets at the minimum MTU */
|
2006-05-05 04:03:21 +04:00
|
|
|
#define IPV6_RECVPATHMTU 43 /* bool; notify an according MTU */
|
|
|
|
#define IPV6_PATHMTU 44 /* mtuinfo; get the current path MTU (sopt),
|
|
|
|
4 bytes int; MTU notification (cmsg) */
|
|
|
|
|
|
|
|
/* more new socket options introduced in RFC3542 */
|
|
|
|
#define IPV6_PKTINFO 46 /* in6_pktinfo; send if, src addr */
|
|
|
|
#define IPV6_HOPLIMIT 47 /* int; send hop limit */
|
|
|
|
#define IPV6_NEXTHOP 48 /* sockaddr; next hop addr */
|
|
|
|
#define IPV6_HOPOPTS 49 /* ip6_hbh; send hop-by-hop option */
|
|
|
|
#define IPV6_DSTOPTS 50 /* ip6_dest; send dst option befor rthdr */
|
|
|
|
#define IPV6_RTHDR 51 /* ip6_rthdr; send routing header */
|
|
|
|
|
|
|
|
#define IPV6_RECVTCLASS 57 /* bool; recv traffic class values */
|
|
|
|
#ifdef _KERNEL
|
|
|
|
#define IPV6_OTCLASS 58 /* u_int8_t; send traffic class value */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define IPV6_TCLASS 61 /* int; send traffic class value */
|
|
|
|
#define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */
|
2000-08-27 05:02:48 +04:00
|
|
|
/* to define items, should talk with KAME guys first, for *BSD compatibility */
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
#define IPV6_RTHDR_LOOSE 0 /* this hop need not be a neighbor. XXX old spec */
|
|
|
|
#define IPV6_RTHDR_STRICT 1 /* this hop must be a neighbor. XXX old spec */
|
|
|
|
#define IPV6_RTHDR_TYPE_0 0 /* IPv6 routing header type 0 */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Defaults and limits for options
|
|
|
|
*/
|
|
|
|
#define IPV6_DEFAULT_MULTICAST_HOPS 1 /* normally limit m'casts to 1 hop */
|
|
|
|
#define IPV6_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Argument structure for IPV6_JOIN_GROUP and IPV6_LEAVE_GROUP.
|
|
|
|
*/
|
|
|
|
struct ipv6_mreq {
|
|
|
|
struct in6_addr ipv6mr_multiaddr;
|
2000-06-08 23:01:44 +04:00
|
|
|
unsigned int ipv6mr_interface;
|
1999-06-28 10:36:47 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IPV6_PKTINFO: Packet information(RFC2292 sec 5)
|
|
|
|
*/
|
|
|
|
struct in6_pktinfo {
|
2000-06-08 23:01:44 +04:00
|
|
|
struct in6_addr ipi6_addr; /* src/dst IPv6 address */
|
|
|
|
unsigned int ipi6_ifindex; /* send/recv interface index */
|
1999-06-28 10:36:47 +04:00
|
|
|
};
|
|
|
|
|
2006-05-05 04:03:21 +04:00
|
|
|
/*
|
|
|
|
* Control structure for IPV6_RECVPATHMTU socket option.
|
|
|
|
*/
|
|
|
|
struct ip6_mtuinfo {
|
|
|
|
struct sockaddr_in6 ip6m_addr; /* or sockaddr_storage? */
|
2006-05-08 03:41:17 +04:00
|
|
|
uint32_t ip6m_mtu;
|
2006-05-05 04:03:21 +04:00
|
|
|
};
|
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
/*
|
|
|
|
* Argument for IPV6_PORTRANGE:
|
|
|
|
* - which range to search when port is unspecified at bind() or connect()
|
|
|
|
*/
|
|
|
|
#define IPV6_PORTRANGE_DEFAULT 0 /* default range */
|
|
|
|
#define IPV6_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */
|
|
|
|
#define IPV6_PORTRANGE_LOW 2 /* "low" - vouchsafe security */
|
|
|
|
|
Add a new feature-test macro, _NETBSD_SOURCE. If this is defined
by the application, all NetBSD interfaces are made visible, even
if some other feature-test macro (like _POSIX_C_SOURCE) is defined.
<sys/featuretest.h> defined _NETBSD_SOURCE if none of _ANSI_SOURCE,
_POSIX_C_SOURCE and _XOPEN_SOURCE is defined, so as to preserve
existing behaviour.
This has two major advantages:
+ Programs that require non-POSIX facilities but define _POSIX_C_SOURCE
can trivially be overruled by putting -D_NETBSD_SOURCE in their CFLAGS.
+ It makes most of the #ifs simpler, in that they're all now ORs of the
various macros, rather than having checks for (!defined(_ANSI_SOURCE) ||
!defined(_POSIX_C_SOURCE) || !defined(_XOPEN_SOURCE)) all over the place.
I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them. In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.
Tested by building for vax, encouraged by thorpej, and uncontested in
tech-userlevel for a week.
2003-04-29 03:16:11 +04:00
|
|
|
#if defined(_NETBSD_SOURCE)
|
1999-06-28 10:36:47 +04:00
|
|
|
/*
|
|
|
|
* Definitions for inet6 sysctl operations.
|
|
|
|
*
|
|
|
|
* Third level is protocol number.
|
|
|
|
* Fourth level is desired variable within that protocol.
|
|
|
|
*/
|
|
|
|
#define IPV6PROTO_MAXID (IPPROTO_PIM + 1) /* don't list to IPV6PROTO_MAX */
|
|
|
|
|
|
|
|
#define CTL_IPV6PROTO_NAMES { \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ "tcp6", CTLTYPE_NODE }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ "udp6", CTLTYPE_NODE }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ "ip6", CTLTYPE_NODE }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
1999-07-02 12:46:47 +04:00
|
|
|
{ "ipsec6", CTLTYPE_NODE }, \
|
1999-06-28 10:36:47 +04:00
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ "icmp6", CTLTYPE_NODE }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ "pim6", CTLTYPE_NODE }, \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Names for IP sysctl objects
|
|
|
|
*/
|
|
|
|
#define IPV6CTL_FORWARDING 1 /* act as router */
|
|
|
|
#define IPV6CTL_SENDREDIRECTS 2 /* may send redirects when forwarding*/
|
|
|
|
#define IPV6CTL_DEFHLIM 3 /* default Hop-Limit */
|
|
|
|
#ifdef notyet
|
|
|
|
#define IPV6CTL_DEFMTU 4 /* default MTU */
|
|
|
|
#endif
|
|
|
|
#define IPV6CTL_FORWSRCRT 5 /* forward source-routed dgrams */
|
|
|
|
#define IPV6CTL_STATS 6 /* stats */
|
|
|
|
#define IPV6CTL_MRTSTATS 7 /* multicast forwarding stats */
|
|
|
|
#define IPV6CTL_MRTPROTO 8 /* multicast routing protocol */
|
|
|
|
#define IPV6CTL_MAXFRAGPACKETS 9 /* max packets reassembly queue */
|
|
|
|
#define IPV6CTL_SOURCECHECK 10 /* verify source route and intf */
|
|
|
|
#define IPV6CTL_SOURCECHECK_LOGINT 11 /* minimume logging interval */
|
|
|
|
#define IPV6CTL_ACCEPT_RTADV 12
|
|
|
|
#define IPV6CTL_KEEPFAITH 13
|
|
|
|
#define IPV6CTL_LOG_INTERVAL 14
|
|
|
|
#define IPV6CTL_HDRNESTLIMIT 15
|
|
|
|
#define IPV6CTL_DAD_COUNT 16
|
1999-07-01 12:12:45 +04:00
|
|
|
#define IPV6CTL_AUTO_FLOWLABEL 17
|
|
|
|
#define IPV6CTL_DEFMCASTHLIM 18
|
|
|
|
#define IPV6CTL_GIF_HLIM 19 /* default HLIM for gif encap packet */
|
|
|
|
#define IPV6CTL_KAME_VERSION 20
|
1999-12-13 18:17:17 +03:00
|
|
|
#define IPV6CTL_USE_DEPRECATED 21 /* use deprecated addr (RFC2462 5.5.4) */
|
|
|
|
#define IPV6CTL_RR_PRUNE 22 /* walk timer for router renumbering */
|
2001-12-21 11:54:52 +03:00
|
|
|
/* 23: reserved */
|
2001-10-15 13:51:15 +04:00
|
|
|
#define IPV6CTL_V6ONLY 24
|
2000-08-26 15:03:45 +04:00
|
|
|
/* 25 to 27: reserved */
|
|
|
|
#define IPV6CTL_ANONPORTMIN 28 /* minimum ephemeral port */
|
|
|
|
#define IPV6CTL_ANONPORTMAX 29 /* maximum ephemeral port */
|
|
|
|
#define IPV6CTL_LOWPORTMIN 30 /* minimum reserved port */
|
|
|
|
#define IPV6CTL_LOWPORTMAX 31 /* maximum reserved port */
|
Better support of IPv6 scoped addresses.
- most of the kernel code will not care about the actual encoding of
scope zone IDs and won't touch "s6_addr16[1]" directly.
- similarly, most of the kernel code will not care about link-local
scoped addresses as a special case.
- scope boundary check will be stricter. For example, the current
*BSD code allows a packet with src=::1 and dst=(some global IPv6
address) to be sent outside of the node, if the application do:
s = socket(AF_INET6);
bind(s, "::1");
sendto(s, some_global_IPv6_addr);
This is clearly wrong, since ::1 is only meaningful within a single
node, but the current implementation of the *BSD kernel cannot
reject this attempt.
- and, while there, don't try to remove the ff02::/32 interface route
entry in in6_ifdetach() as it's already gone.
This also includes some level of support for the standard source
address selection algorithm defined in RFC3484, which will be
completed on in the future.
From the KAME project via JINMEI Tatuya.
Approved by core@.
2006-01-21 03:15:35 +03:00
|
|
|
/* 32 to 38: reserved */
|
|
|
|
#define IPV6CTL_USE_DEFAULTZONE 39 /* use default scope zone */
|
|
|
|
/* 40: reserved */
|
2002-05-28 07:04:05 +04:00
|
|
|
#define IPV6CTL_MAXFRAGS 41 /* max fragments */
|
2003-11-12 18:25:19 +03:00
|
|
|
#define IPV6CTL_IFQ 42 /* ip6intrq node */
|
1999-06-28 10:36:47 +04:00
|
|
|
/* New entries should be added here from current IPV6CTL_MAXID value. */
|
2000-08-26 15:03:45 +04:00
|
|
|
/* to define items, should talk with KAME guys first, for *BSD compatibility */
|
2003-11-12 18:25:19 +03:00
|
|
|
#define IPV6CTL_MAXID 43
|
1999-12-13 18:17:17 +03:00
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
#define IPV6CTL_NAMES { \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ "forwarding", CTLTYPE_INT }, \
|
|
|
|
{ "redirect", CTLTYPE_INT }, \
|
|
|
|
{ "hlim", CTLTYPE_INT }, \
|
|
|
|
{ "mtu", CTLTYPE_INT }, \
|
|
|
|
{ "forwsrcrt", CTLTYPE_INT }, \
|
2005-08-29 01:01:53 +04:00
|
|
|
{ "stats", CTLTYPE_STRUCT }, \
|
1999-06-28 10:36:47 +04:00
|
|
|
{ 0, 0 }, \
|
|
|
|
{ "mrtproto", CTLTYPE_INT }, \
|
|
|
|
{ "maxfragpackets", CTLTYPE_INT }, \
|
|
|
|
{ "sourcecheck", CTLTYPE_INT }, \
|
|
|
|
{ "sourcecheck_logint", CTLTYPE_INT }, \
|
|
|
|
{ "accept_rtadv", CTLTYPE_INT }, \
|
|
|
|
{ "keepfaith", CTLTYPE_INT }, \
|
|
|
|
{ "log_interval", CTLTYPE_INT }, \
|
|
|
|
{ "hdrnestlimit", CTLTYPE_INT }, \
|
|
|
|
{ "dad_count", CTLTYPE_INT }, \
|
|
|
|
{ "auto_flowlabel", CTLTYPE_INT }, \
|
|
|
|
{ "defmcasthlim", CTLTYPE_INT }, \
|
|
|
|
{ "gifhlim", CTLTYPE_INT }, \
|
|
|
|
{ "kame_version", CTLTYPE_STRING }, \
|
1999-12-13 18:17:17 +03:00
|
|
|
{ "use_deprecated", CTLTYPE_INT }, \
|
|
|
|
{ "rr_prune", CTLTYPE_INT }, \
|
2000-01-06 18:46:07 +03:00
|
|
|
{ 0, 0 }, \
|
2002-05-14 14:27:28 +04:00
|
|
|
{ "v6only", CTLTYPE_INT }, \
|
2000-08-26 15:03:45 +04:00
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ "anonportmin", CTLTYPE_INT }, \
|
|
|
|
{ "anonportmax", CTLTYPE_INT }, \
|
|
|
|
{ "lowportmin", CTLTYPE_INT }, \
|
|
|
|
{ "lowportmax", CTLTYPE_INT }, \
|
2002-05-28 07:04:05 +04:00
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ 0, 0 }, \
|
|
|
|
{ "maxfrags", CTLTYPE_INT }, \
|
2003-11-12 18:25:19 +03:00
|
|
|
{ "ifq", CTLTYPE_NODE }, \
|
1999-06-28 10:36:47 +04:00
|
|
|
}
|
|
|
|
|
Add a new feature-test macro, _NETBSD_SOURCE. If this is defined
by the application, all NetBSD interfaces are made visible, even
if some other feature-test macro (like _POSIX_C_SOURCE) is defined.
<sys/featuretest.h> defined _NETBSD_SOURCE if none of _ANSI_SOURCE,
_POSIX_C_SOURCE and _XOPEN_SOURCE is defined, so as to preserve
existing behaviour.
This has two major advantages:
+ Programs that require non-POSIX facilities but define _POSIX_C_SOURCE
can trivially be overruled by putting -D_NETBSD_SOURCE in their CFLAGS.
+ It makes most of the #ifs simpler, in that they're all now ORs of the
various macros, rather than having checks for (!defined(_ANSI_SOURCE) ||
!defined(_POSIX_C_SOURCE) || !defined(_XOPEN_SOURCE)) all over the place.
I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them. In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.
Tested by building for vax, encouraged by thorpej, and uncontested in
tech-userlevel for a week.
2003-04-29 03:16:11 +04:00
|
|
|
#endif /* _NETBSD_SOURCE */
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
#ifdef _KERNEL
|
|
|
|
struct cmsghdr;
|
|
|
|
|
2001-06-02 20:17:09 +04:00
|
|
|
/*
|
|
|
|
* in6_cksum_phdr:
|
|
|
|
*
|
|
|
|
* Compute significant parts of the IPv6 checksum pseudo-header
|
|
|
|
* for use in a delayed TCP/UDP checksum calculation.
|
|
|
|
*
|
|
|
|
* Args:
|
|
|
|
*
|
|
|
|
* src Source IPv6 address
|
|
|
|
* dst Destination IPv6 address
|
|
|
|
* len htonl(proto-hdr-len)
|
|
|
|
* nxt htonl(next-proto-number)
|
|
|
|
*
|
|
|
|
* NOTE: We expect the src and dst addresses to be 16-bit
|
|
|
|
* aligned!
|
|
|
|
*/
|
2007-12-25 21:33:32 +03:00
|
|
|
static __inline u_int16_t __unused
|
2001-06-02 20:17:09 +04:00
|
|
|
in6_cksum_phdr(const struct in6_addr *src, const struct in6_addr *dst,
|
|
|
|
u_int32_t len, u_int32_t nxt)
|
|
|
|
{
|
|
|
|
u_int32_t sum = 0;
|
|
|
|
const u_int16_t *w;
|
|
|
|
|
2001-11-17 21:55:11 +03:00
|
|
|
/*LINTED*/
|
|
|
|
w = (const u_int16_t *) src;
|
2001-06-02 20:17:09 +04:00
|
|
|
sum += w[0];
|
|
|
|
if (!IN6_IS_SCOPE_LINKLOCAL(src))
|
|
|
|
sum += w[1];
|
|
|
|
sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
|
2002-06-09 01:22:29 +04:00
|
|
|
sum += w[6]; sum += w[7];
|
2001-06-02 20:17:09 +04:00
|
|
|
|
2001-11-17 21:55:11 +03:00
|
|
|
/*LINTED*/
|
|
|
|
w = (const u_int16_t *) dst;
|
2001-06-02 20:17:09 +04:00
|
|
|
sum += w[0];
|
|
|
|
if (!IN6_IS_SCOPE_LINKLOCAL(dst))
|
|
|
|
sum += w[1];
|
|
|
|
sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
|
|
|
|
sum += w[6]; sum += w[7];
|
|
|
|
|
|
|
|
sum += (u_int16_t)(len >> 16) + (u_int16_t)(len /*& 0xffff*/);
|
|
|
|
|
|
|
|
sum += (u_int16_t)(nxt >> 16) + (u_int16_t)(nxt /*& 0xffff*/);
|
|
|
|
|
|
|
|
sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum /*& 0xffff*/);
|
|
|
|
|
|
|
|
if (sum > 0xffff)
|
|
|
|
sum -= 0xffff;
|
|
|
|
|
|
|
|
return (sum);
|
|
|
|
}
|
|
|
|
|
2005-12-20 22:32:58 +03:00
|
|
|
struct mbuf;
|
|
|
|
struct ifnet;
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
int sockaddr_in6_cmp(const struct sockaddr *, const struct sockaddr *);
|
Make ifconfig(8) set and display preference numbers for IPv6
addresses. Make the kernel support SIOC[SG]IFADDRPREF for IPv6
interface addresses.
In in6ifa_ifpforlinklocal(), consult preference numbers before
making an otherwise arbitrary choice of in6_ifaddr. Otherwise,
preference numbers are *not* consulted by the kernel, but that will
be rather easy for somebody with a little bit of free time to fix.
Please note that setting the preference number for a link-local
IPv6 address does not work right, yet, but that ought to be fixed
soon.
In support of the changes above,
1 Add a method to struct domain for "externalizing" a sockaddr, and
provide an implementation for IPv6. Expect more work in this area: it
may be more proper to say that the IPv6 implementation "internalizes"
a sockaddr. Add sockaddr_externalize().
2 Add a subroutine, sofamily(), that returns a struct socket's address
family or AF_UNSPEC.
3 Make a lot of IPv4-specific code generic, and move it from
sys/netinet/ to sys/net/ for re-use by IPv6 parts of the kernel and
ifconfig(8).
2009-09-12 02:06:29 +04:00
|
|
|
struct sockaddr *sockaddr_in6_externalize(struct sockaddr *, socklen_t,
|
|
|
|
const struct sockaddr *);
|
2007-10-24 10:37:20 +04:00
|
|
|
int in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t);
|
|
|
|
void in6_delayed_cksum(struct mbuf *);
|
|
|
|
int in6_localaddr(const struct in6_addr *);
|
|
|
|
int in6_addrscope(const struct in6_addr *);
|
|
|
|
struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *);
|
|
|
|
extern void in6_if_up(struct ifnet *);
|
Better support of IPv6 scoped addresses.
- most of the kernel code will not care about the actual encoding of
scope zone IDs and won't touch "s6_addr16[1]" directly.
- similarly, most of the kernel code will not care about link-local
scoped addresses as a special case.
- scope boundary check will be stricter. For example, the current
*BSD code allows a packet with src=::1 and dst=(some global IPv6
address) to be sent outside of the node, if the application do:
s = socket(AF_INET6);
bind(s, "::1");
sendto(s, some_global_IPv6_addr);
This is clearly wrong, since ::1 is only meaningful within a single
node, but the current implementation of the *BSD kernel cannot
reject this attempt.
- and, while there, don't try to remove the ff02::/32 interface route
entry in in6_ifdetach() as it's already gone.
This also includes some level of support for the standard source
address selection algorithm defined in RFC3484, which will be
completed on in the future.
From the KAME project via JINMEI Tatuya.
Approved by core@.
2006-01-21 03:15:35 +03:00
|
|
|
#ifndef __FreeBSD__
|
2007-10-24 10:37:20 +04:00
|
|
|
extern int in6_src_sysctl(void *, size_t *, void *, size_t);
|
Better support of IPv6 scoped addresses.
- most of the kernel code will not care about the actual encoding of
scope zone IDs and won't touch "s6_addr16[1]" directly.
- similarly, most of the kernel code will not care about link-local
scoped addresses as a special case.
- scope boundary check will be stricter. For example, the current
*BSD code allows a packet with src=::1 and dst=(some global IPv6
address) to be sent outside of the node, if the application do:
s = socket(AF_INET6);
bind(s, "::1");
sendto(s, some_global_IPv6_addr);
This is clearly wrong, since ::1 is only meaningful within a single
node, but the current implementation of the *BSD kernel cannot
reject this attempt.
- and, while there, don't try to remove the ff02::/32 interface route
entry in in6_ifdetach() as it's already gone.
This also includes some level of support for the standard source
address selection algorithm defined in RFC3484, which will be
completed on in the future.
From the KAME project via JINMEI Tatuya.
Approved by core@.
2006-01-21 03:15:35 +03:00
|
|
|
#endif
|
2007-10-24 10:37:20 +04:00
|
|
|
extern void addrsel_policy_init(void);
|
2000-02-17 13:59:32 +03:00
|
|
|
extern u_char ip6_protox[];
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
#define satosin6(sa) ((struct sockaddr_in6 *)(sa))
|
KNF: de-__P, bzero -> memset, bcmp -> memcmp. Remove extraneous
parentheses in return statements.
Cosmetic: don't open-code TAILQ_FOREACH().
Cosmetic: change types of variables to avoid oodles of casts: in
in6_src.c, avoid casts by changing several route_in6 pointers
to struct route pointers. Remove unnecessary casts to caddr_t
elsewhere.
Pave the way for eliminating address family-specific route caches:
soon, struct route will not embed a sockaddr, but it will hold
a reference to an external sockaddr, instead. We will set the
destination sockaddr using rtcache_setdst(). (I created a stub
for it, but it isn't used anywhere, yet.) rtcache_free() will
free the sockaddr. I have extracted from rtcache_free() a helper
subroutine, rtcache_clear(). rtcache_clear() will "forget" a
cached route, but it will not forget the destination by releasing
the sockaddr. I use rtcache_clear() instead of rtcache_free()
in rtcache_update(), because rtcache_update() is not supposed
to forget the destination.
Constify:
1 Introduce const accessor for route->ro_dst, rtcache_getdst().
2 Constify the 'dst' argument to ifnet->if_output(). This
led me to constify a lot of code called by output routines.
3 Constify the sockaddr argument to protosw->pr_ctlinput. This
led me to constify a lot of code called by ctlinput routines.
4 Introduce const macros for converting from a generic sockaddr
to family-specific sockaddrs, e.g., sockaddr_in: satocsin6,
satocsin, et cetera.
2007-02-18 01:34:07 +03:00
|
|
|
#define satocsin6(sa) ((const struct sockaddr_in6 *)(sa))
|
1999-06-28 10:36:47 +04:00
|
|
|
#define sin6tosa(sin6) ((struct sockaddr *)(sin6))
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
#define sin6tocsa(sin6) ((const struct sockaddr *)(sin6))
|
1999-06-28 10:36:47 +04:00
|
|
|
#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa))
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
|
|
|
|
static inline void
|
|
|
|
sockaddr_in6_init1(struct sockaddr_in6 *sin6, const struct in6_addr *addr,
|
|
|
|
in_port_t port, uint32_t flowinfo, uint32_t scope_id)
|
|
|
|
{
|
|
|
|
sin6->sin6_port = port;
|
|
|
|
sin6->sin6_flowinfo = flowinfo;
|
|
|
|
sin6->sin6_addr = *addr;
|
|
|
|
sin6->sin6_scope_id = scope_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
sockaddr_in6_init(struct sockaddr_in6 *sin6, const struct in6_addr *addr,
|
|
|
|
in_port_t port, uint32_t flowinfo, uint32_t scope_id)
|
|
|
|
{
|
|
|
|
sin6->sin6_family = AF_INET6;
|
|
|
|
sin6->sin6_len = sizeof(*sin6);
|
|
|
|
sockaddr_in6_init1(sin6, addr, port, flowinfo, scope_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct sockaddr *
|
|
|
|
sockaddr_in6_alloc(const struct in6_addr *addr, in_port_t port,
|
|
|
|
uint32_t flowinfo, uint32_t scope_id, int flags)
|
|
|
|
{
|
|
|
|
struct sockaddr *sa;
|
|
|
|
|
Use malloc(9) for sockaddrs instead of pool(9), and remove dom_sa_pool
and dom_sa_len members from struct domain. Pools of fixed-size
objects are too rigid for sockaddr_dls, whose size can vary over
a wide range.
Return sockaddr_dl to its "historical" size. Now that I'm using
malloc(9) instead of pool(9) to allocate sockaddr_dl, I can create
a sockaddr_dl of any size in the kernel, so expanding sockaddr_dl
is useless.
Avoid using sizeof(struct sockaddr_dl) in the kernel.
Introduce sockaddr_dl_alloc() for allocating & initializing an
arbitrary sockaddr_dl on the heap.
Add an argument, the sockaddr length, to sockaddr_alloc(),
sockaddr_copy(), and sockaddr_dl_setaddr().
Constify: LLADDR() -> CLLADDR().
Where the kernel overwrites LLADDR(), use sockaddr_dl_setaddr(),
instead. Used properly, sockaddr_dl_setaddr() will not overrun
the end of the sockaddr.
2007-08-30 06:17:34 +04:00
|
|
|
if ((sa = sockaddr_alloc(AF_INET6, sizeof(struct sockaddr_in6),
|
|
|
|
flags)) == NULL)
|
Eliminate address family-specific route caches (struct route, struct
route_in6, struct route_iso), replacing all caches with a struct
route.
The principle benefit of this change is that all of the protocol
families can benefit from route cache-invalidation, which is
necessary for correct routing. Route-cache invalidation fixes an
ancient PR, kern/3508, at long last; it fixes various other PRs,
also.
Discussions with and ideas from Joerg Sonnenberger influenced this
work tremendously. Of course, all design oversights and bugs are
mine.
DETAILS
1 I added to each address family a pool of sockaddrs. I have
introduced routines for allocating, copying, and duplicating,
and freeing sockaddrs:
struct sockaddr *sockaddr_alloc(sa_family_t af, int flags);
struct sockaddr *sockaddr_copy(struct sockaddr *dst,
const struct sockaddr *src);
struct sockaddr *sockaddr_dup(const struct sockaddr *src, int flags);
void sockaddr_free(struct sockaddr *sa);
sockaddr_alloc() returns either a sockaddr from the pool belonging
to the specified family, or NULL if the pool is exhausted. The
returned sockaddr has the right size for that family; sa_family
and sa_len fields are initialized to the family and sockaddr
length---e.g., sa_family = AF_INET and sa_len = sizeof(struct
sockaddr_in). sockaddr_free() puts the given sockaddr back into
its family's pool.
sockaddr_dup() and sockaddr_copy() work analogously to strdup()
and strcpy(), respectively. sockaddr_copy() KASSERTs that the
family of the destination and source sockaddrs are alike.
The 'flags' argumet for sockaddr_alloc() and sockaddr_dup() is
passed directly to pool_get(9).
2 I added routines for initializing sockaddrs in each address
family, sockaddr_in_init(), sockaddr_in6_init(), sockaddr_iso_init(),
etc. They are fairly self-explanatory.
3 structs route_in6 and route_iso are no more. All protocol families
use struct route. I have changed the route cache, 'struct route',
so that it does not contain storage space for a sockaddr. Instead,
struct route points to a sockaddr coming from the pool the sockaddr
belongs to. I added a new method to struct route, rtcache_setdst(),
for setting the cache destination:
int rtcache_setdst(struct route *, const struct sockaddr *);
rtcache_setdst() returns 0 on success, or ENOMEM if no memory is
available to create the sockaddr storage.
It is now possible for rtcache_getdst() to return NULL if, say,
rtcache_setdst() failed. I check the return value for NULL
everywhere in the kernel.
4 Each routing domain (struct domain) has a list of live route
caches, dom_rtcache. rtflushall(sa_family_t af) looks up the
domain indicated by 'af', walks the domain's list of route caches
and invalidates each one.
2007-05-03 00:40:22 +04:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sockaddr_in6_init1(satosin6(sa), addr, port, flowinfo, scope_id);
|
|
|
|
|
|
|
|
return sa;
|
|
|
|
}
|
1999-06-28 10:36:47 +04:00
|
|
|
#endif /* _KERNEL */
|
|
|
|
|
Add a new feature-test macro, _NETBSD_SOURCE. If this is defined
by the application, all NetBSD interfaces are made visible, even
if some other feature-test macro (like _POSIX_C_SOURCE) is defined.
<sys/featuretest.h> defined _NETBSD_SOURCE if none of _ANSI_SOURCE,
_POSIX_C_SOURCE and _XOPEN_SOURCE is defined, so as to preserve
existing behaviour.
This has two major advantages:
+ Programs that require non-POSIX facilities but define _POSIX_C_SOURCE
can trivially be overruled by putting -D_NETBSD_SOURCE in their CFLAGS.
+ It makes most of the #ifs simpler, in that they're all now ORs of the
various macros, rather than having checks for (!defined(_ANSI_SOURCE) ||
!defined(_POSIX_C_SOURCE) || !defined(_XOPEN_SOURCE)) all over the place.
I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them. In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.
Tested by building for vax, encouraged by thorpej, and uncontested in
tech-userlevel for a week.
2003-04-29 03:16:11 +04:00
|
|
|
#if defined(_NETBSD_SOURCE)
|
2002-05-13 19:20:30 +04:00
|
|
|
|
|
|
|
#include <machine/ansi.h>
|
|
|
|
|
|
|
|
#ifdef _BSD_SIZE_T_
|
|
|
|
typedef _BSD_SIZE_T_ size_t;
|
|
|
|
#define _SIZE_T
|
|
|
|
#undef _BSD_SIZE_T_
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
1999-06-28 10:36:47 +04:00
|
|
|
__BEGIN_DECLS
|
|
|
|
struct cmsghdr;
|
|
|
|
|
2007-11-01 23:33:56 +03:00
|
|
|
void in6_sin6_2_sin(struct sockaddr_in *, struct sockaddr_in6 *);
|
|
|
|
void in6_sin_2_v4mapsin6(struct sockaddr_in *, struct sockaddr_in6 *);
|
|
|
|
void in6_sin6_2_sin_in_sock(struct sockaddr *);
|
|
|
|
void in6_sin_2_v4mapsin6_in_sock(struct sockaddr **);
|
|
|
|
|
|
|
|
extern int inet6_option_space(int);
|
|
|
|
extern int inet6_option_init(void *, struct cmsghdr **, int);
|
|
|
|
extern int inet6_option_append(struct cmsghdr *, const uint8_t *,
|
|
|
|
int, int);
|
|
|
|
extern uint8_t *inet6_option_alloc(struct cmsghdr *, int, int, int);
|
|
|
|
extern int inet6_option_next(const struct cmsghdr *, uint8_t **);
|
|
|
|
extern int inet6_option_find(const struct cmsghdr *, uint8_t **, int);
|
|
|
|
|
|
|
|
extern size_t inet6_rthdr_space(int, int);
|
|
|
|
extern struct cmsghdr *inet6_rthdr_init(void *, int);
|
|
|
|
extern int inet6_rthdr_add(struct cmsghdr *, const struct in6_addr *,
|
|
|
|
unsigned int);
|
|
|
|
extern int inet6_rthdr_lasthop(struct cmsghdr *, unsigned int);
|
1999-06-28 10:36:47 +04:00
|
|
|
#if 0 /* not implemented yet */
|
2007-11-01 23:33:56 +03:00
|
|
|
extern int inet6_rthdr_reverse(const struct cmsghdr *, struct cmsghdr *);
|
1999-06-28 10:36:47 +04:00
|
|
|
#endif
|
2007-11-01 23:33:56 +03:00
|
|
|
extern int inet6_rthdr_segments(const struct cmsghdr *);
|
|
|
|
extern struct in6_addr *inet6_rthdr_getaddr(struct cmsghdr *, int);
|
|
|
|
extern int inet6_rthdr_getflags(const struct cmsghdr *, int);
|
|
|
|
|
|
|
|
extern int inet6_opt_init(void *, socklen_t);
|
|
|
|
extern int inet6_opt_append(void *, socklen_t, int, uint8_t,
|
|
|
|
socklen_t, uint8_t, void **);
|
|
|
|
extern int inet6_opt_finish(void *, socklen_t, int);
|
|
|
|
extern int inet6_opt_set_val(void *, int, void *, socklen_t);
|
|
|
|
|
|
|
|
extern int inet6_opt_next(void *, socklen_t, int, uint8_t *,
|
|
|
|
socklen_t *, void **);
|
|
|
|
extern int inet6_opt_find(void *, socklen_t, int, uint8_t,
|
|
|
|
socklen_t *, void **);
|
|
|
|
extern int inet6_opt_get_val(void *, int, void *, socklen_t);
|
|
|
|
extern socklen_t inet6_rth_space(int, int);
|
|
|
|
extern void *inet6_rth_init(void *, socklen_t, int, int);
|
|
|
|
extern int inet6_rth_add(void *, const struct in6_addr *);
|
|
|
|
extern int inet6_rth_reverse(const void *, void *);
|
|
|
|
extern int inet6_rth_segments(const void *);
|
|
|
|
extern struct in6_addr *inet6_rth_getaddr(const void *, int);
|
1999-06-28 10:36:47 +04:00
|
|
|
__END_DECLS
|
Add a new feature-test macro, _NETBSD_SOURCE. If this is defined
by the application, all NetBSD interfaces are made visible, even
if some other feature-test macro (like _POSIX_C_SOURCE) is defined.
<sys/featuretest.h> defined _NETBSD_SOURCE if none of _ANSI_SOURCE,
_POSIX_C_SOURCE and _XOPEN_SOURCE is defined, so as to preserve
existing behaviour.
This has two major advantages:
+ Programs that require non-POSIX facilities but define _POSIX_C_SOURCE
can trivially be overruled by putting -D_NETBSD_SOURCE in their CFLAGS.
+ It makes most of the #ifs simpler, in that they're all now ORs of the
various macros, rather than having checks for (!defined(_ANSI_SOURCE) ||
!defined(_POSIX_C_SOURCE) || !defined(_XOPEN_SOURCE)) all over the place.
I've tried not to change the semantics of the headers in any case where
_NETBSD_SOURCE wasn't defined, but there were some places where the
current semantics were clearly mad, and retaining them was harder than
correcting them. In particular, I've mostly normalised things so that
_ANSI_SOURCE gets you the smallest set of stuff, then _POSIX_C_SOURCE,
_XOPEN_SOURCE and _NETBSD_SOURCE in that order.
Tested by building for vax, encouraged by thorpej, and uncontested in
tech-userlevel for a week.
2003-04-29 03:16:11 +04:00
|
|
|
#endif /* _NETBSD_SOURCE */
|
1999-06-28 10:36:47 +04:00
|
|
|
|
|
|
|
#endif /* !_NETINET6_IN6_H_ */
|