From: Oleksij Rempel <o.rempel@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Oleksij Rempel <o.rempel@pengutronix.de>
Subject: [PATCH v1] add ip command
Date: Tue, 11 Jun 2024 15:43:50 +0200 [thread overview]
Message-ID: <20240611134350.3817821-1-o.rempel@pengutronix.de> (raw)
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
reply other threads:[~2024-06-11 13:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240611134350.3817821-1-o.rempel@pengutronix.de \
--to=o.rempel@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox