#ifndef _NETINET6_IN6_H_
#define _NETINET6_IN6_H_
#include <sys/featuretest.h>
#ifndef __KAME_NETINET_IN_H_INCLUDED_
#error "do not include netinet6/in6.h directly, include netinet/in.h. see RFC2553"
#endif
#include <sys/socket.h>
#include <sys/endian.h>
#define __KAME__
#define __KAME_VERSION "NetBSD-current"
#if defined(_NETBSD_SOURCE)
#define IPV6PORT_RESERVED 1024
#define IPV6PORT_ANONMIN 49152
#define IPV6PORT_ANONMAX 65535
#define IPV6PORT_RESERVEDMIN 600
#define IPV6PORT_RESERVEDMAX (IPV6PORT_RESERVED-1)
#endif
struct in6_addr {
union {
__uint8_t __u6_addr8[16];
__uint16_t __u6_addr16[8];
uint32_t __u6_addr32[4];
} __u6_addr;
};
#define s6_addr __u6_addr.__u6_addr8
#ifdef _KERNEL
#define s6_addr8 __u6_addr.__u6_addr8
#define s6_addr16 __u6_addr.__u6_addr16
#define s6_addr32 __u6_addr.__u6_addr32
#endif
#define INET6_ADDRSTRLEN 46
#if defined(_NETBSD_SOURCE)
#define SIN6_LEN
#endif
struct sockaddr_in6 {
uint8_t sin6_len;
sa_family_t sin6_family;
in_port_t sin6_port;
uint32_t sin6_flowinfo;
struct in6_addr sin6_addr;
uint32_t sin6_scope_id;
};
#ifdef _KERNEL
#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
#ifdef _KERNEL
extern const struct sockaddr_in6 sa6_any;
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
#ifdef _KERNEL
#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
#endif
#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 }}}
#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
{{{ 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
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) \
(memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
#define IN6_IS_ADDR_UNSPECIFIED(a) \
((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)
#define IN6_IS_ADDR_LOOPBACK(a) \
((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))
#define IN6_IS_ADDR_V4COMPAT(a) \
((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))
#define IN6_IS_ADDR_V4MAPPED(a) \
((a)->__u6_addr.__u6_addr32[0] == 0 && \
(a)->__u6_addr.__u6_addr32[1] == 0 && \
(a)->__u6_addr.__u6_addr32[2] == ntohl(0x0000ffff))
#ifdef _KERNEL
#define IPV6_ADDR_SCOPE_NODELOCAL 0x01
#define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01
#define IPV6_ADDR_SCOPE_LINKLOCAL 0x02
#define IPV6_ADDR_SCOPE_SITELOCAL 0x05
#define IPV6_ADDR_SCOPE_ORGLOCAL 0x08
#define IPV6_ADDR_SCOPE_GLOBAL 0x0e
#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
#define __IPV6_ADDR_SCOPE_GLOBAL 0x0e
#endif
#define IN6_IS_ADDR_LINKLOCAL(a) \
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
#define IN6_IS_ADDR_SITELOCAL(a) \
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
#ifdef _KERNEL
#define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
#else
#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
#endif
#ifdef _KERNEL
#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_INTFACELOCAL(a) \
(IN6_IS_ADDR_MULTICAST(a) && \
(IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL))
#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))
#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
#ifdef _KERNEL
#define IN6_IS_SCOPE_LINKLOCAL(a) \
((IN6_IS_ADDR_LINKLOCAL(a)) || \
(IN6_IS_ADDR_MC_LINKLOCAL(a)))
#define IN6_IS_SCOPE_EMBEDDABLE(__a) \
(IN6_IS_SCOPE_LINKLOCAL(__a) || IN6_IS_ADDR_MC_INTFACELOCAL(__a))
#define IFA6_IS_DEPRECATED(a) \
((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
(u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
(a)->ia6_lifetime.ia6t_pltime)
#define IFA6_IS_INVALID(a) \
((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \
(u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
(a)->ia6_lifetime.ia6t_vltime)
#endif
#if 0
#define IPV6_OPTIONS 1
#define IPV6_RECVOPTS 5
#define IPV6_RECVRETOPTS 6
#define IPV6_RECVDSTADDR 7
#define IPV6_RETOPTS 8
#endif
#define IPV6_SOCKOPT_RESERVED1 3
#define IPV6_UNICAST_HOPS 4
#define IPV6_MULTICAST_IF 9
#define IPV6_MULTICAST_HOPS 10
#define IPV6_MULTICAST_LOOP 11
#define IPV6_JOIN_GROUP 12
#define IPV6_LEAVE_GROUP 13
#define IPV6_PORTRANGE 14
#if defined(_NETBSD_SOURCE)
#define IPV6_PORTALGO 17
#define ICMP6_FILTER 18
#endif
#ifdef _KERNEL
#define IPV6_2292PKTINFO 19
#define IPV6_2292HOPLIMIT 20
#define IPV6_2292NEXTHOP 21
#define IPV6_2292HOPOPTS 22
#define IPV6_2292DSTOPTS 23
#define IPV6_2292RTHDR 24
#define IPV6_2292PKTOPTIONS 25
#endif
#define IPV6_CHECKSUM 26
#define IPV6_V6ONLY 27
#define IPV6_IPSEC_POLICY 28
#define IPV6_FAITH 29
#define IPV6_RTHDRDSTOPTS 35
#define IPV6_RECVPKTINFO 36
#define IPV6_RECVHOPLIMIT 37
#define IPV6_RECVRTHDR 38
#define IPV6_RECVHOPOPTS 39
#define IPV6_RECVDSTOPTS 40
#ifdef _KERNEL
#define IPV6_RECVRTHDRDSTOPTS 41
#endif
#define IPV6_USE_MIN_MTU 42
#define IPV6_RECVPATHMTU 43
#define IPV6_PATHMTU 44
#define IPV6_PKTINFO 46
#define IPV6_HOPLIMIT 47
#define IPV6_NEXTHOP 48
#define IPV6_HOPOPTS 49
#define IPV6_DSTOPTS 50
#define IPV6_RTHDR 51
#define IPV6_RECVTCLASS 57
#ifdef _KERNEL
#define IPV6_OTCLASS 58
#endif
#define IPV6_TCLASS 61
#define IPV6_DONTFRAG 62
#define IPV6_PREFER_TEMPADDR 63
#define IPV6_BINDANY 64
#define IPV6_RTHDR_LOOSE 0
#define IPV6_RTHDR_STRICT 1
#define IPV6_RTHDR_TYPE_0 0
#define IPV6_DEFAULT_MULTICAST_HOPS 1
#define IPV6_DEFAULT_MULTICAST_LOOP 1
struct ipv6_mreq {
struct in6_addr ipv6mr_multiaddr;
unsigned int ipv6mr_interface;
};
struct in6_pktinfo {
struct in6_addr ipi6_addr;
unsigned int ipi6_ifindex;
};
struct ip6_mtuinfo {
struct sockaddr_in6 ip6m_addr;
uint32_t ip6m_mtu;
};
#define IPV6_PORTRANGE_DEFAULT 0
#define IPV6_PORTRANGE_HIGH 1
#define IPV6_PORTRANGE_LOW 2
#if defined(_NETBSD_SOURCE)
#define IPV6CTL_FORWARDING 1
#define IPV6CTL_SENDREDIRECTS 2
#define IPV6CTL_DEFHLIM 3
#define IPV6CTL_FORWSRCRT 5
#define IPV6CTL_STATS 6
#define IPV6CTL_MRTSTATS 7
#define IPV6CTL_MRTPROTO 8
#define IPV6CTL_MAXFRAGPACKETS 9
#define IPV6CTL_SOURCECHECK 10
#define IPV6CTL_SOURCECHECK_LOGINT 11
#define IPV6CTL_KEEPFAITH 13
#define IPV6CTL_LOG_INTERVAL 14
#define IPV6CTL_HDRNESTLIMIT 15
#define IPV6CTL_DAD_COUNT 16
#define IPV6CTL_AUTO_FLOWLABEL 17
#define IPV6CTL_DEFMCASTHLIM 18
#define IPV6CTL_GIF_HLIM 19
#define IPV6CTL_KAME_VERSION 20
#define IPV6CTL_USE_DEPRECATED 21
#define IPV6CTL_V6ONLY 24
#define IPV6CTL_ANONPORTMIN 28
#define IPV6CTL_ANONPORTMAX 29
#define IPV6CTL_LOWPORTMIN 30
#define IPV6CTL_LOWPORTMAX 31
#define IPV6CTL_AUTO_LINKLOCAL 35
#define IPV6CTL_ADDRCTLPOLICY 38
#define IPV6CTL_USE_DEFAULTZONE 39
#define IPV6CTL_MAXFRAGS 41
#define IPV6CTL_IFQ 42
#define IPV6CTL_GIF_PMTU 45
#define IPV6CTL_IPSEC_HLIM 46
#define IPV6CTL_IPSEC_PMTU 47
#endif
#ifdef _KERNEL
struct cmsghdr;
static __inline u_int16_t __unused
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;
w = (const u_int16_t *) src;
sum += w[0];
if (!IN6_IS_SCOPE_LINKLOCAL(src))
sum += w[1];
sum += w[2]; sum += w[3]; sum += w[4]; sum += w[5];
sum += w[6]; sum += w[7];
w = (const u_int16_t *) dst;
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 );
sum += (u_int16_t)(nxt >> 16) + (u_int16_t)(nxt );
sum = (u_int16_t)(sum >> 16) + (u_int16_t)(sum );
if (sum > 0xffff)
sum -= 0xffff;
return (sum);
}
struct mbuf;
struct ifnet;
int sockaddr_in6_cmp(const struct sockaddr *, const struct sockaddr *);
struct sockaddr *sockaddr_in6_externalize(struct sockaddr *, socklen_t,
const struct sockaddr *);
int in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t);
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_link_up(struct ifnet *);
extern void in6_if_link_down(struct ifnet *);
extern void in6_if_link_state_change(struct ifnet *, int);
extern void in6_if_up(struct ifnet *);
extern void in6_if_down(struct ifnet *);
extern void addrsel_policy_init(void);
extern u_char ip6_protox[];
struct ip6_hdr;
int in6_tunnel_validate(const struct ip6_hdr *, const struct in6_addr *,
const struct in6_addr *);
#define satosin6(sa) ((struct sockaddr_in6 *)(sa))
#define satocsin6(sa) ((const struct sockaddr_in6 *)(sa))
#define sin6tosa(sin6) ((struct sockaddr *)(sin6))
#define sin6tocsa(sin6) ((const struct sockaddr *)(sin6))
#define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa))
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;
if ((sa = sockaddr_alloc(AF_INET6, sizeof(struct sockaddr_in6),
flags)) == NULL)
return NULL;
sockaddr_in6_init1(satosin6(sa), addr, port, flowinfo, scope_id);
return sa;
}
#endif
#if defined(_NETBSD_SOURCE)
#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>
__BEGIN_DECLS
struct cmsghdr;
void in6_in_2_v4mapin6(const struct in_addr *, struct in6_addr *);
void in6_sin6_2_sin(struct sockaddr_in *, struct sockaddr_in6 *);
void in6_sin_2_v4mapsin6(const struct sockaddr_in *, struct sockaddr_in6 *);
void in6_sin6_2_sin_in_sock(struct sockaddr *);
void in6_sin_2_v4mapsin6_in_sock(struct sockaddr **);
#define INET6_IS_ADDR_LINKLOCAL 1
#define INET6_IS_ADDR_MC_LINKLOCAL 2
#define INET6_IS_ADDR_SITELOCAL 4
void inet6_getscopeid(struct sockaddr_in6 *, int);
void inet6_putscopeid(struct sockaddr_in6 *, int);
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);
#if 0
extern int inet6_rthdr_reverse(const struct cmsghdr *, struct cmsghdr *);
#endif
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);
__END_DECLS
#endif
#if defined(_KERNEL) || defined(_TEST)
int in6_print(char *, size_t, const struct in6_addr *);
#define IN6_PRINT(b, a) (in6_print((b), sizeof(b), (a)), (b))
int sin6_print(char *, size_t, const void *);
#endif
#endif