All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Packham <judge.packham@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH v2 06/11] net: IPv6 skeleton and environment variables
Date: Mon,  9 Nov 2015 20:38:51 +1300	[thread overview]
Message-ID: <1447054736-27658-7-git-send-email-judge.packham@gmail.com> (raw)
In-Reply-To: <1447054736-27658-1-git-send-email-judge.packham@gmail.com>

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 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            |  5 +++
 net/Makefile           |  1 +
 net/net6.c             | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 112 insertions(+)
 create mode 100644 net/net6.c

diff --git a/include/env_callback.h b/include/env_callback.h
index 90b95b5..97e245b 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 8823fb9..bf93f15 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,"
+#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 a44a783..bacd914 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -32,4 +32,9 @@ 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
+
 endif   # if NET
diff --git a/net/Makefile b/net/Makefile
index e9cc8ad..6da8019 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -20,3 +20,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 0000000..f778cef
--- /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.5.3

  parent reply	other threads:[~2015-11-09  7:38 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-09  7:38 [U-Boot] [RFC PATCH v2 00/11] IPv6 support Chris Packham
2015-11-09  7:38 ` [U-Boot] [RFC PATCH v2 01/11] Initial net6.h Chris Packham
2015-11-24  1:05   ` Joe Hershberger
2015-11-09  7:38 ` [U-Boot] [RFC PATCH v2 02/11] lib: vsprintf: add IPv6 compressed format %pI6c Chris Packham
2015-11-24  1:06   ` Joe Hershberger
2015-11-09  7:38 ` [U-Boot] [RFC PATCH v2 03/11] lib: net_utils: make string_to_ip stricter Chris Packham
2015-11-24  1:06   ` Joe Hershberger
2015-11-24  9:37     ` Chris Packham
2015-11-09  7:38 ` [U-Boot] [RFC PATCH v2 04/11] lib: net_utils: add string_to_ip6 Chris Packham
2015-11-24  1:06   ` Joe Hershberger
2015-11-09  7:38 ` [U-Boot] [RFC PATCH v2 05/11] net: add definition of udp_hdr Chris Packham
2015-11-24  1:06   ` Joe Hershberger
2015-11-09  7:38 ` Chris Packham [this message]
2015-11-24  1:06   ` [U-Boot] [RFC PATCH v2 06/11] net: IPv6 skeleton and environment variables Joe Hershberger
2015-11-24  9:47     ` Chris Packham
2015-11-09  7:38 ` [U-Boot] [RFC PATCH v2 07/11] net: IPv6 support Chris Packham
2015-11-24  1:06   ` Joe Hershberger
2015-11-09  7:38 ` [U-Boot] [RFC PATCH v2 08/11] net: Add ping6 command and implementation Chris Packham
2015-11-24  1:06   ` Joe Hershberger
2015-11-09  7:38 ` [U-Boot] [RFC PATCH v2 09/11] net: TFTP over IPv6 Chris Packham
2015-11-24  1:07   ` Joe Hershberger
2015-11-09  7:38 ` [U-Boot] [RFC PATCH v2 10/11] net: IPv6 documentation Chris Packham
2015-11-09  7:38 ` [U-Boot] [RFC PATCH v2 11/11] net: e1000 enable multicast reception Chris Packham
2015-11-24  1:07   ` Joe Hershberger

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=1447054736-27658-7-git-send-email-judge.packham@gmail.com \
    --to=judge.packham@gmail.com \
    --cc=u-boot@lists.denx.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.