From patchwork Wed Nov 15 15:31:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13456965 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7257D39FCB for ; Wed, 15 Nov 2023 15:32:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="jXizO+PK" Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2086.outbound.protection.outlook.com [40.107.244.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70A5A101 for ; Wed, 15 Nov 2023 07:32:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EyhGcuwHf+nD7CKR8OXAgSLL3yGaqmWFhswSpNnV2t+nHRKOJ2eLdV4oF8xPkkaacgnek3bTnVNYIYA7vIpcRYFC3OkaIwrWXOkefBBGq4dsolHeJiEu9Hg2HXD9hyPQYqikdOu3JAqYfqKCNzFfG6SdnjEx5s4xgv8aSmdNwN7EpY9OtuiGR8fuFwhlkkMfB54pLx57gMRz0TFqtNMDUcb+YAdU/BTFhfWgUP78ZKvBMelkP6uVHJz4dBgxV88O8qsAdXg0qaRl9MteIxbdz66a7iZYutAf9JitVhTuCPMmfuSIhaLokLp5zW7klgWA1u5C7MvGCODAmfSbEsJSRA== 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=UVQTH7ZcsZz7Yw8xYV7AHLzAyaeBQ0wlzDhM6CRuZro=; b=Rl3IH+H5BbEtu5VwJMwVJp+yy/yUl50w+sH0hH3Rdyuq9cnepbqA9yBuat67qRQjT1U4H+iu/J5X/bGJpRIuIGdU1Exq1109ubsCHfuGhfULgyzvtNy714KD0b0VV9MkjWy8qgdA/BkplF1B8G30CJEe0X+vJ62frN8YxOkoTILvgchPcu7t7awvBoQPbQkJjOAtnlJu2dz+g9bjzyqOoajkR5Y3fQR5FkLuZoO8j2GHNiYuDqP5Ly00OZs5rCUeLOYYzpZ5jL9643wYyA7Jt5OGzo4T52SxVPolfAxDzIAcFLStc1RcnBoq/IpYIiLe92+ugjiHDgEo3bPUI/AYSQ== 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=UVQTH7ZcsZz7Yw8xYV7AHLzAyaeBQ0wlzDhM6CRuZro=; b=jXizO+PK+Itnv8XojiVgISLXmdOR9HkixlytHL+/4cNShZobgz/FpSiTQKPHJjJPWChXX3aLNygOnDKcH9B7NGLP3jXHeMyx14k2sa4ftrF7OBUIFyqrvG/HMWSNNIFvpA8MtINiJajRedSnUvwBkogILUTOQYhToL4xZnW3p75qCdHbuITX/uzqlozKUL/BJlrvIYLJjYd0N4UHZmviwzYv6cn+UJjHCwOKlSrgGcsUgXbCgK7CVYuBZ3eyFCevB2+RBbcBsQiSX7FjLkSgW6GsdIt3znTjl4Fd0TQ6DvNq5jfLV9iGMFWkmyIHbJTDYM3zY0aZhBrFMfggtPAE0w== Received: from MN2PR10CA0033.namprd10.prod.outlook.com (2603:10b6:208:120::46) by CH3PR12MB8307.namprd12.prod.outlook.com (2603:10b6:610:12f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.17; Wed, 15 Nov 2023 15:32:50 +0000 Received: from BL6PEPF0001AB54.namprd02.prod.outlook.com (2603:10b6:208:120:cafe::71) by MN2PR10CA0033.outlook.office365.com (2603:10b6:208:120::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.20 via Frontend Transport; Wed, 15 Nov 2023 15:32:49 +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 BL6PEPF0001AB54.mail.protection.outlook.com (10.167.241.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.20 via Frontend Transport; Wed, 15 Nov 2023 15:32: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.986.41; Wed, 15 Nov 2023 07:32:28 -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, 15 Nov 2023 07:32:26 -0800 From: Petr Machata To: David Ahern , Stephen Hemminger , CC: Patrisious Haddad , Petr Machata , Matteo Croce Subject: [PATCH iproute2-next 1/3] lib: utils: Switch matches() to returning int again Date: Wed, 15 Nov 2023 16:31:57 +0100 Message-ID: <28d043036e69125ea3ab5e2712ed5da49353d8d8.1700061513.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-Originating-IP: [10.126.230.35] 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: BL6PEPF0001AB54:EE_|CH3PR12MB8307:EE_ X-MS-Office365-Filtering-Correlation-Id: 74933420-e58c-4b05-9e9a-08dbe5f02038 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NiYvTcoLDWAmWfn5rxO7Kl0Kd5veJexQga+iTTmrAiy3WcFmUd8pqfWwmMbfnt2W3wk9dI+kehGCH7Wa0ZmrwmhZPXJTKUJwElk30PthGLUHaKfXnxg35v6pdGVqMt9MBNjNOdvMd2EGkMMOHQPdtLgMo4OuULV0GVdbozZIEndfsaVDOUVdjs8DnOuISbEFYD1ZIQ5ke7wtfQ6iHCNShhCiZ7THkFTEjKPYn09TA10snuVbLE+GII/fHqlhQ/42UQqxCBjUCLjlErwYm8+a9TPzLXjkfsfYWQWowd3lHzZCOeuygCThfXfz/O+zktoZDijjF/IDtB0I+qS7I2vhu4fz05TgW5QH38Jv8nvXR66l8dHszM/vh8oVyfKeFA71au9H0LfYIhSTVLKB/UbeFvxMWUCb9+whZbfaho9wTt+kZqFVfMCrXJcmkdxrdTg5O8OAmfGYvVQvEA6zH8GqguON+2/M+gf4wxuP2KoDYuYzsRmNVwlQIHkDJGvSIOYAo2V/Z+LwIn/+v+SADUFG62KfG7+0ZJ7GRkmmWp1YAfs/8dEsy1XIUtRu17HAdRGgsFrxVA6e0LFsJNL9DxeWtubnhFdxQI2FTDYTGRjGD5rknZY7loAo1pKl2NlDLklaDTZqBs4vdyXQmL7cz1LdRjaeaj8z3TjZFwEbwtC+MgaBML1qVp/I08twTIxhXL24uVRFi5DYo3WkqJ8dltugFQnbU2sZVUntmFFEwC4ruSLObQhcYpSwf+lRqX3FaB0a 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)(376002)(346002)(230922051799003)(451199024)(1800799009)(186009)(64100799003)(82310400011)(36840700001)(40470700004)(46966006)(26005)(82740400003)(40460700003)(86362001)(336012)(2616005)(426003)(478600001)(8936002)(4326008)(8676002)(36756003)(41300700001)(16526019)(2906002)(54906003)(70586007)(70206006)(316002)(110136005)(5660300002)(40480700001)(6666004)(47076005)(7636003)(356005)(36860700001)(83380400001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2023 15:32:49.5737 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 74933420-e58c-4b05-9e9a-08dbe5f02038 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: BL6PEPF0001AB54.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8307 X-Patchwork-Delegate: dsahern@gmail.com Since the commit cited below, 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(). The function actually even 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 Fixes: 1f420318bda3 ("utils: don't match empty strings as prefixes") 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 15 15:31:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13456966 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 420A539FE9 for ; Wed, 15 Nov 2023 15:32:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="LwoRpmkB" Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2075.outbound.protection.outlook.com [40.107.94.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A4F6C2 for ; Wed, 15 Nov 2023 07:32:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jq8d+DPbg8gPMAPR6hO90jJ1Y49QVew5EZ91QAvvCmeQGp3zPcToU9OuEbUFLDfNF9ekJFSYnA0RGpU4/xzc1+wC0xxc8rVHWOpW2naOW05rKY7iKaTeBCMdYIYnAKy7xiEvZ7ftRZa9mxKos7j2sctMhvCDgD2vxrRm3QUURx+Rzb06FdZCuhb04k2JYwug4w+UJcHLrha2jMmg5i901l6HGBe1FfK86+FPazdHMLOULUiCVA1MTmTnYcOdvRscB/sVJw3XPpgEWxltF8xykIeAH1V+SB0xqEyrjl0VwgFg5E3pZhXgGLYaufZ5JLAqB4gipN6q6KI1Z66L+yuljg== 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=wzF1BtbpxPwLqP3p2QsFwJCwutJy6nYYfpiDRGkEZqQ=; b=JCQMeNj2X9ez4ae2lJv0Nr5F70lPRGiHfFXVjS9urYvwRq61m1R8u0Xkjdljzckw+TGVU+NQl4G9CyCGd+T3lnoJI1ONgLP02kX0rwWccfZ0L46hmQrPCdD2JsKahDKtZ5Ri6aUFPzVNXIz3HdbnnXDWXAzYztyz0TSISE+MPDw4uxtdIsBROcDg36qZUxTJ80822vJVwyblK0GfRZvtecOUVPRwXwMdxXdzEmHAIke1wkLndVT0wd6L/9jDNUAFCobki/QFGgrTqfDBsoAbrnQecQy+PqkEyASBTxDtJNuCSARqFFm8WojFirzlJOvVpl3Au7MeSsS5bk3MqAD3KQ== 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=wzF1BtbpxPwLqP3p2QsFwJCwutJy6nYYfpiDRGkEZqQ=; b=LwoRpmkBoZgZl+1xghPy3AxHbnYmXgzz5hrMt0t1PZWyQr9euXmjcoie77REuzP81TbeIl2X3sj8Wj3EDXK2W2TB5hE3yA8mOhoSDOboxoNsLLkCQIuN/dsXkSjgWZDpS07bgiHo9pfo286jo10+qzCU4XooqPnnk2nasQicndkbE1aFLVpnL/twkPT16H1jiKRwpwucz2DYKZSAEFWcQCkW8Jw0SBuL/YrfwB4yGIwNJQ5DQUqrnBR1iZkJ/yapWu0GI0l6exW+J5mR9pAMNAnChoEzG38LUZbgqK1X5D5epM57gyj1/jUqCFJc0smZN9NyLMBVTJ3k9oND9lTZxQ== Received: from BL1P221CA0029.NAMP221.PROD.OUTLOOK.COM (2603:10b6:208:2c5::25) by PH8PR12MB7424.namprd12.prod.outlook.com (2603:10b6:510:228::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.31; Wed, 15 Nov 2023 15:32:52 +0000 Received: from BL6PEPF0001AB58.namprd02.prod.outlook.com (2603:10b6:208:2c5:cafe::fd) by BL1P221CA0029.outlook.office365.com (2603:10b6:208:2c5::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.17 via Frontend Transport; Wed, 15 Nov 2023 15:32:51 +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 BL6PEPF0001AB58.mail.protection.outlook.com (10.167.241.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.20 via Frontend Transport; Wed, 15 Nov 2023 15:32:51 +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, 15 Nov 2023 07:32:30 -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, 15 Nov 2023 07:32:28 -0800 From: Petr Machata To: David Ahern , Stephen Hemminger , CC: Patrisious Haddad , Petr Machata Subject: [PATCH iproute2-next 2/3] lib: utils: Generalize code of parse_one_of(), parse_on_off() Date: Wed, 15 Nov 2023 16:31:58 +0100 Message-ID: <0090c2dd421a51856d33ba62fdcc740624753464.1700061513.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-Originating-IP: [10.126.230.35] 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: BL6PEPF0001AB58:EE_|PH8PR12MB7424:EE_ X-MS-Office365-Filtering-Correlation-Id: dad8cfeb-949e-4283-5d47-08dbe5f0215a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tDp0GE2rUTWGVDLY1kZy2XyjDmnriQvdVJZ4aT1DZzUFYaEV++9bK1CMwz8qrhRhoxTKLLGdjs1PjfG/N6gu119g9gQ/FwMtCts8gRuKwawJREX2kDStoLz1sREYdN/IdnXNCy/GC2A2WgqsILfT8IrfkY91urQEtHMDeH64I0qYUohqR6mVQhhu/06inBt2n0yX2uLE7gL3z8iMBedY5rvOp+2CvWKr4yhuvMxA7ai0LScSvnE9KPTAMPz+vNBgrEJXUnE1BY7aTBZ70CZoA2x81XGpTBHQJ+4aoADragF1bgq4UJk4pgIXzjSXVQeM8k3QwEw2su4lrwwvBH8VIcsTqjT+SjaVSQdEVlfrDQfUv3llNlG5oBHbLnkYMu9ashvf4t1sbKQKcUhZbw6Mmwogz185TCILCX5/0PRsqtSvtOsPqY5xZs7g2xT+rMTR3wcJSwuwhPMyGRvhJJCxAPuJq018YZTflB24UQW3uO1nhZq79sXcgnpKGpzs1cbEC+HZfxViuw3Jtk/3EPKwzEx2/ABlWXNQiAwzQnbqHkP0AXOh544Nyj27finLaz6vwe5zRjDIHhcM/BHGzjIKPpzWck5JdrcPsJJ8/1zxY3e7c+WwQaM4dV2DEmvWEMj+DW/LKLUyqYreUUYGb7AMw9u6r4Emi9kjsjP/hNN1MmoN5y2mIs27wJvX6aMtG4qGm2OnJ+RXWymnR96RtHSbVEgPw9x3Cmrucj2tmTlVRek= 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)(39860400002)(136003)(346002)(376002)(396003)(230922051799003)(186009)(451199024)(64100799003)(82310400011)(1800799009)(40470700004)(46966006)(36840700001)(36756003)(110136005)(70586007)(316002)(54906003)(86362001)(40480700001)(70206006)(7636003)(82740400003)(356005)(40460700003)(26005)(426003)(336012)(47076005)(83380400001)(16526019)(36860700001)(478600001)(8936002)(8676002)(4326008)(107886003)(2616005)(6666004)(5660300002)(41300700001)(2906002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2023 15:32:51.5195 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dad8cfeb-949e-4283-5d47-08dbe5f0215a 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: BL6PEPF0001AB58.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7424 X-Patchwork-Delegate: dsahern@gmail.com The following patch will split these two functions into their deprecated and vanilla versions. Their behavior should be identical, except the deprecated version will keep using matches() under the hood, wherease the vanilla will use strcmp(). To prepare for this change, extract from each function a core, which express in terms of a configurable matcher. Then rewrite parse_one_of() and parse_on_off() as wrappers that pass matches() as the matcher to keep the current behavior. Signed-off-by: Petr Machata --- lib/utils.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/utils.c b/lib/utils.c index 1fc42a9a..7aa3409f 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,24 @@ int parse_one_of(const char *msg, const char *realval, const char * const *list, return 0; } -bool parse_on_off(const char *msg, const char *realval, int *p_err) +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); +} + +static bool __parse_on_off(const char *msg, const char *realval, int *p_err, + int (*matcher)(const char *, const char *)) { 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, matcher); +} + +bool parse_on_off(const char *msg, const char *realval, int *p_err) +{ + return __parse_on_off(msg, realval, p_err, matches); } int parse_mapping_gen(int *argcp, char ***argvp, From patchwork Wed Nov 15 15:31:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13456967 X-Patchwork-Delegate: dsahern@gmail.com Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A5CB39FD3 for ; Wed, 15 Nov 2023 15:33:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="SCmKSzDk" Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2087.outbound.protection.outlook.com [40.107.92.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48E17101 for ; Wed, 15 Nov 2023 07:32:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SoJaLTGtjJVsmubkwmpoWGYHoVpt2edlFjCLBQy9GcpxWu26+Ev1CpX3VQjY1n0lE6IBGeOagqJwaeoNUsh9rLpNF82HzJ2YVxR1aet6jXV9sSVtecPnNsVLl/JSMQtnx8BSirni8gDP/esBrbxYy6xOb2bCq8aTgfgxvovPLCM10NIPh5paSvqIHOAJ/dsUNDIjVPleTR3fXDlPgQtShTh2qss233dF6MT6Sgr2EsL7dI3KpHdLAlQNG2mJMmpV5S5BwmEkhI4h0ygzLYxBRNf0nPKM2J7CYYU8fjld7mhhEObulFKFIaWRNY3mVPQEKUFACdJnU0bCiO8sggrU1Q== 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=I53FrI5scooQFI/R/44vlL7va4Nlb2hJXNNIVjy92g8=; b=kGd/xaX1oVrcmVZeNeEHvU2zwKLm1iIF+lzHE3za4Ok8ceqQYOwbZiPf1dJK+HTdPajFKN7VNaS5kR/0+8YfqXLffvr/mS2I3QfB+v2KHJ+6ENZrcnWSXVj0qxWofaQFZTR79LoxNL4XD69XWW3QuY/ljHrR6uhoh3009jAAIHGwjOS0klNRyBwa3sOUgwdAnMJV9pq4A9nx0u6kWR40CWGNAjJTyR5QEcDPWLg9Vq5IIlFfQ9MFlGnQ/zsixnMGtspamJSZrsj8uTk5AI0+wk9cHUOqvcnu0Noy4edY8j73V8PZ9fSizxNr0OF94lRYJT7hnpFkVHm1qVG5ayT2DA== 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=I53FrI5scooQFI/R/44vlL7va4Nlb2hJXNNIVjy92g8=; b=SCmKSzDkkMCODMqPqIpFOCuM9R6E5/gDxFOPQ4/+NzHZb+whLMoj6SHjG6eThubitR5IpOHizzb2zRXbJEmJ6ZzZyXHVD4cZ7XnC5ZmXMGvZPGFVkXf7uVbomKvTamMNpWEf4aErIZmkh/Yeflp3JpPhCgs/cFY9rC0BGNwIz9A4drlywASs2taz+UG0sxo3XDsPrANpGNRKxXypXTvcvthtUdKv/6J9ys2A2QoWLYIujv5PAE8ZjqcaKohVq9eQfl3TU8qAsP6F8cAKt24oukVVqkSK5Uzq0MRYV0j4PgE9g2IWeCE++zT1APpb558eywe0J9e2IzPQM/rXo4P33Q== Received: from SA9PR11CA0028.namprd11.prod.outlook.com (2603:10b6:806:6e::33) by LV8PR12MB9136.namprd12.prod.outlook.com (2603:10b6:408:18e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.17; Wed, 15 Nov 2023 15:32:56 +0000 Received: from SN1PEPF000252A2.namprd05.prod.outlook.com (2603:10b6:806:6e:cafe::75) by SA9PR11CA0028.outlook.office365.com (2603:10b6:806:6e::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.20 via Frontend Transport; Wed, 15 Nov 2023 15:32:56 +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 SN1PEPF000252A2.mail.protection.outlook.com (10.167.242.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7002.20 via Frontend Transport; Wed, 15 Nov 2023 15:32:56 +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, 15 Nov 2023 07:32:32 -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, 15 Nov 2023 07:32:30 -0800 From: Petr Machata To: David Ahern , Stephen Hemminger , CC: Patrisious Haddad , Petr Machata Subject: [PATCH iproute2-next 3/3] lib: utils: Add parse_one_of_deprecated(), parse_on_off_deprecated() Date: Wed, 15 Nov 2023 16:31:59 +0100 Message-ID: <8ca3747c14bacccf87408280663c0598d0dc824e.1700061513.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-Originating-IP: [10.126.230.35] 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: SN1PEPF000252A2:EE_|LV8PR12MB9136:EE_ X-MS-Office365-Filtering-Correlation-Id: a8e516c4-34e5-443f-9c9e-08dbe5f0241b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MojuZoHvm2sIMLd2wR2B0xSyqycb0HSx+q78yFbVvZkwiIUZtk+yhbIeMnirWU1D//3pP58REjh4PqPttGVeMBKMY2iw9gIBEleV8R2o9K0wQcfbzK8cEovRV/+3Vwzl7tNRO2GMeUZ4sOUAdgFXNmx4Orx13yAPIk9Z9EzDB49QyMhSAaAkOQzaLq7o0QM8Et9/Md++kJiU6XIT1Reicogvgnkvd3+fOxPOAKWss0rgg9IB60D656zQbqt9SuibkAnvweJfSDel+hvBgFQmEI7qNs8GQE1mPNTBWKrhv10U0kCTvkzZ3scw4ghAcduvU8WBcUVZxKPF+SDjtCkzHb0wBu9GTU+qpHFptFOljFBErNjU17ZOu9NBK0+f6XEZG5NeVSe1xFLgDEgaV0ze5vlEnuyUSecNGob8gnjQ5cwr/QWnpUKt8vvUcT7BUyjNHkUZVYFeZcJWoreUyMmyZTCbw6hkKjYvFRCEBubWsBtOKbxh5e15rorJQ4+GvlxrjqXYFevWDKUpl8kzzbQqcOMLXAc0W9iFAk+1o1TfxkX+BlXHJYcnZDbSreAccifSyaeFUeNaDZWyAXbQ1ZJaJYlksGMmIlXt+wax/QJxTBkV7PM4q/iHLLu1AjUSMYDBNEfficYShnyet/OqZ7FL0Bx4ndN/dGv/9LY+hF0WfYEKZvwf6KDYVjhKU01VlrIaUJltcRgurEEox2srQd75DKN/7Zyt2w1kURvz0yO1iLGlTDJrAnTs3yXo/DWieUjhtKVBE7TjTKlZjRPdv51+Mg== 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)(136003)(396003)(376002)(346002)(39860400002)(230922051799003)(64100799003)(451199024)(186009)(82310400011)(1800799009)(40470700004)(46966006)(36840700001)(4326008)(66899024)(40460700003)(36756003)(426003)(336012)(26005)(2906002)(66574015)(16526019)(30864003)(83380400001)(356005)(82740400003)(47076005)(86362001)(41300700001)(36860700001)(7636003)(2616005)(5660300002)(107886003)(478600001)(40480700001)(316002)(70586007)(54906003)(70206006)(110136005)(6666004)(8676002)(8936002)(309714004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2023 15:32:56.2352 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a8e516c4-34e5-443f-9c9e-08dbe5f0241b 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: SN1PEPF000252A2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9136 X-Patchwork-Delegate: dsahern@gmail.com The functions parse_on_off() and parse_one_of() currently use 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. By sheer luck, the end result actually makes some sense: "on" means on, anything else means off (or errors out). Similar issues are in principle also possible for parse_one_of() uses, though currently this does not come up. Ideally parse_on_off() would accept the strings "on" and "off" and no others, likewise for parse_one_of(). Therefore in this patch, rename the old matches()-based parsers to parse_one_of_deprecated() and parse_on_off_deprecated(). Introduce new strcmp()-based parsers, parse_one_of() and parse_on_off(), for future users. All existing users have been converted to the _deprecated() variants, with one exception for RDMA's sys_set_privileged_qkey_args(), which was introduced recently enough that it is unlikely to have users relying on the broken behavior. Signed-off-by: Petr Machata --- bridge/link.c | 48 ++++++++++++++++++++++++++-------------- bridge/vlan.c | 4 ++-- dcb/dcb_ets.c | 6 +++-- dcb/dcb_pfc.c | 5 +++-- include/utils.h | 4 ++++ ip/iplink.c | 15 ++++++++----- ip/iplink_bridge_slave.c | 2 +- ip/ipmacsec.c | 27 +++++++++++++--------- ip/ipstats.c | 3 ++- lib/utils.c | 11 +++++++++ 10 files changed, 84 insertions(+), 41 deletions(-) diff --git a/bridge/link.c b/bridge/link.c index 1c8faa85..2a83c914 100644 --- a/bridge/link.c +++ b/bridge/link.c @@ -374,37 +374,44 @@ static int brlink_modify(int argc, char **argv) d = *argv; } else if (strcmp(*argv, "guard") == 0) { NEXT_ARG(); - bpdu_guard = parse_on_off("guard", *argv, &ret); + bpdu_guard = parse_on_off_deprecated("guard", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "hairpin") == 0) { NEXT_ARG(); - hairpin = parse_on_off("hairpin", *argv, &ret); + hairpin = parse_on_off_deprecated("hairpin", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "fastleave") == 0) { NEXT_ARG(); - fast_leave = parse_on_off("fastleave", *argv, &ret); + fast_leave = parse_on_off_deprecated("fastleave", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "root_block") == 0) { NEXT_ARG(); - root_block = parse_on_off("root_block", *argv, &ret); + root_block = parse_on_off_deprecated("root_block", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "learning") == 0) { NEXT_ARG(); - learning = parse_on_off("learning", *argv, &ret); + learning = parse_on_off_deprecated("learning", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "learning_sync") == 0) { NEXT_ARG(); - learning_sync = parse_on_off("learning_sync", *argv, &ret); + learning_sync = parse_on_off_deprecated("learning_sync", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "flood") == 0) { NEXT_ARG(); - flood = parse_on_off("flood", *argv, &ret); + flood = parse_on_off_deprecated("flood", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "mcast_router") == 0) { @@ -412,17 +419,20 @@ static int brlink_modify(int argc, char **argv) mcast_router = atoi(*argv); } else if (strcmp(*argv, "mcast_flood") == 0) { NEXT_ARG(); - mcast_flood = parse_on_off("mcast_flood", *argv, &ret); + mcast_flood = parse_on_off_deprecated("mcast_flood", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "bcast_flood") == 0) { NEXT_ARG(); - bcast_flood = parse_on_off("bcast_flood", *argv, &ret); + bcast_flood = parse_on_off_deprecated("bcast_flood", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "mcast_to_unicast") == 0) { NEXT_ARG(); - mcast_to_unicast = parse_on_off("mcast_to_unicast", *argv, &ret); + mcast_to_unicast = parse_on_off_deprecated("mcast_to_unicast", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "mcast_max_groups") == 0) { @@ -466,33 +476,37 @@ static int brlink_modify(int argc, char **argv) flags |= BRIDGE_FLAGS_MASTER; } else if (strcmp(*argv, "neigh_suppress") == 0) { NEXT_ARG(); - neigh_suppress = parse_on_off("neigh_suppress", *argv, &ret); + neigh_suppress = parse_on_off_deprecated("neigh_suppress", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "neigh_vlan_suppress") == 0) { NEXT_ARG(); - neigh_vlan_suppress = parse_on_off("neigh_vlan_suppress", - *argv, &ret); + neigh_vlan_suppress = + parse_on_off_deprecated("neigh_vlan_suppress", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "vlan_tunnel") == 0) { NEXT_ARG(); - vlan_tunnel = parse_on_off("vlan_tunnel", *argv, &ret); + vlan_tunnel = parse_on_off_deprecated("vlan_tunnel", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "isolated") == 0) { NEXT_ARG(); - isolated = parse_on_off("isolated", *argv, &ret); + isolated = parse_on_off_deprecated("isolated", + *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "locked") == 0) { NEXT_ARG(); - locked = parse_on_off("locked", *argv, &ret); + locked = parse_on_off_deprecated("locked", *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "mab") == 0) { NEXT_ARG(); - macauth = parse_on_off("mab", *argv, &ret); + macauth = parse_on_off_deprecated("mab", *argv, &ret); if (ret) return ret; } else if (strcmp(*argv, "backup_port") == 0) { diff --git a/bridge/vlan.c b/bridge/vlan.c index dfc62f83..338b9b0c 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -361,8 +361,8 @@ static int vlan_option_set(int argc, char **argv) int ret; NEXT_ARG(); - neigh_suppress = parse_on_off("neigh_suppress", *argv, - &ret); + neigh_suppress = parse_on_off_deprecated("neigh_suppress", + *argv, &ret); if (ret) return ret; addattr8(&req.n, sizeof(req), diff --git a/dcb/dcb_ets.c b/dcb/dcb_ets.c index c2088105..ea8786ff 100644 --- a/dcb/dcb_ets.c +++ b/dcb/dcb_ets.c @@ -61,7 +61,8 @@ static int dcb_ets_parse_mapping_tc_tsa(__u32 key, char *value, void *data) __u8 tsa; int ret; - tsa = parse_one_of("TSA", value, tsa_names, ARRAY_SIZE(tsa_names), &ret); + tsa = parse_one_of_deprecated("TSA", value, tsa_names, + ARRAY_SIZE(tsa_names), &ret); if (ret) return ret; @@ -274,7 +275,8 @@ static int dcb_cmd_ets_set(struct dcb *dcb, const char *dev, int argc, char **ar return 0; } else if (matches(*argv, "willing") == 0) { NEXT_ARG(); - ets.willing = parse_on_off("willing", *argv, &ret); + ets.willing = parse_on_off_deprecated("willing", + *argv, &ret); if (ret) return ret; } else if (matches(*argv, "tc-tsa") == 0) { diff --git a/dcb/dcb_pfc.c b/dcb/dcb_pfc.c index aaa09022..a89c274f 100644 --- a/dcb/dcb_pfc.c +++ b/dcb/dcb_pfc.c @@ -73,7 +73,7 @@ static int dcb_pfc_parse_mapping_prio_pfc(__u32 key, char *value, void *data) dcb_pfc_to_array(pfc_en, pfc->pfc_en); - enabled = parse_on_off("PFC", value, &ret); + enabled = parse_on_off_deprecated("PFC", value, &ret); if (ret) return ret; @@ -185,7 +185,8 @@ static int dcb_cmd_pfc_set(struct dcb *dcb, const char *dev, int argc, char **ar continue; } else if (matches(*argv, "macsec-bypass") == 0) { NEXT_ARG(); - pfc.mbc = parse_on_off("macsec-bypass", *argv, &ret); + pfc.mbc = parse_on_off_deprecated("macsec-bypass", + *argv, &ret); if (ret) return ret; } else if (matches(*argv, "delay") == 0) { diff --git a/include/utils.h b/include/utils.h index add55bfa..c9318c20 100644 --- a/include/utils.h +++ b/include/utils.h @@ -342,7 +342,11 @@ 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); +bool parse_on_off_deprecated(const char *msg, const char *realval, int *p_err); int parse_mapping_num_all(__u32 *keyp, const char *key); int parse_mapping_gen(int *argcp, char ***argvp, diff --git a/ip/iplink.c b/ip/iplink.c index 9a548dd3..e868bc66 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -470,7 +470,8 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp, struct ifla_vf_spoofchk ivs; NEXT_ARG(); - ivs.setting = parse_on_off("spoofchk", *argv, &ret); + ivs.setting = parse_on_off_deprecated("spoofchk", + *argv, &ret); if (ret) return ret; ivs.vf = vf; @@ -481,7 +482,8 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp, struct ifla_vf_rss_query_en ivs; NEXT_ARG(); - ivs.setting = parse_on_off("query_rss", *argv, &ret); + ivs.setting = parse_on_off_deprecated("query_rss", + *argv, &ret); if (ret) return ret; ivs.vf = vf; @@ -492,7 +494,8 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp, struct ifla_vf_trust ivt; NEXT_ARG(); - ivt.setting = parse_on_off("trust", *argv, &ret); + ivt.setting = parse_on_off_deprecated("trust", + *argv, &ret); if (ret) return ret; ivt.vf = vf; @@ -738,7 +741,8 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type) int carrier; NEXT_ARG(); - carrier = parse_on_off("carrier", *argv, &err); + carrier = parse_on_off_deprecated("carrier", + *argv, &err); if (err) return err; @@ -893,7 +897,8 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type) unsigned int proto_down; NEXT_ARG(); - proto_down = parse_on_off("protodown", *argv, &err); + proto_down = parse_on_off_deprecated("protodown", + *argv, &err); if (err) return err; addattr8(&req->n, sizeof(*req), IFLA_PROTO_DOWN, diff --git a/ip/iplink_bridge_slave.c b/ip/iplink_bridge_slave.c index 3821923b..361d5880 100644 --- a/ip/iplink_bridge_slave.c +++ b/ip/iplink_bridge_slave.c @@ -319,7 +319,7 @@ static void bridge_slave_parse_on_off(char *arg_name, char *arg_val, struct nlmsghdr *n, int type) { int ret; - __u8 val = parse_on_off(arg_name, arg_val, &ret); + __u8 val = parse_on_off_deprecated(arg_name, arg_val, &ret); if (ret) exit(1); diff --git a/ip/ipmacsec.c b/ip/ipmacsec.c index 476a6d1d..e958a37b 100644 --- a/ip/ipmacsec.c +++ b/ip/ipmacsec.c @@ -593,7 +593,8 @@ static int do_offload(enum cmd c, int argc, char **argv) if (argc == 0) ipmacsec_usage(); - offload = parse_one_of("offload", *argv, offload_str, ARRAY_SIZE(offload_str), &ret); + offload = parse_one_of_deprecated("offload", *argv, offload_str, + ARRAY_SIZE(offload_str), &ret); if (ret) ipmacsec_usage(); @@ -1402,7 +1403,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv, NEXT_ARG(); int i; - i = parse_on_off("encrypt", *argv, &ret); + i = parse_on_off_deprecated("encrypt", *argv, &ret); if (ret != 0) return ret; addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_ENCRYPT, i); @@ -1410,7 +1411,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv, NEXT_ARG(); int i; - i = parse_on_off("send_sci", *argv, &ret); + i = parse_on_off_deprecated("send_sci", *argv, &ret); if (ret != 0) return ret; send_sci = i; @@ -1420,7 +1421,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv, NEXT_ARG(); int i; - i = parse_on_off("end_station", *argv, &ret); + i = parse_on_off_deprecated("end_station", *argv, &ret); if (ret != 0) return ret; es = i; @@ -1429,7 +1430,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv, NEXT_ARG(); int i; - i = parse_on_off("scb", *argv, &ret); + i = parse_on_off_deprecated("scb", *argv, &ret); if (ret != 0) return ret; scb = i; @@ -1438,7 +1439,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv, NEXT_ARG(); int i; - i = parse_on_off("protect", *argv, &ret); + i = parse_on_off_deprecated("protect", *argv, &ret); if (ret != 0) return ret; addattr8(n, MACSEC_BUFLEN, IFLA_MACSEC_PROTECT, i); @@ -1446,7 +1447,7 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv, NEXT_ARG(); int i; - i = parse_on_off("replay", *argv, &ret); + i = parse_on_off_deprecated("replay", *argv, &ret); if (ret != 0) return ret; replay_protect = !!i; @@ -1457,8 +1458,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, @@ -1472,8 +1475,10 @@ static int macsec_parse_opt(struct link_util *lu, int argc, char **argv, invarg("expected an { 0..3 }", *argv); } else if (strcmp(*argv, "offload") == 0) { NEXT_ARG(); - offload = parse_one_of("offload", *argv, offload_str, - ARRAY_SIZE(offload_str), &ret); + offload = parse_one_of_deprecated("offload", *argv, + offload_str, + ARRAY_SIZE(offload_str), + &ret); if (ret != 0) return ret; addattr8(n, MACSEC_BUFLEN, diff --git a/ip/ipstats.c b/ip/ipstats.c index 3f94ff1e..ce6c8a0e 100644 --- a/ip/ipstats.c +++ b/ip/ipstats.c @@ -1282,7 +1282,8 @@ static int ipstats_set(int argc, char **argv) return -EINVAL; } at = IFLA_STATS_SET_OFFLOAD_XSTATS_L3_STATS; - enable = parse_on_off("l3_stats", *argv, &err); + enable = parse_on_off_deprecated("l3_stats", + *argv, &err); if (err) return err; } else if (strcmp(*argv, "help") == 0) { diff --git a/lib/utils.c b/lib/utils.c index 7aa3409f..19a2b63d 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1754,6 +1754,12 @@ __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, strcmp); +} + +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); } @@ -1768,6 +1774,11 @@ static bool __parse_on_off(const char *msg, const char *realval, int *p_err, } bool parse_on_off(const char *msg, const char *realval, int *p_err) +{ + return __parse_on_off(msg, realval, p_err, strcmp); +} + +bool parse_on_off_deprecated(const char *msg, const char *realval, int *p_err) { return __parse_on_off(msg, realval, p_err, matches); }