
On Wed, Jan 25, 2017 at 3:56 AM, Chris Packham judge.packham@gmail.com wrote:
Create net6.c and add CONFIG_NET6 to Kconfig/Makefile. Also add support for the following environment variables:
- ip6addr
- gateway6
- serverip6
Signed-off-by: Chris Packham judge.packham@gmail.com
Changes in v3: None Changes in v2:
- Split environment variables from main implementation
- remove "prefixlength6" environment variable. The prefix length is now set when specifying the address i.e. setenv ip6addr 2001:db8::1/64.
include/env_callback.h | 8 +++++ include/env_flags.h | 9 +++++ net/Kconfig | 6 +++- net/Makefile | 1 + net/net6.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 net/net6.c
diff --git a/include/env_callback.h b/include/env_callback.h index 90b95b5e6676..97e245bff09d 100644 --- a/include/env_callback.h +++ b/include/env_callback.h @@ -60,6 +60,13 @@ #define NET_CALLBACKS #endif
+#ifdef CONFIG_NET6 +#define NET6_CALLBACKS \
"ip6addr:ip6addr," \
"serverip6:serverip6,"
+#else +#define NET6_CALLBACKS +#endif /*
- This list of callback bindings is static, but may be overridden by defining
- a new association in the ".callbacks" environment variable.
@@ -68,6 +75,7 @@ ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \ "baudrate:baudrate," \ NET_CALLBACKS \
NET6_CALLBACKS \ "loadaddr:loadaddr," \ SILENT_CALLBACK \ SPLASHIMAGE_CALLBACK \
diff --git a/include/env_flags.h b/include/env_flags.h index 0dcec0689b19..916e4bec394f 100644 --- a/include/env_flags.h +++ b/include/env_flags.h @@ -65,6 +65,14 @@ enum env_flags_varaccess { #define NET_FLAGS #endif
+#ifdef CONFIG_NET6 +#define NET6_FLAGS \
"ip6addr:s," \
"serverip6:s,"
It would be good to add a flag that validates the address format. Maybe '6' can be the flag (needs to be a single char). This could come later, but as it is, the has basically no meaning because 's' is already the default.
+#else +#define NET6_FLAGS +#endif
#ifndef CONFIG_ENV_OVERWRITE #define SERIAL_FLAGS "serial#:so," #else @@ -74,6 +82,7 @@ enum env_flags_varaccess { #define ENV_FLAGS_LIST_STATIC \ ETHADDR_FLAGS \ NET_FLAGS \
NET6_FLAGS \ SERIAL_FLAGS \ CONFIG_ENV_FLAGS_LIST_STATIC
diff --git a/net/Kconfig b/net/Kconfig index 414c5497c758..bc70cc59defd 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -32,6 +32,11 @@ config NET_TFTP_VARS If unset, timeout and maximum are hard-defined as 1 second and 10 timouts per TFTP transfer.
+config NET6
bool "IPv6 support"
help
Support for IPv6
config BOOTP_PXE_CLIENTARCH hex default 0x16 if ARM64 @@ -44,5 +49,4 @@ config BOOTP_VCI_STRING default "U-Boot.armv8" if ARM64 default "U-Boot.arm" if ARM default "U-Boot"
endif # if NET diff --git a/net/Makefile b/net/Makefile index f03d6083268f..b5e8c5c758c9 100644 --- a/net/Makefile +++ b/net/Makefile @@ -25,3 +25,4 @@ obj-$(CONFIG_CMD_PING) += ping.o obj-$(CONFIG_CMD_RARP) += rarp.o obj-$(CONFIG_CMD_SNTP) += sntp.o obj-$(CONFIG_CMD_NET) += tftp.o +obj-$(CONFIG_NET6) += net6.o diff --git a/net/net6.c b/net/net6.c new file mode 100644 index 000000000000..f778cef5ada9 --- /dev/null +++ b/net/net6.c @@ -0,0 +1,89 @@ +/*
- Simple IPv6 network layer implementation.
- Based and/or adapted from the IPv4 network layer in net.[hc]
- (C) Copyright 2013 Allied Telesis Labs NZ
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <environment.h> +#include <malloc.h> +#include <net.h> +#include <net6.h> +#include "ndisc.h"
+/* Our gateway's IPv6 address */ +struct in6_addr net_gateway6 = ZERO_IPV6_ADDR; +/* Our IPv6 addr (0 = unknown) */ +struct in6_addr net_ip6 = ZERO_IPV6_ADDR; +/* set server IPv6 addr (0 = unknown) */ +struct in6_addr net_server_ip6 = ZERO_IPV6_ADDR; +/* The prefix length of our network */ +u_int32_t net_prefix_length;
+static int on_ip6addr(const char *name, const char *value, enum env_op op,
int flags)
+{
char *v, *s, *strcopy;
int i;
if (flags & H_PROGRAMMATIC)
return 0;
if (op == env_op_delete) {
net_prefix_length = 0;
net_copy_ip6(&net_ip6, &net_null_addr_ip6);
return 0;
}
strcopy = strdup(value);
if (strcopy == NULL)
return -1;
net_prefix_length = 128;
i = 0;
s = strcopy;
while (s) {
v = strsep(&s, "/");
if (!v)
break;
switch (i++) {
case 0:
string_to_ip6(v, &net_ip6);
break;
case 1:
net_prefix_length = simple_strtoul(v, NULL, 10);
break;
default:
break;
}
}
free(strcopy);
return 0;
+} +U_BOOT_ENV_CALLBACK(ip6addr, on_ip6addr);
+static int on_gatewayip6(const char *name, const char *value, enum env_op op,
int flags)
+{
if (flags & H_PROGRAMMATIC)
return 0;
return string_to_ip6(value, &net_gateway6);
+} +U_BOOT_ENV_CALLBACK(gatewayip6, on_gatewayip6);
+static int on_serverip6(const char *name, const char *value, enum env_op op,
int flags)
+{
if (flags & H_PROGRAMMATIC)
return 0;
return string_to_ip6(value, &net_server_ip6);
+}
+U_BOOT_ENV_CALLBACK(serverip6, on_serverip6);
2.11.0.24.ge6920cf
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot