From nobody Fri Aug 12 12:45:14 2022 X-Original-To: dev-commits-src-all@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 4M43L23v2Fz4Z64c; Fri, 12 Aug 2022 12:45:14 +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 4M43L23QdGz3b5P; Fri, 12 Aug 2022 12:45:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660308314; 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=Uj3RgqULXpfUz+VCyX0SFcKXPZ6zQoiRpJ8DLiiPBYA=; b=g4iNzfmh2VyRVkshvpUziQjjMq0MRcwbfkOPSu94HDELhEcFfAkW5cJuKJyGrKrGplazEm wKkPhg7FaQD19816MuBuHbYlpgW/XAImt0rcZOROsec8po5IRTngYO5GP87LdAGAdNzNRg XwKIHdUPE84RgNtfrNIRAYqSnTwiaw7TS98rMA58eugSUt6h3khDt0XgjVCj/C7tRsOZaz b9ptqOlsbkjSqp9LgByGoMAUcyq//BtgpTbi+4hmNTaWtHTczrFDRSjrtu253FQh0VrWV+ 9vKiYZmcxnWY57ReuPHPhfNV+iSc5PcPCIiimL69ZqloVxmJTTJCDKBBaveVPA== 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 4M43L22TFyzXZd; Fri, 12 Aug 2022 12:45:14 +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 27CCjEDa011468; Fri, 12 Aug 2022 12:45:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27CCjEQg011467; Fri, 12 Aug 2022 12:45:14 GMT (envelope-from git) Date: Fri, 12 Aug 2022 12:45:14 GMT Message-Id: <202208121245.27CCjEQg011467@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 9d16275c65bf - main - netinet6: simplify defrouter_select_fib() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 9d16275c65bfe0f577e6f97397e024a33169acc9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660308314; 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=Uj3RgqULXpfUz+VCyX0SFcKXPZ6zQoiRpJ8DLiiPBYA=; b=mm5Ns4hnEfBYvTbeya/yLLW2BduUu56o1SE7XiB9r4olzlVk3RfXO/309A7otdQp1R1Qtw w1LKPGtTg1raA72VPTGjpxXBa07X/U/BYX+xKfIhkXF2IQm7Sg2JKY8T++sPf2KI4TO4Z1 5j6kTN73NmAV3HuZ8wJ7WMLID4PGSiKbAlBpcZ+E5MKUQnDunrBm1h+mvpsAOBEkMLKkkt ykOv2sd9muyCJ3/6ABpUidRUevV1jbsQS7+w+XQNAPsy2LgocFbAhlzPl9kDWlGtaC6xuc au6QRz/q5YpK40aKq+JhtNnFFEyudZ3vK9Fidy8HzUjwM1cI974c/wpl/I8b1w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660308314; a=rsa-sha256; cv=none; b=KHdNs3efZxFgizzbXWcIdqf89pcWOVRDvc5LJy+1dHRbQPwwOzaJUsX+NHcTYA/ZkGX23b 2oiaAJrR2cCK2bWCqpujDdqdwZuzRYsJ9kFawKhl7MoSz96VaDzHn4KHJ/zvTHUokSMxUy MUWk886hyxrxeZDJ3JHQC50MD/tcJQJ0RTxIpZ/gDgouQdreFDkqtZdu2IHVxhtkTMxJNU pQxXDrcKBY+B7WvC3hZEkHxOtEVxWyH13buQSe3YNwCxkNNXS+pDDGZltfpfw2g3nw0E85 sC8GfYXXUg5O+yboOEEFkX4FTZfEzmjgv5FCIPdj2cuWMqR0Wjpm7J6Z3M72lA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=9d16275c65bfe0f577e6f97397e024a33169acc9 commit 9d16275c65bfe0f577e6f97397e024a33169acc9 Author: Alexander V. Chernikov AuthorDate: 2022-08-12 11:43:14 +0000 Commit: Alexander V. Chernikov CommitDate: 2022-08-12 11:43:37 +0000 netinet6: simplify defrouter_select_fib() * factor out underlying llentry check into a separate function and use it consistently * enter epoch once instead of per-router enter/exit * don't execute body with fibnum = `RT_ALL_FIBS` Differential Revision: https://reviews.freebsd.org/D35523 MFC after: 2 weeks --- sys/netinet6/nd6_rtr.c | 51 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index 47cc6bd0aa99..4502428e1690 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -915,6 +915,18 @@ rtpref(struct nd_defrouter *dr) /* NOTREACHED */ } +static bool +is_dr_reachable(const struct nd_defrouter *dr) { + struct llentry *ln = NULL; + + ln = nd6_lookup(&dr->rtaddr, LLE_SF(AF_INET6, 0), dr->ifp); + if (ln == NULL) + return (false); + bool reachable = ND6_IS_LLINFO_PROBREACH(ln); + LLE_RUNLOCK(ln); + return reachable; +} + /* * Default Router Selection according to Section 6.3.6 of RFC 2461 and * draft-ietf-ipngwg-router-selection: @@ -945,12 +957,12 @@ defrouter_select_fib(int fibnum) { struct epoch_tracker et; struct nd_defrouter *dr, *selected_dr, *installed_dr; - struct llentry *ln = NULL; if (fibnum == RT_ALL_FIBS) { for (fibnum = 0; fibnum < rt_numfibs; fibnum++) { defrouter_select_fib(fibnum); } + return; } ND6_RLOCK(); @@ -969,21 +981,17 @@ defrouter_select_fib(int fibnum) * the ordering rule of the list described in defrtrlist_update(). */ selected_dr = installed_dr = NULL; + NET_EPOCH_ENTER(et); TAILQ_FOREACH(dr, &V_nd6_defrouter, dr_entry) { - NET_EPOCH_ENTER(et); - if (selected_dr == NULL && dr->ifp->if_fib == fibnum && - (ln = nd6_lookup(&dr->rtaddr, LLE_SF(AF_INET6, 0), dr->ifp)) && - ND6_IS_LLINFO_PROBREACH(ln)) { + if (dr->ifp->if_fib != fibnum) + continue; + + if (selected_dr == NULL && is_dr_reachable(dr)) { selected_dr = dr; defrouter_ref(selected_dr); } - NET_EPOCH_EXIT(et); - if (ln != NULL) { - LLE_RUNLOCK(ln); - ln = NULL; - } - if (dr->installed && dr->ifp->if_fib == fibnum) { + if (dr->installed) { if (installed_dr == NULL) { installed_dr = dr; defrouter_ref(installed_dr); @@ -997,6 +1005,7 @@ defrouter_select_fib(int fibnum) } } } + /* * If none of the default routers was found to be reachable, * round-robin the list regardless of preference. @@ -1021,22 +1030,14 @@ defrouter_select_fib(int fibnum) } } } else if (installed_dr != NULL) { - NET_EPOCH_ENTER(et); - if ((ln = nd6_lookup(&installed_dr->rtaddr, 0, - installed_dr->ifp)) && - ND6_IS_LLINFO_PROBREACH(ln) && - installed_dr->ifp->if_fib == fibnum && + if (is_dr_reachable(installed_dr) && rtpref(selected_dr) <= rtpref(installed_dr)) { defrouter_rele(selected_dr); selected_dr = installed_dr; } - NET_EPOCH_EXIT(et); - if (ln != NULL) - LLE_RUNLOCK(ln); } ND6_RUNLOCK(); - NET_EPOCH_ENTER(et); /* * If we selected a router for this FIB and it's different * than the installed one, remove the installed router and @@ -1807,20 +1808,12 @@ find_pfxlist_reachable_router(struct nd_prefix *pr) { struct epoch_tracker et; struct nd_pfxrouter *pfxrtr; - struct llentry *ln; - int canreach; ND6_LOCK_ASSERT(); NET_EPOCH_ENTER(et); LIST_FOREACH(pfxrtr, &pr->ndpr_advrtrs, pfr_entry) { - ln = nd6_lookup(&pfxrtr->router->rtaddr, LLE_SF(AF_INET6, 0), - pfxrtr->router->ifp); - if (ln == NULL) - continue; - canreach = ND6_IS_LLINFO_PROBREACH(ln); - LLE_RUNLOCK(ln); - if (canreach) + if (is_dr_reachable(pfxrtr->router)) break; } NET_EPOCH_EXIT(et);