From patchwork Wed Jul 19 13:57:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Poirier X-Patchwork-Id: 122674 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2503654vqt; Wed, 19 Jul 2023 08:07:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlH6QhDAXYrcoxPHMe6kdaMvnXpJMxhU46WpZNo1m1f2G2tQ8KBwF4R7FpOXMzyAhkA2sQJ4 X-Received: by 2002:a17:902:c246:b0:1b8:92fc:7429 with SMTP id 6-20020a170902c24600b001b892fc7429mr17861520plg.53.1689779267609; Wed, 19 Jul 2023 08:07:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1689779267; cv=pass; d=google.com; s=arc-20160816; b=VWgQBzOo5KUmO8/Q+4WiAgaSYXFEzesXhD/jJqm/Z+XXbXJrEmWEFrF3lfGmGz+bZC /gQ2B70SfiNNTKA6bGBxfgKW+OiFXWk5QkVy1kQ1pEaT/4FONdr1O6WOAfguC/9BZrZA alCGW7sC1BvRi4c3TYEygT/vkYwH3Zfy4zMcygwe8ovDwtMA+Br8TfD3fVgRI/noDy+E G0dR1+SCYfQb/2jl7Rc8xV7SrC4CLSbDxbZYE2N/e4kgHJGVqWA+UmtVYLK0ajkKx8gV E0h/myR6hjqncRvQR6yzHzaVRfBs1LK37XMbeISiKFhKJod1sW+wH8RUv2mDnl+rAWDe 00EQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=tUeV8oIuvHrSih9x/1pXMDjhs4xpnIKANIY1SsSmAiE=; fh=P+OoruTqX4rYb5vOClp3S2Ec+4Lwbb7mgHr70Gx7J+k=; b=f0g5+SMojMKMzsZw0007DV9dr4eB4aKNXIHPGApj9HKV7JrHLuA8ULJUb3GHIJyoZe wJIQs/0MVixVGou/GlqRKppPfbKhhUkPQRPazBWO8P2xa1ps22vPgZK0zWfSyKfk+NtJ sF6L2ZhAletIGKzrWTwJTLmBaSVzKGcqnDrSwtABrdxdSC2obaM36thOIBxAkT/dg+OK ywKK9xQH+QIe+9C15oHHXuqr+qGWnvblTm14QeaBSQlvye0KDMOWEfu5dbGvNhJFCfA8 N6WnywXHJ19g4n/Q2gi1pDlDf/XBUaHL0EQXsB4iS7SDl9XfcDDeu31sAysyabkHB5tB JpbQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="aUiWmK2/"; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l7-20020a170903120700b001ae4a01a7e0si3765238plh.236.2023.07.19.08.07.33; Wed, 19 Jul 2023 08:07:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="aUiWmK2/"; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231171AbjGSN5Q (ORCPT + 99 others); Wed, 19 Jul 2023 09:57:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231303AbjGSN5O (ORCPT ); Wed, 19 Jul 2023 09:57:14 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2075.outbound.protection.outlook.com [40.107.92.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8760912C; Wed, 19 Jul 2023 06:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I62xG8eX7qsyxlAsn7pH+uR8Y9LLdWY7b9HEG7yKKwo1a1EmZyJHJ3Y2QizASdSbS9KrGQNK+uYMOQAfnEQ3yCVTau2ifBssMFuN74CjmmYPH4X3FHRzRRCNyYPZVbhLPbhPPcjSSdLgqhv0J3quXwhm04foP+cdRi3TvRlquxPPCkclGrjyiJLkXAl0IL0LYqYEDmE4JkD0R4RbehbBKzKlCIOynMn5FOgtbGlgVsdZIV0NOGtiOu8URqBymEELIY4kURANuLbFJO7Ktu/EVCJcdf2XnWbZyN8ZhLgmXXlGXSnFrorrFjx1ar4GGSYSjA2JDiyYCgf0pDWG0rW+hw== 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=tUeV8oIuvHrSih9x/1pXMDjhs4xpnIKANIY1SsSmAiE=; b=mE0BwpAAqQHjPAr5cHA2rmlGpav2jvYayl1CW84ozB0KsOuZbFAcMNTGk9TNRU4F1Fy8aQVhnWijWWc37TsxLs71n4a9LuEna09kJ29pX0WxNhXGK6Zzj6JiR7rrBvWc8Y7O1MWTahX/ocWtXu4CWAdkDry3XpzZft3mH/ymtH9q6sw1xWkiBGvqwuqiRseF4tYvthT5gY9zfpWvTIl65doImMeBZgF+KW2I7OyNXM4netzk0Qm7+wOtjGbcB2nTJE4J1+7xwIC6qBidW315JKCWwk5QHdWKnyhV9f6IuULL8z+p+l4lvE0wwqaTuBPZLB9/hbOUQElbZzr1eFa0qA== 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=tUeV8oIuvHrSih9x/1pXMDjhs4xpnIKANIY1SsSmAiE=; b=aUiWmK2/wyWjNwxBqRm+mVkC69aYaM5QzZKfJ2I7tFoJ0/xoI59ZalAWTa3eIK3Sdg4DOyr1AKd4JN7uqLhMWpCkd5nhkjKNNx5U1vhBZQVhe7InWenDj8p4DSsR16dz+gmWNqIKdNuXlXWASuU7dQX3M0ETiZ1Zpc9Faz50mDukHLMRehGeoYlzsxJimuK7v+sRJ7H2I5vdtTauNU63VNJbgLjvWXkZXV8Y/BO1/HW1iQtzpAf/iyqcEcgACPxdwAnJDWJzg/NU4giqQNy4+obenMb9u7/mNBc0N2uMuD/rvks2+7S2/FcrNpXNA4OLk+iivtPd1oKlIkizS0vTPQ== Received: from MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) by SA1PR12MB6994.namprd12.prod.outlook.com (2603:10b6:806:24d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.23; Wed, 19 Jul 2023 13:57:11 +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:11 +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 1/4] nexthop: Factor out hash threshold fdb nexthop selection Thread-Topic: [PATCH net-next v2 1/4] nexthop: Factor out hash threshold fdb nexthop selection Thread-Index: Adm6SOo2pRJ1b9JTe0qaFpcgHytNCA== Date: Wed, 19 Jul 2023 13:57:11 +0000 Message-ID: <20230719-nh_select-v2-1-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: YQBPR01CA0111.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:1::11) 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_|SA1PR12MB6994:EE_ x-ms-office365-filtering-correlation-id: 0179fdf1-1668-4f01-79d8-08db88600cb3 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: wbZ2KqZq0jkWSbxmd2wET4D2USkpHJ0X7keB/s4+Boo7TVRtRbZ/Ve8b/1PPG2bff+XRaqo0QOxunpQBHnYNLlj/QMbkzlOQAkmVkdMpFn7qIZ/GlnsWy9+hOtJoL9zHPNwfj6OtyBUBdL964J//JG/dYlgu0kzarfLKlDn+3LvadTENXS4eQ3ZN0Xy0/pARBiCYt52onele1lVxIuZEwesTU85R+2k6DzVU7AbOsh5Deg+oKJioJO50bn6nImoSbU/VhW52xm6GCel5T2C5jP4h7LYff7Am/HB8wlJQmSD1+Cj+Cuf/sDEIq9JBVWw2scwCCd6iwdNbZN5dGo6as9HmTjS9G0cZn++0elo8oH4LZFYXpFcQyg1mvLFn5WjeNbhQ3stV6ObrMRGnPnH1LshIkLf9cpyba6jMYfSZwAH20u0/oIiIcvJuf2x5qhzGhoVTTu82wQPHUTwGOtNwPFeNBOId1VglGjY0IPkKa4DFuAehtOF9lvu5lRd7B3364bQAjTMWMrGCC/60WoR0LieQeKLB2SmeklbwSBIH32CzNTas7wX5cJh4EQgYJm/K 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)(346002)(366004)(136003)(39860400002)(376002)(396003)(451199021)(316002)(41300700001)(66476007)(64756008)(4326008)(66946007)(66446008)(66556008)(5660300002)(8676002)(8936002)(2616005)(83380400001)(86362001)(38100700002)(122000001)(186003)(26005)(6486002)(36756003)(6512007)(6506007)(107886003)(110136005)(54906003)(478600001)(71200400001)(2906002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?AhoaCay1JuwoEgwfu307iAbMrfFK?= =?utf-8?q?qLAsLTxE2oP3XErUQqxLJRhRY3us8u2Da91yR13SShBgfP9eBILyNWGTwn3Zf9Wnm?= =?utf-8?q?/LktqOVLTzCSMsjT4S9hMOMe+L6RrCPKPdlu43arty5d1Ln4pc6tJllJL3lBSV0RC?= =?utf-8?q?ohnITxQzRr5AvNA+bKY+JDwTRhW8DVTcm93xEUuvZlzmzPZE0W7ZyKqNE/Brs6dR9?= =?utf-8?q?YOpPG1tz3chjiW3VINvkPh9bPd/Eu0uvZR/z6AKcIa/V3tbcBq+cqCaXn7zFrT/I9?= =?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?= =?utf-8?q?OyR31jkTn3f0H+NvQs8+cgXE9p2PIf8oB+3eZ6glwvm4FNGiQjwoeB5mYRfZ4f9yD?= =?utf-8?q?nF7s8ilbOouPp8jkPPWz3BM1GIj6jx8bZh402cBNX6jZNItQEp57Ii4++3KLOawpl?= =?utf-8?q?eWHOaJVNrOQJup2f0HB0LUCpvNzCdmOTnBwPHSDZrRlIaTGxJtah+aCEViktEIIru?= =?utf-8?q?TBEI/zrBnzBr5Z1NU0njXrmXwbk8Ll3rmtuG7n2In9YzEA44hahvCdatxzqeiKyun?= =?utf-8?q?mYWwBPxnweC66MghAQEIHBfNMySHy7ujKMDV00UKhYk/bftg0ymt+Un0mNyXxfjk8?= =?utf-8?q?7z0AHt40rdbkWkYqF13hfBS9/hGQcPzKqZo7d0+7x0kaLaiF8A0EiJ4Qkq91i2Zwh?= =?utf-8?q?5LkB6gvZTKJY?= Content-ID: <3226475388E5084BB5AAC618C3FD29AA@namprd12.prod.outlook.com> 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: 0179fdf1-1668-4f01-79d8-08db88600cb3 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jul 2023 13:57:11.4082 (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: rcJb5PL7M9me788VnfNIwydHdacLzuF7J/dmujJ0sJ1vpOmfZVCwHMgY+Z+GfxKXrrKaQJkKiGtnzgTuEejmfA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6994 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771861985319933004 X-GMAIL-MSGID: 1771861985319933004 The loop in nexthop_select_path_hthr() includes code to check for neighbor validity. Since this does not apply to fdb nexthops, simplify the loop by moving the fdb nexthop selection to its own function. Signed-off-by: Ido Schimmel Signed-off-by: Benjamin Poirier Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) -- 2.40.1 diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index f95142e56da0..27089dea0ed0 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -1152,11 +1152,31 @@ static bool ipv4_good_nh(const struct fib_nh *nh) return !!(state & NUD_VALID); } +static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash) +{ + int i; + + for (i = 0; i < nhg->num_nh; i++) { + struct nh_grp_entry *nhge = &nhg->nh_entries[i]; + + if (hash > atomic_read(&nhge->hthr.upper_bound)) + continue; + + return nhge->nh; + } + + WARN_ON_ONCE(1); + return NULL; +} + static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) { struct nexthop *rc = NULL; int i; + if (nhg->fdb_nh) + return nexthop_select_path_fdb(nhg, hash); + for (i = 0; i < nhg->num_nh; ++i) { struct nh_grp_entry *nhge = &nhg->nh_entries[i]; struct nh_info *nhi; @@ -1165,8 +1185,6 @@ static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) continue; nhi = rcu_dereference(nhge->nh->nh_info); - if (nhi->fdb_nh) - return nhge->nh; /* nexthops always check if it is good and does * not rely on a sysctl for this behavior 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: 122656 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2483947vqt; Wed, 19 Jul 2023 07:37:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlFK4YpoOh0RPmERtLZVaXBzr33tSp+xy0pj1DLlZPuhy1+L83Pl7UeHGa3L7lO+36BdUPcK X-Received: by 2002:a05:6402:3453:b0:51d:e59c:6190 with SMTP id l19-20020a056402345300b0051de59c6190mr2761383edc.2.1689777443511; Wed, 19 Jul 2023 07:37:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1689777443; cv=pass; d=google.com; s=arc-20160816; b=1LLHsqObowSPExJxcfQ7L/NnsJjC8H9C/SJxLH0ESA4w5J8/aee86ckvoskQowjwFc P2+BpobtjOGMKATXbJOjfRIqlcbx/MwN8mAtHe3X+YDgjX/rt++kUJDl1YgsWnSaqEAX t6mVoNrfxbU5q8DYafFSHLesVtPc5NVs4qNTfk7ceXVuLAGf1DztjP4O4OGSlnBFhOID XjHXXyuftTbUUyzGdk+VlQ7PFlWFZbfwvsFn4EMvmUTRSUfIRYsKAM6QinCqTEWwD+pB C6o3tKNHU/gKvpBEIM6RIZaJCLEtQo+5s4o9O+Ef3gggoQwoU+hKX34p5EfG4BV8MmYP Xigw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=5G7duKyBRwn33i/M0Orq92l5Mbix0iGcQuUUTFgRYXY=; fh=P+OoruTqX4rYb5vOClp3S2Ec+4Lwbb7mgHr70Gx7J+k=; b=t3W895QsLen0DWBiI9NGMIhVp9smRvuMUjajD681okVgFpO48Edk8EW3oukU7g4e49 1lW4FOT/tv5Y/BohNVKflo4HVjAeaRdAoha3Ht6niPmy3rkGE9QpTGXlERrLYkBO2hfU LcnJBBLJPCm7kZOyqYUJDaYHijgWBoDhBRKQoN19g7M0fxbF2HfniEoBtrqni/Hkk1XS vkhtt0SZMqvTvDQfQLljawZIR2Qp7Zz5WDKdndnP6FDcbma58X/eA+HvEvtxcjy6+wUE b2O5HqZwigTvaduIL5cY7mjyrypOe0RxFKRqgtJQyo2cVyGW+PuHky79nZZaNybWXaeq Matg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Kw7AudvM; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d23-20020a50fb17000000b0051dff4faa21si3095999edq.176.2023.07.19.07.36.59; Wed, 19 Jul 2023 07:37:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Kw7AudvM; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231308AbjGSN50 (ORCPT + 99 others); Wed, 19 Jul 2023 09:57:26 -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?yGsTing1uvQEteUUvs4uQ2+t67yoxOBM8Em+bQGIjUINP3Im839Mq8He5ZRgsWV2w?= =?utf-8?q?EW8mKnTUOTFYyECzJbJIud56AQiNXrtQgWygC5SujTlnKiPvQjOOn7IU0SfnJ9yfw?= =?utf-8?q?H7scUkL0f1H6PdIELmNux7iLr/OIVlJTBNJkGwPvf1AraOyTKui+Fq/wbQhEP+8Nf?= =?utf-8?q?M6LmedqofLW5bF3VaabIfSdQUri8rzeq8hy+lg2+Qq4BsDxgSOICJ+/jVUZ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f-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 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771860072810454328 X-GMAIL-MSGID: 1771860072810454328 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(-) -- 2.40.1 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; From patchwork Wed Jul 19 13:57:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Poirier X-Patchwork-Id: 122650 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2482567vqt; Wed, 19 Jul 2023 07:35:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlGadnRaqPMtHDXYjyAQDmbyDLITvK92+31JKYa00KgGX1Y5Mh4fKIWe5d/3Z2ntMd+Cd2Y+ X-Received: by 2002:a2e:8697:0:b0:2b6:df8a:d44b with SMTP id l23-20020a2e8697000000b002b6df8ad44bmr41744lji.36.1689777311880; Wed, 19 Jul 2023 07:35:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1689777311; cv=pass; d=google.com; s=arc-20160816; b=qjN8W/Gez7vQt+l6tYy+RjABhNXIiVvL5wmNROIRT8Yuu/yo9NrV+7lw3aGqQEvh2d eTqXTqVvLRHaMF9lWBegHU+o+pHkO/Hutqoe6dm3+dlZirAFvTEnQ3n5UH2Wd9O9+tv5 tKLOSFz7hnAWyXDo/cuKGBpYHsuzr9V6cA4K+rg+jtCDcU9RcVGbmIkwplpKFC/Bg6tw uQdfsjeZpFgsvCaPii8L+AstvqeVVLcsUarxRxI+NQTO8Xp7uHGYwTxycoqD0+Jwu7TB a+wwyH34Vz1mgwHUtllQYybIsZ+Z1//y72Y18nH8wFjvUpnACydBSvr8+fEKs3/rAKaz 9W3A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=xxpO4bcWuo1MgkT2NiTuTmmshEYXt3etyzvEDEnQDdc=; fh=P+OoruTqX4rYb5vOClp3S2Ec+4Lwbb7mgHr70Gx7J+k=; b=TwplI0H2L5Abl+qC/dNZmUbAE9KGlB+92K13qZsnTaE2Zd/2b27irqRvwRYNtNZxOb TVVRnErYY5h1xacTNqqxxKFrdUvw7BOA2WC9DmeYQH4F7r734sW+6JDDNzluSNZufdzQ Pxu6WJLLH34LEEJIeF7bRyEqqjhtlzaOdtm/KvOz/T6Gg2XCAHhDMaEZ3HRUutervX5I 1REaoElhsqzQc1+Yyn6M8o+35Y4fRC+xNhTygbEoRSbi6F0BGGrucSe+Dmt9dGmgXu3C uipATHGOja3ZXgdQUeAQ0OvmmUzrjBjxxMK/MtkR7L9tub1NpL48guD4DbwTFppnONhG LYTw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="M/QqG0RH"; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p25-20020a170906229900b00992f8116abdsi3043623eja.480.2023.07.19.07.34.45; Wed, 19 Jul 2023 07:35:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b="M/QqG0RH"; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231411AbjGSN5d (ORCPT + 99 others); Wed, 19 Jul 2023 09:57:33 -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 S229915AbjGSN53 (ORCPT ); Wed, 19 Jul 2023 09:57:29 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2050.outbound.protection.outlook.com [40.107.92.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66A041BF5; Wed, 19 Jul 2023 06:57:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yrtmbe4o94yrI2Sly2digJt5GyCs28ixFN3WwlHLOGFDBUZWU+5j5SFfadkh1KOEUUUQh9NzSHMA3kQYN+czX4Fi0xB7aLKJ8BQ4Pm74xStK8GTsxnTphrcMitHtRJ8LY8RoLqcjMEWabkehXoCdIzK+5OrWp7NgQVx6IHveG/Bi/YFbsjC7sQ+RgDImuBAqAr064Eqq4n+rr+ShBbyfTFFAiwCjpi9gZ5FgHgudhf213v0C9xDPkB+8yIOaCkRmd6Z1RFGYkSAqSUxSvMCYT8nK8Cx62pKc7k1AFsTXwhstiUu2VIIihnzn6ww0AXRqGoTl+c+C+5Ik4lJSaMguVQ== 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=xxpO4bcWuo1MgkT2NiTuTmmshEYXt3etyzvEDEnQDdc=; b=KXeFyAMV53etekt76F0m6VpNOdd1g2qhclpP5r0ePB7caO7VdWrbcizTWRXfhpQfzssJJNKLdhhDM6ZvFIbHuYojL8p1A8D1YlVZ38FTyD3JSTC8PI2yom9/f7RvugFHoOwcLWy6Wui1IuPCKWrE38xbVqBthrmV+itP+b5GTddsLf2e9+62XTprBFOJzbX1TmPvMaIbwRKBDXLaDxdKODFAJ2b3X8+44nA4d85Qu1hZwsDnRViQbA08b0XaOGHVSJ0CzxNvsOI8IaBYWgfpnvlypcg0r25gWjXxOiDc5MaKzQwObERsTe68akodF8lV6/Ks5MS9L85SEFLRcUaE0A== 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=xxpO4bcWuo1MgkT2NiTuTmmshEYXt3etyzvEDEnQDdc=; b=M/QqG0RHUJ0mOgTGuSUhQwrO5g7m+/dfWUcagmAqyOqQlmhpJI5dA45PJBFk4u7q+Q7fMBmDZ4wbAf0H13Jz6TLvbzAP7NTBAgI1y/YFf9/7D+BwV/3jP9je3eX/tR+cibAK5YwZyHORiQdSUnQMRyNnH0CNyidkruDnflHqgaycatSn+YOc2q33gwD8rWw5JeE78nEWcYqile9KYhMCGn9Ks6A5y2cPBpc6YBFG801Htk7hvo95fc60ZtwWs/feCgzg7xjT73uUkqBSFCEM9VLBe0TFGZ7YK14L0DWh89L1nieKqBWcXdI4fxl7EBb4nU7zcmqMCmpd1+rS8s7qSw== 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:22 +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:22 +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 3/4] nexthop: Do not return invalid nexthop object during multipath selection Thread-Topic: [PATCH net-next v2 3/4] nexthop: Do not return invalid nexthop object during multipath selection Thread-Index: Adm6SPCTjLnm6ZDF2UuYdzGvm4mP9w== Date: Wed, 19 Jul 2023 13:57:22 +0000 Message-ID: <20230719-nh_select-v2-3-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: YQXP288CA0028.CANP288.PROD.OUTLOOK.COM (2603:10b6:c00:41::40) 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: 1b305924-6441-45d3-f67b-08db88601311 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 9SrbSJxm0ffRrFOZu2eWUcL5lVO6wXLc73ytkiYB+nmL874YjRJh0J7BmDRlYwY3JgaxdgeQgOdGhzqBrEWpks0SJKR0SwQoorAW5tS8G+qUdyxDX7HJ2SSfYDOPaKRcNTxAxLhyo/1FEnNgs8O8jjWODd8deMLbs7u2MWcOBmOzhZ/w7lpDelrOaKt+fxypL9Wh3C6HmtLve8EIHlTFZQGxxctZfXXlP6DR6XWk1GPq3kIbrpt4IfV8VIQUpuDhx+jKMok3rtj1n/qCNONsqUemS32NSCBnllyTXoQ7rNJI/RMMiNMjgRnReIm07Bzx5f7mJzeuapAheonhepFrNOg4+jgvePasOEtTVYRGOggxfBySciPMz/7cOGeU0nSbs2pwzpWw6dJeXtAPKi/UhbozSDZYIqr2ahbFV3tLzG5vEWyKI8Ye8+9yQPraox0HUiyq3gdBQd0/fl5BjFV8GqDs6eahfTjVN1wE9h2XDWm6FlO4moLiCz78c5R9zFfQod8qLUHIjwbz56QQB7lF/mOXZKaQcjyf2Xu3qQo+c+KTZO3jWYW4Cur8aVwj3v5Q 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?fxk8FmSI8xb0bBtxbxXc9nRnFL21?= =?utf-8?q?HvehY+Zec40UORO9C0W+qt9XHD7FGVSv4MvhZRugMSux7Pa8YHxRqijkyQKUr0wT6?= =?utf-8?q?gGeDQVJWS0fQm1V9km/ro6Vo7j2d71UnmdoEgpZLDz1CXa9AwWzdMNGv1ltWB6kp0?= =?utf-8?q?aAIlec4fshwdXD73IUPl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qvjaBs8JCja82vkwW/JCwmJuKoo9Qzzcqa1dujVvjx5O?= =?utf-8?q?oNR892K/E3s8G97AMHaEIT/zKrk6LrTo/tl7CqIRMeH3m044yRya+njgJckE+u9vv?= =?utf-8?q?r7Vk5krlALl14S2qLT4uccYa6EPcmFDWS+RT85HZ0vqUplC6IBDooskeQUCPhSoij?= =?utf-8?q?ztMSD4k0WCPzNPYv1v2JPOEB8GG4IMLMpApYSm0rk6JOX9nPcRQpafsCTeg0LHg3v?= =?utf-8?q?5OmQBEljeEVA7qv6FLtW8YgRYGxHuU76xWA+iwCLXctTG/XI9z0GHNdA9dQ/ojajR?= =?utf-8?q?HDcdjua5tQf87HWGQQoCNJ63pi1x/Pm92bpZtRBkjGDyXo9bTTzb9TPRWMI9V5aIt?= =?utf-8?q?DHlUvLwl0aWG26tNTMCK3qP2ZrHzfPD2SfnA9IlSArgb8jVAxf5P7YC9xk+inDjKg?= =?utf-8?q?29+uRSPV0TLTD4f8EYrweVtN19IayG6KQBfFKgXFv3uy/d/dO4VCJx5z4XGGvn11s?= =?utf-8?q?lyk90C4F656s?= 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: 1b305924-6441-45d3-f67b-08db88601311 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jul 2023 13:57:22.1009 (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: CFRE29vqlxDz3Z86gHnSe3hJ4JNyZ37NqhkAjrkUcg7ckagKEYODgck26oEOoKRFL3Y+SEYWaW7P2B+13M7aQw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6687 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771859934943277419 X-GMAIL-MSGID: 1771859934943277419 With legacy nexthops, when net.ipv4.fib_multipath_use_neigh is set, fib_select_multipath() will never set res->nhc to a nexthop that is not good (as per fib_good_nh()). OTOH, with nexthop objects, nexthop_select_path_hthr() may return a nexthop that failed the nexthop_is_good_nh() test even if there was one that passed. Refactor nexthop_select_path_hthr() to follow a selection logic more similar to fib_select_multipath(). The issue can be demonstrated with the following sequence of commands. The first block shows that things work as expected with legacy nexthops. The last sequence of `ip rou get` in the second block shows the problem case - some routes still use the .2 nexthop. sysctl net.ipv4.fib_multipath_use_neigh=1 ip link add dummy1 up type dummy ip rou add 198.51.100.0/24 nexthop via 192.0.2.1 dev dummy1 onlink nexthop via 192.0.2.2 dev dummy1 onlink for i in {10..19}; do ip -o rou get 198.51.100.$i; done ip neigh add 192.0.2.1 dev dummy1 nud failed echo ".1 failed:" # results should not use .1 for i in {10..19}; do ip -o rou get 198.51.100.$i; done ip neigh del 192.0.2.1 dev dummy1 ip neigh add 192.0.2.2 dev dummy1 nud failed echo ".2 failed:" # results should not use .2 for i in {10..19}; do ip -o rou get 198.51.100.$i; done ip link del dummy1 ip link add dummy1 up type dummy ip nexthop add id 1 via 192.0.2.1 dev dummy1 onlink ip nexthop add id 2 via 192.0.2.2 dev dummy1 onlink ip nexthop add id 1001 group 1/2 ip rou add 198.51.100.0/24 nhid 1001 for i in {10..19}; do ip -o rou get 198.51.100.$i; done ip neigh add 192.0.2.1 dev dummy1 nud failed echo ".1 failed:" # results should not use .1 for i in {10..19}; do ip -o rou get 198.51.100.$i; done ip neigh del 192.0.2.1 dev dummy1 ip neigh add 192.0.2.2 dev dummy1 nud failed echo ".2 failed:" # results should not use .2 for i in {10..19}; do ip -o rou get 198.51.100.$i; done ip link del dummy1 Signed-off-by: Ido Schimmel Signed-off-by: Benjamin Poirier Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) -- 2.40.1 diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index c12acbf39659..93f14d39fef6 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -1194,20 +1194,22 @@ 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]; - if (hash > atomic_read(&nhge->hthr.upper_bound)) - continue; - /* nexthops always check if it is good and does * not rely on a sysctl for this behavior */ - if (nexthop_is_good_nh(nhge->nh)) - return nhge->nh; + if (!nexthop_is_good_nh(nhge->nh)) + continue; if (!rc) rc = nhge->nh; + + if (hash > atomic_read(&nhge->hthr.upper_bound)) + continue; + + return nhge->nh; } - return rc; + return rc ? : nhg->nh_entries[0].nh; } static struct nexthop *nexthop_select_path_res(struct nh_group *nhg, int hash) From patchwork Wed Jul 19 13:57:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Poirier X-Patchwork-Id: 122639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2470335vqt; Wed, 19 Jul 2023 07:15:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlFnpVKkslwRek5nye4J40hl6BWNk9xZMo0nAeVULbgP+AP2dKfVaj+2qGZGjucDlDPklBSW X-Received: by 2002:a17:902:e5c4:b0:1b8:50a9:6869 with SMTP id u4-20020a170902e5c400b001b850a96869mr5749866plf.66.1689776144780; Wed, 19 Jul 2023 07:15:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1689776144; cv=pass; d=google.com; s=arc-20160816; b=Itju8aA2vxURGpO7sTrmgwo2f3EJNln3AwgGtoXArqks5Wo/yJsjLCwPftnRv6LKPT MB5xSz/Of/UDLtXZt0JxR1RY2iTY3jGGIJIiq9bvdI/PUUziK+6oq+lflIBmhdq0IFFd n0HyRcHc5KaDOl1o9w3vQFhAQ0lsORlhXfSyL99zNdh562a/kUF2zKMMMTq5Dpvi4bfC J69ZaYc2+wfib4HzaVI47jGQVLkrjuPn9hfdmPbO9RfQeC4AifQgknUigQXppWduOxin YAdMep3DdxPZKeb9iLSLeWEt7gA992EfSqIe4gq7XSuhPrVjhN9TNbGy8BlpdRfgInyK 04sw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=mHreOrxHmeQscue0UYzAUvLaEA5x2VQ2tDaoVTf6vR0=; fh=jMLAnOc50wK4IAYUv1ZKYkNIPQtbhvyVUXux3m1hUuM=; b=INvQI2PnE8Gx/tMtK3WyDoqmCqS4ri27GyryMRJenjhfM2iK5JiVaTXUdP/XdQ/0im hhERd4XUXw0ahySjfJEc3RWjXd14dpU8Kc0LjatogcVk7YEfE9mgTo1HNEbv/F+S4V9q 6eavGUi5LwtYNf4gziyv/nJn60t1DwjGnhaCpco4mv3gYO+MpXs09Iy+EansPRvGfp0/ K0Vx8cS9yud1AjlZGrbjVFYoy66930/VD30fUUuR0UL5jPIOowsIKUJeyUbqdu6hm9s0 8aLNcmSZnfY99iEGg8I6+WkgWFY1/vnEING3opeO78eq69BKwTBBDTS8dv0qeTCYNrRO AOkg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Pk0fRJ5l; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ij10-20020a170902ab4a00b001b3d6c68bd1si3351233plb.643.2023.07.19.07.15.30; Wed, 19 Jul 2023 07:15:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=Pk0fRJ5l; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230186AbjGSN5p (ORCPT + 99 others); Wed, 19 Jul 2023 09:57:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231434AbjGSN5n (ORCPT ); Wed, 19 Jul 2023 09:57:43 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2050.outbound.protection.outlook.com [40.107.92.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E68A1FFB; Wed, 19 Jul 2023 06:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LCVrFmt5NKhRTsGhnlgU6ohT9/+6HK9tEwzn4JDeIz805o+ky1WjX4zXEQTKlz2ZPp+J4ComvIq++VggrUUZbVotQktsIHG9PWKbrdqVTbp/30Esx0emdb/LvEZ0iGSl/IrwSM4z+NC1NwLk2oPWoskFlg0MOF2whsDljg8wAo1TXjy9H6R21bpxJWFB1AklDkciYPt/MGq/YIIBhX3MU2mx6FR5vp9gXq8tc2VB3fZmld7oP4Kk4ErAHD0CBbeh5Rbx1+Y1f9n+7JTF4bVbSJh4/CN6Blbg4C2FgaDcePOk4S5EjnbJWD2sZwD58AANX2m6pqI+DCEfYWdSMWtt1w== 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=mHreOrxHmeQscue0UYzAUvLaEA5x2VQ2tDaoVTf6vR0=; b=Y6J7dLe3Bv6QXEFDj2Dv8aqd6p2Q3vWX2094cjd9tdaeMX6vHcq0M/xmdqHRS0gCa8NRgCxb4vzk76n1uiRGLMM23Oc9+dxYsAtxazwqKphKxlWlHIeJmE+u2E30TvDc72k0UrTxkaAor+Nf+H9tQzzxWGGzvpbxnWWdFkah/9+5DRipGs2S7fv023fxSmuMZtzfc45mpM9LvvN+ehc8Bp3n5Ue0kFlBDutcQSyesMvvhyDPWRu5BrmotvPEbMSpf/qcpc1fnngxFR7kFjfaNxbB2ACm+GrcOqqNq+XDIei5ESPsjNqBAEPSS0IIe2Cthvn/lPM+3nABOrkf00VJfQ== 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=mHreOrxHmeQscue0UYzAUvLaEA5x2VQ2tDaoVTf6vR0=; b=Pk0fRJ5l0cwtD8YsmKLHbSOJOYWr/ClDW1npDFvUJyo//FBFSEGnvPi+UXz65p56S5KgRjviXRwUCdV//QwQAN7d3004baNUnl+uIe5V/7SLOL3DTHa5A8EMPLRWcuhjn1JH0OXyqE3JRZV2ZP98yrETbwwIJLCQV1Kv3LZFdMrpBipCGUs1kszEJAr4Al5rz7UYKBB7lX3yEBXFWbq+HVRBb+/9O8IqOSX6muNlPn0JSe19K/muhbfUsTiUS4hf27bEH7Q+FwkECbQ5JOVPvLAgsTRFOB5HEAFKzbd4vduPVZgpC+vBdR5no/X40lWYrCOpmx76AvXoQMEy1PqDLQ== 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:27 +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:27 +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" Subject: [PATCH net-next v2 4/4] selftests: net: Add test cases for nexthop groups with invalid neighbors Thread-Topic: [PATCH net-next v2 4/4] selftests: net: Add test cases for nexthop groups with invalid neighbors Thread-Index: Adm6SPOwIKYdSXmxeUyme8WchlbtrA== Date: Wed, 19 Jul 2023 13:57:27 +0000 Message-ID: <20230719-nh_select-v2-4-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: YQBPR01CA0033.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01::41) 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: b927cd76-6496-43f2-22e8-08db8860162e x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: YbBlhdjsajkkNGTzG6GYm6OJG5xLZ2wfMUzLsoEohLFkyPJiUHtDdsPdk6Jc929t8qD6j3wzR5scFAlbSpota3L322NKlArs3GNXcuIkbCRzGpqbhTsTtI0yRjjHJAAySRVfrl+6AiA3S+FNZW76hRhQUPZOnnouz0FE1JrZK81sxwlhotYZTrx9yYxoafWZJk/9bl+l58EviyyWfWvoZpDdYNf+jdwh9bN6CsmUY3uUZjB42kxMYKSIBOSgf90tSw7DtLedsbrO/pfvvnjVSBKY9CShFhXoyPpTt97OQ4SCvIVG/NEND/lSbElGSw2EiO7sochBgtQ0/hZYcg5yVhtxbnF3+KZbA03LE5+8Am2Y92EIdFYjL8quw/TzpYzpYd2399VcuEJYuUk6CwD0bpkAUSRMtOKe5RhkaUnvlw6eE0j3obXbJvdG0Cvbq1bPUtwuL1dXcv/mG+HvDPen8xWbOFuuiQy3XEjfLKeoEqvj01v7q1GDCEQLchk2aAfkLUQMiqJUoEC6qw6Rr6WuLK0hZaeqc5/1vbmrBh1T8Odp9Sv3CP5AYUTrFKK7d8wo 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)(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?6Hzk4atqK4krWnV1DWwJ+M3npQZL?= =?utf-8?q?r3FmJYM8BXSr/clY/4NPYYutNAl0V6OIDIy/FGbpCC39Q1XTymc54jUn2QqwaSJY9?= =?utf-8?q?sQ0BdLye9RIsEvyWmoAtwjGF4UxivmHJly+teFVyq1VHBdVSNNomc4cdQom7tzXVi?= =?utf-8?q?NGiCtF2FuX3Kl/9ZruRk/pyRmuvj2/dRNLWqCih/97HHhu/kJ8yjt80oihAecUn1+?= =?utf-8?q?SfjIl418GLcafkPoTuZ/b0Zf4xHxORK9h/41uWJl46ilDnG8s3A74JqjKiRmUvQXo?= =?utf-8?q?WboD+qgXITILLhc/UXywjUKgLH8bX8a8hZkca1Xo5JhsC3W/zs+qMFCVx3/cQiZ/4?= =?utf-8?q?81BnqvlfBSYNVsKyK5qLJaFTAzXx15HXI9Ux+mfOUo+7W4HNpsYjXoZCK8CD1goDj?= =?utf-8?q?7RQhnVFNJQkpXXlDCn0FXV2rzUhMOOPqT13hxENZMx+0kI6yDd/958NCVH5nwKpWu?= =?utf-8?q?kTzHTXOROYiiGRaCh4gbUXzPqxYdi118mkc2qmpTSFR7IOaVf8Qdevur1caDYENPd?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utf-8?q?Y3sAhm3VWn6F6R0LvsFcWWvmbaKex6XcXcCxtaoanGn3r3S6tzlbC1cR5FgDvdJsQ?= =?utf-8?q?Y596ykyhV1/XaL66sK+h9PwLMGWR6wwcmkigrvN+AzgK0F3apX0e2+I2DGTC8RLfe?= =?utf-8?q?8vdI6PrDc/+w?= 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: b927cd76-6496-43f2-22e8-08db8860162e X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jul 2023 13:57:27.3386 (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: opR0o+KslADtf3gXgBq+ILajGfBVh4AlIMKsae1jbjrcMtSFeWIXQkNbpXUoZAMX9sfpoZSbej1/0uawRbRptA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6687 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771858710780223950 X-GMAIL-MSGID: 1771858710780223950 Add test cases for hash threshold (multipath) nexthop groups with invalid neighbors. Check that a nexthop with invalid neighbor is not selected when there is another nexthop with a valid neighbor. Check that there is no crash when there is no nexthop with a valid neighbor. The first test fails before the previous commit in this series. Signed-off-by: Benjamin Poirier Reviewed-by: David Ahern --- tools/testing/selftests/net/fib_nexthops.sh | 129 ++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) -- 2.40.1 diff --git a/tools/testing/selftests/net/fib_nexthops.sh b/tools/testing/selftests/net/fib_nexthops.sh index 0f5e88c8f4ff..54ec2b7b7b8c 100755 --- a/tools/testing/selftests/net/fib_nexthops.sh +++ b/tools/testing/selftests/net/fib_nexthops.sh @@ -29,6 +29,7 @@ IPV4_TESTS=" ipv4_large_res_grp ipv4_compat_mode ipv4_fdb_grp_fcnal + ipv4_mpath_select ipv4_torture ipv4_res_torture " @@ -42,6 +43,7 @@ IPV6_TESTS=" ipv6_large_res_grp ipv6_compat_mode ipv6_fdb_grp_fcnal + ipv6_mpath_select ipv6_torture ipv6_res_torture " @@ -370,6 +372,27 @@ check_large_res_grp() log_test $? 0 "Dump large (x$buckets) nexthop buckets" } +get_route_dev() +{ + local pfx="$1" + local out + + if out=$($IP -j route get "$pfx" | jq -re ".[0].dev"); then + echo "$out" + fi +} + +check_route_dev() +{ + local pfx="$1" + local expected="$2" + local out + + out=$(get_route_dev "$pfx") + + check_output "$out" "$expected" +} + start_ip_monitor() { local mtype=$1 @@ -575,6 +598,112 @@ ipv4_fdb_grp_fcnal() $IP link del dev vx10 } +ipv4_mpath_select() +{ + local rc dev match h addr + + echo + echo "IPv4 multipath selection" + echo "------------------------" + if [ ! -x "$(command -v jq)" ]; then + echo "SKIP: Could not run test; need jq tool" + return $ksft_skip + fi + + # Use status of existing neighbor entry when determining nexthop for + # multipath routes. + local -A gws + gws=([veth1]=172.16.1.2 [veth3]=172.16.2.2) + local -A other_dev + other_dev=([veth1]=veth3 [veth3]=veth1) + + run_cmd "$IP nexthop add id 1 via ${gws["veth1"]} dev veth1" + run_cmd "$IP nexthop add id 2 via ${gws["veth3"]} dev veth3" + run_cmd "$IP nexthop add id 1001 group 1/2" + run_cmd "$IP ro add 172.16.101.0/24 nhid 1001" + rc=0 + for dev in veth1 veth3; do + match=0 + for h in {1..254}; do + addr="172.16.101.$h" + if [ "$(get_route_dev "$addr")" = "$dev" ]; then + match=1 + break + fi + done + if (( match == 0 )); then + echo "SKIP: Did not find a route using device $dev" + return $ksft_skip + fi + run_cmd "$IP neigh add ${gws[$dev]} dev $dev nud failed" + if ! check_route_dev "$addr" "${other_dev[$dev]}"; then + rc=1 + break + fi + run_cmd "$IP neigh del ${gws[$dev]} dev $dev" + done + log_test $rc 0 "Use valid neighbor during multipath selection" + + run_cmd "$IP neigh add 172.16.1.2 dev veth1 nud incomplete" + run_cmd "$IP neigh add 172.16.2.2 dev veth3 nud incomplete" + run_cmd "$IP route get 172.16.101.1" + # if we did not crash, success + log_test $rc 0 "Multipath selection with no valid neighbor" +} + +ipv6_mpath_select() +{ + local rc dev match h addr + + echo + echo "IPv6 multipath selection" + echo "------------------------" + if [ ! -x "$(command -v jq)" ]; then + echo "SKIP: Could not run test; need jq tool" + return $ksft_skip + fi + + # Use status of existing neighbor entry when determining nexthop for + # multipath routes. + local -A gws + gws=([veth1]=2001:db8:91::2 [veth3]=2001:db8:92::2) + local -A other_dev + other_dev=([veth1]=veth3 [veth3]=veth1) + + run_cmd "$IP nexthop add id 1 via ${gws["veth1"]} dev veth1" + run_cmd "$IP nexthop add id 2 via ${gws["veth3"]} dev veth3" + run_cmd "$IP nexthop add id 1001 group 1/2" + run_cmd "$IP ro add 2001:db8:101::/64 nhid 1001" + rc=0 + for dev in veth1 veth3; do + match=0 + for h in {1..65535}; do + addr=$(printf "2001:db8:101::%x" $h) + if [ "$(get_route_dev "$addr")" = "$dev" ]; then + match=1 + break + fi + done + if (( match == 0 )); then + echo "SKIP: Did not find a route using device $dev" + return $ksft_skip + fi + run_cmd "$IP neigh add ${gws[$dev]} dev $dev nud failed" + if ! check_route_dev "$addr" "${other_dev[$dev]}"; then + rc=1 + break + fi + run_cmd "$IP neigh del ${gws[$dev]} dev $dev" + done + log_test $rc 0 "Use valid neighbor during multipath selection" + + run_cmd "$IP neigh add 2001:db8:91::2 dev veth1 nud incomplete" + run_cmd "$IP neigh add 2001:db8:92::2 dev veth3 nud incomplete" + run_cmd "$IP route get 2001:db8:101::1" + # if we did not crash, success + log_test $rc 0 "Multipath selection with no valid neighbor" +} + ################################################################################ # basic operations (add, delete, replace) on nexthops and nexthop groups #