Skip to contentSkip to conversation

IPv6 support

RFC PATCH New Chris Packham 5 participants 24 messages Jan 25, 2017 – Feb 6, 2017 2 messages not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover IPv6 support

This series adds basic IPv6 support to U-boot. It is a reboot of my earlier work on this[1]. This latest version is itself a reboot of work that was last posted to the list in late 2015. Right now I've just rebased against master so functionally it is little different to what was last posted.

Most of this is ported from Allied Telesis' additions to u-boot[2]. (Note that I am employed by Allied Telesis[3]). The hard work was done some time ago by Angga, I've cleaned it up and made some improvements with the hope of getting it accepted upstream.

A few open issues

1) rxhand_f currently takes an struct in_addr. TFTP doesn't use this (I haven't looked at other users). To support V6 this may need to be a new union, a void * with some kind of flag or nothing if no rxhandler actually cares. It has been suggested that this parameter be removed and any users that care can re-parse the packet.

2) Unit tests. This code needs them. The testing so-far has been ad-hoc manual testing using qemu-x86.

3) Fancy v6 feature xyz. There are a lot of things that _could_ be implemented on top of this (DHCPV6 and SLAAC are two obvious things that stick out). For now I want to concentrate on getting the core code stable and accepted, if anyone else wants to work on either of those features that'd be great.

--
[1] - http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/151390
[2] - http://www.alliedtelesis.co.nz/support/gpl/other.html
[3] - some of this has been done on work time, other parts have been done in my personal time. Since I'm subscribed to the list using my gmail account I've signed using that.

Changes in v3:
- Add brief testing section

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.
- split ping6 support into separate patch
- split environment variables into separate patch
- change ip6_ndisc_* to ndisc_*, fix CamelCase
- split ping6 support into it's own patch
- Support parsing the server address from the command parameter.

Chris Packham (11):
Initial net6.h
lib: vsprintf: add IPv6 compressed format %pI6c
lib: net_utils: add string_to_ip6
net: add definition of udp_hdr
net: IPv6 skeleton and environment variables
net: IPv6 support
net: Add ping6 command and implementation
net: TFTP over IPv6
net: IPv6 documentation
net: e1000 enable multicast reception
net: tsec: enable promiscuous mode

 README                 |   3 +
 cmd/Kconfig            |  15 ++
 cmd/net.c              |  41 +++++
 doc/README.ipv6        |  55 ++++++
 drivers/net/e1000.c    |   5 +
 drivers/net/tsec.c     |   4 +
 include/env_callback.h |   8 +
 include/env_flags.h    |   9 +
 include/net.h          |  18 +-
 include/net6.h         | 262 ++++++++++++++++++++++++++++
 lib/net_utils.c        | 121 +++++++++++++
 lib/vsprintf.c         | 154 ++++++++++++++---
 net/Kconfig            |   6 +-
 net/Makefile           |   3 +
 net/ndisc.c            | 266 ++++++++++++++++++++++++++++
 net/ndisc.h            |  25 +++
 net/net.c              |  40 ++++-
 net/net6.c             | 459 +++++++++++++++++++++++++++++++++++++++++++++++++
 net/ping6.c            | 111 ++++++++++++
 net/tftp.c             |  58 +++++++
 20 files changed, 1635 insertions(+), 28 deletions(-)
 create mode 100644 doc/README.ipv6
 create mode 100644 include/net6.h
 create mode 100644 net/ndisc.c
 create mode 100644 net/ndisc.h
 create mode 100644 net/net6.c
 create mode 100644 net/ping6.c
Signature · 1 line
2.11.0.24.ge6920cf
#1 lore raw

RFC PATCH v3 1/11 Initial net6.h

The initial net6.h just has the definition of an IPv6 address and IPv6 header. Subsequent changes will build on this.

---

Changes in v3: None
Changes in v2: None

 include/net6.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 include/net6.h
include/net6.h new file +48 -0
new file mode 100644
index 000000000000..b62295181d45
@@ -0,0 +1,48 @@
+/**
+ * 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+
+ */
+#ifndef __NET6_H__
+#define __NET6_H__
+
+struct in6_addr {
+	union {
+		__u8	u6_addr8[16];
+		__be16	u6_addr16[8];
+		__be32	u6_addr32[4];
+	} in6_u;
+
+#define s6_addr		in6_u.u6_addr8
+#define s6_addr16	in6_u.u6_addr16
+#define s6_addr32	in6_u.u6_addr32
+};
+
+/**
+ * struct ipv6hdr - Internet Protocol V6 (IPv6) header.
+ *
+ * IPv6 packet header as defined in RFC 2460.
+ */
+struct ip6_hdr {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+	__u8    priority:4,
+		version:4;
+#elif defined(__BIG_ENDIAN_BITFIELD)
+	__u8    version:4,
+		priority:4;
+#else
+#error  "Please fix <asm/byteorder.h>"
+#endif
+	__u8		flow_lbl[3];
+	__be16		payload_len;
+	__u8		nexthdr;
+	__u8		hop_limit;
+	struct in6_addr	saddr;
+	struct in6_addr	daddr;
+};
+
+#endif /* __NET6_H__ */
Signature · 1 line
2.11.0.24.ge6920cf
#2 lore raw

RFC PATCH v3 2/11 lib: vsprintf: add IPv6 compressed format %pI6c

In reply to Chris Packham

Add support for "human friendly" IPv6 address representations as specified in https://www.rfc-editor.org/rfc/rfc5952.txt

This code has been adapted from Linux kernel with minimal modification.

---

Changes in v3: None
Changes in v2: None

 include/net6.h |  13 +++++
 lib/vsprintf.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 144 insertions(+), 23 deletions(-)
include/net6.h +13 -0
index b62295181d45..1b82c25ec76e 100644
@@ -45,4 +45,17 @@ struct ip6_hdr {
 	struct in6_addr	daddr;
 };
 
+/* ::ffff:0:0/96 is reserved for v4 mapped addresses */
+static inline int ipv6_addr_v4mapped(const struct in6_addr *a)
+{
+	return (a->s6_addr32[0] | a->s6_addr32[1] |
+		(a->s6_addr32[2] ^ htonl(0x0000ffff))) == 0;
+}
+
+/* Intra-Site Automatic Tunnel Addressing Protocol Address */
+static inline int ipv6_addr_is_isatap(const struct in6_addr *a)
+{
+	return (a->s6_addr32[2] | htonl(0x02000000)) == htonl(0x02005EFE);
+}
+
 #endif /* __NET6_H__ */
lib/vsprintf.c +131 -23

200 lines not on this page · raw message

Signature · 1 line
2.11.0.24.ge6920cf
#3 lore raw

RFC PATCH v3 2/11 lib: vsprintf: add IPv6 compressed format %pI6c

Quoted 6 lines · Chris Packham

Add support for "human friendly" IPv6 address representations as specified in https://www.rfc-editor.org/rfc/rfc5952.txt

This code has been adapted from Linux kernel with minimal modification.

Quoted 8 lines

---

Changes in v3: None
Changes in v2: None

 include/net6.h |  13 +++++
 lib/vsprintf.c | 154 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 144 insertions(+), 23 deletions(-)

Can you please add function comments for these?

ip6_addr_string()
ip6_compressed_string()

#4 lore raw

RFC PATCH v3 3/11 lib: net_utils: add string_to_ip6

In reply to Chris Packham

string_to_ip6 parses an IPv6 address from a string. Parsing v6 addresses is a bit more complicated than parsing v4 because there are a number of different formats that can be used.

---
I'm sure the parsing can be better and done in less code with only a single pass but I haven't yet figured it out. The main problem is that "::" can represent a variable number of contiguous "0000:" so when parsing "::" we can't tell how many half words to skip.

Changes in v3: None
Changes in v2: None

 include/net6.h  |   3 ++
 lib/net_utils.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+)
include/net6.h +3 -0
index 1b82c25ec76e..a41eb876fc53 100644
@@ -58,4 +58,7 @@ static inline int ipv6_addr_is_isatap(const struct in6_addr *a)
 	return (a->s6_addr32[2] | htonl(0x02000000)) == htonl(0x02005EFE);
 }
 
+/* Convert a string to an ipv6 address */
+int string_to_ip6(const char *s, struct in6_addr *addr);
+
 #endif /* __NET6_H__ */
lib/net_utils.c +121 -0

130 lines not on this page · raw message

Signature · 1 line
2.11.0.24.ge6920cf
#5 lore raw

RFC PATCH v3 3/11 lib: net_utils: add string_to_ip6

Hi Chris,

Quoted 12 lines · Chris Packham

string_to_ip6 parses an IPv6 address from a string. Parsing v6 addresses is a bit more complicated than parsing v4 because there are a number of different formats that can be used.

---
I'm sure the parsing can be better and done in less code with only a single pass but I haven't yet figured it out. The main problem is that "::" can represent a variable number of contiguous "0000:" so when parsing "::" we can't tell how many half words to skip.

Quoted 6 lines

Changes in v3: None
Changes in v2: None

 include/net6.h  |   3 ++
 lib/net_utils.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+)

But I'd like to see a test for this. You could write something like test/net_ut and have it called by the pytests. I think it is valuable to have tests to verify the behaviour and make it easier to change / improve the code later.

#6 lore raw

RFC PATCH v3 4/11 net: add definition of udp_hdr

In reply to Chris Packham

UDP is the same over IPv4 as it is over other protocols (i.e. IPv6) add a definition of just the UDP header independent of the IPv4 header that it may or may not be combined with.

---
Ideally struct ip_udp_hdr would be defined as

  struct ip_udp_hdr {
          struct ip_hdr  ip;
          struct udp_hdr udp;
  };

Implementing this touches more code that I really want to at this point. Some of the code that currently uses struct ip_udp_hdr could probably just use struct ip_hdr instead but some care would need to be taken to much such a change.

Changes in v3: None
Changes in v2: None

 include/net.h | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
