From b2369a19b8249ae45e501dc453a099f2a20a320f Mon Sep 17 00:00:00 2001 From: Sean Edmond Date: Tue, 25 Jul 2023 16:13:29 -0700 Subject: net: dhcp6: Fix OPT_BOOTFILE_PARAM parsing RFC 5970 states that OPT_BOOTFILE_PARAM (option 60) can be multiple parameters that start with a 16-bit length field followed by the parameter. For example: [ param-len 1 (16-bits) ] [ parameter 1 (variable length) ] This fix ensure we're considering "param-len 1" in the parsing. Signed-off-by: Sean Edmond --- net/dhcpv6.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'net') diff --git a/net/dhcpv6.c b/net/dhcpv6.c index 73a1067877c..4aea779f6f2 100644 --- a/net/dhcpv6.c +++ b/net/dhcpv6.c @@ -304,7 +304,7 @@ static void dhcp6_parse_ia_options(struct dhcp6_option_hdr *ia_ptr, uchar *ia_op static void dhcp6_parse_options(uchar *rx_pkt, unsigned int len) { uchar *option_ptr; - int sol_max_rt_sec, option_len; + int sol_max_rt_sec, option_len, param_len_1; char *s, *e; struct dhcp6_option_hdr *option_hdr; @@ -390,14 +390,23 @@ static void dhcp6_parse_options(uchar *rx_pkt, unsigned int len) case DHCP6_OPTION_OPT_BOOTFILE_PARAM: if (IS_ENABLED(CONFIG_DHCP6_PXE_DHCP_OPTION)) { debug("DHCP6_OPTION_OPT_BOOTFILE_PARAM FOUND\n"); + /* if CONFIG_DHCP6_PXE_DHCP_OPTION is set the PXE config file path + * is contained in the first OPT_BOOTFILE_PARAM argument + */ + param_len_1 = ntohs(*((u16 *)option_ptr)); + option_ptr += sizeof(u16); + if (param_len_1 + sizeof(u16) > option_len) { + debug("Invalid BOOTFILE_PARAM param_len_1. Skipping\n"); + break; + } if (pxelinux_configfile) free(pxelinux_configfile); - pxelinux_configfile = (char *)malloc((option_len + 1) * + pxelinux_configfile = (char *)malloc((param_len_1 + 1) * sizeof(char)); if (pxelinux_configfile) - strlcpy(pxelinux_configfile, option_ptr, option_len + 1); + strlcpy(pxelinux_configfile, option_ptr, param_len_1 + 1); else printf("Error: Failed to allocate pxelinux_configfile\n"); -- cgit v1.2.3 From 91953956d29d104137bb8085a6a73d14fea99e1e Mon Sep 17 00:00:00 2001 From: Sean Edmond Date: Tue, 25 Jul 2023 16:20:30 -0700 Subject: net: Get pxe config file from dhcp option 209 Allow dhcp server pass pxe config file full path by using option 209 Signed-off-by: Sean Edmond --- net/bootp.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'net') diff --git a/net/bootp.c b/net/bootp.c index 7b0f45e18a9..68002909634 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -26,6 +26,7 @@ #ifdef CONFIG_BOOTP_RANDOM_DELAY #include "net_rand.h" #endif +#include #define BOOTP_VENDOR_MAGIC 0x63825363 /* RFC1048 Magic Cookie */ @@ -601,6 +602,10 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip, *e++ = 42; *cnt += 1; #endif + if (IS_ENABLED(CONFIG_BOOTP_PXE_DHCP_OPTION)) { + *e++ = 209; /* PXELINUX Config File */ + *cnt += 1; + } /* no options, so back up to avoid sending an empty request list */ if (*cnt == 0) e -= 2; @@ -909,6 +914,22 @@ static void dhcp_process_options(uchar *popt, uchar *end) net_boot_file_name[size] = 0; } break; + case 209: /* PXELINUX Config File */ + if (IS_ENABLED(CONFIG_BOOTP_PXE_DHCP_OPTION)) { + /* In case it has already been allocated when get DHCP Offer packet, + * free first to avoid memory leak. + */ + if (pxelinux_configfile) + free(pxelinux_configfile); + + pxelinux_configfile = (char *)malloc((oplen + 1) * sizeof(char)); + + if (pxelinux_configfile) + strlcpy(pxelinux_configfile, popt + 2, oplen + 1); + else + printf("Error: Failed to allocate pxelinux_configfile\n"); + } + break; default: #if defined(CONFIG_BOOTP_VENDOREX) if (dhcp_vendorex_proc(popt)) -- cgit v1.2.3 From d71e7f41bfc3f68e259b8070706c586d95a49157 Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Fri, 15 Sep 2023 16:10:06 +0200 Subject: net: eth-uclass: Setup ROM source only when ROM reading passes There is no reason to setup ROM source if read_rom_hwaddr hook doesn't exist or reading mac address fails. It is ending up with confusion about mac address source. It is nicely visible if you put mac address to DT as local-mac-address = [ff ff ff ff ff ff]; but also save ethaddr to variables setenv -f ethaddr 02:18:31:7e:3e:01 Before this patch U-Boot prints that source is ROM Address in ROM is ff:ff:ff:ff:ff:ff Address in environment is 02:18:31:7e:3e:01 After that source is DT: Address in DT is ff:ff:ff:ff:ff:ff Address in environment is 02:18:31:7e:3e:01 Signed-off-by: Michal Simek --- net/eth-uclass.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'net') diff --git a/net/eth-uclass.c b/net/eth-uclass.c index 4311f3fe6e8..565db15b5a9 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -562,10 +562,14 @@ static int eth_post_probe(struct udevice *dev) /* Check if the device has a valid MAC address in device tree */ if (!eth_dev_get_mac_address(dev, pdata->enetaddr) || !is_valid_ethaddr(pdata->enetaddr)) { - source = "ROM"; /* Check if the device has a MAC address in ROM */ - if (eth_get_ops(dev)->read_rom_hwaddr) - eth_get_ops(dev)->read_rom_hwaddr(dev); + if (eth_get_ops(dev)->read_rom_hwaddr) { + int ret; + + ret = eth_get_ops(dev)->read_rom_hwaddr(dev); + if (!ret) + source = "ROM"; + } } eth_env_get_enetaddr_by_index("eth", dev_seq(dev), env_enetaddr); -- cgit v1.2.3 From 798962cedd7e30f95e9a3a6126276b77086a6d08 Mon Sep 17 00:00:00 2001 From: Sean Anderson Date: Sat, 7 Oct 2023 21:53:12 -0400 Subject: net: Add option for tracing packets Add an option to trace all packets send/received. This can be helpful when debugging protocol issues, as the packets can then be imported into wireshark [1] and analyzed further. [1] https://www.wireshark.org/docs/wsug_html_chunked/ChIOImportSection.html Signed-off-by: Sean Anderson Reviewed-by: Simon Glass --- net/net.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'net') diff --git a/net/net.c b/net/net.c index 8357f084101..0fb2d250773 100644 --- a/net/net.c +++ b/net/net.c @@ -1201,6 +1201,9 @@ void net_process_received_packet(uchar *in_packet, int len) ushort cti = 0, vlanid = VLAN_NONE, myvlanid, mynvlanid; debug_cond(DEBUG_NET_PKT, "packet received\n"); + if (DEBUG_NET_PKT_TRACE) + print_hex_dump_bytes("rx: ", DUMP_PREFIX_OFFSET, in_packet, + len); #if defined(CONFIG_CMD_PCAP) pcap_post(in_packet, len, false); -- cgit v1.2.3 From 7907cf80049df56d7a8f66c91626154986fa59e2 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Fri, 20 Oct 2023 09:41:51 -0300 Subject: net: eth-uclass: Improve error message when MAC is not found While bringinp up a new board without the MAC fuses programmed, the following error message was observed: Error: ethernet@30bf0000 address not set. Improve the error message to make it clearer the reason of the failure. Signed-off-by: Fabio Estevam --- net/eth-uclass.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net') diff --git a/net/eth-uclass.c b/net/eth-uclass.c index 565db15b5a9..3d0ec91dfa4 100644 --- a/net/eth-uclass.c +++ b/net/eth-uclass.c @@ -598,7 +598,7 @@ static int eth_post_probe(struct udevice *dev) eth_env_set_enetaddr_by_index("eth", dev_seq(dev), pdata->enetaddr); #else - printf("\nError: %s address not set.\n", + printf("\nError: %s No valid MAC address found.\n", dev->name); return -EINVAL; #endif -- cgit v1.2.3