1/* $OpenBSD: in6_var.h,v 1.85 2026/03/22 23:14:00 bluhm Exp $ */
2/* $KAME: in6_var.h,v 1.55 2001/02/16 12:49:45 itojun Exp $ */
3
4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33/*
34 * Copyright (c) 1985, 1986, 1993
35 * The Regents of the University of California. All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * @(#)in_var.h 8.1 (Berkeley) 6/10/93
62 */
63
64#ifndef _NETINET6_IN6_VAR_H_
65#define _NETINET6_IN6_VAR_H_
66
67/*
68 * Locks used to protect struct members in this file:
69 * I immutable after creation
70 * m multicast if_maddrlock rwlock of parent interface
71 */
72
73/*
74 * Interface address, Internet version. One of these structures
75 * is allocated for each interface with an Internet address.
76 * The ifaddr structure contains the protocol-independent part
77 * of the structure and is assumed to be first.
78 */
79
80/*
81 * pltime/vltime are just for future reference (required to implements 2
82 * hour rule for hosts). they should never be modified by nd6_timeout or
83 * anywhere else.
84 * userland -> kernel: accept pltime/vltime
85 * kernel -> userland: throw up everything
86 * in kernel: modify preferred/expire only
87 */
88struct in6_addrlifetime {
89 time_t ia6t_expire; /* valid lifetime expiration time */
90 time_t ia6t_preferred; /* preferred lifetime expiration time */
91 u_int32_t ia6t_vltime; /* valid lifetime */
92 u_int32_t ia6t_pltime; /* prefix lifetime */
93};
94
95#ifdef _KERNEL
96struct in6_ifaddr {
97 struct ifaddr ia_ifa; /* protocol-independent info */
98#define ia_ifp ia_ifa.ifa_ifp
99#define ia_flags ia_ifa.ifa_flags
100
101 struct sockaddr_in6 ia_addr; /* interface address */
102 struct sockaddr_in6 ia_gwaddr; /* router we learned address from */
103 struct sockaddr_in6 ia_dstaddr; /* space for destination addr */
104 struct sockaddr_in6 ia_prefixmask; /* prefix mask */
105 TAILQ_ENTRY(in6_ifaddr) ia_list; /* list of IP6 addresses */
106 int ia6_flags;
107
108 struct in6_addrlifetime ia6_lifetime;
109 time_t ia6_updatetime;
110
111 /* multicast addresses joined from the kernel */
112 LIST_HEAD(, in6_multi_mship) ia6_memberships;
113};
114#endif /* _KERNEL */
115
116/*
117 * IPv6 interface statistics, as defined in RFC2465 Ipv6IfStatsEntry (p12).
118 */
119struct in6_ifstat {
120 u_int64_t ifs6_in_receive; /* # of total input datagram */
121 u_int64_t ifs6_in_hdrerr; /* # of datagrams with invalid hdr */
122 u_int64_t ifs6_in_toobig; /* # of datagrams exceeded MTU */
123 u_int64_t ifs6_in_noroute; /* # of datagrams with no route */
124 u_int64_t ifs6_in_addrerr; /* # of datagrams with invalid dst */
125 u_int64_t ifs6_in_protounknown; /* # of datagrams with unknown proto */
126 /* NOTE: increment on final dst if */
127 u_int64_t ifs6_in_truncated; /* # of truncated datagrams */
128 u_int64_t ifs6_in_discard; /* # of discarded datagrams */
129 /* NOTE: fragment timeout is not here */
130 u_int64_t ifs6_in_deliver; /* # of datagrams delivered to ULP */
131 /* NOTE: increment on final dst if */
132 u_int64_t ifs6_out_forward; /* # of datagrams forwarded */
133 /* NOTE: increment on outgoing if */
134 u_int64_t ifs6_out_request; /* # of outgoing datagrams from ULP */
135 /* NOTE: does not include forwards */
136 u_int64_t ifs6_out_discard; /* # of discarded datagrams */
137 u_int64_t ifs6_out_fragok; /* # of datagrams fragmented */
138 u_int64_t ifs6_out_fragfail; /* # of datagrams failed on fragment */
139 u_int64_t ifs6_out_fragcreat; /* # of fragment datagrams */
140 /* NOTE: this is # after fragment */
141 u_int64_t ifs6_reass_reqd; /* # of incoming fragmented packets */
142 /* NOTE: increment on final dst if */
143 u_int64_t ifs6_reass_ok; /* # of reassembled packets */
144 /* NOTE: this is # after reass */
145 /* NOTE: increment on final dst if */
146 u_int64_t ifs6_reass_fail; /* # of reass failures */
147 /* NOTE: may not be packet count */
148 /* NOTE: increment on final dst if */
149 u_int64_t ifs6_in_mcast; /* # of inbound multicast datagrams */
150 u_int64_t ifs6_out_mcast; /* # of outbound multicast datagrams */
151};
152
153/*
154 * ICMPv6 interface statistics, as defined in RFC2466 Ipv6IfIcmpEntry.
155 * XXX: I'm not sure if this file is the right place for this structure...
156 */
157struct icmp6_ifstat {
158 /*
159 * Input statistics
160 */
161 /* ipv6IfIcmpInMsgs, total # of input messages */
162 u_int64_t ifs6_in_msg;
163 /* ipv6IfIcmpInErrors, # of input error messages */
164 u_int64_t ifs6_in_error;
165 /* ipv6IfIcmpInDestUnreachs, # of input dest unreach errors */
166 u_int64_t ifs6_in_dstunreach;
167 /* ipv6IfIcmpInAdminProhibs, # of input administratively prohibited errs */
168 u_int64_t ifs6_in_adminprohib;
169 /* ipv6IfIcmpInTimeExcds, # of input time exceeded errors */
170 u_int64_t ifs6_in_timeexceed;
171 /* ipv6IfIcmpInParmProblems, # of input parameter problem errors */
172 u_int64_t ifs6_in_paramprob;
173 /* ipv6IfIcmpInPktTooBigs, # of input packet too big errors */
174 u_int64_t ifs6_in_pkttoobig;
175 /* ipv6IfIcmpInEchos, # of input echo requests */
176 u_int64_t ifs6_in_echo;
177 /* ipv6IfIcmpInEchoReplies, # of input echo replies */
178 u_int64_t ifs6_in_echoreply;
179 /* ipv6IfIcmpInRouterSolicits, # of input router solicitations */
180 u_int64_t ifs6_in_routersolicit;
181 /* ipv6IfIcmpInRouterAdvertisements, # of input router advertisements */
182 u_int64_t ifs6_in_routeradvert;
183 /* ipv6IfIcmpInNeighborSolicits, # of input neighbor solicitations */
184 u_int64_t ifs6_in_neighborsolicit;
185 /* ipv6IfIcmpInNeighborAdvertisements, # of input neighbor advertisements */
186 u_int64_t ifs6_in_neighboradvert;
187 /* ipv6IfIcmpInRedirects, # of input redirects */
188 u_int64_t ifs6_in_redirect;
189 /* ipv6IfIcmpInGroupMembQueries, # of input MLD queries */
190 u_int64_t ifs6_in_mldquery;
191 /* ipv6IfIcmpInGroupMembResponses, # of input MLD reports */
192 u_int64_t ifs6_in_mldreport;
193 /* ipv6IfIcmpInGroupMembReductions, # of input MLD done */
194 u_int64_t ifs6_in_mlddone;
195
196 /*
197 * Output statistics. We should solve unresolved routing problem...
198 */
199 /* ipv6IfIcmpOutMsgs, total # of output messages */
200 u_int64_t ifs6_out_msg;
201 /* ipv6IfIcmpOutErrors, # of output error messages */
202 u_int64_t ifs6_out_error;
203 /* ipv6IfIcmpOutDestUnreachs, # of output dest unreach errors */
204 u_int64_t ifs6_out_dstunreach;
205 /* ipv6IfIcmpOutAdminProhibs, # of output administratively prohibited errs */
206 u_int64_t ifs6_out_adminprohib;
207 /* ipv6IfIcmpOutTimeExcds, # of output time exceeded errors */
208 u_int64_t ifs6_out_timeexceed;
209 /* ipv6IfIcmpOutParmProblems, # of output parameter problem errors */
210 u_int64_t ifs6_out_paramprob;
211 /* ipv6IfIcmpOutPktTooBigs, # of output packet too big errors */
212 u_int64_t ifs6_out_pkttoobig;
213 /* ipv6IfIcmpOutEchos, # of output echo requests */
214 u_int64_t ifs6_out_echo;
215 /* ipv6IfIcmpOutEchoReplies, # of output echo replies */
216 u_int64_t ifs6_out_echoreply;
217 /* ipv6IfIcmpOutRouterSolicits, # of output router solicitations */
218 u_int64_t ifs6_out_routersolicit;
219 /* ipv6IfIcmpOutRouterAdvertisements, # of output router advertisements */
220 u_int64_t ifs6_out_routeradvert;
221 /* ipv6IfIcmpOutNeighborSolicits, # of output neighbor solicitations */
222 u_int64_t ifs6_out_neighborsolicit;
223 /* ipv6IfIcmpOutNeighborAdvertisements, # of output neighbor advertisements */
224 u_int64_t ifs6_out_neighboradvert;
225 /* ipv6IfIcmpOutRedirects, # of output redirects */
226 u_int64_t ifs6_out_redirect;
227 /* ipv6IfIcmpOutGroupMembQueries, # of output MLD queries */
228 u_int64_t ifs6_out_mldquery;
229 /* ipv6IfIcmpOutGroupMembResponses, # of output MLD reports */
230 u_int64_t ifs6_out_mldreport;
231 /* ipv6IfIcmpOutGroupMembReductions, # of output MLD done */
232 u_int64_t ifs6_out_mlddone;
233};
234
235struct in6_ifreq {
236 char ifr_name[IFNAMSIZ];
237 union {
238 struct sockaddr_in6 ifru_addr;
239 struct sockaddr_in6 ifru_dstaddr;
240 short ifru_flags;
241 int ifru_flags6;
242 int ifru_metric;
243 caddr_t ifru_data;
244 struct in6_addrlifetime ifru_lifetime;
245 struct in6_ifstat ifru_stat;
246 struct icmp6_ifstat ifru_icmp6stat;
247 } ifr_ifru;
248};
249
250struct in6_aliasreq {
251 char ifra_name[IFNAMSIZ];
252 union {
253 struct sockaddr_in6 ifrau_addr;
254 int ifrau_align;
255 } ifra_ifrau;
256#ifndef ifra_addr
257#define ifra_addr ifra_ifrau.ifrau_addr
258#endif
259 struct sockaddr_in6 ifra_dstaddr;
260 struct sockaddr_in6 ifra_prefixmask;
261 int ifra_flags;
262 struct in6_addrlifetime ifra_lifetime;
263};
264
265/*
266 * Given a pointer to an in6_ifaddr (ifaddr),
267 * return a pointer to the addr as a sockaddr_in6
268 */
269#define IA6_IN6(ia) (&((ia)->ia_addr.sin6_addr))
270#define IA6_DSTIN6(ia) (&((ia)->ia_dstaddr.sin6_addr))
271#define IA6_MASKIN6(ia) (&((ia)->ia_prefixmask.sin6_addr))
272#define IA6_SIN6(ia) (&((ia)->ia_addr))
273#define IA6_DSTSIN6(ia) (&((ia)->ia_dstaddr))
274#define IFA_IN6(x) (&((struct sockaddr_in6 *)((x)->ifa_addr))->sin6_addr)
275#define IFA_DSTIN6(x) (&((struct sockaddr_in6 *)((x)->ifa_dstaddr))->sin6_addr)
276
277#define SIOCDIFADDR_IN6 _IOW('i', 25, struct in6_ifreq)
278#define SIOCAIFADDR_IN6 _IOW('i', 26, struct in6_aliasreq)
279
280#define SIOCGIFDSTADDR_IN6 _IOWR('i', 34, struct in6_ifreq)
281#define SIOCGIFNETMASK_IN6 _IOWR('i', 37, struct in6_ifreq)
282
283#define SIOCGIFAFLAG_IN6 _IOWR('i', 73, struct in6_ifreq)
284
285#define SIOCGIFINFO_IN6 _IOWR('i', 108, struct in6_ndireq)
286#define SIOCGNBRINFO_IN6 _IOWR('i', 78, struct in6_nbrinfo)
287
288#define SIOCGIFALIFETIME_IN6 _IOWR('i', 81, struct in6_ifreq)
289
290#define SIOCGETSGCNT_IN6 _IOWR('u', 106, struct sioc_sg_req6)
291#define SIOCGETMIFCNT_IN6 _IOWR('u', 107, struct sioc_mif_req6)
292
293#define IN6_IFF_ANYCAST 0x01 /* anycast address */
294#define IN6_IFF_TENTATIVE 0x02 /* tentative address */
295#define IN6_IFF_DUPLICATED 0x04 /* DAD detected duplicate */
296#define IN6_IFF_DETACHED 0x08 /* may be detached from the link */
297#define IN6_IFF_DEPRECATED 0x10 /* deprecated address */
298#define IN6_IFF_AUTOCONF 0x40 /* autoconfigurable address. */
299#define IN6_IFF_TEMPORARY 0x80 /* RFC 4941 temporary address */
300
301#ifdef _KERNEL
302#define IN6_ARE_MASKED_ADDR_EQUAL(d, a, m) ( \
303 (((d)->s6_addr32[0] ^ (a)->s6_addr32[0]) & (m)->s6_addr32[0]) == 0 && \
304 (((d)->s6_addr32[1] ^ (a)->s6_addr32[1]) & (m)->s6_addr32[1]) == 0 && \
305 (((d)->s6_addr32[2] ^ (a)->s6_addr32[2]) & (m)->s6_addr32[2]) == 0 && \
306 (((d)->s6_addr32[3] ^ (a)->s6_addr32[3]) & (m)->s6_addr32[3]) == 0 )
307
308#define IN6_ARE_SCOPE_CMP(a,b) ((a)-(b))
309#define IN6_ARE_SCOPE_EQUAL(a,b) ((a)==(b))
310
311/*
312 * Multi-cast membership entry. One for each group/ifp that a PCB
313 * belongs to.
314 */
315struct in6_multi_mship {
316 struct in6_multi *i6mm_maddr; /* Multicast address pointer */
317 LIST_ENTRY(in6_multi_mship) i6mm_chain; /* multicast options chain */
318};
319
320struct in6_multi {
321 struct ifmaddr in6m_ifma; /* Protocol-independent info */
322#define in6m_refcnt in6m_ifma.ifma_refcnt
323#define in6m_ifidx in6m_ifma.ifma_ifidx
324
325 struct sockaddr_in6 in6m_sin; /* [I] IPv6 multicast address */
326#define in6m_addr in6m_sin.sin6_addr
327
328 u_int in6m_state; /* [m] state of membership */
329 u_int in6m_timer; /* [m] MLD6 membership report */
330};
331
332static __inline struct in6_multi *
333ifmatoin6m(struct ifmaddr *ifma)
334{
335 return ((struct in6_multi *)(ifma));
336}
337
338struct in6_multi *in6_lookupmulti(const struct in6_addr *, struct ifnet *);
339struct in6_multi *in6_addmulti(const struct in6_addr *, struct ifnet *, int *);
340void in6_delmulti(struct in6_multi *);
341int in6_hasmulti(const struct in6_addr *, struct ifnet *);
342struct in6_multi_mship *in6_joingroup(struct ifnet *, const struct in6_addr *,
343 int *);
344void in6_leavegroup(struct in6_multi_mship *);
345int in6_control(struct socket *, u_long, caddr_t, struct ifnet *);
346int in6_ioctl(u_long, caddr_t, struct ifnet *, int);
347int in6_update_ifa(struct ifnet *, struct in6_aliasreq *,
348 struct in6_ifaddr *);
349void in6_purgeaddr(struct ifaddr *);
350int in6if_do_dad(struct ifnet *);
351struct in6_ifaddr *in6ifa_ifpforlinklocal(struct ifnet *, int);
352struct in6_ifaddr *in6ifa_ifpwithaddr(struct ifnet *, struct in6_addr *);
353int in6_addr2scopeid(unsigned int, const struct in6_addr *);
354int in6_matchlen(const struct in6_addr *, const struct in6_addr *);
355void in6_prefixlen2mask(struct in6_addr *, int);
356#endif /* _KERNEL */
357
358#endif /* _NETINET6_IN6_VAR_H_ */