From 528298b702a0ad238dd01b3497f7c0bb671bf7c9 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Mon, 20 Nov 2017 23:06:13 +0100 Subject: 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 --- commands/dhcp.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'commands') 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; } -- cgit v1.2.3