include/net.h +12 -1
index 1f4d94735007..10d98d92535b 100644
@@ -375,6 +375,18 @@ struct ip_hdr {
 #define IP_HDR_SIZE		(sizeof(struct ip_hdr))
 
 /*
+ *	UDP header.
+ */
+struct udp_hdr {
+	__be16		udp_src;	/* UDP source port		*/
+	__be16		udp_dst;	/* UDP destination port		*/
+	__be16		udp_len;	/* Length of UDP packet		*/
+	__be16		udp_xsum;	/* Checksum			*/
+};
+
+#define UDP_HDR_SIZE		(sizeof(struct udp_hdr))
+
+/*
  *	Internet Protocol (IP) + UDP header.
  */
 struct ip_udp_hdr {
@@ -395,7 +407,6 @@ struct ip_udp_hdr {
 };
 
 #define IP_UDP_HDR_SIZE		(sizeof(struct ip_udp_hdr))
-#define UDP_HDR_SIZE		(IP_UDP_HDR_SIZE - IP_HDR_SIZE)
 
 /*
  *	Address Resolution Protocol (ARP) header.
Signature · 1 line
2.11.0.24.ge6920cf
#7 lore raw

RFC PATCH v3 5/11 net: IPv6 skeleton and environment variables

In reply to Chris Packham

Create net6.c and add CONFIG_NET6 to Kconfig/Makefile. Also add support for the following environment variables:
- ip6addr
- gateway6
- serverip6

---

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
include/env_callback.h +8 -0
index 90b95b5e6676..97e245bff09d 100644
@@ -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 \
include/env_flags.h +9 -0
index 0dcec0689b19..916e4bec394f 100644
@@ -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
 
net/Kconfig +5 -1
index 414c5497c758..bc70cc59defd 100644
@@ -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
net/Makefile +1 -0
index f03d6083268f..b5e8c5c758c9 100644
@@ -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
net/net6.c new file +89 -0

89 lines not on this page · raw message

Signature · 1 line
2.11.0.24.ge6920cf
#8 lore raw

RFC PATCH v3 5/11 net: IPv6 skeleton and environment variables

Quoted 54 lines · Chris Packham

Create net6.c and add CONFIG_NET6 to Kconfig/Makefile. Also add support for the following environment variables:
- ip6addr
- gateway6
- serverip6

---

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
include/env_callback.h +8 -0
index 90b95b5e6676..97e245bff09d 100644
@@ -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 \
include/env_flags.h +0 -0
index 0dcec0689b19..916e4bec394f 100644

include/env_flags.h enum env_flags_varaccess { · line 71

Quoted 7 lines
include/env_flags.h +4 -0
@@ -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.

Quoted 148 lines
include/env_flags.h +5 -0
+#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
 
net/Kconfig +5 -1
index 414c5497c758..bc70cc59defd 100644
@@ -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
net/Makefile +1 -0
index f03d6083268f..b5e8c5c758c9 100644
@@ -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
net/net6.c new file +89 -1
new file mode 100644
index 000000000000..f778cef5ada9
@@ -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 at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#9 lore raw

RFC PATCH v3 6/11 net: IPv6 support

In reply to Chris Packham

Adds basic support for IPv6. Neighbor discovery and ping6 are the only things supported at the moment.

---
Now we have something functional. With this and the next patch you can do something like 'setenv ipaddr6 3ffe::1/64' and 'ping6 3ffe::2' should work.

I seem to have a problem that when you send a ping6 for a non-existent address that ends up stuck and the next non-ipv6 net operation tries to resolve it. I suspect this is because the pending neighbor discovery information isn't cleaned up properly, I need to look into that.

Changes in v3: None
Changes in v2:
- split ping6 support into separate patch
- split environment variables into separate patch
- change ip6_ndisc_* to ndisc_*, fix CamelCase

 include/net.h  |   1 +
 include/net6.h | 194 +++++++++++++++++++++++++++++++++++++
 net/Makefile   |   2 +
 net/ndisc.c    | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++
 net/ndisc.h    |  25 +++++
 net/net.c      |  37 ++++++-
 net/net6.c     | 299 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 823 insertions(+), 1 deletion(-)
 create mode 100644 net/ndisc.c
 create mode 100644 net/ndisc.h
include/net.h +1 -0
index 10d98d92535b..b0348adf955e 100644
@@ -341,6 +341,7 @@ struct vlan_ethernet_hdr {
 #define VLAN_ETHER_HDR_SIZE	(sizeof(struct vlan_ethernet_hdr))
 
 #define PROT_IP		0x0800		/* IP protocol			*/
+#define PROT_IP6        0x86DD          /* IPv6 protocol		*/
 #define PROT_ARP	0x0806		/* IP ARP protocol		*/
 #define PROT_RARP	0x8035		/* IP ARP protocol		*/
 #define PROT_VLAN	0x8100		/* IEEE 802.1q protocol		*/
include/net6.h +194 -0

210 lines not on this page · raw message

net/Makefile +2 -0
index b5e8c5c758c9..6967eefffffe 100644
@@ -26,3 +26,5 @@ obj-$(CONFIG_CMD_RARP) += rarp.o
 obj-$(CONFIG_CMD_SNTP) += sntp.o
 obj-$(CONFIG_CMD_NET)  += tftp.o
 obj-$(CONFIG_NET6)     += net6.o
+obj-$(CONFIG_NET6)     += ndisc.o
+obj-$(CONFIG_CMD_PING6) += ping6.o
net/ndisc.c new file +266 -0

266 lines not on this page · raw message

net/ndisc.h new file +25 -0
new file mode 100644
index 000000000000..75138d0a777c
@@ -0,0 +1,25 @@
+/*
+ * net/ndisc.h
+ *
+ * (C) Copyright 2013 Allied Telesis Labs NZ
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+/* IPv6 destination address of packet waiting for ND */
+extern struct in6_addr net_nd_sol_packet_ip6;
+/* MAC destination address of packet waiting for ND */
+extern uchar *net_nd_packet_mac;
+/* pointer to packet waiting to be transmitted after ND is resolved */
+extern uchar *net_nd_tx_packet;
+/* size of packet waiting to be transmitted */
+extern int net_nd_tx_packet_size;
+/* the timer for ND resolution */
+extern ulong net_nd_timer_start;
+/* the number of requests we have sent so far */
+extern int net_nd_try;
+
+void ndisc_init(void);
+void ndisc_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len);
+void ndisc_request(void);
+int ndisc_timeout_check(void);
net/net.c +36 -1
index 6e678770fa9d..527c99f96f9f 100644
@@ -87,6 +87,7 @@
 #include <environment.h>
 #include <errno.h>
 #include <net.h>
+#include <net6.h>
 #include <net/tftp.h>
 #if defined(CONFIG_LED_STATUS)
 #include <miiphy.h>
@@ -95,6 +96,7 @@
 #include <watchdog.h>
 #include <linux/compiler.h>
 #include "arp.h"
+#include "ndisc.h"
 #include "bootp.h"
 #include "cdp.h"
 #if defined(CONFIG_CMD_DNS)
@@ -342,8 +344,12 @@ void net_auto_load(void)
 
 static void net_init_loop(void)
 {
-	if (eth_get_dev())
+	if (eth_get_dev()) {
 		memcpy(net_ethaddr, eth_get_ethaddr(), 6);
+#ifdef CONFIG_NET6
+		ip6_make_lladdr(&net_link_local_ip6, net_ethaddr);
+#endif
+	}
 
 	return;
 }
@@ -377,6 +383,9 @@ void net_init(void)
 				(i + 1) * PKTSIZE_ALIGN;
 		}
 		arp_init();
+#ifdef CONFIG_NET6
+		ndisc_init();
+#endif
 		net_clear_handlers();
 
 		/* Only need to setup buffer pointers once. */
@@ -479,6 +488,11 @@ restart:
 			ping_start();
 			break;
 #endif
+#ifdef CONFIG_CMD_PING6
+		case PING6:
+			ping6_start();
+			break;
+#endif
 #if defined(CONFIG_CMD_NFS)
 		case NFS:
 			nfs_start();
@@ -544,6 +558,11 @@ restart:
 #endif
 		if (arp_timeout_check() > 0)
 			time_start = get_timer(0);
+#ifdef CONFIG_NET6
+		else if (ndisc_timeout_check() > 0)
+			time_start = get_timer(0);
+#endif
+
 
 		/*
 		 *	Check the ethernet for a new packet.  The ethernet
@@ -559,6 +578,9 @@ restart:
 		if (ctrlc()) {
 			/* cancel any ARP that may not have completed */
 			net_arp_wait_packet_ip.s_addr = 0;
+#ifdef CONFIG_NET6
+			net_nd_sol_packet_ip6 = net_null_addr_ip6;
+#endif
 
 			net_cleanup_loop();
 			eth_halt();
@@ -1137,6 +1159,11 @@ void net_process_received_packet(uchar *in_packet, int len)
 		rarp_receive(ip, len);
 		break;
 #endif
+#ifdef CONFIG_NET6
+	case PROT_IP6:
+		net_ip6_handler(et, (struct ip6_hdr *)ip, len);
+		break;
+#endif
 	case PROT_IP:
 		debug_cond(DEBUG_NET_PKT, "Got IP\n");
 		/* Before we start poking the header, make sure it is there */
@@ -1291,6 +1318,14 @@ static int net_check_prereq(enum proto_t protocol)
 		}
 		goto common;
 #endif
