Home | History | Annotate | Line # | Download | only in net
nd.c revision 1.8
      1  1.8     ozaki /*	$NetBSD: nd.c,v 1.8 2025/08/18 06:46:43 ozaki-r 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.8     ozaki __KERNEL_RCSID(0, "$NetBSD: nd.c,v 1.8 2025/08/18 06:46:43 ozaki-r 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.8     ozaki 		if (ln->ln_asked < nd->nd_mmaxtries) {
     89  1.8     ozaki 			ln->ln_asked++;
     90  1.8     ozaki 			send_ns = true;
     91  1.1       roy 			break;
     92  1.8     ozaki 		}
     93  1.1       roy 
     94  1.1       roy 		if (ln->ln_hold) {
     95  1.1       roy 			struct mbuf *m0, *mnxt;
     96  1.1       roy 
     97  1.1       roy 			/*
     98  1.1       roy 			 * Assuming every packet in ln_hold
     99  1.1       roy 			 * has the same IP header.
    100  1.1       roy 			 */
    101  1.1       roy 			m = ln->ln_hold;
    102  1.1       roy 			for (m0 = m->m_nextpkt; m0 != NULL; m0 = mnxt) {
    103  1.1       roy 				mnxt = m0->m_nextpkt;
    104  1.1       roy 				m0->m_nextpkt = NULL;
    105  1.1       roy 				m_freem(m0);
    106  1.1       roy 			}
    107  1.1       roy 
    108  1.1       roy 			m->m_nextpkt = NULL;
    109  1.1       roy 			ln->ln_hold = NULL;
    110  1.7  riastrad 			ln->la_numheld = 0;
    111  1.1       roy 		}
    112  1.1       roy 
    113  1.7  riastrad 		KASSERTMSG(ln->la_numheld == 0, "la_numheld=%d",
    114  1.7  riastrad 		    ln->la_numheld);
    115  1.7  riastrad 
    116  1.3       roy 		missed = ND_LLINFO_INCOMPLETE;
    117  1.1       roy 		ln->ln_state = ND_LLINFO_WAITDELETE;
    118  1.1       roy 		break;
    119  1.1       roy 
    120  1.1       roy 	case ND_LLINFO_REACHABLE:
    121  1.8     ozaki 		if (!ND_IS_LLINFO_PERMANENT(ln))
    122  1.1       roy 			ln->ln_state = ND_LLINFO_STALE;
    123  1.1       roy 		break;
    124  1.1       roy 
    125  1.1       roy 	case ND_LLINFO_PURGE: /* FALLTHROUGH */
    126  1.1       roy 	case ND_LLINFO_STALE:
    127  1.1       roy 		if (!ND_IS_LLINFO_PERMANENT(ln)) {
    128  1.1       roy 			LLE_REMREF(ln);
    129  1.1       roy 			nd->nd_free(ln, 1);
    130  1.1       roy 			ln = NULL;
    131  1.1       roy 		}
    132  1.1       roy 		break;
    133  1.1       roy 
    134  1.1       roy 	case ND_LLINFO_DELAY:
    135  1.1       roy 		if (nd->nd_nud_enabled(ifp)) {
    136  1.1       roy 			ln->ln_asked = 1;
    137  1.1       roy 			ln->ln_state = ND_LLINFO_PROBE;
    138  1.1       roy 			send_ns = true;
    139  1.1       roy 			daddrp = &taddr;
    140  1.8     ozaki 		} else
    141  1.1       roy 			ln->ln_state = ND_LLINFO_STALE;
    142  1.1       roy 		break;
    143  1.1       roy 
    144  1.1       roy 	case ND_LLINFO_PROBE:
    145  1.3       roy 		send_ns = true;
    146  1.3       roy 		if (ln->ln_asked++ < nd->nd_umaxtries) {
    147  1.1       roy 			daddrp = &taddr;
    148  1.1       roy 		} else {
    149  1.3       roy 			ln->ln_state = ND_LLINFO_UNREACHABLE;
    150  1.3       roy 			ln->ln_asked = 1;
    151  1.3       roy 			missed = ND_LLINFO_PROBE;
    152  1.3       roy 			/* nd_missed() consumers can use missed to know if
    153  1.3       roy 			 * they need to send ICMP UNREACHABLE or not. */
    154  1.1       roy 		}
    155  1.1       roy 		break;
    156  1.3       roy 	case ND_LLINFO_UNREACHABLE:
    157  1.3       roy 		/*
    158  1.3       roy 		 * RFC 7048 Section 3 says in the UNREACHABLE state
    159  1.3       roy 		 * packets continue to be sent to the link-layer address and
    160  1.3       roy 		 * then backoff exponentially.
    161  1.3       roy 		 * We adjust this slightly and move to the INCOMPLETE state
    162  1.3       roy 		 * after nd_mmaxtries probes and then start backing off.
    163  1.3       roy 		 *
    164  1.3       roy 		 * This results in simpler code whilst providing a more robust
    165  1.3       roy 		 * model which doubles the time to failure over what we did
    166  1.3       roy 		 * before. We don't want to be back to the old ARP model where
    167  1.3       roy 		 * no unreachability errors are returned because very
    168  1.3       roy 		 * few applications would look at unreachability hints provided
    169  1.3       roy 		 * such as ND_LLINFO_UNREACHABLE or RTM_MISS.
    170  1.3       roy 		 */
    171  1.3       roy 		send_ns = true;
    172  1.3       roy 		if (ln->ln_asked++ < nd->nd_mmaxtries)
    173  1.3       roy 			break;
    174  1.3       roy 
    175  1.3       roy 		missed = ND_LLINFO_UNREACHABLE;
    176  1.3       roy 		ln->ln_state = ND_LLINFO_WAITDELETE;
    177  1.3       roy 		ln->la_flags &= ~LLE_VALID;
    178  1.3       roy 		break;
    179  1.1       roy 	}
    180  1.1       roy 
    181  1.8     ozaki 	if (ln != NULL) {
    182  1.8     ozaki 		int type = ND_TIMER_RETRANS;
    183  1.8     ozaki 		if (ln->ln_state == ND_LLINFO_WAITDELETE)
    184  1.8     ozaki 			type = ND_TIMER_RETRANS_BACKOFF;
    185  1.8     ozaki 		else if (ln->ln_state == ND_LLINFO_STALE)
    186  1.8     ozaki 			type = ND_TIMER_GC;
    187  1.8     ozaki 		nd_set_timer(ln, type);
    188  1.8     ozaki 	}
    189  1.1       roy 	if (send_ns) {
    190  1.1       roy 		uint8_t lladdr[255], *lladdrp;
    191  1.2       roy 		union l3addr src, *psrc;
    192  1.1       roy 
    193  1.1       roy 		if (ln->ln_state > ND_LLINFO_INCOMPLETE &&
    194  1.1       roy 		    ln->la_flags & LLE_VALID)
    195  1.1       roy 		{
    196  1.1       roy 			KASSERT(sizeof(lladdr) >= ifp->if_addrlen);
    197  1.1       roy 			memcpy(lladdr, &ln->ll_addr, ifp->if_addrlen);
    198  1.1       roy 			lladdrp = lladdr;
    199  1.1       roy 		} else
    200  1.1       roy 			lladdrp = NULL;
    201  1.1       roy 		psrc = nd->nd_holdsrc(ln, &src);
    202  1.1       roy 		LLE_FREE_LOCKED(ln);
    203  1.1       roy 		ln = NULL;
    204  1.1       roy 		nd->nd_output(ifp, daddrp, &taddr, lladdrp, psrc);
    205  1.1       roy 	}
    206  1.1       roy 
    207  1.1       roy out:
    208  1.1       roy 	if (ln != NULL)
    209  1.1       roy 		LLE_FREE_LOCKED(ln);
    210  1.1       roy 	SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE();
    211  1.1       roy 
    212  1.4       roy 	if (missed != ND_LLINFO_NOSTATE)
    213  1.3       roy 		nd->nd_missed(ifp, &taddr, missed, m);
    214  1.1       roy 	if (ifp != NULL)
    215  1.1       roy 		if_release(ifp, &psref);
    216  1.1       roy }
    217  1.1       roy 
    218  1.1       roy static void
    219  1.1       roy nd_set_timertick(struct llentry *ln, time_t xtick)
    220  1.1       roy {
    221  1.1       roy 
    222  1.1       roy 	CTASSERT(sizeof(time_t) > sizeof(int));
    223  1.1       roy 	KASSERT(xtick >= 0);
    224  1.1       roy 
    225  1.1       roy 	/*
    226  1.1       roy 	 * We have to take care of a reference leak which occurs if
    227  1.1       roy 	 * callout_reset overwrites a pending callout schedule.  Unfortunately
    228  1.1       roy 	 * we don't have a mean to know the overwrite, so we need to know it
    229  1.1       roy 	 * using callout_stop.  We need to call callout_pending first to exclude
    230  1.1       roy 	 * the case that the callout has never been scheduled.
    231  1.1       roy 	 */
    232  1.1       roy 	if (callout_pending(&ln->la_timer)) {
    233  1.1       roy 		bool expired;
    234  1.1       roy 
    235  1.1       roy 		expired = callout_stop(&ln->la_timer);
    236  1.1       roy 		if (!expired)
    237  1.1       roy 			LLE_REMREF(ln);
    238  1.1       roy 	}
    239  1.1       roy 
    240  1.1       roy 	ln->ln_expire = time_uptime + xtick / hz;
    241  1.1       roy 	LLE_ADDREF(ln);
    242  1.1       roy 	if (xtick > INT_MAX) {
    243  1.1       roy 		ln->ln_ntick = xtick - INT_MAX;
    244  1.1       roy 		xtick = INT_MAX;
    245  1.1       roy 	} else {
    246  1.1       roy 		ln->ln_ntick = 0;
    247  1.1       roy 	}
    248  1.1       roy 	callout_reset(&ln->ln_timer_ch, xtick, nd_timer, ln);
    249  1.1       roy }
    250  1.1       roy 
    251  1.1       roy void
    252  1.1       roy nd_set_timer(struct llentry *ln, int type)
    253  1.1       roy {
    254  1.1       roy 	time_t xtick;
    255  1.1       roy 	struct ifnet *ifp;
    256  1.1       roy 	struct nd_domain *nd;
    257  1.1       roy 
    258  1.1       roy 	LLE_WLOCK_ASSERT(ln);
    259  1.1       roy 
    260  1.1       roy 	ifp = ln->lle_tbl->llt_ifp;
    261  1.1       roy 	nd = nd_find_domain(ln->lle_tbl->llt_af);
    262  1.1       roy 
    263  1.1       roy 	switch (type) {
    264  1.1       roy 	case ND_TIMER_IMMEDIATE:
    265  1.1       roy 		xtick = 0;
    266  1.1       roy 		break;
    267  1.1       roy 	case ND_TIMER_TICK:
    268  1.1       roy 		xtick = ln->ln_ntick;
    269  1.1       roy 		break;
    270  1.1       roy 	case ND_TIMER_RETRANS:
    271  1.1       roy 		xtick = nd->nd_retrans(ifp) * hz / 1000;
    272  1.1       roy 		break;
    273  1.3       roy 	case ND_TIMER_RETRANS_BACKOFF:
    274  1.3       roy 	{
    275  1.3       roy 		unsigned int retrans = nd->nd_retrans(ifp);
    276  1.3       roy 		unsigned int attempts = ln->ln_asked - nd->nd_mmaxtries;
    277  1.3       roy 
    278  1.3       roy 		xtick = retrans;
    279  1.3       roy 		while (attempts-- != 0) {
    280  1.3       roy 			xtick *= nd->nd_retransmultiple;
    281  1.3       roy 			if (xtick > nd->nd_maxretrans || xtick < retrans) {
    282  1.3       roy 				xtick = nd->nd_maxretrans;
    283  1.3       roy 				break;
    284  1.3       roy 			}
    285  1.3       roy 		}
    286  1.3       roy 		xtick = xtick * hz / 1000;
    287  1.3       roy 		break;
    288  1.3       roy 	}
    289  1.1       roy 	case ND_TIMER_REACHABLE:
    290  1.1       roy 		xtick = nd->nd_reachable(ifp) * hz / 1000;
    291  1.1       roy 		break;
    292  1.1       roy 	case ND_TIMER_EXPIRE:
    293  1.1       roy 		if (ln->ln_expire > time_uptime)
    294  1.1       roy 			xtick = (ln->ln_expire - time_uptime) * hz;
    295  1.1       roy 		else
    296  1.1       roy 			xtick = nd_gctimer * hz;
    297  1.1       roy 		break;
    298  1.1       roy 	case ND_TIMER_DELAY:
    299  1.1       roy 		xtick = nd->nd_delay * hz;
    300  1.1       roy 		break;
    301  1.1       roy 	case ND_TIMER_GC:
    302  1.1       roy 		xtick = nd_gctimer * hz;
    303  1.1       roy 		break;
    304  1.1       roy 	default:
    305  1.1       roy 		panic("%s: invalid timer type\n", __func__);
    306  1.1       roy 	}
    307  1.1       roy 
    308  1.1       roy 	nd_set_timertick(ln, xtick);
    309  1.1       roy }
    310  1.1       roy 
    311  1.1       roy int
    312  1.1       roy nd_resolve(struct llentry *ln, const struct rtentry *rt, struct mbuf *m,
    313  1.1       roy     uint8_t *lldst, size_t dstsize)
    314  1.1       roy {
    315  1.1       roy 	struct ifnet *ifp;
    316  1.1       roy 	struct nd_domain *nd;
    317  1.1       roy 	int error;
    318  1.1       roy 
    319  1.1       roy 	LLE_WLOCK_ASSERT(ln);
    320  1.1       roy 
    321  1.1       roy 	ifp = ln->lle_tbl->llt_ifp;
    322  1.1       roy 	nd = nd_find_domain(ln->lle_tbl->llt_af);
    323  1.1       roy 
    324  1.1       roy 	/* We don't have to do link-layer address resolution on a p2p link. */
    325  1.1       roy 	if (ifp->if_flags & IFF_POINTOPOINT &&
    326  1.1       roy 	    ln->ln_state < ND_LLINFO_REACHABLE)
    327  1.1       roy 	{
    328  1.1       roy 		ln->ln_state = ND_LLINFO_STALE;
    329  1.1       roy 		nd_set_timer(ln, ND_TIMER_GC);
    330  1.1       roy 	}
    331  1.1       roy 
    332  1.1       roy 	/*
    333  1.1       roy 	 * The first time we send a packet to a neighbor whose entry is
    334  1.1       roy 	 * STALE, we have to change the state to DELAY and a sets a timer to
    335  1.1       roy 	 * expire in DELAY_FIRST_PROBE_TIME seconds to ensure do
    336  1.1       roy 	 * neighbor unreachability detection on expiration.
    337  1.1       roy 	 * (RFC 2461 7.3.3)
    338  1.1       roy 	 */
    339  1.1       roy 	if (ln->ln_state == ND_LLINFO_STALE) {
    340  1.1       roy 		ln->ln_asked = 0;
    341  1.1       roy 		ln->ln_state = ND_LLINFO_DELAY;
    342  1.1       roy 		nd_set_timer(ln, ND_TIMER_DELAY);
    343  1.1       roy 	}
    344  1.1       roy 
    345  1.1       roy 	/*
    346  1.1       roy 	 * If the neighbor cache entry has a state other than INCOMPLETE
    347  1.1       roy 	 * (i.e. its link-layer address is already resolved), just
    348  1.1       roy 	 * send the packet.
    349  1.1       roy 	 */
    350  1.1       roy 	if (ln->ln_state > ND_LLINFO_INCOMPLETE) {
    351  1.1       roy 		KASSERT((ln->la_flags & LLE_VALID) != 0);
    352  1.1       roy 		memcpy(lldst, &ln->ll_addr, MIN(dstsize, ifp->if_addrlen));
    353  1.1       roy 		LLE_WUNLOCK(ln);
    354  1.1       roy 		return 0;
    355  1.1       roy 	}
    356  1.1       roy 
    357  1.1       roy 	/*
    358  1.1       roy 	 * There is a neighbor cache entry, but no ethernet address
    359  1.1       roy 	 * response yet.  Append this latest packet to the end of the
    360  1.1       roy 	 * packet queue in the mbuf, unless the number of the packet
    361  1.1       roy 	 * does not exceed maxqueuelen.  When it exceeds maxqueuelen,
    362  1.1       roy 	 * the oldest packet in the queue will be removed.
    363  1.1       roy 	 */
    364  1.1       roy 	if (ln->ln_state == ND_LLINFO_NOSTATE ||
    365  1.1       roy 	    ln->ln_state == ND_LLINFO_WAITDELETE)
    366  1.1       roy 		ln->ln_state = ND_LLINFO_INCOMPLETE;
    367  1.1       roy 
    368  1.5      yamt #ifdef MBUFTRACE
    369  1.5      yamt 	m_claimm(m, ln->lle_tbl->llt_mowner);
    370  1.5      yamt #endif
    371  1.1       roy 	if (ln->ln_hold != NULL) {
    372  1.1       roy 		struct mbuf *m_hold;
    373  1.1       roy 		int i;
    374  1.1       roy 
    375  1.1       roy 		i = 0;
    376  1.1       roy 		for (m_hold = ln->ln_hold; m_hold; m_hold = m_hold->m_nextpkt) {
    377  1.1       roy 			i++;
    378  1.1       roy 			if (m_hold->m_nextpkt == NULL) {
    379  1.1       roy 				m_hold->m_nextpkt = m;
    380  1.1       roy 				break;
    381  1.1       roy 			}
    382  1.1       roy 		}
    383  1.6  riastrad 		KASSERTMSG(ln->la_numheld == i, "la_numheld=%d i=%d",
    384  1.6  riastrad 		    ln->la_numheld, i);
    385  1.1       roy 		while (i >= nd->nd_maxqueuelen) {
    386  1.1       roy 			m_hold = ln->ln_hold;
    387  1.1       roy 			ln->ln_hold = ln->ln_hold->m_nextpkt;
    388  1.1       roy 			m_freem(m_hold);
    389  1.1       roy 			i--;
    390  1.6  riastrad 			ln->la_numheld--;
    391  1.1       roy 		}
    392  1.6  riastrad 	} else {
    393  1.6  riastrad 		KASSERTMSG(ln->la_numheld == 0, "la_numheld=%d",
    394  1.6  riastrad 		    ln->la_numheld);
    395  1.1       roy 		ln->ln_hold = m;
    396  1.6  riastrad 	}
    397  1.6  riastrad 
    398  1.6  riastrad 	KASSERTMSG(ln->la_numheld < nd->nd_maxqueuelen,
    399  1.6  riastrad 	    "la_numheld=%d nd_maxqueuelen=%d",
    400  1.6  riastrad 	    ln->la_numheld, nd->nd_maxqueuelen);
    401  1.6  riastrad 	ln->la_numheld++;
    402  1.1       roy 
    403  1.1       roy 	if (ln->ln_asked >= nd->nd_mmaxtries)
    404  1.1       roy 		error = (rt != NULL && rt->rt_flags & RTF_GATEWAY) ?
    405  1.1       roy 		    EHOSTUNREACH : EHOSTDOWN;
    406  1.1       roy 	else
    407  1.1       roy 		error = EWOULDBLOCK;
    408  1.1       roy 
    409  1.1       roy 	/*
    410  1.1       roy 	 * If there has been no NS for the neighbor after entering the
    411  1.1       roy 	 * INCOMPLETE state, send the first solicitation.
    412  1.1       roy 	 */
    413  1.1       roy 	if (!ND_IS_LLINFO_PERMANENT(ln) && ln->ln_asked == 0) {
    414  1.1       roy 		struct psref psref;
    415  1.2       roy 		union l3addr dst, src, *psrc;
    416  1.1       roy 
    417  1.1       roy 		ln->ln_asked++;
    418  1.1       roy 		nd_set_timer(ln, ND_TIMER_RETRANS);
    419  1.1       roy 		memcpy(&dst, &ln->r_l3addr, sizeof(dst));
    420  1.1       roy 		psrc = nd->nd_holdsrc(ln, &src);
    421  1.1       roy 		if_acquire(ifp, &psref);
    422  1.1       roy 		LLE_WUNLOCK(ln);
    423  1.1       roy 
    424  1.1       roy 		nd->nd_output(ifp, NULL, &dst, NULL, psrc);
    425  1.1       roy 		if_release(ifp, &psref);
    426  1.1       roy 	} else
    427  1.1       roy 		LLE_WUNLOCK(ln);
    428  1.1       roy 
    429  1.1       roy 	return error;
    430  1.1       roy }
    431  1.1       roy 
    432  1.1       roy void
    433  1.1       roy nd_nud_hint(struct llentry *ln)
    434  1.1       roy {
    435  1.1       roy 	struct nd_domain *nd;
    436  1.1       roy 
    437  1.1       roy 	if (ln == NULL)
    438  1.1       roy 		return;
    439  1.1       roy 
    440  1.1       roy 	LLE_WLOCK_ASSERT(ln);
    441  1.1       roy 
    442  1.1       roy 	if (ln->ln_state < ND_LLINFO_REACHABLE)
    443  1.1       roy 		goto done;
    444  1.1       roy 
    445  1.1       roy 	nd = nd_find_domain(ln->lle_tbl->llt_af);
    446  1.1       roy 
    447  1.1       roy 	/*
    448  1.1       roy 	 * if we get upper-layer reachability confirmation many times,
    449  1.1       roy 	 * it is possible we have false information.
    450  1.1       roy 	 */
    451  1.1       roy 	ln->ln_byhint++;
    452  1.1       roy 	if (ln->ln_byhint > nd->nd_maxnudhint)
    453  1.1       roy 		goto done;
    454  1.1       roy 
    455  1.1       roy 	ln->ln_state = ND_LLINFO_REACHABLE;
    456  1.1       roy 	if (!ND_IS_LLINFO_PERMANENT(ln))
    457  1.1       roy 		nd_set_timer(ln, ND_TIMER_REACHABLE);
    458  1.1       roy 
    459  1.1       roy done:
    460  1.1       roy 	LLE_WUNLOCK(ln);
    461  1.1       roy 
    462  1.1       roy 	return;
    463  1.1       roy }
    464  1.1       roy 
    465  1.1       roy static struct nd_domain *
    466  1.1       roy nd_find_domain(int af)
    467  1.1       roy {
    468  1.1       roy 
    469  1.1       roy 	KASSERT(af < __arraycount(nd_domains) && nd_domains[af] != NULL);
    470  1.1       roy 	return nd_domains[af];
    471  1.1       roy }
    472  1.1       roy 
    473  1.1       roy void
    474  1.1       roy nd_attach_domain(struct nd_domain *nd)
    475  1.1       roy {
    476  1.1       roy 
    477  1.1       roy 	KASSERT(nd->nd_family < __arraycount(nd_domains));
    478  1.1       roy 	nd_domains[nd->nd_family] = nd;
    479  1.1       roy }
    480