From patchwork Wed Dec 18 17:15:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 852215 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2078.outbound.protection.outlook.com [40.107.94.78]) (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 612C1198E63; Wed, 18 Dec 2024 17:17:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.78 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734542257; cv=fail; b=SrAbhGPDM8SAAByGwZWIIzZC2JNfArXB+kezAojFXfoNppQn7lmXcf4xO39jg6Pq4q6cAcWeM+bk4nDW60/k6FPtnXyxS/L6gg4o6VtaHJXjjqokO1YuwY58e1ZGOQJITnCQ1oL3xaT+gOEy8bDY/wVSxFrBJsc3ONoguq7WsX8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734542257; c=relaxed/simple; bh=72Tj6F35N+teTQfR6KLHIPnuOkxI2m2/DPmwIz5o2e4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gZXXxMiuCfxq4xOdfKllYcjaKKNuVDinBfGTR8OcR/WbSQmtPPbpQ4q92qwdmNq0kIy2B1jJ48FX5vlV92f93j92t+79rrOv6OvDj0paiqPdQmuiy0z2f7godrwZ7s/yINc9cGaBMhN8Zm671ArC+Nyfl91DNUJqHbWfx1xJeHY= 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=NAwKDPS3; arc=fail smtp.client-ip=40.107.94.78 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="NAwKDPS3" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=J3BXf3iFYNMLhkhc8dRN7Tla5qxdvJxdEnPmzambp21tzzJe4qbnM0TtrCt44rXEw1CCPmZysDlMepRRcUI1WSawdIURFV7IzFcsmhIZWI/z9h2AtuSFWgH65r401r/TPPaFm6yLefygNBGuuYw9xoKp67E63t1aYRttSXl2WUX/BCbeQ4K5mpYsfcg8lWFhAiS+TUltumuIjmZ6kH/sMSwB0qChXZsiBW8XJDspx5hJga8VrUszi7F5loiUas8xbaGh5TziLRs6HnooWudIn/jioZs+sZlZUjOKbcboC4OC3K98UqF6+2pcSvqtzJ++RMg5zpjB+KpwSyC50TSpEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=bkjvYXJjPuGyltjZxXeHun2wjq05wcX06Rjey/K9d3g=; b=jvbh5RXQEeXzj37BcF48BaujdT2JcqPImUWRzF87g3ZEuyzv/Nc5xET2iYAigGccF3/InE4J2lDplmgMHgH1StOU3kPOSTkKJA1jC59GZ6cpdAfMKV1QSyWxJbyQKMso1MXen4ujXNjljpaW+20Vul+/1kmvKSqBkMIloYZXg1tQeGv+UXC5wJXgBDHMQDtE/F/U3sgYIopLKfMdtt/ksq1epsM5IKt9MZ/nwlldEb6uoMsr95sjPN9DrAkvO3xoiPUqWKBrTgn9UCP6pkqQbBsBST8fHEvXsfWVjfXbDb4s4jvO9N/nA1pSBoqR7blP2in9iVa1gCNEBmij8Pvkig== 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=bkjvYXJjPuGyltjZxXeHun2wjq05wcX06Rjey/K9d3g=; b=NAwKDPS3tLL27PAJV3EzJDsNPNmJ6X4LBzfCje7ITV3bMOT9mT9Qk+oGSPlLF2dhk+ON/FPgHn1XnvNOxZb17p0nHQ+bEgbHt0sWRDi6QdrQLuUtDZKGOpxEphNvLD/aUJLvdi1T14dyTU28XMkJECLZaA8rTssneE9duvrtcD3JDE22ZI6IbnJdemCVfAWqjQeQkEgY2QwJMnLhM5vZgSOxXJmTbJtUHVmZj2C2OfOQnurq/5l0EwqAsEQV7Y4dn+T78hwo5KE4qFPZFS58qDRmUuA4ijgLjjukaxNEACykAKD8I94VZYa1qBChu00jMi6gUgTmIBIYHMJ6xqKDhg== Received: from SJ0PR05CA0168.namprd05.prod.outlook.com (2603:10b6:a03:339::23) by DM6PR12MB4299.namprd12.prod.outlook.com (2603:10b6:5:223::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.19; Wed, 18 Dec 2024 17:17:32 +0000 Received: from CO1PEPF000044F6.namprd21.prod.outlook.com (2603:10b6:a03:339:cafe::4b) by SJ0PR05CA0168.outlook.office365.com (2603:10b6:a03:339::23) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8251.20 via Frontend Transport; Wed, 18 Dec 2024 17:17:29 +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 CO1PEPF000044F6.mail.protection.outlook.com (10.167.241.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8293.6 via Frontend Transport; Wed, 18 Dec 2024 17:17:29 +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; Wed, 18 Dec 2024 09:17:09 -0800 Received: from fedora.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; Wed, 18 Dec 2024 09:17:03 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Simon Horman , Roopa Prabhu , "Nikolay Aleksandrov" , , Ido Schimmel , Petr Machata , , Shuah Khan , Subject: [PATCH net-next 3/4] selftests: net: lib: Add a couple autodefer helpers Date: Wed, 18 Dec 2024 18:15:58 +0100 Message-ID: <856d9e01725fdba21b7f6716358f645b19131af2.1734540770.git.petrm@nvidia.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000044F6:EE_|DM6PR12MB4299:EE_ X-MS-Office365-Filtering-Correlation-Id: ada83f6e-4b62-4a51-2954-08dd1f87d9f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: zcLyptPMcDpZd39jxtuV1uerCzV50w4gn7LYS1zWatQKPDrYfTBpsLhVXzneqz7xmOjFE0Ky7Mpcjwz4pg/RVpkdvh3yiFI5SFPnYbjBhvI/O8FcDBFProIUMxkuyFOvAx0GB6C5yzMarM0imDFih4bWqqH/DZQM4HHUwa1coanFme+Bg28oNI3F1cNtGpaExyroPzprFEJ8UnwKZrfDu+WXu6VCsrombZMix+ORLO1k7J3KVSsvZGvtpmvJ7oMO0ks60R8SFCY6KbKvrNSUzTzMiqW6zNc9+jn+GWc17fNNSTaGL9Z5btMe0vo2wshBhfq7bgfyhjqHZ937e1rOobbNS/MWNFbK7ezeOxm9XtktZojHqGiBBYkmvYt8haUsNIB6Po9jtaMMvjJ/nr71SCZq5qLYvOCLUoasoQrKCHKUNkzfO/2SChj+kb87Vt5QgxkBRG0LTd+Ay1XNfj1E05LeDYGqaUx6pOQtdo42eGKhZDn7eolYcRbIb/qkvz2J7A6NQo0W61Ogl7Dvib0tN+PwIVni+9ud6AagTIOC1I9a7I1Fo3X3mVSDdplIa8j5eN53HCgYQO6HrAnQ1WcsGye2cmot3BfKpzUQv+Pi7F5LL/4fwaIpjKLJlr9TSs/0dz78BRk1PIY+gUlnUHDW2rZeq+UuMCIZT16qF9LlCdK2I43Lt6xvxlpZq6OM9VaESC9ppttFM2BZvaPq3Y8zpqm+RPG4YKx2qxEZDSqKr5Nb+4cxyuE8mZpAnsksIYGzTi43GpnnP0Pch3eVOYYGMIKhOh6L1wTGgYmF3ZN8hUwgNE93NLc84SwV9UnVFEuRuhNnRUU7mvkMvic+WZsbHQEHR7wV9EG4bYVTr6qpfUrvwDlrRxzHXF83jCZmqMY4ONLg6hZPlN9xFJ8RFcoKF/QU+Ub09rPjVFIMVobDhpWdmu1dH5nI8lxVk9b01u9wikpTc5VaDcr+mA7mrRMjNv1lOALmY05GOp6ndDuAbsswSXkjcBXnoNJIalonke1iUiwhjFfMgkB3gaEKrkq4q5eJvVh4HCJQy9lNZ1EMHUWtfKN9LpDoE5lEJBRF1mj2NQpDq2iv1zZP7ow1+NRJwR2VucIy1289GFcDTOzPEIJ1PtnZNRj6jV2HyV4b0vERRltmnE57dJX2hmdLWqLbMwWZJcP9IuJL5MyvxNqH3NzEP4rU8uZbbx+WS7TgRUe9VumXbezmtrW+rEgjwTR/FVX54B0ntsiN54dpZNvXkksNSZY8C7T0N4Wp1La2IRVml7+6hiATPflWjnn6ySKhJ3Nx3nAWi2v7PO2JCjnsPQ9vB/7kcr8V8AhDpdrLCcQ9aLloEyEYkSMlgjcv/eehdGzpJXJeQlQdH807HcTV/5javMdcoPkLk9R5EnrpQ0XevVLKoPb/qCP7CMrRYI/qn6Vd1C1EYvZ0rvHZFI5akH/lBqNtYsbL7Z07T4VSPCGXlfLWvIpcdcuYB1gdV11UVJ+loPtq8/EQC0NPBbZ1YYU= 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:(13230040)(82310400026)(36860700013)(376014)(7416014)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2024 17:17:29.2725 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ada83f6e-4b62-4a51-2954-08dd1f87d9f8 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: CO1PEPF000044F6.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4299 Alongside the helper ip_link_set_up(), one to set the link down will be useful as well. Add a helper to determine the link state as well, ip_link_is_up(), and use it to short-circuit any changes if the state is already the desired one. Furthermore, add a helper bridge_vlan_add(). Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel Acked-by: Nikolay Aleksandrov --- CC: Shuah Khan CC: linux-kselftest@vger.kernel.org --- tools/testing/selftests/net/lib.sh | 31 ++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/lib.sh b/tools/testing/selftests/net/lib.sh index 2cd5c743b2d9..0bd9a038a1f0 100644 --- a/tools/testing/selftests/net/lib.sh +++ b/tools/testing/selftests/net/lib.sh @@ -477,12 +477,33 @@ ip_link_set_addr() defer ip link set dev "$name" address "$old_addr" } +ip_link_is_up() +{ + local name=$1; shift + + local state=$(ip -j link show "$name" | + jq -r '(.[].flags[] | select(. == "UP")) // "DOWN"') + [[ $state == "UP" ]] +} + ip_link_set_up() { local name=$1; shift - ip link set dev "$name" up - defer ip link set dev "$name" down + if ! ip_link_is_up "$name"; then + ip link set dev "$name" up + defer ip link set dev "$name" down + fi +} + +ip_link_set_down() +{ + local name=$1; shift + + if ip_link_is_up "$name"; then + ip link set dev "$name" down + defer ip link set dev "$name" up + fi } ip_addr_add() @@ -498,3 +519,9 @@ ip_route_add() ip route add "$@" defer ip route del "$@" } + +bridge_vlan_add() +{ + bridge vlan add "$@" + defer bridge vlan del "$@" +} From patchwork Wed Dec 18 17:15:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 851909 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2059.outbound.protection.outlook.com [40.107.93.59]) (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 E65EE1F892F; Wed, 18 Dec 2024 17:17:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.93.59 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734542263; cv=fail; b=a5vjbMr5WUD+Ui88FwC+YLgtxdfIb+1jdgxgqxyHGXnPMIXmWpMOuOZ8ZMMy9kKFuQV372Mp0E6YoGEVJf3o52Dt9gU9oHh48N5ASADRjlRfV6M45AgkUXEwG/IwP+amGrvX5Qksn3FphuV5QQqeMQuvlV95xc5A0Q2P8NHhTvg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734542263; c=relaxed/simple; bh=Vwp3lUHHvujSoWb4POXPbrUUbEzwqbqwDRKe4J4pOFc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=eGhOcxbq0BcvJmpRBGsJlqH+obO6yrqZzisYkAInYfP5k2Rahx72Oh5oyqqodzJYJ7EaexFCg5YXgPqM9ibY3BZpd3FljvkMzOyH0dMK6U6qbicFWZZ8kGUkKkPuaA/RaN1fsJLBRcdOR4PYYGZm/E4jCb/xJQx66sowkgKXshc= 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=oaxmFbcN; arc=fail smtp.client-ip=40.107.93.59 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="oaxmFbcN" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LvD4TINiqIkhdMx/LvULLEap7DldBkqa/Vv2rLEKCobdXoOWCH1FEiAiMSbXU7KtEfldSvXnb513MBvIFwU8QMEQJALxVsjly2Ftr0F6nNrm3/4vE4C54QORt3pr9N1OpQBNapm/VCOkciASJ6bEZ5/dTqA5DPwBBgsOlMhyoncVxKJqhAswzx7701KIvQ/k63DKAOHp+0G/KUVVo2CfAywodTOEeNLwIwfSTuKqnbj83XA0UD94q6b+VZMenzk7zrnCmCbdiZFLwCly6OIHPZBNoplDL1S7AhuMTmhglCDaPq531g++8M1STkCvW90QWUYb3MQv+ohqO7SQljjziQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=nH+pZ5P++boFENwS3s1empsfhYQbMoop11/VBUzQeh4=; b=N/LekQaqrsErPDuYndopAv4MaqEn+DunUIYin9hHjL4h2NAjjcTn8/8IReBWmoU0AlpfLJmOgo0VJoXGdi23JuyFC6AR+Ho1CXmxby4E41sVD6Owcnq4DViQaGUa5+DsqgOSLvb58BQHR5rolojDdRPjzT7xcWXNf9zqPH3ovi7K0hHrxhS7yikUD/W+fYslTrjhBZjTHjJKFDVHj5aiIjLCIyxcG80m34BPwDozqGOJUoENc8q93OSeVloSkwmrbklUsB2Z++gIjAL3yXDGe3KB+qN4QavoKQACwUc6a5aPyL9asU4zraqUo6lZpfoCaWPh0RLrTSNjijvx6kBSaQ== 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=nH+pZ5P++boFENwS3s1empsfhYQbMoop11/VBUzQeh4=; b=oaxmFbcNBpDCHTAL75kdi21arvtxZxTI4KYvtL1mSUxNQ2X7tNbJcIUB/Csg5MorocgC/DPz7xYchnrZJBR67N0M7BTMk4MxUIdkKPBl2yhY/uJ9JEMI5pUYilJ0mez237AZbiGinLDyJKSlIimWkTWTkSILoOhl65vCZH77C5KN+0lo32wDpmW/9+q4JgskNwl8+U6vflF7HiNp8Ny65lkFFilTClNtl5v2kHnzZ8Au4Hj8OirvYnURRsssoIgd9BcF4EKCr41zz9jzUYaDX33uCNrhSaOOdfft/ZFjGcwNjmCnrnYj7MCIJdbpqoq+lTcpoUzW6qXNkD/3PokrFQ== Received: from BL1PR13CA0013.namprd13.prod.outlook.com (2603:10b6:208:256::18) by IA0PR12MB8976.namprd12.prod.outlook.com (2603:10b6:208:485::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8272.13; Wed, 18 Dec 2024 17:17:37 +0000 Received: from BN3PEPF0000B373.namprd21.prod.outlook.com (2603:10b6:208:256:cafe::51) by BL1PR13CA0013.outlook.office365.com (2603:10b6:208:256::18) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8272.10 via Frontend Transport; Wed, 18 Dec 2024 17:17:37 +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 BN3PEPF0000B373.mail.protection.outlook.com (10.167.243.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8293.6 via Frontend Transport; Wed, 18 Dec 2024 17:17:36 +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; Wed, 18 Dec 2024 09:17:16 -0800 Received: from fedora.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; Wed, 18 Dec 2024 09:17:09 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Simon Horman , Roopa Prabhu , "Nikolay Aleksandrov" , , Ido Schimmel , Petr Machata , , Shuah Khan , Subject: [PATCH net-next 4/4] selftests: net: Add a VLAN bridge binding selftest Date: Wed, 18 Dec 2024 18:15:59 +0100 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN3PEPF0000B373:EE_|IA0PR12MB8976:EE_ X-MS-Office365-Filtering-Correlation-Id: f4803180-343c-494d-102f-08dd1f87de8a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|7416014|376014|1800799024; X-Microsoft-Antispam-Message-Info: +jb7IjCMjKm96QISqDLjrhTkznIW202x+vbnKIqY0i3N/xJFfcYw59v6EP8jGM9Mq9ea1jVyYI4T2YReOCpN3e1pWiVhyklfSzb44xgXhwbsryZUnvoqLNrMYvNnzlmnoJva2G5cKvUd9D9zs+ORx1jwgEP1WNXEhL6c+dw5OBS4fNxg/OmJ+bQ4XB4Bkrzjj2JiB5VFe23oO/eLTrbgJ24XRhZzcyuoZRPmnzY+EixDfsrBjjzJlzTE15cojNURZ7379nGUIPhARjB25Er6QoIzDYFOTnGcyUMhDlswofJ6673qVhsfED0rJqKAyOYsc89WFVzN9b+q74f1tx2fWMBw4bIHVwQBagBNf9aU66BMUm1+s77Pgk4o9Dfl5xcI9ineH14UgabNJeMnyM4RjZ9F7QxAseSqRDQxB1+4juu+hEQgjuTMk6s+7gEmZmK3Mto6+qpFXQUEQIdHL7Pc3waBnknxewjKxCAkWRaUcsILUCgsQA3l4CP4oPqGOEBTRkEdI+1dJzi/LNUYygfQoLcnZV1fhjxiwmKEs7skhrrvMINK9Ef+2z2+nYJOZDUqdn2X2L/esJrtFBJbWSInEDuU4CTwh7PGCu6INC8ZVimo1Z1gNg8sm07t0cGsn6uRwtCyzld9Bc4Lc8zLIl3vDqQ3A4N6ScWAF9mY6zIPK/S6h34embyAgqb3h9sAdA7P8TdzYxNOoceupGzthx+oDaCD2d44QKNcL5HTlam/y8nu+UNGdYiF6Xl2ja9OtEKC24VaXfx2UMTVWqmaGwgwzZ8HEozOerAnNdMABlGWNCmixxaAHo+W31siVOgKiido/cWZlFiJ5E7TLZi5PWykrgUgoT/Z1VLg/RgSBy6EmuQXWSMyAApaYbbEE/ML97iYY5Tfa4um0O93IbAdEMZo8phDJdH2TcZsVV0w56RmJ/qSmKZIdHsx/ZdhJqo3JWYgMaTdeXBj4RZRfm5/6Q9li4+HGVqiDYJ2MfAdOObTr/Kpj7wn0jvb11ZEcRw6a4ysjBdt0oqhnttEggwSN7izE8MTT+9Ra3aFH/eG5gEwIxB7N0HN8mkSD+cpIm39l0Z1lD18k8mHQB03p+mRlQpZOj6OozK4FtaM04je4WXJh6nuFBzirZ2mM8PU6/PVYdk4ppdl1k55RpqkzEclNS/9/iR7KrT5ISHxJ0k8d8Ty3i4LOVUBzi1VZ3ZsUBlF9ubd9goAz3SMhs0RFj6mX1gJ6rjS2f/SRQe2rWTv/VV0KVeROpynwEI4XsKeZqdxE6YhBAb5Sx8RJ/AgcZK5ZzYXOY60Qq5vR4HsdzTky9/+WrLx/WFcESeEGLsI9Snpm8TwoQIRCUDI8vwYDxOxI5qRk7Vw0RLNqAyWohJhg0sZmyz8lmhRDLYcPXKcUWz1IgPYl5vIOgHQbxI+exEMUq8Eju5a1YdjnbD3s03jiQak9KHlXPOREjSosL7gaq9nzQoaOAg22C+Mb+hHNCELgr/GZAHrCOC3A9fLjdAPOHz3/Ps= 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:(13230040)(82310400026)(36860700013)(7416014)(376014)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Dec 2024 17:17:36.8927 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f4803180-343c-494d-102f-08dd1f87de8a 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: BN3PEPF0000B373.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8976 Add a test that exercises bridge binding. Signed-off-by: Petr Machata Reviewed-by: Ido Schimmel --- CC: Shuah Khan CC: linux-kselftest@vger.kernel.org --- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/vlan_bridge_binding.sh | 256 ++++++++++++++++++ 2 files changed, 257 insertions(+) create mode 100755 tools/testing/selftests/net/vlan_bridge_binding.sh diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index f09bd96cc978..73ee88d6b043 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -96,6 +96,7 @@ TEST_PROGS += test_bridge_backup_port.sh TEST_PROGS += fdb_flush.sh fdb_notify.sh TEST_PROGS += fq_band_pktlimit.sh TEST_PROGS += vlan_hw_filter.sh +TEST_PROGS += vlan_bridge_binding.sh TEST_PROGS += bpf_offload.py TEST_PROGS += ipv6_route_update_soft_lockup.sh TEST_PROGS += busy_poll_test.sh diff --git a/tools/testing/selftests/net/vlan_bridge_binding.sh b/tools/testing/selftests/net/vlan_bridge_binding.sh new file mode 100755 index 000000000000..e7cb8c678bde --- /dev/null +++ b/tools/testing/selftests/net/vlan_bridge_binding.sh @@ -0,0 +1,256 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +source lib.sh + +ALL_TESTS=" + test_binding_on + test_binding_off + test_binding_toggle_on + test_binding_toggle_off + test_binding_toggle_on_when_upper_down + test_binding_toggle_off_when_upper_down + test_binding_toggle_on_when_lower_down + test_binding_toggle_off_when_lower_down +" + +setup_prepare() +{ + local port + + ip_link_add br up type bridge vlan_filtering 1 + + for port in d1 d2 d3; do + ip_link_add $port type veth peer name r$port + ip_link_set_up $port + ip_link_set_up r$port + ip_link_set_master $port br + done + + bridge_vlan_add vid 11 dev br self + bridge_vlan_add vid 11 dev d1 master + + bridge_vlan_add vid 12 dev br self + bridge_vlan_add vid 12 dev d2 master + + bridge_vlan_add vid 13 dev br self + bridge_vlan_add vid 13 dev d1 master + bridge_vlan_add vid 13 dev d2 master + + bridge_vlan_add vid 14 dev br self + bridge_vlan_add vid 14 dev d1 master + bridge_vlan_add vid 14 dev d2 master + bridge_vlan_add vid 14 dev d3 master +} + +operstate_is() +{ + local dev=$1; shift + local expect=$1; shift + + local operstate=$(ip -j link show $dev | jq -r .[].operstate) + if [[ $operstate == UP ]]; then + operstate=1 + elif [[ $operstate == DOWN || $operstate == LOWERLAYERDOWN ]]; then + operstate=0 + fi + echo -n $operstate + [[ $operstate == $expect ]] +} + +check_operstate() +{ + local dev=$1; shift + local expect=$1; shift + local operstate + + operstate=$(busywait 1000 \ + operstate_is "$dev" "$expect") + check_err $? "Got operstate of $operstate, expected $expect" +} + +add_one_vlan() +{ + local link=$1; shift + local id=$1; shift + + ip_link_add $link.$id link $link type vlan id $id "$@" +} + +add_vlans() +{ + add_one_vlan br 11 "$@" + add_one_vlan br 12 "$@" + add_one_vlan br 13 "$@" + add_one_vlan br 14 "$@" +} + +set_vlans() +{ + ip link set dev br.11 "$@" + ip link set dev br.12 "$@" + ip link set dev br.13 "$@" + ip link set dev br.14 "$@" +} + +down_netdevs() +{ + local dev + + for dev in "$@"; do + ip_link_set_down $dev + done +} + +check_operstates() +{ + local opst_11=$1; shift + local opst_12=$1; shift + local opst_13=$1; shift + local opst_14=$1; shift + + check_operstate br.11 $opst_11 + check_operstate br.12 $opst_12 + check_operstate br.13 $opst_13 + check_operstate br.14 $opst_14 +} + +do_test_binding() +{ + local inject=$1; shift + local what=$1; shift + local opsts_d1=$1; shift + local opsts_d2=$1; shift + local opsts_d12=$1; shift + local opsts_d123=$1; shift + + RET=0 + + defer_scope_push + down_netdevs d1 + $inject + check_operstates $opsts_d1 + defer_scope_pop + + defer_scope_push + down_netdevs d2 + $inject + check_operstates $opsts_d2 + defer_scope_pop + + defer_scope_push + down_netdevs d1 d2 + $inject + check_operstates $opsts_d12 + defer_scope_pop + + defer_scope_push + down_netdevs d1 d2 d3 + $inject + check_operstates $opsts_d123 + defer_scope_pop + + log_test "Test bridge_binding $what" +} + +do_test_binding_on() +{ + local inject=$1; shift + local what=$1; shift + + do_test_binding "$inject" "$what" \ + "0 1 1 1" \ + "1 0 1 1" \ + "0 0 0 1" \ + "0 0 0 0" +} + +do_test_binding_off() +{ + local inject=$1; shift + local what=$1; shift + + do_test_binding "$inject" "$what" \ + "1 1 1 1" \ + "1 1 1 1" \ + "1 1 1 1" \ + "0 0 0 0" +} + +test_binding_on() +{ + add_vlans bridge_binding on + set_vlans up + do_test_binding_on : "on" +} + +test_binding_off() +{ + add_vlans bridge_binding off + set_vlans up + do_test_binding_off : "off" +} + +test_binding_toggle_on() +{ + add_vlans bridge_binding off + set_vlans up + set_vlans type vlan bridge_binding on + do_test_binding_on : "off->on" +} + +test_binding_toggle_off() +{ + add_vlans bridge_binding on + set_vlans up + set_vlans type vlan bridge_binding off + do_test_binding_off : "on->off" +} + +dfr_set_binding_on() +{ + set_vlans type vlan bridge_binding on + defer set_vlans type vlan bridge_binding off +} + +dfr_set_binding_off() +{ + set_vlans type vlan bridge_binding off + defer set_vlans type vlan bridge_binding on +} + +test_binding_toggle_on_when_lower_down() +{ + add_vlans bridge_binding off + set_vlans up + do_test_binding_on dfr_set_binding_on "off->on when lower down" +} + +test_binding_toggle_off_when_lower_down() +{ + add_vlans bridge_binding on + set_vlans up + do_test_binding_off dfr_set_binding_off "on->off when lower down" +} + +test_binding_toggle_on_when_upper_down() +{ + add_vlans bridge_binding off + set_vlans type vlan bridge_binding on + set_vlans up + do_test_binding_on : "off->on when upper down" +} + +test_binding_toggle_off_when_upper_down() +{ + add_vlans bridge_binding on + set_vlans type vlan bridge_binding off + set_vlans up + do_test_binding_off : "on->off when upper down" +} + +trap defer_scopes_cleanup EXIT +setup_prepare +tests_run + +exit $EXIT_STATUS