From patchwork Sun May 29 14:28:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Jawad Hussain X-Patchwork-Id: 112020 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4C376A0544; Sun, 29 May 2022 16:28:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F295540A82; Sun, 29 May 2022 16:28:20 +0200 (CEST) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by mails.dpdk.org (Postfix) with ESMTP id D5FD440041 for ; Sun, 29 May 2022 16:28:19 +0200 (CEST) Received: by mail-wm1-f49.google.com with SMTP id l188-20020a1c25c5000000b003978df8a1e2so3084415wml.1 for ; Sun, 29 May 2022 07:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=x3ku5I2l6vpsOS2brNQuqnXvtlMXcshso7kLGWDZdPc=; b=MqUxZnIhF6p4ZwZwmBewlCpry+gzQ4EvUXZ9Z3apzKcNRcb+SBEZGMFXUqvPM0+7Ik /0GDAKbTwOgO5CRYkjRQKZ/88QNuCMDlP52JkOIkUtgMFd9uQXb3we05GUiyqbR8kYoN 8CaCyBR42MKSJCjBbN7yv+1YxVapVqSXIDreAyGflJlL5TjfQ8IDq08sSzepq+C6+Y6C moqri/Sx+HxgqlfJ6eDgD4iKj8pDlyXUoBxHwDH0XamyUmMDQJHuofVGCf6c8HKuGkzq Ve77J+0cM+6lRNLd8osNJ8YftIEdt4sg4NhWwdZaBOY0rQEtJP228BLuKLTQmS/H+HqD TCyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=x3ku5I2l6vpsOS2brNQuqnXvtlMXcshso7kLGWDZdPc=; b=c49VFS5huEiN99cltyFCrCA9WxWTb9Ow0MpAEhkIYoy2SAbwDzINY2ET9he29oIlpj G2cZmnZs53JTspbdF4NAqWi71N0+spHkJe2zzwL5C1eklh98XuSaWKmua23HXlaclQbj xNJ1MO3/9KDU8UMlVYfiXvty8c5OE2CdMgheNsUKM/45NljxzWTUTzcihnZPs2JS/sze qtBaJkIZdtKy4IM9m/zyMRCtL9Ieqd8k5RSWG+qtPPRczJIoC5DNtxToVRkmzz0HLsgA UR/vbzhcT3t0nFczWTBfvJvtPhUrsNCWYrQpxkyk3DWv8Bb6W3Fjp4sbl/v0c3YFW3Sz vRfA== X-Gm-Message-State: AOAM53220VQKnlllebU7SBEWAUGU35ePjOy4LQfJM5ElPqDo6XdV3ET8 Gz+ipXjmZ1gz8n5hqulsCd/TyrumCVRarQ== X-Google-Smtp-Source: ABdhPJyvpzDYe4YPs5e15ZaJbQPFxGTerKb37f4hzGKsinGeoTIan9Y/tRmF4fBW1m1bJQkeqsmykg== X-Received: by 2002:a05:600c:2212:b0:397:8d05:7a42 with SMTP id z18-20020a05600c221200b003978d057a42mr10442694wml.57.1653834499382; Sun, 29 May 2022 07:28:19 -0700 (PDT) Received: from localhost.localdomain ([39.32.39.45]) by smtp.gmail.com with ESMTPSA id j13-20020a05600c1c0d00b00397243d3dbcsm8221568wms.31.2022.05.29.07.28.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 May 2022 07:28:18 -0700 (PDT) From: Muhammad Jawad Hussain To: dev@dpdk.org Cc: jawad.hussain@emumba.com Subject: [PATCH v2] examples/ethtool: adds promiscuous mode functionality Date: Sun, 29 May 2022 19:28:04 +0500 Message-Id: <20220529142804.76368-1-jawad.hussain@emumba.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 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 ethtool did not have promiscuous mode functioality previously which is needed for viewing broadcast and multicast packets. This patch allows user to turn on/off promiscuous mode on each port through command line. Signed-off-by: Muhammad Jawad Hussain --- doc/guides/sample_app_ug/ethtool.rst | 1 + examples/ethtool/ethtool-app/ethapp.c | 79 ++++++++++++++++++++++++++- examples/ethtool/lib/rte_ethtool.c | 24 ++++++++ examples/ethtool/lib/rte_ethtool.h | 2 + 4 files changed, 104 insertions(+), 2 deletions(-) diff --git a/doc/guides/sample_app_ug/ethtool.rst b/doc/guides/sample_app_ug/ethtool.rst index 159e9e0639..6edd9940b8 100644 --- a/doc/guides/sample_app_ug/ethtool.rst +++ b/doc/guides/sample_app_ug/ethtool.rst @@ -54,6 +54,7 @@ they do as follows: * ``regs``: Dump port register(s) to file * ``ringparam``: Get/set ring parameters * ``rxmode``: Toggle port Rx mode +* ``set promisc``: Enable/Disable promiscuous mode on ports * ``stop``: Stop port * ``validate``: Check that given MAC address is valid unicast address * ``vlan``: Add/remove VLAN id diff --git a/examples/ethtool/ethtool-app/ethapp.c b/examples/ethtool/ethtool-app/ethapp.c index 78e86534e8..f89e4c4cf0 100644 --- a/examples/ethtool/ethtool-app/ethapp.c +++ b/examples/ethtool/ethtool-app/ethapp.c @@ -13,8 +13,16 @@ #include "ethapp.h" #define EEPROM_DUMP_CHUNKSIZE 1024 - - +typedef uint16_t portid_t; + +/* *** PROMISC_MODE *** */ +struct cmd_set_promisc_mode_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t promisc; + cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ + uint16_t port_num; /* valid if "allports" argument == 0 */ + cmdline_fixed_string_t mode; +}; struct pcmd_get_params { cmdline_fixed_string_t cmd; }; @@ -133,6 +141,22 @@ cmdline_parse_token_string_t pcmd_vlan_token_mode = cmdline_parse_token_num_t pcmd_vlan_token_vid = TOKEN_NUM_INITIALIZER(struct pcmd_vlan_params, vid, RTE_UINT16); +/* promisc mode */ + +cmdline_parse_token_string_t cmd_setpromisc_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, set, "set"); +cmdline_parse_token_string_t cmd_setpromisc_promisc = + TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, promisc, + "promisc"); +cmdline_parse_token_string_t cmd_setpromisc_portall = + TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, port_all, + "all"); +cmdline_parse_token_num_t cmd_setpromisc_portnum = + TOKEN_NUM_INITIALIZER(struct cmd_set_promisc_mode_result, port_num, + RTE_UINT16); +cmdline_parse_token_string_t cmd_setpromisc_mode = + TOKEN_STRING_INITIALIZER(struct cmd_set_promisc_mode_result, mode, + "on#off"); static void pcmd_quit_callback(__rte_unused void *ptr_params, @@ -142,6 +166,30 @@ pcmd_quit_callback(__rte_unused void *ptr_params, cmdline_quit(ctx); } +static void pcmd_set_promisc_mode_parsed(void *ptr_params, + __rte_unused struct cmdline *ctx, + void *allports) +{ + struct cmd_set_promisc_mode_result *res = ptr_params; + int enable; + portid_t i; + if (!strcmp(res->mode, "on")) + enable = 1; + else + enable = 0; + + /* all ports */ + if (allports) { + RTE_ETH_FOREACH_DEV(i) + eth_set_promisc_mode(i, enable); + } else { + eth_set_promisc_mode(res->port_num, enable); + } + if (enable) + printf("Promisc mode Enabled\n"); + else + printf("Promisc mode Disabled\n"); +} static void pcmd_drvinfo_callback(__rte_unused void *ptr_params, @@ -869,6 +917,31 @@ cmdline_parse_inst_t pcmd_vlan = { }, }; +cmdline_parse_inst_t cmd_set_promisc_mode_all = { + .f = pcmd_set_promisc_mode_parsed, + .data = (void *)1, + .help_str = "set promisc all \n Set promisc mode for all ports", + .tokens = { + (void *)&cmd_setpromisc_set, + (void *)&cmd_setpromisc_promisc, + (void *)&cmd_setpromisc_portall, + (void *)&cmd_setpromisc_mode, + NULL, + }, +}; + +cmdline_parse_inst_t cmd_set_promisc_mode_one = { + .f = pcmd_set_promisc_mode_parsed, + .data = (void *)0, + .help_str = "set promisc \n Set promisc mode on port_id", + .tokens = { + (void *)&cmd_setpromisc_set, + (void *)&cmd_setpromisc_promisc, + (void *)&cmd_setpromisc_portnum, + (void *)&cmd_setpromisc_mode, + NULL, + }, +}; cmdline_parse_ctx_t list_prompt_commands[] = { (cmdline_parse_inst_t *)&pcmd_drvinfo, @@ -886,6 +959,8 @@ cmdline_parse_ctx_t list_prompt_commands[] = { (cmdline_parse_inst_t *)&pcmd_ringparam, (cmdline_parse_inst_t *)&pcmd_ringparam_set, (cmdline_parse_inst_t *)&pcmd_rxmode, + (cmdline_parse_inst_t *)&cmd_set_promisc_mode_one, + (cmdline_parse_inst_t *)&cmd_set_promisc_mode_all, (cmdline_parse_inst_t *)&pcmd_stop, (cmdline_parse_inst_t *)&pcmd_validate, (cmdline_parse_inst_t *)&pcmd_vlan, diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c index ffaad96498..2fb47471cb 100644 --- a/examples/ethtool/lib/rte_ethtool.c +++ b/examples/ethtool/lib/rte_ethtool.c @@ -18,6 +18,30 @@ #define PKTPOOL_CACHE 32 +int +eth_set_promisc_mode(uint16_t port, int enable) +{ + int ret; + + + if (enable) + ret = rte_eth_promiscuous_enable(port); + else + ret = rte_eth_promiscuous_disable(port); + + if (ret != 0) { + fprintf(stderr, + "Error during %s promiscuous mode for port %u: %s\n", + enable ? "enabling" : "disabling", + port, rte_strerror(-ret)); + return 0; + } else + return 1; +} + + + + int rte_ethtool_get_drvinfo(uint16_t port_id, struct ethtool_drvinfo *drvinfo) { diff --git a/examples/ethtool/lib/rte_ethtool.h b/examples/ethtool/lib/rte_ethtool.h index d27e0102b1..2b19907b4d 100644 --- a/examples/ethtool/lib/rte_ethtool.h +++ b/examples/ethtool/lib/rte_ethtool.h @@ -408,6 +408,8 @@ int rte_ethtool_get_ringparam(uint16_t port_id, int rte_ethtool_set_ringparam(uint16_t port_id, struct ethtool_ringparam *ring_param); +int +eth_set_promisc_mode(uint16_t port, int enable); #ifdef __cplusplus }