+#ifdef CONFIG_CMD_PING6
+	case PING6:
+		if (ip6_is_unspecified_addr(&net_ping_ip6)) {
+			puts("*** ERROR: ping address not given\n");
+			return 1;
+		}
+		goto common;
+#endif
 #if defined(CONFIG_CMD_SNTP)
 	case SNTP:
 		if (net_ntp_server.s_addr == 0) {
net/net6.c +299 -0

318 lines not on this page · raw message

Signature · 1 line
2.11.0.24.ge6920cf
#10 lore raw

RFC PATCH v3 6/11 net: IPv6 support

Hi Chris,

Quoted 22 lines · Chris Packham

Adds basic support for IPv6. Neighbor discovery and ping6 are the only things supported at the moment.

---
Now we have something functional. With this and the next patch you can do something like 'setenv ipaddr6 3ffe::1/64' and 'ping6 3ffe::2' should work.

I seem to have a problem that when you send a ping6 for a non-existent address that ends up stuck and the next non-ipv6 net operation tries to resolve it. I suspect this is because the pending neighbor discovery information isn't cleaned up properly, I need to look into that.

Changes in v3: None
Changes in v2:
- split ping6 support into separate patch
- split environment variables into separate patch
- change ip6_ndisc_* to ndisc_*, fix CamelCase

Quoted 11 lines
 include/net.h  |   1 +
 include/net6.h | 194 +++++++++++++++++++++++++++++++++++++
 net/Makefile   |   2 +
 net/ndisc.c    | 266 ++++++++++++++++++++++++++++++++++++++++++++++++++
 net/ndisc.h    |  25 +++++
 net/net.c      |  37 ++++++-
 net/net6.c     | 299 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 823 insertions(+), 1 deletion(-)
 create mode 100644 net/ndisc.c
 create mode 100644 net/ndisc.h

Looks good to me. I've made a few suggestions below.

Quoted 4 lines
include/net.h +0 -0
index 10d98d92535b..b0348adf955e 100644

[..]

include/net.h

Quoted 4 lines
include/net.h +4 -0
+struct nd_opt_hdr {
+       __u8            nd_opt_type;
+       __u8            nd_opt_len;
+} __attribute__((__packed__));

Can you use __packed?

include/net.h

Quoted 11 lines
include/net.h +11 -0
+
+extern struct in6_addr const net_null_addr_ip6;        /* NULL IPv6 address */
+extern struct in6_addr net_gateway6;   /* Our gateways IPv6 address */
+extern struct in6_addr net_ip6;        /* Our IPv6 addr (0 = unknown) */
+extern struct in6_addr net_link_local_ip6;     /* Our link local IPv6 addr */
+extern u_int32_t net_prefix_length;    /* Our prefixlength (0 = unknown) */
+extern struct in6_addr net_server_ip6; /* Server IPv6 addr (0 = unknown) */
+
+#ifdef CONFIG_CMD_PING
+extern struct in6_addr net_ping_ip6;   /* the ipv6 address to ping */
+#endif

Do these need to be external? Perhaps they should be accessed via functions?

Quoted 12 lines
include/net.h +5 -0
+
 /* ::ffff:0:0/96 is reserved for v4 mapped addresses */
 static inline int ipv6_addr_v4mapped(const struct in6_addr *a)
 {
@@ -61,4 +210,49 @@ static inline int ipv6_addr_is_isatap(const struct in6_addr *a)
 /* Convert a string to an ipv6 address */
 int string_to_ip6(const char *s, struct in6_addr *addr);
 
+/* check that an IPv6 address is unspecified (zero) */
+int ip6_is_unspecified_addr(struct in6_addr *addr);
+
+/* check that an IPv6 address is ours */

include/net.h static inline int ipv6_addr_is_isatap(const struct in6_addr *a) · line 226

Quoted 10 lines
include/net.h +10 -0
+int ip6_is_our_addr(struct in6_addr *addr);
+
+void ip6_make_lladdr(struct in6_addr *lladr, unsigned char const enetaddr[6]);
+
+void ip6_make_snma(struct in6_addr *mcast_addr, struct in6_addr *ip6_addr);
+
+void ip6_make_mult_ethdstaddr(unsigned char enetaddr[6],
+                             struct in6_addr *mcast_addr);
+
+/* check if neighbour is in the same subnet as us */

What does it return in either case? E.g. does 0 mean it does, or does not? Can you beef up the comments on these functions a bit, with arg descriptions and return values?

Quoted 75 lines
include/net.h +31 -0
+int ip6_addr_in_subnet(struct in6_addr *our_addr, struct in6_addr *neigh_addr,
+                      __u32 prefix_length);
+
+unsigned int csum_partial(const unsigned char *buff, int len, unsigned int sum);
+
+unsigned short int csum_ipv6_magic(struct in6_addr *saddr,
+                                  struct in6_addr *daddr, __u16 len,
+                                  unsigned short proto, unsigned int csum);
+
+int ip6_add_hdr(uchar *xip, struct in6_addr *src, struct in6_addr *dest,
+               int nextheader, int hoplimit, int payload_len);
+
+/* sends an IPv6 echo request to a host */
+int ping6_send(void);
+
+/* starts a Ping6 process */
+void ping6_start(void);
+
+/* handles reception of icmpv6 echo request/reply */
+void ping6_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6,
+                         int len);
+
+/* handler for incoming IPv6 echo packet */
+void net_ip6_handler(struct ethernet_hdr *et, struct ip6_hdr *ip6,
+                           int len);
+
+/* copy IPv6 */
+static inline void net_copy_ip6(void *to, const void *from)
+{
+       memcpy((void *)to, from, sizeof(struct in6_addr));
+}
 #endif /* __NET6_H__ */
net/Makefile +2 -0
index b5e8c5c758c9..6967eefffffe 100644
@@ -26,3 +26,5 @@ obj-$(CONFIG_CMD_RARP) += rarp.o
 obj-$(CONFIG_CMD_SNTP) += sntp.o
 obj-$(CONFIG_CMD_NET)  += tftp.o
 obj-$(CONFIG_NET6)     += net6.o
+obj-$(CONFIG_NET6)     += ndisc.o
+obj-$(CONFIG_CMD_PING6) += ping6.o
net/ndisc.c new file +27 -0
new file mode 100644
index 000000000000..290eaeeb9465
@@ -0,0 +1,266 @@
+/*
+ * net/ndisc.c
+ *
+ * (C) Copyright 2013 Allied Telesis Labs NZ
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <net.h>
+#include <net6.h>
+#include "ndisc.h"
+
+/* IPv6 destination address of packet waiting for ND */
+struct in6_addr net_nd_sol_packet_ip6 = ZERO_IPV6_ADDR;
+/* IPv6 address we are expecting ND advert from */
+static struct in6_addr net_nd_rep_packet_ip6 = ZERO_IPV6_ADDR;
+/* MAC destination address of packet waiting for ND */
+uchar *net_nd_packet_mac;
+/* pointer to packet waiting to be transmitted after ND is resolved */
+uchar *net_nd_tx_packet;
+static uchar net_nd_packet_buf[PKTSIZE_ALIGN + PKTALIGN];
+/* size of packet waiting to be transmitted */
+int net_nd_tx_packet_size;
+/* the timer for ND resolution */
+ulong net_nd_timer_start;
+/* the number of requests we have sent so far */

net/ndisc.c line 37

Quoted 10 lines
net/ndisc.c new file +10 -0
+int net_nd_try;
+
+#define IP6_NDISC_OPT_SPACE(len) (((len)+2+7)&~7)
+
+/**
+ * Insert an option into a neighbor discovery packet.
+ * Returns the number of bytes inserted (which may be >= len)
+ */
+static int
+ndisc_insert_option(struct nd_msg *ndisc, int type, u8 *data, int len)

Should join those lines, wrapping the args if needed. Similarly below.

Quoted 9 lines
net/ndisc.c new file +9 -0
+{
+       int space = IP6_NDISC_OPT_SPACE(len);
+
+       ndisc->opt[0] = type;
+       ndisc->opt[1] = space >> 3;
+       memcpy(&ndisc->opt[2], data, len);
+       len += 2;
+
+       /* fill the remainder with 0 */

net/ndisc.c line 56

Quoted 10 lines
net/ndisc.c new file +10 -0
+       if ((space - len) > 0)
+               memset(&ndisc->opt[len], 0, space - len);
+
+       return space;
+}
+
+/**
+ * Extract the Ethernet address from a neighbor discovery packet.
+ * Note that the link layer address could be anything but the only networking
+ * media that u-boot supports is Ethernet so we assume we're extracting a 6

U-Boot

net/ndisc.c line 66

Quoted 10 lines
net/ndisc.c new file +10 -0
+ * byte Ethernet MAC address.
+ */
+static void ndisc_extract_enetaddr(struct nd_msg *ndisc, uchar enetaddr[6])
+{
+       memcpy(enetaddr, &ndisc->opt[2], 6);
+}
+
+/**
+ * Check to see if the neighbor discovery packet has
+ * the specified option set.

@return ...

Similarly elsewhere

Quoted 86 lines
net/ndisc.c new file +86 -0
+ */
+static int ndisc_has_option(struct ip6_hdr *ip6, __u8 type)
+{
+       struct nd_msg *ndisc = (struct nd_msg *)(((uchar *)ip6) + IP6_HDR_SIZE);
+
+       if (ip6->payload_len <= sizeof(struct icmp6hdr))
+               return 0;
+
+       return ndisc->opt[0] == type;
+}
+
+static void ip6_send_ns(struct in6_addr *neigh_addr)
+{
+       struct in6_addr dst_adr;
+       unsigned char enetaddr[6];
+       struct nd_msg *msg;
+       __u16 len;
+       uchar *pkt;
+
+       debug("sending neighbor solicitation for %pI6c our address %pI6c\n",
+             neigh_addr, &net_link_local_ip6);
+
+       /* calculate src, dest IPv6 addr and dest Eth addr */
+       ip6_make_snma(&dst_adr, neigh_addr);
+       ip6_make_mult_ethdstaddr(enetaddr, &dst_adr);
+       len = sizeof(struct icmp6hdr) + IN6ADDRSZ +
+           IP6_NDISC_OPT_SPACE(INETHADDRSZ);
+
+       pkt = (uchar *)net_tx_packet;
+       pkt += net_set_ether(pkt, enetaddr, PROT_IP6);
+       pkt += ip6_add_hdr(pkt, &net_link_local_ip6, &dst_adr, IPPROTO_ICMPV6,
+                          IPV6_NDISC_HOPLIMIT, len);
+
+       /* ICMPv6 - NS */
+       msg = (struct nd_msg *)pkt;
+       msg->icmph.icmp6_type = IPV6_NDISC_NEIGHBOUR_SOLICITATION;
+       msg->icmph.icmp6_code = 0;
+       memset(&msg->icmph.icmp6_cksum, 0, sizeof(__be16));
+       memset(&msg->icmph.icmp6_unused, 0, sizeof(__be32));
+
+       /* Set the target address and llsaddr option */
+       net_copy_ip6(&msg->target, neigh_addr);
+       ndisc_insert_option(msg, ND_OPT_SOURCE_LL_ADDR, net_ethaddr,
+                           INETHADDRSZ);
+
+       /* checksum */
+       msg->icmph.icmp6_cksum = csum_ipv6_magic(&net_link_local_ip6, &dst_adr,
+                                                len, IPPROTO_ICMPV6,
+                                                csum_partial((__u8 *)msg, len, 0));
+
+       pkt += len;
+
+       /* send it! */
+       net_send_packet(net_tx_packet, (pkt - net_tx_packet));
+}
+
+static void
+ip6_send_na(uchar *eth_dst_addr, struct in6_addr *neigh_addr,
+           struct in6_addr *target)
+{
+       struct nd_msg *msg;
+       __u16 len;
+       uchar *pkt;
+
+       debug("sending neighbor advertisement for %pI6c to %pI6c (%pM)\n",
+             target, neigh_addr, eth_dst_addr);
+
+       len = sizeof(struct icmp6hdr) + IN6ADDRSZ +
+           IP6_NDISC_OPT_SPACE(INETHADDRSZ);
+
+       pkt = (uchar *)net_tx_packet;
+       pkt += net_set_ether(pkt, eth_dst_addr, PROT_IP6);
+       pkt += ip6_add_hdr(pkt, &net_link_local_ip6, neigh_addr,
+                          IPPROTO_ICMPV6, IPV6_NDISC_HOPLIMIT, len);
+
+       /* ICMPv6 - NA */
+       msg = (struct nd_msg *)pkt;
+       msg->icmph.icmp6_type = IPV6_NDISC_NEIGHBOUR_ADVERTISEMENT;
+       msg->icmph.icmp6_code = 0;
+       memset(&msg->icmph.icmp6_cksum, 0, sizeof(__be16));
+       memset(&msg->icmph.icmp6_unused, 0, sizeof(__be32));
+
+       /* Set the target address and lltargetaddr option */
+       net_copy_ip6(&msg->target, target);
+       ndisc_insert_option(msg, ND_OPT_TARGET_LL_ADDR, net_ethaddr,
+                           INETHADDRSZ);

net/ndisc.c line 162

Quoted 10 lines
net/ndisc.c new file +10 -0
+
+       /* checksum */
+       msg->icmph.icmp6_cksum = csum_ipv6_magic(&net_link_local_ip6,
+                                                neigh_addr, len, IPPROTO_ICMPV6,
+                                                csum_partial((__u8 *)msg, len, 0));
+
+       pkt += len;
+
+       /* send it! */
+       net_send_packet(net_tx_packet, (pkt - net_tx_packet));

This code seems similar to the previous function. Can you see if you can factor out the common code?

Quoted 24 lines
net/ndisc.c new file +24 -0
+}
+
+void ndisc_request(void)
+{
+       if (!ip6_addr_in_subnet(&net_ip6, &net_nd_sol_packet_ip6,
+                               net_prefix_length)) {
+               if (ip6_is_unspecified_addr(&net_gateway6)) {
+                       puts("## Warning: gatewayip6 is needed but not set\n");
+                       net_nd_rep_packet_ip6 = net_nd_sol_packet_ip6;
+               } else {
+                       net_nd_rep_packet_ip6 = net_gateway6;
+               }
+       } else {
+               net_nd_rep_packet_ip6 = net_nd_sol_packet_ip6;
+       }
+
+       ip6_send_ns(&net_nd_rep_packet_ip6);
+}
+
+int ndisc_timeout_check(void)
+{
+       ulong t;
+
+       if (ip6_is_unspecified_addr(&net_nd_sol_packet_ip6))

net/ndisc.c line 196

Quoted 10 lines
net/ndisc.c new file +10 -0
+               return 0;
+
+       t = get_timer(0);
+
+       /* check for NDISC timeout */
+       if ((t - net_nd_timer_start) > NDISC_TIMEOUT) {
+               net_nd_try++;
+               if (net_nd_try >= NDISC_TIMEOUT_COUNT) {
+                       puts("\nNeighbour discovery retry count exceeded; "
+                            "starting again\n");

Use printf() and don't split strings as it makes it hard to grep. A long line is OK in this situation.

Quoted 9 lines
net/ndisc.c new file +9 -0
+                       net_nd_try = 0;
+                       net_set_state(NETLOOP_FAIL);
+               } else {
+                       net_nd_timer_start = t;
+                       ndisc_request();
+               }
+       }
+       return 1;
+}

net/ndisc.c line 215

Quoted 10 lines
net/ndisc.c new file +10 -0
+
+void ndisc_init(void)
+{
+       net_nd_packet_mac = NULL;
+       net_nd_tx_packet = NULL;
+       net_nd_sol_packet_ip6 = net_null_addr_ip6;
+       net_nd_rep_packet_ip6 = net_null_addr_ip6;
+       net_nd_tx_packet_size = 0;
+       net_nd_tx_packet = &net_nd_packet_buf[0] + (PKTALIGN - 1);
+       net_nd_tx_packet -= (ulong)net_nd_tx_packet % PKTALIGN;

Can these go in a struct instead of all being individual globals?

Quoted 11 lines
net/ndisc.c new file +11 -0
+}
+
+void ndisc_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len)
+{
+       struct icmp6hdr *icmp =
+           (struct icmp6hdr *)(((uchar *)ip6) + IP6_HDR_SIZE);
+       struct nd_msg *ndisc = (struct nd_msg *)icmp;
+       uchar neigh_eth_addr[6];
+
+       switch (icmp->icmp6_type) {
+       case IPV6_NDISC_NEIGHBOUR_SOLICITATION:

net/ndisc.c line 236

Quoted 10 lines
net/ndisc.c new file +10 -0
+               debug("received neighbor solicitation for %pI6c from %pI6c\n",
+                     &ndisc->target, &ip6->saddr);
+               if (ip6_is_our_addr(&ndisc->target) &&
+                   ndisc_has_option(ip6, ND_OPT_SOURCE_LL_ADDR)) {
+                       ndisc_extract_enetaddr(ndisc, neigh_eth_addr);
+                       ip6_send_na(neigh_eth_addr, &ip6->saddr,
+                                   &ndisc->target);
+               }
+               break;
+

Don't need this blank line.

Quoted 140 lines
net/ndisc.c new file +30 -0
+       case IPV6_NDISC_NEIGHBOUR_ADVERTISEMENT:
+               /* are we waiting for a reply ? */
+               if (ip6_is_unspecified_addr(&net_nd_sol_packet_ip6))
+                       break;
+
+               if ((memcmp(&ndisc->target, &net_nd_rep_packet_ip6,
+                           sizeof(struct in6_addr)) == 0) &&
+                   ndisc_has_option(ip6, ND_OPT_TARGET_LL_ADDR)) {
+                       ndisc_extract_enetaddr(ndisc, neigh_eth_addr);
+
+                       /* save address for later use */
+                       if (net_nd_packet_mac != NULL)
+                               memcpy(net_nd_packet_mac, neigh_eth_addr, 6);
+
+                       /* modify header, and transmit it */
+                       memcpy(((struct ethernet_hdr *)net_nd_tx_packet)->et_dest,
+                              neigh_eth_addr, 6);
+                       net_send_packet(net_nd_tx_packet,
+                                       net_nd_tx_packet_size);
+
+                       /* no ND request pending now */
+                       net_nd_sol_packet_ip6 = net_null_addr_ip6;
+                       net_nd_tx_packet_size = 0;
+                       net_nd_packet_mac = NULL;
+               }
+               break;
+       default:
+               debug("Unexpected ICMPv6 type 0x%x\n", icmp->icmp6_type);
+       }
+}
net/ndisc.h new file +25 -0
new file mode 100644
index 000000000000..75138d0a777c
@@ -0,0 +1,25 @@
+/*
+ * net/ndisc.h
+ *
+ * (C) Copyright 2013 Allied Telesis Labs NZ
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+/* IPv6 destination address of packet waiting for ND */
+extern struct in6_addr net_nd_sol_packet_ip6;
+/* MAC destination address of packet waiting for ND */
+extern uchar *net_nd_packet_mac;
+/* pointer to packet waiting to be transmitted after ND is resolved */
+extern uchar *net_nd_tx_packet;
+/* size of packet waiting to be transmitted */
+extern int net_nd_tx_packet_size;
+/* the timer for ND resolution */
+extern ulong net_nd_timer_start;
+/* the number of requests we have sent so far */
+extern int net_nd_try;
+
+void ndisc_init(void);
+void ndisc_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len);
+void ndisc_request(void);
+int ndisc_timeout_check(void);
net/net.c +23 -1
index 6e678770fa9d..527c99f96f9f 100644
@@ -87,6 +87,7 @@
 #include <environment.h>
 #include <errno.h>
 #include <net.h>
