summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2012-08-15 15:38:38 +0800
committerSascha Hauer <s.hauer@pengutronix.de>2012-10-02 08:57:07 +0200
commitd166d74211e72088fa2d9f008c86ae1d45ca0f02 (patch)
treecdd23e4e6dccadf3bc8c61757bbc4d6b93234d01 /net
parent91b563613e5c831998210a2c500ec4d2492a650b (diff)
downloadbarebox-d166d74211e72088fa2d9f008c86ae1d45ca0f02.tar.gz
barebox-d166d74211e72088fa2d9f008c86ae1d45ca0f02.tar.xz
dhcp: add copy_only_if_valid support
This will allow to only update a var if recive a valid data. This is need for hostname. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'net')
-rw-r--r--net/dhcp.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/net/dhcp.c b/net/dhcp.c
index b4f28302de..02dc529b1b 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -110,6 +110,7 @@ struct dhcp_opt {
unsigned char option;
/* request automatically the option when creating the DHCP request */
bool optional;
+ bool copy_only_if_valid;
const char *barebox_var_name;
const char *barebox_dhcp_global;
void (*handle)(struct dhcp_opt *opt, unsigned char *data, int tlen);
@@ -153,6 +154,9 @@ static void env_str_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen
memcpy(tmp, popt, optlen);
tmp[optlen] = 0;
+ if (opt->copy_only_if_valid && !strlen(tmp))
+ return;
+
if (opt->barebox_var_name)
setenv(opt->barebox_var_name, tmp);
if (opt->barebox_dhcp_global)
@@ -208,6 +212,7 @@ struct dhcp_opt dhcp_options[] = {
.barebox_var_name = "net.nameserver",
}, {
.option = 12,
+ .copy_only_if_valid = 1,
.handle = env_str_handle,
.barebox_var_name = "global.hostname",
}, {
@@ -647,7 +652,7 @@ static void dhcp_reset_env(void)
for (i = 0; i < ARRAY_SIZE(dhcp_options); i++) {
opt = &dhcp_options[i];
- if (!opt->barebox_var_name)
+ if (!opt->barebox_var_name || opt->copy_only_if_valid)
continue;
setenv(opt->barebox_var_name,"");