From nobody Fri Jan 13 21:25:40 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NtvbS6rJDz2qkv7; Fri, 13 Jan 2023 21:25:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NtvbS6C33z43Ly; Fri, 13 Jan 2023 21:25:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Jg/C3SC6KRX3/K5dGJqbs7FGAYFdw4ar/FnczGEvq8c=; b=qIFNYhXk6qdi5Zb77lBmNTlpEo2ctqSsC0Ia4WwxWwdAw8vmHI1hYXJUGbbTkH+0o8MGGr 7DmMKLtqwMlUvKmX3plk80erdE/XaVGUvWhghhTiUAi1IuJa6fcuKvaryhiBr7GCF+ysdj AUg3UL3aerAuCzD9yOdtp4Hj2+GbEbiz9jQKX/aVuhDFC737IghxTs8wC49X/V9Fn0D7n1 qRPeG45KpymcasU8qcWfqcMn1iDXaZVdt5zlyIqF3dbYsHDOqYyBZdi5/0/ayNx5qL6urC MYdNR3hdkdzGFEy4HQ2ZE2AVYDoDWLaq6DFw6nTp2gjKB7SSdkXx8KMNyLvlLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Jg/C3SC6KRX3/K5dGJqbs7FGAYFdw4ar/FnczGEvq8c=; b=BnnUaKYhdQyp5B7QfOoRPCdZ81U8eqh8hetYEialjjm7Vs3SVb9PXFMNfU0bMyAk23axXw hlkguYDmHL58EihsM9A6xeo5g/hnw8tSqUh186QZbJ1mDOxYH4vr93yUy6RNTuQ52gMS3k cmXZa2Y0eP/6lZlqSomHk3/rA9l4DOffR8H33znM140poKBbDV9nvz1rq9Y0es5J3JHc5d yg5TzAhanh8lHSMbZkxhrrkbYihHTtbR1DfpKWzayPpknwtnWDnupN4qjHWx80qWYat5gG uml6H2D8A2gJ/Bp/ekSlI3/27ZmUAlO35osmRzZYYA4EmEaM3f/uC73vXTy1tg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673645140; a=rsa-sha256; cv=none; b=BdVqBfKMWOC9Ou+KlVpubjesmOXgB/XINoijzsiJtQVi2izAG6hF6tGI1LbB2nnH3yjQCo 0gwMpwKO3keyjCLs4jeN1ImRgLUrM7epuA6+88ods/97f31rLyiJkggSMPxcfNmUzgWpLJ sOUG4JDTzrHz5+Lz/MHDJc9i1u9fXEv3DzSEa+6yTzO47OldZlPha8TArBjKWVMKeFkJ4Q i6aadQO7/c06TMgFs/GoM3iliYphFYVA4h+wSOvMzIFnRj94OcpLD5P6aJf6vc3ItEinaW cisBnNE9xeOJ1IgzZa3E8x1TLF20Nk/RHqT5SzurdQ8oloD09cm4kLHnCQyYhA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NtvbS4j2TzNDM; Fri, 13 Jan 2023 21:25:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30DLPebc042175; Fri, 13 Jan 2023 21:25:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30DLPek4042174; Fri, 13 Jan 2023 21:25:40 GMT (envelope-from git) Date: Fri, 13 Jan 2023 21:25:40 GMT Message-Id: <202301132125.30DLPek4042174@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 95b5ff22a93c - stable/13 - netinet6: allow ND entries creation for all directly-reachable destinations. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 95b5ff22a93c50911f167ad11ffc25d6a9413fc9 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=95b5ff22a93c50911f167ad11ffc25d6a9413fc9 commit 95b5ff22a93c50911f167ad11ffc25d6a9413fc9 Author: Alexander V. Chernikov AuthorDate: 2022-08-10 11:51:58 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-01-13 21:24:11 +0000 netinet6: allow ND entries creation for all directly-reachable destinations. The current assumption is that kernel-handled rtadv prefixes along with the interface address prefixes are the only prefixes considered in the ND neighbor eligibility code. Change this by allowing any non-gatewaye routes to be eligible. This will allow DHCPv6-controlled routes to be correctly handled by the ND code. Refactor nd6_is_new_addr_neighbor() to enable more deterministic performance in "found" case and remove non-needed V_rt_add_addr_allfibs handling logic. Reviewed By: kbowling Differential Revision: https://reviews.freebsd.org/D23695 MFC after: 1 month (cherry picked from commit f998535a66b986f51dd65b5153d1a580d50ddfbe) --- sys/netinet6/nd6.c | 90 +++++++++++++----------------------------------------- 1 file changed, 22 insertions(+), 68 deletions(-) diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index b772fb74b257..e4d657feed98 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -71,6 +71,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -129,7 +130,7 @@ VNET_DEFINE(int, nd6_recalc_reachtm_interval) = ND6_RECALC_REACHTM_INTERVAL; int (*send_sendso_input_hook)(struct mbuf *, struct ifnet *, int, int); -static int nd6_is_new_addr_neighbor(const struct sockaddr_in6 *, +static bool nd6_is_new_addr_neighbor(const struct sockaddr_in6 *, struct ifnet *); static void nd6_setmtu0(struct ifnet *, struct nd_ifinfo *); static void nd6_slowtimo(void *); @@ -1225,20 +1226,11 @@ nd6_alloc(const struct in6_addr *addr6, int flags, struct ifnet *ifp) } /* - * Test whether a given IPv6 address is a neighbor or not, ignoring - * the actual neighbor cache. The neighbor cache is ignored in order - * to not reenter the routing code from within itself. + * Test whether a given IPv6 address can be a neighbor. */ -static int +static bool nd6_is_new_addr_neighbor(const struct sockaddr_in6 *addr, struct ifnet *ifp) { - struct nd_prefix *pr; - struct ifaddr *ifa; - struct rt_addrinfo info; - struct sockaddr_in6 rt_key; - const struct sockaddr *dst6; - uint64_t genid; - int error, fibnum; /* * A link-local address is always a neighbor. @@ -1262,89 +1254,51 @@ nd6_is_new_addr_neighbor(const struct sockaddr_in6 *addr, struct ifnet *ifp) else return (0); } + /* Checking global unicast */ - bzero(&rt_key, sizeof(rt_key)); - bzero(&info, sizeof(info)); - info.rti_info[RTAX_DST] = (struct sockaddr *)&rt_key; + /* If an address is directly reachable, it is a neigbor */ + struct nhop_object *nh; + nh = fib6_lookup(ifp->if_fib, &addr->sin6_addr, 0, NHR_NONE, 0); + if (nh != NULL && nh->nh_aifp == ifp && (nh->nh_flags & NHF_GATEWAY) == 0) + return (true); /* - * If the address matches one of our addresses, - * it should be a neighbor. - * If the address matches one of our on-link prefixes, it should be a - * neighbor. + * Check prefixes with desired on-link state, as some may be not + * installed in the routing table. */ + bool matched = false; + struct nd_prefix *pr; ND6_RLOCK(); -restart: LIST_FOREACH(pr, &V_nd_prefix, ndpr_entry) { if (pr->ndpr_ifp != ifp) continue; - - if ((pr->ndpr_stateflags & NDPRF_ONLINK) == 0) { - dst6 = (const struct sockaddr *)&pr->ndpr_prefix; - - /* - * We only need to check all FIBs if add_addr_allfibs - * is unset. If set, checking any FIB will suffice. - */ - fibnum = V_rt_add_addr_allfibs ? rt_numfibs - 1 : 0; - for (; fibnum < rt_numfibs; fibnum++) { - genid = V_nd6_list_genid; - ND6_RUNLOCK(); - - /* - * Restore length field before - * retrying lookup - */ - rt_key.sin6_len = sizeof(rt_key); - error = rib_lookup_info(fibnum, dst6, 0, 0, - &info); - - ND6_RLOCK(); - if (genid != V_nd6_list_genid) - goto restart; - if (error == 0) - break; - } - if (error != 0) - continue; - - /* - * This is the case where multiple interfaces - * have the same prefix, but only one is installed - * into the routing table and that prefix entry - * is not the one being examined here. - */ - if (!IN6_ARE_ADDR_EQUAL(&pr->ndpr_prefix.sin6_addr, - &rt_key.sin6_addr)) - continue; - } - + if ((pr->ndpr_stateflags & NDPRF_ONLINK) == 0) + continue; if (IN6_ARE_MASKED_ADDR_EQUAL(&pr->ndpr_prefix.sin6_addr, &addr->sin6_addr, &pr->ndpr_mask)) { - ND6_RUNLOCK(); - return (1); + matched = true; + break; } } ND6_RUNLOCK(); + if (matched) + return (true); /* * If the address is assigned on the node of the other side of * a p2p interface, the address should be a neighbor. */ if (ifp->if_flags & IFF_POINTOPOINT) { - struct epoch_tracker et; + struct ifaddr *ifa; - NET_EPOCH_ENTER(et); CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { if (ifa->ifa_addr->sa_family != addr->sin6_family) continue; if (ifa->ifa_dstaddr != NULL && sa_equal(addr, ifa->ifa_dstaddr)) { - NET_EPOCH_EXIT(et); - return 1; + return (true); } } - NET_EPOCH_EXIT(et); } /*