examples/l2fwd: add promiscuous mode selection through command line option

Message ID 20211013072303.157394-1-sarosh.arif@emumba.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series examples/l2fwd: add promiscuous mode selection through command line option |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build fail github build: failed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-spell-check-testing warning Testing issues
ci/iol-mellanox-Performance fail Performance Testing issues
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

Sarosh Arif Oct. 13, 2021, 7:23 a.m. UTC
  The default behaviour of l2fwd is to exit if we are unable to turn
promiscuous mode on. On some aws instances turning promiscuous mode
on is not permitted. In such cases there should be a way to run the
application without promiscuous mode. 

This patch allows user to turn promiscuous mode on via command line
parameter. l3fwd has a similar option available.

Signed-off-by: Sarosh Arif <sarosh.arif@emumba.com>
---
 .../sample_app_ug/l2_forward_real_virtual.rst |  4 ++++
 examples/l2fwd/main.c                         | 23 +++++++++++++------
 2 files changed, 20 insertions(+), 7 deletions(-)
  

Comments

Bruce Richardson Oct. 13, 2021, 8:28 a.m. UTC | #1
On Wed, Oct 13, 2021 at 12:23:03PM +0500, Sarosh Arif wrote:
> The default behaviour of l2fwd is to exit if we are unable to turn
> promiscuous mode on. On some aws instances turning promiscuous mode
> on is not permitted. In such cases there should be a way to run the
> application without promiscuous mode. 
> 
> This patch allows user to turn promiscuous mode on via command line
> parameter. l3fwd has a similar option available.
> 
> Signed-off-by: Sarosh Arif <sarosh.arif@emumba.com>
> ---

This is a behaviour change, but since this is sample application, I think
it's acceptable, and agree that the change is needed.

Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  
Thomas Monjalon Oct. 25, 2021, 7:48 p.m. UTC | #2
13/10/2021 10:28, Bruce Richardson:
> On Wed, Oct 13, 2021 at 12:23:03PM +0500, Sarosh Arif wrote:
> > The default behaviour of l2fwd is to exit if we are unable to turn
> > promiscuous mode on. On some aws instances turning promiscuous mode
> > on is not permitted. In such cases there should be a way to run the
> > application without promiscuous mode. 
> > 
> > This patch allows user to turn promiscuous mode on via command line
> > parameter. l3fwd has a similar option available.
> > 
> > Signed-off-by: Sarosh Arif <sarosh.arif@emumba.com>
> > ---
> 
> This is a behaviour change, but since this is sample application, I think
> it's acceptable, and agree that the change is needed.
> 
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied (with small reformat of the doc), thanks.
  

Patch

diff --git a/doc/guides/sample_app_ug/l2_forward_real_virtual.rst b/doc/guides/sample_app_ug/l2_forward_real_virtual.rst
index 7b1529b2fa..ac1eab0b31 100644
--- a/doc/guides/sample_app_ug/l2_forward_real_virtual.rst
+++ b/doc/guides/sample_app_ug/l2_forward_real_virtual.rst
@@ -92,6 +92,7 @@  The application requires a number of command line options:
 .. code-block:: console
 
     ./<build_dir>/examples/dpdk-l2fwd [EAL options] -- -p PORTMASK
+                                   [-P]
                                    [-q NQ]
                                    --[no-]mac-updating
                                    [--portmap="(port, port)[,(port, port)]"]
@@ -100,6 +101,9 @@  where,
 
 *   p PORTMASK: A hexadecimal bitmask of the ports to configure
 
+*   P: Optional, sets all ports to promiscuous mode so that packets are accepted regardless of the packet's Ethernet MAC destination address.
+  Without this option, only packets with the Ethernet MAC destination address set to the Ethernet address of the port are accepted.
+
 *   q NQ: A number of queues (=ports) per lcore (default is 1)
 
 *   --[no-]mac-updating: Enable or disable MAC addresses updating (enabled by default)
diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c
index f3deeba0a6..ce56cef863 100644
--- a/examples/l2fwd/main.c
+++ b/examples/l2fwd/main.c
@@ -44,6 +44,9 @@  static volatile bool force_quit;
 /* MAC updating enabled by default */
 static int mac_updating = 1;
 
+/* Ports set in promiscuous mode off by default. */
+static int promiscuous_on;
+
 #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1
 
 #define MAX_PKT_BURST 32
@@ -307,8 +310,9 @@  l2fwd_launch_one_lcore(__rte_unused void *dummy)
 static void
 l2fwd_usage(const char *prgname)
 {
-	printf("%s [EAL options] -- -p PORTMASK [-q NQ]\n"
+	printf("%s [EAL options] -- -p PORTMASK [-P] [-q NQ]\n"
 	       "  -p PORTMASK: hexadecimal bitmask of ports to configure\n"
+	       "  -P : Enable promiscuous mode\n"
 	       "  -q NQ: number of queue (=ports) per lcore (default is 1)\n"
 	       "  -T PERIOD: statistics will be refreshed each PERIOD seconds (0 to disable, 10 default, 86400 maximum)\n"
 	       "  --no-mac-updating: Disable MAC addresses updating (enabled by default)\n"
@@ -425,6 +429,7 @@  l2fwd_parse_timer_period(const char *q_arg)
 
 static const char short_options[] =
 	"p:"  /* portmask */
+	"P"   /* promiscuous */
 	"q:"  /* number of queues */
 	"T:"  /* timer period */
 	;
@@ -473,6 +478,9 @@  l2fwd_parse_args(int argc, char **argv)
 				return -1;
 			}
 			break;
+		case 'P':
+			promiscuous_on = 1;
+			break;
 
 		/* nqueue */
 		case 'q':
@@ -872,12 +880,13 @@  main(int argc, char **argv)
 				  ret, portid);
 
 		printf("done: \n");
-
-		ret = rte_eth_promiscuous_enable(portid);
-		if (ret != 0)
-			rte_exit(EXIT_FAILURE,
-				 "rte_eth_promiscuous_enable:err=%s, port=%u\n",
-				 rte_strerror(-ret), portid);
+		if (promiscuous_on) {
+			ret = rte_eth_promiscuous_enable(portid);
+			if (ret != 0)
+				rte_exit(EXIT_FAILURE,
+					"rte_eth_promiscuous_enable:err=%s, port=%u\n",
+					rte_strerror(-ret), portid);
+		}
 
 		printf("Port %u, MAC address: " RTE_ETHER_ADDR_PRT_FMT "\n\n",
 			portid,