in6_var.h revision 194971
1112694Stegge/*-
2112694Stegge * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3112694Stegge * All rights reserved.
4112694Stegge *
5112694Stegge * Redistribution and use in source and binary forms, with or without
6112694Stegge * modification, are permitted provided that the following conditions
7112694Stegge * are met:
8112694Stegge * 1. Redistributions of source code must retain the above copyright
9112694Stegge *    notice, this list of conditions and the following disclaimer.
10112694Stegge * 2. Redistributions in binary form must reproduce the above copyright
11112694Stegge *    notice, this list of conditions and the following disclaimer in the
12112694Stegge *    documentation and/or other materials provided with the distribution.
13112694Stegge * 3. Neither the name of the project nor the names of its contributors
14112694Stegge *    may be used to endorse or promote products derived from this software
15112694Stegge *    without specific prior written permission.
16112694Stegge *
17112694Stegge * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18112694Stegge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19112694Stegge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20112694Stegge * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21112694Stegge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22112694Stegge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23112694Stegge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24112694Stegge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25112694Stegge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26112694Stegge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27116192Sobrien * SUCH DAMAGE.
28116192Sobrien *
29116192Sobrien *	$KAME: in6_var.h,v 1.56 2001/03/29 05:34:31 itojun Exp $
30112694Stegge */
31112694Stegge
32112694Stegge/*-
33112694Stegge * Copyright (c) 1985, 1986, 1993
34112694Stegge *	The Regents of the University of California.  All rights reserved.
35112694Stegge *
36114216Skan * Redistribution and use in source and binary forms, with or without
37112694Stegge * modification, are permitted provided that the following conditions
38112694Stegge * are met:
39112694Stegge * 1. Redistributions of source code must retain the above copyright
40112694Stegge *    notice, this list of conditions and the following disclaimer.
41112694Stegge * 2. Redistributions in binary form must reproduce the above copyright
42112694Stegge *    notice, this list of conditions and the following disclaimer in the
43112694Stegge *    documentation and/or other materials provided with the distribution.
44112694Stegge * 4. Neither the name of the University nor the names of its contributors
45248084Sattilio *    may be used to endorse or promote products derived from this software
46118986Salc *    without specific prior written permission.
47112694Stegge *
48112694Stegge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49118986Salc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50119088Salc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51112694Stegge * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52141522Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53112694Stegge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54112694Stegge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55112694Stegge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56112694Stegge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57112694Stegge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58112694Stegge * SUCH DAMAGE.
59112694Stegge *
60112694Stegge *	@(#)in_var.h	8.1 (Berkeley) 6/10/93
61112694Stegge * $FreeBSD: head/sys/netinet6/in6_var.h 194971 2009-06-25 16:35:28Z rwatson $
62112694Stegge */
63112694Stegge
64112694Stegge#ifndef _NETINET6_IN6_VAR_H_
65112694Stegge#define _NETINET6_IN6_VAR_H_
66112694Stegge
67112694Stegge#include <sys/tree.h>
68112694Stegge
69112694Stegge#ifdef _KERNEL
70176559Sattilio#include <sys/libkern.h>
71112694Stegge#endif
72112694Stegge
73112694Stegge/*
74112694Stegge * Interface address, Internet version.  One of these structures
75112694Stegge * is allocated for each interface with an Internet address.
76112694Stegge * The ifaddr structure contains the protocol-independent part
77112694Stegge * of the structure and is assumed to be first.
78112694Stegge */
79112694Stegge
80112694Stegge/*
81112694Stegge * pltime/vltime are just for future reference (required to implements 2
82112694Stegge * hour rule for hosts).  they should never be modified by nd6_timeout or
83112694Stegge * anywhere else.
84112694Stegge *	userland -> kernel: accept pltime/vltime
85112694Stegge *	kernel -> userland: throw up everything
86112694Stegge *	in kernel: modify preferred/expire only
87112694Stegge */
88267494Skibstruct in6_addrlifetime {
89267494Skib	time_t ia6t_expire;	/* valid lifetime expiration time */
90267494Skib	time_t ia6t_preferred;	/* preferred lifetime expiration time */
91112694Stegge	u_int32_t ia6t_vltime;	/* valid lifetime */
92112694Stegge	u_int32_t ia6t_pltime;	/* prefix lifetime */
93112694Stegge};
94267494Skib
95112694Steggestruct nd_ifinfo;
96112694Steggestruct scope6_id;
97176559Sattiliostruct lltable;
98112694Steggestruct mld_ifinfo;
99112694Stegge
100112694Steggestruct in6_ifextra {
101136943Sphk	struct in6_ifstat *in6_ifstat;
102156225Stegge	struct icmp6_ifstat *icmp6_ifstat;
103200770Skib	struct nd_ifinfo *nd_ifinfo;
104112694Stegge	struct scope6_id *scope6_id;
105112694Stegge	struct lltable *lltable;
106177493Sjeff	struct mld_ifinfo *mld_ifinfo;
107177493Sjeff};
108112694Stegge
109136943Sphk#define	LLTABLE6(ifp)	(((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->lltable)
110136968Sphk
111200770Skibstruct	in6_ifaddr {
112200770Skib	struct	ifaddr ia_ifa;		/* protocol-independent info */
113112694Stegge#define	ia_ifp		ia_ifa.ifa_ifp
114177493Sjeff#define ia_flags	ia_ifa.ifa_flags
115112694Stegge	struct	sockaddr_in6 ia_addr;	/* interface address */
116156225Stegge	struct	sockaddr_in6 ia_net;	/* network number of interface */
117176559Sattilio	struct	sockaddr_in6 ia_dstaddr; /* space for destination addr */
118156225Stegge	struct	sockaddr_in6 ia_prefixmask; /* prefix mask */
119156225Stegge	u_int32_t ia_plen;		/* prefix length */
120156225Stegge	TAILQ_ENTRY(in6_ifaddr)	ia_link;	/* list of IPv6 addresses */
121175294Sattilio	int	ia6_flags;
122156225Stegge
123175294Sattilio	struct in6_addrlifetime ia6_lifetime;
124176559Sattilio	time_t	ia6_createtime; /* the creation time of this address, which is
125112694Stegge				 * currently used for temporary addresses only.
126112694Stegge				 */
127175294Sattilio	time_t	ia6_updatetime;
128112694Stegge
129112694Stegge	/* back pointer to the ND prefix (for autoconfigured addresses only) */
130112694Stegge	struct nd_prefix *ia6_ndpr;
131112694Stegge
132158325Stegge	/* multicast addresses joined from the kernel */
133158325Stegge	LIST_HEAD(, in6_multi_mship) ia6_memberships;
134158325Stegge};
135158325Stegge
136158325Stegge/* List of in6_ifaddr's. */
137175294SattilioTAILQ_HEAD(in6_ifaddrhead, in6_ifaddr);
138158325Stegge
139158325Stegge/* control structure to manage address selection policy */
140158325Steggestruct in6_addrpolicy {
141112694Stegge	struct sockaddr_in6 addr; /* prefix address */
142200770Skib	struct sockaddr_in6 addrmask; /* prefix mask */
143200770Skib	int preced;		/* precedence */
144112694Stegge	int label;		/* matching label */
145248084Sattilio	u_quad_t use;		/* statistics */
146200770Skib};
147248084Sattilio
148177493Sjeff/*
149177493Sjeff * IPv6 interface statistics, as defined in RFC2465 Ipv6IfStatsEntry (p12).
150112694Stegge */
151112694Steggestruct in6_ifstat {
152177493Sjeff	u_quad_t ifs6_in_receive;	/* # of total input datagram */
153136943Sphk	u_quad_t ifs6_in_hdrerr;	/* # of datagrams with invalid hdr */
154136943Sphk	u_quad_t ifs6_in_toobig;	/* # of datagrams exceeded MTU */
155136943Sphk	u_quad_t ifs6_in_noroute;	/* # of datagrams with no route */
156177493Sjeff	u_quad_t ifs6_in_addrerr;	/* # of datagrams with invalid dst */
157136943Sphk	u_quad_t ifs6_in_protounknown;	/* # of datagrams with unknown proto */
158175294Sattilio					/* NOTE: increment on final dst if */
159158325Stegge	u_quad_t ifs6_in_truncated;	/* # of truncated datagrams */
160136943Sphk	u_quad_t ifs6_in_discard;	/* # of discarded datagrams */
161112694Stegge					/* NOTE: fragment timeout is not here */
162112694Stegge	u_quad_t ifs6_in_deliver;	/* # of datagrams delivered to ULP */
163136968Sphk					/* NOTE: increment on final dst if */
164177493Sjeff	u_quad_t ifs6_out_forward;	/* # of datagrams forwarded */
165233438Smckusick					/* NOTE: increment on outgoing if */
166112694Stegge	u_quad_t ifs6_out_request;	/* # of outgoing datagrams from ULP */
167175294Sattilio					/* NOTE: does not include forwrads */
168158325Stegge	u_quad_t ifs6_out_discard;	/* # of discarded datagrams */
169112694Stegge	u_quad_t ifs6_out_fragok;	/* # of datagrams fragmented */
170112694Stegge	u_quad_t ifs6_out_fragfail;	/* # of datagrams failed on fragment */
171177493Sjeff	u_quad_t ifs6_out_fragcreat;	/* # of fragment datagrams */
172136968Sphk					/* NOTE: this is # after fragment */
173112694Stegge	u_quad_t ifs6_reass_reqd;	/* # of incoming fragmented packets */
174112694Stegge					/* NOTE: increment on final dst if */
175177493Sjeff	u_quad_t ifs6_reass_ok;		/* # of reassembled packets */
176112694Stegge					/* NOTE: this is # after reass */
177175294Sattilio					/* NOTE: increment on final dst if */
178156225Stegge	u_quad_t ifs6_reass_fail;	/* # of reass failures */
179112694Stegge					/* NOTE: may not be packet count */
180112694Stegge					/* NOTE: increment on final dst if */
181177493Sjeff	u_quad_t ifs6_in_mcast;		/* # of inbound multicast datagrams */
182112694Stegge	u_quad_t ifs6_out_mcast;	/* # of outbound multicast datagrams */
183112694Stegge};
184112694Stegge
185112694Stegge/*
186112694Stegge * ICMPv6 interface statistics, as defined in RFC2466 Ipv6IfIcmpEntry.
187112694Stegge * XXX: I'm not sure if this file is the right place for this structure...
188112694Stegge */
189112694Steggestruct icmp6_ifstat {
190112694Stegge	/*
191112694Stegge	 * Input statistics
192112694Stegge	 */
193112694Stegge	/* ipv6IfIcmpInMsgs, total # of input messages */
194112694Stegge	u_quad_t ifs6_in_msg;
195112694Stegge	/* ipv6IfIcmpInErrors, # of input error messages */
196112694Stegge	u_quad_t ifs6_in_error;
197112694Stegge	/* ipv6IfIcmpInDestUnreachs, # of input dest unreach errors */
198112694Stegge	u_quad_t ifs6_in_dstunreach;
199112694Stegge	/* ipv6IfIcmpInAdminProhibs, # of input administratively prohibited errs */
200112694Stegge	u_quad_t ifs6_in_adminprohib;
201112694Stegge	/* ipv6IfIcmpInTimeExcds, # of input time exceeded errors */
202112694Stegge	u_quad_t ifs6_in_timeexceed;
203119049Sphk	/* ipv6IfIcmpInParmProblems, # of input parameter problem errors */
204119049Sphk	u_quad_t ifs6_in_paramprob;
205112694Stegge	/* ipv6IfIcmpInPktTooBigs, # of input packet too big errors */
206112694Stegge	u_quad_t ifs6_in_pkttoobig;
207112694Stegge	/* ipv6IfIcmpInEchos, # of input echo requests */
208119049Sphk	u_quad_t ifs6_in_echo;
209119049Sphk	/* ipv6IfIcmpInEchoReplies, # of input echo replies */
210119049Sphk	u_quad_t ifs6_in_echoreply;
211112694Stegge	/* ipv6IfIcmpInRouterSolicits, # of input router solicitations */
212112694Stegge	u_quad_t ifs6_in_routersolicit;
213112694Stegge	/* ipv6IfIcmpInRouterAdvertisements, # of input router advertisements */
214112694Stegge	u_quad_t ifs6_in_routeradvert;
215112694Stegge	/* ipv6IfIcmpInNeighborSolicits, # of input neighbor solicitations */
216112694Stegge	u_quad_t ifs6_in_neighborsolicit;
217112694Stegge	/* ipv6IfIcmpInNeighborAdvertisements, # of input neighbor advertisements */
218122747Sphk	u_quad_t ifs6_in_neighboradvert;
219112694Stegge	/* ipv6IfIcmpInRedirects, # of input redirects */
220145702Sjeff	u_quad_t ifs6_in_redirect;
221112694Stegge	/* ipv6IfIcmpInGroupMembQueries, # of input MLD queries */
222112694Stegge	u_quad_t ifs6_in_mldquery;
223121354Stegge	/* ipv6IfIcmpInGroupMembResponses, # of input MLD reports */
224121354Stegge	u_quad_t ifs6_in_mldreport;
225112694Stegge	/* ipv6IfIcmpInGroupMembReductions, # of input MLD done */
226112694Stegge	u_quad_t ifs6_in_mlddone;
227112694Stegge
228112694Stegge	/*
229112694Stegge	 * Output statistics. We should solve unresolved routing problem...
230112694Stegge	 */
231119049Sphk	/* ipv6IfIcmpOutMsgs, total # of output messages */
232119049Sphk	u_quad_t ifs6_out_msg;
233112694Stegge	/* ipv6IfIcmpOutErrors, # of output error messages */
234121354Stegge	u_quad_t ifs6_out_error;
235112694Stegge	/* ipv6IfIcmpOutDestUnreachs, # of output dest unreach errors */
236112694Stegge	u_quad_t ifs6_out_dstunreach;
237112694Stegge	/* ipv6IfIcmpOutAdminProhibs, # of output administratively prohibited errs */
238112694Stegge	u_quad_t ifs6_out_adminprohib;
239112694Stegge	/* ipv6IfIcmpOutTimeExcds, # of output time exceeded errors */
240112694Stegge	u_quad_t ifs6_out_timeexceed;
241112694Stegge	/* ipv6IfIcmpOutParmProblems, # of output parameter problem errors */
242248515Skib	u_quad_t ifs6_out_paramprob;
243112694Stegge	/* ipv6IfIcmpOutPktTooBigs, # of output packet too big errors */
244112694Stegge	u_quad_t ifs6_out_pkttoobig;
245218195Smdf	/* ipv6IfIcmpOutEchos, # of output echo requests */
246112694Stegge	u_quad_t ifs6_out_echo;
247112694Stegge	/* ipv6IfIcmpOutEchoReplies, # of output echo replies */
248112694Stegge	u_quad_t ifs6_out_echoreply;
249112694Stegge	/* ipv6IfIcmpOutRouterSolicits, # of output router solicitations */
250112694Stegge	u_quad_t ifs6_out_routersolicit;
251112694Stegge	/* ipv6IfIcmpOutRouterAdvertisements, # of output router advertisements */
252112694Stegge	u_quad_t ifs6_out_routeradvert;
253112694Stegge	/* ipv6IfIcmpOutNeighborSolicits, # of output neighbor solicitations */
254121354Stegge	u_quad_t ifs6_out_neighborsolicit;
255121354Stegge	/* ipv6IfIcmpOutNeighborAdvertisements, # of output neighbor advertisements */
256112694Stegge	u_quad_t ifs6_out_neighboradvert;
257112694Stegge	/* ipv6IfIcmpOutRedirects, # of output redirects */
258112694Stegge	u_quad_t ifs6_out_redirect;
259112694Stegge	/* ipv6IfIcmpOutGroupMembQueries, # of output MLD queries */
260112694Stegge	u_quad_t ifs6_out_mldquery;
261248515Skib	/* ipv6IfIcmpOutGroupMembResponses, # of output MLD reports */
262112694Stegge	u_quad_t ifs6_out_mldreport;
263112694Stegge	/* ipv6IfIcmpOutGroupMembReductions, # of output MLD done */
264140051Sphk	u_quad_t ifs6_out_mlddone;
265112694Stegge};
266112694Stegge
267112694Steggestruct	in6_ifreq {
268112694Stegge	char	ifr_name[IFNAMSIZ];
269112694Stegge	union {
270112694Stegge		struct	sockaddr_in6 ifru_addr;
271112694Stegge		struct	sockaddr_in6 ifru_dstaddr;
272112694Stegge		int	ifru_flags;
273112694Stegge		int	ifru_flags6;
274112694Stegge		int	ifru_metric;
275112694Stegge		caddr_t	ifru_data;
276112694Stegge		struct in6_addrlifetime ifru_lifetime;
277112694Stegge		struct in6_ifstat ifru_stat;
278112694Stegge		struct icmp6_ifstat ifru_icmp6stat;
279112694Stegge		u_int32_t ifru_scope_id[16];
280112694Stegge	} ifr_ifru;
281112694Stegge};
282112694Stegge
283112694Steggestruct	in6_aliasreq {
284112694Stegge	char	ifra_name[IFNAMSIZ];
285112694Stegge	struct	sockaddr_in6 ifra_addr;
286112694Stegge	struct	sockaddr_in6 ifra_dstaddr;
287112694Stegge	struct	sockaddr_in6 ifra_prefixmask;
288112694Stegge	int	ifra_flags;
289112694Stegge	struct in6_addrlifetime ifra_lifetime;
290112694Stegge};
291112694Stegge
292112694Stegge/* prefix type macro */
293112694Stegge#define IN6_PREFIX_ND	1
294112694Stegge#define IN6_PREFIX_RR	2
295112694Stegge
296112694Stegge/*
297112694Stegge * prefix related flags passed between kernel(NDP related part) and
298112694Stegge * user land command(ifconfig) and daemon(rtadvd).
299112694Stegge */
300112694Steggestruct in6_prflags {
301112694Stegge	struct prf_ra {
302112694Stegge		u_char onlink : 1;
303112694Stegge		u_char autonomous : 1;
304112694Stegge		u_char reserved : 6;
305112694Stegge	} prf_ra;
306112694Stegge	u_char prf_reserved1;
307166506Stegge	u_short prf_reserved2;
308112694Stegge	/* want to put this on 4byte offset */
309112694Stegge	struct prf_rr {
310112694Stegge		u_char decrvalid : 1;
311112694Stegge		u_char decrprefd : 1;
312112694Stegge		u_char reserved : 6;
313112694Stegge	} prf_rr;
314112694Stegge	u_char prf_reserved3;
315112694Stegge	u_short prf_reserved4;
316112694Stegge};
317112694Stegge
318112694Steggestruct  in6_prefixreq {
319112694Stegge	char	ipr_name[IFNAMSIZ];
320112694Stegge	u_char	ipr_origin;
321166506Stegge	u_char	ipr_plen;
322112694Stegge	u_int32_t ipr_vltime;
323112694Stegge	u_int32_t ipr_pltime;
324112694Stegge	struct in6_prflags ipr_flags;
325112694Stegge	struct	sockaddr_in6 ipr_prefix;
326112694Stegge};
327112694Stegge
328112694Stegge#define PR_ORIG_RA	0
329112694Stegge#define PR_ORIG_RR	1
330112694Stegge#define PR_ORIG_STATIC	2
331112694Stegge#define PR_ORIG_KERNEL	3
332112694Stegge
333112694Stegge#define ipr_raf_onlink		ipr_flags.prf_ra.onlink
334166506Stegge#define ipr_raf_auto		ipr_flags.prf_ra.autonomous
335112694Stegge
336112694Stegge#define ipr_statef_onlink	ipr_flags.prf_state.onlink
337112694Stegge
338112694Stegge#define ipr_rrf_decrvalid	ipr_flags.prf_rr.decrvalid
339112694Stegge#define ipr_rrf_decrprefd	ipr_flags.prf_rr.decrprefd
340112694Stegge
341112694Steggestruct	in6_rrenumreq {
342112694Stegge	char	irr_name[IFNAMSIZ];
343112718Stegge	u_char	irr_origin;
344112694Stegge	u_char	irr_m_len;	/* match len for matchprefix */
345112694Stegge	u_char	irr_m_minlen;	/* minlen for matching prefix */
346112694Stegge	u_char	irr_m_maxlen;	/* maxlen for matching prefix */
347112694Stegge	u_char	irr_u_uselen;	/* uselen for adding prefix */
348112694Stegge	u_char	irr_u_keeplen;	/* keeplen from matching prefix */
349112694Stegge	struct irr_raflagmask {
350112694Stegge		u_char onlink : 1;
351112694Stegge		u_char autonomous : 1;
352112694Stegge		u_char reserved : 6;
353112694Stegge	} irr_raflagmask;
354112694Stegge	u_int32_t irr_vltime;
355112694Stegge	u_int32_t irr_pltime;
356112694Stegge	struct in6_prflags irr_flags;
357112694Stegge	struct	sockaddr_in6 irr_matchprefix;
358112694Stegge	struct	sockaddr_in6 irr_useprefix;
359112694Stegge};
360112694Stegge
361112694Stegge#define irr_raf_mask_onlink	irr_raflagmask.onlink
362112694Stegge#define irr_raf_mask_auto	irr_raflagmask.autonomous
363112694Stegge#define irr_raf_mask_reserved	irr_raflagmask.reserved
364112694Stegge
365112694Stegge#define irr_raf_onlink		irr_flags.prf_ra.onlink
366112694Stegge#define irr_raf_auto		irr_flags.prf_ra.autonomous
367112694Stegge
368112694Stegge#define irr_statef_onlink	irr_flags.prf_state.onlink
369112694Stegge
370112694Stegge#define irr_rrf			irr_flags.prf_rr
371112694Stegge#define irr_rrf_decrvalid	irr_flags.prf_rr.decrvalid
372112694Stegge#define irr_rrf_decrprefd	irr_flags.prf_rr.decrprefd
373112694Stegge
374112694Stegge/*
375112694Stegge * Given a pointer to an in6_ifaddr (ifaddr),
376112694Stegge * return a pointer to the addr as a sockaddr_in6
377112694Stegge */
378112694Stegge#define IA6_IN6(ia)	(&((ia)->ia_addr.sin6_addr))
379112694Stegge#define IA6_DSTIN6(ia)	(&((ia)->ia_dstaddr.sin6_addr))
380112694Stegge#define IA6_MASKIN6(ia)	(&((ia)->ia_prefixmask.sin6_addr))
381112694Stegge#define IA6_SIN6(ia)	(&((ia)->ia_addr))
382112694Stegge#define IA6_DSTSIN6(ia)	(&((ia)->ia_dstaddr))
383166506Stegge#define IFA_IN6(x)	(&((struct sockaddr_in6 *)((x)->ifa_addr))->sin6_addr)
384112694Stegge#define IFA_DSTIN6(x)	(&((struct sockaddr_in6 *)((x)->ifa_dstaddr))->sin6_addr)
385112694Stegge
386112694Stegge#define IFPR_IN6(x)	(&((struct sockaddr_in6 *)((x)->ifpr_prefix))->sin6_addr)
387112694Stegge
388112694Stegge#ifdef _KERNEL
389112694Stegge#define IN6_ARE_MASKED_ADDR_EQUAL(d, a, m)	(	\
390112694Stegge	(((d)->s6_addr32[0] ^ (a)->s6_addr32[0]) & (m)->s6_addr32[0]) == 0 && \
391112694Stegge	(((d)->s6_addr32[1] ^ (a)->s6_addr32[1]) & (m)->s6_addr32[1]) == 0 && \
392112694Stegge	(((d)->s6_addr32[2] ^ (a)->s6_addr32[2]) & (m)->s6_addr32[2]) == 0 && \
393112694Stegge	(((d)->s6_addr32[3] ^ (a)->s6_addr32[3]) & (m)->s6_addr32[3]) == 0 )
394112694Stegge#endif
395112694Stegge
396112694Stegge#define SIOCSIFADDR_IN6		 _IOW('i', 12, struct in6_ifreq)
397112694Stegge#define SIOCGIFADDR_IN6		_IOWR('i', 33, struct in6_ifreq)
398166506Stegge
399112694Stegge#ifdef _KERNEL
400112694Stegge/*
401112694Stegge * SIOCSxxx ioctls should be unused (see comments in in6.c), but
402112694Stegge * we do not shift numbers for binary compatibility.
403112694Stegge */
404112694Stegge#define SIOCSIFDSTADDR_IN6	 _IOW('i', 14, struct in6_ifreq)
405112694Stegge#define SIOCSIFNETMASK_IN6	 _IOW('i', 22, struct in6_ifreq)
406112694Stegge#endif
407112694Stegge
408112694Stegge#define SIOCGIFDSTADDR_IN6	_IOWR('i', 34, struct in6_ifreq)
409112694Stegge#define SIOCGIFNETMASK_IN6	_IOWR('i', 37, struct in6_ifreq)
410112694Stegge
411112694Stegge#define SIOCDIFADDR_IN6		 _IOW('i', 25, struct in6_ifreq)
412112694Stegge#define SIOCAIFADDR_IN6		 _IOW('i', 26, struct in6_aliasreq)
413166506Stegge
414166506Stegge#define SIOCSIFPHYADDR_IN6       _IOW('i', 70, struct in6_aliasreq)
415112694Stegge#define	SIOCGIFPSRCADDR_IN6	_IOWR('i', 71, struct in6_ifreq)
416166506Stegge#define	SIOCGIFPDSTADDR_IN6	_IOWR('i', 72, struct in6_ifreq)
417112694Stegge
418112694Stegge#define SIOCGIFAFLAG_IN6	_IOWR('i', 73, struct in6_ifreq)
419112718Stegge
420112694Stegge#define SIOCGDRLST_IN6		_IOWR('i', 74, struct in6_drlist)
421112694Stegge#ifdef _KERNEL
422166506Stegge/* XXX: SIOCGPRLST_IN6 is exposed in KAME but in6_oprlist is not. */
423112694Stegge#define SIOCGPRLST_IN6		_IOWR('i', 75, struct in6_oprlist)
424112694Stegge#endif
425112694Stegge#ifdef _KERNEL
426112694Stegge#define OSIOCGIFINFO_IN6	_IOWR('i', 76, struct in6_ondireq)
427112694Stegge#endif
428112694Stegge#define SIOCGIFINFO_IN6		_IOWR('i', 108, struct in6_ndireq)
429112694Stegge#define SIOCSIFINFO_IN6		_IOWR('i', 109, struct in6_ndireq)
430112694Stegge#define SIOCSNDFLUSH_IN6	_IOWR('i', 77, struct in6_ifreq)
431112694Stegge#define SIOCGNBRINFO_IN6	_IOWR('i', 78, struct in6_nbrinfo)
432112694Stegge#define SIOCSPFXFLUSH_IN6	_IOWR('i', 79, struct in6_ifreq)
433112694Stegge#define SIOCSRTRFLUSH_IN6	_IOWR('i', 80, struct in6_ifreq)
434112694Stegge
435112694Stegge#define SIOCGIFALIFETIME_IN6	_IOWR('i', 81, struct in6_ifreq)
436112694Stegge#define SIOCSIFALIFETIME_IN6	_IOWR('i', 82, struct in6_ifreq)
437112694Stegge#define SIOCGIFSTAT_IN6		_IOWR('i', 83, struct in6_ifreq)
438112694Stegge#define SIOCGIFSTAT_ICMP6	_IOWR('i', 84, struct in6_ifreq)
439112694Stegge
440112694Stegge#define SIOCSDEFIFACE_IN6	_IOWR('i', 85, struct in6_ndifreq)
441112694Stegge#define SIOCGDEFIFACE_IN6	_IOWR('i', 86, struct in6_ndifreq)
442112694Stegge
443112694Stegge#define SIOCSIFINFO_FLAGS	_IOWR('i', 87, struct in6_ndireq) /* XXX */
444112694Stegge
445130023Stjr#define SIOCSSCOPE6		_IOW('i', 88, struct in6_ifreq)
446130023Stjr#define SIOCGSCOPE6		_IOWR('i', 89, struct in6_ifreq)
447112694Stegge#define SIOCGSCOPE6DEF		_IOWR('i', 90, struct in6_ifreq)
448112694Stegge
449112694Stegge#define SIOCSIFPREFIX_IN6	_IOW('i', 100, struct in6_prefixreq) /* set */
450112694Stegge#define SIOCGIFPREFIX_IN6	_IOWR('i', 101, struct in6_prefixreq) /* get */
451112694Stegge#define SIOCDIFPREFIX_IN6	_IOW('i', 102, struct in6_prefixreq) /* del */
452112694Stegge#define SIOCAIFPREFIX_IN6	_IOW('i', 103, struct in6_rrenumreq) /* add */
453112694Stegge#define SIOCCIFPREFIX_IN6	_IOW('i', 104, \
454112694Stegge				     struct in6_rrenumreq) /* change */
455112694Stegge#define SIOCSGIFPREFIX_IN6	_IOW('i', 105, \
456112694Stegge				     struct in6_rrenumreq) /* set global */
457112694Stegge
458136966Sphk#define SIOCGETSGCNT_IN6	_IOWR('u', 106, \
459112694Stegge				      struct sioc_sg_req6) /* get s,g pkt cnt */
460112694Stegge#define SIOCGETMIFCNT_IN6	_IOWR('u', 107, \
461112694Stegge				      struct sioc_mif_req6) /* get pkt cnt per if */
462112694Stegge
463176559Sattilio#define SIOCAADDRCTL_POLICY	_IOW('u', 108, struct in6_addrpolicy)
464112694Stegge#define SIOCDADDRCTL_POLICY	_IOW('u', 109, struct in6_addrpolicy)
465112694Stegge
466112694Stegge#define IN6_IFF_ANYCAST		0x01	/* anycast address */
467112694Stegge#define IN6_IFF_TENTATIVE	0x02	/* tentative address */
468112694Stegge#define IN6_IFF_DUPLICATED	0x04	/* DAD detected duplicate */
469112694Stegge#define IN6_IFF_DETACHED	0x08	/* may be detached from the link */
470112694Stegge#define IN6_IFF_DEPRECATED	0x10	/* deprecated address */
471112694Stegge#define IN6_IFF_NODAD		0x20	/* don't perform DAD on this address
472112694Stegge					 * (used only at first SIOC* call)
473112694Stegge					 */
474112694Stegge#define IN6_IFF_AUTOCONF	0x40	/* autoconfigurable address. */
475112694Stegge#define IN6_IFF_TEMPORARY	0x80	/* temporary (anonymous) address. */
476112694Stegge#define IN6_IFF_NOPFX		0x8000	/* skip kernel prefix management.
477112694Stegge					 * XXX: this should be temporary.
478112694Stegge					 */
479112694Stegge
480112694Stegge/* do not input/output */
481112694Stegge#define IN6_IFF_NOTREADY (IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED)
482112694Stegge
483112694Stegge#ifdef _KERNEL
484112694Stegge#define IN6_ARE_SCOPE_CMP(a,b) ((a)-(b))
485112694Stegge#define IN6_ARE_SCOPE_EQUAL(a,b) ((a)==(b))
486112694Stegge#endif
487112694Stegge
488112694Stegge#ifdef _KERNEL
489112694Stegge#ifdef VIMAGE_GLOBALS
490112694Steggeextern struct in6_ifaddr *in6_ifaddr;
491112694Stegge
492112694Steggeextern struct icmp6stat icmp6stat;
493112694Stegge
494112694Steggeextern unsigned long in6_maxmtu;
495112694Stegge#endif /* VIMAGE_GLOBALS */
496
497extern struct rwlock in6_ifaddr_lock;
498#define	IN6_IFADDR_LOCK_ASSERT(	)	rw_assert(&in6_ifaddr_lock, RA_LOCKED)
499#define	IN6_IFADDR_RLOCK()		rw_rlock(&in6_ifaddr_lock)
500#define	IN6_IFADDR_RLOCK_ASSERT()	rw_assert(&in6_ifaddr_lock, RA_RLOCKED)
501#define	IN6_IFADDR_RUNLOCK()		rw_runlock(&in6_ifaddr_lock)
502#define	IN6_IFADDR_WLOCK()		rw_wlock(&in6_ifaddr_lock)
503#define	IN6_IFADDR_WLOCK_ASSERT()	rw_assert(&in6_ifaddr_lock, RA_WLOCKED)
504#define	IN6_IFADDR_WUNLOCK()		rw_wunlock(&in6_ifaddr_lock)
505
506#define in6_ifstat_inc(ifp, tag) \
507do {								\
508	if (ifp)						\
509		((struct in6_ifextra *)((ifp)->if_afdata[AF_INET6]))->in6_ifstat->tag++; \
510} while (/*CONSTCOND*/ 0)
511
512extern struct in6_addr zeroin6_addr;
513extern u_char inet6ctlerrmap[];
514#endif /* _KERNEL */
515
516/*
517 * IPv6 multicast MLD-layer source entry.
518 */
519struct ip6_msource {
520	RB_ENTRY(ip6_msource)	im6s_link;	/* RB tree links */
521	struct in6_addr		im6s_addr;
522	struct im6s_st {
523		uint16_t	ex;		/* # of exclusive members */
524		uint16_t	in;		/* # of inclusive members */
525	}			im6s_st[2];	/* state at t0, t1 */
526	uint8_t			im6s_stp;	/* pending query */
527};
528RB_HEAD(ip6_msource_tree, ip6_msource);
529
530/*
531 * IPv6 multicast PCB-layer source entry.
532 *
533 * NOTE: overlapping use of struct ip6_msource fields at start.
534 */
535struct in6_msource {
536	RB_ENTRY(ip6_msource)	im6s_link;	/* Common field */
537	struct in6_addr		im6s_addr;	/* Common field */
538	uint8_t			im6sl_st[2];	/* state before/at commit */
539};
540
541#ifdef _KERNEL
542/*
543 * IPv6 source tree comparison function.
544 *
545 * An ordered predicate is necessary; bcmp() is not documented to return
546 * an indication of order, memcmp() is, and is an ISO C99 requirement.
547 */
548static __inline int
549ip6_msource_cmp(const struct ip6_msource *a, const struct ip6_msource *b)
550{
551
552	return (memcmp(&a->im6s_addr, &b->im6s_addr, sizeof(struct in6_addr)));
553}
554RB_PROTOTYPE(ip6_msource_tree, ip6_msource, im6s_link, ip6_msource_cmp);
555#endif /* _KERNEL */
556
557/*
558 * IPv6 multicast PCB-layer group filter descriptor.
559 */
560struct in6_mfilter {
561	struct ip6_msource_tree	im6f_sources; /* source list for (S,G) */
562	u_long			im6f_nsrc;    /* # of source entries */
563	uint8_t			im6f_st[2];   /* state before/at commit */
564};
565
566/*
567 * Legacy KAME IPv6 multicast membership descriptor.
568 */
569struct in6_multi_mship {
570	struct	in6_multi *i6mm_maddr;
571	LIST_ENTRY(in6_multi_mship) i6mm_chain;
572};
573
574/*
575 * IPv6 group descriptor.
576 *
577 * For every entry on an ifnet's if_multiaddrs list which represents
578 * an IP multicast group, there is one of these structures.
579 *
580 * If any source filters are present, then a node will exist in the RB-tree
581 * to permit fast lookup by source whenever an operation takes place.
582 * This permits pre-order traversal when we issue reports.
583 * Source filter trees are kept separately from the socket layer to
584 * greatly simplify locking.
585 *
586 * When MLDv2 is active, in6m_timer is the response to group query timer.
587 * The state-change timer in6m_sctimer is separate; whenever state changes
588 * for the group the state change record is generated and transmitted,
589 * and kept if retransmissions are necessary.
590 *
591 * FUTURE: in6m_link is now only used when groups are being purged
592 * on a detaching ifnet. It could be demoted to a SLIST_ENTRY, but
593 * because it is at the very start of the struct, we can't do this
594 * w/o breaking the ABI for ifmcstat.
595 */
596struct in6_multi {
597	LIST_ENTRY(in6_multi) in6m_entry; /* list glue */
598	struct	in6_addr in6m_addr;	/* IPv6 multicast address */
599	struct	ifnet *in6m_ifp;	/* back pointer to ifnet */
600	struct	ifmultiaddr *in6m_ifma;	/* back pointer to ifmultiaddr */
601	u_int	in6m_refcount;		/* reference count */
602	u_int	in6m_state;		/* state of the membership */
603	u_int	in6m_timer;		/* MLD6 listener report timer */
604
605	/* New fields for MLDv2 follow. */
606	struct mld_ifinfo	*in6m_mli;	/* MLD info */
607	SLIST_ENTRY(in6_multi)	 in6m_nrele;	/* to-be-released by MLD */
608	struct ip6_msource_tree	 in6m_srcs;	/* tree of sources */
609	u_long			 in6m_nsrc;	/* # of tree entries */
610
611	struct ifqueue		 in6m_scq;	/* queue of pending
612						 * state-change packets */
613	struct timeval		 in6m_lastgsrtv;	/* last G-S-R query */
614	uint16_t		 in6m_sctimer;	/* state-change timer */
615	uint16_t		 in6m_scrv;	/* state-change rexmit count */
616
617	/*
618	 * SSM state counters which track state at T0 (the time the last
619	 * state-change report's RV timer went to zero) and T1
620	 * (time of pending report, i.e. now).
621	 * Used for computing MLDv2 state-change reports. Several refcounts
622	 * are maintained here to optimize for common use-cases.
623	 */
624	struct in6m_st {
625		uint16_t	iss_fmode;	/* MLD filter mode */
626		uint16_t	iss_asm;	/* # of ASM listeners */
627		uint16_t	iss_ex;		/* # of exclusive members */
628		uint16_t	iss_in;		/* # of inclusive members */
629		uint16_t	iss_rec;	/* # of recorded sources */
630	}			in6m_st[2];	/* state at t0, t1 */
631};
632
633/*
634 * Helper function to derive the filter mode on a source entry
635 * from its internal counters. Predicates are:
636 *  A source is only excluded if all listeners exclude it.
637 *  A source is only included if no listeners exclude it,
638 *  and at least one listener includes it.
639 * May be used by ifmcstat(8).
640 */
641static __inline uint8_t
642im6s_get_mode(const struct in6_multi *inm, const struct ip6_msource *ims,
643    uint8_t t)
644{
645
646	t = !!t;
647	if (inm->in6m_st[t].iss_ex > 0 &&
648	    inm->in6m_st[t].iss_ex == ims->im6s_st[t].ex)
649		return (MCAST_EXCLUDE);
650	else if (ims->im6s_st[t].in > 0 && ims->im6s_st[t].ex == 0)
651		return (MCAST_INCLUDE);
652	return (MCAST_UNDEFINED);
653}
654
655#ifdef _KERNEL
656
657/*
658 * Lock macros for IPv6 layer multicast address lists.  IPv6 lock goes
659 * before link layer multicast locks in the lock order.  In most cases,
660 * consumers of IN_*_MULTI() macros should acquire the locks before
661 * calling them; users of the in_{add,del}multi() functions should not.
662 */
663extern struct mtx in6_multi_mtx;
664#define	IN6_MULTI_LOCK()		mtx_lock(&in6_multi_mtx)
665#define	IN6_MULTI_UNLOCK()		mtx_unlock(&in6_multi_mtx)
666#define	IN6_MULTI_LOCK_ASSERT()		mtx_assert(&in6_multi_mtx, MA_OWNED)
667#define	IN6_MULTI_UNLOCK_ASSERT()	mtx_assert(&in6_multi_mtx, MA_NOTOWNED)
668
669/*
670 * Look up an in6_multi record for an IPv6 multicast address
671 * on the interface ifp.
672 * If no record found, return NULL.
673 *
674 * SMPng: The IN6_MULTI_LOCK and IF_ADDR_LOCK on ifp must be held.
675 */
676static __inline struct in6_multi *
677in6m_lookup_locked(struct ifnet *ifp, const struct in6_addr *mcaddr)
678{
679	struct ifmultiaddr *ifma;
680	struct in6_multi *inm;
681
682	IN6_MULTI_LOCK_ASSERT();
683	IF_ADDR_LOCK_ASSERT(ifp);
684
685	inm = NULL;
686	TAILQ_FOREACH(ifma, &((ifp)->if_multiaddrs), ifma_link) {
687		if (ifma->ifma_addr->sa_family == AF_INET6) {
688			inm = (struct in6_multi *)ifma->ifma_protospec;
689			if (IN6_ARE_ADDR_EQUAL(&inm->in6m_addr, mcaddr))
690				break;
691			inm = NULL;
692		}
693	}
694	return (inm);
695}
696
697/*
698 * Wrapper for in6m_lookup_locked().
699 *
700 * SMPng: Assumes that neithr the IN6_MULTI_LOCK() or IF_ADDR_LOCK() are held.
701 */
702static __inline struct in6_multi *
703in6m_lookup(struct ifnet *ifp, const struct in6_addr *mcaddr)
704{
705	struct in6_multi *inm;
706
707	IN6_MULTI_LOCK();
708	IF_ADDR_LOCK(ifp);
709	inm = in6m_lookup_locked(ifp, mcaddr);
710	IF_ADDR_UNLOCK(ifp);
711	IN6_MULTI_UNLOCK();
712
713	return (inm);
714}
715
716/* Acquire an in6_multi record. */
717static __inline void
718in6m_acquire_locked(struct in6_multi *inm)
719{
720
721	IN6_MULTI_LOCK_ASSERT();
722	++inm->in6m_refcount;
723}
724
725struct ip6_moptions;
726struct sockopt;
727
728/* Multicast KPIs. */
729int	im6o_mc_filter(const struct ip6_moptions *, const struct ifnet *,
730	    const struct sockaddr *, const struct sockaddr *);
731int	in6_mc_join(struct ifnet *, const struct in6_addr *,
732	    struct in6_mfilter *, struct in6_multi **, int);
733int	in6_mc_join_locked(struct ifnet *, const struct in6_addr *,
734	    struct in6_mfilter *, struct in6_multi **, int);
735int	in6_mc_leave(struct in6_multi *, struct in6_mfilter *);
736int	in6_mc_leave_locked(struct in6_multi *, struct in6_mfilter *);
737void	in6m_clear_recorded(struct in6_multi *);
738void	in6m_commit(struct in6_multi *);
739void	in6m_print(const struct in6_multi *);
740int	in6m_record_source(struct in6_multi *, const struct in6_addr *);
741void	in6m_release_locked(struct in6_multi *);
742void	ip6_freemoptions(struct ip6_moptions *);
743int	ip6_getmoptions(struct inpcb *, struct sockopt *);
744int	ip6_setmoptions(struct inpcb *, struct sockopt *);
745
746/* Legacy KAME multicast KPIs. */
747struct in6_multi_mship *
748	in6_joingroup(struct ifnet *, struct in6_addr *, int *, int);
749int	in6_leavegroup(struct in6_multi_mship *);
750
751/* flags to in6_update_ifa */
752#define IN6_IFAUPDATE_DADDELAY	0x1 /* first time to configure an address */
753
754int	in6_mask2len __P((struct in6_addr *, u_char *));
755int	in6_control __P((struct socket *, u_long, caddr_t, struct ifnet *,
756	struct thread *));
757int	in6_update_ifa __P((struct ifnet *, struct in6_aliasreq *,
758	struct in6_ifaddr *, int));
759void	in6_purgeaddr __P((struct ifaddr *));
760int	in6if_do_dad __P((struct ifnet *));
761void	in6_purgeif __P((struct ifnet *));
762void	in6_savemkludge __P((struct in6_ifaddr *));
763void	*in6_domifattach __P((struct ifnet *));
764void	in6_domifdetach __P((struct ifnet *, void *));
765void	in6_setmaxmtu   __P((void));
766int	in6_if2idlen   __P((struct ifnet *));
767struct in6_ifaddr *in6ifa_ifpforlinklocal __P((struct ifnet *, int));
768struct in6_ifaddr *in6ifa_ifpwithaddr __P((struct ifnet *, struct in6_addr *));
769char	*ip6_sprintf __P((char *, const struct in6_addr *));
770int	in6_addr2zoneid __P((struct ifnet *, struct in6_addr *, u_int32_t *));
771int	in6_matchlen __P((struct in6_addr *, struct in6_addr *));
772int	in6_are_prefix_equal __P((struct in6_addr *, struct in6_addr *, int));
773void	in6_prefixlen2mask __P((struct in6_addr *, int));
774int	in6_prefix_ioctl __P((struct socket *, u_long, caddr_t,
775	struct ifnet *));
776int	in6_prefix_add_ifid __P((int, struct in6_ifaddr *));
777void	in6_prefix_remove_ifid __P((int, struct in6_ifaddr *));
778void	in6_purgeprefix __P((struct ifnet *));
779void	in6_ifremloop(struct ifaddr *);
780void	in6_ifaddloop(struct ifaddr *);
781
782int	in6_is_addr_deprecated __P((struct sockaddr_in6 *));
783struct inpcb;
784int in6_src_ioctl __P((u_long, caddr_t));
785#endif /* _KERNEL */
786
787#endif /* _NETINET6_IN6_VAR_H_ */
788