[PATCH 1/1] net: add multiple nameserver support

Christoph Fritz chf.fritz at googlemail.com
Sat Sep 22 15:25:57 EDT 2012


On Sat, 2012-09-22 at 20:27 +0200, Jean-Christophe PLAGNIOL-VILLARD
wrote:

> +
>  static int do_host(int argc, char *argv[])
>  {
>  	IPaddr_t ip;
> diff --git a/net/net.c b/net/net.c
> index 3ac098f..edadf51 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -677,7 +677,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", NULL, NULL, 0);
> +	dev_add_param(&net_device, "nameserver1", NULL, NULL, 0);

What do you think about a function that checks if nameserver0/1 is
really an IP, like this:

+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;
---

It has the benefit that you get an error message ("set parameter:
Invalid argument") if it's defined wrong.

Thanks,
 -- Christoph




More information about the barebox mailing list