From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 764D845D4C; Wed, 20 Nov 2024 05:05:59 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E571842F29; Wed, 20 Nov 2024 05:05:50 +0100 (CET) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2041.outbound.protection.outlook.com [40.107.104.41]) by mails.dpdk.org (Postfix) with ESMTP id 3D65F42EF3 for ; Wed, 20 Nov 2024 05:05:48 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NohQmQ1eF85M+sQ3Ek6UIa+uILnZviQTNq8Wpu/FczxoaQwaUdvdOxEzPgYqXk3KeowV03C2ta+NR34WQ9fV67jNy4v6eRnfT6SrTigOONJF3z4WBTvFWEXsnragzksiiMVVoJAzu+MQVN1wHhArDiQSg539O6eClUYKTQYa/HsB3cemEqlZMM3hPoToejQLcPSMnQwrZK55eodGQzZgVgj5UOeDan44zHMKmG10dRLXIN10e9L4KIPK2nRZGEtW+BQHQqCow3evn13Ftlt6eL5/NbyhHBLQ3aezti6mFDcTKUeSKrk5FKHFNCFMoIG5PECj3v106D1mxz7N5E/A7g== 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=GsD2dvLSLsMq03o8YVRIX6YhMoRjWKACzstwKK2b9s4=; b=hiL42t3xYUMoWmG36C34hCu/UZU8gYpAedIwSO9wUAB/Hp1FMYHxdrKw/pKPageZTzWqgX2pZ0Hfk8TE72O7H0hMQa9RN7Ta5r74BjEx5R0gwTCvUoxlzgJfEm0vW70Gks8OnWqGVww+RvXYDmE46naN87wkA5cnJUc88NDw5Ivzyz77ZDyB4UzLrPiIsvDhYTyDKKEIDO0VLazAUM3QTs18Y1n4xXxQcY8HEsScdzgHTLtfM/3mdOCvx8BEV+8BfUfGpumX52Na9BTfGvvLRebRGSj2LHJMM3u5CQLRPOuiH4RGR7U9+rlywuefdHF7od1wrzmDsbJGxo7QSQs3hQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GsD2dvLSLsMq03o8YVRIX6YhMoRjWKACzstwKK2b9s4=; b=nlgvkfyAa6D25I9kFyKPwW11HVMM8t96jtOGdUOELFQm4YIzpg/ci85dPXs926YwiXkIkBG6aMJYjPxA0jiPkWwQ1WbNzn7nzVL+EeU4rLc5ahUNA7EglReWy6/JjErRVfkHjFEcGYV6zqWvZkqnuWI0zRYlkQquZMRePyIQcsNZXSPltcALo5aBcgMZl9at2j6IxpLFyBK/wyWPTXyvwLYaO2Ekud+BLxEgrNz0PYw+NIvU0NB90haDAOyhQ7P2fuug2jUixvfYo7OUfU4QJ33W6DCrVXvsq21VBeIef/P0OfrsEEIC6H7kDfsV1olCANmouhT0zsQYLZvYzM1Aew== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8198.eurprd04.prod.outlook.com (2603:10a6:20b:3b0::14) by PAWPR04MB9837.eurprd04.prod.outlook.com (2603:10a6:102:385::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.23; Wed, 20 Nov 2024 04:05:47 +0000 Received: from AS8PR04MB8198.eurprd04.prod.outlook.com ([fe80::2e32:1a4a:7d29:195]) by AS8PR04MB8198.eurprd04.prod.outlook.com ([fe80::2e32:1a4a:7d29:195%4]) with mapi id 15.20.8182.013; Wed, 20 Nov 2024 04:05:47 +0000 From: Gagandeep Singh To: dev@dpdk.org Subject: [v3 3/3] examples/l3fwd: enhance valid ports checking Date: Wed, 20 Nov 2024 09:35:16 +0530 Message-Id: <20241120040516.2836371-4-g.singh@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241120040516.2836371-1-g.singh@nxp.com> References: <20240806034120.3165295-1-g.singh@nxp.com> <20241120040516.2836371-1-g.singh@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SI2P153CA0034.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::17) To AS8PR04MB8198.eurprd04.prod.outlook.com (2603:10a6:20b:3b0::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8198:EE_|PAWPR04MB9837:EE_ X-MS-Office365-Filtering-Correlation-Id: 734171df-705d-489e-f205-08dd09189c26 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|52116014|1800799024|366016|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?1CPPdVtUMtbO3hOMBeFC21Fr7KUhr+Wbc8W8l7VY5zTIX7/3LukpAqNSeTVd?= =?us-ascii?Q?f53piquGuMtg4H02HFvt2AMm4UTmaxZmUFgcLjp1RoJNiTUrE2kfNtG1IJFH?= =?us-ascii?Q?G+l+BB19UKOA2lv+LEYJS3Szsg9qcMpOnd9e4yIFX1EBz3rbNcmeV7DhVF74?= =?us-ascii?Q?ZVe784oWGBr3LdHmNVs1ggQh/BlyUc6q0ZmjsqX4SHzmKdxFhuflKyZmANN3?= =?us-ascii?Q?UhHeq4njObPigvfDQQ/FEiXkNitJsg5HbPfoP0MWE8uxsIYdTZOihQFZiEZc?= =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pSIcQ3Bnn6lIovj9bx0BEvC2r/EqqxGSBW+y6Tk?= =?us-ascii?Q?hNcvKPViT6iw02HZQNq6SA5zscuK1BsMoKanaEb/HNPvLUlm6s4kbUc3RhvY?= =?us-ascii?Q?l8cLD4OlCuf6teO7dB+cqwCcR53iXaoVze4Oqm7rVthceEAQgybR8ePcIKq5?= =?us-ascii?Q?YMQUEI8n5JCo/oN6j2FDSnSeP+BFhki86nEFs75/fLijG0CRIlBXnDphX5UK?= =?us-ascii?Q?gpr5WA0=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB8198.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(52116014)(1800799024)(366016)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?0cmvLSVHS8ocs8QtRF8IE4hIO2bCNMByFCpfrUhk6zs1i6NN01+NsmT7UigF?= =?us-ascii?Q?VgunWtxmYNhHv9Fo1PjY34Tkyk1gMO5CiSrAo5Gpq0UYo/w/G6yRd6UuU2Su?= =?us-ascii?Q?qJeX7vpW+oR0zbJeP/6xwueNDVlh4sbBKQT0Kz9iIg3CHmFgM2hwnM8NInYo?= =?us-ascii?Q?VTJ3pkmvqHQ0yzpjedK8UZUEwJ1e6aBoRwDJipLFiO4YY0o4gwNdlXFGCWv6?= =?us-ascii?Q?DSQm7ZOaaVd9g3uO+qEl4pTsg8Ajjk0pONhS0T/4PqzsOiQNnxxZDSL3QYEA?= =?us-ascii?Q?N9NP9hIhBIt//GcpeR5HjicvwBlsXqv0Nfi8Ae3jBEkIHIy+OXT4PJ33+C53?= =?us-ascii?Q?BvNG2o0zoGsIC1XMl+XuEkD3Sd4R8EiI+eVQrezhARdQY3705ZigwmAYe6Y+?= =?us-ascii?Q?YfAjyApgUKAhStarP0k2Xodxtz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Q?FtMgLING5vAlQjwebdxllRZ68uzqDEnXtmXeK41s6N624ZrRRP+iMN7oPgtu?= =?us-ascii?Q?N3uh7WuU87eiL1GstiVTEePgeZV9jFGzcuRCpFo15p1TA+wbAB+2LaoRDsqx?= =?us-ascii?Q?6W4zQAzvSnrw+rNQSczp7S+ztO6FLt1zyuX5tBXSW78MhsjSGeP9xYsYDjEG?= =?us-ascii?Q?UsLk7GoRi/6RAN90bWfbHWbr9/2JnGBR4pQopyzpSY5ydOqr9hL5NlTG16sE?= =?us-ascii?Q?uq1NAQwC3Mu8Q9uoFnY=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 734171df-705d-489e-f205-08dd09189c26 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8198.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2024 04:05:46.9393 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Z9rMH2IJ74yJOCzbPMjyFPepGci3UBNzsU5wtnMYAM2r/mc8U85IlhBrJqPT4uzW X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR04MB9837 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The current port ID validation logic in the routes add code has two issues: - It can pass if port ID in route is 31+. - It silently skips rules with disabled or invalid port IDs This patch is: - Improving the enabled port IDs check logic. - Introducing a user option, "exit_on_failure", to control the behavior when attempting to add rules for disabled or invalid port IDs (either exit or skip) - Creating a port ID validation function for use across various setup functions Signed-off-by: Gagandeep Singh --- examples/l3fwd/em_route_parse.c | 4 +-- examples/l3fwd/l3fwd.h | 16 +++++++++ examples/l3fwd/l3fwd_em.c | 22 +++++++++---- examples/l3fwd/l3fwd_fib.c | 26 ++++++++++----- examples/l3fwd/l3fwd_lpm.c | 26 ++++++++++----- examples/l3fwd/l3fwd_route.h | 2 ++ examples/l3fwd/main.c | 58 ++++++++++++++++++++++++++++----- 7 files changed, 121 insertions(+), 33 deletions(-) diff --git a/examples/l3fwd/em_route_parse.c b/examples/l3fwd/em_route_parse.c index 8b534de5f1..b80442d7b8 100644 --- a/examples/l3fwd/em_route_parse.c +++ b/examples/l3fwd/em_route_parse.c @@ -10,8 +10,8 @@ #include "l3fwd.h" #include "l3fwd_route.h" -static struct em_rule *em_route_base_v4; -static struct em_rule *em_route_base_v6; +struct em_rule *em_route_base_v4; +struct em_rule *em_route_base_v6; enum { CB_FLD_DST_ADDR, diff --git a/examples/l3fwd/l3fwd.h b/examples/l3fwd/l3fwd.h index 0cce3406ee..bcbaf4d143 100644 --- a/examples/l3fwd/l3fwd.h +++ b/examples/l3fwd/l3fwd.h @@ -57,6 +57,15 @@ #define L3FWD_HASH_ENTRIES (1024*1024*1) #endif +/* Select Longest-Prefix, Exact match, Forwarding Information Base or Access Control. */ +enum L3FWD_LOOKUP_MODE { + L3FWD_LOOKUP_DEFAULT, + L3FWD_LOOKUP_LPM, + L3FWD_LOOKUP_EM, + L3FWD_LOOKUP_FIB, + L3FWD_LOOKUP_ACL +}; + struct parm_cfg { const char *rule_ipv4_name; const char *rule_ipv6_name; @@ -102,6 +111,9 @@ extern struct rte_ether_addr ports_eth_addr[RTE_MAX_ETHPORTS]; /* mask of enabled ports */ extern uint32_t enabled_port_mask; +/* Skip or exit on invalid route */ +extern bool exit_on_failure; + /* Used only in exact match mode. */ extern int ipv6; /**< ipv6 is false by default. */ extern uint32_t hash_entry_number; @@ -222,6 +234,10 @@ init_mem(uint16_t portid, unsigned int nb_mbuf); int config_port_max_pkt_len(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev_info); +int +l3fwd_validate_routes_port(enum L3FWD_LOOKUP_MODE mode, uint32_t i, + bool is_ipv4); + /* Function pointers for ACL, LPM, EM or FIB functionality. */ void setup_acl(const int socketid); diff --git a/examples/l3fwd/l3fwd_em.c b/examples/l3fwd/l3fwd_em.c index da9c45e3a4..9b482c3c4e 100644 --- a/examples/l3fwd/l3fwd_em.c +++ b/examples/l3fwd/l3fwd_em.c @@ -384,9 +384,14 @@ populate_ipv4_flow_into_table(const struct rte_hash *h) struct in_addr src; struct in_addr dst; - if ((1 << em_route_base_v4[i].if_out & - enabled_port_mask) == 0) - continue; + ret = l3fwd_validate_routes_port(L3FWD_LOOKUP_EM, i, true); + if (ret) { + if (exit_on_failure) + rte_exit(EXIT_FAILURE, "IDX: %d: Port ID %d in IPv4 rule is not" + " enabled\n", i, em_route_base_v4[i].if_out); + else + continue; + } entry = &em_route_base_v4[i]; convert_ipv4_5tuple(&(entry->v4_key), &newkey); @@ -436,9 +441,14 @@ populate_ipv6_flow_into_table(const struct rte_hash *h) struct em_rule *entry; union ipv6_5tuple_host newkey; - if ((1 << em_route_base_v6[i].if_out & - enabled_port_mask) == 0) - continue; + ret = l3fwd_validate_routes_port(L3FWD_LOOKUP_EM, i, false); + if (ret) { + if (exit_on_failure) + rte_exit(EXIT_FAILURE, "IDX %d: Port ID %d given in IPv6 rule is not" + " enabled\n", i, em_route_base_v6[i].if_out); + else + continue; + } entry = &em_route_base_v6[i]; convert_ipv6_5tuple(&(entry->v6_key), &newkey); diff --git a/examples/l3fwd/l3fwd_fib.c b/examples/l3fwd/l3fwd_fib.c index 82f1739df7..fa399d8c25 100644 --- a/examples/l3fwd/l3fwd_fib.c +++ b/examples/l3fwd/l3fwd_fib.c @@ -667,10 +667,15 @@ setup_fib(const int socketid) for (i = 0; i < route_num_v4; i++) { struct in_addr in; - /* Skip unused ports. */ - if ((1 << route_base_v4[i].if_out & - enabled_port_mask) == 0) - continue; + /* Check for valid ports */ + ret = l3fwd_validate_routes_port(L3FWD_LOOKUP_FIB, i, true); + if (ret) { + if (exit_on_failure) + rte_exit(EXIT_FAILURE, "IDX %d: Port ID %d in IPv4 rule is not" + " enabled\n", i, route_base_v4[i].if_out); + else + continue; + } ret = rte_eth_dev_info_get(route_base_v4[i].if_out, &dev_info); if (ret < 0) @@ -725,10 +730,15 @@ setup_fib(const int socketid) /* Populate the fib IPv6 table. */ for (i = 0; i < route_num_v6; i++) { - /* Skip unused ports. */ - if ((1 << route_base_v6[i].if_out & - enabled_port_mask) == 0) - continue; + /* Check for valid ports. */ + ret = l3fwd_validate_routes_port(L3FWD_LOOKUP_FIB, i, false); + if (ret) { + if (exit_on_failure) + rte_exit(EXIT_FAILURE, "IDX %d: Port ID %d given in IPv6 rule is not" + " enabled\n", i, route_base_v6[i].if_out); + else + continue; + } ret = rte_eth_dev_info_get(route_base_v6[i].if_out, &dev_info); if (ret < 0) diff --git a/examples/l3fwd/l3fwd_lpm.c b/examples/l3fwd/l3fwd_lpm.c index fec0aeb79c..e3bf2007db 100644 --- a/examples/l3fwd/l3fwd_lpm.c +++ b/examples/l3fwd/l3fwd_lpm.c @@ -583,10 +583,15 @@ setup_lpm(const int socketid) for (i = 0; i < route_num_v4; i++) { struct in_addr in; - /* skip unused ports */ - if ((1 << route_base_v4[i].if_out & - enabled_port_mask) == 0) - continue; + /* Check for valid ports */ + ret = l3fwd_validate_routes_port(L3FWD_LOOKUP_LPM, i, true); + if (ret) { + if (exit_on_failure) + rte_exit(EXIT_FAILURE, "IDX: %d: Port ID %d in IPv4 rule is not" + " enabled\n", i, route_base_v4[i].if_out); + else + continue; + } ret = rte_eth_dev_info_get(route_base_v4[i].if_out, &dev_info); if (ret < 0) @@ -630,10 +635,15 @@ setup_lpm(const int socketid) /* populate the LPM table */ for (i = 0; i < route_num_v6; i++) { - /* skip unused ports */ - if ((1 << route_base_v6[i].if_out & - enabled_port_mask) == 0) - continue; + /* Check for valid ports */ + ret = l3fwd_validate_routes_port(L3FWD_LOOKUP_LPM, i, false); + if (ret) { + if (exit_on_failure) + rte_exit(EXIT_FAILURE, "IDX %d Port ID %d given in IPv6 rule is not" + " enabled\n", i, route_base_v6[i].if_out); + else + continue; + } ret = rte_eth_dev_info_get(route_base_v6[i].if_out, &dev_info); if (ret < 0) diff --git a/examples/l3fwd/l3fwd_route.h b/examples/l3fwd/l3fwd_route.h index 62263c3540..98254deeeb 100644 --- a/examples/l3fwd/l3fwd_route.h +++ b/examples/l3fwd/l3fwd_route.h @@ -81,6 +81,8 @@ struct em_rule { extern struct lpm_route_rule *route_base_v4; extern struct lpm_route_rule *route_base_v6; +extern struct em_rule *em_route_base_v4; +extern struct em_rule *em_route_base_v6; extern int route_num_v4; extern int route_num_v6; diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c index 994b7dd8e5..b3b5be4076 100644 --- a/examples/l3fwd/main.c +++ b/examples/l3fwd/main.c @@ -63,14 +63,6 @@ uint32_t mb_mempool_cache_size = MEMPOOL_CACHE_SIZE; /**< Ports set in promiscuous mode off by default. */ static int promiscuous_on; -/* Select Longest-Prefix, Exact match, Forwarding Information Base or Access Control. */ -enum L3FWD_LOOKUP_MODE { - L3FWD_LOOKUP_DEFAULT, - L3FWD_LOOKUP_LPM, - L3FWD_LOOKUP_EM, - L3FWD_LOOKUP_FIB, - L3FWD_LOOKUP_ACL -}; static enum L3FWD_LOOKUP_MODE lookup_mode; /* Global variables. */ @@ -92,7 +84,8 @@ xmm_t val_eth[RTE_MAX_ETHPORTS]; /* mask of enabled ports */ uint32_t enabled_port_mask; - +bool exit_on_failure; /**< Skip the route rule with invalid or */ + /**< disabled port ID */ /* Used only in exact match mode. */ int ipv6; /**< ipv6 is false by default. */ @@ -271,6 +264,43 @@ l3fwd_set_alg(const char *optarg) parm_config.alg = parse_acl_alg(optarg); } +/* This function will work only after read_config_files step */ +int +l3fwd_validate_routes_port(enum L3FWD_LOOKUP_MODE mode, uint32_t i, + bool is_ipv4) +{ + uint32_t max_port_count = (sizeof(enabled_port_mask) * CHAR_BIT); + + if (mode == L3FWD_LOOKUP_LPM || + mode == L3FWD_LOOKUP_FIB) { + if (is_ipv4) { + if (route_base_v4[i].if_out >= max_port_count || + ((1 << route_base_v4[i].if_out & + enabled_port_mask) == 0)) + return -1; + } else { + if (route_base_v6[i].if_out >= max_port_count || + ((1 << route_base_v6[i].if_out & + enabled_port_mask) == 0)) + return -1; + } + } else if (mode == L3FWD_LOOKUP_EM) { + if (is_ipv4) { + if (em_route_base_v4[i].if_out >= max_port_count || + ((1 << em_route_base_v4[i].if_out & + enabled_port_mask) == 0)) + return -1; + } else { + if (em_route_base_v6[i].if_out >= max_port_count || + ((1 << em_route_base_v6[i].if_out & + enabled_port_mask) == 0)) + return -1; + } + } + + return 0; +} + /* * Setup lookup methods for forwarding. * Currently exact-match, longest-prefix-match and forwarding information @@ -408,6 +438,7 @@ print_usage(const char *prgname) " [--parse-ptype]" " [--per-port-pool]" " [--mode]" + " [--exit-on-failure]" #ifdef RTE_LIB_EVENTDEV " [--eventq-sched]" " [--event-vector [--event-vector-size SIZE] [--event-vector-tmo NS]]" @@ -438,6 +469,8 @@ print_usage(const char *prgname) " --per-port-pool: Use separate buffer pool per port\n" " --mode: Packet transfer mode for I/O, poll or eventdev\n" " Default mode = poll\n" + " --exit-on-failure: Exit on invalid/disabled port ID given in route rule\n" + " Default action is skip the rule\n" #ifdef RTE_LIB_EVENTDEV " --eventq-sched: Event queue synchronization method\n" " ordered, atomic or parallel.\n" @@ -758,6 +791,7 @@ static const char short_options[] = #define CMD_LINE_OPT_RELAX_RX_OFFLOAD "relax-rx-offload" #define CMD_LINE_OPT_PER_PORT_POOL "per-port-pool" #define CMD_LINE_OPT_MODE "mode" +#define CMD_LINE_OPT_EXIT_ON_FAILURE "exit-on-failure" #define CMD_LINE_OPT_EVENTQ_SYNC "eventq-sched" #define CMD_LINE_OPT_EVENT_ETH_RX_QUEUES "event-eth-rxqs" #define CMD_LINE_OPT_LOOKUP "lookup" @@ -800,6 +834,7 @@ enum { CMD_LINE_OPT_VECTOR_TMO_NS_NUM, CMD_LINE_OPT_PKT_BURST_NUM, CMD_LINE_OPT_MB_CACHE_SIZE_NUM, + CMD_LINE_OPT_EXIT_ON_FAILURE_NUM }; static const struct option lgopts[] = { @@ -816,6 +851,7 @@ static const struct option lgopts[] = { {CMD_LINE_OPT_DISABLE_RSS, 0, 0, CMD_LINE_OPT_DISABLE_RSS_NUM}, {CMD_LINE_OPT_PER_PORT_POOL, 0, 0, CMD_LINE_OPT_PARSE_PER_PORT_POOL}, {CMD_LINE_OPT_MODE, 1, 0, CMD_LINE_OPT_MODE_NUM}, + {CMD_LINE_OPT_EXIT_ON_FAILURE, 0, 0, CMD_LINE_OPT_EXIT_ON_FAILURE_NUM}, {CMD_LINE_OPT_EVENTQ_SYNC, 1, 0, CMD_LINE_OPT_EVENTQ_SYNC_NUM}, {CMD_LINE_OPT_EVENT_ETH_RX_QUEUES, 1, 0, CMD_LINE_OPT_EVENT_ETH_RX_QUEUES_NUM}, @@ -968,6 +1004,10 @@ parse_args(int argc, char **argv) parse_mode(optarg); break; + case CMD_LINE_OPT_EXIT_ON_FAILURE_NUM: + exit_on_failure = true; + break; + #ifdef RTE_LIB_EVENTDEV case CMD_LINE_OPT_EVENTQ_SYNC_NUM: parse_eventq_sched(optarg); -- 2.25.1