RTEMS  5.1
_kernel_in6.h
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 #if !defined(_NETINET6_IN6_H_) || !defined(_KERNEL)
35 #error "must be included via <netinet6/in6.h> in kernel space"
36 #endif
37 
38 /* XXX nonstandard */
39 #define s6_addr8 __u6_addr.__u6_addr8
40 #define s6_addr16 __u6_addr.__u6_addr16
41 #define s6_addr32 __u6_addr.__u6_addr32
42 
43 /*
44  * Local definition for masks
45  */
46 /* XXX nonstandard */
47 #define IN6MASK0 {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}}
48 #define IN6MASK32 {{{ 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, \
49  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
50 #define IN6MASK64 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
51  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
52 #define IN6MASK96 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
53  0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 }}}
54 #define IN6MASK128 {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
55  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}}
56 
57 extern const struct sockaddr_in6 sa6_any;
58 
59 extern const struct in6_addr in6mask0;
60 extern const struct in6_addr in6mask32;
61 extern const struct in6_addr in6mask64;
62 extern const struct in6_addr in6mask96;
63 extern const struct in6_addr in6mask128;
64 
65 /*
66  * Macros started with IPV6_ADDR is KAME local
67  */
68 /* XXX nonstandard */
69 #if _BYTE_ORDER == _BIG_ENDIAN
70 #define IPV6_ADDR_INT32_ONE 1
71 #define IPV6_ADDR_INT32_TWO 2
72 #define IPV6_ADDR_INT32_MNL 0xff010000
73 #define IPV6_ADDR_INT32_MLL 0xff020000
74 #define IPV6_ADDR_INT32_SMP 0x0000ffff
75 #define IPV6_ADDR_INT16_ULL 0xfe80
76 #define IPV6_ADDR_INT16_USL 0xfec0
77 #define IPV6_ADDR_INT16_MLL 0xff02
78 #elif _BYTE_ORDER == _LITTLE_ENDIAN
79 #define IPV6_ADDR_INT32_ONE 0x01000000
80 #define IPV6_ADDR_INT32_TWO 0x02000000
81 #define IPV6_ADDR_INT32_MNL 0x000001ff
82 #define IPV6_ADDR_INT32_MLL 0x000002ff
83 #define IPV6_ADDR_INT32_SMP 0xffff0000
84 #define IPV6_ADDR_INT16_ULL 0x80fe
85 #define IPV6_ADDR_INT16_USL 0xc0fe
86 #define IPV6_ADDR_INT16_MLL 0x02ff
87 #endif
88 
89 /* XXX nonstandard */
90 #define IPV6_ADDR_SCOPE_NODELOCAL 0x01
91 #define IPV6_ADDR_SCOPE_INTFACELOCAL 0x01
92 #define IPV6_ADDR_SCOPE_LINKLOCAL 0x02
93 #define IPV6_ADDR_SCOPE_SITELOCAL 0x05
94 #define IPV6_ADDR_SCOPE_ORGLOCAL 0x08 /* just used in this file */
95 #define IPV6_ADDR_SCOPE_GLOBAL 0x0e
96 
97 #define IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
98 
99 /* refers nonstandard items */
100 #define IN6_IS_ADDR_MC_NODELOCAL(a) \
101  (IN6_IS_ADDR_MULTICAST(a) && \
102  (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_NODELOCAL))
103 #define IN6_IS_ADDR_MC_INTFACELOCAL(a) \
104  (IN6_IS_ADDR_MULTICAST(a) && \
105  (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_INTFACELOCAL))
106 #define IN6_IS_ADDR_MC_LINKLOCAL(a) \
107  (IN6_IS_ADDR_MULTICAST(a) && \
108  (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_LINKLOCAL))
109 #define IN6_IS_ADDR_MC_SITELOCAL(a) \
110  (IN6_IS_ADDR_MULTICAST(a) && \
111  (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_SITELOCAL))
112 #define IN6_IS_ADDR_MC_ORGLOCAL(a) \
113  (IN6_IS_ADDR_MULTICAST(a) && \
114  (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_ORGLOCAL))
115 #define IN6_IS_ADDR_MC_GLOBAL(a) \
116  (IN6_IS_ADDR_MULTICAST(a) && \
117  (IPV6_ADDR_MC_SCOPE(a) == IPV6_ADDR_SCOPE_GLOBAL))
118 
119 /* nonstandard */
120 /*
121  * KAME Scope
122  */
123 #define IN6_IS_SCOPE_LINKLOCAL(a) \
124  ((IN6_IS_ADDR_LINKLOCAL(a)) || \
125  (IN6_IS_ADDR_MC_LINKLOCAL(a)))
126 #define IN6_IS_SCOPE_EMBED(a) \
127  ((IN6_IS_ADDR_LINKLOCAL(a)) || \
128  (IN6_IS_ADDR_MC_LINKLOCAL(a)) || \
129  (IN6_IS_ADDR_MC_INTFACELOCAL(a)))
130 
131 #define IFA6_IS_DEPRECATED(a) \
132  ((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
133  (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
134  (a)->ia6_lifetime.ia6t_pltime)
135 #define IFA6_IS_INVALID(a) \
136  ((a)->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME && \
137  (u_int32_t)((time_uptime - (a)->ia6_updatetime)) > \
138  (a)->ia6_lifetime.ia6t_vltime)
139 
140 #define MTAG_ABI_IPV6 1444287380 /* IPv6 ABI */
141 #define IPV6_TAG_DIRECT 0 /* direct-dispatch IPv6 */
142 
143 /* RFC2292 options */
144 #define IPV6_2292PKTINFO 19 /* bool; send/recv if, src/dst addr */
145 #define IPV6_2292HOPLIMIT 20 /* bool; hop limit */
146 #define IPV6_2292NEXTHOP 21 /* bool; next hop addr */
147 #define IPV6_2292HOPOPTS 22 /* bool; hop-by-hop option */
148 #define IPV6_2292DSTOPTS 23 /* bool; destinaion option */
149 #define IPV6_2292RTHDR 24 /* bool; routing header */
150 #define IPV6_2292PKTOPTIONS 25 /* buf/cmsghdr; set/get IPv6 options */
151 
152 #define IPV6_RECVRTHDRDSTOPTS 41 /* bool; recv dst option before rthdr */
153 
154 struct cmsghdr;
155 struct ip6_hdr;
156 
157 int in6_cksum_pseudo(struct ip6_hdr *, uint32_t, uint8_t, uint16_t);
158 int in6_cksum(struct mbuf *, u_int8_t, u_int32_t, u_int32_t);
159 int in6_cksum_partial(struct mbuf *, u_int8_t, u_int32_t, u_int32_t,
160  u_int32_t);
161 int in6_localaddr(struct in6_addr *);
162 int in6_localip(struct in6_addr *);
163 int in6_ifhasaddr(struct ifnet *, struct in6_addr *);
164 int in6_addrscope(const struct in6_addr *);
165 char *ip6_sprintf(char *, const struct in6_addr *);
166 struct in6_ifaddr *in6_ifawithifp(struct ifnet *, struct in6_addr *);
167 extern void in6_if_up(struct ifnet *);
168 struct sockaddr;
169 extern u_char ip6_protox[];
170 
171 void in6_sin6_2_sin(struct sockaddr_in *sin,
172  struct sockaddr_in6 *sin6);
173 void in6_sin_2_v4mapsin6(struct sockaddr_in *sin,
174  struct sockaddr_in6 *sin6);
175 void in6_sin6_2_sin_in_sock(struct sockaddr *nam);
176 void in6_sin_2_v4mapsin6_in_sock(struct sockaddr **nam);
177 extern void addrsel_policy_init(void);
178 
179 #define satosin6(sa) ((struct sockaddr_in6 *)(sa))
180 #define sin6tosa(sin6) ((struct sockaddr *)(sin6))
181 #define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa))