[PATCH v3 3/8] ethlog: option to enable/disable promisc mode

Oleksij Rempel o.rempel at pengutronix.de
Mon Nov 7 03:16:56 PST 2022


Add -p option to control promisc mode of the ethrnet device.
Example:
ethlog -p eth0 - will enable promisc mode and logging on the eth0
device
ethlog -rp eth0 - will disable promisc mode and logging on the eth0
device

All the same commands without "-p" option will not touch promisc
configuration.

Signed-off-by: Oleksij Rempel <o.rempel at pengutronix.de>
---
 commands/ethlog.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/commands/ethlog.c b/commands/ethlog.c
index 0cc93ba808..7885d32c6b 100644
--- a/commands/ethlog.c
+++ b/commands/ethlog.c
@@ -29,11 +29,14 @@ static int do_ethlog(int argc, char *argv[])
 {
 	struct eth_device *edev;
 	const char *edevname;
-	bool remove = false;
-	int opt;
+	bool remove = false, promisc = false;
+	int opt, ret;
 
-	while ((opt = getopt(argc, argv, "r")) > 0) {
+	while ((opt = getopt(argc, argv, "pr")) > 0) {
 		switch (opt) {
+		case 'p':
+			promisc = true;
+			break;
 		case 'r':
 			remove = true;
 			break;
@@ -56,10 +59,19 @@ static int do_ethlog(int argc, char *argv[])
 	if (remove) {
 		edev->tx_monitor = NULL;
 		edev->rx_monitor = NULL;
+		if (promisc)
+			eth_set_promisc(edev, false);
 
 		return 0;
 	}
 
+	if (promisc) {
+		ret = eth_set_promisc(edev, true);
+		if (ret)
+			dev_warn(&edev->dev, "Failed to set promisc mode: %pe\n",
+				 ERR_PTR(ret));
+	}
+
 	edev->tx_monitor = ethlog_tx_monitor;
 	edev->rx_monitor = ethlog_rx_monitor;
 
@@ -69,12 +81,13 @@ static int do_ethlog(int argc, char *argv[])
 BAREBOX_CMD_HELP_START(ethlog)
 BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT("-r", "remove log handler from Ethernet interface")
+BAREBOX_CMD_HELP_OPT("-p", "Enable promisc mode, or disable if -r is used")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(ethlog)
 	.cmd		= do_ethlog,
 	BAREBOX_CMD_DESC("ETHLOG - tool to get dump of Ethernet packets")
-	BAREBOX_CMD_OPTS("[-r] [device]")
+	BAREBOX_CMD_OPTS("[-rp] [device]")
 	BAREBOX_CMD_GROUP(CMD_GRP_NET)
 	BAREBOX_CMD_COMPLETE(eth_complete)
 BAREBOX_CMD_END
-- 
2.30.2




More information about the barebox mailing list