From a0245818f7f8e375abc00f36ff88326331e4e2f9 Mon Sep 17 00:00:00 2001 From: Sean Edmond Date: Tue, 11 Apr 2023 10:48:46 -0700 Subject: net: dhcp6: Add DHCPv6 (DHCP for IPv6) Adds DHCPv6 protocol to u-boot. Allows for address assignement with DHCPv6 4-message exchange (SOLICIT->ADVERTISE->REQUEST->REPLY). Includes DHCPv6 options required by RFC 8415. Also adds DHCPv6 options required for PXE boot. Possible enhancements: - Duplicate address detection on DHCPv6 assigned address - IPv6 address assignement through SLAAC - Sending/parsing other DHCPv6 options (NTP, DNS, etc...) Signed-off-by: Sean Edmond Reviewed-by: Ramon Fried --- net/net.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'net/net.c') diff --git a/net/net.c b/net/net.c index c9a749f6cc8..8cb8b4b9f34 100644 --- a/net/net.c +++ b/net/net.c @@ -107,6 +107,8 @@ #include #include #include +#include +#include #include "arp.h" #include "bootp.h" #include "cdp.h" @@ -120,8 +122,7 @@ #if defined(CONFIG_CMD_WOL) #include "wol.h" #endif -#include -#include +#include "dhcpv6.h" /** BOOTP EXTENTIONS **/ @@ -135,6 +136,8 @@ struct in_addr net_dns_server; /* Our 2nd DNS IP address */ struct in_addr net_dns_server2; #endif +/* Indicates whether the pxe path prefix / config file was specified in dhcp option */ +char *pxelinux_configfile; /** END OF BOOTP EXTENTIONS **/ @@ -510,6 +513,10 @@ restart: dhcp_request(); /* Basically same as BOOTP */ break; #endif + case DHCP6: + if (IS_ENABLED(CONFIG_CMD_DHCP6)) + dhcp6_start(); + break; #if defined(CONFIG_CMD_BOOTP) case BOOTP: bootp_reset(); -- cgit v1.2.3 From 443d319180a68156ca152d164f446e6789004c1d Mon Sep 17 00:00:00 2001 From: Dmitrii Merkurev Date: Wed, 12 Apr 2023 19:49:30 +0100 Subject: net: add fastboot TCP support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Known limitations are 1. fastboot reboot doesn't work (answering OK but not rebooting) 2. flashing isn't supported (TCP transport only limitation) The command syntax is fastboot tcp Signed-off-by: Dmitrii Merkurev Cc: Ying-Chun Liu (PaulLiu) Cc: Simon Glass Сс: Joe Hershberger Сс: Ramon Fried Reviewed-by: Simon Glass --- net/net.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'net/net.c') diff --git a/net/net.c b/net/net.c index 8cb8b4b9f34..253340f3c44 100644 --- a/net/net.c +++ b/net/net.c @@ -93,7 +93,8 @@ #include #include #include -#include +#include +#include #include #include #if defined(CONFIG_CMD_PCAP) @@ -501,9 +502,14 @@ restart: tftp_start_server(); break; #endif -#ifdef CONFIG_UDP_FUNCTION_FASTBOOT - case FASTBOOT: - fastboot_start_server(); +#if defined(CONFIG_UDP_FUNCTION_FASTBOOT) + case FASTBOOT_UDP: + fastboot_udp_start_server(); + break; +#endif +#if defined(CONFIG_TCP_FUNCTION_FASTBOOT) + case FASTBOOT_TCP: + fastboot_tcp_start_server(); break; #endif #if defined(CONFIG_CMD_DHCP) @@ -1498,7 +1504,8 @@ common: /* Fall through */ case NETCONS: - case FASTBOOT: + case FASTBOOT_UDP: + case FASTBOOT_TCP: case TFTPSRV: if (IS_ENABLED(CONFIG_IPV6) && use_ip6) { if (!memcmp(&net_link_local_ip6, &net_null_addr_ip6, -- cgit v1.2.3 From 6de98b60ba89fb96a3adada11a5b5406f3b3786b Mon Sep 17 00:00:00 2001 From: Ehsan Mohandesi Date: Fri, 21 Apr 2023 17:08:21 -0700 Subject: net: ipv6: Add support for default gateway discovery. In IPv6, the default gateway and prefix length are determined by receiving a router advertisement as defined in - https://www.rfc-editor.org/rfc/rfc4861. Add support for sending router solicitation (RS) and processing router advertisements (RA). If the RA has prefix info option and following conditions are met, then gatewayip6 and net_prefix_length of ip6addr env variables are initialized. These are later consumed by IPv6 code for non-local destination IP. - "Router Lifetime" != 0 - Prefix is NOT link-local prefix (0xfe80::/10) - L flag is 1 - "Valid Lifetime" != 0 Timing Parameters: - MAX_RTR_SOLICITATION_DELAY (0-1s) - RTR_SOLICITATION_INTERVAL (4s) (min retransmit delay) - MAX_RTR_SOLICITATIONS (3 RS transmissions) The functionality is enabled by CONFIG_IPV6_ROUTER_DISCOVERY and invoked automatically from net_init_loop(). Signed-off-by: Ehsan Mohandesi Tested-by: Viacheslav Mitrofanov Reviewed-by: Tested-by: Viacheslav Mitrofanov Reviewed-by: Viacheslav Mitrofanov Tested-by: Sergei Antonov Reviewed-by: Sergei Antonov --- net/net.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'net/net.c') diff --git a/net/net.c b/net/net.c index 253340f3c44..43abbac7c32 100644 --- a/net/net.c +++ b/net/net.c @@ -24,7 +24,7 @@ * - name of bootfile * Next step: ARP * - * LINK_LOCAL: + * LINKLOCAL: * * Prerequisites: - own ethernet address * We want: - own IP address @@ -124,6 +124,7 @@ #include "wol.h" #endif #include "dhcpv6.h" +#include "net_rand.h" /** BOOTP EXTENTIONS **/ @@ -350,6 +351,8 @@ void net_auto_load(void) static int net_init_loop(void) { + static bool first_call = true; + if (eth_get_dev()) { memcpy(net_ethaddr, eth_get_ethaddr(), 6); @@ -369,6 +372,12 @@ static int net_init_loop(void) */ return -ENONET; + if (IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY)) + if (first_call && use_ip6) { + first_call = false; + srand_mac(); /* This is for rand used in ip6_send_rs. */ + net_loop(RS); + } return 0; } @@ -587,6 +596,10 @@ restart: ncsi_probe_packages(); break; #endif + case RS: + if (IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY)) + ip6_send_rs(); + break; default: break; } @@ -684,7 +697,13 @@ restart: x = time_handler; time_handler = (thand_f *)0; (*x)(); - } + } else if (IS_ENABLED(CONFIG_IPV6_ROUTER_DISCOVERY)) + if (time_handler && protocol == RS) + if (!ip6_is_unspecified_addr(&net_gateway6) && + net_prefix_length != 0) { + net_set_state(NETLOOP_SUCCESS); + net_set_timeout_handler(0, NULL); + } if (net_state == NETLOOP_FAIL) ret = net_start_again(); -- cgit v1.2.3