+#include <net6.h>
 #include <net/tftp.h>
 #if defined(CONFIG_LED_STATUS)
 #include <miiphy.h>
@@ -95,6 +96,7 @@
 #include <watchdog.h>
 #include <linux/compiler.h>
 #include "arp.h"
+#include "ndisc.h"
 #include "bootp.h"
 #include "cdp.h"
 #if defined(CONFIG_CMD_DNS)
@@ -342,8 +344,12 @@ void net_auto_load(void)
 
 static void net_init_loop(void)
 {
-       if (eth_get_dev())
+       if (eth_get_dev()) {
                memcpy(net_ethaddr, eth_get_ethaddr(), 6);
+#ifdef CONFIG_NET6
+               ip6_make_lladdr(&net_link_local_ip6, net_ethaddr);
+#endif
+       }
 
        return;
 }
@@ -377,6 +383,9 @@ void net_init(void)
                                (i + 1) * PKTSIZE_ALIGN;
                }
                arp_init();
+#ifdef CONFIG_NET6
+               ndisc_init();
+#endif
                net_clear_handlers();
 
                /* Only need to setup buffer pointers once. */
@@ -479,6 +488,11 @@ restart:
                        ping_start();
                        break;
 #endif
+#ifdef CONFIG_CMD_PING6
+               case PING6:
+                       ping6_start();
+                       break;
+#endif
 #if defined(CONFIG_CMD_NFS)
                case NFS:
                        nfs_start();
@@ -544,6 +558,11 @@ restart:
 #endif
                if (arp_timeout_check() > 0)
                        time_start = get_timer(0);
+#ifdef CONFIG_NET6
+               else if (ndisc_timeout_check() > 0)
+                       time_start = get_timer(0);
+#endif
+
 
                /*
                 *      Check the ethernet for a new packet.  The ethernet
@@ -559,6 +578,9 @@ restart:
                if (ctrlc()) {
                        /* cancel any ARP that may not have completed */
                        net_arp_wait_packet_ip.s_addr = 0;
+#ifdef CONFIG_NET6
+                       net_nd_sol_packet_ip6 = net_null_addr_ip6;
+#endif
 
                        net_cleanup_loop();
                        eth_halt();

net/net.c void net_process_received_packet(uchar *in_packet, int len) · line 1164

Quoted 6 lines
net/net.c +3 -0
@@ -1137,6 +1159,11 @@ void net_process_received_packet(uchar *in_packet, int len)
                rarp_receive(ip, len);
                break;
 #endif
+#ifdef CONFIG_NET6
+       case PROT_IP6:
+               net_ip6_handler(et, (struct ip6_hdr *)ip, len);

net_ip6_handler() looks like it should return an error, which can be checked here.

Quoted 46 lines
net/net.c +10 -0
+               break;
+#endif
        case PROT_IP:
                debug_cond(DEBUG_NET_PKT, "Got IP\n");
                /* Before we start poking the header, make sure it is there */
@@ -1291,6 +1318,14 @@ static int net_check_prereq(enum proto_t protocol)
                }
                goto common;
 #endif
