| 1 | /*	$OpenBSD: nd6.h,v 1.106 2026/03/23 13:12:39 jsg Exp $	*/ |
| 2 | /*	$KAME: nd6.h,v 1.95 2002/06/08 11:31:06 itojun Exp $	*/ |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. Neither the name of the project nor the names of its contributors |
| 17 | * may be used to endorse or promote products derived from this software |
| 18 | * without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | * SUCH DAMAGE. |
| 31 | */ |
| 32 | |
| 33 | #ifndef _NETINET6_ND6_H_ |
| 34 | #define _NETINET6_ND6_H_ |
| 35 | |
| 36 | #define ND6_LLINFO_PURGE	-3 |
| 37 | #define ND6_LLINFO_NOSTATE	-2 |
| 38 | #define ND6_LLINFO_INCOMPLETE	0 |
| 39 | #define ND6_LLINFO_REACHABLE	1 |
| 40 | #define ND6_LLINFO_STALE	2 |
| 41 | #define ND6_LLINFO_DELAY	3 |
| 42 | #define ND6_LLINFO_PROBE	4 |
| 43 | |
| 44 | /* |
| 45 | * Locks used to protect struct members in this file: |
| 46 | *	I	immutable after creation |
| 47 | *	K	kernel lock |
| 48 | *	m	nd6 mutex, needed when net lock is shared |
| 49 | *	N	net lock |
| 50 | */ |
| 51 | |
| 52 | struct nd_ifinfo { |
| 53 | 	u_int32_t reachable;		/* [N] Reachable Time */ |
| 54 | 	int recalctm;			/* [N] BaseReachable recalc timer */ |
| 55 | }; |
| 56 | |
| 57 | struct in6_nbrinfo { |
| 58 | 	char ifname[IFNAMSIZ];	/* if name, e.g. "en0" */ |
| 59 | 	struct in6_addr addr;	/* IPv6 address of the neighbor */ |
| 60 | 	time_t	expire;		/* lifetime for NDP state transition */ |
| 61 | 	long	asked;		/* number of queries already sent for addr */ |
| 62 | 	int	isrouter;	/* if it acts as a router */ |
| 63 | 	int	state;		/* reachability state */ |
| 64 | }; |
| 65 | |
| 66 | struct	in6_ndireq { |
| 67 | 	char ifname[IFNAMSIZ]; |
| 68 | 	struct nd_ifinfo ndi; |
| 69 | }; |
| 70 | |
| 71 | /* protocol constants */ |
| 72 | #define MAX_RTR_SOLICITATION_DELAY	1	/*1sec*/ |
| 73 | #define RTR_SOLICITATION_INTERVAL	4	/*4sec*/ |
| 74 | #define MAX_RTR_SOLICITATIONS		3 |
| 75 | |
| 76 | #define ND6_INFINITE_LIFETIME		0xffffffff |
| 77 | |
| 78 | #ifdef _KERNEL |
| 79 | |
| 80 | #include <sys/queue.h> |
| 81 | |
| 82 | struct llinfo_nd6 { |
| 83 | 	TAILQ_ENTRY(llinfo_nd6)	 ln_list;	/* [m] global nd6_list */ |
| 84 | 	struct	rtentry		*ln_rt;		/* [I] backpointer to rtentry */ |
| 85 | 	/* keep fields above in sync with struct llinfo_nd6_iterator */ |
| 86 | 	struct	refcnt		 ln_refcnt;	/* entry referenced by list */ |
| 87 | 	struct	mbuf_queue ln_mq;	/* hold packets until resolved */ |
| 88 | 	struct	in6_addr ln_saddr6;	/* source of prompting packet */ |
| 89 | 	long	ln_asked;	/* number of queries already sent for addr */ |
| 90 | 	short	ln_state;	/* reachability state */ |
| 91 | 	short	ln_router;	/* 2^0: ND6 router bit */ |
| 92 | }; |
| 93 | #define LN_HOLD_QUEUE 10 |
| 94 | #define LN_HOLD_TOTAL 100 |
| 95 | |
| 96 | struct llinfo_nd6_iterator { |
| 97 | 	TAILQ_ENTRY(llinfo_nd6)	 ln_list;	/* [m] global nd6_list */ |
| 98 | 	struct	rtentry		*ln_rt;		/* [I] always NULL */ |
| 99 | 	/* keep fields above in sync with struct llinfo_nd6 */ |
| 100 | }; |
| 101 | |
| 102 | extern unsigned int ln_hold_total; |
| 103 | |
| 104 | #define ND6_LLINFO_PERMANENT(n)	((n)->ln_rt->rt_expire == 0) |
| 105 | |
| 106 | /* node constants */ |
| 107 | #define REACHABLE_TIME			30000	/* msec */ |
| 108 | #define RETRANS_TIMER			1000	/* msec */ |
| 109 | #define MIN_RANDOM_FACTOR		512	/* 1024 * 0.5 */ |
| 110 | #define MAX_RANDOM_FACTOR		1536	/* 1024 * 1.5 */ |
| 111 | #define ND_COMPUTE_RTIME(x) \ |
| 112 | 		(((MIN_RANDOM_FACTOR * (x >> 10)) + (arc4random() & \ |
| 113 | 		((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000) |
| 114 | |
| 115 | extern int nd6_delay; |
| 116 | extern int nd6_umaxtries; |
| 117 | extern int nd6_mmaxtries; |
| 118 | extern const int nd6_gctimer; |
| 119 | |
| 120 | struct nd_opts { |
| 121 | 	struct nd_opt_hdr *nd_opts_src_lladdr; |
| 122 | 	struct nd_opt_hdr *nd_opts_tgt_lladdr; |
| 123 | }; |
| 124 | |
| 125 | void nd6_init(void); |
| 126 | void nd6_ifattach(struct ifnet *); |
| 127 | void nd6_ifdetach(struct ifnet *); |
| 128 | int nd6_is_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *); |
| 129 | int nd6_options(void *, int, struct nd_opts *); |
| 130 | struct	rtentry *nd6_lookup(const struct in6_addr *, int, struct ifnet *, |
| 131 | u_int); |
| 132 | void nd6_llinfo_settimer(const struct llinfo_nd6 *, unsigned int); |
| 133 | void nd6_purge(struct ifnet *); |
| 134 | void nd6_rtrequest(struct ifnet *, int, struct rtentry *); |
| 135 | int nd6_ioctl(u_long, caddr_t, struct ifnet *); |
| 136 | void nd6_cache_lladdr(struct ifnet *, const struct in6_addr *, char *, |
| 137 | int, int, int, int); |
| 138 | int nd6_resolve(struct ifnet *, struct rtentry *, struct mbuf *, |
| 139 | 	 struct sockaddr *, u_char *); |
| 140 | int nd6_need_cache(struct ifnet *); |
| 141 | |
| 142 | void nd6_na_input(struct mbuf *, int, int); |
| 143 | void nd6_na_output(struct ifnet *, const struct in6_addr *, |
| 144 | 	const struct in6_addr *, u_long, int, struct sockaddr *); |
| 145 | void nd6_ns_input(struct mbuf *, int, int); |
| 146 | void nd6_ns_output(struct ifnet *, const struct in6_addr *, |
| 147 | 	const struct in6_addr *, const struct in6_addr *, int); |
| 148 | caddr_t nd6_ifptomac(struct ifnet *); |
| 149 | void nd6_dad_start(struct ifaddr *); |
| 150 | void nd6_dad_stop(struct ifaddr *); |
| 151 | |
| 152 | void nd6_rtr_cache(struct mbuf *, int, int, int); |
| 153 | |
| 154 | int rt6_flush(struct in6_addr *, struct ifnet *); |
| 155 | |
| 156 | void nd6_expire_timer_update(struct in6_ifaddr *); |
| 157 | #endif /* _KERNEL */ |
| 158 | |
| 159 | #endif /* _NETINET6_ND6_H_ */ |