summaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2018-01-05 12:08:20 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2018-01-05 12:08:20 +0100
commit3dbe78ab5c0be677b142a6c111942557ba761f1c (patch)
tree034e6a794e756c9b48f1c5938b381d00e5c5fb37 /commands
parent052d1c9e0756db2b02da98c97a6c50d26b8c28ce (diff)
parent8201a940e313cd9c2f989a7af5d6a4fb3f8ab31c (diff)
downloadbarebox-3dbe78ab5c0be677b142a6c111942557ba761f1c.tar.gz
Merge branch 'for-next/net'
Diffstat (limited to 'commands')
-rw-r--r--commands/Kconfig10
-rw-r--r--commands/Makefile2
-rw-r--r--commands/detect.c21
-rw-r--r--commands/dhcp.c29
-rw-r--r--commands/ip-route-get.c96
-rw-r--r--commands/net.c66
6 files changed, 132 insertions, 92 deletions
diff --git a/commands/Kconfig b/commands/Kconfig
index ae2dc4b..eee4b6a 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1200,6 +1200,16 @@ config CMD_TFTP
Options:
-p push to TFTP server
+config CMD_IP_ROUTE_GET
+ tristate
+ prompt "ip-route-get"
+ default y
+ help
+ The ip-route-get command is used to retrieve the network interface
+ which is used to reach the specified IP address. Information can
+ be shown on the command line or alternatively a variable is set to
+ the result.
+
# end Network commands
endmenu
diff --git a/commands/Makefile b/commands/Makefile
index 37486dc..eb47963 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -22,7 +22,6 @@ obj-$(CONFIG_CMD_MSLEEP) += msleep.o
obj-$(CONFIG_CMD_RESET) += reset.o
obj-$(CONFIG_CMD_POWEROFF) += poweroff.o
obj-$(CONFIG_CMD_GO) += go.o
-obj-$(CONFIG_NET) += net.o
obj-$(CONFIG_CMD_PARTITION) += partition.o
obj-$(CONFIG_CMD_LS) += ls.o
obj-$(CONFIG_CMD_CD) += cd.o
@@ -123,3 +122,4 @@ obj-$(CONFIG_CMD_SPD_DECODE) += spd_decode.o
obj-$(CONFIG_CMD_MMC_EXTCSD) += mmc_extcsd.o
obj-$(CONFIG_CMD_NAND_BITFLIP) += nand-bitflip.o
obj-$(CONFIG_CMD_SEED) += seed.o
+obj-$(CONFIG_CMD_IP_ROUTE_GET) += ip-route-get.o
diff --git a/commands/detect.c b/commands/detect.c
index 1586a6f..48bab4d 100644
--- a/commands/detect.c
+++ b/commands/detect.c
@@ -26,9 +26,8 @@
static int do_detect(int argc, char *argv[])
{
struct device_d *dev;
- int opt, i, ret;
+ int opt, i, ret, err;
int option_list = 0;
- int option_error = 0;
int option_all = 0;
while ((opt = getopt(argc, argv, "ela")) > 0) {
@@ -37,7 +36,6 @@ static int do_detect(int argc, char *argv[])
option_list = 1;
break;
case 'e':
- option_error = 1;
break;
case 'a':
option_all = 1;
@@ -56,37 +54,34 @@ static int do_detect(int argc, char *argv[])
}
if (option_all) {
- for_each_device(dev) {
- ret = device_detect(dev);
- if (ret && ret != -ENOSYS && option_error)
- return ret;
- }
+ device_detect_all();
return 0;
}
if (argc == optind)
return COMMAND_ERROR_USAGE;
+ err = 0;
+
for (i = optind; i < argc; i++) {
ret = device_detect_by_name(argv[i]);
- if (ret && option_error)
- return ret;
+ if (!err && ret)
+ err = ret;
}
- return 0;
+ return err;
}
BAREBOX_CMD_HELP_START(detect)
BAREBOX_CMD_HELP_TEXT("Options:")
BAREBOX_CMD_HELP_OPT ("-l", "list detectable devices")
-BAREBOX_CMD_HELP_OPT ("-e", "bail out if one device fails to detect")
BAREBOX_CMD_HELP_OPT ("-a", "detect all devices")
BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(detect)
.cmd = do_detect,
BAREBOX_CMD_DESC("detect devices")
- BAREBOX_CMD_OPTS("[-lea] [devices]")
+ BAREBOX_CMD_OPTS("[-la] [devices]")
BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
BAREBOX_CMD_COMPLETE(device_complete)
BAREBOX_CMD_HELP(cmd_detect_help)
diff --git a/commands/dhcp.c b/commands/dhcp.c
index 4f4f549..1f07b2f 100644
--- a/commands/dhcp.c
+++ b/commands/dhcp.c
@@ -15,15 +15,14 @@
#include <environment.h>
#include <getopt.h>
#include <dhcp.h>
+#include <net.h>
static int do_dhcp(int argc, char *argv[])
{
int ret, opt;
- int retries = DHCP_DEFAULT_RETRY;
- struct dhcp_req_param dhcp_param;
-
- memset(&dhcp_param, 0, sizeof(struct dhcp_req_param));
- getenv_uint("global.dhcp.retries", &retries);
+ struct dhcp_req_param dhcp_param = {};
+ struct eth_device *edev;
+ const char *edevname;
while ((opt = getopt(argc, argv, "H:v:c:u:U:r:")) > 0) {
switch (opt) {
@@ -43,19 +42,25 @@ static int do_dhcp(int argc, char *argv[])
dhcp_param.user_class = optarg;
break;
case 'r':
- retries = simple_strtoul(optarg, NULL, 10);
+ dhcp_param.retries = simple_strtoul(optarg, NULL, 10);
break;
default:
return COMMAND_ERROR_USAGE;
}
}
- if (!retries) {
- printf("retries is set to zero, set it to %d\n", DHCP_DEFAULT_RETRY);
- retries = DHCP_DEFAULT_RETRY;
+ if (optind == argc)
+ edevname = "eth0";
+ else
+ edevname = argv[optind];
+
+ edev = eth_get_byname(edevname);
+ if (!edev) {
+ printf("No such network device: %s\n", edevname);
+ return 1;
}
- ret = dhcp(retries, &dhcp_param);
+ ret = dhcp(edev, &dhcp_param);
return ret;
}
@@ -73,8 +78,8 @@ BAREBOX_CMD_HELP_END
BAREBOX_CMD_START(dhcp)
.cmd = do_dhcp,
BAREBOX_CMD_DESC("DHCP client to obtain IP or boot params")
- BAREBOX_CMD_OPTS("[-HvcuUr]")
+ BAREBOX_CMD_OPTS("[-HvcuUr] [device]")
BAREBOX_CMD_GROUP(CMD_GRP_NET)
BAREBOX_CMD_HELP(cmd_dhcp_help)
- BAREBOX_CMD_COMPLETE(empty_complete)
+ BAREBOX_CMD_COMPLETE(eth_complete)
BAREBOX_CMD_END
diff --git a/commands/ip-route-get.c b/commands/ip-route-get.c
new file mode 100644
index 0000000..d393218
--- /dev/null
+++ b/commands/ip-route-get.c
@@ -0,0 +1,96 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+#include <command.h>
+#include <common.h>
+#include <getopt.h>
+#include <complete.h>
+#include <environment.h>
+#include <net.h>
+
+static int do_ip_route_get(int argc, char *argv[])
+{
+ struct eth_device *edev;
+ IPaddr_t ip, gw = 0;
+ const char *variable = NULL;
+ int opt, ret;
+ bool bootarg = false;
+
+ while ((opt = getopt(argc, argv, "b")) > 0) {
+ switch (opt) {
+ case 'b':
+ bootarg = true;
+ break;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ if (argc == optind)
+ return COMMAND_ERROR_USAGE;
+
+ if (argc == optind + 2)
+ variable = argv[optind + 1];
+
+ ret = string_to_ip(argv[optind], &ip);
+ if (ret) {
+ printf("Cannot convert %s into a IP address: %s\n",
+ argv[1], strerror(-ret));
+ return 1;
+ }
+
+ edev = net_route(ip);
+ if (!edev) {
+ gw = net_get_gateway();
+ if (gw)
+ edev = net_route(gw);
+ }
+
+ if (!edev) {
+ printf("IP %pI4 is not reachable\n", &ip);
+ return 1;
+ }
+
+ if (variable) {
+ if (bootarg)
+ setenv(variable, edev->bootarg);
+ else
+ setenv(variable, edev->devname);
+ return 0;
+ }
+
+ if (bootarg) {
+ printf("%s\n", edev->bootarg);
+ } else {
+ if (gw)
+ printf("%pI4 via %pI4 dev %s\n", &ip, &gw,
+ edev->devname);
+ else
+ printf("%pI4 dev %s\n", &ip, edev->devname);
+ }
+
+ return 0;
+}
+
+BAREBOX_CMD_HELP_START(ip_route_get)
+BAREBOX_CMD_HELP_TEXT("get ethernet device used to reach given IP address")
+BAREBOX_CMD_HELP_TEXT("")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-b", "Instead of ethernet device, show linux bootargs for that device")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(ip_route_get)
+ .cmd = do_ip_route_get,
+ BAREBOX_CMD_DESC("get ethernet device name for an IP address")
+ BAREBOX_CMD_OPTS("[-b] <IP> [variable]")
+ BAREBOX_CMD_GROUP(CMD_GRP_MISC)
+ BAREBOX_CMD_COMPLETE(empty_complete)
+BAREBOX_CMD_END
diff --git a/commands/net.c b/commands/net.c
deleted file mode 100644
index 219c7ef..0000000
--- a/commands/net.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * (C) Copyright 2000
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
-
-/**
- * @file
- * @brief tftp, rarpboot, dhcp, nfs, cdp - Boot support
- */
-
-#include <common.h>
-#include <command.h>
-#include <complete.h>
-#include <environment.h>
-#include <driver.h>
-#include <net.h>
-#include <fs.h>
-#include <errno.h>
-#include <libbb.h>
-
-static int do_ethact(int argc, char *argv[])
-{
- struct eth_device *edev;
-
- if (argc == 1) {
- edev = eth_get_current();
- if (edev)
- printf("%s%d\n", edev->dev.name, edev->dev.id);
- return 0;
- }
-
- if (argc != 2)
- return COMMAND_ERROR_USAGE;
-
- edev = eth_get_byname(argv[1]);
- if (edev)
- eth_set_current(edev);
- else {
- printf("no such net device: %s\n", argv[1]);
- return 1;
- }
-
- return 0;
-}
-
-BAREBOX_CMD_START(ethact)
- .cmd = do_ethact,
- BAREBOX_CMD_DESC("get or set current ethernet device")
- BAREBOX_CMD_OPTS("[ETHX]")
- BAREBOX_CMD_GROUP(CMD_GRP_NET)
- BAREBOX_CMD_COMPLETE(eth_complete)
-BAREBOX_CMD_END