1 /* $OpenBSD: nd6.h,v 1.101 2024/10/17 05:37:54 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; /* [mN] global nd6_list */ 84 struct rtentry *ln_rt; /* [I] backpointer to rtentry */ 85 struct mbuf_queue ln_mq; /* hold packets until resolved */ 86 struct in6_addr ln_saddr6; /* source of prompting packet */ 87 long ln_asked; /* number of queries already sent for addr */ 88 int ln_byhint; /* # of times we made it reachable by UL hint */ 89 short ln_state; /* reachability state */ 90 short ln_router; /* 2^0: ND6 router bit */ 91 }; 92 #define LN_HOLD_QUEUE 10 93 #define LN_HOLD_TOTAL 100 94 95 extern unsigned int ln_hold_total; 96 97 #define ND6_LLINFO_PERMANENT(n) ((n)->ln_rt->rt_expire == 0) 98 99 /* node constants */ 100 #define REACHABLE_TIME 30000 /* msec */ 101 #define RETRANS_TIMER 1000 /* msec */ 102 #define MIN_RANDOM_FACTOR 512 /* 1024 * 0.5 */ 103 #define MAX_RANDOM_FACTOR 1536 /* 1024 * 1.5 */ 104 #define ND_COMPUTE_RTIME(x) \ 105 (((MIN_RANDOM_FACTOR * (x >> 10)) + (arc4random() & \ 106 ((MAX_RANDOM_FACTOR - MIN_RANDOM_FACTOR) * (x >> 10)))) /1000) 107 108 extern int nd6_delay; 109 extern int nd6_umaxtries; 110 extern int nd6_mmaxtries; 111 extern int nd6_maxnudhint; 112 extern int nd6_gctimer; 113 extern int nd6_debug; 114 115 #define nd6log(x) do { if (nd6_debug) log x; } while (0) 116 117 struct nd_opts { 118 struct nd_opt_hdr *nd_opts_src_lladdr; 119 struct nd_opt_hdr *nd_opts_tgt_lladdr; 120 }; 121 122 void nd6_init(void); 123 void nd6_ifattach(struct ifnet *); 124 void nd6_ifdetach(struct ifnet *); 125 int nd6_is_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *); 126 int nd6_options(void *, int, struct nd_opts *); 127 struct rtentry *nd6_lookup(const struct in6_addr *, int, struct ifnet *, 128 u_int); 129 void nd6_llinfo_settimer(const struct llinfo_nd6 *, unsigned int); 130 void nd6_purge(struct ifnet *); 131 void nd6_nud_hint(struct rtentry *); 132 void nd6_rtrequest(struct ifnet *, int, struct rtentry *); 133 int nd6_ioctl(u_long, caddr_t, struct ifnet *); 134 void nd6_cache_lladdr(struct ifnet *, const struct in6_addr *, char *, 135 int, int, int, int); 136 int nd6_resolve(struct ifnet *, struct rtentry *, struct mbuf *, 137 struct sockaddr *, u_char *); 138 int nd6_need_cache(struct ifnet *); 139 140 void nd6_na_input(struct mbuf *, int, int); 141 void nd6_na_output(struct ifnet *, const struct in6_addr *, 142 const struct in6_addr *, u_long, int, struct sockaddr *); 143 void nd6_ns_input(struct mbuf *, int, int); 144 void nd6_ns_output(struct ifnet *, const struct in6_addr *, 145 const struct in6_addr *, const struct in6_addr *, int); 146 caddr_t nd6_ifptomac(struct ifnet *); 147 void nd6_dad_start(struct ifaddr *); 148 void nd6_dad_stop(struct ifaddr *); 149 150 void nd6_rtr_cache(struct mbuf *, int, int, int); 151 152 int rt6_flush(struct in6_addr *, struct ifnet *); 153 154 void nd6_expire_timer_update(struct in6_ifaddr *); 155 #endif /* _KERNEL */ 156 157 #endif /* _NETINET6_ND6_H_ */ 158