diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2017-11-20 23:06:13 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-12-14 14:30:16 +0100 |
commit | 528298b702a0ad238dd01b3497f7c0bb671bf7c9 (patch) | |
tree | de45aac980aca35e3761921449728afadd033f77 /commands | |
parent | 6b4a38d00255149c63277100ed1a3f5f95ab2e75 (diff) | |
download | barebox-528298b702a0ad238dd01b3497f7c0bb671bf7c9.tar.gz barebox-528298b702a0ad238dd01b3497f7c0bb671bf7c9.tar.xz |
net: dhcp: rework
The DHCP code is a mess. It is not clear which options are sent to the
server and which options are returned from the server. Also environment
variables are read from and written to all over the place.
This patch cleans this up. There now is struct dhcp_req_param which is
used for options sent to the server and struct dhcp_result which contains
the values sent from the server. The values from the server are written
to the barebox variables in a single place. Also it's now possible to
call the dhcp code without modifying barebox variables at all, storing
the result only in the dhcp result struct.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands')
-rw-r--r-- | commands/dhcp.c | 15 |
1 files changed, 3 insertions, 12 deletions
diff --git a/commands/dhcp.c b/commands/dhcp.c index ce4a78830d..1f07b2f2ce 100644 --- a/commands/dhcp.c +++ b/commands/dhcp.c @@ -20,14 +20,10 @@ static int do_dhcp(int argc, char *argv[]) { int ret, opt; - int retries = DHCP_DEFAULT_RETRY; - struct dhcp_req_param dhcp_param; + 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); - while ((opt = getopt(argc, argv, "H:v:c:u:U:r:")) > 0) { switch (opt) { case 'H': @@ -46,7 +42,7 @@ 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; @@ -64,12 +60,7 @@ static int do_dhcp(int argc, char *argv[]) return 1; } - if (!retries) { - printf("retries is set to zero, set it to %d\n", DHCP_DEFAULT_RETRY); - retries = DHCP_DEFAULT_RETRY; - } - - ret = dhcp(edev, retries, &dhcp_param); + ret = dhcp(edev, &dhcp_param); return ret; } |