mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v1] add ip command
@ 2024-06-11 13:43 Oleksij Rempel
  0 siblings, 0 replies; only message in thread
From: Oleksij Rempel @ 2024-06-11 13:43 UTC (permalink / raw)
  To: barebox; +Cc: Oleksij Rempel

The output of this command will as follow:
eth0: 5800a000.ethernet@5800a000.of
    link/ether 00:00:00:00:00:00
    inet 0.0.0.0
    link status: UP
eth1: spi-gpio-0:switch@0:ports:port@0.of
    link/ether 00:00:00:00:00:00
    inet 0.0.0.0
    link status: DOWN
eth2: spi-gpio-0:switch@0:ports:port@1.of
    link/ether 00:00:00:00:00:00
    inet 0.0.0.0
    link status: DOWN
eth3: spi-gpio-0:switch@0:ports:port@2.of
    link/ether 00:00:00:00:00:00
    inet 0.0.0.0
    link status: DOWN
eth4: spi-gpio-0:switch@0:ports:port@3.of
    link/ether 00:00:00:00:00:00
    inet 0.0.0.0
    link status: UP
eth5: usb1-0
    link/ether 00:50:b6:e5:b0:11
    inet 0.0.0.0
    link status: UNKNOWN

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
 commands/Kconfig  |  7 +++++++
 commands/Makefile |  1 +
 commands/ip.c     | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)
 create mode 100644 commands/ip.c

diff --git a/commands/Kconfig b/commands/Kconfig
index 899673bfee..cc8f5b9628 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1367,6 +1367,13 @@ config CMD_TFTP
 	  Options:
 		  -p	push to TFTP server
 
+config CMD_IP
+	tristate
+	prompt "ip"
+	default y
+	help
+	  The ip command is used to show current network configuration.
+
 config CMD_IP_ROUTE_GET
 	tristate
 	prompt "ip-route-get"
diff --git a/commands/Makefile b/commands/Makefile
index 30e1f8403e..5d7e5b9eaf 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -60,6 +60,7 @@ obj-$(CONFIG_CMD_FALSE)		+= false.o
 obj-$(CONFIG_CMD_VERSION)	+= version.o
 obj-$(CONFIG_CMD_HELP)		+= help.o
 obj-$(CONFIG_CMD_LSMOD)		+= lsmod.o
+obj-$(CONFIG_CMD_IP)		+= ip.o
 obj-$(CONFIG_CMD_INSMOD)	+= insmod.o
 obj-$(CONFIG_CMD_SPLASH)	+= splash.o
 obj-$(CONFIG_CMD_FBTEST)	+= fbtest.o
diff --git a/commands/ip.c b/commands/ip.c
new file mode 100644
index 0000000000..8a26baa231
--- /dev/null
+++ b/commands/ip.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <command.h>
+#include <net.h>
+
+static int do_ip(int argc, char *argv[])
+{
+	struct eth_device *edev;
+
+	list_for_each_entry(edev, &netdev_list, list) {
+		printf("%s: %s\n", edev->devname, edev->parent->name);
+		printf("    link/ether %pM\n", edev->ethaddr);
+		printf("    inet %pI4\n", &edev->ipaddr);
+
+		if (edev->phydev) {
+			printf("    link status: %s\n",
+				edev->phydev->link ? "UP" : "DOWN");
+		} else {
+			printf("    link status: UNKNOWN\n");
+		}
+	}
+
+	return 0;
+}
+
+BAREBOX_CMD_HELP_START(ip)
+BAREBOX_CMD_HELP_TEXT("List network interfaces and their configuration or status")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(ip)
+	.cmd = do_ip,
+	BAREBOX_CMD_DESC("List network interfaces and their configuration or status")
+	BAREBOX_CMD_GROUP(CMD_GRP_NET)
+	BAREBOX_CMD_HELP(cmd_ip_help)
+BAREBOX_CMD_END
-- 
2.39.2




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-06-11 13:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-11 13:43 [PATCH v1] add ip command Oleksij Rempel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox