From patchwork Fri Jun 7 15:13:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13690370 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2089.outbound.protection.outlook.com [40.107.223.89]) (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 067B515B134 for ; Fri, 7 Jun 2024 15:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717773298; cv=fail; b=nZX4JIc/v8qai7sVDAaoU571sMiPunIAVzxYIioTLl/jrW2qawAyVl5BAWV5nNimdgjShVM5uBbitjohVJAwtnfQ1Gq9Gn/b6CxpzpB6xjgaDrmsFH2cBBHxooQkbRJhR0xey7FhSXkkc1OBiOYg5Ge4+nx1eL2tbioGU8aoHV0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717773298; c=relaxed/simple; bh=sJKXc6Ds6xXtX1oM31uU5JNTerUvLiEqeApYzErPBBE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rTdWx5faa1VLKNnqNqr4sbgId61WUJT/mDVBv9r+GPpADCV84Ytozi+W/slUvHl1Zm/0YVieZpPpu5FJobRoF0JEOVc4Np8DM/idLVGMdI3HaMXHxJBcFoUmdemGQjIdCMFdRCz/P1lRaUV6WkVVhZwSRLw8RiHkHLJh/K7zuPU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Vaeis4Nn; arc=fail smtp.client-ip=40.107.223.89 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Vaeis4Nn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IANUAa/kRdZcaE5UZS/Bbzf/9EG61xoVF/lM0ejt0xuQodqj1+Z1fSs5L/WM7q/wp3RP7EDwlBnQ4Cl7SJLVdtsceqzA3egQdFJAfzIu1TJASgC8Xf9OROIG9VMPyXHlYWXzU0mnaCf0QEPW8uLKipPEjTvWpAumegjw/r8aNYe/VVfQgb8/XvwLT90kO0qDBqxPsqvMHo6gxMjUIbfzUMjLDo31DhX9rHlHarm4t+BNK6kY4h8yhTtFU4krLBSRGwz2N3cyMCbtgsF/A/revd2JAHGSy83L3Lwk1hvwCAcc5Pi2BkGb41rLuMmogxcKIUEUTVxCipCmXzEYFqjxWQ== 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=L95kBzA3w62b6G9R8rhcWKxSO/6rgs+hVKjG+ZRzyN0=; b=Emwc2cwZUnNZVMP5z7Yuj9GaugvRjB9iYpjkgx+jeMgNkt4/uIML54crnOzelfw4HzzXKhbFC+Vzwx+4JJNaoSRYaiTgKQV39FIbV8GxeQaroPnoWJi9sE6vhUAuEseCPdbNpqcj7zZ6N57t3YwaLlbylYH8eURlJUciqpfyVE+Run7mbkS4G3r3UQqYNgi9ehST+9HpvswF+XZ2GDdzOhkqUY5duZx64FkCiSWkAaH3X/GBHMX9nQXxendm7XKKOWo/fEYcmEFIuhfvL8/w3GrzHiG6RfVk2jN5jHwKhKbslNZb7ct/1IcFsImJjGrNEO9fUmkplZpWEGmG+WbYTg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=L95kBzA3w62b6G9R8rhcWKxSO/6rgs+hVKjG+ZRzyN0=; b=Vaeis4NnhnwK8zT2l3hAzeoEEVedKXO7YIFWRc7BJO7yrZDoAc+JCZWmaoBxLKNBmZlL6A6dn+uvMWe1rulBBHGsKgat3sbL+xXzivLK1drynNjLIyRGvwmqiqaEba9zjG9XbVuqnbOO1aVcnE2yYfHjE6W99nLCaQKBt/zhT6qvW6HUg9HIPScCh0P5EuO9DnBlMxzlPTVtwOlw2Cptd47zOMNwebxTmznOIkjwNOYqWQx1SvKrbz1l9rVgdohOyMd9Le6Fwv+aZxcOmy38HgXmY+5p49l4H0TTYSqL412NVBH5/O8Qex1dwizs39AfcA8vXbiHVB2kwK5rX83b1Q== Received: from BL1PR13CA0169.namprd13.prod.outlook.com (2603:10b6:208:2bd::24) by DM4PR12MB6037.namprd12.prod.outlook.com (2603:10b6:8:b0::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.31; Fri, 7 Jun 2024 15:14:50 +0000 Received: from BL6PEPF0001AB76.namprd02.prod.outlook.com (2603:10b6:208:2bd:cafe::db) by BL1PR13CA0169.outlook.office365.com (2603:10b6:208:2bd::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.12 via Frontend Transport; Fri, 7 Jun 2024 15:14:50 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL6PEPF0001AB76.mail.protection.outlook.com (10.167.242.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.15 via Frontend Transport; Fri, 7 Jun 2024 15:14:49 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 7 Jun 2024 08:14:34 -0700 Received: from yaviefel.mtl.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 7 Jun 2024 08:14:30 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Nikolay Aleksandrov , Subject: [PATCH net-next v2 1/5] net: ipv4,ipv6: Pass multipath hash computation through a helper Date: Fri, 7 Jun 2024 17:13:53 +0200 Message-ID: <20240607151357.421181-2-petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240607151357.421181-1-petrm@nvidia.com> References: <20240607151357.421181-1-petrm@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB76:EE_|DM4PR12MB6037:EE_ X-MS-Office365-Filtering-Correlation-Id: 1dc04971-093b-4fee-ea14-08dc87049338 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|82310400017|36860700004; X-Microsoft-Antispam-Message-Info: wSH8CLx1Bvb70B+iQpieJMPpbrY6CawYaJBzI0+fxaL44A9uvrdqbeUHlSrdok2F/j+c5fPVSQMHy9yBevLVq+O0GrGmaOkozkiDp3TMMLlJ9QuXo++OOfF9PFzWFybGk8bYtVdCG0TTE1y5iIjdWdmBHpzgPyLfO4lBBIo/2M8JSB5kBWM6B++xm/arlmZ6bpFK8r2h2LPCofpY1dUK5kj3pRduXo1YeBJYxv2zpmA4Lj5YB8W3sS3okGqsi6A3Yg/WuydgaR1+GowAD5IjyW+MPghKOHnZs6BUhWNuft3N1wdFbzEvhRZX9Q1Kc8L7B6nzm7Er5A2ULy34q2ZXm0TbL7coJ0ZWO0+MOkNyny0pRSDPXXwt6cYhnSMdwAkq06jDTHmGFP7e2H6SG3k6Ot9zEz9V7LQHuuABMw9YcgM8xMP27TBx14BEz7yIb5cAZ1YjGNzaoLr9RF2QBLfT3c81WRek22Mm6UXKZUoMG71N/5MSFRzykrjAkWJNefxreLY0mjArHj0fwlVT+kzC6EIs/0F8GDjKGFS6yD/LNUF0Z9QJThIQyL8Uk5yc+mPhd3GvJSRMWJoW3oYjZJIj8mHevLeAqeBZTBkmS/+b6002qNzvcf1WIqnO20hti3YRK9dQpvfdp0+jvbMgOHD1tnSvKoIwD60+Zxa7VQgQiPuUqtxW3M+facjLoAl4Ncjle4D4BcpunHrhR+ZGVtrmmsC4Ab7aTPIAAVrBThOvc2nNB7+0OgFuxoN8/OyBnRWKkOed/hhzIvrclX/RLsMUd4qeBHCc+hG5WSFptgCRFk+bHtPc+ewLZyuN43sKhYdHR8aa/Q1pLynfItGmjvoHVqHsX2hiBKhJ67TuvePL6+J1CQANyFnzZjFEG6sh5bDBTdBmSDo4ea2CEIzKZp6F6HaY7NkA5QX64hOnXGFbcIuUzuMgmUFX7xUYNa+cSPvegWFr4QO2TcXNcMPuAdNuyj5pPXTY7qeLom4Xe1oA22HCFSZXKeQjrd45HAkFdNOH2WqQfJqcojfAM4Lt3/ncdjjdd84hwdjN4Gk/kpeo8nPcM9R9o7/EWFQ9xcw7vaRgONYJT5mi/sK3gPHL9+MW5A/iNCDUOBh8zd7Wrj3vimXFw/SDDghJ6F09VioD69F8CYVteDMk8zvpJjRPwE2AmlzNsLy2UXniiEUyxH5wTBJWtg2vidxhNA9h/LRvnNtDIoZjj447EEl0B6EJeSOVdhXImFxHygf2SnQb7N6zi+M3fqdffR/ZqQUdhy7oDZP13CUuOnria4D9u0QaOkLAqdkMVxrw6QdypjgZZnBUNnEqpQegv0V06OVKCG8/f5E93Of4MzEDzPMu5jB+r3gb+Wvfsk8tWzY7reB9NX3886EPQAxHOxopqlU0BsSuZbSO19OK6SFOsVdnTny9SCuGLQ== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(376005)(1800799015)(82310400017)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2024 15:14:49.7492 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1dc04971-093b-4fee-ea14-08dc87049338 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB76.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6037 X-Patchwork-Delegate: kuba@kernel.org The following patches will add a sysctl to control multipath hash seed. In order to centralize the hash computation, add a helper, fib_multipath_hash_from_keys(), and have all IPv4 and IPv6 route.c invocations of flow_hash_from_keys() go through this helper instead. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- include/net/ip_fib.h | 7 +++++++ net/ipv4/route.c | 12 ++++++------ net/ipv6/route.c | 12 ++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 9b2f69ba5e49..b8b3c07e8f7b 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -521,6 +521,13 @@ void fib_nhc_update_mtu(struct fib_nh_common *nhc, u32 new, u32 orig); int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, const struct sk_buff *skb, struct flow_keys *flkeys); #endif + +static inline u32 fib_multipath_hash_from_keys(const struct net *net, + struct flow_keys *keys) +{ + return flow_hash_from_keys(keys); +} + int fib_check_nh(struct net *net, struct fib_nh *nh, u32 table, u8 scope, struct netlink_ext_ack *extack); void fib_select_multipath(struct fib_result *res, int hash); diff --git a/net/ipv4/route.c b/net/ipv4/route.c index cb0bdf34ed50..54512acbead7 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1923,7 +1923,7 @@ static u32 fib_multipath_custom_hash_outer(const struct net *net, hash_keys.ports.dst = keys.ports.dst; *p_has_inner = !!(keys.control.flags & FLOW_DIS_ENCAPSULATION); - return flow_hash_from_keys(&hash_keys); + return fib_multipath_hash_from_keys(net, &hash_keys); } static u32 fib_multipath_custom_hash_inner(const struct net *net, @@ -1972,7 +1972,7 @@ static u32 fib_multipath_custom_hash_inner(const struct net *net, if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT) hash_keys.ports.dst = keys.ports.dst; - return flow_hash_from_keys(&hash_keys); + return fib_multipath_hash_from_keys(net, &hash_keys); } static u32 fib_multipath_custom_hash_skb(const struct net *net, @@ -2009,7 +2009,7 @@ static u32 fib_multipath_custom_hash_fl4(const struct net *net, if (hash_fields & FIB_MULTIPATH_HASH_FIELD_DST_PORT) hash_keys.ports.dst = fl4->fl4_dport; - return flow_hash_from_keys(&hash_keys); + return fib_multipath_hash_from_keys(net, &hash_keys); } /* if skb is set it will be used and fl4 can be NULL */ @@ -2030,7 +2030,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, hash_keys.addrs.v4addrs.src = fl4->saddr; hash_keys.addrs.v4addrs.dst = fl4->daddr; } - mhash = flow_hash_from_keys(&hash_keys); + mhash = fib_multipath_hash_from_keys(net, &hash_keys); break; case 1: /* skb is currently provided only when forwarding */ @@ -2064,7 +2064,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, hash_keys.ports.dst = fl4->fl4_dport; hash_keys.basic.ip_proto = fl4->flowi4_proto; } - mhash = flow_hash_from_keys(&hash_keys); + mhash = fib_multipath_hash_from_keys(net, &hash_keys); break; case 2: memset(&hash_keys, 0, sizeof(hash_keys)); @@ -2095,7 +2095,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, hash_keys.addrs.v4addrs.src = fl4->saddr; hash_keys.addrs.v4addrs.dst = fl4->daddr; } - mhash = flow_hash_from_keys(&hash_keys); + mhash = fib_multipath_hash_from_keys(net, &hash_keys); break; case 3: if (skb) diff --git a/net/ipv6/route.c b/net/ipv6/route.c index ad5fff5a210c..1916de615398 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -2372,7 +2372,7 @@ static u32 rt6_multipath_custom_hash_outer(const struct net *net, hash_keys.ports.dst = keys.ports.dst; *p_has_inner = !!(keys.control.flags & FLOW_DIS_ENCAPSULATION); - return flow_hash_from_keys(&hash_keys); + return fib_multipath_hash_from_keys(net, &hash_keys); } static u32 rt6_multipath_custom_hash_inner(const struct net *net, @@ -2421,7 +2421,7 @@ static u32 rt6_multipath_custom_hash_inner(const struct net *net, if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT) hash_keys.ports.dst = keys.ports.dst; - return flow_hash_from_keys(&hash_keys); + return fib_multipath_hash_from_keys(net, &hash_keys); } static u32 rt6_multipath_custom_hash_skb(const struct net *net, @@ -2460,7 +2460,7 @@ static u32 rt6_multipath_custom_hash_fl6(const struct net *net, if (hash_fields & FIB_MULTIPATH_HASH_FIELD_DST_PORT) hash_keys.ports.dst = fl6->fl6_dport; - return flow_hash_from_keys(&hash_keys); + return fib_multipath_hash_from_keys(net, &hash_keys); } /* if skb is set it will be used and fl6 can be NULL */ @@ -2482,7 +2482,7 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6, hash_keys.tags.flow_label = (__force u32)flowi6_get_flowlabel(fl6); hash_keys.basic.ip_proto = fl6->flowi6_proto; } - mhash = flow_hash_from_keys(&hash_keys); + mhash = fib_multipath_hash_from_keys(net, &hash_keys); break; case 1: if (skb) { @@ -2514,7 +2514,7 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6, hash_keys.ports.dst = fl6->fl6_dport; hash_keys.basic.ip_proto = fl6->flowi6_proto; } - mhash = flow_hash_from_keys(&hash_keys); + mhash = fib_multipath_hash_from_keys(net, &hash_keys); break; case 2: memset(&hash_keys, 0, sizeof(hash_keys)); @@ -2551,7 +2551,7 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6, hash_keys.tags.flow_label = (__force u32)flowi6_get_flowlabel(fl6); hash_keys.basic.ip_proto = fl6->flowi6_proto; } - mhash = flow_hash_from_keys(&hash_keys); + mhash = fib_multipath_hash_from_keys(net, &hash_keys); break; case 3: if (skb) From patchwork Fri Jun 7 15:13:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13690371 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2058.outbound.protection.outlook.com [40.107.236.58]) (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 7580E19AA62; Fri, 7 Jun 2024 15:15:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717773311; cv=fail; b=T+zD6HQtCE4Gxe8NvcQbI39CgbdxEGuDnpJVwE3cD8ABUljKreJarTS2g1DfjnZL/0LvdHYM8/1ISSjDJ1Gf4Law4ED87Z7AJ10/Dz26fHD4Y3vH4MNug/ZCyrz3giPqLwW/ahdf370ln2TbhamrYe/aGOseHdqiBbDGaVepC7U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717773311; c=relaxed/simple; bh=M+WrdidwYg3eg8sJ7UKN+5nMBlcjisurnsRrJPlKisc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NfoD/ULzMZLJGPwvUpozZjQt5yCYVfpIw6QB2O4SghyburJyN5wu3pu0D2R9Yulibm+RlwWqC3QgldNWaYreBCJxbn+ucpAj2Im4mK1DFuhAbRS47l03u9VaNFkt1t5A3q5q5gvOhBkiBLkyb/0MtIc9TnZudqddnYKR2UkoXyI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Ly+9ds/2; arc=fail smtp.client-ip=40.107.236.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Ly+9ds/2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FEFOPm7d8NuvqXJgzPjQg4gvTmwlQh09209YYOG71lYRS8x7TCLm1TzAQUmQtcH86+Yliczocp7qhgddeJENbgrVPNG9LXJ8hbH/t6m/drmog5DAH3MXY/oh8UmB15hIpezbYCIRQOREt+c3hC/9+XPN9ECvVUMFbXFYgWo9Ya2yqf8pZedgN19z6L3K1f8k9r2ya6qWweENoOUrztnLW359IeBvTeWVQXNz7f0c5llEvgEPr6khdW4szfRevCSBwjRT9zwAaObNKABZUS6xlpzhhK4FmA9nM9Iln/W3nDwaDcV/DnzwELWcVNxZQnRgDnDCj3wT+OHJjr6BWX/lUg== 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=rAAGtLP28LcsngzDgs9+7IqMAFiuVHMWoczvrDR+MZc=; b=F4tvtIcmUInfsGmE6WhKBDFdX3oe028ilbK6VOHlpc2tVgyAC3FRbFDpZ9FS8yARVvm4d9GsqVG3Zqj1tf/QUDiY4puPQiQ4RqP9m27MybRKEtr4u5iwiDDQG407ORbuGM6xNay2S53Z5JpPEH1KeehLkqw7aK0GXSzV6XMtEe7r82y8F3TCcNB734p7kYjwggrN/eNdCilpjkARR3i++MoqoyTMWMMfcZdD3PllFswbR3tA/ZrVy80+aWuXj6UOsQiLpp7oAnDYqvNEFXmdm4T9xKY+qmOVakeFBxQNXrWhTkHN7X5f5mM74s1rSbUQJHAckpnOt2op6KVif/e5tA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=rAAGtLP28LcsngzDgs9+7IqMAFiuVHMWoczvrDR+MZc=; b=Ly+9ds/2AGOBlnQLAkyHBbQdX9CEFbKPvKrwMd4jbV5dBeaz0N1AycGfU1bXjim1eLh/8jE5SkOsxp6bVfsZJe1dxiRYzegGQUyak0a4mZOcGgWL/JdK5gRBpcpmHTJ0W34RmQgRf8YkJOVjNZFxw7RUKWYx2DiuWPdQIQ/AlvEB0cdm46yfb+JPPI4IEjlsDvcqb1Qu9Tl/9EPZrwHcFKIN48s003VlKDPCDfLE+LqzL1MfQ3xqoSEJZ3mdnFaWPTU6vqH3AaAa4EpbWKJakUCHE805MXoTsc1mGVY5wpEhSEESBIYvwmLASmurdH0fovp7m1eRLHZ31rQNABjMtA== Received: from SA0PR11CA0051.namprd11.prod.outlook.com (2603:10b6:806:d0::26) by BL3PR12MB6474.namprd12.prod.outlook.com (2603:10b6:208:3ba::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.34; Fri, 7 Jun 2024 15:14:59 +0000 Received: from SA2PEPF00003F66.namprd04.prod.outlook.com (2603:10b6:806:d0:cafe::27) by SA0PR11CA0051.outlook.office365.com (2603:10b6:806:d0::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.17 via Frontend Transport; Fri, 7 Jun 2024 15:14:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by SA2PEPF00003F66.mail.protection.outlook.com (10.167.248.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.15 via Frontend Transport; Fri, 7 Jun 2024 15:14:58 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 7 Jun 2024 08:14:40 -0700 Received: from yaviefel.mtl.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 7 Jun 2024 08:14:34 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Nikolay Aleksandrov , , Jonathan Corbet , , Simon Horman Subject: [PATCH net-next v2 2/5] net: ipv4: Add a sysctl to set multipath hash seed Date: Fri, 7 Jun 2024 17:13:54 +0200 Message-ID: <20240607151357.421181-3-petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240607151357.421181-1-petrm@nvidia.com> References: <20240607151357.421181-1-petrm@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F66:EE_|BL3PR12MB6474:EE_ X-MS-Office365-Filtering-Correlation-Id: 88f04e75-1232-43d0-0fe0-08dc87049877 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|7416005|376005|36860700004|1800799015; X-Microsoft-Antispam-Message-Info: SvX5CbEcYYFqXKmV4mSPlXs0JUusg02dFHczTUABDkHnDJ9Mq4nAY4r4vbCZW87lvGDIDMc9+07ok8XS1BzFxIx9mNH8Ks1dnEQRFNzI7+eI9sAYifS7bkCSRNsNUchGiuqpYCkNk0KOu7Q1CDo0kXuC5cUa0Ol3iu7z95c8S4w1zi93iYnrCdQye7owryP6MPwz7yrs359KY4GZCBGjB11MzbDIQWTH79mlhnJTBbbv3j4ky+iYCbAJ03+H67feaenWMk6nP6rgBinIhicUkJpk+9BJnymfeyhDxxVjFfe4/cDB0doXPQ52PGPgSwNUksiEP++2cy/89cXZSlohoFlZvPUb261klDGTQeLRexcnroXIZCTNkqwftZy1X8+d5QFlgzkr8CI/wH4EDYpkiNDwHpdc3+BJ2Yat5VqqfXNwbZbIhpk2RGkwigzRlwc/hWKsXHKanyi0NqdiHLiB1j/6a/OTNz8E6ZDDxdTYRsIEVzKDADx+YHYKqQkCkLiyYU/ZmgjgkFc8T1dRj4C1jBfwF0rW7jMSS8OdMlWk7t+qdkpP+Vt303VDyKNhbFzZ/Gb3Ce83BQvvNwTCBdWsXG6LNRXgVPTqzbtMwTMyUluV+I6oWYM056Pg3Ir1SS69JGp7PZv8Z0sX0nUDxLhrUPVQ3n79IJgMhjJjK7aMRT23VFloABmp0/ZZAXK6z6bv1feE2m34nMLUNrAfP4S4w3Fi3sTn22wRY2g4oUZUFb9ypjA7sv9/ud8KxZMotAGpoSK+WXH3tRYoKDTM093UaJl4QlaW/ux0KLMfgvmwm5l441ahAkjX1Skrk/yW21woFWiTdIpV50OiHDS/fleAfM1kqwEGfII+/EMOaed54DGAIRK4c+tWOfHpMixnOIx45rP13yrrR9NdYBq8SAEOoWFMqJfojTSEwY2QNkZbiT/Vvs1cctIL5QTC9weluDoUBDz+9VPiVdorG9tpQ97koUf5pdMEQkV0ieai/5exmox72CW6cVar7paN/qMmG7o9jaHs/2T2x5eyVFeUMV2jHoyKNum/j3M/Lt8FMKYlon3/fqm7IGyCaxH6viiPsrUuE5gBx9xy/YDpyFT5BXHgsOyMwntqiol4IwgOsrKI94gz8p1VwRUgDN1M/wcAOp1R+2qiKAzoB9S/XmnmHiQtDA/SSLWCe684T67kBXRZlK+Bfdjv6KpMdtBdGjmm4Qn1zP1l3FwV2QI3w76tO9ZRcFiJ0k2/2JJOWsuChUHCnkqBhn5gTWpG6mKeF9Qz7YysVSkS9PUVVuL/2ibFkeM32RzRVf5STZ4RYcizBYtwaSNqnrq+BxlCs9JAepZ56r0XXx+B/RBwqfDuDX7lHPOf7nR6OjwSPSxC1fE/kTKXGYClv7jFrbnVzNlfvtsvJ5QlB55wKzlkhnPW3e+nH79x5w== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(82310400017)(7416005)(376005)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2024 15:14:58.5920 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 88f04e75-1232-43d0-0fe0-08dc87049877 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F66.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6474 X-Patchwork-Delegate: kuba@kernel.org When calculating hashes for the purpose of multipath forwarding, both IPv4 and IPv6 code currently fall back on flow_hash_from_keys(). That uses a randomly-generated seed. That's a fine choice by default, but unfortunately some deployments may need a tighter control over the seed used. In this patch, make the seed configurable by adding a new sysctl key, net.ipv4.fib_multipath_hash_seed to control the seed. This seed is used specifically for multipath forwarding and not for the other concerns that flow_hash_from_keys() is used for, such as queue selection. Expose the knob as sysctl because other such settings, such as headers to hash, are also handled that way. Like those, the multipath hash seed is a per-netns variable. Despite being placed in the net.ipv4 namespace, the multipath seed sysctl is used for both IPv4 and IPv6, similarly to e.g. a number of TCP variables. The seed used by flow_hash_from_keys() is a 128-bit quantity. However it seems that usually the seed is a much more modest value. 32 bits seem typical (Cisco, Cumulus), some systems go even lower. For that reason, and to decouple the user interface from implementation details, go with a 32-bit quantity, which is then quadruplicated to form the siphash key. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- Cc: Jonathan Corbet Cc: linux-doc@vger.kernel.org Cc: Simon Horman Notes: v2: - Instead of precomputing the siphash key, construct it in place of use thus obviating the need to use RCU. - Instead of dispatching to the flow dissector for cases where user seed is 0, maintain a separate random seed. Initialize it early so that we can avoid a branch at the seed reader. - In documentation, s/only valid/only present/ (when CONFIG_IP_ROUTE_MULTIPATH). Also mention the algorithm is unspecified and unstable in principle. Documentation/networking/ip-sysctl.rst | 14 ++++++ include/net/flow_dissector.h | 2 + include/net/ip_fib.h | 23 ++++++++- include/net/netns/ipv4.h | 8 ++++ net/core/flow_dissector.c | 7 +++ net/ipv4/sysctl_net_ipv4.c | 66 ++++++++++++++++++++++++++ 6 files changed, 119 insertions(+), 1 deletion(-) diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst index 6e99eccdb837..3616389c8c2d 100644 --- a/Documentation/networking/ip-sysctl.rst +++ b/Documentation/networking/ip-sysctl.rst @@ -131,6 +131,20 @@ fib_multipath_hash_fields - UNSIGNED INTEGER Default: 0x0007 (source IP, destination IP and IP protocol) +fib_multipath_hash_seed - UNSIGNED INTEGER + The seed value used when calculating hash for multipath routes. Applies + to both IPv4 and IPv6 datapath. Only present for kernels built with + CONFIG_IP_ROUTE_MULTIPATH enabled. + + When set to 0, the seed value used for multipath routing defaults to an + internal random-generated one. + + The actual hashing algorithm is not specified -- there is no guarantee + that a next hop distribution effected by a given seed will keep stable + across kernel versions. + + Default: 0 (random) + fib_sync_mem - UNSIGNED INTEGER Amount of dirty memory from fib entries that can be backlogged before synchronize_rcu is forced. diff --git a/include/net/flow_dissector.h b/include/net/flow_dissector.h index 99626475c3f4..3e47e123934d 100644 --- a/include/net/flow_dissector.h +++ b/include/net/flow_dissector.h @@ -442,6 +442,8 @@ static inline bool flow_keys_have_l4(const struct flow_keys *keys) } u32 flow_hash_from_keys(struct flow_keys *keys); +u32 flow_hash_from_keys_seed(struct flow_keys *keys, + const siphash_key_t *keyval); void skb_flow_get_icmp_tci(const struct sk_buff *skb, struct flow_dissector_key_icmp *key_icmp, const void *data, int thoff, int hlen); diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index b8b3c07e8f7b..6e7984bfb986 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -520,13 +520,34 @@ void fib_nhc_update_mtu(struct fib_nh_common *nhc, u32 new, u32 orig); #ifdef CONFIG_IP_ROUTE_MULTIPATH int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, const struct sk_buff *skb, struct flow_keys *flkeys); -#endif +static void +fib_multipath_hash_construct_key(siphash_key_t *key, u32 mp_seed) +{ + u64 mp_seed_64 = mp_seed; + + key->key[0] = (mp_seed_64 << 32) | mp_seed_64; + key->key[1] = key->key[0]; +} + +static inline u32 fib_multipath_hash_from_keys(const struct net *net, + struct flow_keys *keys) +{ + siphash_aligned_key_t hash_key; + u32 mp_seed; + + mp_seed = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed).mp_seed; + fib_multipath_hash_construct_key(&hash_key, mp_seed); + + return flow_hash_from_keys_seed(keys, &hash_key); +} +#else static inline u32 fib_multipath_hash_from_keys(const struct net *net, struct flow_keys *keys) { return flow_hash_from_keys(keys); } +#endif int fib_check_nh(struct net *net, struct fib_nh *nh, u32 table, u8 scope, struct netlink_ext_ack *extack); diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h index a91bb971f901..5fcd61ada622 100644 --- a/include/net/netns/ipv4.h +++ b/include/net/netns/ipv4.h @@ -40,6 +40,13 @@ struct inet_timewait_death_row { struct tcp_fastopen_context; +#ifdef CONFIG_IP_ROUTE_MULTIPATH +struct sysctl_fib_multipath_hash_seed { + u32 user_seed; + u32 mp_seed; +}; +#endif + struct netns_ipv4 { /* Cacheline organization can be found documented in * Documentation/networking/net_cachelines/netns_ipv4_sysctl.rst. @@ -246,6 +253,7 @@ struct netns_ipv4 { #endif #endif #ifdef CONFIG_IP_ROUTE_MULTIPATH + struct sysctl_fib_multipath_hash_seed sysctl_fib_multipath_hash_seed; u32 sysctl_fib_multipath_hash_fields; u8 sysctl_fib_multipath_use_neigh; u8 sysctl_fib_multipath_hash_policy; diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c index 59fe46077b3c..fcd584588baa 100644 --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -1806,6 +1806,13 @@ u32 flow_hash_from_keys(struct flow_keys *keys) } EXPORT_SYMBOL(flow_hash_from_keys); +u32 flow_hash_from_keys_seed(struct flow_keys *keys, + const siphash_key_t *keyval) +{ + return __flow_hash_from_keys(keys, keyval); +} +EXPORT_SYMBOL(flow_hash_from_keys_seed); + static inline u32 ___skb_get_hash(const struct sk_buff *skb, struct flow_keys *keys, const siphash_key_t *keyval) diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index bb64c0ef092d..9140d20eb2d4 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c @@ -464,6 +464,61 @@ static int proc_fib_multipath_hash_fields(struct ctl_table *table, int write, return ret; } + +static u32 proc_fib_multipath_hash_rand_seed __ro_after_init; + +static void proc_fib_multipath_hash_init_rand_seed(void) +{ + get_random_bytes(&proc_fib_multipath_hash_rand_seed, + sizeof(proc_fib_multipath_hash_rand_seed)); +} + +static void proc_fib_multipath_hash_set_seed(struct net *net, u32 user_seed) +{ + struct sysctl_fib_multipath_hash_seed new = { + .user_seed = user_seed, + .mp_seed = (user_seed ? user_seed : + proc_fib_multipath_hash_rand_seed), + }; + + WRITE_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed, new); +} + +static int proc_fib_multipath_hash_seed(struct ctl_table *table, int write, + void *buffer, size_t *lenp, + loff_t *ppos) +{ + struct sysctl_fib_multipath_hash_seed *mphs; + struct net *net = table->data; + struct ctl_table tmp; + u32 user_seed; + int ret; + + mphs = &net->ipv4.sysctl_fib_multipath_hash_seed; + user_seed = mphs->user_seed; + + tmp = *table; + tmp.data = &user_seed; + + ret = proc_douintvec_minmax(&tmp, write, buffer, lenp, ppos); + + if (write && ret == 0) { + proc_fib_multipath_hash_set_seed(net, user_seed); + call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net); + } + + return ret; +} +#else + +static void proc_fib_multipath_hash_init_rand_seed(void) +{ +} + +static void proc_fib_multipath_hash_set_seed(struct net *net, u32 user_seed) +{ +} + #endif static struct ctl_table ipv4_table[] = { @@ -1072,6 +1127,13 @@ static struct ctl_table ipv4_net_table[] = { .extra1 = SYSCTL_ONE, .extra2 = &fib_multipath_hash_fields_all_mask, }, + { + .procname = "fib_multipath_hash_seed", + .data = &init_net, + .maxlen = sizeof(u32), + .mode = 0644, + .proc_handler = proc_fib_multipath_hash_seed, + }, #endif { .procname = "ip_unprivileged_port_start", @@ -1550,6 +1612,8 @@ static __net_init int ipv4_sysctl_init_net(struct net *net) if (!net->ipv4.sysctl_local_reserved_ports) goto err_ports; + proc_fib_multipath_hash_set_seed(net, 0); + return 0; err_ports: @@ -1584,6 +1648,8 @@ static __init int sysctl_ipv4_init(void) if (!hdr) return -ENOMEM; + proc_fib_multipath_hash_init_rand_seed(); + if (register_pernet_subsys(&ipv4_sysctl_ops)) { unregister_net_sysctl_table(hdr); return -ENOMEM; From patchwork Fri Jun 7 15:13:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13690373 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2068.outbound.protection.outlook.com [40.107.220.68]) (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 04749195999 for ; Fri, 7 Jun 2024 15:15:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717773321; cv=fail; b=Ww/B/N5eB92g0lHRbawWR5RZ/USmjErWOBeMMwm0xBW1esVZ+DeoMl+D7ykoWT396G/x+UsHueAo5BaczNcpm1F8exZa84tAAF3os/vHo8CLORExnkZt0qhHjCBfloEN2MtSBygS1LjW0boUKTdKwAuzpwFQJOh5fguvMPW8WWo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717773321; c=relaxed/simple; bh=YcvSLs2LU3INVOOeut4w4V7clSoF8oKqm5Z/n3gzDrY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Bj3ivTp6UeNatzyW6yQAFBaBVT3fuzUlo9h9+dwcPMLwwmHLnP5N8cf3DNVwGifgih8ZSa4KTDobf8OOHHErA7MPuO+aC53UA1kP+XlKOXUkwzvxFtWQgL60LFgpdl6u9KSfb9TRM2TsaodagsVbgIGdl48YjnHbC/uCzWGc7ho= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=HQ/kCXAv; arc=fail smtp.client-ip=40.107.220.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="HQ/kCXAv" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JJp0YryRjZEl12GtM4qF7vfBFDHcfq9Tu1lUVuGFvzh/o4FACbWd1W++XvGG2Q6VhbhTDvLuiRt9m+hw3l6Kfp7NkfuoFv+j/Kc6wYKikHAOc7bmTu0qnIkLdFH7PA2859Fl/I+5wGs4HV/tXw80AxrcrfVv3x51J7sS40TWthM8QhU8Y0/0lGYqm/kWItIy6AXoDs7uRblPMUnROhu79++v0Y0bNRNEzxJck6rT770mfJ3LU0myXVmfsH74gnWVl6Yd8/rqzA4Z4wTaXdAynndKGcmcr6BXeC24hrTQKhfoh7vF6HtplHLYZD87Z7Tc+3Fh46R0ip0go/At/1gtpg== 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=kqDEVXIY8wIC0A1XXD36OZ818h/X519G/2xgJixeNZA=; b=mw/df6p0YUd5TWlTOPLaI74mvWKzN1yOoPBzLp5DC517a/M4kLfby1KVlam/yIydCj23r1PGKf6GbuISXr/Cp/9jISaiVk/rHWFzutpJVyI22PNSI6aN0NjNyCpFG/yk7yGjufH7VdQ3Jtu7McC4Q2IlmY6mo75zAbieRqquZtr5vdWwTTjB7jNOFVxGL6YygXSjyFYA23eLMiEpc0AgNLHaR3lFHQJjCH/l2Os5gkYnU87FzoGCcHxfJgQb3zHwzTvS11dWDsmrW91WpZI0PnopGIQs2nBtkoqeVl0erFXouSB/NUQmrXAJc496b9CTDcIpimtRYCu0LqGKCB9KHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=kqDEVXIY8wIC0A1XXD36OZ818h/X519G/2xgJixeNZA=; b=HQ/kCXAvUET63XkWlH0wpigm/jsumT1Xoc45RGMetg2KZrP37pqPs2QXqB/3HtHPqcNFgEuV8Gp9kNvX9xHA0Ux6y7EpMxW83e2TUwZT/AsUOvkmQzqjrzS17sDh6yPSWivKPpuwWYxPa5hM/acC1ujQNZX2cmPy8WKZ/coQS4opCi7W1M/4yHmw6tRbPoEG/ffRK2ufNjLT3iodA0n9MePMcZ7+GPDG1DTqwuOBgfcb8p2rnwXK8bNGDzoKritH1CHXWXEdoAkv2ZFVU5BmmbJEA/kchRNAPoAQuAAq+qVJzst77OMVOgb//XEW5enKWaukBEBmOioK1Bh7QB1ayg== Received: from MN2PR13CA0014.namprd13.prod.outlook.com (2603:10b6:208:160::27) by PH7PR12MB6955.namprd12.prod.outlook.com (2603:10b6:510:1b8::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.33; Fri, 7 Jun 2024 15:15:03 +0000 Received: from BL6PEPF0001AB73.namprd02.prod.outlook.com (2603:10b6:208:160:cafe::a) by MN2PR13CA0014.outlook.office365.com (2603:10b6:208:160::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.14 via Frontend Transport; Fri, 7 Jun 2024 15:15:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL6PEPF0001AB73.mail.protection.outlook.com (10.167.242.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.15 via Frontend Transport; Fri, 7 Jun 2024 15:15:00 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 7 Jun 2024 08:14:44 -0700 Received: from yaviefel.mtl.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 7 Jun 2024 08:14:40 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Nikolay Aleksandrov , Subject: [PATCH net-next v2 3/5] mlxsw: spectrum_router: Apply user-defined multipath hash seed Date: Fri, 7 Jun 2024 17:13:55 +0200 Message-ID: <20240607151357.421181-4-petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240607151357.421181-1-petrm@nvidia.com> References: <20240607151357.421181-1-petrm@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB73:EE_|PH7PR12MB6955:EE_ X-MS-Office365-Filtering-Correlation-Id: 384a7595-59b6-4cb2-db64-08dc870499a1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|82310400017|36860700004|1800799015|376005; X-Microsoft-Antispam-Message-Info: eCGicibtTcfUYh3vmIzAVlLo1mntg/QYJn99Na0nO/IDTTDWOyEV6V5kZnK97HFj568uPYS8c4fuim5pstyHH5h9XuqtaohvUIXKfP2jJ98hycZ0XNHf8zVbbyXg9yKjLJ1z7DV25gtP/SK2NFrTkt+1WR6Yy2zp6ADne8Hl6d6zDCyWi3t6AGwKc1rRoe3qnZL6Dsxnqq7WZI7fXf/tNw9LPeC+lavS1jGpCa/1U9bROzcGR+6AMUb6Wmb4TZOWcMBMMqMd3xUAqNfkOdio0J8LiK7noChd7j68hWh8pXSrCeSmAapqLpMls/3W7HBpkYIKOi/LlxJMXe1rt5bbS+LAYUStcFcOCbbpS5fFNkMhx2cRCIGxUvZ5ZRd0zLVqeXGBVeYtWa26rTAmejOL0lGlVbMflBbrAwX5OpVqAurvnmq8lp1gesjmVK+irpKTU/t2v1FhULywvgHshrrN1CK6iVTwl7qHRmrE0rG2tIQgaR+UBFeoOgOhWQYCrmO0e5BqKk6C/FKUIx+WOR3r4Qv3EXV7XTGJmZc0iZG88o8GEbwagMYsqzlgNkVG5FXKZD/Gq29rTbdRDRqWwLQS3T1N8YNZPZqa37hJc4Nj51qdAR35pjmpr9wsRnQpSXnfh+3d5WUbcMlVM7t2wIGJCbvu4oZSinm4c6/3103zNT4yelK9GTrLCudzz40cvtloocoSUZFA2EnyV+OA2jNoWipNd2bYxSBfl1Q3/Up9bpzm8RJ+AC8mjM6TYRfm3U9K2iegp7gxm0VjC4oiJa7q8Q6LHN6501fK2BioJ/z8+XzL4Phdb2uf38gKCcIf8Xwgiv1YqQPYSGfNzEXUaVD/U3T8FOzagN/pmltW7AKFeDezXbi4F7OOze+BSMPu8HmD6No0rWXo3qhSZhWdfZe+Su8K0MVUBUmKo31Ep8SMy6AfjuG/ih+XL5GhqUfTxyy1yt31zRc74cJbO3Xar2ZPtsCug1Y9jgHcr2jCg+2OaB8LzRasItYnBU5GXhY1cDkFs8nijdPvztxuENtOoW0adiy0IOzDp09LFE6uaNYcfjw1gtK1ACcCapMbOHW4/w5KxUvVtSYpk1QK3M2ZonFGz1svWjhMmIN443SE1XBdfrMYC06eMhV7L/QF06LY8xrseSXnV9oi0HJFXm8ynK7nQGjcQK/OnbOEFOAzqGdpZUEhgjaS4ljgSEi0kEUG8wz3ly1ww7DEq9QpcaD3+LQZVneNnrvHuOzzb0iHv4tl6vCxUAiipQBspuSzDNioMBDkhRb4C2yvH1Us5PtIH+QdhjLBykjqlX1HjqpYQ1woAc6z0ZV9Op0B+UYLlrXFoDmseykMr3P7/9kyzOlZrL8xizNdoplUFEhWZukI2MwgEBWyTvvCuB5zjzaPhxHSjoChM6dfPJFzZQ5mFs+02E9V+g== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(82310400017)(36860700004)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2024 15:15:00.4877 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 384a7595-59b6-4cb2-db64-08dc870499a1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB73.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6955 X-Patchwork-Delegate: kuba@kernel.org When Spectrum machines compute hash for the purposes of ECMP routing, they use a seed specified through RECR_v2 (Router ECMP Configuration Register). Up until now mlxsw computed the seed by hashing the machine's base MAC. Now that we can optionally have a user-provided seed, use that if possible. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- Notes: v2: - Update to match changes in patch #2. drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index 40ba314fbc72..800dfb64ec83 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -11450,12 +11450,16 @@ static int mlxsw_sp_mp_hash_init(struct mlxsw_sp *mlxsw_sp) { bool old_inc_parsing_depth, new_inc_parsing_depth; struct mlxsw_sp_mp_hash_config config = {}; + struct net *net = mlxsw_sp_net(mlxsw_sp); char recr2_pl[MLXSW_REG_RECR2_LEN]; unsigned long bit; u32 seed; int err; - seed = jhash(mlxsw_sp->base_mac, sizeof(mlxsw_sp->base_mac), 0); + seed = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed).user_seed; + if (!seed) + seed = jhash(mlxsw_sp->base_mac, sizeof(mlxsw_sp->base_mac), 0); + mlxsw_reg_recr2_pack(recr2_pl, seed); mlxsw_sp_mp4_hash_init(mlxsw_sp, &config); mlxsw_sp_mp6_hash_init(mlxsw_sp, &config); From patchwork Fri Jun 7 15:13:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13690372 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2079.outbound.protection.outlook.com [40.107.223.79]) (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 812DF194AC2; Fri, 7 Jun 2024 15:15:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717773313; cv=fail; b=j3YTDkX+239sM6MPawN/zbRovxVoX5+w/o+HPSHDLAlGWpLGNFdUnWebygEQQrOsJDy9Wel5AXYoU8IT8UfLr6caJb9IJduEuFkN41iZNtBejpX4KFOWBUHezrCpkaNsx7wMBM9CYWiS1vITX01nPSZ9LUVc4XObzOc5nBYYFnQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717773313; c=relaxed/simple; bh=lLcb6eaXq4gcg1qgUBqzgE26aNxbx6w8SibCqsqR+Pk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jVrmbzx5o6TexMddD36BR9AojHj3q0tUdkjBm4nj3v/tUdfKHEMDI477rffh/nbc0uSmR+jPVmcWgapmHBBA/j43YGBhl83SZp9L5m/3CymakkK/c3rZGy+THFUXGg+QntofVk1gPsdk58U7j5R03Bw/WiF2EilKxotQmiM6Ruo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=lGjR5Mt1; arc=fail smtp.client-ip=40.107.223.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="lGjR5Mt1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZewGvSYRQK/2mQsEMnChm+TgmP9t3UEj73MUAoOTLMvXKnd/1OWzpqbx1ZiuGNEa+yKd1e8wO2W6lLr6+wlbXNnEUYtufqsqXEtzzYCODVAPMcwG+lpQJyjzP5T4VLPWwEXJ/f2Tbl9bfBcLYDtGjRit61IBlBJmiWIMSyMNdcZ16/YzaqBfcZBGCmLd6ew8JoC+/qZxbPWEW8kSpnShGmfWP6ZUFG4PZfebpZAirmAgU6ajO6+ejdEfeB5eu0aPzJpG5HgkdJzNNpEw9Ertze5Ju5XaV/d7IENE2Z1B2vIfAIbxamB7gupvdKeIldSUNa+ZPwG5ZyBVSw8PMsiaSg== 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=pbanpn7aTaQwvnq1jLYqpIkmKFt2I0F2FxvZYhaOz/I=; b=e7loCBPTFVhxwypPrGZFEX0+MXHtzfCt0CzcEboINXWsIbc1ruN3HSeGCm/RUPvopZ+2s7c6ErP1XSjDV4MER9mlU2OMruU46zMsozTE0fZUSV/WlQF65ORyMYlHjJhmlDVfggItXMnKzc1JF5/mEE12lPS+hXGctn7Rv9FKjkttugrPUoxzPbUYEIjh0pAskrlBZt8rdsXS3jM0IPxVYD5C40dzV/GowdE3GzqkYO4DwOIaQ1DdOwxNFTAkUq5gHPLbfuZsswhyA4pFVKVSlZcGVkBGuIwI/x/8BrvQ25mn4va5KpEQVWvZ2jydLrFeJI43n8Q0NAojuY/Sz/icPA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=pbanpn7aTaQwvnq1jLYqpIkmKFt2I0F2FxvZYhaOz/I=; b=lGjR5Mt1TVaYLiN+GnsolqvWmpgHEnIjCTiP+hwHBfcRcwrhG0Z54jzhnx4s5tGRLbFyLLYAJJwrW9OgQbRUX4L2Sli4//vnHT1YtXl0lnP8PfpL9oPIcm6qdcb4xTd6bdTaQHjrTzyEn2BfGE2DTjbVLsZivdypwWWU66cE2NozSZf6C0M+7ngOisSz5AX8cVvx4aG3a+XidKAySt3nutk38G50/nfOR5AA8mrBesMv5spzS0aYteYbOLXaZ83k0yo3qo8LxolyHPGiofu3LkYrBwKKnbhogEeIGdgBk+zXmkbm11bv0qAHpFrU+EbWJ6Xj8UkPgIi+TCZI8D4orQ== Received: from BL0PR02CA0092.namprd02.prod.outlook.com (2603:10b6:208:51::33) by DM6PR12MB4434.namprd12.prod.outlook.com (2603:10b6:5:2ad::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.34; Fri, 7 Jun 2024 15:15:08 +0000 Received: from BL6PEPF0001AB72.namprd02.prod.outlook.com (2603:10b6:208:51:cafe::ea) by BL0PR02CA0092.outlook.office365.com (2603:10b6:208:51::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.22 via Frontend Transport; Fri, 7 Jun 2024 15:15:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL6PEPF0001AB72.mail.protection.outlook.com (10.167.242.165) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.15 via Frontend Transport; Fri, 7 Jun 2024 15:15:08 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 7 Jun 2024 08:14:49 -0700 Received: from yaviefel.mtl.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 7 Jun 2024 08:14:45 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Nikolay Aleksandrov , , Shuah Khan , Subject: [PATCH net-next v2 4/5] selftests: forwarding: lib: Split sysctl_save() out of sysctl_set() Date: Fri, 7 Jun 2024 17:13:56 +0200 Message-ID: <20240607151357.421181-5-petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240607151357.421181-1-petrm@nvidia.com> References: <20240607151357.421181-1-petrm@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB72:EE_|DM6PR12MB4434:EE_ X-MS-Office365-Filtering-Correlation-Id: f064348f-6c1f-49c5-8b52-08dc87049e29 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|82310400017|36860700004; X-Microsoft-Antispam-Message-Info: briG6Q014paRMt1zvZ5aeYBPCzhppjejTxGsiDn1dzhJy6+QfCp/leP25V2ivJ2DmG69rs3hkckoyd/I+XPiObTXtG8b3Ih9oiFmRywzsR+CNIKNRuolRCv8ocMvj/jEMaL37HubR++MFQm4ym5AVX/Hc5r/sscGPzVCJxpUHk4ol7qGpuvzKja8quUXnUEAdXXE57FsTahbEK+Elp1tfyqK3h/B0XXUkX9F75OgsRuquDVv+gP4nnFz9gtNpKghLgd6hgfoUdn6SOqz+bYXK2t8Clf3xjB1mc2Fu8XmCclTdOXa6VONAMzYEKFF+cEt6rLlRoToJ8KfBiDhWvt6n4maK6uS4M6GF2aqdZr0aOoMyWs1NAUor9CfLis8Up0XALgkmZD3D5t0Sf3TZLjmvy0IcKkFQsQSvtRl788bd+VezkWd1hQksAXT+6VsfaDp6AHZECestAz9/RiR1rdEqaHau5jiaabuHrYfzH6Lp8eUAFW0mpUxeG5nGKnAU8wZOsslMoLaT+ooDEKGK6FepFSp/8srfNXpzMZbxd4DnxYGW0NKViMtzThxnc71NwGVI+d5IWb2ZaAhSkmtRS142fXTdZZqhN8BZLq2ITLJ9KbLEYiWAG8QqHAfcuOOzoOCBRSYOa1vleaxZLK/M+ghgsXHBO0HS/+SAFOb254i0/wcZePopPV1Fd4KWJ5lv/A8uxHHHmcSiBcBvGZR5B4s3K9h5CC0MqFy3gOYOREY0uLCHYRg+gcJhQvhGWWqCN9cn1Yzw2Nq4k5EY5L2BDtjL19iAwBJ0QAlld9W3kfm0KwfHYVgr5QXy18Ij2lwnPkDiKnQXj6u5EF/vqn3ttMbOX7gvzF1m8j09REKiADkIJAs6/BcuxmH6ehnma5ySp79NoJkNpbl1swKp6rdvxH4NNI9X1y60yhaLrdgS8rAt095JovmoB/6JH0iSxZChsJDFCT6Q7H4HxQ3nIMxSjJdlkhtsbWWPn7cGSkDpTFs5RRKmAFQ/+qMQeGrAmZNIqgQ3ZQrbPvdvGexm2X3mA4ol0jRFLt6N8LIkYqkDmNJK8s5mAXRitEw7e0NUkhyURosXGQd/Tn91nvgFWX8ofP/bVTnzK28gMGMgDP8w2MyasUpPrM8z1xa+AscnoiJoBuZHmjQlDXLHn709HXstfYuCE6WgdZIjXAMka/4dmys+N6Iv6hBhBIlhkPmDfD4PxbVZk1cwc1YMrGsP2jT+0BdltqW6vAGUgJznaAX1pSIIby6REgUpS8GGyzn9IYMVqH1dKyy9OVOv2Bh56vhuA909xgk/L4sBVKMOQx+PsyG2bP4xy0Fcqdyow6HnxviQWVk4rEFwW7Oo6QV4NlCbcy4GgE93sr8jF16KP/rhKnwBTEPxNGABFWwGGBNr9oQ+nNzNGERNBQFT+O7QNcqysAhZw== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(376005)(1800799015)(82310400017)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2024 15:15:08.1034 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f064348f-6c1f-49c5-8b52-08dc87049e29 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB72.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4434 X-Patchwork-Delegate: kuba@kernel.org In order to be able to save the current value of a sysctl without changing it, split the relevant bit out of sysctl_set() into a new helper. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- Cc: Shuah Khan Cc: linux-kselftest@vger.kernel.org Notes: v2: - New patch. tools/testing/selftests/net/forwarding/lib.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh index eabbdf00d8ca..9086d2015296 100644 --- a/tools/testing/selftests/net/forwarding/lib.sh +++ b/tools/testing/selftests/net/forwarding/lib.sh @@ -1134,12 +1134,19 @@ bridge_ageing_time_get() } declare -A SYSCTL_ORIG +sysctl_save() +{ + local key=$1; shift + + SYSCTL_ORIG[$key]=$(sysctl -n $key) +} + sysctl_set() { local key=$1; shift local value=$1; shift - SYSCTL_ORIG[$key]=$(sysctl -n $key) + sysctl_save "$key" sysctl -qw $key="$value" } From patchwork Fri Jun 7 15:13:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13690374 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2065.outbound.protection.outlook.com [40.107.96.65]) (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 449EA19885E; Fri, 7 Jun 2024 15:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.65 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717773323; cv=fail; b=C94afRv12smickdElKSPHW2VrobSns3LEZYq2+EPFM6lVRgiKfQutjGdCth/knGfqKwAPxafklEzJRI38rIoUI177y91JLR9DXd+bOXZTdEBXA11UByfDeK6o1+sMNzbn+89cFQWEfi9y/QRQqI0Lp05LnHIcMRbvttF+iAqGQg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717773323; c=relaxed/simple; bh=vdHBwUWCaO/YOuxMhoPw/y7XFO4JwgQxX9z+sJlwbnE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=U7o1dxO+4X1TuIu0pB5vcUnFNBz2mqxnIzFkCCE92HILfvYIYtns06qtAdUOWU0DTsFTN0iGZwP9fbSG6JkuToAZ/NmoqYG24BB3lE7DJ87d2LYrUosRvx/Q27OCoOnfNaKEaiMIH5P8gEDpZ1CqPW0iuqdHsY2aP0LvA2nl6Cg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=EOuNYowg; arc=fail smtp.client-ip=40.107.96.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="EOuNYowg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gsBdkXeEMtsFXnHAuVx/Mr4Rnx2iB/P8gbLGl0QSv3941gDCyz5LxOLIOK9VkjpNBgUO4EIhDjjS+VeizF9br/e5cxKZMQIjsehGFZnRTudMzp641YL2MlYO7Rw2SMP3voLav5+YmAolI11xR1fvUnhnIqnemC7yCVc6spGfEQ7PR6FklWGHiPqAolDdZFiSWpIjvyMBbR/cGVI8e6psWTSecpoN3T48GDFrNobQ3DFo54lRLI8+YsjEQ57HNkt/lhRvCjDD73k0sfeY2jZmzYHrCui6WaMNjwsDAigZi2ZNc1CdwYUVq5QnVOo54qAJmQKCuqkOWTAqEn/B+FPAmw== 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=+NiVE+o4ZswaqIsVty2uSoRzac0/lbYCqG503PWVH4Y=; b=Ji7n77UqI6u8CjnIFcyjp+ybcdIJxBd5+mmSpVnxpsKr18Fwqlq5V3rBqgZr4tQ+WUxOKEkyuPqJNf6bPy11LGvNvtFTY8JVrB+krccVs31CrTzbRbBC4SZqd0Jq1fZ+/QdavzQe5ZgksBv0baObhiGOOJo+HhSGdCUGRhUdi5Kea3+SbNTtsVYQ6eMe4e4iWvpdgY7H2HiFv5oJzjK0EYFwkOdp09Ysp6NK2MQuhtjs+/uLEesUHN92FRR0ISZmRf24+rmXUyZ+rGJvXsEyzED+LDpQtVPKB59bx1+C2enpMpYPVX5IMm+MI8eIFw1IYMW67Ykspfcw/1ngwbgQNQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) 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=+NiVE+o4ZswaqIsVty2uSoRzac0/lbYCqG503PWVH4Y=; b=EOuNYowgsFcG9beWFG8eVuquN1GmZVvso0VDHMxgnk4iKjfi4WB8VoeYGuu7hWA9crHPgW2eK6vaheNANBIYlIth625e5/sw2fAXxVxV9brPKqR72RWvzMZ+/j98ZbGlWVa276+m1qtMLFYSHzZX8Qh/RGK5mv0wtY7UVUxBZErjYWodZV6wnHuE/1Q3fiZTopfImdSQJUSgNTnKFSWoqxhrEdH3zE8uitY693eODQj9tzDG522HczsS1HUg1i6T95Vvz2ZIMCE6/sRV6EGDyz1e4pJZmtshbcFpfH9OSACYx0swW+qStHFLcjZ92SMVvGJymL8dqkHJgNyW0fZbxg== Received: from MN2PR20CA0022.namprd20.prod.outlook.com (2603:10b6:208:e8::35) by PH7PR12MB5950.namprd12.prod.outlook.com (2603:10b6:510:1d9::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.21; Fri, 7 Jun 2024 15:15:14 +0000 Received: from BL6PEPF0001AB76.namprd02.prod.outlook.com (2603:10b6:208:e8:cafe::92) by MN2PR20CA0022.outlook.office365.com (2603:10b6:208:e8::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.28 via Frontend Transport; Fri, 7 Jun 2024 15:15:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BL6PEPF0001AB76.mail.protection.outlook.com (10.167.242.169) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.15 via Frontend Transport; Fri, 7 Jun 2024 15:15:13 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 7 Jun 2024 08:14:55 -0700 Received: from yaviefel.mtl.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 7 Jun 2024 08:14:50 -0700 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "David Ahern" , Nikolay Aleksandrov , , Shuah Khan , Subject: [PATCH net-next v2 5/5] selftests: forwarding: router_mpath_hash: Add a new selftest Date: Fri, 7 Jun 2024 17:13:57 +0200 Message-ID: <20240607151357.421181-6-petrm@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240607151357.421181-1-petrm@nvidia.com> References: <20240607151357.421181-1-petrm@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB76:EE_|PH7PR12MB5950:EE_ X-MS-Office365-Filtering-Correlation-Id: 339ee6a3-c6b0-4eb7-1fa0-08dc8704a13d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|82310400017|36860700004; X-Microsoft-Antispam-Message-Info: YAU/H2TvQ85UZw3JizCyifLZejwPFkkqtQwrqMvl/O0d6C0kDIHGZXJVhTbvmkMaOlvVD4fY3uWPCeiaz9AKxTRZDCLcEFAqN/bfimP8gUpz/pHrxjhjp8wkXaJOdB6DBRj1SE2Y2KBs6NHYY+W71CucfOpLqAU5gqQ4WC5pNOsAgTxEyW0CQoBSt5sxYvKVNuQz/LqKSv0B128xng3anYjtIbiPjXtePMkmCZQOFx0stCI0oz/L1KIu866nDmOl0VUB1ogFHcz5DhX13GTGVTLmEBxhxYTJVsudbftPfm9J/rA4FdmIiI2IzLQ+wLEQ4Rmwe0fOjeOdE1EA1RMpKEkeN/Pu8NUrA9jHIydGSWpB53ztugjUHFGEDlHgL2rLWB04gjNMEUu1t96zA7d5EZiqK2+oVScwTfDU8KDkZjiH3XuiQPGWI0dZzti4KnhAn3K4+02YPIE8khlIsAnLgb0yO6HFwkQiRcqSI5yfb11AAiyBmFqlXD5jNWko++832Dmcsb4Fh4etgaT/PCiWbwvWPtsnPQYo3PsE+Wxl1MOL/9oNOaEkCc3JklD/o4FMEgYCzFRJpQVmBQf3yDmwoWfW/EmbKmH532JImjyrOykwgqBzgTnXwxmnmDmD33B+o8SEksOKC7v9tRRbgktyUTFCSmas3PjaOopkwm4i9R66TbOMyWG1/xFS3PVXfxG8ctyPZX4xNThXDDvW53pKBjGfqJXqhRYjVhEIwt90ke9/00/Bq2p8RvKW/JevZIC/9Iio4Pi02rZeaE77ibx/oXACTftm9zBtruZGsBZswfYFfbI0RDQlJ3wtqgIV3+AybmU2DthEnVIAaxe2RogcHyLnz1qSn62eV8qqMaU7sJ9Kr4c/kmY2eWpvOlj4VzbjftdjdkSeErlYuhbJbptDYZKIWmHB0WyQVFSEnIX/1b2ut+8Ec6YA93XPkY+ecb8JiSwcE27SMmMB0MDcNq1qgcenazlqMB0Hpy/Kfrc4oh0RnXc5kndpZQXXLDOcnXdKlan7FhQB76bKJBsWo2zmA1odJJPHILrQh5Fz1hcl1vKsDI7in0viDpWpxBRZJ/k9PwP+s2BkRLQctET+4WIKsox9Vostg8yWqdGQf9l4GobRkJMvBH8jCCxmtT3RtU4QLNfjX/5YTxdggvKLJ+Mvh2QRkgPJxxGz3+kaLqFtup19RgqOJw0dReJt3qElOWk/O+gBetDV0LoTrd4mX8hbiDOGq1d/67MsubuDl1tlJBf4xVY50hboa+XZc4wGTxyMpJnZmmtytVpFIL1g08F2p/V5Js3t6sryY3gvJKKum2MGOuiYWvLPKmIvh/XyH/LnI+yBAfetxmdSD3mp9Nt9wJyGBdXao18favb+0WjDtX5W5pxviyAxaj5nIWFnKbawQC6Ut84ZPdqc2Qm6GBRk/Q== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(1800799015)(376005)(82310400017)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2024 15:15:13.2336 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 339ee6a3-c6b0-4eb7-1fa0-08dc8704a13d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB76.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5950 X-Patchwork-Delegate: kuba@kernel.org Add a selftest that exercises the sysctl added in the previous patches. Test that set/get works as expected; that across seeds we eventually hit all NHs (test_mpath_seed_*); and that a given seed keeps hitting the same NHs even across seed changes (test_mpath_seed_stability_*). Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- Cc: Shuah Khan Cc: linux-kselftest@vger.kernel.org Notes: v2: - Do not set seed on test init and run the stability tests first to catch the cases of a missed pernet seed init. .../testing/selftests/net/forwarding/Makefile | 1 + .../net/forwarding/router_mpath_seed.sh | 333 ++++++++++++++++++ 2 files changed, 334 insertions(+) create mode 100755 tools/testing/selftests/net/forwarding/router_mpath_seed.sh diff --git a/tools/testing/selftests/net/forwarding/Makefile b/tools/testing/selftests/net/forwarding/Makefile index fa7b59ff4029..99576d7ecbf6 100644 --- a/tools/testing/selftests/net/forwarding/Makefile +++ b/tools/testing/selftests/net/forwarding/Makefile @@ -70,6 +70,7 @@ TEST_PROGS = bridge_fdb_learning_limit.sh \ router_broadcast.sh \ router_mpath_nh_res.sh \ router_mpath_nh.sh \ + router_mpath_seed.sh \ router_multicast.sh \ router_multipath.sh \ router_nh.sh \ diff --git a/tools/testing/selftests/net/forwarding/router_mpath_seed.sh b/tools/testing/selftests/net/forwarding/router_mpath_seed.sh new file mode 100755 index 000000000000..314cb906c1eb --- /dev/null +++ b/tools/testing/selftests/net/forwarding/router_mpath_seed.sh @@ -0,0 +1,333 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# +-------------------------+ +-------------------------+ +# | H1 | | H2 | +# | $h1 + | | + $h2 | +# | 192.0.2.1/28 | | | | 192.0.2.34/28 | +# | 2001:db8:1::1/64 | | | | 2001:db8:3::2/64 | +# +-------------------|-----+ +-|-----------------------+ +# | | +# +-------------------|-----+ +-|-----------------------+ +# | R1 | | | | R2 | +# | $rp11 + | | + $rp21 | +# | 192.0.2.2/28 | | 192.0.2.33/28 | +# | 2001:db8:1::2/64 | | 2001:db8:3::1/64 | +# | | | | +# | $rp12 + | | + $rp22 | +# | 192.0.2.17/28 | | | | 192.0.2.18..27/28 | +# | 2001:db8:2::17/64 | | | | 2001:db8:2::18..27/64 | +# +-------------------|-----+ +-|-----------------------+ +# | | +# `----------' + +ALL_TESTS=" + ping_ipv4 + ping_ipv6 + test_mpath_seed_stability_ipv4 + test_mpath_seed_stability_ipv6 + test_mpath_seed_get + test_mpath_seed_ipv4 + test_mpath_seed_ipv6 +" +NUM_NETIFS=6 +source lib.sh + +h1_create() +{ + simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64 + ip -4 route add 192.0.2.32/28 vrf v$h1 nexthop via 192.0.2.2 + ip -6 route add 2001:db8:3::/64 vrf v$h1 nexthop via 2001:db8:1::2 +} + +h1_destroy() +{ + ip -6 route del 2001:db8:3::/64 vrf v$h1 nexthop via 2001:db8:1::2 + ip -4 route del 192.0.2.32/28 vrf v$h1 nexthop via 192.0.2.2 + simple_if_fini $h1 192.0.2.1/28 2001:db8:1::1/64 +} + +h2_create() +{ + simple_if_init $h2 192.0.2.34/28 2001:db8:3::2/64 + ip -4 route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.33 + ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:3::1 +} + +h2_destroy() +{ + ip -6 route del 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:3::1 + ip -4 route del 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.33 + simple_if_fini $h2 192.0.2.34/28 2001:db8:3::2/64 +} + +router1_create() +{ + simple_if_init $rp11 192.0.2.2/28 2001:db8:1::2/64 + __simple_if_init $rp12 v$rp11 192.0.2.17/28 2001:db8:2::17/64 +} + +router1_destroy() +{ + __simple_if_fini $rp12 192.0.2.17/28 2001:db8:2::17/64 + simple_if_fini $rp11 192.0.2.2/28 2001:db8:1::2/64 +} + +router2_create() +{ + simple_if_init $rp21 192.0.2.33/28 2001:db8:3::1/64 + __simple_if_init $rp22 v$rp21 192.0.2.18/28 2001:db8:2::18/64 + ip -4 route add 192.0.2.0/28 vrf v$rp21 nexthop via 192.0.2.17 + ip -6 route add 2001:db8:1::/64 vrf v$rp21 nexthop via 2001:db8:2::17 +} + +router2_destroy() +{ + ip -6 route del 2001:db8:1::/64 vrf v$rp21 nexthop via 2001:db8:2::17 + ip -4 route del 192.0.2.0/28 vrf v$rp21 nexthop via 192.0.2.17 + __simple_if_fini $rp22 192.0.2.18/28 2001:db8:2::18/64 + simple_if_fini $rp21 192.0.2.33/28 2001:db8:3::1/64 +} + +nexthops_create() +{ + local i + for i in $(seq 10); do + ip nexthop add id $((1000 + i)) via 192.0.2.18 dev $rp12 + ip nexthop add id $((2000 + i)) via 2001:db8:2::18 dev $rp12 + done + + ip nexthop add id 1000 group $(seq -s / 1001 1010) hw_stats on + ip nexthop add id 2000 group $(seq -s / 2001 2010) hw_stats on + ip -4 route add 192.0.2.32/28 vrf v$rp11 nhid 1000 + ip -6 route add 2001:db8:3::/64 vrf v$rp11 nhid 2000 +} + +nexthops_destroy() +{ + local i + + ip -6 route del 2001:db8:3::/64 vrf v$rp11 nhid 2000 + ip -4 route del 192.0.2.32/28 vrf v$rp11 nhid 1000 + ip nexthop del id 2000 + ip nexthop del id 1000 + + for i in $(seq 10 -1 1); do + ip nexthop del id $((2000 + i)) + ip nexthop del id $((1000 + i)) + done +} + +setup_prepare() +{ + h1=${NETIFS[p1]} + rp11=${NETIFS[p2]} + + rp12=${NETIFS[p3]} + rp22=${NETIFS[p4]} + + rp21=${NETIFS[p5]} + h2=${NETIFS[p6]} + + sysctl_save net.ipv4.fib_multipath_hash_seed + + vrf_prepare + + h1_create + h2_create + router1_create + router2_create + + forwarding_enable +} + +cleanup() +{ + pre_cleanup + + forwarding_restore + + nexthops_destroy + router2_destroy + router1_destroy + h2_destroy + h1_destroy + + vrf_cleanup + + sysctl_restore net.ipv4.fib_multipath_hash_seed +} + +ping_ipv4() +{ + ping_test $h1 192.0.2.34 +} + +ping_ipv6() +{ + ping6_test $h1 2001:db8:3::2 +} + +test_mpath_seed_get() +{ + RET=0 + + local i + for ((i = 0; i < 100; i++)); do + local seed_w=$((999331 * i)) + sysctl -qw net.ipv4.fib_multipath_hash_seed=$seed_w + local seed_r=$(sysctl -n net.ipv4.fib_multipath_hash_seed) + ((seed_r == seed_w)) + check_err $? "mpath seed written as $seed_w, but read as $seed_r" + done + + log_test "mpath seed set/get" +} + +nh_stats_snapshot() +{ + local group_id=$1; shift + + ip -j -s -s nexthop show id $group_id | + jq -c '[.[].group_stats | sort_by(.id) | .[].packets]' +} + +get_active_nh() +{ + local s0=$1; shift + local s1=$1; shift + + jq -n --argjson s0 "$s0" --argjson s1 "$s1" -f /dev/stdin <<-"EOF" + [range($s0 | length)] | + map($s1[.] - $s0[.]) | + map(if . > 8 then 1 else 0 end) | + index(1) + EOF +} + +probe_nh() +{ + local group_id=$1; shift + local -a mz=("$@") + + local s0=$(nh_stats_snapshot $group_id) + "${mz[@]}" + local s1=$(nh_stats_snapshot $group_id) + + get_active_nh "$s0" "$s1" +} + +probe_seed() +{ + local group_id=$1; shift + local seed=$1; shift + local -a mz=("$@") + + sysctl -qw net.ipv4.fib_multipath_hash_seed=$seed + probe_nh "$group_id" "${mz[@]}" +} + +test_mpath_seed() +{ + local group_id=$1; shift + local what=$1; shift + local -a mz=("$@") + local ii + + RET=0 + + local -a tally=(0 0 0 0 0 0 0 0 0 0) + for ((ii = 0; ii < 100; ii++)); do + local act=$(probe_seed $group_id $((999331 * ii)) "${mz[@]}") + ((tally[act]++)) + done + + local tally_str="${tally[@]}" + for ((ii = 0; ii < ${#tally[@]}; ii++)); do + ((tally[ii] > 0)) + check_err $? "NH #$ii not hit, tally='$tally_str'" + done + + log_test "mpath seed $what" + sysctl -qw net.ipv4.fib_multipath_hash_seed=0 +} + +test_mpath_seed_ipv4() +{ + test_mpath_seed 1000 IPv4 \ + $MZ $h1 -A 192.0.2.1 -B 192.0.2.34 -q \ + -p 64 -d 0 -c 10 -t udp +} + +test_mpath_seed_ipv6() +{ + test_mpath_seed 2000 IPv6 \ + $MZ -6 $h1 -A 2001:db8:1::1 -B 2001:db8:3::2 -q \ + -p 64 -d 0 -c 10 -t udp +} + +check_mpath_seed_stability() +{ + local seed=$1; shift + local act_0=$1; shift + local act_1=$1; shift + + ((act_0 == act_1)) + check_err $? "seed $seed: active NH moved from $act_0 to $act_1 after seed change" +} + +test_mpath_seed_stability() +{ + local group_id=$1; shift + local what=$1; shift + local -a mz=("$@") + + RET=0 + + local seed_0=0 + local seed_1=3221338814 + local seed_2=3735928559 + + # Initial active NH before touching the seed at all. + local act_ini=$(probe_nh $group_id "${mz[@]}") + + local act_0_0=$(probe_seed $group_id $seed_0 "${mz[@]}") + local act_1_0=$(probe_seed $group_id $seed_1 "${mz[@]}") + local act_2_0=$(probe_seed $group_id $seed_2 "${mz[@]}") + + local act_0_1=$(probe_seed $group_id $seed_0 "${mz[@]}") + local act_1_1=$(probe_seed $group_id $seed_1 "${mz[@]}") + local act_2_1=$(probe_seed $group_id $seed_2 "${mz[@]}") + + check_mpath_seed_stability initial $act_ini $act_0_0 + check_mpath_seed_stability $seed_0 $act_0_0 $act_0_1 + check_mpath_seed_stability $seed_1 $act_1_0 $act_1_1 + check_mpath_seed_stability $seed_2 $act_2_0 $act_2_1 + + log_test "mpath seed stability $what" + sysctl -qw net.ipv4.fib_multipath_hash_seed=0 +} + +test_mpath_seed_stability_ipv4() +{ + test_mpath_seed_stability 1000 IPv4 \ + $MZ $h1 -A 192.0.2.1 -B 192.0.2.34 -q \ + -p 64 -d 0 -c 10 -t udp +} + +test_mpath_seed_stability_ipv6() +{ + test_mpath_seed_stability 2000 IPv6 \ + $MZ -6 $h1 -A 2001:db8:1::1 -B 2001:db8:3::2 -q \ + -p 64 -d 0 -c 10 -t udp +} + +trap cleanup EXIT + +setup_prepare +setup_wait +nexthops_create + +tests_run + +exit $EXIT_STATUS