xref: /freebsd/sys/netinet6/nd6.h (revision 8482aa77481a1576df7a19dbeaccb91243fbb2a3)
1caf43b02SWarner Losh /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
482cd038dSYoshinobu Inoue  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
582cd038dSYoshinobu Inoue  * All rights reserved.
682cd038dSYoshinobu Inoue  *
782cd038dSYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
882cd038dSYoshinobu Inoue  * modification, are permitted provided that the following conditions
982cd038dSYoshinobu Inoue  * are met:
1082cd038dSYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
1182cd038dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
1282cd038dSYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
1382cd038dSYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
1482cd038dSYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
1582cd038dSYoshinobu Inoue  * 3. Neither the name of the project nor the names of its contributors
1682cd038dSYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
1782cd038dSYoshinobu Inoue  *    without specific prior written permission.
1882cd038dSYoshinobu Inoue  *
1982cd038dSYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
2082cd038dSYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2182cd038dSYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2282cd038dSYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2382cd038dSYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2482cd038dSYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2582cd038dSYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2682cd038dSYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2782cd038dSYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2882cd038dSYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2982cd038dSYoshinobu Inoue  * SUCH DAMAGE.
30b48287a3SDavid E. O'Brien  *
31b48287a3SDavid E. O'Brien  *	$KAME: nd6.h,v 1.76 2001/12/18 02:10:31 itojun Exp $
32b48287a3SDavid E. O'Brien  * $FreeBSD$
3382cd038dSYoshinobu Inoue  */
3482cd038dSYoshinobu Inoue 
3582cd038dSYoshinobu Inoue #ifndef _NETINET6_ND6_H_
3682cd038dSYoshinobu Inoue #define _NETINET6_ND6_H_
3782cd038dSYoshinobu Inoue 
38686cdd19SJun-ichiro itojun Hagino /* see net/route.h, or net/if_inarp.h */
39686cdd19SJun-ichiro itojun Hagino #ifndef RTF_ANNOUNCE
40686cdd19SJun-ichiro itojun Hagino #define RTF_ANNOUNCE	RTF_PROTO2
41686cdd19SJun-ichiro itojun Hagino #endif
42686cdd19SJun-ichiro itojun Hagino 
4382cd038dSYoshinobu Inoue #include <sys/queue.h>
4433841545SHajimu UMEMOTO #include <sys/callout.h>
4582cd038dSYoshinobu Inoue 
466e6b3f7cSQing Li struct llentry;
4782cd038dSYoshinobu Inoue 
4882cd038dSYoshinobu Inoue #define ND6_LLINFO_NOSTATE	-2
4933841545SHajimu UMEMOTO /*
5033841545SHajimu UMEMOTO  * We don't need the WAITDELETE state any more, but we keep the definition
5133841545SHajimu UMEMOTO  * in a comment line instead of removing it. This is necessary to avoid
5233841545SHajimu UMEMOTO  * unintentionally reusing the value for another purpose, which might
5333841545SHajimu UMEMOTO  * affect backward compatibility with old applications.
5433841545SHajimu UMEMOTO  * (20000711 jinmei@kame.net)
5533841545SHajimu UMEMOTO  */
5633841545SHajimu UMEMOTO /* #define ND6_LLINFO_WAITDELETE	-1 */
5782cd038dSYoshinobu Inoue #define ND6_LLINFO_INCOMPLETE	0
5882cd038dSYoshinobu Inoue #define ND6_LLINFO_REACHABLE	1
5982cd038dSYoshinobu Inoue #define ND6_LLINFO_STALE	2
6082cd038dSYoshinobu Inoue #define ND6_LLINFO_DELAY	3
6182cd038dSYoshinobu Inoue #define ND6_LLINFO_PROBE	4
6282cd038dSYoshinobu Inoue 
63686cdd19SJun-ichiro itojun Hagino #define ND6_IS_LLINFO_PROBREACH(n) ((n)->ln_state > ND6_LLINFO_INCOMPLETE)
646e6b3f7cSQing Li #define ND6_LLINFO_PERMANENT(n) (((n)->la_expire == 0) && ((n)->ln_state > ND6_LLINFO_INCOMPLETE))
65686cdd19SJun-ichiro itojun Hagino 
6682cd038dSYoshinobu Inoue struct nd_ifinfo {
6782cd038dSYoshinobu Inoue 	u_int32_t linkmtu;		/* LinkMTU */
6882cd038dSYoshinobu Inoue 	u_int32_t maxmtu;		/* Upper bound of LinkMTU */
6982cd038dSYoshinobu Inoue 	u_int32_t basereachable;	/* BaseReachableTime */
7082cd038dSYoshinobu Inoue 	u_int32_t reachable;		/* Reachable Time */
7182cd038dSYoshinobu Inoue 	u_int32_t retrans;		/* Retrans Timer */
72686cdd19SJun-ichiro itojun Hagino 	u_int32_t flags;		/* Flags */
7382cd038dSYoshinobu Inoue 	int recalctm;			/* BaseReacable re-calculation timer */
7482cd038dSYoshinobu Inoue 	u_int8_t chlim;			/* CurHopLimit */
7531b1bfe1SHajimu UMEMOTO 	u_int8_t initialized; /* Flag to see the entry is initialized */
7688ff5695SSUZUKI Shinsuke 	/* the following 3 members are for privacy extension for addrconf */
7733841545SHajimu UMEMOTO 	u_int8_t randomseed0[8]; /* upper 64 bits of MD5 digest */
7833841545SHajimu UMEMOTO 	u_int8_t randomseed1[8]; /* lower 64 bits (usually the EUI64 IFID) */
7933841545SHajimu UMEMOTO 	u_int8_t randomid[8];	/* current random ID */
8082cd038dSYoshinobu Inoue };
8182cd038dSYoshinobu Inoue 
82686cdd19SJun-ichiro itojun Hagino #define ND6_IFF_PERFORMNUD	0x1
8307cf047dSHajimu UMEMOTO #define ND6_IFF_ACCEPT_RTADV	0x2
84f6c336feSHiroki Sato #define ND6_IFF_PREFER_SOURCE	0x4 /* Not used in FreeBSD. */
855b27b045SSUZUKI Shinsuke #define ND6_IFF_IFDISABLED	0x8 /* IPv6 operation is disabled due to
865b27b045SSUZUKI Shinsuke 				     * DAD failure.  (XXX: not ND-specific)
875b27b045SSUZUKI Shinsuke 				     */
88743eee66SSUZUKI Shinsuke #define ND6_IFF_DONT_SET_IFROUTE	0x10
89a283298cSHiroki Sato #define ND6_IFF_AUTO_LINKLOCAL	0x20
90e7fa8d0aSHiroki Sato #define	ND6_IFF_NO_RADR		0x40
91164051ceSHajimu UMEMOTO #define ND6_IFF_NO_PREFER_IFACE	0x80 /* XXX: not related to ND. */
9259333867SHiroki Sato #define ND6_IFF_NO_DAD		0x100
93201100c5SBjoern A. Zeeb #ifdef EXPERIMENTAL
9421231a7aSBjoern A. Zeeb /* XXX: not related to ND. */
95201100c5SBjoern A. Zeeb #define	ND6_IFF_IPV6_ONLY	0x200 /* draft-ietf-6man-ipv6only-flag */
9621231a7aSBjoern A. Zeeb #define	ND6_IFF_IPV6_ONLY_MANUAL	0x400
9721231a7aSBjoern A. Zeeb #define	ND6_IFF_IPV6_ONLY_MASK	(ND6_IFF_IPV6_ONLY|ND6_IFF_IPV6_ONLY_MANUAL)
98201100c5SBjoern A. Zeeb #endif
99686cdd19SJun-ichiro itojun Hagino 
10031b1bfe1SHajimu UMEMOTO #ifdef _KERNEL
10131b1bfe1SHajimu UMEMOTO #define ND_IFINFO(ifp) \
10231b1bfe1SHajimu UMEMOTO 	(((struct in6_ifextra *)(ifp)->if_afdata[AF_INET6])->nd_ifinfo)
10331b1bfe1SHajimu UMEMOTO #define IN6_LINKMTU(ifp) \
10431b1bfe1SHajimu UMEMOTO 	((ND_IFINFO(ifp)->linkmtu && ND_IFINFO(ifp)->linkmtu < (ifp)->if_mtu) \
10531b1bfe1SHajimu UMEMOTO 	    ? ND_IFINFO(ifp)->linkmtu \
10631b1bfe1SHajimu UMEMOTO 	    : ((ND_IFINFO(ifp)->maxmtu && ND_IFINFO(ifp)->maxmtu < (ifp)->if_mtu) \
10731b1bfe1SHajimu UMEMOTO 		? ND_IFINFO(ifp)->maxmtu : (ifp)->if_mtu))
10831b1bfe1SHajimu UMEMOTO #endif
10931b1bfe1SHajimu UMEMOTO 
11082cd038dSYoshinobu Inoue struct in6_nbrinfo {
11182cd038dSYoshinobu Inoue 	char ifname[IFNAMSIZ];	/* if name, e.g. "en0" */
11282cd038dSYoshinobu Inoue 	struct in6_addr addr;	/* IPv6 address of the neighbor */
11382cd038dSYoshinobu Inoue 	long	asked;		/* number of queries already sent for this addr */
11482cd038dSYoshinobu Inoue 	int	isrouter;	/* if it acts as a router */
11582cd038dSYoshinobu Inoue 	int	state;		/* reachability state */
11682cd038dSYoshinobu Inoue 	int	expire;		/* lifetime for NDP state transition */
11782cd038dSYoshinobu Inoue };
11882cd038dSYoshinobu Inoue 
119b3a25d29SBjoern A. Zeeb /* Sysctls, shared with user space. */
12033841545SHajimu UMEMOTO struct	in6_defrouter {
12133841545SHajimu UMEMOTO 	struct	sockaddr_in6 rtaddr;
12233841545SHajimu UMEMOTO 	u_char	flags;
12333841545SHajimu UMEMOTO 	u_short	rtlifetime;
12433841545SHajimu UMEMOTO 	u_long	expire;
12533841545SHajimu UMEMOTO 	u_short if_index;
12623cd8d58SHidetoshi Shimokawa };
12733841545SHajimu UMEMOTO 
12833841545SHajimu UMEMOTO struct in6_prefix {
12933841545SHajimu UMEMOTO 	struct	sockaddr_in6 prefix;
13033841545SHajimu UMEMOTO 	struct prf_ra raflags;
13133841545SHajimu UMEMOTO 	u_char	prefixlen;
13233841545SHajimu UMEMOTO 	u_char	origin;
133f95d4633SHajimu UMEMOTO 	u_int32_t vltime;
134f95d4633SHajimu UMEMOTO 	u_int32_t pltime;
135f95d4633SHajimu UMEMOTO 	time_t expire;
13633841545SHajimu UMEMOTO 	u_int32_t flags;
13733841545SHajimu UMEMOTO 	int refcnt;
13833841545SHajimu UMEMOTO 	u_short if_index;
13933841545SHajimu UMEMOTO 	u_short advrtrs; /* number of advertisement routers */
14033841545SHajimu UMEMOTO 	/* struct sockaddr_in6 advrtr[] */
14123cd8d58SHidetoshi Shimokawa };
14233841545SHajimu UMEMOTO 
14333841545SHajimu UMEMOTO #ifdef _KERNEL
14433841545SHajimu UMEMOTO struct	in6_ondireq {
14533841545SHajimu UMEMOTO 	char ifname[IFNAMSIZ];
14633841545SHajimu UMEMOTO 	struct {
14733841545SHajimu UMEMOTO 		u_int32_t linkmtu;	/* LinkMTU */
14833841545SHajimu UMEMOTO 		u_int32_t maxmtu;	/* Upper bound of LinkMTU */
14933841545SHajimu UMEMOTO 		u_int32_t basereachable; /* BaseReachableTime */
15033841545SHajimu UMEMOTO 		u_int32_t reachable;	/* Reachable Time */
15133841545SHajimu UMEMOTO 		u_int32_t retrans;	/* Retrans Timer */
15233841545SHajimu UMEMOTO 		u_int32_t flags;	/* Flags */
15333841545SHajimu UMEMOTO 		int recalctm;		/* BaseReacable re-calculation timer */
15433841545SHajimu UMEMOTO 		u_int8_t chlim;		/* CurHopLimit */
15533841545SHajimu UMEMOTO 		u_int8_t receivedra;
15633841545SHajimu UMEMOTO 	} ndi;
15733841545SHajimu UMEMOTO };
15833841545SHajimu UMEMOTO #endif
15933841545SHajimu UMEMOTO 
16082cd038dSYoshinobu Inoue struct	in6_ndireq {
16182cd038dSYoshinobu Inoue 	char ifname[IFNAMSIZ];
16282cd038dSYoshinobu Inoue 	struct nd_ifinfo ndi;
16382cd038dSYoshinobu Inoue };
16482cd038dSYoshinobu Inoue 
165686cdd19SJun-ichiro itojun Hagino struct	in6_ndifreq {
166686cdd19SJun-ichiro itojun Hagino 	char ifname[IFNAMSIZ];
167686cdd19SJun-ichiro itojun Hagino 	u_long ifindex;
168686cdd19SJun-ichiro itojun Hagino };
169686cdd19SJun-ichiro itojun Hagino 
17033841545SHajimu UMEMOTO /* Prefix status */
17133841545SHajimu UMEMOTO #define NDPRF_ONLINK		0x1
17233841545SHajimu UMEMOTO #define NDPRF_DETACHED		0x2
173686cdd19SJun-ichiro itojun Hagino 
17482cd038dSYoshinobu Inoue /* protocol constants */
17582cd038dSYoshinobu Inoue #define MAX_RTR_SOLICITATION_DELAY	1	/* 1sec */
17682cd038dSYoshinobu Inoue #define RTR_SOLICITATION_INTERVAL	4	/* 4sec */
17782cd038dSYoshinobu Inoue #define MAX_RTR_SOLICITATIONS		3
17882cd038dSYoshinobu Inoue 
17982cd038dSYoshinobu Inoue #define ND6_INFINITE_LIFETIME		0xffffffff
18082cd038dSYoshinobu Inoue 
18182cd038dSYoshinobu Inoue #ifdef _KERNEL
18282cd038dSYoshinobu Inoue /* node constants */
18382cd038dSYoshinobu Inoue #define MAX_REACHABLE_TIME		3600000	/* msec */
18482cd038dSYoshinobu Inoue #define REACHABLE_TIME			30000	/* msec */
18582cd038dSYoshinobu Inoue #define RETRANS_TIMER			1000	/* msec */
18682cd038dSYoshinobu Inoue #define MIN_RANDOM_FACTOR		512	/* 1024 * 0.5 */
18782cd038dSYoshinobu Inoue #define MAX_RANDOM_FACTOR		1536	/* 1024 * 1.5 */
18833841545SHajimu UMEMOTO #define DEF_TEMP_VALID_LIFETIME		604800	/* 1 week */
18933841545SHajimu UMEMOTO #define DEF_TEMP_PREFERRED_LIFETIME	86400	/* 1 day */
19033841545SHajimu UMEMOTO #define TEMPADDR_REGEN_ADVANCE		5	/* sec */
19133841545SHajimu UMEMOTO #define MAX_TEMP_DESYNC_FACTOR		600	/* 10 min */
19282cd038dSYoshinobu Inoue #define ND_COMPUTE_RTIME(x) \
193a02e1e2bSHajimu UMEMOTO 		(((MIN_RANDOM_FACTOR * (x >> 10)) + (arc4random() & \
19482cd038dSYoshinobu Inoue 		((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000)
19582cd038dSYoshinobu Inoue 
19682cd038dSYoshinobu Inoue struct nd_defrouter {
197686cdd19SJun-ichiro itojun Hagino 	TAILQ_ENTRY(nd_defrouter) dr_entry;
19882cd038dSYoshinobu Inoue 	struct in6_addr rtaddr;
19901869be5SMark Johnston 	u_char	raflags;	/* flags on RA message */
20082cd038dSYoshinobu Inoue 	u_short	rtlifetime;
20182cd038dSYoshinobu Inoue 	u_long	expire;
20282cd038dSYoshinobu Inoue 	struct ifnet *ifp;
203743eee66SSUZUKI Shinsuke 	int	installed;	/* is installed into kernel routing table */
2044de485feSMark Johnston 	u_int	refcnt;
20582cd038dSYoshinobu Inoue };
20682cd038dSYoshinobu Inoue 
207743eee66SSUZUKI Shinsuke struct nd_prefixctl {
208743eee66SSUZUKI Shinsuke 	struct ifnet *ndpr_ifp;
209743eee66SSUZUKI Shinsuke 
210743eee66SSUZUKI Shinsuke 	/* prefix */
211743eee66SSUZUKI Shinsuke 	struct sockaddr_in6 ndpr_prefix;
212743eee66SSUZUKI Shinsuke 	u_char	ndpr_plen;
213743eee66SSUZUKI Shinsuke 
214743eee66SSUZUKI Shinsuke 	u_int32_t ndpr_vltime;	/* advertised valid lifetime */
215743eee66SSUZUKI Shinsuke 	u_int32_t ndpr_pltime;	/* advertised preferred lifetime */
216743eee66SSUZUKI Shinsuke 
217743eee66SSUZUKI Shinsuke 	struct prf_ra ndpr_flags;
218743eee66SSUZUKI Shinsuke };
219743eee66SSUZUKI Shinsuke 
220d748f7efSMark Johnston LIST_HEAD(nd_prhead, nd_prefix);
22182cd038dSYoshinobu Inoue struct nd_prefix {
22282cd038dSYoshinobu Inoue 	struct ifnet *ndpr_ifp;
223e3975643SJake Burkholder 	LIST_ENTRY(nd_prefix) ndpr_entry;
22482cd038dSYoshinobu Inoue 	struct sockaddr_in6 ndpr_prefix;	/* prefix */
22582cd038dSYoshinobu Inoue 	struct in6_addr ndpr_mask; /* netmask derived from the prefix */
226743eee66SSUZUKI Shinsuke 
22782cd038dSYoshinobu Inoue 	u_int32_t ndpr_vltime;	/* advertised valid lifetime */
22882cd038dSYoshinobu Inoue 	u_int32_t ndpr_pltime;	/* advertised preferred lifetime */
229743eee66SSUZUKI Shinsuke 
23082cd038dSYoshinobu Inoue 	time_t ndpr_expire;	/* expiration time of the prefix */
23182cd038dSYoshinobu Inoue 	time_t ndpr_preferred;	/* preferred time of the prefix */
232743eee66SSUZUKI Shinsuke 	time_t ndpr_lastupdate; /* reception time of last advertisement */
233743eee66SSUZUKI Shinsuke 
23482cd038dSYoshinobu Inoue 	struct prf_ra ndpr_flags;
23533841545SHajimu UMEMOTO 	u_int32_t ndpr_stateflags; /* actual state flags */
23682cd038dSYoshinobu Inoue 	/* list of routers that advertise the prefix: */
237e3975643SJake Burkholder 	LIST_HEAD(pr_rtrhead, nd_pfxrouter) ndpr_advrtrs;
23882cd038dSYoshinobu Inoue 	u_char	ndpr_plen;
2390bbf244eSMark Johnston 	int	ndpr_addrcnt;	/* count of derived addresses */
240d748f7efSMark Johnston 	volatile u_int ndpr_refcnt;
24182cd038dSYoshinobu Inoue };
24282cd038dSYoshinobu Inoue 
24382cd038dSYoshinobu Inoue #define ndpr_raf		ndpr_flags
24482cd038dSYoshinobu Inoue #define ndpr_raf_onlink		ndpr_flags.onlink
24582cd038dSYoshinobu Inoue #define ndpr_raf_auto		ndpr_flags.autonomous
246743eee66SSUZUKI Shinsuke #define ndpr_raf_router		ndpr_flags.router
24782cd038dSYoshinobu Inoue 
24882cd038dSYoshinobu Inoue struct nd_pfxrouter {
249e3975643SJake Burkholder 	LIST_ENTRY(nd_pfxrouter) pfr_entry;
25082cd038dSYoshinobu Inoue 	struct nd_defrouter *router;
25182cd038dSYoshinobu Inoue };
25282cd038dSYoshinobu Inoue 
2535e0a6f31SMark Johnston #ifdef MALLOC_DECLARE
2545e0a6f31SMark Johnston MALLOC_DECLARE(M_IP6NDP);
2555e0a6f31SMark Johnston #endif
2565e0a6f31SMark Johnston 
25782cd038dSYoshinobu Inoue /* nd6.c */
258eddfbb76SRobert Watson VNET_DECLARE(int, nd6_prune);
259eddfbb76SRobert Watson VNET_DECLARE(int, nd6_delay);
260eddfbb76SRobert Watson VNET_DECLARE(int, nd6_umaxtries);
261eddfbb76SRobert Watson VNET_DECLARE(int, nd6_mmaxtries);
262eddfbb76SRobert Watson VNET_DECLARE(int, nd6_useloopback);
263eddfbb76SRobert Watson VNET_DECLARE(int, nd6_maxnudhint);
264eddfbb76SRobert Watson VNET_DECLARE(int, nd6_gctimer);
265eddfbb76SRobert Watson VNET_DECLARE(struct nd_prhead, nd_prefix);
266eddfbb76SRobert Watson VNET_DECLARE(int, nd6_debug);
267eddfbb76SRobert Watson VNET_DECLARE(int, nd6_onlink_ns_rfc4861);
2681e77c105SRobert Watson #define	V_nd6_prune			VNET(nd6_prune)
2691e77c105SRobert Watson #define	V_nd6_delay			VNET(nd6_delay)
2701e77c105SRobert Watson #define	V_nd6_umaxtries			VNET(nd6_umaxtries)
2711e77c105SRobert Watson #define	V_nd6_mmaxtries			VNET(nd6_mmaxtries)
2721e77c105SRobert Watson #define	V_nd6_useloopback		VNET(nd6_useloopback)
2731e77c105SRobert Watson #define	V_nd6_maxnudhint		VNET(nd6_maxnudhint)
2741e77c105SRobert Watson #define	V_nd6_gctimer			VNET(nd6_gctimer)
2751e77c105SRobert Watson #define	V_nd_prefix			VNET(nd_prefix)
2761e77c105SRobert Watson #define	V_nd6_debug			VNET(nd6_debug)
2771e77c105SRobert Watson #define	V_nd6_onlink_ns_rfc4861		VNET(nd6_onlink_ns_rfc4861)
27882cea7e6SBjoern A. Zeeb 
2794de485feSMark Johnston /* Lock for the prefix and default router lists. */
2804de485feSMark Johnston VNET_DECLARE(struct rwlock, nd6_lock);
281d748f7efSMark Johnston VNET_DECLARE(uint64_t, nd6_list_genid);
2824de485feSMark Johnston #define	V_nd6_lock			VNET(nd6_lock)
283d748f7efSMark Johnston #define	V_nd6_list_genid		VNET(nd6_list_genid)
2844de485feSMark Johnston 
2854de485feSMark Johnston #define	ND6_RLOCK()			rw_rlock(&V_nd6_lock)
2864de485feSMark Johnston #define	ND6_RUNLOCK()			rw_runlock(&V_nd6_lock)
2874de485feSMark Johnston #define	ND6_WLOCK()			rw_wlock(&V_nd6_lock)
2884de485feSMark Johnston #define	ND6_WUNLOCK()			rw_wunlock(&V_nd6_lock)
289d748f7efSMark Johnston #define	ND6_TRY_UPGRADE()		rw_try_upgrade(&V_nd6_lock)
2904de485feSMark Johnston #define	ND6_WLOCK_ASSERT()		rw_assert(&V_nd6_lock, RA_WLOCKED)
2914de485feSMark Johnston #define	ND6_RLOCK_ASSERT()		rw_assert(&V_nd6_lock, RA_RLOCKED)
2924de485feSMark Johnston #define	ND6_LOCK_ASSERT()		rw_assert(&V_nd6_lock, RA_LOCKED)
2934de485feSMark Johnston #define	ND6_UNLOCK_ASSERT()		rw_assert(&V_nd6_lock, RA_UNLOCKED)
2944de485feSMark Johnston 
295d748f7efSMark Johnston /* Mutex for prefix onlink/offlink transitions. */
296d748f7efSMark Johnston VNET_DECLARE(struct mtx, nd6_onlink_mtx);
297d748f7efSMark Johnston #define	V_nd6_onlink_mtx		VNET(nd6_onlink_mtx)
298d748f7efSMark Johnston 
299d748f7efSMark Johnston #define	ND6_ONLINK_LOCK()		mtx_lock(&V_nd6_onlink_mtx)
300d748f7efSMark Johnston #define	ND6_ONLINK_TRYLOCK()		mtx_trylock(&V_nd6_onlink_mtx)
301d748f7efSMark Johnston #define	ND6_ONLINK_UNLOCK()		mtx_unlock(&V_nd6_onlink_mtx)
302d748f7efSMark Johnston #define	ND6_ONLINK_LOCK_ASSERT()	mtx_assert(&V_nd6_onlink_mtx, MA_OWNED)
303d748f7efSMark Johnston #define	ND6_ONLINK_UNLOCK_ASSERT()	mtx_assert(&V_nd6_onlink_mtx, MA_NOTOWNED)
304d748f7efSMark Johnston 
30582cea7e6SBjoern A. Zeeb #define nd6log(x)	do { if (V_nd6_debug) log x; } while (/*CONSTCOND*/ 0)
30682cea7e6SBjoern A. Zeeb 
307686cdd19SJun-ichiro itojun Hagino /* nd6_rtr.c */
308eddfbb76SRobert Watson VNET_DECLARE(int, nd6_defifindex);
309eddfbb76SRobert Watson VNET_DECLARE(int, ip6_desync_factor);	/* seconds */
310eddfbb76SRobert Watson VNET_DECLARE(u_int32_t, ip6_temp_preferred_lifetime); /* seconds */
311eddfbb76SRobert Watson VNET_DECLARE(u_int32_t, ip6_temp_valid_lifetime); /* seconds */
312eddfbb76SRobert Watson VNET_DECLARE(int, ip6_temp_regen_advance); /* seconds */
3131e77c105SRobert Watson #define	V_nd6_defifindex		VNET(nd6_defifindex)
3141e77c105SRobert Watson #define	V_ip6_desync_factor		VNET(ip6_desync_factor)
3151e77c105SRobert Watson #define	V_ip6_temp_preferred_lifetime	VNET(ip6_temp_preferred_lifetime)
3161e77c105SRobert Watson #define	V_ip6_temp_valid_lifetime	VNET(ip6_temp_valid_lifetime)
3171e77c105SRobert Watson #define	V_ip6_temp_regen_advance	VNET(ip6_temp_regen_advance)
31886413abfSBjoern A. Zeeb 
31982cd038dSYoshinobu Inoue union nd_opts {
32011d8451dSHiroki Sato 	struct nd_opt_hdr *nd_opt_array[16];	/* max = ND_OPT_NONCE */
32182cd038dSYoshinobu Inoue 	struct {
32282cd038dSYoshinobu Inoue 		struct nd_opt_hdr *zero;
32382cd038dSYoshinobu Inoue 		struct nd_opt_hdr *src_lladdr;
32482cd038dSYoshinobu Inoue 		struct nd_opt_hdr *tgt_lladdr;
32582cd038dSYoshinobu Inoue 		struct nd_opt_prefix_info *pi_beg; /* multiple opts, start */
32682cd038dSYoshinobu Inoue 		struct nd_opt_rd_hdr *rh;
32782cd038dSYoshinobu Inoue 		struct nd_opt_mtu *mtu;
32811d8451dSHiroki Sato 		struct nd_opt_hdr *__res6;
32911d8451dSHiroki Sato 		struct nd_opt_hdr *__res7;
33011d8451dSHiroki Sato 		struct nd_opt_hdr *__res8;
33111d8451dSHiroki Sato 		struct nd_opt_hdr *__res9;
33211d8451dSHiroki Sato 		struct nd_opt_hdr *__res10;
33311d8451dSHiroki Sato 		struct nd_opt_hdr *__res11;
33411d8451dSHiroki Sato 		struct nd_opt_hdr *__res12;
33511d8451dSHiroki Sato 		struct nd_opt_hdr *__res13;
33611d8451dSHiroki Sato 		struct nd_opt_nonce *nonce;
33711d8451dSHiroki Sato 		struct nd_opt_hdr *__res15;
33882cd038dSYoshinobu Inoue 		struct nd_opt_hdr *search;	/* multiple opts */
33982cd038dSYoshinobu Inoue 		struct nd_opt_hdr *last;	/* multiple opts */
34082cd038dSYoshinobu Inoue 		int done;
34182cd038dSYoshinobu Inoue 		struct nd_opt_prefix_info *pi_end;/* multiple opts, end */
34282cd038dSYoshinobu Inoue 	} nd_opt_each;
34382cd038dSYoshinobu Inoue };
34482cd038dSYoshinobu Inoue #define nd_opts_src_lladdr	nd_opt_each.src_lladdr
34582cd038dSYoshinobu Inoue #define nd_opts_tgt_lladdr	nd_opt_each.tgt_lladdr
34682cd038dSYoshinobu Inoue #define nd_opts_pi		nd_opt_each.pi_beg
34782cd038dSYoshinobu Inoue #define nd_opts_pi_end		nd_opt_each.pi_end
34882cd038dSYoshinobu Inoue #define nd_opts_rh		nd_opt_each.rh
34982cd038dSYoshinobu Inoue #define nd_opts_mtu		nd_opt_each.mtu
35011d8451dSHiroki Sato #define nd_opts_nonce		nd_opt_each.nonce
35182cd038dSYoshinobu Inoue #define nd_opts_search		nd_opt_each.search
35282cd038dSYoshinobu Inoue #define nd_opts_last		nd_opt_each.last
35382cd038dSYoshinobu Inoue #define nd_opts_done		nd_opt_each.done
35482cd038dSYoshinobu Inoue 
35582cd038dSYoshinobu Inoue /* XXX: need nd6_var.h?? */
35682cd038dSYoshinobu Inoue /* nd6.c */
3576f56329aSXin LI void nd6_init(void);
358bc29160dSMarko Zec #ifdef VIMAGE
3596f56329aSXin LI void nd6_destroy(void);
360bc29160dSMarko Zec #endif
3616f56329aSXin LI struct nd_ifinfo *nd6_ifattach(struct ifnet *);
36289856f7eSBjoern A. Zeeb void nd6_ifdetach(struct ifnet *, struct nd_ifinfo *);
363f0316e1aSAlexander V. Chernikov int nd6_is_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *);
3646f56329aSXin LI void nd6_option_init(void *, int, union nd_opts *);
3656f56329aSXin LI struct nd_opt_hdr *nd6_option(union nd_opts *);
3666f56329aSXin LI int nd6_options(union nd_opts *);
367f0316e1aSAlexander V. Chernikov struct llentry *nd6_lookup(const struct in6_addr *, int, struct ifnet *);
3686f56329aSXin LI void nd6_setmtu(struct ifnet *);
369aa5f023eSAlexander V. Chernikov void nd6_llinfo_setstate(struct llentry *lle, int newstate);
3706f56329aSXin LI void nd6_timer(void *);
3716f56329aSXin LI void nd6_purge(struct ifnet *);
3724fb3a820SAlexander V. Chernikov int nd6_resolve_addr(struct ifnet *ifp, int flags, const struct sockaddr *dst,
3734fb3a820SAlexander V. Chernikov     char *desten, uint32_t *pflags);
3741fe201c3SAlexander V. Chernikov int nd6_resolve(struct ifnet *, int, struct mbuf *,
3756d768226SGeorge V. Neville-Neil     const struct sockaddr *, u_char *, uint32_t *, struct llentry **);
3766f56329aSXin LI int nd6_ioctl(u_long, caddr_t, struct ifnet *);
3770e2dcee6SAlexander V. Chernikov void nd6_cache_lladdr(struct ifnet *, struct in6_addr *,
3786f56329aSXin LI 	char *, int, int, int);
379*8482aa77SAlexander V. Chernikov struct mbuf *nd6_grab_holdchain(struct llentry *);
380*8482aa77SAlexander V. Chernikov int nd6_flush_holdchain(struct ifnet *, struct llentry *, struct mbuf *);
381f6b84910SAlexander V. Chernikov int nd6_add_ifa_lle(struct in6_ifaddr *);
3823e7a2321SAlexander V. Chernikov void nd6_rem_ifa_lle(struct in6_ifaddr *, int);
3831fe201c3SAlexander V. Chernikov int nd6_output_ifp(struct ifnet *, struct ifnet *, struct mbuf *,
384637670e7SAlexander V. Chernikov     struct sockaddr_in6 *, struct route *);
38582cd038dSYoshinobu Inoue 
3864c7ba83fSAlexander V. Chernikov struct rib_head;
3874c7ba83fSAlexander V. Chernikov struct rib_cmd_info;
3884c7ba83fSAlexander V. Chernikov void nd6_subscription_cb(struct rib_head *rnh, struct rib_cmd_info *rc,
3894c7ba83fSAlexander V. Chernikov     void *arg);
3904c7ba83fSAlexander V. Chernikov 
39182cd038dSYoshinobu Inoue /* nd6_nbr.c */
3926f56329aSXin LI void nd6_na_input(struct mbuf *, int, int);
3936f56329aSXin LI void nd6_na_output(struct ifnet *, const struct in6_addr *,
3946f56329aSXin LI 	const struct in6_addr *, u_long, int, struct sockaddr *);
3956f56329aSXin LI void nd6_ns_input(struct mbuf *, int, int);
3966f56329aSXin LI void nd6_ns_output(struct ifnet *, const struct in6_addr *,
39726deb882SAlexander V. Chernikov 	const struct in6_addr *, const struct in6_addr *, uint8_t *);
3986f56329aSXin LI caddr_t nd6_ifptomac(struct ifnet *);
399d6ad6a86SMark Johnston void nd6_dad_init(void);
4006f56329aSXin LI void nd6_dad_start(struct ifaddr *, int);
4016f56329aSXin LI void nd6_dad_stop(struct ifaddr *);
40282cd038dSYoshinobu Inoue 
40382cd038dSYoshinobu Inoue /* nd6_rtr.c */
4046f56329aSXin LI void nd6_rs_input(struct mbuf *, int, int);
4056f56329aSXin LI void nd6_ra_input(struct mbuf *, int, int);
40630b45077SBjoern A. Zeeb void nd6_ifnet_link_event(void *, struct ifnet *, int);
407aaad3c4fSAlexander V. Chernikov struct nd_defrouter *defrouter_lookup(const struct in6_addr *, struct ifnet *);
408aaad3c4fSAlexander V. Chernikov struct nd_defrouter *defrouter_lookup_locked(const struct in6_addr *,
409aaad3c4fSAlexander V. Chernikov     struct ifnet *);
4106f56329aSXin LI void defrouter_reset(void);
411559b4296SAlan Somers void defrouter_select_fib(int fibnum);
4124de485feSMark Johnston void defrouter_rele(struct nd_defrouter *);
413ff63037dSMark Johnston bool defrouter_remove(struct in6_addr *, struct ifnet *);
414ad675b32SBjoern A. Zeeb bool nd6_defrouter_list_empty(void);
415ad675b32SBjoern A. Zeeb void nd6_defrouter_flush_all(void);
416ad675b32SBjoern A. Zeeb void nd6_defrouter_purge(struct ifnet *);
417ad675b32SBjoern A. Zeeb void nd6_defrouter_timer(void);
418ad675b32SBjoern A. Zeeb void nd6_defrouter_init(void);
4196f56329aSXin LI int nd6_prelist_add(struct nd_prefixctl *, struct nd_defrouter *,
4206f56329aSXin LI     struct nd_prefix **);
421d748f7efSMark Johnston void nd6_prefix_unlink(struct nd_prefix *, struct nd_prhead *);
422d748f7efSMark Johnston void nd6_prefix_del(struct nd_prefix *);
423d748f7efSMark Johnston void nd6_prefix_ref(struct nd_prefix *);
424d748f7efSMark Johnston void nd6_prefix_rele(struct nd_prefix *);
425d748f7efSMark Johnston int nd6_prefix_offlink(struct nd_prefix *);
4266f56329aSXin LI void pfxlist_onlink_check(void);
4276f56329aSXin LI struct nd_prefix *nd6_prefix_lookup(struct nd_prefixctl *);
4286f56329aSXin LI void rt6_flush(struct in6_addr *, struct ifnet *);
4296f56329aSXin LI int nd6_setdefaultiface(int);
4306f56329aSXin LI int in6_tmpifadd(const struct in6_ifaddr *, int, int);
43182cd038dSYoshinobu Inoue 
43282cd038dSYoshinobu Inoue #endif /* _KERNEL */
43382cd038dSYoshinobu Inoue 
43482cd038dSYoshinobu Inoue #endif /* _NETINET6_ND6_H_ */
435