From patchwork Wed Nov 22 15:23:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13465031 X-Patchwork-Delegate: dsahern@gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="HH+ei9NT" Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 107A61B8 for ; Wed, 22 Nov 2023 07:24:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NTOx1PAMyydcNzVcboXwnflidP8Mk1LJEHzHGFhzUCg/sY+ZUqg96cR9vyQC/whxzcro6ve7opwe8OYuavImqiTUah0Ybod8vEygF608l45R7u+1Dq6KKl0y+TEo1exGCU/SiGj+SwLc5sJL/QqXo+6Z0uOPmvlci8CYqu7/zjaKHtTP34H8LzTm/q+jiDw3XxdFZe+7Xi1iAak41AraZo+LIZGFLI+oB5G4zvLzXUBuOx6+9uQok8v7k4LD+oPUkfdlxLxgQqFlpZy4wJrf0ADFH6PmP5OXJDQUu/vTkxmtvshCRzOPn3d/hwaIMKaL6TyrounxlGXL22swMJkbFA== 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=NNJmNDBiPHI/wQdUFK82KDN3a6aJLtxdQvDCsuleVLs=; b=CO27oDriF95UjiY6I/484zFZozvtn8mwcMwQCuwBBvpbM9jVbPERCYGUxeXY273svpO+Wq+1m2K6lJ1kZZkyf5ZPMe+7KV6HGwDP45PwwbP+sqXODNaDd2yv9m4sbXFQWhyh7g2jAtCaMoGy7T5Z4o5PHysqsDsnc1OhY7IqaEWsm5mpJl5I4WCTJsKcm7gWsZIrk2uv3l4oQ1l1mKn0+KwbQPsbqrEb6Fq4LtsGBSVzgCOWENmOfkpwkht0afwE9x+Qb4DZTIKS1qghjT/IOOSZcMau5V0ElKhhhZWTg6TM7gKQ+2TvlYF9OjrwgY1kbGPX9OXq/qYQXWfQWkES5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=gmail.com 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=NNJmNDBiPHI/wQdUFK82KDN3a6aJLtxdQvDCsuleVLs=; b=HH+ei9NTMOM+HNzG9Uk8cP426Atish+VOHo3CREsKoTQlp06FJfOotknPEEeghgRbHgp+pHilv8COkOfugdBdQKQYim9PHqipEnAn3jgCP5Bf0iq7ErNU4UfSxWVAFZrNAM2TXm5ueqN7we9TxztJayjVlbwcd/ZoKCxzkHMO8bnuYmEa6JCqFb2O3+Ji6+ZIw36Hm3dmWxKwDBdh/zOvAY30RSboT6jcJ+H2nMWOK/GbX3NTX/X5qO3vJcSFhXbHg5qu4XDiYwPIBxIQ8WypwSUluDyIPbbYT31gSbGK/Xk/Qql8lMwZtqzSaODmTjkdYxZufCRJuQ4DOW45n0eGA== Received: from BN8PR03CA0020.namprd03.prod.outlook.com (2603:10b6:408:94::33) by DM6PR12MB4910.namprd12.prod.outlook.com (2603:10b6:5:1bb::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18; Wed, 22 Nov 2023 15:24:17 +0000 Received: from SN1PEPF00026369.namprd02.prod.outlook.com (2603:10b6:408:94:cafe::7f) by BN8PR03CA0020.outlook.office365.com (2603:10b6:408:94::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.28 via Frontend Transport; Wed, 22 Nov 2023 15:24:16 +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 SN1PEPF00026369.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.12 via Frontend Transport; Wed, 22 Nov 2023 15:24:16 +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.986.41; Wed, 22 Nov 2023 07:24:03 -0800 Received: from localhost.localdomain (10.126.230.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.986.41; Wed, 22 Nov 2023 07:24:01 -0800 From: Petr Machata To: David Ahern , Stephen Hemminger , CC: Patrisious Haddad , Petr Machata , Matteo Croce Subject: [PATCH iproute2-next v2 1/5] lib: utils: Switch matches() to returning int again Date: Wed, 22 Nov 2023 16:23:28 +0100 Message-ID: <7f3153037fd56a99b25cca45de7a4b8000a41190.1700666420.git.petrm@nvidia.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00026369:EE_|DM6PR12MB4910:EE_ X-MS-Office365-Filtering-Correlation-Id: d2074828-a035-42d3-9831-08dbeb6f1729 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Dl8ojIrbJ6ETQGgtOk1ggmJ60enVAa8rwXOcbTVgBo/XW9X4AcAgwcvvXuPFhCXtobCtj/DyXbarBRl+Vi5nmMLtgIqENU2fnfS8I6QIIGQLbQanHfAllJig6D/2Adakh7FnC7P34nzJCdlBq96ozvW0SNO9bv/xcqgS3qYH07KBO/AE7xQPcyCZ8DanyK5VXVGCFj/nZwRm/n8wd/fYY/29sbgcGBAdk/6TMPk7Seu0iqejA2KOxk2/S/P61Lnp4SEt5EmTxzdC5QH+oUHKQa/9zcye8IqYBRt2QNSEMIaq3LcaohvZZzoSjaunjy5gLQ+cIJzHdJoyQzYjKEUjLnNtmrsJx8T9lLaXIKP5tdzodkulp/bmZzs5IWMN3Z7VrwL86NFGNrsymVylfr15xbihJXhgkBbbzac3ukGANS2VP891OBIRTOBaj1Kzeqinnc+wB+8n5wexnUDTaB8HJ3emnvIImkaWpjiuxEBy+uu2Rdrq0N1j4EJRSLEUySzOrCdyhv0mv3RxHNrZxTHwRNRsNETVIOeGr24EELj1sJALP0NuknZ0BQOlmWTIzAGQ0KJNlxEdsCfsdOibKcIDSsGrmPb7t6eJl1c3Z31BsKxNcE5BgtJGrrIsGhHBYpKTBRiJ42+jOp7iM56gveUtpjHvtdGgviVxaEdQJUjN3pGwtkvFaSbTjTqgL7ejs/KD/imJiAloqulszxXS5oYzOZ0xnb89Ba8wRhJGM8JVo86ysve4MjlCW22uj4AGTPpY 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)(4636009)(136003)(396003)(39860400002)(346002)(376002)(230922051799003)(1800799012)(82310400011)(186009)(64100799003)(451199024)(46966006)(40470700004)(36840700001)(8676002)(4326008)(356005)(8936002)(7636003)(5660300002)(2616005)(478600001)(83380400001)(40480700001)(82740400003)(6666004)(2906002)(54906003)(110136005)(70206006)(70586007)(316002)(41300700001)(36860700001)(40460700003)(336012)(426003)(26005)(36756003)(47076005)(86362001)(16526019);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 15:24:16.4149 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d2074828-a035-42d3-9831-08dbeb6f1729 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: SN1PEPF00026369.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4910 X-Patchwork-Delegate: dsahern@gmail.com Since commit 1f420318bda3 ("utils: don't match empty strings as prefixes") the function has pretended to return a boolean. But every user expects it to return zero on success and a non-zero value on failure, like strcmp(). Even the function itself actually returns "true" to mean "no match". This only makes sense if one considers a boolean to be a one-bit unsigned integer with no inherent meaning, which I do not think is reasonable. Switch the prototype back to int, and return 1 instead of true. Cc: Matteo Croce Signed-off-by: Petr Machata --- include/utils.h | 2 +- lib/utils.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/utils.h b/include/utils.h index f26ed822..add55bfa 100644 --- a/include/utils.h +++ b/include/utils.h @@ -198,7 +198,7 @@ int check_ifname(const char *); int check_altifname(const char *name); int get_ifname(char *, const char *); const char *get_ifname_rta(int ifindex, const struct rtattr *rta); -bool matches(const char *prefix, const char *string); +int matches(const char *prefix, const char *string); int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits); int inet_addr_match_rta(const inet_prefix *m, const struct rtattr *rta); diff --git a/lib/utils.c b/lib/utils.c index 99ba7a23..1fc42a9a 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -873,18 +873,18 @@ const char *get_ifname_rta(int ifindex, const struct rtattr *rta) return name; } -/* Returns false if 'prefix' is a not empty prefix of 'string'. +/* Returns 0 if 'prefix' is a not empty prefix of 'string', != 0 otherwise. */ -bool matches(const char *prefix, const char *string) +int matches(const char *prefix, const char *string) { if (!*prefix) - return true; + return 1; while (*string && *prefix == *string) { prefix++; string++; } - return !!*prefix; + return *prefix; } int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits) From patchwork Wed Nov 22 15:23:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13465032 X-Patchwork-Delegate: dsahern@gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="s5bt9FiZ" Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2058.outbound.protection.outlook.com [40.107.95.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A68C18D for ; Wed, 22 Nov 2023 07:24:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ipyXvCVw45aOC2iU5jgxwwlfeDjUMpkFpivm7DJoXqNPgsLBza/kyEDULe7/AzmQDjnyZM4dHjawI+tJ24oL9AQfpbu0Mi3rmfcr6KE7MB+4KDCGyflY7j2hdI3fOAncn46HJpxs96E80K8UWjs13Nvw5SQAhOJPHAmurKtTZZ/izOTmbt6yegm5jndjtSdq2YdXQNkVN40SGbjv2WJSxtgW0oxOiVkqegRSGD4aGcFly4+ZjEy0Y5/hIg6HAzOAlla7PeosdQODZQJDcDe2lIup61fHI6/1zLChXv5sv0NCP9U7dEJo4Qmdl83TzDv/8BCsfQivyDH2ikAjjasUSw== 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=yI7/j2jtaySb19OSdFOuKYYrINuIIdlypMpFhTKQlxI=; b=e8Wj+tp/VR6PTKk11UMhLLwNEfNDIoR6D0rqgFULXn+/xGPgTsphxCrry91WKtcPyoMggxf9TAZcrfMQbwFdcAvqy+iA0MPPH2m+756SE8Zg1tnh+kpfKodDCvk4pPefj8OSnwy6pntWPufCNYN4MgY7s/+zFGc6IocBm4BYKambWw63i/SQeSz/OPKoMjK4bB9D0PZzURvJzhcNJ7uIsWhFOLBY10wzYqN8RCzmlpgV8Z+ePPvHk5AZP6x/yXEUfWe1BfhKp6pccPfmLPQVQ+WNamcf5IXdWk1kXT9YNl45RvYQCRe8G8A/8Un32YOKQSwNntFxmu/908xv3K626Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=gmail.com 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=yI7/j2jtaySb19OSdFOuKYYrINuIIdlypMpFhTKQlxI=; b=s5bt9FiZLP/uYkAUf1yGdnP+KGbdzlN7Mk7q6Adnb475a9B2JE+JBzH40I7xhL633NHDa1EucGjIZ2HjEC4/shLzlmBZeIBi3vXkjgR6klOFI2bWjG2QklJuHhuB7jOHSi8O7BCRc3ngDddBLgyWzEhCtnS/g+y46s7EEE8WMXOrmdWtSE6JMbbNfaFoV6ijYlYmRZuwXYAUQG/bPGh0YAbVVJVrP1gL5MWb6sdUlSSI7fe5FSCY3LnMKotQPl3SniIHLKE424Gn2q9m5weeO3mvMeOtREOjKKRzzhV1VNA5bMrMJg8rgantdYK5GBo97SE0sOLfPsIvdWPR3yHz5w== Received: from DM6PR02CA0113.namprd02.prod.outlook.com (2603:10b6:5:1b4::15) by SA1PR12MB7200.namprd12.prod.outlook.com (2603:10b6:806:2bb::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.26; Wed, 22 Nov 2023 15:24:18 +0000 Received: from DS1PEPF00017096.namprd05.prod.outlook.com (2603:10b6:5:1b4:cafe::3c) by DM6PR02CA0113.outlook.office365.com (2603:10b6:5:1b4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18 via Frontend Transport; Wed, 22 Nov 2023 15:24:18 +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 DS1PEPF00017096.mail.protection.outlook.com (10.167.18.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.12 via Frontend Transport; Wed, 22 Nov 2023 15:24:18 +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.986.41; Wed, 22 Nov 2023 07:24:05 -0800 Received: from localhost.localdomain (10.126.230.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.986.41; Wed, 22 Nov 2023 07:24:03 -0800 From: Petr Machata To: David Ahern , Stephen Hemminger , CC: Patrisious Haddad , Petr Machata Subject: [PATCH iproute2-next v2 2/5] lib: utils: Generalize parse_one_of() Date: Wed, 22 Nov 2023 16:23:29 +0100 Message-ID: <901baed98bf9e9fe28611f3e473f22ef7d186d94.1700666420.git.petrm@nvidia.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017096:EE_|SA1PR12MB7200:EE_ X-MS-Office365-Filtering-Correlation-Id: a74cf85b-ccc8-4dbe-8cac-08dbeb6f188e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IZ94Awu0OMhlZgGUebnOKd/A+IaPWj8JSeTYobyPflxzjznrQUGFIaoqmdXu6p7qXxX9HCvNXU+gWWGmMH5KwN6M7tnTeOhcPYqhcIZe1aCPkxD60f+6HA5JSm6/wI6E8Fec4zzvXHSyjwS13PaqRFPm3IgToBL4IVTOeT0wXiKLmIhtGTyMUg7Dehv6AMzWABbHMrEyt3muxd5/iu+b5ak9a4H75esjKG825z3hm8dmzB9Tc9pduKPwsk+He+giWVgUgzgK/RzEhwrv9QHQDp/iVOVN+XlHiDx0UQn9sC+HTDhyxgUyDtKlYicW4fL2vGzEvVUlvwfWML2NZL7xqrUe9Ey8RWn/9wH7GZN2Vu4drAwRsvRAFw53DU12/n1dZkS7hXOl6PKdDEGmNPLe7+EJ0AEsGAY7Gp3Z6rlV0P9pRe3iOWwvHGt9INUka/4wkXwz0IUcLBwJ7I1FAPGTrBTv8El8Ln0jtHd++9vCEwLIujDNe5iH7XYzBPgljUTDkF22rI3LBnnz1OH69RYRrjqMFFrjfS9EJVNktlnvF5dXzzB2+32AXRk8DacDcuMCQY8dpPNGCiztwCgkoqoL/IRCz+Z+kUkY5FULixfBABeUjGtLZvNiVILFsi8zPnRgh1mEN8oe9vDYbVazRsJq2kBpkZoLu72eNSrxB4elxFwNBGpZ0LZtlY/4zR1rpVKz2okD3i4VxckQwwP45ttgdbyRIMhzyfvcHNKYOY3qD1E= 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)(4636009)(396003)(39860400002)(346002)(136003)(376002)(230922051799003)(82310400011)(451199024)(1800799012)(64100799003)(186009)(40470700004)(46966006)(36840700001)(41300700001)(36756003)(5660300002)(86362001)(40460700003)(2906002)(47076005)(7636003)(356005)(40480700001)(107886003)(16526019)(2616005)(6666004)(426003)(478600001)(83380400001)(336012)(82740400003)(4326008)(8676002)(316002)(8936002)(26005)(70586007)(36860700001)(110136005)(54906003)(70206006);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 15:24:18.7387 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a74cf85b-ccc8-4dbe-8cac-08dbeb6f188e 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: DS1PEPF00017096.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7200 X-Patchwork-Delegate: dsahern@gmail.com The following patch will change the way parse_one_of() and parse_on_off() parse the strings they are given. To prepare for this change, extract from parse_one_of() the functional core, which express in terms of a configurable matcher, a pointer to a function that does the string comparison. Then rewrite parse_one_of() and parse_on_off() as wrappers that just pass matches() as the matcher, thereby maintaining the same behavior as they currently have. Signed-off-by: Petr Machata --- lib/utils.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/utils.c b/lib/utils.c index 1fc42a9a..5c91aaa9 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1729,13 +1729,15 @@ int do_batch(const char *name, bool force, return ret; } -int parse_one_of(const char *msg, const char *realval, const char * const *list, - size_t len, int *p_err) +static int +__parse_one_of(const char *msg, const char *realval, + const char * const *list, size_t len, int *p_err, + int (*matcher)(const char *, const char *)) { int i; for (i = 0; i < len; i++) { - if (list[i] && matches(realval, list[i]) == 0) { + if (list[i] && matcher(realval, list[i]) == 0) { *p_err = 0; return i; } @@ -1750,11 +1752,18 @@ int parse_one_of(const char *msg, const char *realval, const char * const *list, return 0; } +int parse_one_of(const char *msg, const char *realval, const char * const *list, + size_t len, int *p_err) +{ + return __parse_one_of(msg, realval, list, len, p_err, matches); +} + bool parse_on_off(const char *msg, const char *realval, int *p_err) { static const char * const values_on_off[] = { "off", "on" }; - return parse_one_of(msg, realval, values_on_off, ARRAY_SIZE(values_on_off), p_err); + return __parse_one_of(msg, realval, values_on_off, + ARRAY_SIZE(values_on_off), p_err, matches); } int parse_mapping_gen(int *argcp, char ***argvp, From patchwork Wed Nov 22 15:23:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13465033 X-Patchwork-Delegate: dsahern@gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="BJENf2Fp" Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2084.outbound.protection.outlook.com [40.107.96.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 127AAE7 for ; Wed, 22 Nov 2023 07:24:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nOi8fyvkLEm9nkpFRXROODPvHmv9zIB/kYf2Iq49JMlsRc6kuDQYltPq+OlpFA3VglrJpJK/M4f34kRbkA1i/U27EDoZt888vPtzzpIOwVRic+xwV4f+VHiUUeAptLgIqZ36Y23l+3rxwWlF2bwgu2v+PcrNiKqxfrZr4QmRjEthZ/tVrA8sRO706a3Fg/u0fndI36GbPsjtji9cUXlpvLYmaSS3njIcFqSEMQn2sz0hmrxpA+NRxQBLDPzb+TyVhUsNwXTkHK06UPCu2sQEBh4W/315fbwcTo0ehJiKgP4ZqXHe45+YtJ2BsUyb8oPAvXykNBZ7nhy2l80a0VqinQ== 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=t/8s6LIYYnB/6r/eNx0bHu9ugMG44wzWBwHpNCvyCgY=; b=U85P4InBIqwSiPNIOYbA6ldu88QYDFMjOMaH01q6afPZ88Hn/c5h5M+9wRyW3KuZ1Qv1laSltwOSVO4WZrJ63Rnt6Wg0LQUcAOEmsApttSuy18GjP9gphFc180iqwJIx+aVnAvunQsG1bvBIGjbIJvlZ58GseS8tFffoT79eJoZef7DZkTWV/IcWcMqTYtgBVlpP/RD2NdHEmQ8/I81Wibxlv25ClivLNlEw2nChSYx5zKPcfn+jdhTfMZvFu9bfvRgrlwnmJ454mDL3yFsjEvRp+PtF33GD7FakLcV/VnocYHC4gNn5GnC6oOpH0dgixLYvxantwzjRifHPKy87vA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=gmail.com 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=t/8s6LIYYnB/6r/eNx0bHu9ugMG44wzWBwHpNCvyCgY=; b=BJENf2Fp/kOgnl82b8zhaArghnwXFTwkMHsZNLWx+GkRI1Yw4Sl6N+I2a9pBDXWF79Mpsg6wARQbcgLTYILarAKqbjkUDfrnJf0AZD5ihJaYi0bJjzphs9hgpX/MLJIEQ13wF37xU3CDrMvF5CoeVOzBSf9Pg684+7YNsI+zy4J2edzj9ar2b3l7UdKbBXOPO4Pd+xWJqVmKY2jJliDocf+o3se/KmQV1hh25a+b2Jrz3WLKHJgKWAoroKihe4C2K3tpoOXPwi0kvOexTm2mSvzo9kvU9MUXAF3UV1yAiCmNv/zlg2QomDXj85aEMIDlzZLt6C01rnbwFB10parcBg== Received: from DM6PR02CA0111.namprd02.prod.outlook.com (2603:10b6:5:1b4::13) by PH8PR12MB7133.namprd12.prod.outlook.com (2603:10b6:510:22e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.27; Wed, 22 Nov 2023 15:24:20 +0000 Received: from DS1PEPF00017096.namprd05.prod.outlook.com (2603:10b6:5:1b4:cafe::c4) by DM6PR02CA0111.outlook.office365.com (2603:10b6:5:1b4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.20 via Frontend Transport; Wed, 22 Nov 2023 15:24:19 +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 DS1PEPF00017096.mail.protection.outlook.com (10.167.18.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.12 via Frontend Transport; Wed, 22 Nov 2023 15:24:19 +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.986.41; Wed, 22 Nov 2023 07:24:07 -0800 Received: from localhost.localdomain (10.126.230.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.986.41; Wed, 22 Nov 2023 07:24:05 -0800 From: Petr Machata To: David Ahern , Stephen Hemminger , CC: Patrisious Haddad , Petr Machata Subject: [PATCH iproute2-next v2 3/5] lib: utils: Convert parse_on_off() to strcmp() Date: Wed, 22 Nov 2023 16:23:30 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017096:EE_|PH8PR12MB7133:EE_ X-MS-Office365-Filtering-Correlation-Id: cc4a3414-e646-459f-5e5a-08dbeb6f1922 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Am7+z6wanZ/nF5K0n27dz3lvtaS8OoOBZkwTxAI6LK8HcQp4t/A4FCqVWtsJhQSKIO3AEK4DnUWjwlOin9jRcadRzztorUSt4C0XvAlACQoNbE/PSooIvHp/oaiEJS+j4VqTVlD6Tm5mzJmXCkDAIian3BwhLKPHz6vgYg1yt634G+WXRWwBCbcBuQMWpvSGR9Ps4xRrQWhPsiK08lENHQ5SjDpRqCm9USIJC27J+QS+5Xyf/nw4n8pJDVrA7zfJbc95Xh5Lx8OfrBufKKJDWXaR/+xOErvtAk/W569fNCJnjQEQ5e6U5P1xBXrqTdJJDFaDY9xXslLPPNl8lMNV4U7GmH5/J5HppFA8xlvmHlcKfvYmWAABZjqa5INYIOO3N9PIhR5XT6HFwMI+H1LTr8E5XuLZRru7F/ISgteMBwOXnvcBKTAHgkMHRggVhA49WkUjkn2ryrqp7kqPRodLSuUbsLXiUReUW/1aP+uuDIze8BGO0tQqeoj5NKOAiKhhcNFtIlf1oan8Wr3+LXA0N0h3puKVYqDmkrTATeiu6oweNVo4YD+Pknt5JTxVocTRti4InYQ36VmsDmbbyhB2KmwHV0RIbZxEuXYPwqJZ3yavKD0euA063a3AgcsGiTgUIBKMoov1BkitN1U1yNmtTQyRcpoR4ZQFsMf8/4eUJIwSSPVSO3FB/aVwK1PSHbiWRwFyF9TaBJ1vIUt/t1Y9lFfDF3LloKxXB8mFKa4YeHN5mOs4oMxyrcOh/hqzdjh6 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)(4636009)(376002)(136003)(39860400002)(396003)(346002)(230922051799003)(1800799012)(82310400011)(186009)(451199024)(64100799003)(46966006)(40470700004)(36840700001)(8676002)(40480700001)(4326008)(36756003)(26005)(8936002)(82740400003)(110136005)(6666004)(2906002)(54906003)(316002)(70586007)(478600001)(5660300002)(70206006)(86362001)(7636003)(356005)(2616005)(36860700001)(47076005)(40460700003)(107886003)(16526019)(83380400001)(426003)(41300700001)(336012);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 15:24:19.7074 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cc4a3414-e646-459f-5e5a-08dbeb6f1922 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: DS1PEPF00017096.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7133 X-Patchwork-Delegate: dsahern@gmail.com The function parse_on_off() currently uses matches() for string comparison under the hood. This has some odd consequences. In particular, "o" can be used as a shorthand for "off", which is not obvious, because "o" is the prefix of both. In this patch, change parsing to strcmp(). This is a breaking change. The following paragraphs give arguments for why it should be considered acceptable. First and foremost: on/off are very short strings that it makes practically no sense to shorten. Since "o" is the universal prefix, the only unambiguous shortening is "of" for "off". It is doubtful that anyone would intentionally decide to save typing of the second "f" when they already typed the first. It also seems unlikely that the typo of "of" for "off" would not be caught immediately, as missing a third of the word length would likely be noticed. In other words, it seems improbable that the abbreviated variants are used, intentionally or by mistake. Commit 9262ccc3ed32 ("bridge: link: Port over to parse_on_off()") and commit 3e0d2a73ba06 ("ip: iplink_bridge_slave: Port over to parse_on_off()") converted several sites from open-coding strcmp()-based on/off parsing to parse_on_off(), which is itself based on matches(). This made the list of permissible strings more generic, but the behavior was exact match to begin with, and this patch restores it. Commit 5f685d064b03 ("ip: iplink: Convert to use parse_on_off()") has changed from matches()-based parsing, which however had branches in the other order, and "o" would parse to mean on. This indicates that at least in this context, people were not using the shorthand of "o" or the commit would have broken their use case. This supports the thesis that the abbreviations are not really used for on/off parsing. For completeness, commit 82604d28525a ("lib: Add parse_one_of(), parse_on_off()") introduced parse_on_off(), converting several users in the ip link macsec code in the process. Those users have always used matches(), and had branches in the same order as the newly-introduced parse_on_off(). A survey of selftests and documentation of Linux kernel (by way of git grep), has not discovered any cases of the involved options getting arguments other than the exact strings on and off. Signed-off-by: Petr Machata --- lib/utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.c b/lib/utils.c index 5c91aaa9..f1ca3852 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1763,7 +1763,7 @@ bool parse_on_off(const char *msg, const char *realval, int *p_err) static const char * const values_on_off[] = { "off", "on" }; return __parse_one_of(msg, realval, values_on_off, - ARRAY_SIZE(values_on_off), p_err, matches); + ARRAY_SIZE(values_on_off), p_err, strcmp); } int parse_mapping_gen(int *argcp, char ***argvp, From patchwork Wed Nov 22 15:23:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13465035 X-Patchwork-Delegate: dsahern@gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="hELlRShM" Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2081.outbound.protection.outlook.com [40.107.92.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7665109 for ; Wed, 22 Nov 2023 07:24:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PGtJMY/C3hSjq2stFTj3Flul2N2Z3xp+VgIpSv8hHNGEl8ad10ISw+qH5Wwnq/6fFQ6XMEx8Mhoki0ru1C8a3OIMwfrCQqK3oOCvWXl8wFqeoMwoZoMyNe/VH8yDiiseHZU7Sk5Q07QS0s+jZEkGgaJvHcDbWI3mogMiLMEaSopZZpyt14sEXehIzffT7FIipdRE0XmjNsB+CBz97ZwHnqOIFOvyyGuJO/mxBIFqD/sHmS6+NPWIZiTpkz8YsDyjvCsrzRv+9D9Q1AtKMylnN0BlF697xlA/lTKWWBUexnIAM5UnMbQBiVOx4F87F9SflQ1dAiDqqWmp4/t1MWFu3A== 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=q8LEGbILjbVg7D/UJVghPhn3ty5smDN7HpQYNqJu/K8=; b=ayLR81ya+on80ad2LOn0MvFoezgAHYCC+zliMwp9TBW4KuNSQQ9oxVFPfBlekkzMz8fef3uzXBqYp3/JH2cWbsl3ryuChZMNpG6N4IAfxr41QaURHuR4MFQk71zPe93zDXTFpNCaL4t3pbTKiW+Xp/cugxyjgXV84Sf8ilfnByRgds0EX1ybcOw8VPpZJCmF8lt2x5ZHqp0fcq+32eUK2XPczJLtipJ3c2JezyALxx6vddHXkiEK7C3bI2ZWF6vTxpDPHDa8OWvouxJKdwEYHtxHoQo9l6rvgZUN42IG91kLe/XYPzy2p24TxZ1eoVqZqPKNbHV7/Z+dzXU2TlasbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=gmail.com 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=q8LEGbILjbVg7D/UJVghPhn3ty5smDN7HpQYNqJu/K8=; b=hELlRShMXjrx2wIv1brZI9Br2mfqq1GQFb9y9tb5N6XB7MxAx5QwiNYmQ54VfEcID1BWtyhV/pt8lk4Sun4e5Ba49DL8D1IJH5ZzMwhrkto0cIbAleOjaWGIZyMJOYY2A5KLJqlorMj19m0pV547KSgqkVjE4zIWdi7G2eHvZ7dYVD7WDtTguk+2HTvjysdnpxNgsDm27Mvynlk03bNwcKMpwln4OGj4//lZPHrggV//kS9j2U1MEGgqF6NnGaISjKxaV1qTgXQK9z/tS7P4ubQWqWqqTDQ42uF9/eWkyo9D5opKkNsFekU61pAq8RHJUGNs8G0Przspiwzw6QhUzA== Received: from BN8PR04CA0057.namprd04.prod.outlook.com (2603:10b6:408:d4::31) by PH7PR12MB7454.namprd12.prod.outlook.com (2603:10b6:510:20d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.19; Wed, 22 Nov 2023 15:24:24 +0000 Received: from SN1PEPF0002636B.namprd02.prod.outlook.com (2603:10b6:408:d4:cafe::b8) by BN8PR04CA0057.outlook.office365.com (2603:10b6:408:d4::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.28 via Frontend Transport; Wed, 22 Nov 2023 15:24:24 +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 SN1PEPF0002636B.mail.protection.outlook.com (10.167.241.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.12 via Frontend Transport; Wed, 22 Nov 2023 15:24:23 +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.986.41; Wed, 22 Nov 2023 07:24:08 -0800 Received: from localhost.localdomain (10.126.230.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.986.41; Wed, 22 Nov 2023 07:24:07 -0800 From: Petr Machata To: David Ahern , Stephen Hemminger , CC: Patrisious Haddad , Petr Machata Subject: [PATCH iproute2-next v2 4/5] lib: utils: Introduce parse_one_of_deprecated() Date: Wed, 22 Nov 2023 16:23:31 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636B:EE_|PH7PR12MB7454:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f7d4827-207a-4e8f-7793-08dbeb6f1b9f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Bp+5so+B0DpQoEDOCl6DJNOn+KpWpqRPR2b4vF9HcrBtJSRONiepEtogwDSk0wEPd31+Kd1cu3w1ISpvIvhAD0UUoJrlp66QOyDNBqhkDt+q7OeVLtHlSm9uyL5eRAHWQFNzl4unXxFWe7wxK3AmiWcq8zRfO1El/DNjVO3xQFn/uDO5R56HGukMxJjTF9LOjrfAznEv8vSrXwpJUTfFNjRZZumP11bWvR49K/fKAN3HPGRd5A7cT6UELwV9NSeW4NdTA52qPFWSgVGPYplLODiBpgelHT6L1HqYGDuHY2k4b3mY6nT35lxLiuNGr5AjNvIZmk5P+ogS8l9X3oFqg6kb8+SbLgbr/PR26lexa/63czR0UsnsYHCyYXPQK+OF3WMC7T1m19kzdJvRCIv/kb8foVpLRjJNC7Y9Jh9no967RGSRzFzAyAuNfiqdyjLohU0/kRmTz6Rs3WjeuDqOEBgHa9gtVrJmsEPX+OiQtvbto1M34vEx9qgI4KrwaZPIuCNGUOotrjXScj3VjzPUQZo2F2/j4NuQ7ouzCpQs7+2tBWfVUz6S6r0E9X34nx18ToWg0GSdKv1r5+6eOKdO/ejW/8CI6vxn39FH7N9bLjCxph1utFghS41OOvqIKLwY2EsEPHnIpjdeflIFzDv/rbyd5/w9//eYeWXqcWd9q5lGcstXAixPKMpKgh6/t5DV3d3z193akDcT8ggKLiOkiWEL5M89QBcTUxBzHG1E+ihVEzqASe9pxyGsbGiHaW5E 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)(4636009)(396003)(136003)(376002)(346002)(39860400002)(230922051799003)(1800799012)(451199024)(64100799003)(82310400011)(186009)(40470700004)(36840700001)(46966006)(83380400001)(478600001)(36756003)(70586007)(70206006)(110136005)(2616005)(40460700003)(426003)(336012)(54906003)(316002)(82740400003)(7636003)(356005)(40480700001)(4326008)(36860700001)(8676002)(8936002)(5660300002)(6666004)(47076005)(16526019)(26005)(86362001)(107886003)(2906002)(41300700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 15:24:23.8983 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f7d4827-207a-4e8f-7793-08dbeb6f1b9f 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: SN1PEPF0002636B.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7454 X-Patchwork-Delegate: dsahern@gmail.com The function parse_one_of() currently uses matches() for string comparison under the hood. Extending matches()-based parsers is tricky, because newly added matches might change the way strings are parsed, if the newly-added string shares a prefix with a string that is matched later in the code. In this patch, introduce a new function, parse_one_of_deprecated(). This will be currently synonymous with parse_one_of(), however the latter will change behavior in the next patch. Use the new function for parsing of the macsec "validate" option. The reason is that the valid strings for that option are "disabled", "check" and "strict". It is not hard to see how "disabled" could be misspelled as "disable", and be baked in some script in this form. Signed-off-by: Petr Machata --- include/utils.h | 3 +++ ip/ipmacsec.c | 6 ++++-- lib/utils.c | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/utils.h b/include/utils.h index add55bfa..9ba129b8 100644 --- a/include/utils.h +++ b/include/utils.h @@ -342,6 +342,9 @@ int do_batch(const char *name, bool force, int parse_one_of(const char *msg, const char *realval, const char * const *list, size_t len, int *p_err); +int parse_one_of_deprecated(const char *msg, const char *realval, + const char * const *list, + size_t len, int *p_err); bool parse_on_off(const char *msg, const char *realval, int *p_err); int parse_mapping_num_all(__u32 *keyp, const char *key); diff --git a/ip/ipmacsec.c b/ip/ipmacsec.c index 476a6d1d..fc4c8631 100644 --- a/ip/ipmacsec.c +++ b/ip/ipmacsec.c @@ -1457,8 +1457,10 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv, invarg("expected replay window size", *argv); } else if (strcmp(*argv, "validate") == 0) { NEXT_ARG(); - validate = parse_one_of("validate", *argv, validate_str, - ARRAY_SIZE(validate_str), &ret); + validate = parse_one_of_deprecated("validate", *argv, + validate_str, + ARRAY_SIZE(validate_str), + &ret); if (ret != 0) return ret; addattr8(n, MACSEC_BUFLEN, diff --git a/lib/utils.c b/lib/utils.c index f1ca3852..9142dc1d 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1758,6 +1758,13 @@ int parse_one_of(const char *msg, const char *realval, const char * const *list, return __parse_one_of(msg, realval, list, len, p_err, matches); } +int parse_one_of_deprecated(const char *msg, const char *realval, + const char * const *list, + size_t len, int *p_err) +{ + return __parse_one_of(msg, realval, list, len, p_err, matches); +} + bool parse_on_off(const char *msg, const char *realval, int *p_err) { static const char * const values_on_off[] = { "off", "on" }; From patchwork Wed Nov 22 15:23:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13465034 X-Patchwork-Delegate: dsahern@gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="bCCKKG1y" Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2056.outbound.protection.outlook.com [40.107.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4589E1B8 for ; Wed, 22 Nov 2023 07:24:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=czuhjITOcpKKgrHf1vR7PM0fNpJT36YROaK5CbBMsz1cuRVCQitt6Al6uuEa7Qw19V/ms9BFTARSz+z6bHT0D4YfsYShxiW/yvM1iWQVFc5bA1t1I6j2z8AQixxVA3jd3xGBFDdfIdEkNoZIHOoDbDsZbxsr38WENGd3WQ1VdeTlj8hB2QlrDFWyBe0i04q4zqScBXOk84IEalKn4N3+Xp7sFWJaoJyPUL0F9jTM3F6myYlkdJg69UvXfFPhq2ID9UAzZjlTHuoARi5SpylShZl/o5v/yFf/rb6uOi6ZzQDwnjbln4hK8J9LL/nf/9F8i5fniKgs092Iv6jlBaYIQA== 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=AjZXTN+hqJnDKxG2U2A/SsBT5u6M86yR8e8PFYHavFI=; b=F3OtSmXfz0XQ/h/d4tHkPtCQcvoAHWqDjdZr56TDQnryrEo8rvDX1Vhm1RVpq3wqx+8c3izEQn/RW0TCZ4CcylI5ww/VX+iBDT1sqFpctneOgUnPQY9svtOCZgD6jzlqw4elP6skax+wEortHYCAM4ZjmPqInn5R3qlPlk8PIw38IqTE/7l9aUDIBeMQ3ouF3C/Rj9V7sOwjJdP/EjzKoGlooWjd0bvAX4B4otqqb88DikekqKLQrzWL03X2+PysXUB3EehJZoDz7vInTXTjyyk4r5nVDKy3PweOyLrvOGJHqCcY4okljgA2yvDMdxQ7lIjvrdzZKYFMSbLwNm4ZAw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=gmail.com 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=AjZXTN+hqJnDKxG2U2A/SsBT5u6M86yR8e8PFYHavFI=; b=bCCKKG1yjAhloklUKHhCgN+h7zP1q55joVA4ZiBHbeO15lHRnjYVZmGLo3pkT+C8xyII8eDOTnET/hDnckQ+TkYMAM2VZbpEvE5xLA36uq3fjkAS05PPzdavXM7K6xKC6o4MsrrumTQgiZ3unV4gFCgr5haaoeWrN0LVNx2R0Sy/9HL+/7BLSuOs8pw4RodcqnysHBH1CFSz+TyZgEe4K2MSfwpgOqzEYpS0kxAlRnGCJgnv4KO6ulKH0kB5nIjXpZ/1orqnxxZG9iecSmiisG0mx8VuLeX8YpZ65xyrKzNDe4in7FJhMUEhtBYNzCIDfG/m4WCTfv33aZLg2faiOg== Received: from SN7PR04CA0183.namprd04.prod.outlook.com (2603:10b6:806:126::8) by IA0PR12MB7532.namprd12.prod.outlook.com (2603:10b6:208:43e::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.19; Wed, 22 Nov 2023 15:24:26 +0000 Received: from SN1PEPF00026369.namprd02.prod.outlook.com (2603:10b6:806:126:cafe::e1) by SN7PR04CA0183.outlook.office365.com (2603:10b6:806:126::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18 via Frontend Transport; Wed, 22 Nov 2023 15:24:26 +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 SN1PEPF00026369.mail.protection.outlook.com (10.167.241.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.12 via Frontend Transport; Wed, 22 Nov 2023 15:24:26 +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.986.41; Wed, 22 Nov 2023 07:24:10 -0800 Received: from localhost.localdomain (10.126.230.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.986.41; Wed, 22 Nov 2023 07:24:09 -0800 From: Petr Machata To: David Ahern , Stephen Hemminger , CC: Patrisious Haddad , Petr Machata Subject: [PATCH iproute2-next v2 5/5] lib: utils: Have parse_one_of() warn about prefix matches Date: Wed, 22 Nov 2023 16:23:32 +0100 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00026369:EE_|IA0PR12MB7532:EE_ X-MS-Office365-Filtering-Correlation-Id: 9da0a5a6-7356-4933-17b0-08dbeb6f1d1d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 97Hx+WSe4uOEH26C3u4o54S5e5lpwUsaZ0etlYKOwLKoPMd402m/W8xpMutjIRHUUSOfRwLdRs7kzjN5YxTgJ3YT1jdRT/Fs3YLlbByUfv6beHRzcwRw082vYzncGVIXr6l+2RlQ4mTARqi+dESB8StcXH1cD9Z8Oa5JTZKp4c5DWPtvL/UmDRtsl2esPlxl/zTzmp7QPvRNsUtP/D0NtLHsT8IW6ysJV5nbg57a4EHjl7KOSANOC6owWxOPeN3W8i1eHUO82O8bPK5FYY1u/49l3yJyqY+CbZlHVNJYvFOG1NzajCR7A6jlAupegzOgFjG++VMiOzES4sjDn6SKT3bFygGdZJEmJs+gi3F7r5v4No7TKjYGnXOdWloyxZrCQjbftvGij+JJKr0m+NHmkjxaqdxrDjq8FR87BB2wMNpwKi2ZUJlAGBC22MdxB32TftM3+kTYHia/KHPQBKnT8/64EC28RsGNLZFzj6Y466tLQeKkMmDe25BiFOIdqjYHWeOLrTyUJTIXFR2+ClfxRdWaAgwmLfC+IbXojqInwvX8ih7n0J2k/FrLbmikhvp/gSnPr5AnNo2HYOw5MtbSbCrQnvaE5GWXiW/u2Ei+ooRuwd8gDcYUc6mI1i7sTvWaiGVd+73VLw3L5j1k4MGbWYy+KCk5dMxNU0D2/r1R9tgQreRXraUQVIRCEQta+m1vMeUTdNBdWyg+/Ts2fhwN7v/z+pfP5hrfoZJ20tUQM0vRmG3g0C6bPLDTM0ftJKHqwsQVPVCmCBHTWRWv+EKY6qheuuFOWvGhntsz0T6Qceo= 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)(4636009)(346002)(376002)(396003)(39860400002)(136003)(230173577357003)(230273577357003)(230922051799003)(64100799003)(82310400011)(451199024)(1800799012)(186009)(40470700004)(36840700001)(46966006)(2616005)(107886003)(26005)(82740400003)(83380400001)(426003)(16526019)(40460700003)(336012)(6666004)(478600001)(36860700001)(40480700001)(86362001)(47076005)(5660300002)(8676002)(4326008)(8936002)(41300700001)(2906002)(70586007)(7636003)(54906003)(110136005)(316002)(70206006)(36756003)(356005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2023 15:24:26.4150 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9da0a5a6-7356-4933-17b0-08dbeb6f1d1d 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: SN1PEPF00026369.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7532 X-Patchwork-Delegate: dsahern@gmail.com The function parse_one_of() currently uses matches() for string comparison under the hood. Extending matches()-based parsers is tricky, because newly added matches might change the way strings are parsed, if the newly-added string shares a prefix with a string that is matched later in the code. Therefore in this patch, add a twist to parse_one_of() that partial prefix matches yield a warning. This will not disturb standard output or the overall behavior, but will make it obvious that the usage is discouraged and prompt users to update their scripts and habits. An example of output: # dcb ets set dev swp1 tc-tsa 0:s WARNING: 's' matches 'strict' by prefix. Matching by prefix is deprecated in this context, please use the full string. Signed-off-by: Petr Machata --- lib/utils.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/utils.c b/lib/utils.c index 9142dc1d..599e859e 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -887,6 +887,23 @@ int matches(const char *prefix, const char *string) return *prefix; } +static int matches_warn(const char *prefix, const char *string) +{ + int rc; + + rc = matches(prefix, string); + if (rc) + return rc; + + if (strlen(prefix) != strlen(string)) + fprintf(stderr, + "WARNING: '%s' matches '%s' by prefix.\n" + "Matching by prefix is deprecated in this context, please use the full string.\n", + prefix, string); + + return 0; +} + int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits) { const __u32 *a1 = a->data; @@ -1755,7 +1772,7 @@ __parse_one_of(const char *msg, const char *realval, int parse_one_of(const char *msg, const char *realval, const char * const *list, size_t len, int *p_err) { - return __parse_one_of(msg, realval, list, len, p_err, matches); + return __parse_one_of(msg, realval, list, len, p_err, matches_warn); } int parse_one_of_deprecated(const char *msg, const char *realval,