diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2017-11-20 22:46:47 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-12-14 14:29:42 +0100 |
commit | ab84733e570b889324f2594685f7f5d33b3c39be (patch) | |
tree | 0a75d7c782667cefb892b8a86772875f62a879c9 /commands/dhcp.c | |
parent | 946bc95a4de8247ea884a3932470344e59618c3a (diff) | |
download | barebox-ab84733e570b889324f2594685f7f5d33b3c39be.tar.gz barebox-ab84733e570b889324f2594685f7f5d33b3c39be.tar.xz |
net: dhcp: Allow to specify network device
Instead of allowing to DHCP only on the "current" network
device, allow to specify the desired network device. This
is a first step to get rid of the concept of a "current"
network device.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/dhcp.c')
-rw-r--r-- | commands/dhcp.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/commands/dhcp.c b/commands/dhcp.c index 4f4f5490c5..ce4a78830d 100644 --- a/commands/dhcp.c +++ b/commands/dhcp.c @@ -15,12 +15,15 @@ #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; + struct eth_device *edev; + const char *edevname; memset(&dhcp_param, 0, sizeof(struct dhcp_req_param)); getenv_uint("global.dhcp.retries", &retries); @@ -50,12 +53,23 @@ static int do_dhcp(int argc, char *argv[]) } } + 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; + } + if (!retries) { printf("retries is set to zero, set it to %d\n", DHCP_DEFAULT_RETRY); retries = DHCP_DEFAULT_RETRY; } - ret = dhcp(retries, &dhcp_param); + ret = dhcp(edev, retries, &dhcp_param); return ret; } @@ -73,8 +87,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 |