summaryrefslogtreecommitdiffstats
path: root/net/net.c
Commit message (Collapse)AuthorAgeFilesLines
* net: fix ping in netconsoleYang Liu2021-01-271-1/+1
| | | | | | | Should not init eth device when doing ping in netconsole. Signed-off-by: Yang Liu <yliu@cybertec.com.au> Cc: Joe Hershberger <joe.hershberger@ni.com>
* net: Expose some errors generated in net_initSean Anderson2020-10-101-4/+11
| | | | | | | | | | | | | | | | | net_init does not always succeed, and there is no existing mechanism to discover errors. This patch allows callers of net_init (such as net_init) to handle errors. The root issue is that eth_get_dev can fail, but net_init_loop doesn't expose that. The ideal way to fix eth_get_dev would be to return an error with ERR_PTR, but there are a lot of callers, and all of them just check if it's NULL. Another approach would be to change the signature to something like int eth_get_dev(struct udevice **pdev) but that would require rewriting all of the many callers. Signed-off-by: Sean Anderson <seanga2@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* sntp: use udp frameworkPhilippe Reynes2020-09-301-30/+1
| | | | | | | | | | This commits update the support of sntp to use the framework udp. This change allows to remove all the reference to sntp in the main network file net/net.c. Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* net: add a generic udp protocolPhilippe Reynes2020-09-301-1/+12
| | | | | | | | | | This commit adds a generic udp protocol framework in the network loop. So protocol based on udp may be implemented without modifying the network loop (for example custom wait magic packet). Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* net: ping: reset stored IP addressMarek Szyprowski2020-08-041-0/+4
| | | | | | | | Reset the stored ping IP address before entering a netloop with different protocol to ensure that it won't be interrupted by the received correct ICMP_ECHO_REPLY packet. Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
* net: move random_port() to dnsBaruch Siach2020-06-121-14/+0
| | | | | | | The random_port() routine is not used anywhere else. Make it local to dns.c to reduce code clutter, and shrink generated code a little. Signed-off-by: Baruch Siach <baruch@tkos.co.il>
* net: Fix error if some network features are disabledKrebs, Olaf2020-06-121-2/+4
| | | | | | | If 'CONFIG_CMD_TFTPBOOT' or 'CONFIG_CMD_BOOTP' are disabled, the usage must be disabled, too! Signed-off-by: Olaf Krebs <olaf.krebs@emh-metering.com> CC: Joe Hershberger <joe.hershberger@ni.com>
* common: Drop log.h from common headerSimon Glass2020-05-181-0/+1
| | | | | | Move this header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
* common: Drop bootstage.h from common headerSimon Glass2020-05-181-0/+1
| | | | | | Move this fairly uncommon header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
* net: convert NET_MAXDEFRAG to KconfigRasmus Villemoes2020-02-131-3/+0
| | | | | Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk> Reviewed-by: Simon Glass <sjg@chromium.org>
* common: Move the image globals into image.hSimon Glass2020-01-171-0/+1
| | | | | | | These three globals relate to image handling. Move them to the image header file. Signed-off-by: Simon Glass <sjg@chromium.org>
* image: Rename load_addr, save_addr, save_sizeSimon Glass2020-01-171-1/+1
| | | | | | | | | These global variables are quite short and generic. In fact the same name is more often used locally for struct members and function arguments. Add a image_ prefix to make them easier to distinguish. Signed-off-by: Simon Glass <sjg@chromium.org>
* net: avoid address-of-packed-member errorHeinrich Schuchardt2019-12-091-13/+7
| | | | | | | | | | | | | | | | | | | | sandbox_defconfig does not compile using GCC 9.2.1: net/net.c: In function ‘net_process_received_packet’: net/net.c:1288:23: error: taking address of packed member of ‘struct ip_udp_hdr’ may result in an unaligned pointer value [-Werror=address-of-packed-member] 1288 | sumptr = (ushort *)&(ip->udp_src); | ^~~~~~~~~~~~~~ Avoid the error by using a u8 pointer instead of an u16 pointer and in-lining ntohs(). Simplify the checksumming of the last message byte. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* net: nfs: Only link in NFS code outside of SPL buildsTom Rini2019-12-091-2/+2
| | | | | | | | | While we have networking use cases within SPL we do not support loading files via NFS at this point in time. Disable calling nfs_start() so that the NFS related code can be garbage collected at link time. Signed-off-by: Tom Rini <trini@konsulko.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* net: Always build the string_to_enetaddr() helperJoe Hershberger2019-12-091-12/+0
| | | | | | | | | | | | Part of the env cleanup moved this out of the environment code and into the net code. However, this helper is sometimes needed even when the net stack isn't included. Move the helper to lib/net_utils.c like it's similarly-purposed string_to_ip(). Also rename the moved function to similar naming. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Reported-by: Ondrej Jirman <megous@megous.com>
* Drop CONFIG_SHOW_ACTIVITYSimon Glass2019-12-021-3/+0
| | | | | | This feature is not enabled by any board. Drop it. Signed-off-by: Simon Glass <sjg@chromium.org>
* CVE: net: fix unbounded memcpy of UDP packetliucheng (G)2019-09-041-0/+3
| | | | | | | | | | This patch adds a check to udp_len to fix unbounded memcpy for CVE-2019-14192, CVE-2019-14193 and CVE-2019-14199. Signed-off-by: Cheng Liu <liucheng32@huawei.com> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Reported-by: Fermín Serna <fermin@semmle.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* net: introduce packet capture supportRamon Fried2019-09-041-0/+11
| | | | | | | | | | | | | | Add support for capturing ethernet packets and storing them in memory in PCAP(2.4) format, later to be analyzed by any PCAP viewer software (IE. Wireshark) This feature greatly assist debugging network issues such as detecting dropped packets, packet corruption etc. Signed-off-by: Ramon Fried <rfried.dev@gmail.com> Reviewed-by: Alex Marginean <alexm.osslist@gmail.com> Tested-by: Alex Marginean <alexm.osslist@gmail.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* env: Rename environment.h to env_internal.hSimon Glass2019-08-111-1/+1
| | | | | | | | | | | | | | This file contains lots of internal details about the environment. Most code can include env.h instead, calling the functions there as needed. Rename this file and add a comment at the top to indicate its internal nature. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Joe Hershberger <joe.hershberger@ni.com> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> [trini: Fixup apalis-tk1.c] Signed-off-by: Tom Rini <trini@konsulko.com>
* env: net: Move eth_parse_enetaddr() to net.c/hSimon Glass2019-08-111-0/+12
| | | | | | | This function fits better with the network subsystem, so move it. Signed-off-by: Simon Glass <sjg@chromium.org> Suggested-by: Joe Hershberger <joe.hershberger@ni.com>
* env: Move env_set_hex() to env.hSimon Glass2019-08-111-0/+1
| | | | | | | | Move env_set_hex() over to the new header file along with env_set_addr() which uses it. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* net: remove CONFIG_MCAST_TFTPChris Packham2019-01-241-7/+0
| | | | | | | | | | | | | | No mainline board enables CONFIG_MCAST_TFTP and there have been compilation issues with the code for some time. Additionally, it has a potential buffer underrun issue (reported as a side note in CVE-2018-18439). Remove the multicast TFTP code but keep the driver API for the future addition of IPv6. Cc: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Signed-off-by: Chris Packham <judge.packham@gmail.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* net: explicitly assign errno to return code in case of network failureThomas RIENOESSL2019-01-241-0/+1
| | | | | | | | | | | | | | | When dealing with two ethernet ports and having "netretry" set to "once", it could occur that the connection (e.g. an ARP request) failed, hence the status of the netloop was "NETLOOP_FAIL". Due to the setting of "netretry", the network logic would then switch to the other network interface, assigning "ret" with the return value of "net_start_again()". If this call succeeded we would return 0 (i.e. success) to the caller when in reality the network action failed. Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info> Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* net: Consolidate UDP header functionsDuncan Hare2018-10-101-9/+26
| | | | | | | | Make it possible to add TCP versions of the same, while reusing IP portions. This patch should not change any behavior. Signed-off-by: Duncan Hare <DH@Synoia.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* net: Don't overwrite waiting packets with asynchronous repliesJoe Hershberger2018-10-101-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Peter originally sent a fix, but it breaks a number of other things. This addresses the original reported issue in a different way. That report was: > U-Boot has 1 common buffer to send Ethernet frames, pointed to by > net_tx_packet. When sending to an IP address without knowing the MAC > address, U-Boot makes an ARP request (using the arp_tx_packet buffer) > to find out the MAC address of the IP addressr. When a matching ARP > reply is received, U-Boot continues sending the frame stored in the > net_tx_packet buffer. > > However, in the mean time, if U-Boot needs to send out any network > packets (e.g. replying ping packets or ARP requests for its own IP > address etc.), it will use the net_tx_packet buffer to prepare the > new packet. Thus this buffer is no longer the original packet meant > to be transmitted after the ARP reply. The original packet will be > lost. This instead uses the ARP tx buffer to send async replies in the case where we are actively waiting for an ARP reply. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Reported-by: Tran Tien Dat <peter.trantiendat@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Bin Meng <bmeng.cn@gmail.com>
* net: Consolidate the parsing of bootfileJoe Hershberger2018-07-261-0/+20
| | | | | | | The same basic parsing was implemented in tftp and nfs, so add a helper function to do the work once. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* net: Read bootfile from env on netboot_common()Joe Hershberger2018-07-261-20/+0
| | | | | | | | | | | Instead of depending on a env callback for bootfile, read it explicitly. We do this because the bootfile can be specified on the command line and if it is, we will overwrite the internal variable. If a netboot_common() is called again with no bootfile parameter, we want to use the one in the environment. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* net: Make copy_filename() accept NULL srcJoe Hershberger2018-07-261-2/+2
| | | | | | Rather than crashing, check the src ptr and set dst to empty string. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* net: Re-check prerequisites when autoloadingJoe Hershberger2018-07-261-0/+20
| | | | | | | | | | | | With net autoload, we check the prerequisites for the initial command, but the greater prerequisites when autoloading are not checked. If we would attempt to autoload, check those prerequisites too. If we are not expecting a serverip from the server, then don't worry about it not being set, but don't attempt to load if it isn't. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* net: When checking prerequisites, consider boot_file_nameJoe Hershberger2018-07-261-1/+6
| | | | | | | | | For net_boot_common, we allow the serverip to be specified as part of the boot file name. For net commands that require serverip, include that source as a valid specification of serverip. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Reviewed-by: Alexander Graf <agraf@suse.de>
* net: Prefer command line argumentsAlexander Graf2018-07-021-0/+2
| | | | | | | | | | | | | | | | | | | | | | We can call commands like dhcp and bootp without arguments or with explicit command line arguments that really should tell the code where to look for files instead. Unfortunately, the current code simply overwrites command line arguments in the dhcp case with dhcp values. This patch allows the code to preserve the command line values if they were set on the command line. That way the semantics are slightly more intuitive. The reason this patch does that by introducing a new variable is that we can not rely on net_boot_file_name[0] being unset, as today it's completely legal to call "dhcp" and afterwards run "tftp" and expect the latter to repeat the same query as before. I would prefer not to break that behavior in case anyone relies on it. Signed-off-by: Alexander Graf <agraf@suse.de> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* net: Add new wol command - Wake on LANLothar Felten2018-07-021-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | Add a new command 'wol': Wait for an incoming Wake-on-LAN packet or time out if no WoL packed is received. If the WoL packet contains a password, it is saved in the environment variable 'wolpassword' using the etherwake format (dot or colon separated decimals). Intended use case: a networked device should boot an alternate image. It's attached to a network on a client site, modifying the DHCP server configuration or setup of a tftp server is not allowed. After power on the device waits a few seconds for a WoL packet. If a packet is received, the device boots the alternate image. Otherwise it boots the default image. This method is a simple way to interact with a system via network even if only the MAC address is known. Tools to send WoL packets are available on all common platforms. Some Ethernet drivers seem to pad the incoming packet. The additional padding bytes might be recognized as Wake-on-LAN password bytes. By default enabled in pengwyn_defconfig. Signed-off-by: Lothar Felten <lothar.felten@gmail.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* net: Protect net_state from reentrant net_loop()Leonid Iziumtsev2018-06-131-0/+3
| | | | | | | | | | | | | | | Global variable "net_state" is used in net_loop() state-machine. But it happens that some times the net_loop() can be called multiple times in the same call stack. For example when the netconsole is enabled and we print the message while some other net protocol is in action. Netconsole will overwrite the "net_state" and that will break the logic for earlier started protocol. To protect the state save and restore "net_state" variable each time when we enter and exit net_loop(). Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* net: fastboot: Merge AOSP UDP fastbootAlex Kiernan2018-05-301-0/+7
| | | | | | | | | | | Merge UDP fastboot support from AOSP: https://android.googlesource.com/platform/external/u-boot/+/android-o-mr1-iot-preview-8 Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com> Signed-off-by: Alex Deymo <deymo@google.com> Signed-off-by: Jocelyn Bohr <bohr@google.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* SPDX: Convert a few files that were missed beforeTom Rini2018-05-101-1/+1
| | | | | | | | | | | As part of the main conversion a few files were missed. These files had additional whitespace after the '*' and before the SPDX tag and my previous regex was too strict. This time I did a grep for all SPDX tags and then filtered out anything that matched the correct styles. Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style") Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de> Signed-off-by: Tom Rini <trini@konsulko.com>
* Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTRTom Rini2018-04-271-2/+0
| | | | | | | | We have a large number of places where while we historically referenced gd in the code we no longer do, as well as cases where the code added that line "just in case" during development and never dropped it. Signed-off-by: Tom Rini <trini@konsulko.com>
* net: Fix netretry conditionLeonid Iziumtsev2018-03-221-1/+1
| | | | | | | | | | | | | | | The "net_try_count" counter starts from "1". And the "retrycnt" contains requested amount of retries. With current logic, that means that the actual retry amount will be one time less then what we set in "netretry" env. For example setting "netretry" to "once" will make "retrycnt" equal "1", so no retries will be triggered at all. Fix the logic by changing the statement of "if" condition. Signed-off-by: Leonid Iziumtsev <leonid.iziumtsev@se.atlascopco.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* env: Rename some other getenv()-related functionsSimon Glass2017-08-161-1/+1
| | | | | | | | | | | | | | We are now using an env_ prefix for environment functions. Rename these other functions as well, for consistency: getenv_vlan() getenv_bootm_size() getenv_bootm_low() getenv_bootm_mapsize() env_get_default() Suggested-by: Wolfgang Denk <wd@denx.de> Signed-off-by: Simon Glass <sjg@chromium.org>
* env: Rename getenv_hex(), getenv_yesno(), getenv_ulong()Simon Glass2017-08-161-1/+1
| | | | | | | | We are now using an env_ prefix for environment functions. Rename these for consistency. Also add function comments in common.h. Suggested-by: Wolfgang Denk <wd@denx.de> Signed-off-by: Simon Glass <sjg@chromium.org>
* env: Rename getenv/_f() to env_get()Simon Glass2017-08-161-3/+3
| | | | | | | | | | | We are now using an env_ prefix for environment functions. Rename these two functions for consistency. Also add function comments in common.h. Quite a few places use getenv() in a condition context, provoking a warning from checkpatch. These are fixed up in this patch also. Suggested-by: Wolfgang Denk <wd@denx.de> Signed-off-by: Simon Glass <sjg@chromium.org>
* env: Rename common functions related to setenv()Simon Glass2017-08-161-2/+2
| | | | | | | | | We are now using an env_ prefix for environment functions. Rename these commonly used functions, for consistency. Also add function comments in common.h. Suggested-by: Wolfgang Denk <wd@denx.de> Signed-off-by: Simon Glass <sjg@chromium.org>
* net: Fix compile failure in net.cHolger Dengler2017-08-071-2/+2
| | | | | | | Add missing "defined" statement to fix the compile failures. Signed-off-by: Holger Dengler <dengler@linutronix.de> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* status_led: Kconfig migrationUri Mashiach2017-01-211-9/+11
| | | | | | | | | | | | | Move all of the status LED feature to drivers/led/Kconfig. The LED status definitions were moved from the board configuration files to the defconfig files. TBD: Move all of the definitions in the include/status_led.h to the relevant board's defconfig files. Tested boards: CL-SOM-AM57x, CM-T335 Signed-off-by: Uri Mashiach <uri.mashiach@compulab.co.il>
* net: Stop including NFS overhead in defragment maxJoe Hershberger2016-08-221-9/+1
| | | | | | | | | | | | | At least on bfin, this "specimen" is actually allocated in the BSS and wastes lots of memory in already tight memory conditions. Also, with the introduction of NFSv3 support, this waste got substantially larger. Just remove it. If a board needs a specific different defragment size, that board can override this setting. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
* efi_loader: Add network access supportAlexander Graf2016-05-271-2/+2
| | | | | | | | | | | | | We can now successfully boot EFI applications from disk, but users may want to also run them from a PXE setup. This patch implements rudimentary network support, allowing a payload to send and receive network packets. With this patch, I was able to successfully run grub2 with network access inside of QEMU's -M xlnx-ep108. Signed-off-by: Alexander Graf <agraf@suse.de>
* net: Fix delay in net_retry testJoe Hershberger2016-01-071-4/+3
| | | | | | | | | | | | | | | | | Introduced in 45b4773 (net/arp: account for ARP delay, avoid duplicate packets on timeout) Check the arp timeout and adjust the timeout start time before the call to eth_recv() so that the sandbox driver has the opportunity to adjust the sandbox timer after the new start time has been recorded. Also, change the adjustment amount by 11 seconds instead of exactly the 10 seconds that the ping timout is expecting since the timeout check is looking for the time elapsed to be greater than but not equal to the specified delay. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Reviewed-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Acked-by: Simon Glass <sjg@chromium.org>
* Move console definitions into a new console.h fileSimon Glass2015-11-191-0/+1
| | | | | | | | The console includes a global variable and several functions that are only used by a small subset of U-Boot files. Before adding more functions, move the definitions into their own header file. Signed-off-by: Simon Glass <sjg@chromium.org>
* net: Increase the size of the net_boot_file_name bufferJacob Stiffler2015-10-291-1/+1
| | | | | | | | | | | The net_boot_file_name buffer is used as storage for the bootfilename command line argument to network boot commands such as tftp and nfs. Increase the size of this buffer to 1024 bytes as the current size of 128 bytes is restrictive for arbitrary paths on the server. Signed-off-by: Jacob Stiffler <j-stiffler@ti.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* net/arp: account for ARP delay, avoid duplicate packets on timeoutStefan Brüns2015-10-281-1/+3
| | | | | | | | | | | eth_rx() in the main reception loop may trigger sending a packet which is already timed out (or will immediately) upon reception of an ARP reply. As long as the ARP reply is pending, the timeout handler of a packet should be postponed. Happens on TFTP with bad network (e.g. WLAN). Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
* net: tftp: Move tftp.h file from ./net to ./include/netLukasz Majewski2015-09-071-1/+1
| | | | | | | | | | This change gives the ability to reuse the <tftp.h> header file by other subsystems (like e.g. dfu). Without this change compilation error emerges for the legacy update.c file. Signed-off-by: Lukasz Majewski <l.majewski@majess.pl> Acked-by: Joe Hershberger <joe.hershberger@ni.com>