From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 2/7] dhcp: add alternative var support
Date: Fri, 24 Aug 2012 07:06:51 +0200 [thread overview]
Message-ID: <1345784816-31344-2-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1345784816-31344-1-git-send-email-plagnioj@jcrosoft.com>
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@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
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2012-08-24 5:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-24 5:03 [PATCH 0/7] defaultenv-2: add bootp support Jean-Christophe PLAGNIOL-VILLARD
2012-08-24 5:06 ` [PATCH 1/7] dhcp: add global var support Jean-Christophe PLAGNIOL-VILLARD
2012-08-24 5:06 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-08-24 5:06 ` [PATCH 3/7] dhcp: add retries limit support Jean-Christophe PLAGNIOL-VILLARD
2012-08-24 7:14 ` Roberto Nibali
2012-08-24 5:06 ` [PATCH 4/7] defaultenv-2: eth0 add default global.dhcp.vendor_id Jean-Christophe PLAGNIOL-VILLARD
2012-08-24 5:06 ` [PATCH 5/7] defaultenv-2: boot/net add bootp support Jean-Christophe PLAGNIOL-VILLARD
2012-08-24 5:06 ` [PATCH 6/7] defaultenv-2: add net boot support with kernel and oftree via nfs Jean-Christophe PLAGNIOL-VILLARD
2012-08-24 5:06 ` [PATCH 7/7] defaultenv-2: add symbolic link support to boot/nfs Jean-Christophe PLAGNIOL-VILLARD
2012-08-28 8:47 ` Sascha Hauer
2012-09-01 12:47 ` Jean-Christophe PLAGNIOL-VILLARD
2012-08-24 7:26 ` [PATCH 1/7] dhcp: add global var support Roberto Nibali
2012-08-28 8:40 ` Sascha Hauer
2012-09-01 12:49 ` Jean-Christophe PLAGNIOL-VILLARD
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1345784816-31344-2-git-send-email-plagnioj@jcrosoft.com \
--to=plagnioj@jcrosoft.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox