xref: /freebsd/sys/netinet6/in6_var.h (revision 1e77c1056af387b57cc979d9b6e04107ffc94594)
1caf43b02SWarner Losh /*-
276429de4SYoshinobu Inoue  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
376429de4SYoshinobu Inoue  * All rights reserved.
476429de4SYoshinobu Inoue  *
576429de4SYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
676429de4SYoshinobu Inoue  * modification, are permitted provided that the following conditions
776429de4SYoshinobu Inoue  * are met:
876429de4SYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
976429de4SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
1076429de4SYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
1176429de4SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
1276429de4SYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
1376429de4SYoshinobu Inoue  * 3. Neither the name of the project nor the names of its contributors
1476429de4SYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
1576429de4SYoshinobu Inoue  *    without specific prior written permission.
1676429de4SYoshinobu Inoue  *
1776429de4SYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1876429de4SYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1976429de4SYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2076429de4SYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2176429de4SYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2276429de4SYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2376429de4SYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2476429de4SYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2576429de4SYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2676429de4SYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2776429de4SYoshinobu Inoue  * SUCH DAMAGE.
28b48287a3SDavid E. O'Brien  *
29b48287a3SDavid E. O'Brien  *	$KAME: in6_var.h,v 1.56 2001/03/29 05:34:31 itojun Exp $
3076429de4SYoshinobu Inoue  */
3176429de4SYoshinobu Inoue 
32caf43b02SWarner Losh /*-
3376429de4SYoshinobu Inoue  * Copyright (c) 1985, 1986, 1993
3476429de4SYoshinobu Inoue  *	The Regents of the University of California.  All rights reserved.
3576429de4SYoshinobu Inoue  *
3676429de4SYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
3776429de4SYoshinobu Inoue  * modification, are permitted provided that the following conditions
3876429de4SYoshinobu Inoue  * are met:
3976429de4SYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
4076429de4SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
4176429de4SYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
4276429de4SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
4376429de4SYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
4476429de4SYoshinobu Inoue  * 4. Neither the name of the University nor the names of its contributors
4576429de4SYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
4676429de4SYoshinobu Inoue  *    without specific prior written permission.
4776429de4SYoshinobu Inoue  *
4876429de4SYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
4976429de4SYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
5076429de4SYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
5176429de4SYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
5276429de4SYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5376429de4SYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
5476429de4SYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
5576429de4SYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
5676429de4SYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5776429de4SYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5876429de4SYoshinobu Inoue  * SUCH DAMAGE.
5976429de4SYoshinobu Inoue  *
6076429de4SYoshinobu Inoue  *	@(#)in_var.h	8.1 (Berkeley) 6/10/93
61b48287a3SDavid E. O'Brien  * $FreeBSD$
6276429de4SYoshinobu Inoue  */
6376429de4SYoshinobu Inoue 
6476429de4SYoshinobu Inoue #ifndef _NETINET6_IN6_VAR_H_
6576429de4SYoshinobu Inoue #define _NETINET6_IN6_VAR_H_
6676429de4SYoshinobu Inoue 
6733cde130SBruce M Simpson #include <sys/tree.h>
6833cde130SBruce M Simpson 
6933cde130SBruce M Simpson #ifdef _KERNEL
7033cde130SBruce M Simpson #include <sys/libkern.h>
7133cde130SBruce M Simpson #endif
7233cde130SBruce M Simpson 
7376429de4SYoshinobu Inoue /*
7476429de4SYoshinobu Inoue  * Interface address, Internet version.  One of these structures
7576429de4SYoshinobu Inoue  * is allocated for each interface with an Internet address.
7676429de4SYoshinobu Inoue  * The ifaddr structure contains the protocol-independent part
7776429de4SYoshinobu Inoue  * of the structure and is assumed to be first.
7876429de4SYoshinobu Inoue  */
7976429de4SYoshinobu Inoue 
8076429de4SYoshinobu Inoue /*
8176429de4SYoshinobu Inoue  * pltime/vltime are just for future reference (required to implements 2
8276429de4SYoshinobu Inoue  * hour rule for hosts).  they should never be modified by nd6_timeout or
8376429de4SYoshinobu Inoue  * anywhere else.
8476429de4SYoshinobu Inoue  *	userland -> kernel: accept pltime/vltime
8588ff5695SSUZUKI Shinsuke  *	kernel -> userland: throw up everything
8676429de4SYoshinobu Inoue  *	in kernel: modify preferred/expire only
8776429de4SYoshinobu Inoue  */
8876429de4SYoshinobu Inoue struct in6_addrlifetime {
8976429de4SYoshinobu Inoue 	time_t ia6t_expire;	/* valid lifetime expiration time */
9076429de4SYoshinobu Inoue 	time_t ia6t_preferred;	/* preferred lifetime expiration time */
9176429de4SYoshinobu Inoue 	u_int32_t ia6t_vltime;	/* valid lifetime */
9276429de4SYoshinobu Inoue 	u_int32_t ia6t_pltime;	/* prefix lifetime */
9376429de4SYoshinobu Inoue };
9476429de4SYoshinobu Inoue 
9531b1bfe1SHajimu UMEMOTO struct nd_ifinfo;
9631b1bfe1SHajimu UMEMOTO struct scope6_id;
976e6b3f7cSQing Li struct lltable;
9833cde130SBruce M Simpson struct mld_ifinfo;
9933cde130SBruce M Simpson 
10031b1bfe1SHajimu UMEMOTO struct in6_ifextra {
10131b1bfe1SHajimu UMEMOTO 	struct in6_ifstat *in6_ifstat;
10231b1bfe1SHajimu UMEMOTO 	struct icmp6_ifstat *icmp6_ifstat;
10331b1bfe1SHajimu UMEMOTO 	struct nd_ifinfo *nd_ifinfo;
10431b1bfe1SHajimu UMEMOTO 	struct scope6_id *scope6_id;
1056e6b3f7cSQing Li 	struct lltable *lltable;
10633cde130SBruce M Simpson 	struct mld_ifinfo *mld_ifinfo;
10731b1bfe1SHajimu UMEMOTO };
10831b1bfe1SHajimu UMEMOTO 
1096e6b3f7cSQing Li #define	LLTABLE6(ifp)	(((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->lltable)
1106e6b3f7cSQing Li 
11176429de4SYoshinobu Inoue struct	in6_ifaddr {
11276429de4SYoshinobu Inoue 	struct	ifaddr ia_ifa;		/* protocol-independent info */
11376429de4SYoshinobu Inoue #define	ia_ifp		ia_ifa.ifa_ifp
11476429de4SYoshinobu Inoue #define ia_flags	ia_ifa.ifa_flags
11576429de4SYoshinobu Inoue 	struct	sockaddr_in6 ia_addr;	/* interface address */
11676429de4SYoshinobu Inoue 	struct	sockaddr_in6 ia_net;	/* network number of interface */
11776429de4SYoshinobu Inoue 	struct	sockaddr_in6 ia_dstaddr; /* space for destination addr */
11876429de4SYoshinobu Inoue 	struct	sockaddr_in6 ia_prefixmask; /* prefix mask */
11976429de4SYoshinobu Inoue 	u_int32_t ia_plen;		/* prefix length */
12080af0152SRobert Watson 	TAILQ_ENTRY(in6_ifaddr)	ia_link;	/* list of IPv6 addresses */
12176429de4SYoshinobu Inoue 	int	ia6_flags;
12276429de4SYoshinobu Inoue 
12333841545SHajimu UMEMOTO 	struct in6_addrlifetime ia6_lifetime;
124743eee66SSUZUKI Shinsuke 	time_t	ia6_createtime; /* the creation time of this address, which is
125743eee66SSUZUKI Shinsuke 				 * currently used for temporary addresses only.
126743eee66SSUZUKI Shinsuke 				 */
127743eee66SSUZUKI Shinsuke 	time_t	ia6_updatetime;
12833841545SHajimu UMEMOTO 
1297efe5d92SHajimu UMEMOTO 	/* back pointer to the ND prefix (for autoconfigured addresses only) */
1307efe5d92SHajimu UMEMOTO 	struct nd_prefix *ia6_ndpr;
13109a52a55SJINMEI Tatuya 
13209a52a55SJINMEI Tatuya 	/* multicast addresses joined from the kernel */
13309a52a55SJINMEI Tatuya 	LIST_HEAD(, in6_multi_mship) ia6_memberships;
13476429de4SYoshinobu Inoue };
13576429de4SYoshinobu Inoue 
13680af0152SRobert Watson /* List of in6_ifaddr's. */
13780af0152SRobert Watson TAILQ_HEAD(in6_ifaddrhead, in6_ifaddr);
13880af0152SRobert Watson 
1397fc91b3fSHajimu UMEMOTO /* control structure to manage address selection policy */
1407fc91b3fSHajimu UMEMOTO struct in6_addrpolicy {
1417fc91b3fSHajimu UMEMOTO 	struct sockaddr_in6 addr; /* prefix address */
1427fc91b3fSHajimu UMEMOTO 	struct sockaddr_in6 addrmask; /* prefix mask */
1437fc91b3fSHajimu UMEMOTO 	int preced;		/* precedence */
1447fc91b3fSHajimu UMEMOTO 	int label;		/* matching label */
1457fc91b3fSHajimu UMEMOTO 	u_quad_t use;		/* statistics */
1467fc91b3fSHajimu UMEMOTO };
1477fc91b3fSHajimu UMEMOTO 
14876429de4SYoshinobu Inoue /*
14976429de4SYoshinobu Inoue  * IPv6 interface statistics, as defined in RFC2465 Ipv6IfStatsEntry (p12).
15076429de4SYoshinobu Inoue  */
15176429de4SYoshinobu Inoue struct in6_ifstat {
152686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_receive;	/* # of total input datagram */
153686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_hdrerr;	/* # of datagrams with invalid hdr */
154686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_toobig;	/* # of datagrams exceeded MTU */
155686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_noroute;	/* # of datagrams with no route */
156686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_addrerr;	/* # of datagrams with invalid dst */
157686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_protounknown;	/* # of datagrams with unknown proto */
15876429de4SYoshinobu Inoue 					/* NOTE: increment on final dst if */
159686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_truncated;	/* # of truncated datagrams */
160686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_discard;	/* # of discarded datagrams */
16176429de4SYoshinobu Inoue 					/* NOTE: fragment timeout is not here */
162686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_deliver;	/* # of datagrams delivered to ULP */
16376429de4SYoshinobu Inoue 					/* NOTE: increment on final dst if */
164686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_forward;	/* # of datagrams forwarded */
16576429de4SYoshinobu Inoue 					/* NOTE: increment on outgoing if */
166686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_request;	/* # of outgoing datagrams from ULP */
16776429de4SYoshinobu Inoue 					/* NOTE: does not include forwrads */
168686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_discard;	/* # of discarded datagrams */
169686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_fragok;	/* # of datagrams fragmented */
170686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_fragfail;	/* # of datagrams failed on fragment */
171686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_fragcreat;	/* # of fragment datagrams */
17276429de4SYoshinobu Inoue 					/* NOTE: this is # after fragment */
173686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_reass_reqd;	/* # of incoming fragmented packets */
17476429de4SYoshinobu Inoue 					/* NOTE: increment on final dst if */
175686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_reass_ok;		/* # of reassembled packets */
17676429de4SYoshinobu Inoue 					/* NOTE: this is # after reass */
17776429de4SYoshinobu Inoue 					/* NOTE: increment on final dst if */
178686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_reass_fail;	/* # of reass failures */
17976429de4SYoshinobu Inoue 					/* NOTE: may not be packet count */
18076429de4SYoshinobu Inoue 					/* NOTE: increment on final dst if */
181686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_mcast;		/* # of inbound multicast datagrams */
182686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_mcast;	/* # of outbound multicast datagrams */
18376429de4SYoshinobu Inoue };
18476429de4SYoshinobu Inoue 
18576429de4SYoshinobu Inoue /*
18676429de4SYoshinobu Inoue  * ICMPv6 interface statistics, as defined in RFC2466 Ipv6IfIcmpEntry.
18776429de4SYoshinobu Inoue  * XXX: I'm not sure if this file is the right place for this structure...
18876429de4SYoshinobu Inoue  */
18976429de4SYoshinobu Inoue struct icmp6_ifstat {
19076429de4SYoshinobu Inoue 	/*
19176429de4SYoshinobu Inoue 	 * Input statistics
19276429de4SYoshinobu Inoue 	 */
19376429de4SYoshinobu Inoue 	/* ipv6IfIcmpInMsgs, total # of input messages */
194686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_msg;
19576429de4SYoshinobu Inoue 	/* ipv6IfIcmpInErrors, # of input error messages */
196686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_error;
19776429de4SYoshinobu Inoue 	/* ipv6IfIcmpInDestUnreachs, # of input dest unreach errors */
198686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_dstunreach;
19976429de4SYoshinobu Inoue 	/* ipv6IfIcmpInAdminProhibs, # of input administratively prohibited errs */
200686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_adminprohib;
20176429de4SYoshinobu Inoue 	/* ipv6IfIcmpInTimeExcds, # of input time exceeded errors */
202686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_timeexceed;
20376429de4SYoshinobu Inoue 	/* ipv6IfIcmpInParmProblems, # of input parameter problem errors */
204686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_paramprob;
20576429de4SYoshinobu Inoue 	/* ipv6IfIcmpInPktTooBigs, # of input packet too big errors */
206686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_pkttoobig;
20776429de4SYoshinobu Inoue 	/* ipv6IfIcmpInEchos, # of input echo requests */
208686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_echo;
20976429de4SYoshinobu Inoue 	/* ipv6IfIcmpInEchoReplies, # of input echo replies */
210686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_echoreply;
21176429de4SYoshinobu Inoue 	/* ipv6IfIcmpInRouterSolicits, # of input router solicitations */
212686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_routersolicit;
21376429de4SYoshinobu Inoue 	/* ipv6IfIcmpInRouterAdvertisements, # of input router advertisements */
214686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_routeradvert;
21576429de4SYoshinobu Inoue 	/* ipv6IfIcmpInNeighborSolicits, # of input neighbor solicitations */
216686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_neighborsolicit;
21776429de4SYoshinobu Inoue 	/* ipv6IfIcmpInNeighborAdvertisements, # of input neighbor advertisements */
218686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_neighboradvert;
21976429de4SYoshinobu Inoue 	/* ipv6IfIcmpInRedirects, # of input redirects */
220686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_redirect;
22176429de4SYoshinobu Inoue 	/* ipv6IfIcmpInGroupMembQueries, # of input MLD queries */
222686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_mldquery;
22376429de4SYoshinobu Inoue 	/* ipv6IfIcmpInGroupMembResponses, # of input MLD reports */
224686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_mldreport;
22576429de4SYoshinobu Inoue 	/* ipv6IfIcmpInGroupMembReductions, # of input MLD done */
226686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_in_mlddone;
22776429de4SYoshinobu Inoue 
22876429de4SYoshinobu Inoue 	/*
22976429de4SYoshinobu Inoue 	 * Output statistics. We should solve unresolved routing problem...
23076429de4SYoshinobu Inoue 	 */
23176429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutMsgs, total # of output messages */
232686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_msg;
23376429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutErrors, # of output error messages */
234686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_error;
23576429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutDestUnreachs, # of output dest unreach errors */
236686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_dstunreach;
23776429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutAdminProhibs, # of output administratively prohibited errs */
238686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_adminprohib;
23976429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutTimeExcds, # of output time exceeded errors */
240686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_timeexceed;
24176429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutParmProblems, # of output parameter problem errors */
242686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_paramprob;
24376429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutPktTooBigs, # of output packet too big errors */
244686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_pkttoobig;
24576429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutEchos, # of output echo requests */
246686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_echo;
24776429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutEchoReplies, # of output echo replies */
248686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_echoreply;
24976429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutRouterSolicits, # of output router solicitations */
250686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_routersolicit;
25176429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutRouterAdvertisements, # of output router advertisements */
252686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_routeradvert;
25376429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutNeighborSolicits, # of output neighbor solicitations */
254686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_neighborsolicit;
25576429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutNeighborAdvertisements, # of output neighbor advertisements */
256686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_neighboradvert;
25776429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutRedirects, # of output redirects */
258686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_redirect;
25976429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutGroupMembQueries, # of output MLD queries */
260686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_mldquery;
26176429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutGroupMembResponses, # of output MLD reports */
262686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_mldreport;
26376429de4SYoshinobu Inoue 	/* ipv6IfIcmpOutGroupMembReductions, # of output MLD done */
264686cdd19SJun-ichiro itojun Hagino 	u_quad_t ifs6_out_mlddone;
26576429de4SYoshinobu Inoue };
26676429de4SYoshinobu Inoue 
26776429de4SYoshinobu Inoue struct	in6_ifreq {
26876429de4SYoshinobu Inoue 	char	ifr_name[IFNAMSIZ];
26976429de4SYoshinobu Inoue 	union {
27076429de4SYoshinobu Inoue 		struct	sockaddr_in6 ifru_addr;
27176429de4SYoshinobu Inoue 		struct	sockaddr_in6 ifru_dstaddr;
27262f76486SMaxim Sobolev 		int	ifru_flags;
27376429de4SYoshinobu Inoue 		int	ifru_flags6;
27476429de4SYoshinobu Inoue 		int	ifru_metric;
27576429de4SYoshinobu Inoue 		caddr_t	ifru_data;
27676429de4SYoshinobu Inoue 		struct in6_addrlifetime ifru_lifetime;
27776429de4SYoshinobu Inoue 		struct in6_ifstat ifru_stat;
27876429de4SYoshinobu Inoue 		struct icmp6_ifstat ifru_icmp6stat;
279686cdd19SJun-ichiro itojun Hagino 		u_int32_t ifru_scope_id[16];
28076429de4SYoshinobu Inoue 	} ifr_ifru;
28176429de4SYoshinobu Inoue };
28276429de4SYoshinobu Inoue 
28376429de4SYoshinobu Inoue struct	in6_aliasreq {
28476429de4SYoshinobu Inoue 	char	ifra_name[IFNAMSIZ];
28576429de4SYoshinobu Inoue 	struct	sockaddr_in6 ifra_addr;
28676429de4SYoshinobu Inoue 	struct	sockaddr_in6 ifra_dstaddr;
28776429de4SYoshinobu Inoue 	struct	sockaddr_in6 ifra_prefixmask;
28876429de4SYoshinobu Inoue 	int	ifra_flags;
28976429de4SYoshinobu Inoue 	struct in6_addrlifetime ifra_lifetime;
29076429de4SYoshinobu Inoue };
29176429de4SYoshinobu Inoue 
29276429de4SYoshinobu Inoue /* prefix type macro */
29376429de4SYoshinobu Inoue #define IN6_PREFIX_ND	1
29476429de4SYoshinobu Inoue #define IN6_PREFIX_RR	2
29576429de4SYoshinobu Inoue 
29676429de4SYoshinobu Inoue /*
29776429de4SYoshinobu Inoue  * prefix related flags passed between kernel(NDP related part) and
29876429de4SYoshinobu Inoue  * user land command(ifconfig) and daemon(rtadvd).
29976429de4SYoshinobu Inoue  */
30076429de4SYoshinobu Inoue struct in6_prflags {
30176429de4SYoshinobu Inoue 	struct prf_ra {
30276429de4SYoshinobu Inoue 		u_char onlink : 1;
30376429de4SYoshinobu Inoue 		u_char autonomous : 1;
30476429de4SYoshinobu Inoue 		u_char reserved : 6;
30576429de4SYoshinobu Inoue 	} prf_ra;
30676429de4SYoshinobu Inoue 	u_char prf_reserved1;
30776429de4SYoshinobu Inoue 	u_short prf_reserved2;
30876429de4SYoshinobu Inoue 	/* want to put this on 4byte offset */
30976429de4SYoshinobu Inoue 	struct prf_rr {
31076429de4SYoshinobu Inoue 		u_char decrvalid : 1;
31176429de4SYoshinobu Inoue 		u_char decrprefd : 1;
31276429de4SYoshinobu Inoue 		u_char reserved : 6;
31376429de4SYoshinobu Inoue 	} prf_rr;
31476429de4SYoshinobu Inoue 	u_char prf_reserved3;
31576429de4SYoshinobu Inoue 	u_short prf_reserved4;
31676429de4SYoshinobu Inoue };
31776429de4SYoshinobu Inoue 
31876429de4SYoshinobu Inoue struct  in6_prefixreq {
31976429de4SYoshinobu Inoue 	char	ipr_name[IFNAMSIZ];
32076429de4SYoshinobu Inoue 	u_char	ipr_origin;
32176429de4SYoshinobu Inoue 	u_char	ipr_plen;
32276429de4SYoshinobu Inoue 	u_int32_t ipr_vltime;
32376429de4SYoshinobu Inoue 	u_int32_t ipr_pltime;
32476429de4SYoshinobu Inoue 	struct in6_prflags ipr_flags;
32576429de4SYoshinobu Inoue 	struct	sockaddr_in6 ipr_prefix;
32676429de4SYoshinobu Inoue };
32776429de4SYoshinobu Inoue 
32876429de4SYoshinobu Inoue #define PR_ORIG_RA	0
32976429de4SYoshinobu Inoue #define PR_ORIG_RR	1
33076429de4SYoshinobu Inoue #define PR_ORIG_STATIC	2
33176429de4SYoshinobu Inoue #define PR_ORIG_KERNEL	3
33276429de4SYoshinobu Inoue 
33376429de4SYoshinobu Inoue #define ipr_raf_onlink		ipr_flags.prf_ra.onlink
33476429de4SYoshinobu Inoue #define ipr_raf_auto		ipr_flags.prf_ra.autonomous
33576429de4SYoshinobu Inoue 
33676429de4SYoshinobu Inoue #define ipr_statef_onlink	ipr_flags.prf_state.onlink
33776429de4SYoshinobu Inoue 
33876429de4SYoshinobu Inoue #define ipr_rrf_decrvalid	ipr_flags.prf_rr.decrvalid
33976429de4SYoshinobu Inoue #define ipr_rrf_decrprefd	ipr_flags.prf_rr.decrprefd
34076429de4SYoshinobu Inoue 
34176429de4SYoshinobu Inoue struct	in6_rrenumreq {
34276429de4SYoshinobu Inoue 	char	irr_name[IFNAMSIZ];
34376429de4SYoshinobu Inoue 	u_char	irr_origin;
34476429de4SYoshinobu Inoue 	u_char	irr_m_len;	/* match len for matchprefix */
34576429de4SYoshinobu Inoue 	u_char	irr_m_minlen;	/* minlen for matching prefix */
34676429de4SYoshinobu Inoue 	u_char	irr_m_maxlen;	/* maxlen for matching prefix */
34776429de4SYoshinobu Inoue 	u_char	irr_u_uselen;	/* uselen for adding prefix */
34876429de4SYoshinobu Inoue 	u_char	irr_u_keeplen;	/* keeplen from matching prefix */
34976429de4SYoshinobu Inoue 	struct irr_raflagmask {
35076429de4SYoshinobu Inoue 		u_char onlink : 1;
35176429de4SYoshinobu Inoue 		u_char autonomous : 1;
35276429de4SYoshinobu Inoue 		u_char reserved : 6;
35376429de4SYoshinobu Inoue 	} irr_raflagmask;
35476429de4SYoshinobu Inoue 	u_int32_t irr_vltime;
35576429de4SYoshinobu Inoue 	u_int32_t irr_pltime;
35676429de4SYoshinobu Inoue 	struct in6_prflags irr_flags;
35776429de4SYoshinobu Inoue 	struct	sockaddr_in6 irr_matchprefix;
35876429de4SYoshinobu Inoue 	struct	sockaddr_in6 irr_useprefix;
35976429de4SYoshinobu Inoue };
36076429de4SYoshinobu Inoue 
36176429de4SYoshinobu Inoue #define irr_raf_mask_onlink	irr_raflagmask.onlink
36276429de4SYoshinobu Inoue #define irr_raf_mask_auto	irr_raflagmask.autonomous
36376429de4SYoshinobu Inoue #define irr_raf_mask_reserved	irr_raflagmask.reserved
36476429de4SYoshinobu Inoue 
36576429de4SYoshinobu Inoue #define irr_raf_onlink		irr_flags.prf_ra.onlink
36676429de4SYoshinobu Inoue #define irr_raf_auto		irr_flags.prf_ra.autonomous
36776429de4SYoshinobu Inoue 
36876429de4SYoshinobu Inoue #define irr_statef_onlink	irr_flags.prf_state.onlink
36976429de4SYoshinobu Inoue 
37076429de4SYoshinobu Inoue #define irr_rrf			irr_flags.prf_rr
37176429de4SYoshinobu Inoue #define irr_rrf_decrvalid	irr_flags.prf_rr.decrvalid
37276429de4SYoshinobu Inoue #define irr_rrf_decrprefd	irr_flags.prf_rr.decrprefd
37376429de4SYoshinobu Inoue 
37476429de4SYoshinobu Inoue /*
37576429de4SYoshinobu Inoue  * Given a pointer to an in6_ifaddr (ifaddr),
37676429de4SYoshinobu Inoue  * return a pointer to the addr as a sockaddr_in6
37776429de4SYoshinobu Inoue  */
37876429de4SYoshinobu Inoue #define IA6_IN6(ia)	(&((ia)->ia_addr.sin6_addr))
37976429de4SYoshinobu Inoue #define IA6_DSTIN6(ia)	(&((ia)->ia_dstaddr.sin6_addr))
38076429de4SYoshinobu Inoue #define IA6_MASKIN6(ia)	(&((ia)->ia_prefixmask.sin6_addr))
38176429de4SYoshinobu Inoue #define IA6_SIN6(ia)	(&((ia)->ia_addr))
38276429de4SYoshinobu Inoue #define IA6_DSTSIN6(ia)	(&((ia)->ia_dstaddr))
38376429de4SYoshinobu Inoue #define IFA_IN6(x)	(&((struct sockaddr_in6 *)((x)->ifa_addr))->sin6_addr)
38476429de4SYoshinobu Inoue #define IFA_DSTIN6(x)	(&((struct sockaddr_in6 *)((x)->ifa_dstaddr))->sin6_addr)
38576429de4SYoshinobu Inoue 
38676429de4SYoshinobu Inoue #define IFPR_IN6(x)	(&((struct sockaddr_in6 *)((x)->ifpr_prefix))->sin6_addr)
38776429de4SYoshinobu Inoue 
38876429de4SYoshinobu Inoue #ifdef _KERNEL
38976429de4SYoshinobu Inoue #define IN6_ARE_MASKED_ADDR_EQUAL(d, a, m)	(	\
39076429de4SYoshinobu Inoue 	(((d)->s6_addr32[0] ^ (a)->s6_addr32[0]) & (m)->s6_addr32[0]) == 0 && \
39176429de4SYoshinobu Inoue 	(((d)->s6_addr32[1] ^ (a)->s6_addr32[1]) & (m)->s6_addr32[1]) == 0 && \
39276429de4SYoshinobu Inoue 	(((d)->s6_addr32[2] ^ (a)->s6_addr32[2]) & (m)->s6_addr32[2]) == 0 && \
39376429de4SYoshinobu Inoue 	(((d)->s6_addr32[3] ^ (a)->s6_addr32[3]) & (m)->s6_addr32[3]) == 0 )
39476429de4SYoshinobu Inoue #endif
39576429de4SYoshinobu Inoue 
39676429de4SYoshinobu Inoue #define SIOCSIFADDR_IN6		 _IOW('i', 12, struct in6_ifreq)
39776429de4SYoshinobu Inoue #define SIOCGIFADDR_IN6		_IOWR('i', 33, struct in6_ifreq)
398686cdd19SJun-ichiro itojun Hagino 
399686cdd19SJun-ichiro itojun Hagino #ifdef _KERNEL
400686cdd19SJun-ichiro itojun Hagino /*
401686cdd19SJun-ichiro itojun Hagino  * SIOCSxxx ioctls should be unused (see comments in in6.c), but
402686cdd19SJun-ichiro itojun Hagino  * we do not shift numbers for binary compatibility.
403686cdd19SJun-ichiro itojun Hagino  */
40476429de4SYoshinobu Inoue #define SIOCSIFDSTADDR_IN6	 _IOW('i', 14, struct in6_ifreq)
40576429de4SYoshinobu Inoue #define SIOCSIFNETMASK_IN6	 _IOW('i', 22, struct in6_ifreq)
406686cdd19SJun-ichiro itojun Hagino #endif
407686cdd19SJun-ichiro itojun Hagino 
408686cdd19SJun-ichiro itojun Hagino #define SIOCGIFDSTADDR_IN6	_IOWR('i', 34, struct in6_ifreq)
40976429de4SYoshinobu Inoue #define SIOCGIFNETMASK_IN6	_IOWR('i', 37, struct in6_ifreq)
41076429de4SYoshinobu Inoue 
41176429de4SYoshinobu Inoue #define SIOCDIFADDR_IN6		 _IOW('i', 25, struct in6_ifreq)
41276429de4SYoshinobu Inoue #define SIOCAIFADDR_IN6		 _IOW('i', 26, struct in6_aliasreq)
41376429de4SYoshinobu Inoue 
41476429de4SYoshinobu Inoue #define SIOCSIFPHYADDR_IN6       _IOW('i', 70, struct in6_aliasreq)
41576429de4SYoshinobu Inoue #define	SIOCGIFPSRCADDR_IN6	_IOWR('i', 71, struct in6_ifreq)
41676429de4SYoshinobu Inoue #define	SIOCGIFPDSTADDR_IN6	_IOWR('i', 72, struct in6_ifreq)
41776429de4SYoshinobu Inoue 
41876429de4SYoshinobu Inoue #define SIOCGIFAFLAG_IN6	_IOWR('i', 73, struct in6_ifreq)
41976429de4SYoshinobu Inoue 
42076429de4SYoshinobu Inoue #define SIOCGDRLST_IN6		_IOWR('i', 74, struct in6_drlist)
421f95d4633SHajimu UMEMOTO #ifdef _KERNEL
422f95d4633SHajimu UMEMOTO /* XXX: SIOCGPRLST_IN6 is exposed in KAME but in6_oprlist is not. */
423f95d4633SHajimu UMEMOTO #define SIOCGPRLST_IN6		_IOWR('i', 75, struct in6_oprlist)
424f95d4633SHajimu UMEMOTO #endif
42533841545SHajimu UMEMOTO #ifdef _KERNEL
42633841545SHajimu UMEMOTO #define OSIOCGIFINFO_IN6	_IOWR('i', 76, struct in6_ondireq)
42733841545SHajimu UMEMOTO #endif
42833841545SHajimu UMEMOTO #define SIOCGIFINFO_IN6		_IOWR('i', 108, struct in6_ndireq)
429b9204379SSUZUKI Shinsuke #define SIOCSIFINFO_IN6		_IOWR('i', 109, struct in6_ndireq)
43076429de4SYoshinobu Inoue #define SIOCSNDFLUSH_IN6	_IOWR('i', 77, struct in6_ifreq)
43176429de4SYoshinobu Inoue #define SIOCGNBRINFO_IN6	_IOWR('i', 78, struct in6_nbrinfo)
43276429de4SYoshinobu Inoue #define SIOCSPFXFLUSH_IN6	_IOWR('i', 79, struct in6_ifreq)
43376429de4SYoshinobu Inoue #define SIOCSRTRFLUSH_IN6	_IOWR('i', 80, struct in6_ifreq)
43476429de4SYoshinobu Inoue 
43576429de4SYoshinobu Inoue #define SIOCGIFALIFETIME_IN6	_IOWR('i', 81, struct in6_ifreq)
43676429de4SYoshinobu Inoue #define SIOCSIFALIFETIME_IN6	_IOWR('i', 82, struct in6_ifreq)
43776429de4SYoshinobu Inoue #define SIOCGIFSTAT_IN6		_IOWR('i', 83, struct in6_ifreq)
43876429de4SYoshinobu Inoue #define SIOCGIFSTAT_ICMP6	_IOWR('i', 84, struct in6_ifreq)
43976429de4SYoshinobu Inoue 
440686cdd19SJun-ichiro itojun Hagino #define SIOCSDEFIFACE_IN6	_IOWR('i', 85, struct in6_ndifreq)
441686cdd19SJun-ichiro itojun Hagino #define SIOCGDEFIFACE_IN6	_IOWR('i', 86, struct in6_ndifreq)
442686cdd19SJun-ichiro itojun Hagino 
443686cdd19SJun-ichiro itojun Hagino #define SIOCSIFINFO_FLAGS	_IOWR('i', 87, struct in6_ndireq) /* XXX */
444686cdd19SJun-ichiro itojun Hagino 
445686cdd19SJun-ichiro itojun Hagino #define SIOCSSCOPE6		_IOW('i', 88, struct in6_ifreq)
446686cdd19SJun-ichiro itojun Hagino #define SIOCGSCOPE6		_IOWR('i', 89, struct in6_ifreq)
447686cdd19SJun-ichiro itojun Hagino #define SIOCGSCOPE6DEF		_IOWR('i', 90, struct in6_ifreq)
448686cdd19SJun-ichiro itojun Hagino 
44976429de4SYoshinobu Inoue #define SIOCSIFPREFIX_IN6	_IOW('i', 100, struct in6_prefixreq) /* set */
45076429de4SYoshinobu Inoue #define SIOCGIFPREFIX_IN6	_IOWR('i', 101, struct in6_prefixreq) /* get */
45176429de4SYoshinobu Inoue #define SIOCDIFPREFIX_IN6	_IOW('i', 102, struct in6_prefixreq) /* del */
45276429de4SYoshinobu Inoue #define SIOCAIFPREFIX_IN6	_IOW('i', 103, struct in6_rrenumreq) /* add */
45376429de4SYoshinobu Inoue #define SIOCCIFPREFIX_IN6	_IOW('i', 104, \
45476429de4SYoshinobu Inoue 				     struct in6_rrenumreq) /* change */
45576429de4SYoshinobu Inoue #define SIOCSGIFPREFIX_IN6	_IOW('i', 105, \
45676429de4SYoshinobu Inoue 				     struct in6_rrenumreq) /* set global */
45776429de4SYoshinobu Inoue 
45876429de4SYoshinobu Inoue #define SIOCGETSGCNT_IN6	_IOWR('u', 106, \
45976429de4SYoshinobu Inoue 				      struct sioc_sg_req6) /* get s,g pkt cnt */
46076429de4SYoshinobu Inoue #define SIOCGETMIFCNT_IN6	_IOWR('u', 107, \
46176429de4SYoshinobu Inoue 				      struct sioc_mif_req6) /* get pkt cnt per if */
46276429de4SYoshinobu Inoue 
4637fc91b3fSHajimu UMEMOTO #define SIOCAADDRCTL_POLICY	_IOW('u', 108, struct in6_addrpolicy)
4647fc91b3fSHajimu UMEMOTO #define SIOCDADDRCTL_POLICY	_IOW('u', 109, struct in6_addrpolicy)
4657fc91b3fSHajimu UMEMOTO 
46676429de4SYoshinobu Inoue #define IN6_IFF_ANYCAST		0x01	/* anycast address */
46776429de4SYoshinobu Inoue #define IN6_IFF_TENTATIVE	0x02	/* tentative address */
46876429de4SYoshinobu Inoue #define IN6_IFF_DUPLICATED	0x04	/* DAD detected duplicate */
46976429de4SYoshinobu Inoue #define IN6_IFF_DETACHED	0x08	/* may be detached from the link */
47076429de4SYoshinobu Inoue #define IN6_IFF_DEPRECATED	0x10	/* deprecated address */
47133841545SHajimu UMEMOTO #define IN6_IFF_NODAD		0x20	/* don't perform DAD on this address
47233841545SHajimu UMEMOTO 					 * (used only at first SIOC* call)
47333841545SHajimu UMEMOTO 					 */
47433841545SHajimu UMEMOTO #define IN6_IFF_AUTOCONF	0x40	/* autoconfigurable address. */
47533841545SHajimu UMEMOTO #define IN6_IFF_TEMPORARY	0x80	/* temporary (anonymous) address. */
47633841545SHajimu UMEMOTO #define IN6_IFF_NOPFX		0x8000	/* skip kernel prefix management.
47733841545SHajimu UMEMOTO 					 * XXX: this should be temporary.
47833841545SHajimu UMEMOTO 					 */
47976429de4SYoshinobu Inoue 
48076429de4SYoshinobu Inoue /* do not input/output */
48176429de4SYoshinobu Inoue #define IN6_IFF_NOTREADY (IN6_IFF_TENTATIVE|IN6_IFF_DUPLICATED)
48276429de4SYoshinobu Inoue 
48376429de4SYoshinobu Inoue #ifdef _KERNEL
484686cdd19SJun-ichiro itojun Hagino #define IN6_ARE_SCOPE_CMP(a,b) ((a)-(b))
485686cdd19SJun-ichiro itojun Hagino #define IN6_ARE_SCOPE_EQUAL(a,b) ((a)==(b))
486686cdd19SJun-ichiro itojun Hagino #endif
487686cdd19SJun-ichiro itojun Hagino 
488686cdd19SJun-ichiro itojun Hagino #ifdef _KERNEL
489eddfbb76SRobert Watson VNET_DECLARE(struct in6_ifaddrhead, in6_ifaddrhead);
490eddfbb76SRobert Watson VNET_DECLARE(struct icmp6stat, icmp6stat);
491eddfbb76SRobert Watson VNET_DECLARE(unsigned long, in6_maxmtu);
49276429de4SYoshinobu Inoue 
4931e77c105SRobert Watson #define	V_in6_ifaddrhead		VNET(in6_ifaddrhead)
4941e77c105SRobert Watson #define	V_icmp6stat			VNET(icmp6stat)
4951e77c105SRobert Watson #define	V_in6_maxmtu			VNET(in6_maxmtu)
496d1da0a06SRobert Watson 
497d1da0a06SRobert Watson extern struct rwlock in6_ifaddr_lock;
498d1da0a06SRobert Watson #define	IN6_IFADDR_LOCK_ASSERT(	)	rw_assert(&in6_ifaddr_lock, RA_LOCKED)
499d1da0a06SRobert Watson #define	IN6_IFADDR_RLOCK()		rw_rlock(&in6_ifaddr_lock)
500d1da0a06SRobert Watson #define	IN6_IFADDR_RLOCK_ASSERT()	rw_assert(&in6_ifaddr_lock, RA_RLOCKED)
501d1da0a06SRobert Watson #define	IN6_IFADDR_RUNLOCK()		rw_runlock(&in6_ifaddr_lock)
502d1da0a06SRobert Watson #define	IN6_IFADDR_WLOCK()		rw_wlock(&in6_ifaddr_lock)
503d1da0a06SRobert Watson #define	IN6_IFADDR_WLOCK_ASSERT()	rw_assert(&in6_ifaddr_lock, RA_WLOCKED)
504d1da0a06SRobert Watson #define	IN6_IFADDR_WUNLOCK()		rw_wunlock(&in6_ifaddr_lock)
505d1da0a06SRobert Watson 
50676429de4SYoshinobu Inoue #define in6_ifstat_inc(ifp, tag) \
50776429de4SYoshinobu Inoue do {								\
50831b1bfe1SHajimu UMEMOTO 	if (ifp)						\
50931b1bfe1SHajimu UMEMOTO 		((struct in6_ifextra *)((ifp)->if_afdata[AF_INET6]))->in6_ifstat->tag++; \
5107efe5d92SHajimu UMEMOTO } while (/*CONSTCOND*/ 0)
51176429de4SYoshinobu Inoue 
51276429de4SYoshinobu Inoue extern struct in6_addr zeroin6_addr;
51376429de4SYoshinobu Inoue extern u_char inet6ctlerrmap[];
51476429de4SYoshinobu Inoue #endif /* _KERNEL */
51576429de4SYoshinobu Inoue 
51676429de4SYoshinobu Inoue /*
51733cde130SBruce M Simpson  * IPv6 multicast MLD-layer source entry.
51876429de4SYoshinobu Inoue  */
51933cde130SBruce M Simpson struct ip6_msource {
52033cde130SBruce M Simpson 	RB_ENTRY(ip6_msource)	im6s_link;	/* RB tree links */
52133cde130SBruce M Simpson 	struct in6_addr		im6s_addr;
52233cde130SBruce M Simpson 	struct im6s_st {
52333cde130SBruce M Simpson 		uint16_t	ex;		/* # of exclusive members */
52433cde130SBruce M Simpson 		uint16_t	in;		/* # of inclusive members */
52533cde130SBruce M Simpson 	}			im6s_st[2];	/* state at t0, t1 */
52633cde130SBruce M Simpson 	uint8_t			im6s_stp;	/* pending query */
52776429de4SYoshinobu Inoue };
52833cde130SBruce M Simpson RB_HEAD(ip6_msource_tree, ip6_msource);
52976429de4SYoshinobu Inoue 
53033cde130SBruce M Simpson /*
53133cde130SBruce M Simpson  * IPv6 multicast PCB-layer source entry.
53233cde130SBruce M Simpson  *
53333cde130SBruce M Simpson  * NOTE: overlapping use of struct ip6_msource fields at start.
53433cde130SBruce M Simpson  */
53533cde130SBruce M Simpson struct in6_msource {
53633cde130SBruce M Simpson 	RB_ENTRY(ip6_msource)	im6s_link;	/* Common field */
53733cde130SBruce M Simpson 	struct in6_addr		im6s_addr;	/* Common field */
53833cde130SBruce M Simpson 	uint8_t			im6sl_st[2];	/* state before/at commit */
53976429de4SYoshinobu Inoue };
54076429de4SYoshinobu Inoue 
54176429de4SYoshinobu Inoue #ifdef _KERNEL
54233cde130SBruce M Simpson /*
54333cde130SBruce M Simpson  * IPv6 source tree comparison function.
54433cde130SBruce M Simpson  *
54533cde130SBruce M Simpson  * An ordered predicate is necessary; bcmp() is not documented to return
54633cde130SBruce M Simpson  * an indication of order, memcmp() is, and is an ISO C99 requirement.
54733cde130SBruce M Simpson  */
54833cde130SBruce M Simpson static __inline int
54933cde130SBruce M Simpson ip6_msource_cmp(const struct ip6_msource *a, const struct ip6_msource *b)
55033cde130SBruce M Simpson {
55133cde130SBruce M Simpson 
55233cde130SBruce M Simpson 	return (memcmp(&a->im6s_addr, &b->im6s_addr, sizeof(struct in6_addr)));
55333cde130SBruce M Simpson }
55433cde130SBruce M Simpson RB_PROTOTYPE(ip6_msource_tree, ip6_msource, im6s_link, ip6_msource_cmp);
55533cde130SBruce M Simpson #endif /* _KERNEL */
55633cde130SBruce M Simpson 
55733cde130SBruce M Simpson /*
55833cde130SBruce M Simpson  * IPv6 multicast PCB-layer group filter descriptor.
55933cde130SBruce M Simpson  */
56033cde130SBruce M Simpson struct in6_mfilter {
56133cde130SBruce M Simpson 	struct ip6_msource_tree	im6f_sources; /* source list for (S,G) */
56233cde130SBruce M Simpson 	u_long			im6f_nsrc;    /* # of source entries */
56333cde130SBruce M Simpson 	uint8_t			im6f_st[2];   /* state before/at commit */
56433cde130SBruce M Simpson };
56533cde130SBruce M Simpson 
56633cde130SBruce M Simpson /*
56733cde130SBruce M Simpson  * Legacy KAME IPv6 multicast membership descriptor.
56833cde130SBruce M Simpson  */
56933cde130SBruce M Simpson struct in6_multi_mship {
57033cde130SBruce M Simpson 	struct	in6_multi *i6mm_maddr;
57133cde130SBruce M Simpson 	LIST_ENTRY(in6_multi_mship) i6mm_chain;
57233cde130SBruce M Simpson };
57333cde130SBruce M Simpson 
57433cde130SBruce M Simpson /*
57533cde130SBruce M Simpson  * IPv6 group descriptor.
57633cde130SBruce M Simpson  *
57733cde130SBruce M Simpson  * For every entry on an ifnet's if_multiaddrs list which represents
57833cde130SBruce M Simpson  * an IP multicast group, there is one of these structures.
57933cde130SBruce M Simpson  *
58033cde130SBruce M Simpson  * If any source filters are present, then a node will exist in the RB-tree
58133cde130SBruce M Simpson  * to permit fast lookup by source whenever an operation takes place.
58233cde130SBruce M Simpson  * This permits pre-order traversal when we issue reports.
58333cde130SBruce M Simpson  * Source filter trees are kept separately from the socket layer to
58433cde130SBruce M Simpson  * greatly simplify locking.
58533cde130SBruce M Simpson  *
58633cde130SBruce M Simpson  * When MLDv2 is active, in6m_timer is the response to group query timer.
58733cde130SBruce M Simpson  * The state-change timer in6m_sctimer is separate; whenever state changes
58833cde130SBruce M Simpson  * for the group the state change record is generated and transmitted,
58933cde130SBruce M Simpson  * and kept if retransmissions are necessary.
59033cde130SBruce M Simpson  *
59133cde130SBruce M Simpson  * FUTURE: in6m_link is now only used when groups are being purged
59233cde130SBruce M Simpson  * on a detaching ifnet. It could be demoted to a SLIST_ENTRY, but
59333cde130SBruce M Simpson  * because it is at the very start of the struct, we can't do this
59433cde130SBruce M Simpson  * w/o breaking the ABI for ifmcstat.
59533cde130SBruce M Simpson  */
59633cde130SBruce M Simpson struct in6_multi {
59733cde130SBruce M Simpson 	LIST_ENTRY(in6_multi) in6m_entry; /* list glue */
59833cde130SBruce M Simpson 	struct	in6_addr in6m_addr;	/* IPv6 multicast address */
59933cde130SBruce M Simpson 	struct	ifnet *in6m_ifp;	/* back pointer to ifnet */
60033cde130SBruce M Simpson 	struct	ifmultiaddr *in6m_ifma;	/* back pointer to ifmultiaddr */
60133cde130SBruce M Simpson 	u_int	in6m_refcount;		/* reference count */
60233cde130SBruce M Simpson 	u_int	in6m_state;		/* state of the membership */
60333cde130SBruce M Simpson 	u_int	in6m_timer;		/* MLD6 listener report timer */
60433cde130SBruce M Simpson 
60533cde130SBruce M Simpson 	/* New fields for MLDv2 follow. */
60633cde130SBruce M Simpson 	struct mld_ifinfo	*in6m_mli;	/* MLD info */
60733cde130SBruce M Simpson 	SLIST_ENTRY(in6_multi)	 in6m_nrele;	/* to-be-released by MLD */
60833cde130SBruce M Simpson 	struct ip6_msource_tree	 in6m_srcs;	/* tree of sources */
60933cde130SBruce M Simpson 	u_long			 in6m_nsrc;	/* # of tree entries */
61033cde130SBruce M Simpson 
61133cde130SBruce M Simpson 	struct ifqueue		 in6m_scq;	/* queue of pending
61233cde130SBruce M Simpson 						 * state-change packets */
61333cde130SBruce M Simpson 	struct timeval		 in6m_lastgsrtv;	/* last G-S-R query */
61433cde130SBruce M Simpson 	uint16_t		 in6m_sctimer;	/* state-change timer */
61533cde130SBruce M Simpson 	uint16_t		 in6m_scrv;	/* state-change rexmit count */
61633cde130SBruce M Simpson 
61733cde130SBruce M Simpson 	/*
61833cde130SBruce M Simpson 	 * SSM state counters which track state at T0 (the time the last
61933cde130SBruce M Simpson 	 * state-change report's RV timer went to zero) and T1
62033cde130SBruce M Simpson 	 * (time of pending report, i.e. now).
62133cde130SBruce M Simpson 	 * Used for computing MLDv2 state-change reports. Several refcounts
62233cde130SBruce M Simpson 	 * are maintained here to optimize for common use-cases.
62333cde130SBruce M Simpson 	 */
62433cde130SBruce M Simpson 	struct in6m_st {
62533cde130SBruce M Simpson 		uint16_t	iss_fmode;	/* MLD filter mode */
62633cde130SBruce M Simpson 		uint16_t	iss_asm;	/* # of ASM listeners */
62733cde130SBruce M Simpson 		uint16_t	iss_ex;		/* # of exclusive members */
62833cde130SBruce M Simpson 		uint16_t	iss_in;		/* # of inclusive members */
62933cde130SBruce M Simpson 		uint16_t	iss_rec;	/* # of recorded sources */
63033cde130SBruce M Simpson 	}			in6m_st[2];	/* state at t0, t1 */
63133cde130SBruce M Simpson };
63233cde130SBruce M Simpson 
63333cde130SBruce M Simpson /*
63433cde130SBruce M Simpson  * Helper function to derive the filter mode on a source entry
63533cde130SBruce M Simpson  * from its internal counters. Predicates are:
63633cde130SBruce M Simpson  *  A source is only excluded if all listeners exclude it.
63733cde130SBruce M Simpson  *  A source is only included if no listeners exclude it,
63833cde130SBruce M Simpson  *  and at least one listener includes it.
63933cde130SBruce M Simpson  * May be used by ifmcstat(8).
64033cde130SBruce M Simpson  */
64133cde130SBruce M Simpson static __inline uint8_t
64233cde130SBruce M Simpson im6s_get_mode(const struct in6_multi *inm, const struct ip6_msource *ims,
64333cde130SBruce M Simpson     uint8_t t)
64433cde130SBruce M Simpson {
64533cde130SBruce M Simpson 
64633cde130SBruce M Simpson 	t = !!t;
64733cde130SBruce M Simpson 	if (inm->in6m_st[t].iss_ex > 0 &&
64833cde130SBruce M Simpson 	    inm->in6m_st[t].iss_ex == ims->im6s_st[t].ex)
64933cde130SBruce M Simpson 		return (MCAST_EXCLUDE);
65033cde130SBruce M Simpson 	else if (ims->im6s_st[t].in > 0 && ims->im6s_st[t].ex == 0)
65133cde130SBruce M Simpson 		return (MCAST_INCLUDE);
65233cde130SBruce M Simpson 	return (MCAST_UNDEFINED);
65333cde130SBruce M Simpson }
65433cde130SBruce M Simpson 
65533cde130SBruce M Simpson #ifdef _KERNEL
65633cde130SBruce M Simpson 
65733cde130SBruce M Simpson /*
65833cde130SBruce M Simpson  * Lock macros for IPv6 layer multicast address lists.  IPv6 lock goes
65933cde130SBruce M Simpson  * before link layer multicast locks in the lock order.  In most cases,
66033cde130SBruce M Simpson  * consumers of IN_*_MULTI() macros should acquire the locks before
66133cde130SBruce M Simpson  * calling them; users of the in_{add,del}multi() functions should not.
66233cde130SBruce M Simpson  */
66333cde130SBruce M Simpson extern struct mtx in6_multi_mtx;
66433cde130SBruce M Simpson #define	IN6_MULTI_LOCK()		mtx_lock(&in6_multi_mtx)
66533cde130SBruce M Simpson #define	IN6_MULTI_UNLOCK()		mtx_unlock(&in6_multi_mtx)
66633cde130SBruce M Simpson #define	IN6_MULTI_LOCK_ASSERT()		mtx_assert(&in6_multi_mtx, MA_OWNED)
66733cde130SBruce M Simpson #define	IN6_MULTI_UNLOCK_ASSERT()	mtx_assert(&in6_multi_mtx, MA_NOTOWNED)
66833cde130SBruce M Simpson 
66933cde130SBruce M Simpson /*
67033cde130SBruce M Simpson  * Look up an in6_multi record for an IPv6 multicast address
67133cde130SBruce M Simpson  * on the interface ifp.
67233cde130SBruce M Simpson  * If no record found, return NULL.
67333cde130SBruce M Simpson  *
67433cde130SBruce M Simpson  * SMPng: The IN6_MULTI_LOCK and IF_ADDR_LOCK on ifp must be held.
67533cde130SBruce M Simpson  */
67633cde130SBruce M Simpson static __inline struct in6_multi *
67733cde130SBruce M Simpson in6m_lookup_locked(struct ifnet *ifp, const struct in6_addr *mcaddr)
67833cde130SBruce M Simpson {
67933cde130SBruce M Simpson 	struct ifmultiaddr *ifma;
68033cde130SBruce M Simpson 	struct in6_multi *inm;
68133cde130SBruce M Simpson 
68233cde130SBruce M Simpson 	IN6_MULTI_LOCK_ASSERT();
68333cde130SBruce M Simpson 	IF_ADDR_LOCK_ASSERT(ifp);
68433cde130SBruce M Simpson 
68533cde130SBruce M Simpson 	inm = NULL;
68633cde130SBruce M Simpson 	TAILQ_FOREACH(ifma, &((ifp)->if_multiaddrs), ifma_link) {
68733cde130SBruce M Simpson 		if (ifma->ifma_addr->sa_family == AF_INET6) {
68833cde130SBruce M Simpson 			inm = (struct in6_multi *)ifma->ifma_protospec;
68933cde130SBruce M Simpson 			if (IN6_ARE_ADDR_EQUAL(&inm->in6m_addr, mcaddr))
69033cde130SBruce M Simpson 				break;
69133cde130SBruce M Simpson 			inm = NULL;
69233cde130SBruce M Simpson 		}
69333cde130SBruce M Simpson 	}
69433cde130SBruce M Simpson 	return (inm);
69533cde130SBruce M Simpson }
69633cde130SBruce M Simpson 
69733cde130SBruce M Simpson /*
69833cde130SBruce M Simpson  * Wrapper for in6m_lookup_locked().
69933cde130SBruce M Simpson  *
70033cde130SBruce M Simpson  * SMPng: Assumes that neithr the IN6_MULTI_LOCK() or IF_ADDR_LOCK() are held.
70133cde130SBruce M Simpson  */
70233cde130SBruce M Simpson static __inline struct in6_multi *
70333cde130SBruce M Simpson in6m_lookup(struct ifnet *ifp, const struct in6_addr *mcaddr)
70433cde130SBruce M Simpson {
70533cde130SBruce M Simpson 	struct in6_multi *inm;
70633cde130SBruce M Simpson 
70733cde130SBruce M Simpson 	IN6_MULTI_LOCK();
70833cde130SBruce M Simpson 	IF_ADDR_LOCK(ifp);
70933cde130SBruce M Simpson 	inm = in6m_lookup_locked(ifp, mcaddr);
71033cde130SBruce M Simpson 	IF_ADDR_UNLOCK(ifp);
71133cde130SBruce M Simpson 	IN6_MULTI_UNLOCK();
71233cde130SBruce M Simpson 
71333cde130SBruce M Simpson 	return (inm);
71433cde130SBruce M Simpson }
71533cde130SBruce M Simpson 
71633cde130SBruce M Simpson /* Acquire an in6_multi record. */
71733cde130SBruce M Simpson static __inline void
71833cde130SBruce M Simpson in6m_acquire_locked(struct in6_multi *inm)
71933cde130SBruce M Simpson {
72033cde130SBruce M Simpson 
72133cde130SBruce M Simpson 	IN6_MULTI_LOCK_ASSERT();
72233cde130SBruce M Simpson 	++inm->in6m_refcount;
72333cde130SBruce M Simpson }
72433cde130SBruce M Simpson 
72533cde130SBruce M Simpson struct ip6_moptions;
72633cde130SBruce M Simpson struct sockopt;
72733cde130SBruce M Simpson 
72833cde130SBruce M Simpson /* Multicast KPIs. */
72933cde130SBruce M Simpson int	im6o_mc_filter(const struct ip6_moptions *, const struct ifnet *,
73033cde130SBruce M Simpson 	    const struct sockaddr *, const struct sockaddr *);
73133cde130SBruce M Simpson int	in6_mc_join(struct ifnet *, const struct in6_addr *,
73233cde130SBruce M Simpson 	    struct in6_mfilter *, struct in6_multi **, int);
73333cde130SBruce M Simpson int	in6_mc_join_locked(struct ifnet *, const struct in6_addr *,
73433cde130SBruce M Simpson 	    struct in6_mfilter *, struct in6_multi **, int);
73533cde130SBruce M Simpson int	in6_mc_leave(struct in6_multi *, struct in6_mfilter *);
73633cde130SBruce M Simpson int	in6_mc_leave_locked(struct in6_multi *, struct in6_mfilter *);
73733cde130SBruce M Simpson void	in6m_clear_recorded(struct in6_multi *);
73833cde130SBruce M Simpson void	in6m_commit(struct in6_multi *);
73933cde130SBruce M Simpson void	in6m_print(const struct in6_multi *);
74033cde130SBruce M Simpson int	in6m_record_source(struct in6_multi *, const struct in6_addr *);
74133cde130SBruce M Simpson void	in6m_release_locked(struct in6_multi *);
74233cde130SBruce M Simpson void	ip6_freemoptions(struct ip6_moptions *);
74333cde130SBruce M Simpson int	ip6_getmoptions(struct inpcb *, struct sockopt *);
74433cde130SBruce M Simpson int	ip6_setmoptions(struct inpcb *, struct sockopt *);
74533cde130SBruce M Simpson 
74633cde130SBruce M Simpson /* Legacy KAME multicast KPIs. */
74733cde130SBruce M Simpson struct in6_multi_mship *
74833cde130SBruce M Simpson 	in6_joingroup(struct ifnet *, struct in6_addr *, int *, int);
74933cde130SBruce M Simpson int	in6_leavegroup(struct in6_multi_mship *);
75033cde130SBruce M Simpson 
751743eee66SSUZUKI Shinsuke /* flags to in6_update_ifa */
752743eee66SSUZUKI Shinsuke #define IN6_IFAUPDATE_DADDELAY	0x1 /* first time to configure an address */
753743eee66SSUZUKI Shinsuke 
754ae360dddSHajimu UMEMOTO int	in6_mask2len __P((struct in6_addr *, u_char *));
7557efe5d92SHajimu UMEMOTO int	in6_control __P((struct socket *, u_long, caddr_t, struct ifnet *,
7567efe5d92SHajimu UMEMOTO 	struct thread *));
75733841545SHajimu UMEMOTO int	in6_update_ifa __P((struct ifnet *, struct in6_aliasreq *,
758743eee66SSUZUKI Shinsuke 	struct in6_ifaddr *, int));
75933841545SHajimu UMEMOTO void	in6_purgeaddr __P((struct ifaddr *));
76033841545SHajimu UMEMOTO int	in6if_do_dad __P((struct ifnet *));
76133841545SHajimu UMEMOTO void	in6_purgeif __P((struct ifnet *));
76276429de4SYoshinobu Inoue void	in6_savemkludge __P((struct in6_ifaddr *));
76331b1bfe1SHajimu UMEMOTO void	*in6_domifattach __P((struct ifnet *));
76431b1bfe1SHajimu UMEMOTO void	in6_domifdetach __P((struct ifnet *, void *));
76576429de4SYoshinobu Inoue void	in6_setmaxmtu   __P((void));
766743eee66SSUZUKI Shinsuke int	in6_if2idlen   __P((struct ifnet *));
767686cdd19SJun-ichiro itojun Hagino struct in6_ifaddr *in6ifa_ifpforlinklocal __P((struct ifnet *, int));
7687efe5d92SHajimu UMEMOTO struct in6_ifaddr *in6ifa_ifpwithaddr __P((struct ifnet *, struct in6_addr *));
7691d54aa3bSBjoern A. Zeeb char	*ip6_sprintf __P((char *, const struct in6_addr *));
7709a4f9608SHajimu UMEMOTO int	in6_addr2zoneid __P((struct ifnet *, struct in6_addr *, u_int32_t *));
77176429de4SYoshinobu Inoue int	in6_matchlen __P((struct in6_addr *, struct in6_addr *));
7727efe5d92SHajimu UMEMOTO int	in6_are_prefix_equal __P((struct in6_addr *, struct in6_addr *, int));
7737efe5d92SHajimu UMEMOTO void	in6_prefixlen2mask __P((struct in6_addr *, int));
7747efe5d92SHajimu UMEMOTO int	in6_prefix_ioctl __P((struct socket *, u_long, caddr_t,
7757efe5d92SHajimu UMEMOTO 	struct ifnet *));
7767efe5d92SHajimu UMEMOTO int	in6_prefix_add_ifid __P((int, struct in6_ifaddr *));
7777efe5d92SHajimu UMEMOTO void	in6_prefix_remove_ifid __P((int, struct in6_ifaddr *));
778686cdd19SJun-ichiro itojun Hagino void	in6_purgeprefix __P((struct ifnet *));
779a9771948SGleb Smirnoff void	in6_ifremloop(struct ifaddr *);
780a9771948SGleb Smirnoff void	in6_ifaddloop(struct ifaddr *);
78133841545SHajimu UMEMOTO 
78233841545SHajimu UMEMOTO int	in6_is_addr_deprecated __P((struct sockaddr_in6 *));
78333841545SHajimu UMEMOTO struct inpcb;
7847fc91b3fSHajimu UMEMOTO int in6_src_ioctl __P((u_long, caddr_t));
78576429de4SYoshinobu Inoue #endif /* _KERNEL */
78676429de4SYoshinobu Inoue 
78776429de4SYoshinobu Inoue #endif /* _NETINET6_IN6_VAR_H_ */
788