1/*	$NetBSD$	*/
2
3/*
4 * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2002  Internet Software Consortium.
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19
20/* Id: ipv6.h,v 1.24 2007/06/19 23:47:18 tbox Exp */
21
22#ifndef ISC_IPV6_H
23#define ISC_IPV6_H 1
24
25/*!
26 * Also define LWRES_IPV6_H to keep it from being included if liblwres is
27 * being used, or redefinition errors will occur.
28 */
29#define LWRES_IPV6_H 1
30
31/*****
32 ***** Module Info
33 *****/
34
35/*! \file isc/ipv6.h
36 * \brief IPv6 definitions for systems which do not support IPv6.
37 *
38 * \li MP:
39 *	No impact.
40 *
41 * \li Reliability:
42 *	No anticipated impact.
43 *
44 * \li Resources:
45 *	N/A.
46 *
47 * \li Security:
48 *	No anticipated impact.
49 *
50 * \li Standards:
51 *	RFC2553.
52 */
53
54/***
55 *** Imports.
56 ***/
57
58#include <isc/int.h>
59#include <isc/platform.h>
60
61/***
62 *** Types.
63 ***/
64
65struct in6_addr {
66        union {
67		isc_uint8_t	_S6_u8[16];
68		isc_uint16_t	_S6_u16[8];
69		isc_uint32_t	_S6_u32[4];
70        } _S6_un;
71};
72#define s6_addr		_S6_un._S6_u8
73#define s6_addr8	_S6_un._S6_u8
74#define s6_addr16	_S6_un._S6_u16
75#define s6_addr32	_S6_un._S6_u32
76
77#define IN6ADDR_ANY_INIT 	{{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
78#define IN6ADDR_LOOPBACK_INIT 	{{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
79
80LIBISC_EXTERNAL_DATA extern const struct in6_addr in6addr_any;
81LIBISC_EXTERNAL_DATA extern const struct in6_addr in6addr_loopback;
82
83struct sockaddr_in6 {
84#ifdef ISC_PLATFORM_HAVESALEN
85	isc_uint8_t		sin6_len;
86	isc_uint8_t		sin6_family;
87#else
88	isc_uint16_t		sin6_family;
89#endif
90	isc_uint16_t		sin6_port;
91	isc_uint32_t		sin6_flowinfo;
92	struct in6_addr		sin6_addr;
93	isc_uint32_t		sin6_scope_id;
94};
95
96#ifdef ISC_PLATFORM_HAVESALEN
97#define SIN6_LEN 1
98#endif
99
100/*%
101 * Unspecified
102 */
103#define IN6_IS_ADDR_UNSPECIFIED(a)      \
104        (((a)->s6_addr32[0] == 0) &&    \
105         ((a)->s6_addr32[1] == 0) &&    \
106         ((a)->s6_addr32[2] == 0) &&    \
107         ((a)->s6_addr32[3] == 0))
108
109/*%
110 * Loopback
111 */
112#define IN6_IS_ADDR_LOOPBACK(a)         \
113        (((a)->s6_addr32[0] == 0) &&    \
114         ((a)->s6_addr32[1] == 0) &&    \
115         ((a)->s6_addr32[2] == 0) &&    \
116         ((a)->s6_addr32[3] == htonl(1)))
117
118/*%
119 * IPv4 compatible
120 */
121#define IN6_IS_ADDR_V4COMPAT(a)         \
122        (((a)->s6_addr32[0] == 0) &&    \
123         ((a)->s6_addr32[1] == 0) &&    \
124         ((a)->s6_addr32[2] == 0) &&    \
125         ((a)->s6_addr32[3] != 0) &&    \
126         ((a)->s6_addr32[3] != htonl(1)))
127
128/*%
129 * Mapped
130 */
131#define IN6_IS_ADDR_V4MAPPED(a)               \
132        (((a)->s6_addr32[0] == 0) &&          \
133         ((a)->s6_addr32[1] == 0) &&          \
134         ((a)->s6_addr32[2] == htonl(0x0000ffff)))
135
136/*%
137 * Multicast
138 */
139#define IN6_IS_ADDR_MULTICAST(a)	\
140	((a)->s6_addr8[0] == 0xffU)
141
142/*%
143 * Unicast link / site local.
144 */
145#define IN6_IS_ADDR_LINKLOCAL(a)	\
146	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
147#define IN6_IS_ADDR_SITELOCAL(a)	\
148	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
149
150#endif /* ISC_IPV6_H */
151