+#ifdef CONFIG_CMD_PING6
+       case PING6:
+               if (ip6_is_unspecified_addr(&net_ping_ip6)) {
+                       puts("*** ERROR: ping address not given\n");
+                       return 1;
+               }
+               goto common;
+#endif
 #if defined(CONFIG_CMD_SNTP)
        case SNTP:
                if (net_ntp_server.s_addr == 0) {
net/net6.c +18 -0
index f778cef5ada9..955a08987be9 100644
@@ -8,6 +8,34 @@
  * SPDX-License-Identifier:    GPL-2.0+
  */
 
+/*
+ * General Desription:
+ *
+ * The user interface supports commands for TFTP6.
+ * Also, we support Neighbour discovery internally. Depending on available
+ * data, these interact as follows:
+ *
+ * Neighbour Discovery:
+ *
+ *      Prerequisites:  - own ethernet address
+ *                      - own IPv6 address
+ *                      - TFTP server IPv6 address
+ *      We want:        - TFTP server ethernet address
+ *      Next step:      TFTP
+ *
+ * TFTP over IPv6:
+ *
+ *      Prerequisites:  - own ethernet address

net/net6.c line 38

Quoted 10 lines
net/net6.c +10 -0
+ *                      - own IPv6 address
+ *                      - TFTP server IPv6 address
+ *                      - TFTP server ethernet address
+ *                      - name of bootfile (if unknown, we use a default name
+ *                        derived from our own IPv6 address)
+ *      We want:        - load the boot file
+ *      Next step:      none
+ *
+ */
+#define DEBUG

Do you want that?

Quoted 37 lines
net/net6.c +19 -0
 #include <common.h>
 #include <environment.h>
 #include <malloc.h>
@@ -15,10 +43,14 @@
 #include <net6.h>
 #include "ndisc.h"
 
+/* NULL IPv6 address */
+struct in6_addr const net_null_addr_ip6 = ZERO_IPV6_ADDR;
 /* 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;
+/* Our link local IPv6 addr (0 = unknown) */
+struct in6_addr net_link_local_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 */
@@ -87,3 +119,270 @@ static int on_serverip6(const char *name, const char *value, enum env_op op,
        return string_to_ip6(value, &net_server_ip6);
 }
 U_BOOT_ENV_CALLBACK(serverip6, on_serverip6);
+
+int ip6_is_unspecified_addr(struct in6_addr *addr)
+{
+       return (addr->s6_addr32[0] | addr->s6_addr32[1] |
+               addr->s6_addr32[2] | addr->s6_addr32[3]) == 0;
+}
+
+/**
+ * We have 2 addresses that we should respond to. A link
+ * local address and a global address. This returns true
+ * if the specified address matches either of these.
+ */
+int ip6_is_our_addr(struct in6_addr *addr)
+{
+       return memcmp(addr, &net_link_local_ip6, sizeof(struct in6_addr)) == 0 ||

net/net6.c static int on_serverip6(const char *name, const char *value, enum env_op op, · line 146

Quoted 10 lines
net/net6.c +10 -0
+              memcmp(addr, &net_ip6, sizeof(struct in6_addr)) == 0;
+}
+
+void ip6_make_eui(unsigned char eui[8], unsigned char const enetaddr[6])
+{
+       memcpy(eui, enetaddr, 3);
+       memcpy(&eui[5], &enetaddr[3], 3);
+       eui[3] = 0xFF;
+       eui[4] = 0xFE;
+       eui[0] ^= 2;            /* "u" bit set to indicate global scope */

|= ?

net/net6.c static int on_serverip6(const char *name, const char *value, enum env_op op, · line 156

Quoted 10 lines
net/net6.c +10 -0
+}
+
+void ip6_make_lladdr(struct in6_addr *lladr, unsigned char const enetaddr[6])
+{
+       uchar eui[8];
+
+       memset(lladr, 0, sizeof(struct in6_addr));
+       lladr->s6_addr16[0] = htons(IPV6_LINK_LOCAL_PREFIX);
+       ip6_make_eui(eui, enetaddr);
+       memcpy(&lladr->s6_addr[8], eui, 8);

What is 8? Is there a sizeof() or #define we could use?

Quoted 57 lines
net/net6.c +57 -0
+}
+
+/*
+ * Given an IPv6 address generate an equivalent Solicited Node Multicast
+ * Address (SNMA) as described in RFC2461.
+ */
+void ip6_make_snma(struct in6_addr *mcast_addr, struct in6_addr *ip6_addr)
+{
+       memset(mcast_addr, 0, sizeof(struct in6_addr));
+       mcast_addr->s6_addr[0] = 0xff;
+       mcast_addr->s6_addr[1] = IPV6_ADDRSCOPE_LINK;
+       mcast_addr->s6_addr[11] = 0x01;
+       mcast_addr->s6_addr[12] = 0xff;
+       mcast_addr->s6_addr[13] = ip6_addr->s6_addr[13];
+       mcast_addr->s6_addr[14] = ip6_addr->s6_addr[14];
+       mcast_addr->s6_addr[15] = ip6_addr->s6_addr[15];
+}
+
+/*
+ * Given an IPv6 address generate the multicast MAC address that corresponds to
+ * it.
+ */
+void
+ip6_make_mult_ethdstaddr(unsigned char enetaddr[6], struct in6_addr *mcast_addr)
+{
+       enetaddr[0] = 0x33;
+       enetaddr[1] = 0x33;
+       memcpy(&enetaddr[2], &mcast_addr->s6_addr[12], 4);
+}
+
+int
+ip6_addr_in_subnet(struct in6_addr *our_addr, struct in6_addr *neigh_addr,
+                  __u32 plen)
+{
+       __be32 *addr_dwords;
+       __be32 *neigh_dwords;
+
+       addr_dwords = our_addr->s6_addr32;
+       neigh_dwords = neigh_addr->s6_addr32;
+
+       while (plen > 32) {
+               if (*addr_dwords++ != *neigh_dwords++)
+                       return 0;
+
+               plen -= 32;
+       }
+
+       /* Check any remaining bits. */
+       if (plen > 0) {
+               if ((*addr_dwords >> (32 - plen)) !=
+                   (*neigh_dwords >> (32 - plen))) {
+                       return 0;
+               }
+       }
+
+       return 1;
+}

net/net6.c static int on_serverip6(const char *name, const char *value, enum env_op op, · line 223

Quoted 10 lines
net/net6.c +10 -0
+
+static inline unsigned int csum_fold(unsigned int sum)
+{
+       sum = (sum & 0xffff) + (sum >> 16);
+       sum = (sum & 0xffff) + (sum >> 16);
+
+       return ~sum;
+}
+
+static __u32 csum_do_csum(const __u8 *buff, int len)

Function comment. It looks like you are trying to optimise for speed here by doing things a word at a time.

Quoted 20 lines
net/net6.c +20 -0
+{
+       int odd, count;
+       unsigned long result = 0;
+
+       if (len <= 0)
+               goto out;
+       odd = 1 & (unsigned long)buff;
+       if (odd) {
+               result = *buff;
+               len--;
+               buff++;
+       }
+       count = len >> 1;       /* nr of 16-bit words.. */
+       if (count) {
+               if (2 & (unsigned long)buff) {
+                       result += *(unsigned short *)buff;
+                       count--;
+                       len -= 2;
+                       buff += 2;
+               }

net/net6.c static int on_serverip6(const char *name, const char *value, enum env_op op, · line 253

Quoted 10 lines
net/net6.c +10 -0
+               count >>= 1;    /* nr of 32-bit words.. */
+               if (count) {
+                       unsigned long carry = 0;
+                       do {
+                               unsigned long w = *(unsigned long *)buff;
+                               count--;
+                               buff += 4;
+                               result += carry;
+                               result += w;
+                               carry = (w > result);

Perhaps have a ulong *ptr instead using buff. Then you can use ptr++ instead of buff += 4.

Quoted 91 lines
net/net6.c +91 -0
+                       } while (count);
+                       result += carry;
+                       result = (result & 0xffff) + (result >> 16);
+               }
+               if (len & 2) {
+                       result += *(unsigned short *)buff;
+                       buff += 2;
+               }
+       }
+       if (len & 1)
+               result += (*buff << 8);
+       result = ~csum_fold(result);
+       if (odd)
+               result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
+out:
+       return result;
+}
+
+unsigned int csum_partial(const unsigned char *buff, int len, unsigned int sum)
+{
+       unsigned int result = csum_do_csum(buff, len);
+
+       /* add in old sum, and carry.. */
+       result += sum;
+       /* 16+c bits -> 16 bits */
+       result = (result & 0xffff) + (result >> 16);
+       return result;
+}
+
+/*
+ * Compute checksum of IPv6 "psuedo-header" per RFC2460 section 8.1
+ */
+unsigned short int
+csum_ipv6_magic(struct in6_addr *saddr, struct in6_addr *daddr,
+               __u16 len, unsigned short proto, unsigned int csum)
+{
+       int i;
+       int carry;
+       __u32 ulen;
+       __u32 uproto;
+       unsigned int finalsum;
+
+       for (i = 0; i < 4; i++) {
+               csum += saddr->s6_addr32[i];
+               carry = (csum < saddr->s6_addr32[i]);
+               csum += carry;
+
+               csum += daddr->s6_addr32[i];
+               carry = (csum < daddr->s6_addr32[i]);
+               csum += carry;
+       }
+
+       ulen = htonl((__u32)len);
+       csum += ulen;
+       carry = (csum < ulen);
+       csum += carry;
+
+       uproto = htonl(proto);
+       csum += uproto;
+       carry = (csum < uproto);
+       csum += carry;
+
+       finalsum = csum_fold(csum);
+       if ((finalsum & 0xffff) == 0x0000)
+               return 0xffff;
+       else if ((finalsum & 0xffff) == 0xffff)
+               return 0x0000;
+       else
+               return finalsum;
+}
+
+int
+ip6_add_hdr(uchar *xip, struct in6_addr *src, struct in6_addr *dest,
+           int nextheader, int hoplimit, int payload_len)
+{
+       struct ip6_hdr *ip6 = (struct ip6_hdr *)xip;
+
+       ip6->version = 6;
+       ip6->priority = 0;
+       ip6->flow_lbl[0] = 0;
+       ip6->flow_lbl[1] = 0;
+       ip6->flow_lbl[2] = 0;
+       ip6->payload_len = htons(payload_len);
+       ip6->nexthdr = nextheader;
+       ip6->hop_limit = hoplimit;
+       net_copy_ip6(&ip6->saddr, src);
+       net_copy_ip6(&ip6->daddr, dest);
+
+       return sizeof(struct ip6_hdr);
+}
+

net/net6.c static int on_serverip6(const char *name, const char *value, enum env_op op, · line 354

Quoted 10 lines
net/net6.c +10 -0
+void net_ip6_handler(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len)
+{
+       struct in_addr zero_ip = {.s_addr = 0 };
+       struct icmp6hdr *icmp;
+       struct udp_hdr *udp;
+       __u16 csum;
+       __u16 hlen;
+
+       if (len < IP6_HDR_SIZE)
+               return;

Return -EINVAL perhaps?

Quoted 35 lines
net/net6.c +34 -1
+
+       if (ip6->version != 6)
+               return;
+
+       switch (ip6->nexthdr) {
+       case IPPROTO_ICMPV6:
+               icmp = (struct icmp6hdr *)(((uchar *)ip6) + IP6_HDR_SIZE);
+               csum = icmp->icmp6_cksum;
+               hlen = ntohs(ip6->payload_len);
+               icmp->icmp6_cksum = 0;
+               /* checksum */
+               icmp->icmp6_cksum = csum_ipv6_magic(&ip6->saddr, &ip6->daddr,
+                                                   hlen, IPPROTO_ICMPV6,
+                                                   csum_partial((__u8 *)icmp, hlen, 0));
+               if (icmp->icmp6_cksum != csum)
+                       return;
+
+               switch (icmp->icmp6_type) {
+               case IPV6_NDISC_NEIGHBOUR_SOLICITATION:
+               case IPV6_NDISC_NEIGHBOUR_ADVERTISEMENT:
+                       ndisc_receive(et, ip6, len);
+                       break;
+
+               default:
+                       return;
+                       break;
+               }
+               break;
+
+       default:
+               return;
+               break;
+       }
+}
--
Quoted 2 lines

2.11.0.24.ge6920cf

Regards,
Simon

#11 lore raw

RFC PATCH v3 7/11 net: Add ping6 command and implementation

In reply to Chris Packham

---

Changes in v3: None
Changes in v2:
- split ping6 support into it's own patch

 cmd/Kconfig   |   6 ++++
 cmd/net.c     |  28 +++++++++++++++
 include/net.h |   4 +--
 net/net6.c    |   7 ++++
 net/ping6.c   | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 154 insertions(+), 2 deletions(-)
 create mode 100644 net/ping6.c
cmd/Kconfig +6 -0
index 91bd3fb0b58e..37126577bc65 100644
@@ -546,6 +546,12 @@ config CMD_PING
 	help
 	  Send ICMP ECHO_REQUEST to network host
 
+config CMD_PING6
+	bool "ping6"
+	depends on CMD_NET6
+	help
+	  Send ICMPv6 ECHO_REQUEST to network host
+
 config CMD_CDP
 	bool "cdp"
 	help
cmd/net.c +28 -0
index df8b6c9b53f0..7f40f257c03c 100644
@@ -11,6 +11,7 @@
 #include <common.h>
 #include <command.h>
 #include <net.h>
+#include <net6.h>
 
 static int netboot_common(enum proto_t, cmd_tbl_t *, int, char * const []);
 
@@ -281,6 +282,33 @@ U_BOOT_CMD(
 );
 #endif
 
+#ifdef CONFIG_CMD_PING6
+int do_ping6(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	if (argc < 2)
+		return -1;
+
+	if (string_to_ip6(argv[1], &net_ping_ip6) != 0)
+		return CMD_RET_USAGE;
+
+	if (net_loop(PING6) < 0) {
+		printf("ping6 failed; host %pI6c is not alive\n",
+		       &net_ping_ip6);
+		return 1;
+	}
+
+	printf("host %pI6c is alive\n", &net_ping_ip6);
+
+	return 0;
+}
+
+U_BOOT_CMD(
+	ping6,  2,      1,      do_ping6,
+	"send ICMPv6 ECHO_REQUEST to network host",
+	"pingAddress"
+);
+#endif /* CONFIG_CMD_PING6 */
+
 #if defined(CONFIG_CMD_CDP)
 
 static void cdp_update_env(void)
include/net.h +2 -2
index b0348adf955e..be75c6c65c6b 100644
@@ -545,8 +545,8 @@ extern ushort		net_native_vlan;	/* Our Native VLAN */
 extern int		net_restart_wrap;	/* Tried all network devices */
 
 enum proto_t {
-	BOOTP, RARP, ARP, TFTPGET, DHCP, PING, DNS, NFS, CDP, NETCONS, SNTP,
-	TFTPSRV, TFTPPUT, LINKLOCAL
+	BOOTP, RARP, ARP, TFTPGET, DHCP, PING, PING6, DNS, NFS, CDP, NETCONS,
+	SNTP, TFTPSRV, TFTPPUT, LINKLOCAL
 };
 
 extern char	net_boot_file_name[1024];/* Boot File name */
net/net6.c +7 -0
index 955a08987be9..8f0c7214f8e1 100644
@@ -370,6 +370,13 @@ void net_ip6_handler(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len)
 			return;
 
 		switch (icmp->icmp6_type) {
+#ifdef CONFIG_CMD_PING6
+		case IPV6_ICMP_ECHO_REQUEST:
+		case IPV6_ICMP_ECHO_REPLY:
+			ping6_receive(et, ip6, len);
+			break;
+#endif /* CONFIG_CMD_PING6 */
+
 		case IPV6_NDISC_NEIGHBOUR_SOLICITATION:
 		case IPV6_NDISC_NEIGHBOUR_ADVERTISEMENT:
 			ndisc_receive(et, ip6, len);
net/ping6.c new file +111 -0

111 lines not on this page · raw message

Signature · 1 line
2.11.0.24.ge6920cf
#12 lore raw

RFC PATCH v3 7/11 net: Add ping6 command and implementation

Hi Chris,

Quoted 8 lines · Chris Packham

---

Changes in v3: None
Changes in v2:
- split ping6 support into it's own patch

Quoted 8 lines
 cmd/Kconfig   |   6 ++++
 cmd/net.c     |  28 +++++++++++++++
 include/net.h |   4 +--
 net/net6.c    |   7 ++++
 net/ping6.c   | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 154 insertions(+), 2 deletions(-)
 create mode 100644 net/ping6.c

I'm not keen on the global variables (e.g. seq_no). Can they go in a struct and be stored in the uclass private data for the Ethernet?

- Simon

#13 lore raw

RFC PATCH v3 8/11 net: TFTP over IPv6

In reply to Chris Packham

Add support for UDP/TFTP over IPv6. To support specifying an server IPv6 address in the command square brackets must be used to separate the address from the filename. e.g
tftpboot6 [2001:db8::1]:zImage

---

Changes in v3: None
Changes in v2:
- Support parsing the server address from the command parameter.

 cmd/Kconfig    |  9 +++++++++
 cmd/net.c      | 13 ++++++++++++
 include/net.h  |  2 +-
 include/net6.h |  4 ++++
 net/net.c      |  3 +++
 net/net6.c     | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/tftp.c     | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 152 insertions(+), 1 deletion(-)
cmd/Kconfig +9 -0
index 37126577bc65..473d354fcb85 100644
@@ -504,6 +504,15 @@ config CMD_NET
 	  bootp - boot image via network using BOOTP/TFTP protocol
 	  tftpboot - boot image via network using TFTP protocol
 
+config CMD_NET6
+	bool "ipv6 commands"
+	select NET
+	select NET6
+	default n
+	help
+	  IPv6 network commands
+	  tftpboot6 - boot image via network using TFTP protocol
+
 config CMD_TFTPPUT
 	bool "tftp put"
 	help
cmd/net.c +13 -0
index 7f40f257c03c..e2c295eabb17 100644
@@ -42,6 +42,19 @@ U_BOOT_CMD(
 	"[loadAddress] [[hostIPaddr:]bootfilename]"
 );
 
+#ifdef CONFIG_CMD_NET6
+int do_tftpb6(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	return netboot_common(TFTP6, cmdtp, argc, argv);
+}
+
+U_BOOT_CMD(
+	tftpboot6,	3,	1,	do_tftpb6,
+	"boot image via network using TFTP protocol",
+	"[loadAddress] [[hostIP6Addr]:][bootfilename]"
+);
+#endif
+
 #ifdef CONFIG_CMD_TFTPPUT
 int do_tftpput(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
include/net.h +1 -1
index be75c6c65c6b..6c968711c37f 100644
@@ -546,7 +546,7 @@ extern int		net_restart_wrap;	/* Tried all network devices */
 
 enum proto_t {
 	BOOTP, RARP, ARP, TFTPGET, DHCP, PING, PING6, DNS, NFS, CDP, NETCONS,
-	SNTP, TFTPSRV, TFTPPUT, LINKLOCAL
+	SNTP, TFTPSRV, TFTPPUT, TFTP6, LINKLOCAL
 };
 
 extern char	net_boot_file_name[1024];/* Boot File name */
include/net6.h +4 -0
index ff97c39a6925..7ae177738e86 100644
@@ -246,6 +246,10 @@ void ping6_start(void);
 void ping6_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6,
 			  int len);
 
+/* Transmit UDP packet using IPv6, performing neighbour discovery if needed */
+int net_send_udp_packet6(uchar *ether, struct in6_addr *dest,
+				int dport, int sport, int len);
+
 /* handler for incoming IPv6 echo packet */
 void net_ip6_handler(struct ethernet_hdr *et, struct ip6_hdr *ip6,
 			    int len);
net/net.c +3 -0
index 527c99f96f9f..567550ef09b6 100644
@@ -454,6 +454,9 @@ restart:
 #ifdef CONFIG_CMD_TFTPPUT
 		case TFTPPUT:
 #endif
+#ifdef CONFIG_CMD_NET6
+		case TFTP6:
+#endif
 			/* always use ARP to get server ethernet address */
 			tftp_start(protocol);
 			break;
net/net6.c +64 -0

76 lines not on this page · raw message

net/tftp.c +58 -0

118 lines not on this page · raw message

Signature · 1 line
2.11.0.24.ge6920cf
#14 lore raw

RFC PATCH v3 8/11 net: TFTP over IPv6

Hi Chris,

Quoted 4 lines · Chris Packham

Add support for UDP/TFTP over IPv6. To support specifying an server IPv6 address in the command square brackets must be used to separate the address from the filename. e.g
tftpboot6 [2001:db8::1]:zImage

Ick, but I suppose we are painted into a corner here. Perhaps we should support a different separator like ',' and then that can be used instead? Having separators inside [] makes it harder to find a 'real' separator since you need to parse the [].

Quoted 8 lines

---

Changes in v3: None
Changes in v2:
- Support parsing the server address from the command parameter.

Quoted 8 lines
 cmd/Kconfig    |  9 +++++++++
 cmd/net.c      | 13 ++++++++++++
 include/net.h  |  2 +-
 include/net6.h |  4 ++++
 net/net.c      |  3 +++
 net/net6.c     | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/tftp.c     | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 152 insertions(+), 1 deletion(-)
Quoted 63 lines
cmd/Kconfig +9 -0
index 37126577bc65..473d354fcb85 100644
@@ -504,6 +504,15 @@ config CMD_NET
          bootp - boot image via network using BOOTP/TFTP protocol
          tftpboot - boot image via network using TFTP protocol
 
+config CMD_NET6
+       bool "ipv6 commands"
+       select NET
+       select NET6
+       default n
+       help
+         IPv6 network commands
+         tftpboot6 - boot image via network using TFTP protocol
+
 config CMD_TFTPPUT
        bool "tftp put"
        help
cmd/net.c +13 -0
index 7f40f257c03c..e2c295eabb17 100644
@@ -42,6 +42,19 @@ U_BOOT_CMD(
        "[loadAddress] [[hostIPaddr:]bootfilename]"
 );
 
+#ifdef CONFIG_CMD_NET6
+int do_tftpb6(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       return netboot_common(TFTP6, cmdtp, argc, argv);
+}
+
+U_BOOT_CMD(
+       tftpboot6,      3,      1,      do_tftpb6,
+       "boot image via network using TFTP protocol",
+       "[loadAddress] [[hostIP6Addr]:][bootfilename]"
+);
+#endif
+
 #ifdef CONFIG_CMD_TFTPPUT
 int do_tftpput(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
include/net.h +1 -1
index be75c6c65c6b..6c968711c37f 100644
@@ -546,7 +546,7 @@ extern int          net_restart_wrap;       /* Tried all network devices */
 
 enum proto_t {
        BOOTP, RARP, ARP, TFTPGET, DHCP, PING, PING6, DNS, NFS, CDP, NETCONS,
-       SNTP, TFTPSRV, TFTPPUT, LINKLOCAL
+       SNTP, TFTPSRV, TFTPPUT, TFTP6, LINKLOCAL
 };
 
 extern char    net_boot_file_name[1024];/* Boot File name */
include/net6.h +0 -0
index ff97c39a6925..7ae177738e86 100644

include/net6.h void ping6_start(void); · line 249

Quoted 4 lines
include/net6.h +1 -0
@@ -246,6 +246,10 @@ void ping6_start(void);
 void ping6_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6,
                          int len);
 
+/* Transmit UDP packet using IPv6, performing neighbour discovery if needed */

Comment args and return value

Quoted 25 lines
include/net6.h +3 -0
+int net_send_udp_packet6(uchar *ether, struct in6_addr *dest,
+                               int dport, int sport, int len);
+
 /* handler for incoming IPv6 echo packet */
 void net_ip6_handler(struct ethernet_hdr *et, struct ip6_hdr *ip6,
                            int len);
net/net.c +3 -0
index 527c99f96f9f..567550ef09b6 100644
@@ -454,6 +454,9 @@ restart:
 #ifdef CONFIG_CMD_TFTPPUT
                case TFTPPUT:
 #endif
+#ifdef CONFIG_CMD_NET6
+               case TFTP6:
+#endif
                        /* always use ARP to get server ethernet address */
                        tftp_start(protocol);
                        break;
net/net6.c +0 -0
index 8f0c7214f8e1..5b8a003f1c4a 100644

net/net6.c ip6_add_hdr(uchar *xip, struct in6_addr *src, struct in6_addr *dest, · line 345

Quoted 4 lines
net/net6.c +1 -0
@@ -342,6 +342,50 @@ ip6_add_hdr(uchar *xip, struct in6_addr *src, struct in6_addr *dest,
        return sizeof(struct ip6_hdr);
 }
 
+int

Join with next line

Quoted 23 lines
net/net6.c +23 -0
+net_send_udp_packet6(uchar *ether, struct in6_addr *dest, int dport, int sport, int len)
+{
+       uchar *pkt;
+       struct udp_hdr *udp;
+
+       udp = (struct udp_hdr *)((uchar *)net_tx_packet + net_eth_hdr_size() + IP6_HDR_SIZE);
+
+       udp->udp_dst = htons(dport);
+       udp->udp_src = htons(sport);
+       udp->udp_len = htons(len + UDP_HDR_SIZE);
+       /* checksum */
+       udp->udp_xsum = 0;
+       udp->udp_xsum = csum_ipv6_magic(&net_ip6, dest, len + UDP_HDR_SIZE,
+               IPPROTO_UDP, csum_partial((__u8 *)udp, len + UDP_HDR_SIZE, 0));
+
+       /* if MAC address was not discovered yet, save the packet and do neighbour discovery */
+       if (memcmp(ether, net_null_ethaddr, 6) == 0) {
+               net_copy_ip6(&net_nd_sol_packet_ip6, dest);
+               net_nd_packet_mac = ether;
+
+               pkt = net_nd_tx_packet;
+               pkt += net_set_ether(pkt, net_nd_packet_mac, PROT_IP6);
+               pkt += ip6_add_hdr(pkt, &net_ip6, dest, IPPROTO_UDP, 64, len + UDP_HDR_SIZE);

net/net6.c ip6_add_hdr(uchar *xip, struct in6_addr *src, struct in6_addr *dest, · line 378

Quoted 10 lines
net/net6.c +10 -0
+               memcpy(pkt, (uchar *)udp, len + UDP_HDR_SIZE);
+
+               /* size of the waiting packet */
+               net_nd_tx_packet_size = (pkt - net_nd_tx_packet) + UDP_HDR_SIZE + len;
+
+               /* and do the neighbor solicitation */
+               net_nd_try = 1;
+               net_nd_timer_start = get_timer(0);
+               ndisc_request();
+               return 1;       /* waiting */

-EAGAIN?

net/net6.c ip6_add_hdr(uchar *xip, struct in6_addr *src, struct in6_addr *dest, · line 384

Quoted 6 lines
net/net6.c +6 -0
+       }
+
+       pkt = (uchar *)net_tx_packet;
+       pkt += net_set_ether(pkt, ether, PROT_IP6);
+       pkt += ip6_add_hdr(pkt, &net_ip6, dest, IPPROTO_UDP, 64, len + UDP_HDR_SIZE);
+       (void) eth_send(net_tx_packet, (pkt - net_tx_packet) + UDP_HDR_SIZE + len);

Why swallow the error? Shouldn't you return it here?

Quoted 11 lines
net/net6.c +4 -0
+
+       return 0;       /* transmitted */
+}
+
 void net_ip6_handler(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len)
 {
        struct in_addr zero_ip = {.s_addr = 0 };
@@ -388,6 +432,26 @@ void net_ip6_handler(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len)
                }
                break;
 

net/net6.c void net_ip6_handler(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len) · line 444

Quoted 10 lines
net/net6.c +10 -0
+       case IPPROTO_UDP:
+               udp = (struct udp_hdr *)(((uchar *)ip6) + IP6_HDR_SIZE);
+               csum = udp->udp_xsum;
+               hlen = ntohs(ip6->payload_len);
+               udp->udp_xsum = 0;
+               /* checksum */
+               udp->udp_xsum = csum_ipv6_magic(&ip6->saddr, &ip6->daddr,
+                               hlen, IPPROTO_UDP, csum_partial((__u8 *)udp, hlen, 0));
+               if (csum != udp->udp_xsum)
+                       return;

Error?

Quoted 93 lines
net/net6.c +10 -0
+
+               /* IP header OK.  Pass the packet to the current handler. */
+               net_get_udp_handler()((uchar *)ip6 + IP6_HDR_SIZE +
+                                       UDP_HDR_SIZE,
+                               ntohs(udp->udp_dst),
+                               zero_ip,
+                               ntohs(udp->udp_src),
+                               ntohs(udp->udp_len) - 8);
+               break;
+
        default:
                return;
                break;
net/tftp.c +26 -0
index ced45ec1f1f4..dbcefd2d4257 100644
@@ -11,6 +11,7 @@
 #include <efi_loader.h>
 #include <mapmem.h>
 #include <net.h>
+#include <net6.h>
 #include <net/tftp.h>
 #include "bootp.h"
 #ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
@@ -67,6 +68,9 @@ enum {
 };
 
 static struct in_addr tftp_remote_ip;
+#ifdef CONFIG_CMD_NET6
+static struct in6_addr tftp_remote_ip6;
+#endif
 /* The UDP port at their end */
 static int     tftp_remote_port;
 /* The UDP port at our end */
@@ -95,6 +99,10 @@ static int   tftp_put_final_block_sent;
 #else
 #define tftp_put_active        0
 #endif
+#ifdef CONFIG_CMD_NET6
+/* 1 if using IPv6, else 0 */
+static int      tftp6_active;
+#endif
 
 #define STATE_SEND_RRQ 1
 #define STATE_DATA     2
@@ -130,6 +138,8 @@ static char tftp_filename[MAX_LEN];
 #else
 #define TFTP_MTU_BLOCKSIZE 1468
 #endif
+/* IPv6 adds 20 bytes extra overhead */
+#define TFTP_MTU_BLOCKSIZE6 (TFTP_MTU_BLOCKSIZE - 20)
 
 static unsigned short tftp_block_size = TFTP_BLOCK_SIZE;
 static unsigned short tftp_block_size_option = TFTP_MTU_BLOCKSIZE;
@@ -342,6 +352,12 @@ static void tftp_send(void)
         *      We will always be sending some sort of packet, so
         *      cobble together the packet headers now.
         */
+#ifdef CONFIG_CMD_NET6
+       if (tftp6_active)
+               pkt = net_tx_packet + net_eth_hdr_size() +
+                     IP6_HDR_SIZE + UDP_HDR_SIZE;
+       else
+#endif
        pkt = net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE;
 
        switch (tftp_state) {
@@ -441,6 +457,12 @@ static void tftp_send(void)
                break;
        }
 
+#ifdef CONFIG_CMD_NET6
+       if (tftp6_active)
+               net_send_udp_packet6(net_server_ethaddr, &tftp_remote_ip6,
+                                    tftp_remote_port, tftp_our_port, len);
+       else
+#endif
        net_send_udp_packet(net_server_ethaddr, tftp_remote_ip,
                            tftp_remote_port, tftp_our_port, len);
 }
@@ -734,6 +756,10 @@ void tftp_start(enum proto_t protocol)
        debug("TFTP blocksize = %i, timeout = %ld ms\n",
              tftp_block_size_option, timeout_ms);
 
+#ifdef CONFIG_CMD_NET6
+       tftp6_active = (protocol == TFTP6);
+       tftp_remote_ip6 = net_server_ip6;
+#endif
        tftp_remote_ip = net_server_ip;
        if (net_boot_file_name[0] == '\0') {
                sprintf(default_filename, "%02X%02X%02X%02X.img",

net/tftp.c void tftp_start(enum proto_t protocol) · line 780

Quoted 8 lines
net/tftp.c +5 -0
@@ -747,6 +773,20 @@ void tftp_start(enum proto_t protocol)
 
                printf("*** Warning: no boot file name; using '%s'\n",
                       tftp_filename);
+#ifdef CONFIG_CMD_NET6
+       } else if (tftp6_active) {
+               char *s, *e;
+               s = strchr(net_boot_file_name, '[');
+               e = strchr(net_boot_file_name, ']');

I don't expected [ or ] would appear in filenames, but they are not actually illegal.

Quoted 45 lines
net/tftp.c +27 -1
+               if (s && e) {
+                       *e++ = 0;
+                       string_to_ip6(s + 1, &tftp_remote_ip6);
+                       strncpy(tftp_filename, e + 1, MAX_LEN);
+               } else {
+                       strncpy(tftp_filename, net_boot_file_name, MAX_LEN);
+                       tftp_filename[MAX_LEN - 1] = 0;
+               }
+#endif
        } else {
                char *p = strchr(net_boot_file_name, ':');
 
@@ -761,6 +801,15 @@ void tftp_start(enum proto_t protocol)
        }
 
        printf("Using %s device\n", eth_get_name());
+#ifdef CONFIG_CMD_NET6
+       if (tftp6_active) {
+               printf("TFTP from server %pI6c; our IP address is %pI6c",
+                      &tftp_remote_ip6,
+                      &net_ip6);
+               if (tftp_block_size_option > TFTP_MTU_BLOCKSIZE6)
+                       tftp_block_size_option = TFTP_MTU_BLOCKSIZE6;
+       } else
+#endif
        printf("TFTP %s server %pI4; our IP address is %pI4",
 #ifdef CONFIG_CMD_TFTPPUT
               protocol == TFTPPUT ? "to" : "from",
@@ -770,6 +819,15 @@ void tftp_start(enum proto_t protocol)
               &tftp_remote_ip, &net_ip);
 
        /* Check if we need to send across this subnet */
+#ifdef CONFIG_CMD_NET6
+       if (tftp6_active) {
+               if (!ip6_addr_in_subnet(&net_ip6, &tftp_remote_ip6,
+                                       net_prefix_length)) {
+                       printf("; sending through gateway %pI6c",
+                              &net_gateway6);
+               }
+       } else
+#endif
        if (net_gateway.s_addr && net_netmask.s_addr) {
                struct in_addr our_net;
                struct in_addr remote_net;
--
Quoted 2 lines

2.11.0.24.ge6920cf

Regards,
Simon

#15 lore raw

RFC PATCH v3 9/11 net: IPv6 documentation

In reply to Chris Packham

---

Changes in v3:
- Add brief testing section

Changes in v2: None

 README          |  3 +++
 doc/README.ipv6 | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)
 create mode 100644 doc/README.ipv6
README +3 -0
index a95348a876b4..4ab4a0e74f32 100644
@@ -922,6 +922,7 @@ The following options need to be configured:
 		CONFIG_CMD_MTDPARTS	* MTD partition support
 		CONFIG_CMD_NAND		* NAND support
 		CONFIG_CMD_NET		  bootp, tftpboot, rarpboot
+		CONFIG_CMD_NET6		* tftpboot6
 		CONFIG_CMD_NFS		  NFS support
 		CONFIG_CMD_PCA953X	* PCA953x I2C gpio commands
 		CONFIG_CMD_PCA953X_INFO * PCA953x I2C gpio info command
@@ -929,6 +930,8 @@ The following options need to be configured:
 		CONFIG_CMD_PCMCIA		* PCMCIA support
 		CONFIG_CMD_PING		* send ICMP ECHO_REQUEST to network
 					  host
+		CONFIG_CMD_PING6	* send ICMPv6 ECHO_REQUEST to network
+					  host
 		CONFIG_CMD_PORTIO	* Port I/O
 		CONFIG_CMD_READ		* Read raw data from partition
 		CONFIG_CMD_REGINFO	* Register dump
doc/README.ipv6 new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
2.11.0.24.ge6920cf
#16 lore raw

RFC PATCH v3 9/11 net: IPv6 documentation

Quoted 5 lines · Chris Packham

---

Changes in v3:
- Add brief testing section

[snip]

Quoted 12 lines
doc/README.ipv6 new file +12 -0
+Testing using QEMU
+------------------
+Refer to README.x86 for instructions on building u-boot for QEMU. Add
+the relevant IPv6 configuration to the configuration (CONFIG_CMD_NET6,
+CONFIG_CMD_PING6) and build.
+
+On the host system run
+
+  sudo qemu-system-i386 -nographic -bios u-boot.rom -net nic -net tap
+
+At the u-boot command line run
+

doc/README.ipv6 line 55

Quoted 10 lines
doc/README.ipv6 new file +10 -0
+  setenv ipaddr 192.168.1.100
+  setenv ip6addr 3ffe::100/64
+
+On the host system run
+
+  sudo ip addr add 3ffe::1/64 dev tap0
+  sudo ip addr add 192.168.1.1
+
+It should now be possible to use ping6 and tftpboot6 to communicate with
+the host system from the emulated u-boot environment.

So we can test this under qemu? Cool! That means we should get some test.py tests written to match up with the ipv4 tests we have today. My gut reaction is that qemu-ppce500 should also be able to work too as it's also using the E1000 driver.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170128/2d5b5fc3/attachment.sig>
#17 lore raw

RFC PATCH v3 9/11 net: IPv6 documentation

Sounds good to me. I will start testing soon and I am going to automate it.

V sob., 28. jan. 2017 8:51 pop. je oseba Tom Rini <[email protected]> napisala:

Quoted 38 lines · Chris Packham
Quoted 5 lines

---

Changes in v3:
- Add brief testing section

[snip]

Quoted 12 lines
doc/README.ipv6 new file +12 -0
+Testing using QEMU
+------------------
+Refer to README.x86 for instructions on building u-boot for QEMU. Add
+the relevant IPv6 configuration to the configuration (CONFIG_CMD_NET6,
+CONFIG_CMD_PING6) and build.
+
+On the host system run
+
+  sudo qemu-system-i386 -nographic -bios u-boot.rom -net nic -net tap
+
+At the u-boot command line run
+

doc/README.ipv6 line 55

Quoted 10 lines
doc/README.ipv6 new file +10 -0
+  setenv ipaddr 192.168.1.100
+  setenv ip6addr 3ffe::100/64
+
+On the host system run
+
+  sudo ip addr add 3ffe::1/64 dev tap0
+  sudo ip addr add 192.168.1.1
+
+It should now be possible to use ping6 and tftpboot6 to communicate with
+the host system from the emulated u-boot environment.

So we can test this under qemu? Cool! That means we should get some test.py tests written to match up with the ipv4 tests we have today. My gut reaction is that qemu-ppce500 should also be able to work too as it's also using the E1000 driver.

--
Tom

A message that is not in the archive (sent off-list or not yet received): CAFOYHZDE=8yoXh705ZcvyfEdTYavULt19_CEkxPBFBh2yMdTaQ@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAFOYHZCunDB+WAyWQkADLA_Swh7+vrTpVSF_uAvj7SVTG2c0OA@mail.gmail.com

#20 lore raw

RFC PATCH v3 9/11 net: IPv6 documentation

On 29/01/2017 8:51 AM, "Tom Rini" <[email protected]> wrote:

Quoted 5 lines · Chris Packham

---

Changes in v3:
- Add brief testing section

[snip]

Quoted 12 lines
doc/README.ipv6 new file +12 -0
+Testing using QEMU
+------------------
+Refer to README.x86 for instructions on building u-boot for QEMU. Add
+the relevant IPv6 configuration to the configuration (CONFIG_CMD_NET6,
+CONFIG_CMD_PING6) and build.
+
+On the host system run
+
+  sudo qemu-system-i386 -nographic -bios u-boot.rom -net nic -net tap
+
+At the u-boot command line run
+

doc/README.ipv6 line 55

Quoted 10 lines
doc/README.ipv6 new file +10 -0
+  setenv ipaddr 192.168.1.100
+  setenv ip6addr 3ffe::100/64
+
+On the host system run
+
+  sudo ip addr add 3ffe::1/64 dev tap0
+  sudo ip addr add 192.168.1.1
+
+It should now be possible to use ping6 and tftpboot6 to communicate with
+the host system from the emulated u-boot environment.

So we can test this under qemu? Cool!

Yup. Thats been really helpful.

That means we should get some
test.py tests written to match up with the ipv4 tests we have today. My gut reaction is that qemu-ppce500 should also be able to work too as it's also using the E1000 driver.

Yeah my initial plan was to add to/copy from the existing ipv4 tests. There may be a little issue with the default Debian config for tftp-hpa but I assume travis-ci has some way to tweak that.

--
Tom

#21 lore raw

RFC PATCH v3 9/11 net: IPv6 documentation

In reply to Chris Packham

Hi Chris,

On 25 January 2017 at 01:56, Chris Packham <[email protected]> wrote:

Commit message?

Quoted 6 lines

---

Changes in v3:
- Add brief testing section

Quoted 6 lines

Changes in v2: None

 README          |  3 +++
 doc/README.ipv6 | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)
 create mode 100644 doc/README.ipv6

But please use 'U-Boot' throughout.

Regards,
Simon

#22 lore raw

RFC PATCH v3 10/11 net: e1000 enable multicast reception

In reply to Chris Packham

IPv6 neighbor discovery uses various multicast addresses to send the request and receive the response. For neighbor discovery to work properly in U-boot the Ethernet device needs to support joining/leaving various L2 multicast groups or it needs to support multicast/promiscuous mode. For the sake of simplicity the latter approach has been taken. The e1000 hardware has slightly finer grained control in that it is possible to enable support for multicast-promiscuous mode separately from unicast so the extra traffic received is less.

---
Drivers that support multicast reception have it enabled/disabled with CONFIG_MCAST_TFTP. It wouldn't be too hard to create a separate CONFIG_MCAST that is selected by enabling CONFIG_MCAST_TFTP or CONFIG_NET6.

Changes in v3: None
Changes in v2: None

 drivers/net/e1000.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/e1000.c +5 -0
index 875682b1b89e..4c26cb4ce68f 100644
@@ -5067,6 +5067,11 @@ e1000_setup_rctl(struct e1000_hw *hw)
 	rctl &= ~(E1000_RCTL_SZ_4096);
 		rctl |= E1000_RCTL_SZ_2048;
 		rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
+
+#ifdef CONFIG_NET6
+	rctl |= E1000_RCTL_MPE;
+#endif
+
 	E1000_WRITE_REG(hw, RCTL, rctl);
 }
 
Signature · 1 line
2.11.0.24.ge6920cf
#23 lore raw

RFC PATCH v3 10/11 net: e1000 enable multicast reception

Quoted 9 lines · Chris Packham

IPv6 neighbor discovery uses various multicast addresses to send the request and receive the response. For neighbor discovery to work properly in U-boot the Ethernet device needs to support joining/leaving various L2 multicast groups or it needs to support multicast/promiscuous mode. For the sake of simplicity the latter approach has been taken. The e1000 hardware has slightly finer grained control in that it is possible to enable support for multicast-promiscuous mode separately from unicast so the extra traffic received is less.

Quoted 7 lines

---
Drivers that support multicast reception have it enabled/disabled with CONFIG_MCAST_TFTP. It wouldn't be too hard to create a separate CONFIG_MCAST that is selected by enabling CONFIG_MCAST_TFTP or CONFIG_NET6.

That sounds like the right approach to me.

Quoted 29 lines

Changes in v3: None
Changes in v2: None

 drivers/net/e1000.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/e1000.c +5 -1
index 875682b1b89e..4c26cb4ce68f 100644
@@ -5067,6 +5067,11 @@ e1000_setup_rctl(struct e1000_hw *hw)
        rctl &= ~(E1000_RCTL_SZ_4096);
                rctl |= E1000_RCTL_SZ_2048;
                rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
+
+#ifdef CONFIG_NET6
+       rctl |= E1000_RCTL_MPE;
+#endif
+
        E1000_WRITE_REG(hw, RCTL, rctl);
 }
 
--

2.11.0.24.ge6920cf

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#24 lore raw

RFC PATCH v3 11/11 net: tsec: enable promiscuous mode

In reply to Chris Packham

IPv6 neighbor discovery uses various multicast addresses to send the request and receive the response. For neighbor discovery to work properly in U-boot the Ethernet device needs to support joining/leaving various multicast groups or it needs to support multicast/promiscuous mode. For the sake of simplicity the latter approach has been taken.

---
Drivers that support multicast reception have it enabled/disabled with CONFIG_MCAST_TFTP. It wouldn't be too hard to create a separate CONFIG_MCAST that is selected by enabling CONFIG_MCAST_TFTP or CONFIG_NET6 but for now I want to concentrate on getting the rest of the IPv6 code in good shape.

Changes in v3: None
Changes in v2: None

 drivers/net/tsec.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/tsec.c +4 -0
index 7df4c63acfd7..d97bafec1eb2 100644
@@ -515,6 +515,10 @@ static void startup_tsec(struct tsec_private *priv)
 	if ((SVR_MAJ(svr) == 1) || IS_SVR_REV(svr, 2, 0))
 		redundant_init(priv);
 #endif
+#ifdef CONFIG_NET6
+	/* Enable promiscuous mode */
+	setbits_be32(&regs->rctrl, 0x8);
+#endif
 	/* Enable Transmit and Receive */
 	setbits_be32(&regs->maccfg1, MACCFG1_RX_EN | MACCFG1_TX_EN);
 
Signature · 1 line
2.11.0.24.ge6920cf
#25 lore raw

v3 cover IPv6 support

In reply to Chris Packham
Quoted 5 lines · Chris Packham

This series adds basic IPv6 support to U-boot. It is a reboot of my earlier work on this[1]. This latest version is itself a reboot of work that was last posted to the list in late 2015. Right now I've just rebased against master so functionally it is little different to what was last posted.

(trimmed the cc list)

nit: should use 'U-Boot' consistently instead of U-boot or u-boot.

- Simon