* [PATCH 1/6] net dns: remove debug code
2012-04-15 13:26 dns work Sascha Hauer
@ 2012-04-15 13:26 ` Sascha Hauer
2012-04-15 13:26 ` [PATCH 2/6] net: use static string in string_to_ip Sascha Hauer
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2012-04-15 13:26 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
net/dns.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/dns.c b/net/dns.c
index fb1178a..0d6c337 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -97,7 +97,7 @@ static int dns_send(char *name)
dotptr = s;
} while (*(dotptr + 1));
*dotptr = 0;
-//memory_display(fullname, 0, strlen(fullname), 1);
+
strcpy(header->data, fullname);
p = header->data + strlen(fullname);
--
1.7.10
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/6] net: use static string in string_to_ip
2012-04-15 13:26 dns work Sascha Hauer
2012-04-15 13:26 ` [PATCH 1/6] net dns: remove debug code Sascha Hauer
@ 2012-04-15 13:26 ` Sascha Hauer
2012-04-15 13:26 ` [PATCH 3/6] net: add nameserver and domainname to net devices Sascha Hauer
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2012-04-15 13:26 UTC (permalink / raw)
To: barebox
Simplify usage of ip_to_string by using a static string.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/net.h | 2 +-
lib/parameter.c | 6 +-----
net/net.c | 14 ++++++--------
net/tftp.c | 3 +--
4 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/include/net.h b/include/net.h
index 3f2187e..01e4b22 100644
--- a/include/net.h
+++ b/include/net.h
@@ -274,7 +274,7 @@ static inline void net_copy_uint32(uint32_t *to, uint32_t *from)
}
/* Convert an IP address to a string */
-char *ip_to_string (IPaddr_t x, char *s);
+char *ip_to_string (IPaddr_t x);
/* Convert a string to ip address */
int string_to_ip(const char *s, IPaddr_t *ip);
diff --git a/lib/parameter.c b/lib/parameter.c
index 379a057..5a7ae1a 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -74,11 +74,7 @@ IPaddr_t dev_get_param_ip(struct device_d *dev, char *name)
int dev_set_param_ip(struct device_d *dev, char *name, IPaddr_t ip)
{
- char ipstr[sizeof("xxx.xxx.xxx.xxx")];
-
- ip_to_string(ip, ipstr);
-
- return dev_set_param(dev, name, ipstr);
+ return dev_set_param(dev, name, ip_to_string(ip));
}
#endif
diff --git a/net/net.c b/net/net.c
index 046ddd4..d164992 100644
--- a/net/net.c
+++ b/net/net.c
@@ -85,8 +85,10 @@ uint16_t net_checksum(unsigned char *ptr, int len)
return xsum & 0xffff;
}
-char *ip_to_string (IPaddr_t x, char *s)
+char *ip_to_string (IPaddr_t x)
{
+ static char s[sizeof("xxx.xxx.xxx.xxx")];
+
x = ntohl (x);
sprintf (s, "%d.%d.%d.%d",
(int) ((x >> 24) & 0xff),
@@ -146,9 +148,9 @@ IPaddr_t getenv_ip_dns(const char *name, int dns)
int setenv_ip(const char *name, IPaddr_t ip)
{
- char str[sizeof("xxx.xxx.xxx.xxx")];
+ const char *str;
- ip_to_string(ip, str);
+ str = ip_to_string(ip);
setenv(name, str);
@@ -157,11 +159,7 @@ int setenv_ip(const char *name, IPaddr_t ip)
void print_IPaddr (IPaddr_t x)
{
- char tmp[16];
-
- ip_to_string (x, tmp);
-
- puts (tmp);
+ puts(ip_to_string(x));
}
int string_to_ethaddr(const char *str, char *enetaddr)
diff --git a/net/tftp.c b/net/tftp.c
index fc33c94..ca12638 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -273,7 +273,6 @@ static void tftp_handler(void *ctx, char *packet, unsigned len)
static int do_tftpb(int argc, char *argv[])
{
char *localfile, *remotefile, *file1, *file2;
- char ip1[16];
int opt;
struct stat s;
unsigned long flags;
@@ -328,7 +327,7 @@ static int do_tftpb(int argc, char *argv[])
printf("TFTP %s server %s ('%s' -> '%s')\n",
tftp_push ? "to" : "from",
- ip_to_string(net_get_serverip(), ip1),
+ ip_to_string(net_get_serverip()),
file1, file2);
init_progression_bar(tftp_push ? s.st_size : 0);
--
1.7.10
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/6] net: add nameserver and domainname to net devices
2012-04-15 13:26 dns work Sascha Hauer
2012-04-15 13:26 ` [PATCH 1/6] net dns: remove debug code Sascha Hauer
2012-04-15 13:26 ` [PATCH 2/6] net: use static string in string_to_ip Sascha Hauer
@ 2012-04-15 13:26 ` Sascha Hauer
2012-04-15 13:20 ` Jean-Christophe PLAGNIOL-VILLARD
2012-04-15 13:26 ` [PATCH 4/6] dhcp: set global domainname and nameserver Sascha Hauer
` (2 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2012-04-15 13:26 UTC (permalink / raw)
To: barebox
This adds nameserver and domainname to net devices. This may not
be 100% correct since the nameserver and domainname are not network
device specific. However, we currently do not have the possibility
for global variables. DNS support depends on the nameserver/domainname
to be set correctly. When we set both inside a script the variables
will not be available to the parent context, so use device parameters
which are global.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/net.h | 4 ++++
net/eth.c | 2 ++
net/net.c | 45 ++++++++++++++++++++++++++++-----------------
3 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/include/net.h b/include/net.h
index 01e4b22..8031d52 100644
--- a/include/net.h
+++ b/include/net.h
@@ -189,8 +189,12 @@ void net_set_ip(IPaddr_t ip);
void net_set_serverip(IPaddr_t ip);
void net_set_netmask(IPaddr_t ip);
void net_set_gateway(IPaddr_t ip);
+void net_set_nameserver(IPaddr_t ip);
+void net_set_domainname(const char *domain);
IPaddr_t net_get_ip(void);
IPaddr_t net_get_serverip(void);
+IPaddr_t net_get_nameserver(void);
+const char *net_get_domainname(void);
/* Do the work */
void net_poll(void);
diff --git a/net/eth.c b/net/eth.c
index f62d24a..38957bb 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -210,6 +210,8 @@ int eth_register(struct eth_device *edev)
dev_add_param(dev, "gateway", eth_set_ipaddr, NULL, 0);
dev_add_param(dev, "netmask", eth_set_ipaddr, NULL, 0);
dev_add_param(dev, "serverip", eth_set_ipaddr, NULL, 0);
+ dev_add_param(dev, "nameserver", eth_set_ipaddr, NULL, 0);
+ dev_add_param(dev, "domainname", NULL, NULL, 0);
edev->init(edev);
diff --git a/net/net.c b/net/net.c
index d164992..3b3aeaa 100644
--- a/net/net.c
+++ b/net/net.c
@@ -45,6 +45,7 @@ static IPaddr_t net_gateway; /* Our gateways IP address */
static unsigned char net_ether[6]; /* Our ethernet address */
static IPaddr_t net_ip; /* Our IP addr (0 = unknown) */
static IPaddr_t net_serverip; /* Our IP addr (0 = unknown) */
+static IPaddr_t net_nameserver; /* Our nameserver */
unsigned char *NetRxPackets[PKTBUFSRX]; /* Receive packets */
static unsigned int net_ip_id;
@@ -129,23 +130,6 @@ int string_to_ip(const char *s, IPaddr_t *ip)
return 0;
}
-IPaddr_t getenv_ip_dns(const char *name, int dns)
-{
- IPaddr_t ip;
- const char *var = getenv(name);
-
- if (!var)
- return 0;
-
- if (!string_to_ip(var, &ip))
- return ip;
-
- if (!dns)
- return 0;
-
- return resolv((char*)var);
-}
-
int setenv_ip(const char *name, IPaddr_t ip)
{
const char *str;
@@ -314,6 +298,18 @@ IPaddr_t net_get_serverip(void)
return net_serverip;
}
+IPaddr_t net_get_nameserver(void)
+{
+ return net_nameserver;
+}
+
+const char *net_get_domainname(void)
+{
+ struct eth_device *edev = eth_get_current();
+
+ return dev_get_param(&edev->dev, "domainname");
+}
+
void net_set_serverip(IPaddr_t ip)
{
struct eth_device *edev = eth_get_current();
@@ -322,6 +318,13 @@ void net_set_serverip(IPaddr_t ip)
dev_set_param_ip(&edev->dev, "serverip", net_serverip);
}
+void net_set_domainname(const char *domain)
+{
+ struct eth_device *edev = eth_get_current();
+
+ dev_set_param(&edev->dev, "domainname", domain);
+}
+
void net_set_ip(IPaddr_t ip)
{
struct eth_device *edev = eth_get_current();
@@ -351,6 +354,14 @@ void net_set_gateway(IPaddr_t gw)
dev_set_param_ip(&edev->dev, "gateway", net_gateway);
}
+void net_set_nameserver(IPaddr_t ns)
+{
+ struct eth_device *edev = eth_get_current();
+
+ net_nameserver = ns;
+ dev_set_param_ip(&edev->dev, "nameserver", net_nameserver);
+}
+
static LIST_HEAD(connection_list);
static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler,
--
1.7.10
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/6] net: add nameserver and domainname to net devices
2012-04-15 13:26 ` [PATCH 3/6] net: add nameserver and domainname to net devices Sascha Hauer
@ 2012-04-15 13:20 ` Jean-Christophe PLAGNIOL-VILLARD
2012-04-15 13:43 ` Sascha Hauer
0 siblings, 1 reply; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-15 13:20 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 15:26 Sun 15 Apr , Sascha Hauer wrote:
> This adds nameserver and domainname to net devices. This may not
> be 100% correct since the nameserver and domainname are not network
> device specific. However, we currently do not have the possibility
> for global variables. DNS support depends on the nameserver/domainname
> to be set correctly. When we set both inside a script the variables
> will not be available to the parent context, so use device parameters
> which are global.
how about put it at bus level instead?
I get an issue is what happened if we have 2 ethernet?
and switch from one to the other?
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/6] net: add nameserver and domainname to net devices
2012-04-15 13:20 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-15 13:43 ` Sascha Hauer
2012-04-15 13:29 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 10+ messages in thread
From: Sascha Hauer @ 2012-04-15 13:43 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Sun, Apr 15, 2012 at 03:20:44PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 15:26 Sun 15 Apr , Sascha Hauer wrote:
> > This adds nameserver and domainname to net devices. This may not
> > be 100% correct since the nameserver and domainname are not network
> > device specific. However, we currently do not have the possibility
> > for global variables. DNS support depends on the nameserver/domainname
> > to be set correctly. When we set both inside a script the variables
> > will not be available to the parent context, so use device parameters
> > which are global.
>
> how about put it at bus level instead?
>
> I get an issue is what happened if we have 2 ethernet?
>
> and switch from one to the other?
I am aware of this issue, but what do you mean with 'put it at bus
level?'
I thought about adding a device named 'net' which would only exist to
store these variables. Is that what you mean?
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/6] net: add nameserver and domainname to net devices
2012-04-15 13:43 ` Sascha Hauer
@ 2012-04-15 13:29 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 0 replies; 10+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-15 13:29 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 15:43 Sun 15 Apr , Sascha Hauer wrote:
> On Sun, Apr 15, 2012 at 03:20:44PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 15:26 Sun 15 Apr , Sascha Hauer wrote:
> > > This adds nameserver and domainname to net devices. This may not
> > > be 100% correct since the nameserver and domainname are not network
> > > device specific. However, we currently do not have the possibility
> > > for global variables. DNS support depends on the nameserver/domainname
> > > to be set correctly. When we set both inside a script the variables
> > > will not be available to the parent context, so use device parameters
> > > which are global.
> >
> > how about put it at bus level instead?
> >
> > I get an issue is what happened if we have 2 ethernet?
> >
> > and switch from one to the other?
>
> I am aware of this issue, but what do you mean with 'put it at bus
> level?'
>
> I thought about adding a device named 'net' which would only exist to
> store these variables. Is that what you mean?
yes exactly
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/6] dhcp: set global domainname and nameserver
2012-04-15 13:26 dns work Sascha Hauer
` (2 preceding siblings ...)
2012-04-15 13:26 ` [PATCH 3/6] net: add nameserver and domainname to net devices Sascha Hauer
@ 2012-04-15 13:26 ` Sascha Hauer
2012-04-15 13:26 ` [PATCH 5/6] dns: use global nameserver/domainname Sascha Hauer
2012-04-15 13:26 ` [PATCH 6/6] fs tftp: use resolv to resolv ip address Sascha Hauer
5 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2012-04-15 13:26 UTC (permalink / raw)
To: barebox
nameserver and domainname are now netdevice parameters. Use them.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
net/dhcp.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/net/dhcp.c b/net/dhcp.c
index 0116ba4..82ab100 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -104,12 +104,21 @@ 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 nameserver_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
{
IPaddr_t ip;
ip = net_read_ip(popt);
- setenv_ip(opt->barebox_var_name, ip);
+ net_set_nameserver(ip);
+}
+
+static void domainname_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
+{
+ char str[256];
+
+ memcpy(str, popt, optlen);
+ str[optlen] = 0;
+ net_set_domainname(str);
}
static void env_str_handle(struct dhcp_opt *opt, unsigned char *popt, int optlen)
@@ -169,16 +178,14 @@ struct dhcp_opt dhcp_options[] = {
.handle = gateway_handle,
}, {
.option = 6,
- .handle = env_ip_handle,
- .barebox_var_name = "nameserver",
+ .handle = nameserver_handle,
}, {
.option = 12,
.handle = env_str_handle,
.barebox_var_name = "hostname",
}, {
.option = 15,
- .handle = env_str_handle,
- .barebox_var_name = "domainname",
+ .handle = domainname_handle,
}, {
.option = 17,
.handle = env_str_handle,
@@ -697,9 +704,7 @@ BAREBOX_CMD_START(dhcp)
BAREBOX_CMD_END
BAREBOX_MAGICVAR(bootfile, "bootfile returned from DHCP request");
-BAREBOX_MAGICVAR(nameserver, "Nameserver returned from DHCP request");
BAREBOX_MAGICVAR(hostname, "hostname returned from DHCP request");
-BAREBOX_MAGICVAR(domainname, "domainname returned from DHCP request");
BAREBOX_MAGICVAR(rootpath, "rootpath returned from DHCP request");
BAREBOX_MAGICVAR(dhcp_vendor_id, "vendor id to send to the DHCP server");
BAREBOX_MAGICVAR(dhcp_client_uuid, "cliend uuid to send to the DHCP server");
--
1.7.10
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 5/6] dns: use global nameserver/domainname
2012-04-15 13:26 dns work Sascha Hauer
` (3 preceding siblings ...)
2012-04-15 13:26 ` [PATCH 4/6] dhcp: set global domainname and nameserver Sascha Hauer
@ 2012-04-15 13:26 ` Sascha Hauer
2012-04-15 13:26 ` [PATCH 6/6] fs tftp: use resolv to resolv ip address Sascha Hauer
5 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2012-04-15 13:26 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
net/dns.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/dns.c b/net/dns.c
index 0d6c337..81fa2ae 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -77,7 +77,7 @@ static int dns_send(char *name)
header->nauth = 0;
header->nother = 0;
- domain = getenv("domainname");
+ domain = net_get_domainname();
if (!strchr(name, '.') && domain && *domain)
fullname = asprintf(".%s.%s.", name, domain);
@@ -205,11 +205,11 @@ IPaddr_t resolv(char *host)
dns_state = STATE_INIT;
- ip = getenv_ip_dns("nameserver", 0);
+ ip = net_get_nameserver();
if (!ip)
return 0;
- debug("resolving host %s via nameserver %s\n", host, getenv("nameserver"));
+ debug("resolving host %s via nameserver %s\n", host, ip_to_string(ip));
dns_con = net_udp_new(ip, DNS_PORT, dns_handler, NULL);
if (IS_ERR(dns_con))
--
1.7.10
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 6/6] fs tftp: use resolv to resolv ip address
2012-04-15 13:26 dns work Sascha Hauer
` (4 preceding siblings ...)
2012-04-15 13:26 ` [PATCH 5/6] dns: use global nameserver/domainname Sascha Hauer
@ 2012-04-15 13:26 ` Sascha Hauer
5 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2012-04-15 13:26 UTC (permalink / raw)
To: barebox
instead of assuming the backingstore is a ip address, use resolv()
to make it possible to pass in a hostname.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
fs/tftp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/tftp.c b/fs/tftp.c
index 463e0fc..e8a209e 100644
--- a/fs/tftp.c
+++ b/fs/tftp.c
@@ -603,7 +603,7 @@ static int tftp_probe(struct device_d *dev)
dev->priv = priv;
- string_to_ip(fsdev->backingstore, &priv->server);
+ priv->server = resolv(fsdev->backingstore);
return 0;
}
--
1.7.10
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread