From ffdbf3bad5f3f2dd8320dc5628104d6c559cd36c Mon Sep 17 00:00:00 2001 From: Viacheslav Mitrofanov Date: Fri, 2 Dec 2022 12:18:06 +0300 Subject: net: ipv6: Incorporate IPv6 support into u-boot net subsystem Add net_ip6_handler (an IPv6 packet handler) into net_loop. Add neighbor discovery mechanism into network init process. That is the main step to run IPv6 in u-boot. Now u-boot is capable to use NDP and handle IPv6 packets. Signed-off-by: Viacheslav Mitrofanov Reviewed-by: Ramon Fried Reviewed-by: Simon Glass --- net/net.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'net/net.c') diff --git a/net/net.c b/net/net.c index aca20e43b0b..63bf962b53a 100644 --- a/net/net.c +++ b/net/net.c @@ -91,6 +91,8 @@ #include #include #include +#include +#include #include #include #include @@ -343,8 +345,17 @@ void net_auto_load(void) static int net_init_loop(void) { - if (eth_get_dev()) + if (eth_get_dev()) { memcpy(net_ethaddr, eth_get_ethaddr(), 6); + + if (IS_ENABLED(CONFIG_IPV6)) { + ip6_make_lladdr(&net_link_local_ip6, net_ethaddr); + if (!memcmp(&net_ip6, &net_null_addr_ip6, + sizeof(struct in6_addr))) + memcpy(&net_ip6, &net_link_local_ip6, + sizeof(struct in6_addr)); + } + } else /* * Not ideal, but there's no way to get the actual error, and I @@ -385,6 +396,7 @@ int net_init(void) (i + 1) * PKTSIZE_ALIGN; } arp_init(); + ndisc_init(); net_clear_handlers(); /* Only need to setup buffer pointers once. */ @@ -589,6 +601,11 @@ restart: if (arp_timeout_check() > 0) time_start = get_timer(0); + if (IS_ENABLED(CONFIG_IPV6)) { + if (use_ip6 && (ndisc_timeout_check() > 0)) + time_start = get_timer(0); + } + /* * Check the ethernet for a new packet. The ethernet * receive routine will process it. @@ -1243,6 +1260,10 @@ void net_process_received_packet(uchar *in_packet, int len) case PROT_RARP: rarp_receive(ip, len); break; +#endif +#if IS_ENABLED(CONFIG_IPV6) + case PROT_IP6: + net_ip6_handler(et, (struct ip6_hdr *)ip, len); #endif case PROT_IP: debug_cond(DEBUG_NET_PKT, "Got IP\n"); -- cgit v1.2.3 From 7fbf230d79ad531e680475529191e2ec08099c7d Mon Sep 17 00:00:00 2001 From: Viacheslav Mitrofanov Date: Fri, 2 Dec 2022 12:18:07 +0300 Subject: net: tftp: Add IPv6 support for tftpboot The command tftpboot uses IPv4 by default. Add the possibility to use IPv6 instead. If an address in the command is an IPv6 address it will use IPv6 to boot or if there is a suffix -ipv6 in the end of the command it also force using IPv6. All other tftpboot features and parameters are left the same. Signed-off-by: Viacheslav Mitrofanov Reviewed-by: Ramon Fried Reviewed-by: Simon Glass --- net/net.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'net/net.c') diff --git a/net/net.c b/net/net.c index 63bf962b53a..28c8dfdef23 100644 --- a/net/net.c +++ b/net/net.c @@ -1455,7 +1455,14 @@ static int net_check_prereq(enum proto_t protocol) /* Fall through */ case TFTPGET: case TFTPPUT: - if (net_server_ip.s_addr == 0 && !is_serverip_in_cmd()) { + if (IS_ENABLED(CONFIG_IPV6) && use_ip6) { + if (!memcmp(&net_server_ip6, &net_null_addr_ip6, + sizeof(struct in6_addr)) && + !strchr(net_boot_file_name, '[')) { + puts("*** ERROR: `serverip6' not set\n"); + return 1; + } + } else if (net_server_ip.s_addr == 0 && !is_serverip_in_cmd()) { puts("*** ERROR: `serverip' not set\n"); return 1; } @@ -1468,7 +1475,13 @@ common: case NETCONS: case FASTBOOT: case TFTPSRV: - if (net_ip.s_addr == 0) { + if (IS_ENABLED(CONFIG_IPV6) && use_ip6) { + if (!memcmp(&net_link_local_ip6, &net_null_addr_ip6, + sizeof(struct in6_addr))) { + puts("*** ERROR: `ip6addr` not set\n"); + return 1; + } + } else if (net_ip.s_addr == 0) { puts("*** ERROR: `ipaddr' not set\n"); return 1; } -- cgit v1.2.3 From eeb0a2c6938226ee3c46fa66971da9231d64667d Mon Sep 17 00:00:00 2001 From: Viacheslav Mitrofanov Date: Fri, 2 Dec 2022 12:18:08 +0300 Subject: net: ping6: Add ping6 command Implement ping6 command to ping hosts using IPv6. It works the same way as an ordinary ping command. There is no ICMP request so it is not possible to ping our host. This patch adds options in Kconfig and Makefile to build ping6 command. Series-changes: 3 - Added structures and functions descriptions - Added to ping6_receive() return value instead of void Series-changes: 4 - Fixed structures and functions description style Signed-off-by: Viacheslav Mitrofanov Reviewed-by: Ramon Fried Reviewed-by: Simon Glass --- net/net.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'net/net.c') diff --git a/net/net.c b/net/net.c index 28c8dfdef23..1c39acc4936 100644 --- a/net/net.c +++ b/net/net.c @@ -525,6 +525,11 @@ restart: ping_start(); break; #endif +#if defined(CONFIG_CMD_PING6) + case PING6: + ping6_start(); + break; +#endif #if defined(CONFIG_CMD_NFS) && !defined(CONFIG_SPL_BUILD) case NFS: nfs_start(); @@ -1434,6 +1439,14 @@ static int net_check_prereq(enum proto_t protocol) } goto common; #endif +#if defined(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_DNS) case DNS: if (net_dns_server.s_addr == 0) { -- cgit v1.2.3