From patchwork Mon May 29 20:19: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: 13258945 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 321F010780 for ; Mon, 29 May 2023 20:20:05 +0000 (UTC) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2074.outbound.protection.outlook.com [40.107.223.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9B0CB7; Mon, 29 May 2023 13:20:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WOpC5pH/0qSNjr+UXRXcNDJDrAhJN80yuiyulntZzzPDm4fMuvuZbfRtdtmtEN5JeifCJrToMDopIMwlhZeRU3DIyUQj05xPnQp1OcXQFmI7uIw2iEwV/IRSe8B0K7pLGdLMSyoG5QE8YrKwbtbzykyu2Z95lymlP4O+ldLxIe4ujkg1f1fzT5ehRfl3PWVPygVqcfVLwKlZ8LoTG81DW5y4J0SPr8OmdNzXF3fMCS9/abKjx2wtgdbQ2iz5jcy5jGVgeN9PPFweNtAb9NY88sXGzgaDciX7Im1ZWM8EYiD4zIwf0Zgcib8HPxJzwLiph4PAqOa3K7+F9E9sb9HUmg== 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=v6rhKu6B8MykQQnV3BsVHwJJwxznNKpwTwyi45MSWfU=; b=XzzzxlMi3LoNPEU1PDhBjirAymL8H0qM9MosVPjngo6bDt6//SKNVlGW8s5ECNfaqi81t8hP6u7Wre74kKMCVd+N0hE+Rgeit91b5noVshna+YT9kBRJEancvHyYa2y5aAG1xFZnnLwmqjI4exux7PAoU2OuxuaB+9b7saV8ljmbm2kNFk/JU4eZlTg21lBEhtbvoq8aEYrOlVcxfS1GWd4UT0nos3Hj/nDt6cw1Elbt6w604HQxccMoAsy84OQccKN6Vh33bCXUkq8Jd7jWg9aI//HvCydmkVRR1orA3asfSSNigcFAoWwQs82cao7AseTrod6Wd07rU58f2m0Blw== 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=v6rhKu6B8MykQQnV3BsVHwJJwxznNKpwTwyi45MSWfU=; b=aAn8Wqnah3j20D7mPApfuolKaLIsJPeIpwmCoVkVjkM/YUkJ/mRsz/YqAEpGWL7y5EtWlkkaVmyQ+1c+ouUCk0XHvhw+64qk201osCwWJLUxLaNDc8iWRNN3+JtTlTXTMWFPgufCr8vsCFmEuMaadg2yTtBUTqKm9H/PT29fYKObqvFWIwTq3NQyO23WKcQ13Lfpo1ZPH/O4YaCWyyrTMi5IUV9cbdvlp8BUSgVG0Z42Sl39eWeNJUL2XGkeizjIdmJd0LaQI2HZSCb6puD68j4bSoeLDrwnmufGMzVxm5eJ1KCrEqCTWQSzg/ed1TaqA8OPbcyyIkf5OUEhwFPOGg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) by IA0PR12MB8254.namprd12.prod.outlook.com (2603:10b6:208:408::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.22; Mon, 29 May 2023 20:20:02 +0000 Received: from MN2PR12MB4373.namprd12.prod.outlook.com ([fe80::96fe:2d5b:98bf:e1da]) by MN2PR12MB4373.namprd12.prod.outlook.com ([fe80::96fe:2d5b:98bf:e1da%5]) with mapi id 15.20.6433.022; Mon, 29 May 2023 20:20:02 +0000 From: Benjamin Poirier To: netdev@vger.kernel.org Cc: David Ahern , Shuah Khan , linux-kselftest@vger.kernel.org, Ido Schimmel Subject: [PATCH net-next 1/4] nexthop: Factor out hash threshold fdb nexthop selection Date: Mon, 29 May 2023 16:19:11 -0400 Message-Id: <20230529201914.69828-2-bpoirier@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230529201914.69828-1-bpoirier@nvidia.com> References: <20230529201914.69828-1-bpoirier@nvidia.com> X-ClientProxiedBy: YQBPR0101CA0284.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:6d::23) To MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR12MB4373:EE_|IA0PR12MB8254:EE_ X-MS-Office365-Filtering-Correlation-Id: 6f2f2bbf-9f23-4abb-06ef-08db608214f4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qKuTubFa7bkQ6YdEKIGhdUsCsh2GNzrniJI7SAVaWQtpg9zIjDkOvBrTD27A9XXkH6A6qcWga3WQ9xRJr83oIlq1KVWK+6awRCp8TDqjGcpJYrnyr7XZeLyhR7Z76On8+GR5+2pa3+6MpLcG9CAdIjRYjoZLggIcyUqnyYRvcAKwcTg4OzLVQcc/p+KV3l6bIRSyqVt4e1EhUYhjhSASf6/G+zRUysmufiC1+ITALJUiRWF+Z+zbBXyva/dTawK6GoEMUDipgBcW1jKISPhebXbh67R5rULrx0FI7Yk4T5SNniI5qUdaCAJ9MjaqpmKUrV+6Q3Yu6nbuS7HYkQ1aAbUCRf1aXkL095iaVX6dP0qjHP2jWyJRJ+HRNmJS0uP9xMBRcsOmd2qGTwUNCe7dFJLQzrq17hyRAAfi+cO6dmz4w67vxgQHAMoz+LmfApmNouubr6NbAaTsEhZJdcT80yKJpfMoA+omM11dIsPSJhVUK5s13wXLK5Onh/U/tcLlFaGHpZ2PyKMbeGoIwYxfTVsXJzBWcAZUqtYX+ApFxVb+CJLoY2luxkYPMGytdZ+d 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)(366004)(346002)(396003)(376002)(136003)(39860400002)(451199021)(38100700002)(478600001)(2616005)(66556008)(83380400001)(66476007)(66946007)(54906003)(86362001)(4326008)(6916009)(2906002)(6666004)(6512007)(6506007)(186003)(6486002)(26005)(1076003)(316002)(41300700001)(36756003)(5660300002)(107886003)(8676002)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NpRUxTcHNij4y2XlDnfRt+n7msa+X1EEPWXF5iCsnPyMuEJdPBJle4dMkM8A5b3MrRgu1Fuck0OuX0jV0DZZVSYmFIyFGLPkzHRz//SNYqTB+ecZ26sI2QI3ZEg8jwenn2/nArhbeC7nrxFxJFc2SeDmIClfSMHvJN/sHzfcqeEXVE4cF8wXe3dRgJ6oWIRNL/kFAr7t7IITHE3sXsu3oTmanS6GmQH2kogGt6Y/RF9TGcJ9dUsnEm6LYhWG+8FZTbeD23dBViP2o0lneV+/IkWBSX3BB0DFhyM+PHUhHj81dLpFposbdEAJaoLcZfIKMLIaW5zRzEQazSwmsXbxmXPo06a1IpWnclKdfMwf8C1YsPoB2Wcv4T0/RADXSzRQbBiSWGeyjNy678R/JsLd8RAcz/5M/PDskPAnR6lr7C2sjQbaS9QWm67rZlqN0U5hOrxwJOfgirNghmOZRoywKhqmNhcfDazcpO+1tvoxslCIAhFEjw+0ieAa25vthpK5eBkre5hDFyCHIEUzOaQHERVEZmS/n0qXDiq+L71QR/Vj+EQ7urKQSeONwlbV6iNs0M04K61B4N4TeVprfX2kva7l7EaLdna1QG4Y3o9QhLXPPSzeGZLr/aLPqaZPgwH38JcyTsOMv2P9prDpcteVuIq4iwVBay0xv54ImbDaHej60piG+b4EA05E2kvw1b8IOq+epPwwqxJ76s1VW7kYKZvp12WIeiEEk1KxfWWBj5ji/vg60srKMVXa+APnGR6/mBCCV5/ktzcG8SBU+CxtiB6HucL+YWoIipfQ2gKM4s8G9vP9OsUi4A56R8gJHnwIIIi1goKEuBvt03dM+yd/0QbzihHYLEPRp2kRcKQRb6zyjiQHeC7E6j/RXXV7/FP1OwakhRGopuFH5ZHmRRPVy59VoNXOUgIZx0c0H2OjliCbwP2HJ63EUUIxRhfbWLn+PQ3OX0jSqPTo0zo42wfYg7XawPMSJTekuqTiIviKUAgaNzxrg3z3s1VoNvm8dhski0cfslxe1QRGtPJblyjpv2rqdSZVYQ7aFzzTloBYcY8CyxaTsScCxGc38zGZZAgwWUBkkxhmHYDbah8jYH/zFP8m4U7dnWPtoxT+nLbamVFtgOFyuiMFzSQNt4owm4nZx9FoiQGhkzNL2cz2VDbf4891PJsvQCVHTk/ym6ezTFKPp1Ue7OXBeMHslRL3nglVP1+M5NCJTa61j+BtEHCHGH7Wa29nDQXnfKvEAOE6mSoeLZTEA9oOyz8kDwsqDA0tpenhJ5PecAu/t7eLR+lSUv3F032gRoDiKeTkspMfbDrdN7OBdPdjGh3Pe+nGRKHJ1mzibQ/yCTb3btZYAyAQqbiNfwbDWLzJn4ALGKfbjHlI6SOiSgPcadDWWtynWg7w53p5qwO0GxEsxYaGccqc7PYzu97ZHDvl31BLM+G5aJ9Aa40p5Pl6JHqBebd83H6f9StJu6iF/arh3ZM8VDq8n1ztoaw8DvyBcVH3+HfsZVblBPifekE4BnP/Q16ELh70w6vAZskT2GMYGPTMHhswR1Z2co1HhJR2CztfpKBLFr2L2gzYSYC30fx/30UJhbj4 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f2f2bbf-9f23-4abb-06ef-08db608214f4 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4373.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2023 20:20:01.9185 (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: Favrc+TY5Z9EAPJaz4S4D0Qqt/QjipjF6upL4oPR75gzIcBg79POQgW3IVOQB03hAkfXWlkR4eLHDc/pMfs0yA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8254 X-Spam-Status: No, score=-1.3 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_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org 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(-) 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 Mon May 29 20:19:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Poirier X-Patchwork-Id: 13258946 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1500101DC for ; Mon, 29 May 2023 20:20:09 +0000 (UTC) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2047.outbound.protection.outlook.com [40.107.223.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93087CF; Mon, 29 May 2023 13:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CRhgk1uZ3skJ8sASOw1YDrBkg71HX6c0aePBEtHmlQgCg2sNRdSqQhIkBhW3tOyK2blyJ4RP6NVxo0+BQYwiQYbG331nGNUbUaBDzdXX3FZTrykjAo6NkYSGncyqFLxbWGQmJjoUSXiZaSqqc8K5Qoha2eE3/6bL5cH7SBFV4YmJ53Mdf+W7CUeJEPJU77AiD5YximABfqnB1oBde9O0kvDSvFOHYdBayXdY8bYmKZszi6aiB3sqnI1ClxSIdaYckgvdNZ36pfzvF5kt/rQB639sZkR2OrHpO0mmQZFLdK0HEiMceekkTY6EJoAWy8l8JXI2KrXKaVUtwIYi+qmlTA== 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=vq2fa6OTzuQ+2tamIGkYzqhpzVAaKTxY4b5Pb6+tnEQ=; b=nOAkA5g03RX5O5Bq6mRZhLFZ8Qpm8zesfvfuCejQe0cVeBCnfk0/b0fNRb8NKGYauSh8xfal9yWTmYml8bLaidi87F/+81xkA8zD8tpX7gg3mK2rs0DiFHnSVQgx6i+kFxgqpjR8K6YmfpNF+Mer33fxSa2NOERB3/FD0+CGuYU6QGz0lHDZ5EIdtkWZQJ3ZS8l7hGDFE/PNXdp0lWbUVm7qrNk9twUpudW62hs8smk/m81Vh5U21vZ7jS3SL95EWVanHvP7ElyzB1Y4pfNirRq7fKvxnW/kWRdWL4AxHT/RwzLD9cWfPrVIo/Z4XOtTRR4a7dye8ALXYLeP8DdhHg== 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=vq2fa6OTzuQ+2tamIGkYzqhpzVAaKTxY4b5Pb6+tnEQ=; b=i9NoyxD5jWV6kYCaOpetctBQ7Q6d2coC9sC7SbVu7BQJ6OJ8e5v51M7s/kIbu2NobtD17rv7OzrC8oG1+Qc/y9ahRAunvUmAziz2VBB6UqJEB13N5+63yqpdeoHMtkCgXkgX+SY7kr+wYJCBaA/O0L6MDO4y7Cqn/bynH/aRcHgnkq2t+OnihgiFbcdg+TNTrI/PhdHUywjuxj7NwWYRrcm68z7GEtwr1pYxLqboaeOOiij5VGzWV2M+/06LEzJtptmEDtEeRktFowo76n9DdbA2Q7GFoIFrzzlK9Qij1vOmKkjgDGS9PvMMgLthxhIdOgue001a+Jw+GqJcoFEDgA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) by IA0PR12MB8254.namprd12.prod.outlook.com (2603:10b6:208:408::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.22; Mon, 29 May 2023 20:20:06 +0000 Received: from MN2PR12MB4373.namprd12.prod.outlook.com ([fe80::96fe:2d5b:98bf:e1da]) by MN2PR12MB4373.namprd12.prod.outlook.com ([fe80::96fe:2d5b:98bf:e1da%5]) with mapi id 15.20.6433.022; Mon, 29 May 2023 20:20:06 +0000 From: Benjamin Poirier To: netdev@vger.kernel.org Cc: David Ahern , Shuah Khan , linux-kselftest@vger.kernel.org, Ido Schimmel Subject: [PATCH net-next 2/4] nexthop: Factor out neighbor validity check Date: Mon, 29 May 2023 16:19:12 -0400 Message-Id: <20230529201914.69828-3-bpoirier@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230529201914.69828-1-bpoirier@nvidia.com> References: <20230529201914.69828-1-bpoirier@nvidia.com> X-ClientProxiedBy: YQBPR0101CA0295.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:6d::20) To MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR12MB4373:EE_|IA0PR12MB8254:EE_ X-MS-Office365-Filtering-Correlation-Id: cf55c36e-8834-4a3d-d49d-08db608217ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jsaAoHj1SMVfmLSY4m8yZUK7gsoLKkmlB0t01klBj/9oCwFzdRGQd+hAA3CRD9DZtpzbZLoGHMk17/bn/nOvvV6xs3seS0Ok9fcrVpnKuLQ9jcrMetx7pOJujaWiUDeBDKKfw8uj9wSDY8r2kdlXf+/HCFdARiI8ybvcBaZlgPWeFvWTc2tQAIxbHHUHTBUOddHuJ2PsvCVt+zm6p5+7Hqo9DzQXAhlRcoA0negOhMfTGP/YUOsWRdDMf1hv0GCqH2XuK9kkZ3MRMAEY7l+84Dd6/8n12oVMifyeKegCLSvx5mkFmjKS2Qkc4lPMnqSWYtey5WxSLUkeqwbCOHQ88MMykBN3arQDLCnBgRREq1unkKhCdPkWiYLhIL9/qe8at2ZGuiOl7pT2Ro9MZkEZ3FKd0e9r6XUiucwNcEH9Ew/ONiOQxDGMMRbNAjHSiBPazfM2vjNS9QSJWga8WxTeOzH2HBss5fAQ3K8k83nVIRK6dMIPaCIM8nwa+CUqWeK9o80wuezV71gE4jnzbR3uRalUS0PAkfKPbV0cFf9lOxCyIZcKRD/+nswRgEWUY+Va 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)(366004)(346002)(396003)(376002)(136003)(39860400002)(451199021)(38100700002)(478600001)(2616005)(66556008)(83380400001)(66476007)(66946007)(54906003)(86362001)(4326008)(6916009)(2906002)(6666004)(6512007)(6506007)(186003)(6486002)(26005)(1076003)(316002)(41300700001)(36756003)(5660300002)(107886003)(8676002)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rRcj/z4/kRC0Z4WZaM1uUXEU/5DcFvYtzQga8342p9QKFyrB9HgV73pL1utqWMU8HpAzRYpOugqn2NjO+weAvD6SlSDYdzeDI2dAqWayBtG4rgO8UAXT2sqPJzeWj+LH6mSYo95jY1k3zsT/8oqRsWUMZtQ5M1OTDCxCnvq4CEsEHpmE64u5uQaGlDWrQ7wp96PasIN/a1TH3ls/yipgl/Sw5T1pcViLNumq9HhawsE0m5qHv8OfVPQTvUvrBAiJpWyV7IcsQDlUYA7vHzxwqL8LsDIYgQ9CGhMERnVDmVllOvh5AsPyEBcHwLePy3Hse1m4zf8RDDbGx9WaiopcT+XWrbSCBjpYdSwwnGary5yqOoe3Pv+OkazQLN8Xqj0k0hhoh9vw1aNKCJH0FhWL8wGMgQ1/pfHPK9ZaN+SHNOobE7lpa1i1rbN3i2Fc1+OC7eCG1c5LAnoClNouLo0vErbmtDVjUaIKssRTQRIZHpuXNM9rzK0N6k+g7sSB8me2rZaLZeFbuZsR0iABiUNm9f35UQG68o4GBia7nhauC1hBrPY7I8exEW9y4nzuP1gd3NQr9qeiKmkpyVsu6HwcWpaJ/iClLqvPJKPppojjHuw09S1yzpgxCihGST66CYjTxb5ApD2TtcbZsCM6H0rvmjKbNoUt02VOwE/sW3scrGSS53zAvkvsyYmFnXFj7QlM5t94wbb0DgDlL+HZ0V8jptPI1v2SMY3glhjNMYBM4xg9OYzNrwyfAjVOTvxsGzfAQ48kzQ2Jwi+wogOq6qm9+bR3ndfl5ao64siMhExSosDKQvgc+ZVms/Hkcl3OgxixqdN2/9m6aZgS0+sxzsRJderhhuvzDOTx0bFry6ihjm5ev9g/emfOnMc87IvOkTIi1nDCsgFNTF6HYx0CJCJPq7eJcLSCv5yVhj2joOxj67bbpDzma9KaWao3IQ6VZ5vnAIg945NpEzczOkiP4Z0JNQCLzxL28U+EaK93gtXxRN1QQt9GBNbMbpNYAJnlvSI8DecRvcDXguBg/l0Q452w4zW7Qu+hBJRuP017htjUOIglwx/0zRsGzxs2dPDObH1/D30fX3wSk5bqChAI3OJK8C7lGEP5RfqPUiwBaW+dfyG55rW/Su16nDa1aOUtfWCPjPRf/dWsfLmu1AWhBbKBTairUDbl5RitXokywJgWKVBvJwoBqu9+nNtzcbdfXHanZvofKAi8vxdpD0lVFUO91uzjZtSpWkjwyxOc/nRlP5XHiXR39GwWmIZ5lx47U/azxx9Z0f0Wqdzobs8BPDmK40aiqx7vMnAMXopO+4H6SU+uQCDREshHJdgBa1+My/mhOeGpstrOwqHg5X4a8+ijx3TPjWIdqEKJEurz2u8b2m+Ms5bQdXRhfzGtCtuI+AucYCaRTYGZrmQDPAkHYFFlPLARV7reEKZEIWcQm57KeVtHmTn+hitsz/Q2z9Sbb6rRM4eaJHctxPK2En90ooWqQG6GGQp3jCjJ7sJcdc+RIceIjIJ31T4+6w6+biPk4RUrmWu1k7NMnK7X9pEyNuiJzK0JyY541iMj5BiZZ9VD1DmxZDMbrIKFYCJ47TTjzXnI X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: cf55c36e-8834-4a3d-d49d-08db608217ee X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4373.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2023 20:20:06.7893 (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: r8wOpevwnlndfx189bJLhvHCte9Mn7i8jq1Vu0uX6x2CrqTDVkjDkojrZ2EYjFxW5Ou5wLeWyHVyOwNBXCWUrg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8254 X-Spam-Status: No, score=-1.3 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_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@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; From patchwork Mon May 29 20:19:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Poirier X-Patchwork-Id: 13258947 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F7171095E for ; Mon, 29 May 2023 20:20:15 +0000 (UTC) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2087.outbound.protection.outlook.com [40.107.223.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C073ECF; Mon, 29 May 2023 13:20:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JIuNgd1RZ+K5dj3WDMfl8O9Tx/CBR4W7qqPTZP0k1LYrIr0GiUpTSCLNl85uCnsKZW8gX5N+eKhg6Weu8zPH4ewXSoxcQs1kDXq8swAo6tKe9Y3AQyVmIDS9WDQzTkxc218QwFa5r6bEFNg7z74WcTpS6n2j/rjjkrRDevc9dMWDskquudgZcR48OmofWzmloK4ZyrwLOMR2CUniUjiOog4fShldru7zDKV9AIJ8iFGcMqmOnAP/U+dmNqSErZs5DsqDE+inWUuCBJXnbXxowPgeqtFA6f6bz3+GfSjRf/ZmvWgAeB6z2CjlrWmujs6FaRZWjc2Lkdbd+ihv3zRq0A== 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=CYPOc4jHoOnhTksCmck1pUnMPVCpbzWb7C5IJiae5kc=; b=PpvHPlXnWfd7E9R+gs5MW22pnblbilRR3BrOzsldVfip3FmO91IPujDiIn5/OqiLJliJNCbAEXlJ04s/NX2D93R+qXNTr4gC1MjAR7LjMaTiDgECQwjqZD+OveFMn4KONbOlxeHRjMG51rU5OC3ZuWQUXjvnkga9MGxTZ/Ho9iVejdaKIZS7vYoJk1hijqJkJdrCJH0rNARYWvoqW1ZoWiWKuLvoRJkUY37rZ78wDOvXcpD0z6zkyaGJ/av5sKjIyf1tp5yGfeaWVgFMdgwvaC4wRBW3EMcjsOoc0mDztZYxdIp59RvgxdOgrx/sY8ogs0/jLSqZ/FQQA184fmipMA== 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=CYPOc4jHoOnhTksCmck1pUnMPVCpbzWb7C5IJiae5kc=; b=S/ud9TMD2Fz0ycUP3OTIigJAoaiaOjKGRvv8htA7KaN8dTCD72EONW15zftz/GMRu+qh3Yc0xFtMmPgqBsD3e7BqRvI/r25EXz0cet5wBfMHLobIZxH4TzDQOYmm7wUpkSFUPM141hK+dRt6NVTznI2lYbLrwVq30vgFJ+lQyUgGDf9HpEBVLZz5kfKIhtX9SCVd8ZQooXG0R6HEO4m3H/syf+AmWHvOznUh+7n74fipBE0m9j922ux1hXxkllSjB1YkSpEREKBPukdlZYxMl1d84SGwlaDqX3Q4DM3B3ndRRDfh41Z5fQXn0wNJSoYkHFtNtF65fXIVSq299TFkHQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) by IA0PR12MB8254.namprd12.prod.outlook.com (2603:10b6:208:408::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.22; Mon, 29 May 2023 20:20:12 +0000 Received: from MN2PR12MB4373.namprd12.prod.outlook.com ([fe80::96fe:2d5b:98bf:e1da]) by MN2PR12MB4373.namprd12.prod.outlook.com ([fe80::96fe:2d5b:98bf:e1da%5]) with mapi id 15.20.6433.022; Mon, 29 May 2023 20:20:12 +0000 From: Benjamin Poirier To: netdev@vger.kernel.org Cc: David Ahern , Shuah Khan , linux-kselftest@vger.kernel.org, Ido Schimmel Subject: [PATCH net-next 3/4] nexthop: Do not return invalid nexthop object during multipath selection Date: Mon, 29 May 2023 16:19:13 -0400 Message-Id: <20230529201914.69828-4-bpoirier@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230529201914.69828-1-bpoirier@nvidia.com> References: <20230529201914.69828-1-bpoirier@nvidia.com> X-ClientProxiedBy: YQBPR0101CA0255.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:68::16) To MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR12MB4373:EE_|IA0PR12MB8254:EE_ X-MS-Office365-Filtering-Correlation-Id: 47993212-8973-4c97-01ac-08db60821b0b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q4XqoK8/ExjvdbqJ0qiG6ci0/WfZa+hBfSerOsrC4DViWiAA3vLGNlaDv/oOMmWaaX/xqRiJY9oYkSvY/Awg3gD4ZXfkMKTKL5XRmbESIaFEsX1XlecPk1AkCSo6zXLXFMmteJu+BszJ/pkF0xDbeKpafU7sDTpD4lZfRiWoKwZE8Md+fdmot5WxiA0BBJfxAYmbcRDaxKHHko1jofagnO0J/i1QmG2FPq6BgoUu9EUsISFQAQQepkwHql63phUcP69+ezIAm5co5jmDVDqmXxo9azVmdx5VT/3V1KVHspkHyJdlx3Ppg21+QsPer6wAcib1/Lts4JDv112p4hXTjbfFxKdV1oInOhLkK5eYMZ8kPd1Pe6xTZoO3HnFW5DPp8wN8xyuF55tfdbigniVApXefGPN7adoKrndu4g9LuQUNS03uQhNB24/FQNgTeJkZozc6HZxMXV7H7R3Re+mJMwp/82dC/kWsaHMir5AEtmoOr6wMQqcH1vQTl85s0kOvU0JzhcKA4l/tOCTd6BpiESKabh46qLf8S2/sloDqpRRQGn/jGfKbZmxStH6UEF9P 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)(366004)(346002)(396003)(376002)(136003)(39860400002)(451199021)(38100700002)(478600001)(2616005)(66556008)(83380400001)(66476007)(66946007)(54906003)(86362001)(4326008)(6916009)(2906002)(6512007)(6506007)(186003)(6486002)(26005)(1076003)(316002)(41300700001)(36756003)(5660300002)(107886003)(8676002)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EIjDcq8LUAaD+7CJq6vcAshNPj34OnPBiI0m3EImxtfrOyLKBBPv1ChqqX0Puthu9P8WFjZTAPGmEmA+tuF+/lweSadsBq+PxoP3XD5TqNbb7Y7fDehcpOIFMGjto6JJOaEeU4rzrg7ZVFsXzjbpS4h+1WccP83JqqbWIXxNKZo3c3/4mPY4wxMXpUleNegGxEjHX7RJLPlbs0wH7/0/uvMxJ57r3MlTL6CzK+zl3B9soKhs7NMSOYLQde9BG1ldmhayPa/BTBJpNSDJJRA6fGoau0xKw9gKB5lrnB8EO0Xx2TkwkzJbXwW21MwEXJrjXwHsRzm1cIM/FB1h4aSMhEqo/y3H1YiPhiVP9fdCmrMjTJ+aR1mEbQXBTCoLSwB/D5eZ3JXJmpcVqxWg1cQfHqlNS2vPiGLt5q3QJY0JCuYiS9UpIuSPCCbpVyDIx0UTKpu++H39aNTf69qNxRgjQjJfzFiTNcEgIW4QHfGJl77ZtLWU7yVh+HPjuRTKWU5IwYCB7M29UyF3uTG7Uzh3CGg2W5cKou1FXYcSd10CCDr1kI+O44cgUIbUecAGCX1g5OOW3uHmD5ydfYA7sNMohqOn4l/DbL3X3p5i7toMWk6RzYBzqzxM8uvInFZvCydDREwb4l8ufQBvs7zDnDRfoeg9vv/pOX6VqCIa95tHmN7ZECJ1X1+7k8owrBaa0nC86/Ym1iP0INU56qJSdogJbMf4ipMonYmnOZeZfq0BtbLHZsB6m+f3JlRLcjogB7VIY0jHPWcZp8zC/y2ChcIJc4aA+Q8DT9xkDsCOjhj7sNP7gfAiAdJi0Pg6oVfiRfVzkH5yojBXnhYCH2kwJyLsgwqHjRs/xsydns5jXLndoU9DDh65VJbfIhSUDL6AWqJ5AoMh2dODVkx5/UpBRQA0TgWNa8wBDwBOi2IH+KRafv4A1Ov3oWWFa7RXqhP/F+JB7nyXc8uuuBAyRAEYgJB2rWa2XExsHBA39AxisW8Vc0Cy/QFRkxTwEheW0xLWBkI3R8mxmj+1BLONC03cN2CxJknDTELqVbTbKahAlbrHniwlInGTiY+XdZr6xp06/J52rGGtNCNCC893gCuJ8GxWYRLkCbOOASZH4UDUawXtSWkXnnq3gWVtIRqtwqngTRL4p7x+R1zVtAgRHGYCXVnVJqpkMxrU1hv8TxDWMx3P84ka7Mek6ayJh+Q8mjYsSfJiEmmKVadZeM8rBYNuIPSaxe+ECp1Ad9mCASsxhiGwxioc1B4pDzazW0kRtdZV4s7EcHIMK0l2Y59/6netudk7M06KvXH4D9jukeI0ECId0Z5AHQmasCdYOWOAMXEKa2vh7GmF4B7f2m/Emss2LIZ+BDDD2EJ+Phl1sO+YEUxeg9fK//qlCwfBL0DCChTH/pIUiMyPaA9M4dbIUxOYZE/KWsM5UHys/zM4GuqedqkGfNhJu99nsLRzQcRbUCqXjcBd4lqlptWSxssc50edIyFZq4gqhHSDn2IsQHVxSOKlLDiU6BKl+RpeAtLXB18X86bcqaG3VRpJPrIb2bh5i0EK7RKefDzxen1geyNr05UBjLq6TTHww2QmNLnMrVdLGUvs X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 47993212-8973-4c97-01ac-08db60821b0b X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4373.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2023 20:20:11.9932 (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: MNipSiCg0pIbI/KGA+Z/Tge4tqgBRw+fVsDHRmNdxAOslVDGa9OeUP82M0x8e4AhZ8H/oR6k1YYhv0bybR7KDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8254 X-Spam-Status: No, score=-1.3 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_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org 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 --- net/ipv4/nexthop.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index c12acbf39659..ca501ced04fb 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -1186,6 +1186,7 @@ static struct nexthop *nexthop_select_path_fdb(struct nh_group *nhg, int hash) static struct nexthop *nexthop_select_path_hthr(struct nh_group *nhg, int hash) { struct nexthop *rc = NULL; + bool first = false; int i; if (nhg->fdb_nh) @@ -1194,20 +1195,24 @@ 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) + if (!first) { rc = nhge->nh; + first = true; + } + + 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 Mon May 29 20:19:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Poirier X-Patchwork-Id: 13258948 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46D88D309 for ; Mon, 29 May 2023 20:20:22 +0000 (UTC) Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on20609.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eaa::609]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF193DB; Mon, 29 May 2023 13:20:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MHB7f4jd/b2qzicK9wgW04dNXCOTP1LEihSdiGjrkE3sysrlUg9KbbV9HnVHS6VM7muk0NMwdfe98EFzePABq5G1iN3UStb7JOeHr9dr7hzMxZZJtUJCJo6Ulo46ae7vWJlC7pTBRxBCA1JnWm7XsB142KDzNZynTFvSBqXWbMPehsAHEmFFDwsjD/u63mEdWXB5AUHwV+DWT5U1MYozgKU2ox4IU/i/ylj+M8GGE/hhKfASg25Pd9AYwNUgIA0yvkbcRWl8IpuExgpp9/MStybDpPXmFo3K0Eb8llpjOgT1zXrznRehjga+2woJd4c3PBFVOLTM+juMHA242kJEgA== 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=846ABl4UnKETUsxN51otHM/2IY5JB2z67k5XvXod2vQ=; b=JM3CM4ez4E/kvPXGN7RUKaYHxuGMrXRL/vP2PnoA85kN9fFlMT9ywM+OAjZMRsM/G5YsvIEOWSyoRsTtzVZ0qr8pOBNMaXz8ZU7xQQc7O8h6XJ0UVnFE8IrhPYF6YAuPUivUO/7m4O9bhoDgYIrLCTUVwWkMACxySXZ/hUoP1cAHNOGbo+ZHQuJ+V2XV8Z18peIHHfg/D/jurO9P027sP7hAHoqfNL5uxsdTGahOEYngyHRYh1TlsSrFlCqL/s4uN3buK1OAHx/jYDh1/7/iI6El+7Dv3jFQkoxokTLUFkMV3w2pvWIeCnoda48mI3iY03dL23A9Y1A38EOyVrWhog== 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=846ABl4UnKETUsxN51otHM/2IY5JB2z67k5XvXod2vQ=; b=LSyporxoNNoMRj9mhbfdIDP0SA5gG4A0XysyaaWdwN0q+J7U2I8xeIllay/8lc6NoxE2tzkk7YgErj32ia9mMifzpLp0tge0D50AF2qll8Y08XZq1weOwpgv86gmXNzxE9Uds+oNQp9Z4XAKigZltwUY8zo6Pd4mlKt7wyD3m0NTTbaa+cwXJfCpn0cRhomdgO3hjrB4AChxsZP1pJXAQzTF6kVJ8laQTFK7K3g8BWn6U2KDJWLz7BxLNcDeGZ/FG17/TemulGDOxya+QvwkrQRYp1ClzlBdJYFBfS9D2M4tm1u4L58PrEk0DBcMPMgXzCLf+7qB3NSgne7eC2O6Hw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) by IA0PR12MB8254.namprd12.prod.outlook.com (2603:10b6:208:408::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.22; Mon, 29 May 2023 20:20:17 +0000 Received: from MN2PR12MB4373.namprd12.prod.outlook.com ([fe80::96fe:2d5b:98bf:e1da]) by MN2PR12MB4373.namprd12.prod.outlook.com ([fe80::96fe:2d5b:98bf:e1da%5]) with mapi id 15.20.6433.022; Mon, 29 May 2023 20:20:17 +0000 From: Benjamin Poirier To: netdev@vger.kernel.org Cc: David Ahern , Shuah Khan , linux-kselftest@vger.kernel.org, Ido Schimmel Subject: [PATCH net-next 4/4] selftests: net: Add test cases for nexthop groups with invalid neighbors Date: Mon, 29 May 2023 16:19:14 -0400 Message-Id: <20230529201914.69828-5-bpoirier@nvidia.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230529201914.69828-1-bpoirier@nvidia.com> References: <20230529201914.69828-1-bpoirier@nvidia.com> X-ClientProxiedBy: YQBPR0101CA0149.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:e::22) To MN2PR12MB4373.namprd12.prod.outlook.com (2603:10b6:208:261::8) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR12MB4373:EE_|IA0PR12MB8254:EE_ X-MS-Office365-Filtering-Correlation-Id: e11dfc89-d1f1-4464-de4e-08db60821e37 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZLa2r2Ruql+FbtOKY873uu/fcGC/m8ux77BdWeNiB7h154bmTe+GJycw8zuUw6chKgVw5ize2kHU45925fGkU9U1h9OKmvmMUlldt0JCTwa953+Sudbayx8g9vh/lRHozae6J5xp7bJ6QuXsNP/93NQ+Hf5cOZtmzdcKYOhqawZL7+lOSGH7gksqcS5O+fP0oUo+l3mfm0RM4uVOMb3Jetye4+qjr99owybruAHWIYQTdosT0ym4jbA0O1rKj0vtIV8W1E5m/QmQFGujnxyIznwVfrN26hzd1hHt2N+yMCV8k43njTqdhZ88MLL0etA4jcgX/apAw3NLStTQ5WpWT5W4uuTXtZCb90w4w/Z4ta+b2ucn8oVoLCj72ZoWsY/5s3vKcy4n/NenEEdosdNmVtUkMAkH8umpe7oRUvdBqtnf9klriTYanvljmDSHIb0iMqMQcKGtm1zmGtLlbp8MgPIsMoIY1xUxplWMWbBsWzFusJusUni4TGSoMFP4lifeUMPDxxnmnbui14c2k/8xNPe7X49x0zFGzWPLtHRnh5WTbWN0GUcJSbCoWgiuYSrn 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)(366004)(346002)(396003)(376002)(136003)(39860400002)(451199021)(38100700002)(478600001)(2616005)(66556008)(83380400001)(66476007)(66946007)(54906003)(86362001)(4326008)(6916009)(2906002)(6666004)(6512007)(6506007)(186003)(6486002)(26005)(1076003)(316002)(41300700001)(36756003)(5660300002)(107886003)(8676002)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bTGcPgpeWtcyxQk/yG5HcuudZd8hfTOUQejJvWAFJIMFIrNffYyhJdA5P1q09yzQL5T53azgcuffI+EPfEOldqnoi3kqPqWURi3KUELvxfmqqMS20dcTTNbIYnUuJqizgSx63RznkHnSve4O5n7d0A9nvAeIGxxrSlh/g39mbN+OVm/hp2dUzAjv5yedLLUh15zCrbhTFjGaOftRNHOo1atY1Qt8QshLvT71oPRQjJW2W1JElwpi/xqSmUUwIekOTz/FwUq+03rvXU7uAaPUXvNBuajExlhAGPIwUTY/UXAdpFFlLyNAJ7tHHFdNGrw7ezjP5Helmps4iBft4nYxOzzaEFcnCOUZuZzhLwGjB9+AS8wnZDPryZl1ej3miaT5ibZTcHb7dOKq4jLPQ8v5tKop3LHwI7sl2BQ1348g/lJNiwPvE/K7wUc4Evf7catg6C+mWuyxKthf1jApBukhqfs1fXK3Qu8EoVoGiaS9Sxsy2H+OSXEwfJPcTH+Lpym4gonHaywSCpAFB/JEWPafVwBdDKBt+a5icxoCzaxvd1XPXMdj2u+w37ndgE+9Mn/pyqyGByahqE8j07GE1wGF3wwtisVF1TSjWbPc4xNxTIRop0LrreH/Io8pGgj/INcNcfDcHmaw9G3sF4ZfqfahOkKMVSF9d16fgfpUArj7VECTO5oCekTTdURoHJU26qPVsLzb17EOI8sqSeTSWQBEmVwpIrXQGmDCbGQ43GHkGdt8B4dm9+Vve6wGxDb6Knf0TSwJ/ATFyQracFIgiwLwoWVCvDXdk5ydU/hQF/yY6vuY5TT7Z2PLnu/4FR2D8Fav0p+B8buixbtie29X4XoG2tUP5vGE90qfW4wyUcO/xeZLgIgNk5Cd7SoSGO5v/O650sp3ED3z9oQtNSdhbiOkX8mJ3jVXWK+OwHBJX2+mUsrd5y0LkZAmnvDK9RQGUxyjN0WxvFJVuLMpxQFbYkCxc+GotaQ6k7gnRZWCmfZCICLbqfarTP3Qf1nq2GLbDgcLBo18xPqMvWPDKwwhZfPNzWMxb/XistHzg2FX47THAyPKo70XEDQcFEAKfZY7J7Ap3B75+/VvXaqE8sWFGqXGESVWV+YuM7ZsuKBpoiijrbGUySpp8XK6UhaTKCGq1IUlLZOTl3NkhA5BVFWXdO5130GXZMiAZ7JRPIsEFH6knKMS3AXfKnofjkeynk7sYxtD5dNoliptSFJRo+V5vBpFAstuXmbfh/bG2tOdGFRyEvEk0/wFj79tlxeoZ0nJPSo7nemNh7g897OyZr2UyucCpllE+5DeBbdizIdxzSLlNbHd3h/qJt8bGGpvVoUp33N2uo4kRMzF0DGr+dnpwCEw0IUG9xwdcRgXyFhFw/X5SN8mwvsKOSu7X2pKj7IyXXqFQCb3HoR0oMyea9ibA7bPEKCX3viPb7fK14SL4IbDHpiMO7GUktrs8JHhiqGy35CsEU8FTZUSfRWVD1XFDbNCDFGdKso84XXClEDP+nhMdt3CGVc8R1wJ0yZUmDt4he724Bw0K9YQrVYDO373mRLpgE1MqUBJ6nERHLkqX1/nYgRoCnokHA+ThGUmhJn0fCnp X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e11dfc89-d1f1-4464-de4e-08db60821e37 X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB4373.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 May 2023 20:20:17.3315 (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: OXEeqT7slUq/Mi2p9YZstQ0y9OCWq5P7Xwlbq+rR+NCG6PREhk/ratP/C6zuOndkU13LJujR51AJN68OqfmrOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8254 X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org 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(+) 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 #