From: Christoph Fritz <chf.fritz@googlemail.com>
To: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>,
Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: [PATCH] net: add multiple nameserver support
Date: Sun, 23 Sep 2012 14:11:39 +0200 [thread overview]
Message-ID: <20120923121139.GA10871@mars> (raw)
In-Reply-To: <20120922201637.GZ26553@game.jcrosoft.org>
Today limit it to 2
Update dhcp support as option 6 allow to get n nameserver
If more than 2 nameserver are provided by the DHCP server ignore them.
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
net/dhcp.c | 24 +++++++++++++++++++-----
net/dns.c | 19 +++++++++++++++----
net/net.c | 18 +++++++++++++++++-
3 files changed, 51 insertions(+), 10 deletions(-)
diff --git a/net/dhcp.c b/net/dhcp.c
index 768255e..91d436f 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -137,12 +137,24 @@ static void gateway_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen
net_set_gateway(ip);
}
-static void env_ip_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
+static void env_ip_multiple_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
{
+ char *var_name;
IPaddr_t ip;
+ int i;
+ int max = (int)opt->data;
- ip = net_read_ip(popt);
- setenv_ip(opt->barebox_var_name, ip);
+ for (i = 0 ; optlen > 0 && i < max; i++) {
+ var_name = asprintf("%s%d", opt->barebox_var_name, i);
+ if (!var_name)
+ return;
+
+ ip = net_read_ip(popt);
+ setenv_ip(var_name, ip);
+ optlen -= 4;
+ popt += 4;
+ free(var_name);
+ }
}
static void env_str_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
@@ -210,8 +222,10 @@ struct dhcp_opt dhcp_options[] = {
.handle = gateway_handle,
}, {
.option = 6,
- .handle = env_ip_handle,
+ .handle = env_ip_multiple_handle,
.barebox_var_name = "net.nameserver",
+ /* max today supported, ignore if more */
+ .data = (void*)2,
}, {
.option = 12,
.copy_only_if_valid = 1,
diff --git a/net/dns.c b/net/dns.c
index eb96c57..5cd29a5 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -194,7 +194,7 @@ static void dns_handler(void *ctx, char *packet, unsigned len)
}
}
-IPaddr_t resolv(char *host)
+static IPaddr_t resolv_on(char *host, const char* nameserver)
{
IPaddr_t ip;
const char *ns;
@@ -206,10 +206,10 @@ IPaddr_t resolv(char *host)
dns_state = STATE_INIT;
- ns = getenv("net.nameserver");
+ ns = getenv(nameserver);
if (!ns || !*ns) {
- printk("%s: no nameserver specified in $net.nameserver\n",
- __func__);
+ printk("%s: no nameserver specified in $%s\n",
+ __func__, nameserver);
return 0;
}
@@ -241,6 +241,17 @@ IPaddr_t resolv(char *host)
return dns_ip;
}
+IPaddr_t resolv(char *host)
+{
+ IPaddr_t ip;
+
+ ip = resolv_on(host, "net.nameserver0");
+ if (ip == 0)
+ ip = resolv_on(host, "net.nameserver1");
+
+ return ip;
+}
+
static int do_host(int argc, char *argv[])
{
IPaddr_t ip;
diff --git a/net/net.c b/net/net.c
index 3ac098f..171e644 100644
--- a/net/net.c
+++ b/net/net.c
@@ -669,6 +669,21 @@ static struct device_d net_device = {
.id = DEVICE_ID_SINGLE,
};
+static int net_set_namesrv(struct device_d *dev, struct param_d *param, const char *val)
+{
+ IPaddr_t ip;
+
+ if (!val)
+ return -EINVAL;
+
+ if (string_to_ip(val, &ip))
+ return -EINVAL;
+
+ dev_param_set_generic(dev, param, val);
+
+ return 0;
+}
+
static int net_init(void)
{
int i;
@@ -677,7 +692,8 @@ static int net_init(void)
NetRxPackets[i] = net_alloc_packet();
register_device(&net_device);
- dev_add_param(&net_device, "nameserver", NULL, NULL, 0);
+ dev_add_param(&net_device, "nameserver0", net_set_namesrv, NULL, 0);
+ dev_add_param(&net_device, "nameserver1", net_set_namesrv, NULL, 0);
dev_add_param(&net_device, "domainname", NULL, NULL, 0);
return 0;
--
1.7.2.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2012-09-23 12:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-22 10:58 [PATCH 1/2] net: add nameserver IPs to kernel-parameter ip= Christoph Fritz
2012-09-22 11:43 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-22 15:41 ` [PATCH 1/2][v2] " Christoph Fritz
2012-09-22 18:24 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-22 18:27 ` [PATCH 1/1] net: add multiple nameserver support Jean-Christophe PLAGNIOL-VILLARD
2012-09-22 19:25 ` Christoph Fritz
2012-09-22 20:16 ` Jean-Christophe PLAGNIOL-VILLARD
2012-09-23 12:11 ` Christoph Fritz [this message]
2012-09-23 13:29 ` [PATCH] " Jean-Christophe PLAGNIOL-VILLARD
2012-09-23 13:57 ` Christoph Fritz
2012-12-10 11:23 ` Christoph Fritz
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=20120923121139.GA10871@mars \
--to=chf.fritz@googlemail.com \
--cc=barebox@lists.infradead.org \
--cc=plagnioj@jcrosoft.com \
--cc=s.hauer@pengutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.