Home | History | Annotate | Line # | Download | only in net
nd.c revision 1.5
      1  1.5  yamt /*	$NetBSD: nd.c,v 1.5 2022/11/19 08:00:51 yamt Exp $	*/
      2  1.1   roy 
      3  1.1   roy /*
      4  1.1   roy  * Copyright (c) 2020 The NetBSD Foundation, Inc.
      5  1.1   roy  *
      6  1.1   roy  * This code is derived from software contributed to The NetBSD Foundation
      7  1.1   roy  * by Roy Marples.
      8  1.1   roy  *
      9  1.1   roy  * Redistribution and use in source and binary forms, with or without
     10  1.1   roy  * modification, are permitted provided that the following conditions
     11  1.1   roy  * are met:
     12  1.1   roy  * 1. Redistributions of source code must retain the above copyright
     13  1.1   roy  *    notice, this list of conditions and the following disclaimer.
     14  1.1   roy  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1   roy  *    notice, this list of conditions and the following disclaimer in the
     16  1.1   roy  *    documentation and/or other materials provided with the distribution.
     17  1.1   roy  *
     18  1.1   roy  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1   roy  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1   roy  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1   roy  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1   roy  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  1.1   roy  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  1.1   roy  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  1.1   roy  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  1.1   roy  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  1.1   roy  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  1.1   roy  */
     29  1.1   roy 
     30  1.1   roy #include <sys/cdefs.h>
     31  1.5  yamt __KERNEL_RCSID(0, "$NetBSD: nd.c,v 1.5 2022/11/19 08:00:51 yamt Exp $");
     32  1.1   roy 
     33  1.1   roy #include <sys/callout.h>
     34  1.1   roy #include <sys/mbuf.h>
     35  1.1   roy #include <sys/socketvar.h> /* for softnet_lock */
     36  1.1   roy 
     37  1.1   roy #include <net/if_llatbl.h>
     38  1.1   roy #include <net/nd.h>
     39  1.1   roy #include <net/route.h>
     40  1.1   roy 
     41  1.1   roy #include <netinet/in.h>
     42  1.1   roy #include <netinet/ip6.h>
     43  1.1   roy 
     44  1.1   roy static struct nd_domain *nd_domains[AF_MAX];
     45  1.1   roy 
     46  1.1   roy static int nd_gctimer = (60 * 60 * 24); /* 1 day: garbage collection timer */
     47  1.1   roy 
     48  1.1   roy static void nd_set_timertick(struct llentry *, time_t);
     49  1.1   roy static struct nd_domain *nd_find_domain(int);
     50  1.1   roy 
     51  1.1   roy static void
     52  1.1   roy nd_timer(void *arg)
     53  1.1   roy {
     54  1.1   roy 	struct llentry *ln = arg;
     55  1.1   roy 	struct nd_domain *nd;
     56  1.1   roy 	struct ifnet *ifp = NULL;
     57  1.1   roy 	struct psref psref;
     58  1.1   roy 	struct mbuf *m = NULL;
     59  1.3   roy 	bool send_ns = false;
     60  1.4   roy 	int16_t missed = ND_LLINFO_NOSTATE;
     61  1.2   roy 	union l3addr taddr, *daddrp = NULL;
     62  1.1   roy 
     63  1.1   roy 	SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
     64  1.1   roy 	LLE_WLOCK(ln);
     65  1.1   roy 
     66  1.1   roy 	if (!(ln->la_flags & LLE_LINKED))
     67  1.1   roy 		goto out;
     68  1.1   roy 	if (ln->ln_ntick > 0) {
     69  1.1   roy 		nd_set_timer(ln, ND_TIMER_TICK);
     70  1.1   roy 		goto out;
     71  1.1   roy 	}
     72  1.1   roy 
     73  1.1   roy 	nd = nd_find_domain(ln->lle_tbl->llt_af);
     74  1.1   roy 	ifp = ln->lle_tbl->llt_ifp;
     75  1.1   roy 	KASSERT(ifp != NULL);
     76  1.1   roy 	if_acquire(ifp, &psref);
     77  1.1   roy 
     78  1.1   roy 	memcpy(&taddr, &ln->r_l3addr, sizeof(taddr));
     79  1.1   roy 
     80  1.1   roy 	switch (ln->ln_state) {
     81  1.1   roy 	case ND_LLINFO_WAITDELETE:
     82  1.1   roy 		LLE_REMREF(ln);
     83  1.1   roy 		nd->nd_free(ln, 0);
     84  1.1   roy 		ln = NULL;
     85  1.1   roy 		break;
     86  1.1   roy 
     87  1.1   roy 	case ND_LLINFO_INCOMPLETE:
     88  1.3   roy 		send_ns = true;
     89  1.3   roy 		if (ln->ln_asked++ < nd->nd_mmaxtries)
     90  1.1   roy 			break;
     91  1.1   roy 
     92  1.1   roy 		if (ln->ln_hold) {
     93  1.1   roy 			struct mbuf *m0, *mnxt;
     94  1.1   roy 
     95  1.1   roy 			/*
     96  1.1   roy 			 * Assuming every packet in ln_hold
     97  1.1   roy 			 * has the same IP header.
     98  1.1   roy 			 */
     99  1.1   roy 			m = ln->ln_hold;
    100  1.1   roy 			for (m0 = m->m_nextpkt; m0 != NULL; m0 = mnxt) {
    101  1.1   roy 				mnxt = m0->m_nextpkt;
    102  1.1   roy 				m0->m_nextpkt = NULL;
    103  1.1   roy 				m_freem(m0);
    104  1.1   roy 			}
    105  1.1   roy 
    106  1.1   roy 			m->m_nextpkt = NULL;
    107  1.1   roy 			ln->ln_hold = NULL;
    108  1.1   roy 		}
    109  1.1   roy 
    110  1.3   roy 		missed = ND_LLINFO_INCOMPLETE;
    111  1.1   roy 		ln->ln_state = ND_LLINFO_WAITDELETE;
    112  1.1   roy 		break;
    113  1.1   roy 
    114  1.1   roy 	case ND_LLINFO_REACHABLE:
    115  1.1   roy 		if (!ND_IS_LLINFO_PERMANENT(ln)) {
    116  1.1   roy 			ln->ln_state = ND_LLINFO_STALE;
    117  1.1   roy 			nd_set_timer(ln, ND_TIMER_GC);
    118  1.1   roy 		}
    119  1.1   roy 		break;
    120  1.1   roy 
    121  1.1   roy 	case ND_LLINFO_PURGE: /* FALLTHROUGH */
    122  1.1   roy 	case ND_LLINFO_STALE:
    123  1.1   roy 		if (!ND_IS_LLINFO_PERMANENT(ln)) {
    124  1.1   roy 			LLE_REMREF(ln);
    125  1.1   roy 			nd->nd_free(ln, 1);
    126  1.1   roy 			ln = NULL;
    127  1.1   roy 		}
    128  1.1   roy 		break;
    129  1.1   roy 
    130  1.1   roy 	case ND_LLINFO_DELAY:
    131  1.1   roy 		if (nd->nd_nud_enabled(ifp)) {
    132  1.1   roy 			ln->ln_asked = 1;
    133  1.1   roy 			ln->ln_state = ND_LLINFO_PROBE;
    134  1.1   roy 			send_ns = true;
    135  1.1   roy 			daddrp = &taddr;
    136  1.1   roy 		} else {
    137  1.1   roy 			ln->ln_state = ND_LLINFO_STALE;
    138  1.1   roy 			nd_set_timer(ln, ND_TIMER_GC);
    139  1.1   roy 		}
    140  1.1   roy 		break;
    141  1.1   roy 
    142  1.1   roy 	case ND_LLINFO_PROBE:
    143  1.3   roy 		send_ns = true;
    144  1.3   roy 		if (ln->ln_asked++ < nd->nd_umaxtries) {
    145  1.1   roy 			daddrp = &taddr;
    146  1.1   roy 		} else {
    147  1.3   roy 			ln->ln_state = ND_LLINFO_UNREACHABLE;
    148  1.3   roy 			ln->ln_asked = 1;
    149  1.3   roy 			missed = ND_LLINFO_PROBE;
    150  1.3   roy 			/* nd_missed() consumers can use missed to know if
    151  1.3   roy 			 * they need to send ICMP UNREACHABLE or not. */
    152  1.1   roy 		}
    153  1.1   roy 		break;
    154  1.3   roy 	case ND_LLINFO_UNREACHABLE:
    155  1.3   roy 		/*
    156  1.3   roy 		 * RFC 7048 Section 3 says in the UNREACHABLE state
    157  1.3   roy 		 * packets continue to be sent to the link-layer address and
    158  1.3   roy 		 * then backoff exponentially.
    159  1.3   roy 		 * We adjust this slightly and move to the INCOMPLETE state
    160  1.3   roy 		 * after nd_mmaxtries probes and then start backing off.
    161  1.3   roy 		 *
    162  1.3   roy 		 * This results in simpler code whilst providing a more robust
    163  1.3   roy 		 * model which doubles the time to failure over what we did
    164  1.3   roy 		 * before. We don't want to be back to the old ARP model where
    165  1.3   roy 		 * no unreachability errors are returned because very
    166  1.3   roy 		 * few applications would look at unreachability hints provided
    167  1.3   roy 		 * such as ND_LLINFO_UNREACHABLE or RTM_MISS.
    168  1.3   roy 		 */
    169  1.3   roy 		send_ns = true;
    170  1.3   roy 		if (ln->ln_asked++ < nd->nd_mmaxtries)
    171  1.3   roy 			break;
    172  1.3   roy 
    173  1.3   roy 		missed = ND_LLINFO_UNREACHABLE;
    174  1.3   roy 		ln->ln_state = ND_LLINFO_WAITDELETE;
    175  1.3   roy 		ln->la_flags &= ~LLE_VALID;
    176  1.3   roy 		break;
    177  1.1   roy 	}
    178  1.1   roy 
    179  1.1   roy 	if (send_ns) {
    180  1.1   roy 		uint8_t lladdr[255], *lladdrp;
    181  1.2   roy 		union l3addr src, *psrc;
    182  1.1   roy 
    183  1.3   roy 		if (ln->ln_state == ND_LLINFO_WAITDELETE)
    184  1.3   roy 			nd_set_timer(ln, ND_TIMER_RETRANS_BACKOFF);
    185  1.3   roy 		else
    186  1.3   roy 			nd_set_timer(ln, ND_TIMER_RETRANS);
    187  1.1   roy 		if (ln->ln_state > ND_LLINFO_INCOMPLETE &&
    188  1.1   roy 		    ln->la_flags & LLE_VALID)
    189  1.1   roy 		{
    190  1.1   roy 			KASSERT(sizeof(lladdr) >= ifp->if_addrlen);
    191  1.1   roy 			memcpy(lladdr, &ln->ll_addr, ifp->if_addrlen);
    192  1.1   roy 			lladdrp = lladdr;
    193  1.1   roy 		} else
    194  1.1   roy 			lladdrp = NULL;
    195  1.1   roy 		psrc = nd->nd_holdsrc(ln, &src);
    196  1.1   roy 		LLE_FREE_LOCKED(ln);
    197  1.1   roy 		ln = NULL;
    198  1.1   roy 		nd->nd_output(ifp, daddrp, &taddr, lladdrp, psrc);
    199  1.1   roy 	}
    200  1.1   roy 
    201  1.1   roy out:
    202  1.1   roy 	if (ln != NULL)
    203  1.1   roy 		LLE_FREE_LOCKED(ln);
    204  1.1   roy 	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
    205  1.1   roy 
    206  1.4   roy 	if (missed != ND_LLINFO_NOSTATE)
    207  1.3   roy 		nd->nd_missed(ifp, &taddr, missed, m);
    208  1.1   roy 	if (ifp != NULL)
    209  1.1   roy 		if_release(ifp, &psref);
    210  1.1   roy }
    211  1.1   roy 
    212  1.1   roy static void
    213  1.1   roy nd_set_timertick(struct llentry *ln, time_t xtick)
    214  1.1   roy {
    215  1.1   roy 
    216  1.1   roy 	CTASSERT(sizeof(time_t) > sizeof(int));
    217  1.1   roy 	KASSERT(xtick >= 0);
    218  1.1   roy 
    219  1.1   roy 	/*
    220  1.1   roy 	 * We have to take care of a reference leak which occurs if
    221  1.1   roy 	 * callout_reset overwrites a pending callout schedule.  Unfortunately
    222  1.1   roy 	 * we don't have a mean to know the overwrite, so we need to know it
    223  1.1   roy 	 * using callout_stop.  We need to call callout_pending first to exclude
    224  1.1   roy 	 * the case that the callout has never been scheduled.
    225  1.1   roy 	 */
    226  1.1   roy 	if (callout_pending(&ln->la_timer)) {
    227  1.1   roy 		bool expired;
    228  1.1   roy 
    229  1.1   roy 		expired = callout_stop(&ln->la_timer);
    230  1.1   roy 		if (!expired)
    231  1.1   roy 			LLE_REMREF(ln);
    232  1.1   roy 	}
    233  1.1   roy 
    234  1.1   roy 	ln->ln_expire = time_uptime + xtick / hz;
    235  1.1   roy 	LLE_ADDREF(ln);
    236  1.1   roy 	if (xtick > INT_MAX) {
    237  1.1   roy 		ln->ln_ntick = xtick - INT_MAX;
    238  1.1   roy 		xtick = INT_MAX;
    239  1.1   roy 	} else {
    240  1.1   roy 		ln->ln_ntick = 0;
    241  1.1   roy 	}
    242  1.1   roy 	callout_reset(&ln->ln_timer_ch, xtick, nd_timer, ln);
    243  1.1   roy }
    244  1.1   roy 
    245  1.1   roy void
    246  1.1   roy nd_set_timer(struct llentry *ln, int type)
    247  1.1   roy {
    248  1.1   roy 	time_t xtick;
    249  1.1   roy 	struct ifnet *ifp;
    250  1.1   roy 	struct nd_domain *nd;
    251  1.1   roy 
    252  1.1   roy 	LLE_WLOCK_ASSERT(ln);
    253  1.1   roy 
    254  1.1   roy 	ifp = ln->lle_tbl->llt_ifp;
    255  1.1   roy 	nd = nd_find_domain(ln->lle_tbl->llt_af);
    256  1.1   roy 
    257  1.1   roy 	switch (type) {
    258  1.1   roy 	case ND_TIMER_IMMEDIATE:
    259  1.1   roy 		xtick = 0;
    260  1.1   roy 		break;
    261  1.1   roy 	case ND_TIMER_TICK:
    262  1.1   roy 		xtick = ln->ln_ntick;
    263  1.1   roy 		break;
    264  1.1   roy 	case ND_TIMER_RETRANS:
    265  1.1   roy 		xtick = nd->nd_retrans(ifp) * hz / 1000;
    266  1.1   roy 		break;
    267  1.3   roy 	case ND_TIMER_RETRANS_BACKOFF:
    268  1.3   roy 	{
    269  1.3   roy 		unsigned int retrans = nd->nd_retrans(ifp);
    270  1.3   roy 		unsigned int attempts = ln->ln_asked - nd->nd_mmaxtries;
    271  1.3   roy 
    272  1.3   roy 		xtick = retrans;
    273  1.3   roy 		while (attempts-- != 0) {
    274  1.3   roy 			xtick *= nd->nd_retransmultiple;
    275  1.3   roy 			if (xtick > nd->nd_maxretrans || xtick < retrans) {
    276  1.3   roy 				xtick = nd->nd_maxretrans;
    277  1.3   roy 				break;
    278  1.3   roy 			}
    279  1.3   roy 		}
    280  1.3   roy 		xtick = xtick * hz / 1000;
    281  1.3   roy 		break;
    282  1.3   roy 	}
    283  1.1   roy 	case ND_TIMER_REACHABLE:
    284  1.1   roy 		xtick = nd->nd_reachable(ifp) * hz / 1000;
    285  1.1   roy 		break;
    286  1.1   roy 	case ND_TIMER_EXPIRE:
    287  1.1   roy 		if (ln->ln_expire > time_uptime)
    288  1.1   roy 			xtick = (ln->ln_expire - time_uptime) * hz;
    289  1.1   roy 		else
    290  1.1   roy 			xtick = nd_gctimer * hz;
    291  1.1   roy 		break;
    292  1.1   roy 	case ND_TIMER_DELAY:
    293  1.1   roy 		xtick = nd->nd_delay * hz;
    294  1.1   roy 		break;
    295  1.1   roy 	case ND_TIMER_GC:
    296  1.1   roy 		xtick = nd_gctimer * hz;
    297  1.1   roy 		break;
    298  1.1   roy 	default:
    299  1.1   roy 		panic("%s: invalid timer type\n", __func__);
    300  1.1   roy 	}
    301  1.1   roy 
    302  1.1   roy 	nd_set_timertick(ln, xtick);
    303  1.1   roy }
    304  1.1   roy 
    305  1.1   roy int
    306  1.1   roy nd_resolve(struct llentry *ln, const struct rtentry *rt, struct mbuf *m,
    307  1.1   roy     uint8_t *lldst, size_t dstsize)
    308  1.1   roy {
    309  1.1   roy 	struct ifnet *ifp;
    310  1.1   roy 	struct nd_domain *nd;
    311  1.1   roy 	int error;
    312  1.1   roy 
    313  1.1   roy 	LLE_WLOCK_ASSERT(ln);
    314  1.1   roy 
    315  1.1   roy 	ifp = ln->lle_tbl->llt_ifp;
    316  1.1   roy 	nd = nd_find_domain(ln->lle_tbl->llt_af);
    317  1.1   roy 
    318  1.1   roy 	/* We don't have to do link-layer address resolution on a p2p link. */
    319  1.1   roy 	if (ifp->if_flags & IFF_POINTOPOINT &&
    320  1.1   roy 	    ln->ln_state < ND_LLINFO_REACHABLE)
    321  1.1   roy 	{
    322  1.1   roy 		ln->ln_state = ND_LLINFO_STALE;
    323  1.1   roy 		nd_set_timer(ln, ND_TIMER_GC);
    324  1.1   roy 	}
    325  1.1   roy 
    326  1.1   roy 	/*
    327  1.1   roy 	 * The first time we send a packet to a neighbor whose entry is
    328  1.1   roy 	 * STALE, we have to change the state to DELAY and a sets a timer to
    329  1.1   roy 	 * expire in DELAY_FIRST_PROBE_TIME seconds to ensure do
    330  1.1   roy 	 * neighbor unreachability detection on expiration.
    331  1.1   roy 	 * (RFC 2461 7.3.3)
    332  1.1   roy 	 */
    333  1.1   roy 	if (ln->ln_state == ND_LLINFO_STALE) {
    334  1.1   roy 		ln->ln_asked = 0;
    335  1.1   roy 		ln->ln_state = ND_LLINFO_DELAY;
    336  1.1   roy 		nd_set_timer(ln, ND_TIMER_DELAY);
    337  1.1   roy 	}
    338  1.1   roy 
    339  1.1   roy 	/*
    340  1.1   roy 	 * If the neighbor cache entry has a state other than INCOMPLETE
    341  1.1   roy 	 * (i.e. its link-layer address is already resolved), just
    342  1.1   roy 	 * send the packet.
    343  1.1   roy 	 */
    344  1.1   roy 	if (ln->ln_state > ND_LLINFO_INCOMPLETE) {
    345  1.1   roy 		KASSERT((ln->la_flags & LLE_VALID) != 0);
    346  1.1   roy 		memcpy(lldst, &ln->ll_addr, MIN(dstsize, ifp->if_addrlen));
    347  1.1   roy 		LLE_WUNLOCK(ln);
    348  1.1   roy 		return 0;
    349  1.1   roy 	}
    350  1.1   roy 
    351  1.1   roy 	/*
    352  1.1   roy 	 * There is a neighbor cache entry, but no ethernet address
    353  1.1   roy 	 * response yet.  Append this latest packet to the end of the
    354  1.1   roy 	 * packet queue in the mbuf, unless the number of the packet
    355  1.1   roy 	 * does not exceed maxqueuelen.  When it exceeds maxqueuelen,
    356  1.1   roy 	 * the oldest packet in the queue will be removed.
    357  1.1   roy 	 */
    358  1.1   roy 	if (ln->ln_state == ND_LLINFO_NOSTATE ||
    359  1.1   roy 	    ln->ln_state == ND_LLINFO_WAITDELETE)
    360  1.1   roy 		ln->ln_state = ND_LLINFO_INCOMPLETE;
    361  1.1   roy 
    362  1.5  yamt #ifdef MBUFTRACE
    363  1.5  yamt 	m_claimm(m, ln->lle_tbl->llt_mowner);
    364  1.5  yamt #endif
    365  1.1   roy 	if (ln->ln_hold != NULL) {
    366  1.1   roy 		struct mbuf *m_hold;
    367  1.1   roy 		int i;
    368  1.1   roy 
    369  1.1   roy 		i = 0;
    370  1.1   roy 		for (m_hold = ln->ln_hold; m_hold; m_hold = m_hold->m_nextpkt) {
    371  1.1   roy 			i++;
    372  1.1   roy 			if (m_hold->m_nextpkt == NULL) {
    373  1.1   roy 				m_hold->m_nextpkt = m;
    374  1.1   roy 				break;
    375  1.1   roy 			}
    376  1.1   roy 		}
    377  1.1   roy 		while (i >= nd->nd_maxqueuelen) {
    378  1.1   roy 			m_hold = ln->ln_hold;
    379  1.1   roy 			ln->ln_hold = ln->ln_hold->m_nextpkt;
    380  1.1   roy 			m_freem(m_hold);
    381  1.1   roy 			i--;
    382  1.1   roy 		}
    383  1.1   roy 	} else
    384  1.1   roy 		ln->ln_hold = m;
    385  1.1   roy 
    386  1.1   roy 	if (ln->ln_asked >= nd->nd_mmaxtries)
    387  1.1   roy 		error = (rt != NULL && rt->rt_flags & RTF_GATEWAY) ?
    388  1.1   roy 		    EHOSTUNREACH : EHOSTDOWN;
    389  1.1   roy 	else
    390  1.1   roy 		error = EWOULDBLOCK;
    391  1.1   roy 
    392  1.1   roy 	/*
    393  1.1   roy 	 * If there has been no NS for the neighbor after entering the
    394  1.1   roy 	 * INCOMPLETE state, send the first solicitation.
    395  1.1   roy 	 */
    396  1.1   roy 	if (!ND_IS_LLINFO_PERMANENT(ln) && ln->ln_asked == 0) {
    397  1.1   roy 		struct psref psref;
    398  1.2   roy 		union l3addr dst, src, *psrc;
    399  1.1   roy 
    400  1.1   roy 		ln->ln_asked++;
    401  1.1   roy 		nd_set_timer(ln, ND_TIMER_RETRANS);
    402  1.1   roy 		memcpy(&dst, &ln->r_l3addr, sizeof(dst));
    403  1.1   roy 		psrc = nd->nd_holdsrc(ln, &src);
    404  1.1   roy 		if_acquire(ifp, &psref);
    405  1.1   roy 		LLE_WUNLOCK(ln);
    406  1.1   roy 
    407  1.1   roy 		nd->nd_output(ifp, NULL, &dst, NULL, psrc);
    408  1.1   roy 		if_release(ifp, &psref);
    409  1.1   roy 	} else
    410  1.1   roy 		LLE_WUNLOCK(ln);
    411  1.1   roy 
    412  1.1   roy 	return error;
    413  1.1   roy }
    414  1.1   roy 
    415  1.1   roy void
    416  1.1   roy nd_nud_hint(struct llentry *ln)
    417  1.1   roy {
    418  1.1   roy 	struct nd_domain *nd;
    419  1.1   roy 
    420  1.1   roy 	if (ln == NULL)
    421  1.1   roy 		return;
    422  1.1   roy 
    423  1.1   roy 	LLE_WLOCK_ASSERT(ln);
    424  1.1   roy 
    425  1.1   roy 	if (ln->ln_state < ND_LLINFO_REACHABLE)
    426  1.1   roy 		goto done;
    427  1.1   roy 
    428  1.1   roy 	nd = nd_find_domain(ln->lle_tbl->llt_af);
    429  1.1   roy 
    430  1.1   roy 	/*
    431  1.1   roy 	 * if we get upper-layer reachability confirmation many times,
    432  1.1   roy 	 * it is possible we have false information.
    433  1.1   roy 	 */
    434  1.1   roy 	ln->ln_byhint++;
    435  1.1   roy 	if (ln->ln_byhint > nd->nd_maxnudhint)
    436  1.1   roy 		goto done;
    437  1.1   roy 
    438  1.1   roy 	ln->ln_state = ND_LLINFO_REACHABLE;
    439  1.1   roy 	if (!ND_IS_LLINFO_PERMANENT(ln))
    440  1.1   roy 		nd_set_timer(ln, ND_TIMER_REACHABLE);
    441  1.1   roy 
    442  1.1   roy done:
    443  1.1   roy 	LLE_WUNLOCK(ln);
    444  1.1   roy 
    445  1.1   roy 	return;
    446  1.1   roy }
    447  1.1   roy 
    448  1.1   roy static struct nd_domain *
    449  1.1   roy nd_find_domain(int af)
    450  1.1   roy {
    451  1.1   roy 
    452  1.1   roy 	KASSERT(af < __arraycount(nd_domains) && nd_domains[af] != NULL);
    453  1.1   roy 	return nd_domains[af];
    454  1.1   roy }
    455  1.1   roy 
    456  1.1   roy void
    457  1.1   roy nd_attach_domain(struct nd_domain *nd)
    458  1.1   roy {
    459  1.1   roy 
    460  1.1   roy 	KASSERT(nd->nd_family < __arraycount(nd_domains));
    461  1.1   roy 	nd_domains[nd->nd_family] = nd;
    462  1.1   roy }
    463