* [PATCH 1/9] net: ip_route_get: Fix error message
2019-01-07 7:39 [PATCH 0/9] net: Allow global.net.server being a hostname Sascha Hauer
@ 2019-01-07 7:40 ` Sascha Hauer
2019-01-07 7:40 ` [PATCH 2/9] net: ip_route_get: Hook help text to command Sascha Hauer
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2019-01-07 7:40 UTC (permalink / raw)
To: Barebox List
We do getopt(), so the next argument is in argv[optind], not in argv[1].
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/ip-route-get.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/commands/ip-route-get.c b/commands/ip-route-get.c
index d393218188..7c304694db 100644
--- a/commands/ip-route-get.c
+++ b/commands/ip-route-get.c
@@ -42,8 +42,8 @@ static int do_ip_route_get(int argc, char *argv[])
ret = string_to_ip(argv[optind], &ip);
if (ret) {
- printf("Cannot convert %s into a IP address: %s\n",
- argv[1], strerror(-ret));
+ printf("Cannot convert \"%s\" into a IP address: %s\n",
+ argv[optind], strerror(-ret));
return 1;
}
--
2.19.1
_______________________________________________
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/9] net: ip_route_get: Hook help text to command
2019-01-07 7:39 [PATCH 0/9] net: Allow global.net.server being a hostname Sascha Hauer
2019-01-07 7:40 ` [PATCH 1/9] net: ip_route_get: Fix error message Sascha Hauer
@ 2019-01-07 7:40 ` Sascha Hauer
2019-01-07 7:40 ` [PATCH 3/9] net: dns: leave host command with error on failure Sascha Hauer
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2019-01-07 7:40 UTC (permalink / raw)
To: Barebox List
The help text is present but not hooked into the command structure. Fix
this.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/ip-route-get.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/commands/ip-route-get.c b/commands/ip-route-get.c
index 7c304694db..b3d4ecce82 100644
--- a/commands/ip-route-get.c
+++ b/commands/ip-route-get.c
@@ -93,4 +93,5 @@ BAREBOX_CMD_START(ip_route_get)
BAREBOX_CMD_OPTS("[-b] <IP> [variable]")
BAREBOX_CMD_GROUP(CMD_GRP_MISC)
BAREBOX_CMD_COMPLETE(empty_complete)
+ BAREBOX_CMD_HELP(cmd_ip_route_get_help)
BAREBOX_CMD_END
--
2.19.1
_______________________________________________
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/9] net: dns: leave host command with error on failure
2019-01-07 7:39 [PATCH 0/9] net: Allow global.net.server being a hostname Sascha Hauer
2019-01-07 7:40 ` [PATCH 1/9] net: ip_route_get: Fix error message Sascha Hauer
2019-01-07 7:40 ` [PATCH 2/9] net: ip_route_get: Hook help text to command Sascha Hauer
@ 2019-01-07 7:40 ` Sascha Hauer
2019-01-07 7:40 ` [PATCH 4/9] net: dns: Allow to set variable with the resolved host Sascha Hauer
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2019-01-07 7:40 UTC (permalink / raw)
To: Barebox List
When we can't resolv a host we should return an error rather than just
successfully.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
net/dns.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/net/dns.c b/net/dns.c
index 4516235df2..d241781939 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -258,15 +258,20 @@ static int do_host(int argc, char *argv[])
{
IPaddr_t ip;
int ret;
+ char *hostname;
if (argc != 2)
return COMMAND_ERROR_USAGE;
+ hostname = argv[1];
+
ret = resolv(argv[1], &ip);
- if (ret)
- printf("unknown host %s\n", argv[1]);
- else
- printf("%s is at %pI4\n", argv[1], &ip);
+ if (ret) {
+ printf("unknown host %s\n", hostname);
+ return 1;
+ }
+
+ printf("%s is at %pI4\n", hostname, &ip);
return 0;
}
--
2.19.1
_______________________________________________
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/9] net: dns: Allow to set variable with the resolved host
2019-01-07 7:39 [PATCH 0/9] net: Allow global.net.server being a hostname Sascha Hauer
` (2 preceding siblings ...)
2019-01-07 7:40 ` [PATCH 3/9] net: dns: leave host command with error on failure Sascha Hauer
@ 2019-01-07 7:40 ` Sascha Hauer
2019-01-07 7:40 ` [PATCH 5/9] defaultenv: Pass serverip to nfsroot string Sascha Hauer
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2019-01-07 7:40 UTC (permalink / raw)
To: Barebox List
Add an additional [VARIABLE] parameter to the host command to allow
setting a variable with the resolved IP address.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
net/dns.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/net/dns.c b/net/dns.c
index d241781939..ffe98ef9e3 100644
--- a/net/dns.c
+++ b/net/dns.c
@@ -258,20 +258,26 @@ static int do_host(int argc, char *argv[])
{
IPaddr_t ip;
int ret;
- char *hostname;
+ char *hostname, *varname = NULL;
- if (argc != 2)
+ if (argc < 2)
return COMMAND_ERROR_USAGE;
hostname = argv[1];
+ if (argc > 2)
+ varname = argv[2];
+
ret = resolv(argv[1], &ip);
if (ret) {
printf("unknown host %s\n", hostname);
return 1;
}
- printf("%s is at %pI4\n", hostname, &ip);
+ if (varname)
+ setenv_ip(varname, ip);
+ else
+ printf("%s is at %pI4\n", hostname, &ip);
return 0;
}
@@ -279,7 +285,7 @@ static int do_host(int argc, char *argv[])
BAREBOX_CMD_START(host)
.cmd = do_host,
BAREBOX_CMD_DESC("resolve a hostname")
- BAREBOX_CMD_OPTS("HOSTNAME")
+ BAREBOX_CMD_OPTS("<HOSTNAME> [VARIABLE]")
BAREBOX_CMD_GROUP(CMD_GRP_NET)
BAREBOX_CMD_END
#endif
--
2.19.1
_______________________________________________
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/9] defaultenv: Pass serverip to nfsroot string
2019-01-07 7:39 [PATCH 0/9] net: Allow global.net.server being a hostname Sascha Hauer
` (3 preceding siblings ...)
2019-01-07 7:40 ` [PATCH 4/9] net: dns: Allow to set variable with the resolved host Sascha Hauer
@ 2019-01-07 7:40 ` Sascha Hauer
2019-01-07 7:40 ` [PATCH 6/9] net: Allow hostnames for global.net.server Sascha Hauer
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2019-01-07 7:40 UTC (permalink / raw)
To: Barebox List
This is necessary to allow overwriting the NFS server Linux boots from.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
defaultenv/defaultenv-2-base/boot/net | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/defaultenv/defaultenv-2-base/boot/net b/defaultenv/defaultenv-2-base/boot/net
index aaa5394f27..840e9fc1f0 100644
--- a/defaultenv/defaultenv-2-base/boot/net
+++ b/defaultenv/defaultenv-2-base/boot/net
@@ -9,7 +9,7 @@ if [ -f "${oftree}" ]; then
global.bootm.oftree="$oftree"
fi
-nfsroot="/home/${global.user}/nfsroot/${global.hostname}"
+nfsroot="${global.net.server}:/home/${global.user}/nfsroot/${global.hostname}"
ip_route_get -b ${global.net.server} global.linux.bootargs.dyn.ip
--
2.19.1
_______________________________________________
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/9] net: Allow hostnames for global.net.server
2019-01-07 7:39 [PATCH 0/9] net: Allow global.net.server being a hostname Sascha Hauer
` (4 preceding siblings ...)
2019-01-07 7:40 ` [PATCH 5/9] defaultenv: Pass serverip to nfsroot string Sascha Hauer
@ 2019-01-07 7:40 ` Sascha Hauer
2019-01-07 7:40 ` [PATCH 7/9] net: ip_route_get: resolv hostnames Sascha Hauer
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2019-01-07 7:40 UTC (permalink / raw)
To: Barebox List
Additional to IPv4 addresses add support for global.net.server being a
hostname.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
Documentation/user/networking.rst | 4 ++--
net/eth.c | 4 ++--
net/net.c | 19 ++++++++++++++-----
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/Documentation/user/networking.rst b/Documentation/user/networking.rst
index 6bb99b0da2..9231ebde56 100644
--- a/Documentation/user/networking.rst
+++ b/Documentation/user/networking.rst
@@ -45,8 +45,8 @@ device:
| | | any directly visible subnet. May be set |
| | | automatically by DHCP. |
+------------------------------+--------------+------------------------------------------------+
-| global.net.server | ipv4 host | The default server address. If unspecified, may|
-| | | be set by DHCP |
+| global.net.server | hostname or | The default server. If unspecified, may be set |
+| | ipv4 address | by DHCP |
+------------------------------+--------------+------------------------------------------------+
| global.net.nameserver | ipv4 address | The DNS server used for resolving host names. |
| | | May be set by DHCP |
diff --git a/net/eth.c b/net/eth.c
index b3e81247c2..53d24baa16 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -344,7 +344,7 @@ static int eth_register_of_fixup(void)
late_initcall(eth_register_of_fixup);
#endif
-extern IPaddr_t net_serverip;
+extern char *net_server;
extern IPaddr_t net_gateway;
static const char * const eth_mode_names[] = {
@@ -384,7 +384,7 @@ int eth_register(struct eth_device *edev)
edev->devname = xstrdup(dev_name(&edev->dev));
dev_add_param_ip(dev, "ipaddr", NULL, NULL, &edev->ipaddr, edev);
- dev_add_param_ip(dev, "serverip", NULL, NULL, &net_serverip, edev);
+ dev_add_param_string(dev, "serverip", NULL, NULL, &net_server, edev);
dev_add_param_ip(dev, "gateway", NULL, NULL, &net_gateway, edev);
dev_add_param_ip(dev, "netmask", NULL, NULL, &edev->netmask, edev);
dev_add_param_mac(dev, "ethaddr", eth_param_set_ethaddr, NULL,
diff --git a/net/net.c b/net/net.c
index f1a7df0298..0d889ddb52 100644
--- a/net/net.c
+++ b/net/net.c
@@ -44,7 +44,7 @@
unsigned char *NetRxPackets[PKTBUFSRX]; /* Receive packets */
static unsigned int net_ip_id;
-IPaddr_t net_serverip;
+char *net_server;
IPaddr_t net_gateway;
static IPaddr_t net_nameserver;
static char *net_domainname;
@@ -271,17 +271,26 @@ static uint16_t net_udp_new_localport(void)
IPaddr_t net_get_serverip(void)
{
- return net_serverip;
+ IPaddr_t ip;
+ int ret;
+
+ ret = resolv(net_server, &ip);
+ if (ret)
+ return 0;
+
+ return ip;
}
void net_set_serverip(IPaddr_t ip)
{
- net_serverip = ip;
+ free(net_server);
+
+ net_server = xasprintf("%pI4", &ip);
}
void net_set_serverip_empty(IPaddr_t ip)
{
- if (net_serverip)
+ if (net_server && *net_server)
return;
net_set_serverip(ip);
@@ -647,7 +656,7 @@ static int net_init(void)
globalvar_add_simple_ip("net.nameserver", &net_nameserver);
globalvar_add_simple_string("net.domainname", &net_domainname);
- globalvar_add_simple_ip("net.server", &net_serverip);
+ globalvar_add_simple_string("net.server", &net_server);
globalvar_add_simple_ip("net.gateway", &net_gateway);
return 0;
--
2.19.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 7/9] net: ip_route_get: resolv hostnames
2019-01-07 7:39 [PATCH 0/9] net: Allow global.net.server being a hostname Sascha Hauer
` (5 preceding siblings ...)
2019-01-07 7:40 ` [PATCH 6/9] net: Allow hostnames for global.net.server Sascha Hauer
@ 2019-01-07 7:40 ` Sascha Hauer
2019-01-07 7:40 ` [PATCH 8/9] defaultenv: defaultenv uses ip_route_get Sascha Hauer
2019-01-07 7:40 ` [PATCH 9/9] defaultenv: resolve global.net.server before using it Sascha Hauer
8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2019-01-07 7:40 UTC (permalink / raw)
To: Barebox List
When global.net.server is a hostname instead of an IP address we have to
resolv it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/ip-route-get.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/commands/ip-route-get.c b/commands/ip-route-get.c
index b3d4ecce82..d3c15b7798 100644
--- a/commands/ip-route-get.c
+++ b/commands/ip-route-get.c
@@ -40,7 +40,7 @@ static int do_ip_route_get(int argc, char *argv[])
if (argc == optind + 2)
variable = argv[optind + 1];
- ret = string_to_ip(argv[optind], &ip);
+ ret = resolv(argv[optind], &ip);
if (ret) {
printf("Cannot convert \"%s\" into a IP address: %s\n",
argv[optind], strerror(-ret));
--
2.19.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 8/9] defaultenv: defaultenv uses ip_route_get
2019-01-07 7:39 [PATCH 0/9] net: Allow global.net.server being a hostname Sascha Hauer
` (6 preceding siblings ...)
2019-01-07 7:40 ` [PATCH 7/9] net: ip_route_get: resolv hostnames Sascha Hauer
@ 2019-01-07 7:40 ` Sascha Hauer
2019-01-07 7:40 ` [PATCH 9/9] defaultenv: resolve global.net.server before using it Sascha Hauer
8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2019-01-07 7:40 UTC (permalink / raw)
To: Barebox List
The default environment uses the ip_route_get command, so select it
when networking is enabled.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/Kconfig | 1 +
1 file changed, 1 insertion(+)
diff --git a/common/Kconfig b/common/Kconfig
index 2ad92158c1..1c2669084a 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -866,6 +866,7 @@ config DEFAULT_ENVIRONMENT_GENERIC_NEW
select FLEXIBLE_BOOTARGS
select CMD_BOOT
select NET_CMD_IFUP if NET
+ select CMD_IP_ROUTE_GET if NET
config DEFAULT_ENVIRONMENT_GENERIC
bool "Generic environment template (old version)"
--
2.19.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 9/9] defaultenv: resolve global.net.server before using it
2019-01-07 7:39 [PATCH 0/9] net: Allow global.net.server being a hostname Sascha Hauer
` (7 preceding siblings ...)
2019-01-07 7:40 ` [PATCH 8/9] defaultenv: defaultenv uses ip_route_get Sascha Hauer
@ 2019-01-07 7:40 ` Sascha Hauer
8 siblings, 0 replies; 10+ messages in thread
From: Sascha Hauer @ 2019-01-07 7:40 UTC (permalink / raw)
To: Barebox List
global.net.server may contain a hostname, so we have to resolve it
before using it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/Kconfig | 1 +
defaultenv/defaultenv-2-base/boot/net | 8 +++++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/common/Kconfig b/common/Kconfig
index 1c2669084a..b522a86ad4 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -867,6 +867,7 @@ config DEFAULT_ENVIRONMENT_GENERIC_NEW
select CMD_BOOT
select NET_CMD_IFUP if NET
select CMD_IP_ROUTE_GET if NET
+ select CMD_HOST if NET
config DEFAULT_ENVIRONMENT_GENERIC
bool "Generic environment template (old version)"
diff --git a/defaultenv/defaultenv-2-base/boot/net b/defaultenv/defaultenv-2-base/boot/net
index 840e9fc1f0..f8895290ad 100644
--- a/defaultenv/defaultenv-2-base/boot/net
+++ b/defaultenv/defaultenv-2-base/boot/net
@@ -9,7 +9,13 @@ if [ -f "${oftree}" ]; then
global.bootm.oftree="$oftree"
fi
-nfsroot="${global.net.server}:/home/${global.user}/nfsroot/${global.hostname}"
+host ${global.net.server} nfsserver
+if [ $? != 0 ]; then
+ echo "Cannot resolve \"${global.net.server}\""
+ exit 1
+fi
+
+nfsroot="${nfsserver}:/home/${global.user}/nfsroot/${global.hostname}"
ip_route_get -b ${global.net.server} global.linux.bootargs.dyn.ip
--
2.19.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 10+ messages in thread