From patchwork Wed Jul 19 13:57:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Poirier X-Patchwork-Id: 13319027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75630EB64DA for ; Wed, 19 Jul 2023 13:57:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231303AbjGSN5Y (ORCPT ); Wed, 19 Jul 2023 09:57:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231411AbjGSN5T (ORCPT ); Wed, 19 Jul 2023 09:57:19 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2074.outbound.protection.outlook.com [40.107.92.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A25C71724; Wed, 19 Jul 2023 06:57:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Htr0M8fqOPdo0ZQUmDux4aWNKFM+AFgfaKgq1DoVvNhCXmbh0mIdvx6npmjO/Y25+maYRXLmqYd/XNYS7EjRKh/Kv3y/6r8Vy77sPUUtthJKd3aQL8C5AEynxzUdfgBE2Inx7xF7vvoHcGVgs0zWFN7qT7S5M3/CFbrflAqrZ/o7VT+xrt6lf/mBALVF+2ao5iqXStJL99GO+7km4gljmGzsj4QDxPTtaMD6CsyiVmT2TPTY30KcD5iB6vrcfp83cNTjopMqe2mikN2krNK3Czp9z5B7YJPvUdhwYve5H8VDLMNXISlLHNzoTPEMvEAf4oRse5zf1qzR5bHOpjlwCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5G7duKyBRwn33i/M0Orq92l5Mbix0iGcQuUUTFgRYXY=; b=AcDE73cdI6ULWf3Yvbard2MwmPbHfHuQCIIbXUdOrebJchCAHn/xM+/RlMBxv+JRKNVBIujK0dTe73MFX5RkBA7dsYFMRYG8jsGAu0M/hkRrPE5DXgKaOuPaQXy4c3doRGXU2yaHHUAHS5mF/4Qyjh4ubzA7FEIvXh4B4eY21ulGcTDpye1f7c3v7QUrz7/y7nMg6RvU3Hq312sqPFDpv0Y+AFAe6IZQFqRIuBQ3wugNqTIZt+CQku5oAJ8x5+hU53uYK4qLvnu9Xi33O0KethgnzC3kXx6jivf5R/2SntUpfKEJybNGC2DXj13HssoW2xnOChE+H1gmLkGTb5Cl5w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5G7duKyBRwn33i/M0Orq92l5Mbix0iGcQuUUTFgRYXY=; b=Kw7AudvM5WaA+os5yY7N81/jEeJ4mxqKA1aakoTkPa8LLFAMSAENs1dQ6fr2lu3C8UGO3VqfKEUd9Q2qGRGVNWAaS7FozfE+DAEj6skE4Ol1WQbJK5MIV3xPrjhlMjaHNz8eIA5kYw2nBgfE9P8bm8ylvJ4972qoy1BYkYqE99kAbK3ML6aa4YUsfZ6u5OUtDP8TfrbDPP36psHW59GcQeLckYAG02ojWjC+zRTdQEmMsjf4SIR8i0dt5BojrDxv30uxOOkILBe6sEY3lkDTxddwoIqcmNwgRV/5uHUFLkkrascvr9CcvQ9o48CeIkoVlTPtmrM7RFpmozbmYvm5aQ== Received: from MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) by SJ0PR12MB6687.namprd12.prod.outlook.com (2603:10b6:a03:47a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.24; Wed, 19 Jul 2023 13:57:16 +0000 Received: from MN2PR12MB4373.namprd12.prod.outlook.com ([fe80::982f:232b:f4af:29ec]) by MN2PR12MB4373.namprd12.prod.outlook.com ([fe80::982f:232b:f4af:29ec%5]) with mapi id 15.20.6609.022; Wed, 19 Jul 2023 13:57:16 +0000 From: Benjamin Poirier To: David Ahern , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan CC: "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , Ido Schimmel Subject: [PATCH net-next v2 2/4] nexthop: Factor out neighbor validity check Thread-Topic: [PATCH net-next v2 2/4] nexthop: Factor out neighbor validity check Thread-Index: Adm6SO0RjClS2VcqDUm7NVFWUjJK/g== Date: Wed, 19 Jul 2023 13:57:16 +0000 Message-ID: <20230719-nh_select-v2-2-04383e89f868@nvidia.com> References: <20230719-nh_select-v2-0-04383e89f868@nvidia.com> In-Reply-To: <20230719-nh_select-v2-0-04383e89f868@nvidia.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: YQXP288CA0030.CANP288.PROD.OUTLOOK.COM (2603:10b6:c00:41::36) To MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) x-mailer: b4 0.12.2 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN2PR12MB4373:EE_|SJ0PR12MB6687:EE_ x-ms-office365-filtering-correlation-id: 843f0ad7-5f98-4caf-ac0b-08db88600f91 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: DglcoChecyAPBKHmC0sIjJko9m9ecUcVX/Qk08GIKSVd53q+qmNG0up0s9Fh5nLvCujlncTzopn/iw5d40886SN7hK/DreDvfESEG3z6NVO23FvjB09k4i9hV4YVUEpbjkpvrsiWS2vyJVckxRN2TUNbjZq44FfrcM49QGeVrl1uRX4lMkewM22HuFhdYE9Yu9dchRR+Ymh2xLl+GLXUqgnSBhjkIjjoCqFmsySKVdsB9bw/E2weueEmfRL15RkTHm4rfmjl8cuqPrA9Qpm0a59ioWjyxKXPXOYGQAr4fR3VPu04oNMPtkc0pAs6a96b0ki8FcJqzRzkB9k6SkVl8wfI+ZAUWhewKTJmmSR0vdG+ZvT3WjlqXx/8HrvLIEDPmS9tpaIfP5fQcaeAnQNhRZ3Px4LRQS5iSgRilH4rdfBBAXnz6UKUXj6GUPcdGSBrBe1oROOfW27KdeUAW1jtUsADDey66fxuJ3nN8wmmek0KYvfQ00mFnSXRfjcSCCNI0T9FWNIaE3QUg9plVys8mqxUxLRdlHdifyI6DzZ2DLZgT/52ovflImshJHxRSiU4 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB4373.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(376002)(366004)(136003)(346002)(39860400002)(396003)(451199021)(71200400001)(107886003)(38100700002)(122000001)(2906002)(6512007)(6486002)(2616005)(83380400001)(36756003)(186003)(6506007)(26005)(86362001)(64756008)(478600001)(4326008)(66446008)(41300700001)(8936002)(8676002)(54906003)(110136005)(66556008)(66476007)(316002)(66946007)(5660300002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?dUnxKIStuG1czk55q5yxz2BOEjht?= =?utf-8?q?yGsTing1uvQEteUUvs4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cjv9gJ1KNvI5/DYy1HvdvQxfu9Pop9HXdMvJvgGi?= =?utf-8?q?42Zh+02oapLmcpcQZxbpyu4t7815+NN7BSq2sROPrw50kHIsy4JEBVx9NimnCVOXH?= =?utf-8?q?0yrbHpFknoVcRE3g2yIgV7oHelRJdekTFi80x3R9iMgJds7Ek3Hw26DK96Q9Jrbli?= =?utf-8?q?LeYk5tHolVDzxwReTC5rKqlvKMQE/7/yca+50UN4R/0007ocNhU8XC2tWPw++V/KN?= =?utf-8?q?QYtz9xUOcEhgiBbk7z8h/Gw9dsPdTpqeZd6vI9pvDV1djULumRoAtlmZGAx58i0Dk?= =?utf-8?q?RMgWRAZTrc+S6+lQNW9raJymiIH/U+4KHQHXedsZSSC4cnRSLr/WholEMQFScSsje?= =?utf-8?q?4jNBZv6msiCdkUFadrrkQsBHk5HISHOAEmWiM/4/yeLcg1wtoMZtLBfazAkP/npRP?= =?utf-8?q?XiwMDWiOfsPVbqi1RxpkC98aOiBPlEQsfi7pJf7QTjeh3Mcm3ATr3YuhvLJCYRVa5?= =?utf-8?q?y7fXcNP7KGBosTWuEXhsA/Kj4tstvX+jmE/SbK4bFEI+AUMKR1JQAUKlA8lRgHdt8?= =?utf-8?q?yrH9FR7FzWR9AawV7YBW8LHMRN1Mc0rc+RR7PLrmHq6slwI/lfABtyQqRlXBxEud9?= =?utf-8?q?YPiG9VY7l/aU?= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4373.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 843f0ad7-5f98-4caf-ac0b-08db88600f91 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jul 2023 13:57:16.2226 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: HhMQHGyVH8UioGs+m0raC7N9mhJ5qb4Y5F4ZGw1rsUXm8TPlDPKygFJ6Jc1+Q2UiMsx6S6WiwD+ueRTv6nTVww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6687 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org For legacy nexthops, there is fib_good_nh() to check the neighbor validity. In order to make the nexthop object code more similar to the legacy nexthop code, factor out the nexthop object neighbor validity check into its own function. Signed-off-by: Ido Schimmel Signed-off-by: Benjamin Poirier Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 27089dea0ed0..c12acbf39659 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -1152,6 +1152,20 @@ static bool ipv4_good_nh(const struct fib_nh *nh) return !!(state & NUD_VALID); } +static bool nexthop_is_good_nh(const struct nexthop *nh) +{ + struct nh_info *nhi = rcu_dereference(nh->nh_info); + + switch (nhi->family) { + case AF_INET: + return ipv4_good_nh(&nhi->fib_nh); + case AF_INET6: + return ipv6_good_nh(&nhi->fib6_nh); + } + + return false; +} + static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash) { int i; @@ -1179,26 +1193,15 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) for (i = 0; i < nhg->num_nh; ++i) { struct nh_grp_entry *nhge = &nhg->nh_entries[i]; - struct nh_info *nhi; if (hash > atomic_read(&nhge->hthr.upper_bound)) continue; - nhi = rcu_dereference(nhge->nh->nh_info); - /* nexthops always check if it is good and does * not rely on a sysctl for this behavior */ - switch (nhi->family) { - case AF_INET: - if (ipv4_good_nh(&nhi->fib_nh)) - return nhge->nh; - break; - case AF_INET6: - if (ipv6_good_nh(&nhi->fib6_nh)) - return nhge->nh; - break; - } + if (nexthop_is_good_nh(nhge->nh)) + return nhge->nh; if (!rc) rc = nhge->nh;