[PATCH 2/7] dhcp: add alternative var support
Jean-Christophe PLAGNIOL-VILLARD
plagnioj at jcrosoft.com
Fri Aug 24 01:06:51 EDT 2012
This is need for the defaultenv-2 to add the bootp suppport.
As now the hostname is store in global.hostname not hostname.
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
net/dhcp.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/net/dhcp.c b/net/dhcp.c
index 51c4283..b32af6a 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_var_alt_name;
const char *barebox_dhcp_global;
@@ -153,7 +154,13 @@ 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;
+
setenv(opt->barebox_var_name, tmp);
+ if (opt->barebox_var_alt_name)
+ setenv(opt->barebox_var_alt_name, tmp);
if (opt->barebox_dhcp_global)
dhcp_set_barebox_global(opt->barebox_dhcp_global, tmp);
@@ -207,8 +214,10 @@ struct dhcp_opt dhcp_options[] = {
.barebox_var_name = "net.nameserver",
}, {
.option = 12,
+ .copy_only_if_valid = 1,
.handle = env_str_handle,
.barebox_var_name = "hostname",
+ .barebox_var_alt_name = "global.hostname",
}, {
.option = 15,
.handle = env_str_handle,
@@ -263,6 +272,9 @@ static int dhcp_set_string_options(struct dhcp_param *param, u8 *e)
if (!str && param->barebox_var_name)
str = (char*)getenv(param->barebox_var_name);
+ if (!str && param->barebox_var_alt_name)
+ str = (char*)getenv(param->barebox_var_alt_name);
+
if (!str && param->barebox_dhcp_global)
str = (char*)dhcp_get_barebox_global(param->barebox_dhcp_global);
@@ -291,6 +303,7 @@ struct dhcp_param dhcp_params[] = {
.option = DHCP_HOSTNAME,
.handle = dhcp_set_string_options,
.barebox_var_name = "hostname",
+ .barebox_var_alt_name = "global.hostname",
}, {
.option = DHCP_VENDOR_ID,
.handle = dhcp_set_string_options,
@@ -655,10 +668,12 @@ 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,"");
+ if (opt->barebox_var_alt_name)
+ setenv(opt->barebox_var_alt_name,"");
if (opt->barebox_dhcp_global)
dhcp_set_barebox_global(opt->barebox_dhcp_global,"");
}
--
1.7.10.4
More information about the barebox
mailing list