[PATCH] net: dhcp: mention that eth0 is the default

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Apr 16 01:16:47 PDT 2025


dhcp has always defaulted to eth0 when called without arguments, which
is not a good default for systems where eth0 is the management port of a
DSA switch.

Point out that eth0 is used by default when dhcp is called without
arguments and while at it make ignored positional arguments an error.

In general, users probably should use ifup -a (or -a1) instead.

Cc: Lars Schmidt <lsc at pengutronix.de>
Cc: Michael Grzeschik <m.grzeschik at pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 commands/dhcp.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/commands/dhcp.c b/commands/dhcp.c
index 97e9b03e4adf..79ab546fc7a9 100644
--- a/commands/dhcp.c
+++ b/commands/dhcp.c
@@ -49,10 +49,17 @@ static int do_dhcp(int argc, char *argv[])
 		}
 	}
 
-	if (optind == argc)
+	switch (argc - optind) {
+	case 0:
 		edevname = "eth0";
-	else
+		puts("Defaulting to eth0\n");
+		break;
+	case 1:
 		edevname = argv[optind];
+		break;
+	default:
+		return COMMAND_ERROR_USAGE;
+	}
 
 	edev = eth_get_byname(edevname);
 	if (!edev) {
-- 
2.39.5




More information about the barebox mailing list