mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 5/7] dhcp: add copy_only_if_valid support
Date: Thu, 13 Sep 2012 18:29:26 +0200	[thread overview]
Message-ID: <1347553768-19030-5-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1347553768-19030-1-git-send-email-plagnioj@jcrosoft.com>

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>
---
 net/dhcp.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/net/dhcp.c b/net/dhcp.c
index b4f2830..02dc529 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,"");
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2012-09-13 16:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-13 15:55 [PATCH 0/7 v2] dhcp: update to globalvar Jean-Christophe PLAGNIOL-VILLARD
2012-09-13 16:29 ` [PATCH 1/7] globalvar: add inline when not enabled Jean-Christophe PLAGNIOL-VILLARD
2012-09-13 16:29   ` [PATCH 2/7] defaultenv: enable glovalvar support Jean-Christophe PLAGNIOL-VILLARD
2012-09-13 16:29   ` [PATCH 3/7] defaultenv: switch hostname to global.hostname Jean-Christophe PLAGNIOL-VILLARD
2012-09-13 16:29   ` [PATCH 4/7] dhcp: switch to global var support Jean-Christophe PLAGNIOL-VILLARD
2012-09-13 16:29   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-09-13 16:29   ` [PATCH 6/7] dhcp: add retries limit support Jean-Christophe PLAGNIOL-VILLARD
2012-09-13 16:29   ` [PATCH 7/7] defaultenv-2: eth0 add default global.dhcp.vendor_id Jean-Christophe PLAGNIOL-VILLARD
2012-09-14  7:07 ` [PATCH 0/7 v2] dhcp: update to globalvar Sascha Hauer
  -- strict thread matches above, loose matches on Subject: below --
2012-09-12 14:27 [PATCH 0/7] " Jean-Christophe PLAGNIOL-VILLARD
2012-09-12 14:48 ` [PATCH 1/7] globalbar: add inline when not enabled Jean-Christophe PLAGNIOL-VILLARD
2012-09-12 14:48   ` [PATCH 5/7] dhcp: add copy_only_if_valid support 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=1347553768-19030-5-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