1 /*
2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7  *
8  * See the COPYRIGHT file distributed with this work for additional
9  * information regarding copyright ownership.
10  */
11 
12 #ifndef ISC_IPV6_H
13 #define ISC_IPV6_H 1
14 
15 /*!
16  * Also define LWRES_IPV6_H to keep it from being included if liblwres is
17  * being used, or redefinition errors will occur.
18  */
19 #define LWRES_IPV6_H 1
20 
21 /*****
22  ***** Module Info
23  *****/
24 
25 /*! \file isc/ipv6.h
26  * \brief IPv6 definitions for systems which do not support IPv6.
27  *
28  * \li MP:
29  *	No impact.
30  *
31  * \li Reliability:
32  *	No anticipated impact.
33  *
34  * \li Resources:
35  *	N/A.
36  *
37  * \li Security:
38  *	No anticipated impact.
39  *
40  * \li Standards:
41  *	RFC2553.
42  */
43 
44 /***
45  *** Imports.
46  ***/
47 
48 #include <inttypes.h>
49 #include <isc/platform.h>
50 
51 /***
52  *** Types.
53  ***/
54 
55 struct in6_addr {
56 	union {
57 		uint8_t	_S6_u8[16];
58 		uint16_t	_S6_u16[8];
59 		uint32_t	_S6_u32[4];
60 	} _S6_un;
61 };
62 #define s6_addr		_S6_un._S6_u8
63 #define s6_addr8	_S6_un._S6_u8
64 #define s6_addr16	_S6_un._S6_u16
65 #define s6_addr32	_S6_un._S6_u32
66 
67 #define IN6ADDR_ANY_INIT 	{{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}}
68 #define IN6ADDR_LOOPBACK_INIT 	{{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }}}
69 
70 LIBISC_EXTERNAL_DATA extern const struct in6_addr in6addr_any;
71 LIBISC_EXTERNAL_DATA extern const struct in6_addr in6addr_loopback;
72 
73 struct sockaddr_in6 {
74 #ifdef ISC_PLATFORM_HAVESALEN
75 	uint8_t		sin6_len;
76 	uint8_t		sin6_family;
77 #else
78 	uint16_t		sin6_family;
79 #endif
80 	uint16_t		sin6_port;
81 	uint32_t		sin6_flowinfo;
82 	struct in6_addr		sin6_addr;
83 	uint32_t		sin6_scope_id;
84 };
85 
86 #ifdef ISC_PLATFORM_HAVESALEN
87 #define SIN6_LEN 1
88 #endif
89 
90 /*%
91  * Unspecified
92  */
93 #define IN6_IS_ADDR_UNSPECIFIED(a)      \
94 	(((a)->s6_addr32[0] == 0) &&    \
95 	 ((a)->s6_addr32[1] == 0) &&    \
96 	 ((a)->s6_addr32[2] == 0) &&    \
97 	 ((a)->s6_addr32[3] == 0))
98 
99 /*%
100  * Loopback
101  */
102 #define IN6_IS_ADDR_LOOPBACK(a)         \
103 	(((a)->s6_addr32[0] == 0) &&    \
104 	 ((a)->s6_addr32[1] == 0) &&    \
105 	 ((a)->s6_addr32[2] == 0) &&    \
106 	 ((a)->s6_addr32[3] == htonl(1)))
107 
108 /*%
109  * IPv4 compatible
110  */
111 #define IN6_IS_ADDR_V4COMPAT(a)         \
112 	(((a)->s6_addr32[0] == 0) &&    \
113 	 ((a)->s6_addr32[1] == 0) &&    \
114 	 ((a)->s6_addr32[2] == 0) &&    \
115 	 ((a)->s6_addr32[3] != 0) &&    \
116 	 ((a)->s6_addr32[3] != htonl(1)))
117 
118 /*%
119  * Mapped
120  */
121 #define IN6_IS_ADDR_V4MAPPED(a)               \
122 	(((a)->s6_addr32[0] == 0) &&          \
123 	 ((a)->s6_addr32[1] == 0) &&          \
124 	 ((a)->s6_addr32[2] == htonl(0x0000ffff)))
125 
126 /*%
127  * Multicast
128  */
129 #define IN6_IS_ADDR_MULTICAST(a)	\
130 	((a)->s6_addr8[0] == 0xffU)
131 
132 /*%
133  * Unicast link / site local.
134  */
135 #define IN6_IS_ADDR_LINKLOCAL(a)	\
136 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
137 #define IN6_IS_ADDR_SITELOCAL(a)	\
138 	(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
139 
140 #endif /* ISC_IPV6_H */
141