diff options
Diffstat (limited to 'net')
| -rw-r--r-- | net/Kconfig | 20 | ||||
| -rw-r--r-- | net/bootp.c | 24 | ||||
| -rw-r--r-- | net/bootp.h | 4 | ||||
| -rw-r--r-- | net/lwip/dhcp.c | 22 | ||||
| -rw-r--r-- | net/net-common.c | 35 | ||||
| -rw-r--r-- | net/tftp.c | 3 |
6 files changed, 49 insertions, 59 deletions
diff --git a/net/Kconfig b/net/Kconfig index 40ec6bbce76..42fcba5323f 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -60,23 +60,9 @@ config SYS_FAULT_ECHO_LINK_DOWN this option is active, then CONFIG_SYS_FAULT_MII_ADDR also needs to be configured. -config TFTP_PORT - bool "Set TFTP UDP source/destination ports via the environment" - help - If this is defined, the environment variable tftpsrcp is used to - supply the TFTP UDP source port value. If tftpsrcp isn't defined, - the normal pseudo-random port number generator is used. - - Also, the environment variable tftpdstp is used to supply the TFTP - UDP destination port value. If tftpdstp isn't defined, the normal - port 69 is used. - - The purpose for tftpsrcp is to allow a TFTP server to blindly start - the TFTP transfer using the pre-configured target IP address and UDP - port. This has the effect of "punching through" the (Windows XP) - firewall, allowing the remainder of the TFTP transfer to proceed - normally. A better solution is to properly configure the firewall, - but sometimes that is not allowed. +config SYS_FAULT_MII_ADDR + hex "MII address of the PHY to check for the Ethernet link state" + depends on SYS_FAULT_ECHO_LINK_DOWN && LED_STATUS_RED_ENABLE config TFTP_WINDOWSIZE int "TFTP window size" diff --git a/net/bootp.c b/net/bootp.c index 19e7453daed..64fca9a42d9 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -379,6 +379,14 @@ static void bootp_handler(uchar *pkt, unsigned dest, struct in_addr sip, debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n", src, dest, len, sizeof(struct bootp_hdr)); + /* Check the minimum size of a BOOTP packet is respected. + * A BOOTP packet is between 300 bytes and 576 bytes big + */ + if (len < offsetof(struct bootp_hdr, bp_vend) + 64) { + printf("Error: got an invalid BOOTP packet (len=%u)\n", len); + return; + } + bp = (struct bootp_hdr *)pkt; /* Filter out pkts we don't want */ @@ -396,7 +404,8 @@ static void bootp_handler(uchar *pkt, unsigned dest, struct in_addr sip, /* Retrieve extended information (we must parse the vendor area) */ if (net_read_u32((u32 *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC)) - bootp_process_vendor((uchar *)&bp->bp_vend[4], len); + bootp_process_vendor((uchar *)&bp->bp_vend[4], len - + (offsetof(struct bootp_hdr, bp_vend) + 4)); net_set_timeout_handler(0, (thand_f *)0); bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP, "bootp_stop"); @@ -491,9 +500,6 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip, #endif int clientarch = -1; -#if defined(CONFIG_BOOTP_VENDOREX) - u8 *x; -#endif #if defined(CONFIG_BOOTP_SEND_HOSTNAME) char *hostname; #endif @@ -584,12 +590,6 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip, e = add_vci(e); -#if defined(CONFIG_BOOTP_VENDOREX) - x = dhcp_vendorex_prep(e); - if (x) - return x - start; -#endif - *e++ = 55; /* Parameter Request List */ cnt = e++; /* Pointer to count of requested items */ *cnt = 0; @@ -977,10 +977,6 @@ static void dhcp_process_options(uchar *popt, uchar *end) } break; default: -#if defined(CONFIG_BOOTP_VENDOREX) - if (dhcp_vendorex_proc(popt)) - break; -#endif printf("*** Unhandled DHCP Option in OFFER/ACK:" " %d\n", *popt); break; diff --git a/net/bootp.h b/net/bootp.h index 47c743479e7..14f5af68e15 100644 --- a/net/bootp.h +++ b/net/bootp.h @@ -24,10 +24,6 @@ #if defined(CONFIG_CMD_DHCP) /* Minimum DHCP Options size per RFC2131 - results in 576 byte pkt */ #define OPT_FIELD_SIZE 312 -#if defined(CONFIG_BOOTP_VENDOREX) -extern u8 *dhcp_vendorex_prep(u8 *e); /*rtn new e after add own opts. */ -extern u8 *dhcp_vendorex_proc(u8 *e); /*rtn next e if mine,else NULL */ -#endif #else #define OPT_FIELD_SIZE 64 #endif diff --git a/net/lwip/dhcp.c b/net/lwip/dhcp.c index 531bf2c6705..b798014ebcb 100644 --- a/net/lwip/dhcp.c +++ b/net/lwip/dhcp.c @@ -150,25 +150,3 @@ int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_SUCCESS; } - -int dhcp_run(ulong addr, const char *fname, bool autoload) -{ - char *dhcp_argv[] = {"dhcp", NULL, }; -#ifdef CONFIG_CMD_TFTPBOOT - char *tftp_argv[] = {"tftpboot", boot_file_name, NULL, }; -#endif - struct cmd_tbl cmdtp = {}; /* dummy */ - - if (autoload) { -#ifdef CONFIG_CMD_TFTPBOOT - /* Assume DHCP was already performed */ - if (boot_file_name[0]) - return do_tftpb(&cmdtp, 0, 2, tftp_argv); - return 0; -#else - return -EOPNOTSUPP; -#endif - } - - return do_dhcp(&cmdtp, 0, 1, dhcp_argv); -} diff --git a/net/net-common.c b/net/net-common.c index b064557d524..442b0597558 100644 --- a/net/net-common.c +++ b/net/net-common.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include <dm/uclass.h> +#include <env.h> #include <net-common.h> #include <linux/time.h> #include <rtc.h> @@ -48,3 +49,37 @@ void net_sntp_set_rtc(u32 seconds) tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); } + +#if defined(CONFIG_CMD_DHCP) +int dhcp_run(ulong addr, const char *fname, bool autoload) +{ + char *dhcp_argv[] = {"dhcp", NULL, (char *)fname, NULL}; + struct cmd_tbl cmdtp = {}; /* dummy */ + char file_addr[17]; + int old_autoload; + int ret, result; + + log_debug("addr=%lx, fname=%s, autoload=%d\n", addr, fname, autoload); + old_autoload = env_get_yesno("autoload"); + ret = env_set("autoload", autoload ? "y" : "n"); + if (ret) + return log_msg_ret("en1", -EINVAL); + + if (autoload) { + sprintf(file_addr, "%lx", addr); + dhcp_argv[1] = file_addr; + } + + result = do_dhcp(&cmdtp, 0, !autoload ? 1 : fname ? 3 : 2, dhcp_argv); + + ret = env_set("autoload", old_autoload == -1 ? NULL : + old_autoload ? "y" : "n"); + if (ret) + return log_msg_ret("en2", -EINVAL); + + if (result) + return log_msg_ret("res", -ENOENT); + + return 0; +} +#endif diff --git a/net/tftp.c b/net/tftp.c index 1ca9a5ea7cf..1760877107f 100644 --- a/net/tftp.c +++ b/net/tftp.c @@ -926,14 +926,13 @@ void tftp_start(enum proto_t protocol) /* Use a pseudo-random port unless a specific port is set */ tftp_our_port = 1024 + (get_timer(0) % 3072); -#ifdef CONFIG_TFTP_PORT ep = env_get("tftpdstp"); if (ep != NULL) tftp_remote_port = simple_strtol(ep, NULL, 10); ep = env_get("tftpsrcp"); if (ep != NULL) tftp_our_port = simple_strtol(ep, NULL, 10); -#endif + tftp_cur_block = 0; tftp_windowsize = 1; tftp_last_nack = 0; |
