summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2020-03-11 13:43:39 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2020-03-31 12:35:45 +0200
commit3d85c402eb2c4db48cace90f464715efcb2eae9f (patch)
treecb7f02383b78cecf5109569d6c41fe5ccd4c90a8 /net
parent7b399ab82f7211dc22887813baf503bb483a9056 (diff)
downloadbarebox-3d85c402eb2c4db48cace90f464715efcb2eae9f.tar.gz
barebox-3d85c402eb2c4db48cace90f464715efcb2eae9f.tar.xz
net: Add ifdown support and command
ifdown is the counterpart to ifup and disables one or all ethernet interfaces. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'net')
-rw-r--r--net/ifup.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/net/ifup.c b/net/ifup.c
index fa2c52ff8b..b76b4bc44c 100644
--- a/net/ifup.c
+++ b/net/ifup.c
@@ -237,6 +237,12 @@ int ifup_edev(struct eth_device *edev, unsigned flags)
return 0;
}
+void ifdown_edev(struct eth_device *edev)
+{
+ eth_close(edev);
+ edev->ifup = false;
+}
+
int ifup(const char *ethname, unsigned flags)
{
struct eth_device *edev;
@@ -253,6 +259,19 @@ int ifup(const char *ethname, unsigned flags)
return ifup_edev(edev, flags);
}
+int ifdown(const char *ethname)
+{
+ struct eth_device *edev;
+
+ edev = eth_get_byname(ethname);
+ if (!edev)
+ return -ENODEV;
+
+ ifdown_edev(edev);
+
+ return 0;
+}
+
static int net_ifup_force_detect;
int ifup_all(unsigned flags)
@@ -286,6 +305,14 @@ int ifup_all(unsigned flags)
return 0;
}
+void ifdown_all(void)
+{
+ struct eth_device *edev;
+
+ for_each_netdev(edev)
+ ifdown_edev(edev);
+}
+
static int ifup_all_init(void)
{
globalvar_add_simple_bool("net.ifup_force_detect", &net_ifup_force_detect);
@@ -346,4 +373,46 @@ BAREBOX_CMD_START(ifup)
BAREBOX_CMD_HELP(cmd_ifup_help)
BAREBOX_CMD_END
+static int do_ifdown(int argc, char *argv[])
+{
+ int opt;
+ int all = 0;
+
+ while ((opt = getopt(argc, argv, "a")) > 0) {
+ switch (opt) {
+ case 'a':
+ all = 1;
+ break;
+ }
+ }
+
+ if (all) {
+ ifdown_all();
+ return 0;
+ }
+
+ if (argc == optind)
+ return COMMAND_ERROR_USAGE;
+
+ return ifdown(argv[optind]);
+}
+
+
+
+BAREBOX_CMD_HELP_START(ifdown)
+BAREBOX_CMD_HELP_TEXT("Disable a network interface")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT ("-a", "disable all interfaces")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(ifdown)
+ .cmd = do_ifdown,
+ BAREBOX_CMD_DESC("disable a network interface")
+ BAREBOX_CMD_OPTS("[-a] [INTF]")
+ BAREBOX_CMD_GROUP(CMD_GRP_NET)
+ BAREBOX_CMD_COMPLETE(eth_complete)
+ BAREBOX_CMD_HELP(cmd_ifdown_help)
+BAREBOX_CMD_END
+
#endif