History log of /u-boot/net/nfs.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# d2986567 26-Mar-2024 Sébastien Szymanski <sebastien.szymanski@armadeus.com>

net: nfs: fix file handle length in NFSv3

The NFS protocol uses file handles to refer to file or directory.
In NFSv2 file handles have a fixed size of 32 bytes.
In NFSv3 file handles have a variable length up to 64 bytes. This is
also true for the MOUNT protocol. [1]
When the NFSv3 server replies with a file handle length > 32 bytes, U-Boot
only copies 32 bytes of that file handle and the next LOOKUP Call fails:

BIOS> nfs ${loadaddr} 192.168.1.51:/nfsroot/opos93dev-br/boot/Image
Using ethernet@428a0000 device
File transfer via NFS from server 192.168.1.51; our IP address is 192.168.1.133
Filename '/nfsroot/opos93dev-br/boot/Image'.
Load address: 0x80400000
Loading: *** ERROR: File lookup fail

done
BIOS>

Looking at this transfer in Wireshark, we can see that the server
replies with the following file handle:

length: 36
[hash (CRC-32): 0x230ac67b]
FileHandle: 0100070101005e000000000091763911f87c449fa73c298552db19ba0c9f60002980cfd2

and U-Boot sends the following file handle in the next LOOKUP Call:

length: 32
[hash (CRC-32): 0x6314131b]
FileHandle: 000000240100070101005e000000000091763911f87c449fa73c298552db19ba

Fix this by using a variable length file handle for dirfh.

[1] https://www.rfc-editor.org/rfc/rfc1813.html#page-106

Fixes: b0baca982048 ("net: NFS: Add NFSv3 support")
Signed-off-by: Sébastien Szymanski <sebastien.szymanski@armadeus.com>
Tested-by: Andrew Davis <afd@ti.com>

# e4bd95bb 10-Mar-2023 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: add NFSv1 support

NFSv1 support added by Christian Gmeiner, Thomas Rienoessl,
September 27, 2018. As of now, NFSv3 is the default choice.
if the server does not support NFSv3, we fall back to
versions 2 or 1.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

# 1b6064b3 10-Mar-2023 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

nfs: handle rpc errors for mount calls

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

# 791a43ea 10-Mar-2023 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

nfs: factor out generic reply error handling

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

# 948d7a60 10-Mar-2023 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

nfs: convert supported_nfs_versions bitfield to an enum

Prep. work to support nfs v1.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

# 4e4bf944 31-Jul-2022 Simon Glass <sjg@chromium.org>

common: Drop display_options.h from common header

Move this out of the common header and include it only where needed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17ead040 23-Jul-2022 Tom Rini <trini@konsulko.com>

Audit <flash.h> inclusion

A large number of files include <flash.h> as it used to be how various
SPI flash related functions were found, or for other reasons entirely.
In order to migrate some further CONFIG symbols to Kconfig we need to
not include flash.h in cases where we don't have a NOR flash of some
sort enabled. Furthermore, in cases where we are in common code and it
doesn't make sense to try and further refactor the code itself in to new
files we need to guard this inclusion.

Signed-off-by: Tom Rini <trini@konsulko.com>

# bdbf7a05 18-May-2022 Andrea zi0Black Cappa <zi0Black@protonmail.com>

net: nfs: Fix CVE-2022-30767 (old CVE-2019-14196)

This patch mitigates the vulnerability identified via CVE-2019-14196.

The previous patch was bypassed/ineffective, and now the vulnerability
is identified via CVE-2022-30767. The patch removes the sanity check
introduced to mitigate CVE-2019-14196 since it's ineffective.
filefh3_length is changed to unsigned type integer, preventing negative
numbers from being used during comparison with positive values during
size sanity checks.

Signed-off-by: Andrea zi0Black Cappa <zi0Black@protonmail.com>

# eeda762a 11-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_NFS_TIMEOUT to Kconfig

This converts the following to Kconfig:
CONFIG_NFS_TIMEOUT

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

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>

# 0ee48252 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move flash_perror() to flash.h

This function belongs more in flash.h than common.h so move it.

Also remove the space before the bracket in some calls.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1045315d 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move get_ticks() function out of common.h

This function belongs in time.h so move it over and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 15eea9a1 02-Sep-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: nfs: remove superfluous conversions

rpc_pkt.u.call.data is an array of uint32_t. There is no need to convert
it to uint32_t *.

memcpy() expects void * as it 1st and 2nd argument. There is no point in
converting pointers to char * before passing them to memcpy().

In ntohl(data[1]) != 0 calling ntohl() is superfluous. If the value is
zero, does not depend on the byte order.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d14ee4e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14196: nfs: fix unbounded memcpy with a failed length check at nfs_lookup_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_lookup_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cf3a4f1e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14195: nfs: fix unbounded memcpy with unvalidated length at nfs_readlink_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_readlink_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# aa207cf3 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14194/CVE-2019-14198: nfs: fix unbounded memcpy with a failed length check at nfs_read_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_read_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 741a8a08 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: nfs: fix stack-based buffer overflow in some nfs_handler reply helper functions

This patch adds a check to nfs_handler to fix buffer overflow for CVE-2019-14197,
CVE-2019-14200, CVE-2019-14201, CVE-2019-14202, CVE-2019-14203 and CVE-2019-14204.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

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>

# faecf84a 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Always print basic info for nfs, just like tftp

nfs was only printing basic info about the transfer in the case of a
DEBUG build. Print the same level of detail as tftp always.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347e32b0 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Check subnet against the actual ip address in use for nfs

The check for sending to the gateway was not using the correct variable
for comparison, so it was reporting that packets are sent to the gateway
when they were not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d48d40a0 14-May-2018 Vasily Khoruzhick <anarsoul@gmail.com>

net: nfs: don't fail when nfs_read_reply returns -NFS_RPC_DROP

That can happen if duplicate UDP packet arrived, and that's not uncommon.
Anyway, we ignore packets with rpc_id lower than last we sent for other
requests, so it makes sense to do that for read request as well.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a73588fe 08-Sep-2016 Joe Hershberger <joe.hershberger@ni.com>

Revert "net: nfs: Use the tx buffer to construct rpc msgs"

This reverts commit 998372b4798fd7ebb666f571950df925b8d80f69.

This caused a data abort on some platform.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Guillaume GARDET <guillaume.gardet@free.fr>

# 1ff65d44 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Simplify rpc_add_credentials()

We use an empty hostname, so remove all the "processing" of the
known-to-be-empty hostname and just write 0's where needed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 998372b4 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use the tx buffer to construct rpc msgs

Instead of always allocating a huge temporary buffer on the stack and
then memcpy()ing the result into the transmit buffer, simply figure out
where in the transmit buffer the bytes will belong and write them there
directly as each message is built.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d89ff2df 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Move some prints to debug statements

Much of the information is verbose and derived directly from the
environment. Only output in debug mode. This also saves about 300 bytes
from the code size.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0517cc45 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use consistent names for the rpc_pkt

Use the same name throughout the nfs code and use the same member of the
union to avoid casts.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c629c45f 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Correct a comment

The buffer is of 32-bit elements, not bytes.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 051ed9af 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Consolidate handling of NFSv3 attributes

Instead of repeating the same large snippet for dealing with attributes
it should be shared with a helper function.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347a9015 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Fix lines that are too long

Fix complaints from checkpatch.pl.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 5280c769 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Share the file handle buffer for v2 / v3

The v3 handles can be larger than v2, but that doesn't mean we need a
separate buffer. Reuse the same (larger) buffer for both.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# b0baca98 29-Jul-2016 Guillaume GARDET <guillaume.gardet@free.fr>

net: NFS: Add NFSv3 support

This patch enables NFSv3 support.
If NFSv2 is available use it as usual.
If NFSv2 is not available, but NFSv3 is available, use NFSv3.
If NFSv2 and NFSv3 are not available, print an error message since NFSv4 is not supported.

Tested on iMX6 sabrelite with 4 Linux NFS servers:
* NFSv2 + NFSv3 + NFSv4 server: use NFSv2 protocol
* NFSv2 + NFSv3 server: use NFSv2 protocol
* NFSv3 + NFSv4 server: use NFSv3 protocol
* NFSv3 server: use NFSv3 protocol

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: Tom Rini <trini@konsulko.com>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f8b26c7a 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Remove separate buffer for default name

There is no reason to store the default filename in a separate buffer
only to immediately copy it to the main name buffer. Just write it there
directly and remove the other buffer.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e4ead4a2 01-Jul-2016 Ralf Hubert <r.hubert@technisat.de>

net: Fix incorrect RPC packets on 64-bit systems

This patch fixes incorrect RPC packet layout caused by
'long' type size difference on 64 and 32-bit architectures.

Signed-off-by: Ralf Hubert <r.hubert@technisat.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 69fd0d41 06-Jun-2016 Guillaume GARDET <guillaume.gardet@free.fr>

NFS: Add error message when U-Boot NFS version (V2) is not supported by NFS server

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 55d5fd9a 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Access mapped physmem in net functions

Previously the net functions would access memory assuming physmem did
not need to be mapped. In sandbox, that's not the case.

Now we map the physmem specified by the user in loadaddr to the buffer
that represents that space.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fa84fa70 11-Dec-2012 Matthias Brugger <matthias.bgg@gmail.com>

net: nfs: add dynamic wait period

This patch tackles the time out problem which leads to break the
boot process, when loading file over nfs. The patch does two things.

First of all, we just ignore messages that arrive with a rpc_id smaller
then the client id. We just interpret this messages as answers to
formaly timed out messages.

Second, when a time out occurs we double the time to wait, so that we
do not stress the server resending the last message.

Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
Tested-by: Enric Balletbo i Serra <eballetbo@gmail.com>

# 48a3e999 03-Jul-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: nfs: make NFS_TIMEOUT configurable

NFS_TIMEOUT is constant value defined in net/nfs.c. But sometimes it needs to adjust.
This patch enables to override NFS_TIMEOUT by defining CONFIG_NFS_TIMEOUT in a board specific config file.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c9f6c91b 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: nfs.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# aabb8cb0 09-Nov-2009 Evan Samanas <esamanas@xes-inc.com>

nfs: NfsTimeout() updates

- NfsTimeout() does not correctly update the NFS timeout value which
results in NfsTimeout() only being called once in certain situations.
This can result in the 'nfs' command hanging indefinetly. For
example, the command:

nfs 192.168.0.1:/home/user/file

will not exit until ctrl-c is pressed if 192.168.0.1 does not have an
NFS server running.

This issue is resolved by reinitializting the NFS timeout value inside
NfsTimeout() when a timeout occurs.

- Make the 'nfs' command print the 'T' character when a timeout occurs.
Previously there was no indication that timeouts were occuring.

- Mimic the 'tftpboot' command and when a download fails print "Retry
count exceeded; starting again", and restart the download taking the
'netretry' environment variable into account.

Signed-off-by: Evan Samanas <esamanas@xes-inc.com>
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

Tested on TQM8xxL.

Tested by: Wolfgang Denk <wd@denx.de>

Tested on MPC8527DS.

Tested by: Ed Swarthout <Ed.Swarthout@freescale.com>

# f64ef9bb 19-Nov-2009 Ed Swarthout <Ed.Swarthout@freescale.com>

fix nfs symlink name corruption

An off by one error may cause nfs readlink lookup fail if
nfs_path_buff has non-zero data from a previous use.

Loading: *** ERROR: File lookup fail

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# fe891ecf 31-Jan-2008 Hiroshi Ito <ito@mlb.co.jp>

NFS Timeout with large files.

Retry to send NFS packet before reaching timeout.

Signed-off-by: Hiroshi Ito <ito@mlb.co.jp>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# 29c29c02 23-Oct-2007 Guennadi Liakhovetski <lg@denx.de>

Fix typo in nfs.c

An obvious typo. Originally fixed in linkstation u-boot port.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>

# 3865b1fb 10-Jul-2007 Stefan Roese <sr@denx.de>

Fix some compile problems introduced by the latest CFG_CMD_xxx cleanup

Signed-off-by: Stefan Roese <sr@denx.de>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 23a7a32d 05-Aug-2005 Wolfgang Denk <wd@denx.de>

Fix return code of NFS command
Patch by Hiroshi Ito, 11 Dec 2004

# c43352cc 03-Aug-2005 Wolfgang Denk <wd@denx.de>

Fix endianess problem in TFTP / NFS default filenames
Patch by Hiroshi Ito, 06 Dec 2004

# a5725fab 28-Sep-2004 Wolfgang Denk <wd@denx.de>

* Patch by Ganapathi C, 04 Aug 2004:
Fix NFS timeout issue

# e94d2cd9 30-Jun-2004 Wolfgang Denk <wd@denx.de>

* Fix "cls" command when used with splash screen

* Increase NFS download timeout (now 1 min - 10 sec is to short for a
slow download of a big image)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# c3f9d493 13-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Yuli Barcohen, 4 Mar 2004:
Fix problems with GCC 3.3.x which changed handling of global
variables explicitly initialized to zero (now in .bss instead of
.data as before).

* Patch by Leon Kukovec, 02 Mar 2004:
add strswab() to fix IDE LBA capacity, firmware and model numbers
on little endian machines

* Patch by Masami Komiya, 02 Mar 2004:
- Remove get_ticks() from NFS code
- Add verification of RPC transaction ID

* Patch by Pierre Aubert, 02 Mar 2004:
cleanup for IDE and USB drivers for MPC5200

# 11dadd54 26-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Steven Scholz, 25 Feb 2004:
- Timeouts in FPGA code should be based on CFG_HZ
- Minor cleanup in code for Altera FPGA ACEX1K

* Patch by Steven Scholz, 25 Feb 2004:
Changed "Directory Hierarchy" section in README

* Patch by Masami Komiya, 25 Feb 2004:
Reduce copy count in nfs_read_reply() of NFS code

# a084f7da 24-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 24 Feb 2004:
Update NetBootFileXferSize in NFS code

* Patch by Scott McNutt, 24 Feb 2004:
fix packet length in NFS code

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# e4bd95bb 10-Mar-2023 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

net: add NFSv1 support

NFSv1 support added by Christian Gmeiner, Thomas Rienoessl,
September 27, 2018. As of now, NFSv3 is the default choice.
if the server does not support NFSv3, we fall back to
versions 2 or 1.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

# 1b6064b3 10-Mar-2023 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

nfs: handle rpc errors for mount calls

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

# 791a43ea 10-Mar-2023 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

nfs: factor out generic reply error handling

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

# 948d7a60 10-Mar-2023 Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

nfs: convert supported_nfs_versions bitfield to an enum

Prep. work to support nfs v1.

Signed-off-by: Thomas RIENOESSL <thomas.rienoessl@bachmann.info>

# 4e4bf944 31-Jul-2022 Simon Glass <sjg@chromium.org>

common: Drop display_options.h from common header

Move this out of the common header and include it only where needed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17ead040 23-Jul-2022 Tom Rini <trini@konsulko.com>

Audit <flash.h> inclusion

A large number of files include <flash.h> as it used to be how various
SPI flash related functions were found, or for other reasons entirely.
In order to migrate some further CONFIG symbols to Kconfig we need to
not include flash.h in cases where we don't have a NOR flash of some
sort enabled. Furthermore, in cases where we are in common code and it
doesn't make sense to try and further refactor the code itself in to new
files we need to guard this inclusion.

Signed-off-by: Tom Rini <trini@konsulko.com>

# bdbf7a05 18-May-2022 Andrea zi0Black Cappa <zi0Black@protonmail.com>

net: nfs: Fix CVE-2022-30767 (old CVE-2019-14196)

This patch mitigates the vulnerability identified via CVE-2019-14196.

The previous patch was bypassed/ineffective, and now the vulnerability
is identified via CVE-2022-30767. The patch removes the sanity check
introduced to mitigate CVE-2019-14196 since it's ineffective.
filefh3_length is changed to unsigned type integer, preventing negative
numbers from being used during comparison with positive values during
size sanity checks.

Signed-off-by: Andrea zi0Black Cappa <zi0Black@protonmail.com>

# eeda762a 11-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_NFS_TIMEOUT to Kconfig

This converts the following to Kconfig:
CONFIG_NFS_TIMEOUT

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

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>

# 0ee48252 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move flash_perror() to flash.h

This function belongs more in flash.h than common.h so move it.

Also remove the space before the bracket in some calls.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1045315d 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move get_ticks() function out of common.h

This function belongs in time.h so move it over and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 15eea9a1 02-Sep-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: nfs: remove superfluous conversions

rpc_pkt.u.call.data is an array of uint32_t. There is no need to convert
it to uint32_t *.

memcpy() expects void * as it 1st and 2nd argument. There is no point in
converting pointers to char * before passing them to memcpy().

In ntohl(data[1]) != 0 calling ntohl() is superfluous. If the value is
zero, does not depend on the byte order.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d14ee4e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14196: nfs: fix unbounded memcpy with a failed length check at nfs_lookup_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_lookup_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cf3a4f1e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14195: nfs: fix unbounded memcpy with unvalidated length at nfs_readlink_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_readlink_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# aa207cf3 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14194/CVE-2019-14198: nfs: fix unbounded memcpy with a failed length check at nfs_read_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_read_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 741a8a08 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: nfs: fix stack-based buffer overflow in some nfs_handler reply helper functions

This patch adds a check to nfs_handler to fix buffer overflow for CVE-2019-14197,
CVE-2019-14200, CVE-2019-14201, CVE-2019-14202, CVE-2019-14203 and CVE-2019-14204.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

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>

# faecf84a 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Always print basic info for nfs, just like tftp

nfs was only printing basic info about the transfer in the case of a
DEBUG build. Print the same level of detail as tftp always.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347e32b0 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Check subnet against the actual ip address in use for nfs

The check for sending to the gateway was not using the correct variable
for comparison, so it was reporting that packets are sent to the gateway
when they were not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d48d40a0 14-May-2018 Vasily Khoruzhick <anarsoul@gmail.com>

net: nfs: don't fail when nfs_read_reply returns -NFS_RPC_DROP

That can happen if duplicate UDP packet arrived, and that's not uncommon.
Anyway, we ignore packets with rpc_id lower than last we sent for other
requests, so it makes sense to do that for read request as well.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a73588fe 08-Sep-2016 Joe Hershberger <joe.hershberger@ni.com>

Revert "net: nfs: Use the tx buffer to construct rpc msgs"

This reverts commit 998372b4798fd7ebb666f571950df925b8d80f69.

This caused a data abort on some platform.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Guillaume GARDET <guillaume.gardet@free.fr>

# 1ff65d44 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Simplify rpc_add_credentials()

We use an empty hostname, so remove all the "processing" of the
known-to-be-empty hostname and just write 0's where needed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 998372b4 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use the tx buffer to construct rpc msgs

Instead of always allocating a huge temporary buffer on the stack and
then memcpy()ing the result into the transmit buffer, simply figure out
where in the transmit buffer the bytes will belong and write them there
directly as each message is built.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d89ff2df 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Move some prints to debug statements

Much of the information is verbose and derived directly from the
environment. Only output in debug mode. This also saves about 300 bytes
from the code size.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0517cc45 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use consistent names for the rpc_pkt

Use the same name throughout the nfs code and use the same member of the
union to avoid casts.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c629c45f 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Correct a comment

The buffer is of 32-bit elements, not bytes.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 051ed9af 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Consolidate handling of NFSv3 attributes

Instead of repeating the same large snippet for dealing with attributes
it should be shared with a helper function.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347a9015 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Fix lines that are too long

Fix complaints from checkpatch.pl.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 5280c769 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Share the file handle buffer for v2 / v3

The v3 handles can be larger than v2, but that doesn't mean we need a
separate buffer. Reuse the same (larger) buffer for both.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# b0baca98 29-Jul-2016 Guillaume GARDET <guillaume.gardet@free.fr>

net: NFS: Add NFSv3 support

This patch enables NFSv3 support.
If NFSv2 is available use it as usual.
If NFSv2 is not available, but NFSv3 is available, use NFSv3.
If NFSv2 and NFSv3 are not available, print an error message since NFSv4 is not supported.

Tested on iMX6 sabrelite with 4 Linux NFS servers:
* NFSv2 + NFSv3 + NFSv4 server: use NFSv2 protocol
* NFSv2 + NFSv3 server: use NFSv2 protocol
* NFSv3 + NFSv4 server: use NFSv3 protocol
* NFSv3 server: use NFSv3 protocol

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: Tom Rini <trini@konsulko.com>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f8b26c7a 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Remove separate buffer for default name

There is no reason to store the default filename in a separate buffer
only to immediately copy it to the main name buffer. Just write it there
directly and remove the other buffer.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e4ead4a2 01-Jul-2016 Ralf Hubert <r.hubert@technisat.de>

net: Fix incorrect RPC packets on 64-bit systems

This patch fixes incorrect RPC packet layout caused by
'long' type size difference on 64 and 32-bit architectures.

Signed-off-by: Ralf Hubert <r.hubert@technisat.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 69fd0d41 06-Jun-2016 Guillaume GARDET <guillaume.gardet@free.fr>

NFS: Add error message when U-Boot NFS version (V2) is not supported by NFS server

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 55d5fd9a 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Access mapped physmem in net functions

Previously the net functions would access memory assuming physmem did
not need to be mapped. In sandbox, that's not the case.

Now we map the physmem specified by the user in loadaddr to the buffer
that represents that space.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fa84fa70 11-Dec-2012 Matthias Brugger <matthias.bgg@gmail.com>

net: nfs: add dynamic wait period

This patch tackles the time out problem which leads to break the
boot process, when loading file over nfs. The patch does two things.

First of all, we just ignore messages that arrive with a rpc_id smaller
then the client id. We just interpret this messages as answers to
formaly timed out messages.

Second, when a time out occurs we double the time to wait, so that we
do not stress the server resending the last message.

Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
Tested-by: Enric Balletbo i Serra <eballetbo@gmail.com>

# 48a3e999 03-Jul-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: nfs: make NFS_TIMEOUT configurable

NFS_TIMEOUT is constant value defined in net/nfs.c. But sometimes it needs to adjust.
This patch enables to override NFS_TIMEOUT by defining CONFIG_NFS_TIMEOUT in a board specific config file.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c9f6c91b 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: nfs.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# aabb8cb0 09-Nov-2009 Evan Samanas <esamanas@xes-inc.com>

nfs: NfsTimeout() updates

- NfsTimeout() does not correctly update the NFS timeout value which
results in NfsTimeout() only being called once in certain situations.
This can result in the 'nfs' command hanging indefinetly. For
example, the command:

nfs 192.168.0.1:/home/user/file

will not exit until ctrl-c is pressed if 192.168.0.1 does not have an
NFS server running.

This issue is resolved by reinitializting the NFS timeout value inside
NfsTimeout() when a timeout occurs.

- Make the 'nfs' command print the 'T' character when a timeout occurs.
Previously there was no indication that timeouts were occuring.

- Mimic the 'tftpboot' command and when a download fails print "Retry
count exceeded; starting again", and restart the download taking the
'netretry' environment variable into account.

Signed-off-by: Evan Samanas <esamanas@xes-inc.com>
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

Tested on TQM8xxL.

Tested by: Wolfgang Denk <wd@denx.de>

Tested on MPC8527DS.

Tested by: Ed Swarthout <Ed.Swarthout@freescale.com>

# f64ef9bb 19-Nov-2009 Ed Swarthout <Ed.Swarthout@freescale.com>

fix nfs symlink name corruption

An off by one error may cause nfs readlink lookup fail if
nfs_path_buff has non-zero data from a previous use.

Loading: *** ERROR: File lookup fail

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# fe891ecf 31-Jan-2008 Hiroshi Ito <ito@mlb.co.jp>

NFS Timeout with large files.

Retry to send NFS packet before reaching timeout.

Signed-off-by: Hiroshi Ito <ito@mlb.co.jp>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# 29c29c02 23-Oct-2007 Guennadi Liakhovetski <lg@denx.de>

Fix typo in nfs.c

An obvious typo. Originally fixed in linkstation u-boot port.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>

# 3865b1fb 10-Jul-2007 Stefan Roese <sr@denx.de>

Fix some compile problems introduced by the latest CFG_CMD_xxx cleanup

Signed-off-by: Stefan Roese <sr@denx.de>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 23a7a32d 05-Aug-2005 Wolfgang Denk <wd@denx.de>

Fix return code of NFS command
Patch by Hiroshi Ito, 11 Dec 2004

# c43352cc 03-Aug-2005 Wolfgang Denk <wd@denx.de>

Fix endianess problem in TFTP / NFS default filenames
Patch by Hiroshi Ito, 06 Dec 2004

# a5725fab 28-Sep-2004 Wolfgang Denk <wd@denx.de>

* Patch by Ganapathi C, 04 Aug 2004:
Fix NFS timeout issue

# e94d2cd9 30-Jun-2004 Wolfgang Denk <wd@denx.de>

* Fix "cls" command when used with splash screen

* Increase NFS download timeout (now 1 min - 10 sec is to short for a
slow download of a big image)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# c3f9d493 13-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Yuli Barcohen, 4 Mar 2004:
Fix problems with GCC 3.3.x which changed handling of global
variables explicitly initialized to zero (now in .bss instead of
.data as before).

* Patch by Leon Kukovec, 02 Mar 2004:
add strswab() to fix IDE LBA capacity, firmware and model numbers
on little endian machines

* Patch by Masami Komiya, 02 Mar 2004:
- Remove get_ticks() from NFS code
- Add verification of RPC transaction ID

* Patch by Pierre Aubert, 02 Mar 2004:
cleanup for IDE and USB drivers for MPC5200

# 11dadd54 26-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Steven Scholz, 25 Feb 2004:
- Timeouts in FPGA code should be based on CFG_HZ
- Minor cleanup in code for Altera FPGA ACEX1K

* Patch by Steven Scholz, 25 Feb 2004:
Changed "Directory Hierarchy" section in README

* Patch by Masami Komiya, 25 Feb 2004:
Reduce copy count in nfs_read_reply() of NFS code

# a084f7da 24-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 24 Feb 2004:
Update NetBootFileXferSize in NFS code

* Patch by Scott McNutt, 24 Feb 2004:
fix packet length in NFS code

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 4e4bf944 31-Jul-2022 Simon Glass <sjg@chromium.org>

common: Drop display_options.h from common header

Move this out of the common header and include it only where needed.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17ead040 23-Jul-2022 Tom Rini <trini@konsulko.com>

Audit <flash.h> inclusion

A large number of files include <flash.h> as it used to be how various
SPI flash related functions were found, or for other reasons entirely.
In order to migrate some further CONFIG symbols to Kconfig we need to
not include flash.h in cases where we don't have a NOR flash of some
sort enabled. Furthermore, in cases where we are in common code and it
doesn't make sense to try and further refactor the code itself in to new
files we need to guard this inclusion.

Signed-off-by: Tom Rini <trini@konsulko.com>

# bdbf7a05 18-May-2022 Andrea zi0Black Cappa <zi0Black@protonmail.com>

net: nfs: Fix CVE-2022-30767 (old CVE-2019-14196)

This patch mitigates the vulnerability identified via CVE-2019-14196.

The previous patch was bypassed/ineffective, and now the vulnerability
is identified via CVE-2022-30767. The patch removes the sanity check
introduced to mitigate CVE-2019-14196 since it's ineffective.
filefh3_length is changed to unsigned type integer, preventing negative
numbers from being used during comparison with positive values during
size sanity checks.

Signed-off-by: Andrea zi0Black Cappa <zi0Black@protonmail.com>

# eeda762a 11-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_NFS_TIMEOUT to Kconfig

This converts the following to Kconfig:
CONFIG_NFS_TIMEOUT

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

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>

# 0ee48252 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move flash_perror() to flash.h

This function belongs more in flash.h than common.h so move it.

Also remove the space before the bracket in some calls.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1045315d 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move get_ticks() function out of common.h

This function belongs in time.h so move it over and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 15eea9a1 02-Sep-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: nfs: remove superfluous conversions

rpc_pkt.u.call.data is an array of uint32_t. There is no need to convert
it to uint32_t *.

memcpy() expects void * as it 1st and 2nd argument. There is no point in
converting pointers to char * before passing them to memcpy().

In ntohl(data[1]) != 0 calling ntohl() is superfluous. If the value is
zero, does not depend on the byte order.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d14ee4e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14196: nfs: fix unbounded memcpy with a failed length check at nfs_lookup_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_lookup_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cf3a4f1e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14195: nfs: fix unbounded memcpy with unvalidated length at nfs_readlink_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_readlink_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# aa207cf3 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14194/CVE-2019-14198: nfs: fix unbounded memcpy with a failed length check at nfs_read_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_read_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 741a8a08 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: nfs: fix stack-based buffer overflow in some nfs_handler reply helper functions

This patch adds a check to nfs_handler to fix buffer overflow for CVE-2019-14197,
CVE-2019-14200, CVE-2019-14201, CVE-2019-14202, CVE-2019-14203 and CVE-2019-14204.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

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>

# faecf84a 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Always print basic info for nfs, just like tftp

nfs was only printing basic info about the transfer in the case of a
DEBUG build. Print the same level of detail as tftp always.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347e32b0 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Check subnet against the actual ip address in use for nfs

The check for sending to the gateway was not using the correct variable
for comparison, so it was reporting that packets are sent to the gateway
when they were not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d48d40a0 14-May-2018 Vasily Khoruzhick <anarsoul@gmail.com>

net: nfs: don't fail when nfs_read_reply returns -NFS_RPC_DROP

That can happen if duplicate UDP packet arrived, and that's not uncommon.
Anyway, we ignore packets with rpc_id lower than last we sent for other
requests, so it makes sense to do that for read request as well.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a73588fe 08-Sep-2016 Joe Hershberger <joe.hershberger@ni.com>

Revert "net: nfs: Use the tx buffer to construct rpc msgs"

This reverts commit 998372b4798fd7ebb666f571950df925b8d80f69.

This caused a data abort on some platform.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Guillaume GARDET <guillaume.gardet@free.fr>

# 1ff65d44 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Simplify rpc_add_credentials()

We use an empty hostname, so remove all the "processing" of the
known-to-be-empty hostname and just write 0's where needed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 998372b4 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use the tx buffer to construct rpc msgs

Instead of always allocating a huge temporary buffer on the stack and
then memcpy()ing the result into the transmit buffer, simply figure out
where in the transmit buffer the bytes will belong and write them there
directly as each message is built.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d89ff2df 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Move some prints to debug statements

Much of the information is verbose and derived directly from the
environment. Only output in debug mode. This also saves about 300 bytes
from the code size.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0517cc45 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use consistent names for the rpc_pkt

Use the same name throughout the nfs code and use the same member of the
union to avoid casts.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c629c45f 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Correct a comment

The buffer is of 32-bit elements, not bytes.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 051ed9af 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Consolidate handling of NFSv3 attributes

Instead of repeating the same large snippet for dealing with attributes
it should be shared with a helper function.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347a9015 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Fix lines that are too long

Fix complaints from checkpatch.pl.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 5280c769 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Share the file handle buffer for v2 / v3

The v3 handles can be larger than v2, but that doesn't mean we need a
separate buffer. Reuse the same (larger) buffer for both.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# b0baca98 29-Jul-2016 Guillaume GARDET <guillaume.gardet@free.fr>

net: NFS: Add NFSv3 support

This patch enables NFSv3 support.
If NFSv2 is available use it as usual.
If NFSv2 is not available, but NFSv3 is available, use NFSv3.
If NFSv2 and NFSv3 are not available, print an error message since NFSv4 is not supported.

Tested on iMX6 sabrelite with 4 Linux NFS servers:
* NFSv2 + NFSv3 + NFSv4 server: use NFSv2 protocol
* NFSv2 + NFSv3 server: use NFSv2 protocol
* NFSv3 + NFSv4 server: use NFSv3 protocol
* NFSv3 server: use NFSv3 protocol

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: Tom Rini <trini@konsulko.com>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f8b26c7a 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Remove separate buffer for default name

There is no reason to store the default filename in a separate buffer
only to immediately copy it to the main name buffer. Just write it there
directly and remove the other buffer.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e4ead4a2 01-Jul-2016 Ralf Hubert <r.hubert@technisat.de>

net: Fix incorrect RPC packets on 64-bit systems

This patch fixes incorrect RPC packet layout caused by
'long' type size difference on 64 and 32-bit architectures.

Signed-off-by: Ralf Hubert <r.hubert@technisat.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 69fd0d41 06-Jun-2016 Guillaume GARDET <guillaume.gardet@free.fr>

NFS: Add error message when U-Boot NFS version (V2) is not supported by NFS server

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 55d5fd9a 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Access mapped physmem in net functions

Previously the net functions would access memory assuming physmem did
not need to be mapped. In sandbox, that's not the case.

Now we map the physmem specified by the user in loadaddr to the buffer
that represents that space.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fa84fa70 11-Dec-2012 Matthias Brugger <matthias.bgg@gmail.com>

net: nfs: add dynamic wait period

This patch tackles the time out problem which leads to break the
boot process, when loading file over nfs. The patch does two things.

First of all, we just ignore messages that arrive with a rpc_id smaller
then the client id. We just interpret this messages as answers to
formaly timed out messages.

Second, when a time out occurs we double the time to wait, so that we
do not stress the server resending the last message.

Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
Tested-by: Enric Balletbo i Serra <eballetbo@gmail.com>

# 48a3e999 03-Jul-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: nfs: make NFS_TIMEOUT configurable

NFS_TIMEOUT is constant value defined in net/nfs.c. But sometimes it needs to adjust.
This patch enables to override NFS_TIMEOUT by defining CONFIG_NFS_TIMEOUT in a board specific config file.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c9f6c91b 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: nfs.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# aabb8cb0 09-Nov-2009 Evan Samanas <esamanas@xes-inc.com>

nfs: NfsTimeout() updates

- NfsTimeout() does not correctly update the NFS timeout value which
results in NfsTimeout() only being called once in certain situations.
This can result in the 'nfs' command hanging indefinetly. For
example, the command:

nfs 192.168.0.1:/home/user/file

will not exit until ctrl-c is pressed if 192.168.0.1 does not have an
NFS server running.

This issue is resolved by reinitializting the NFS timeout value inside
NfsTimeout() when a timeout occurs.

- Make the 'nfs' command print the 'T' character when a timeout occurs.
Previously there was no indication that timeouts were occuring.

- Mimic the 'tftpboot' command and when a download fails print "Retry
count exceeded; starting again", and restart the download taking the
'netretry' environment variable into account.

Signed-off-by: Evan Samanas <esamanas@xes-inc.com>
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

Tested on TQM8xxL.

Tested by: Wolfgang Denk <wd@denx.de>

Tested on MPC8527DS.

Tested by: Ed Swarthout <Ed.Swarthout@freescale.com>

# f64ef9bb 19-Nov-2009 Ed Swarthout <Ed.Swarthout@freescale.com>

fix nfs symlink name corruption

An off by one error may cause nfs readlink lookup fail if
nfs_path_buff has non-zero data from a previous use.

Loading: *** ERROR: File lookup fail

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# fe891ecf 31-Jan-2008 Hiroshi Ito <ito@mlb.co.jp>

NFS Timeout with large files.

Retry to send NFS packet before reaching timeout.

Signed-off-by: Hiroshi Ito <ito@mlb.co.jp>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# 29c29c02 23-Oct-2007 Guennadi Liakhovetski <lg@denx.de>

Fix typo in nfs.c

An obvious typo. Originally fixed in linkstation u-boot port.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>

# 3865b1fb 10-Jul-2007 Stefan Roese <sr@denx.de>

Fix some compile problems introduced by the latest CFG_CMD_xxx cleanup

Signed-off-by: Stefan Roese <sr@denx.de>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 23a7a32d 05-Aug-2005 Wolfgang Denk <wd@denx.de>

Fix return code of NFS command
Patch by Hiroshi Ito, 11 Dec 2004

# c43352cc 03-Aug-2005 Wolfgang Denk <wd@denx.de>

Fix endianess problem in TFTP / NFS default filenames
Patch by Hiroshi Ito, 06 Dec 2004

# a5725fab 28-Sep-2004 Wolfgang Denk <wd@denx.de>

* Patch by Ganapathi C, 04 Aug 2004:
Fix NFS timeout issue

# e94d2cd9 30-Jun-2004 Wolfgang Denk <wd@denx.de>

* Fix "cls" command when used with splash screen

* Increase NFS download timeout (now 1 min - 10 sec is to short for a
slow download of a big image)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# c3f9d493 13-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Yuli Barcohen, 4 Mar 2004:
Fix problems with GCC 3.3.x which changed handling of global
variables explicitly initialized to zero (now in .bss instead of
.data as before).

* Patch by Leon Kukovec, 02 Mar 2004:
add strswab() to fix IDE LBA capacity, firmware and model numbers
on little endian machines

* Patch by Masami Komiya, 02 Mar 2004:
- Remove get_ticks() from NFS code
- Add verification of RPC transaction ID

* Patch by Pierre Aubert, 02 Mar 2004:
cleanup for IDE and USB drivers for MPC5200

# 11dadd54 26-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Steven Scholz, 25 Feb 2004:
- Timeouts in FPGA code should be based on CFG_HZ
- Minor cleanup in code for Altera FPGA ACEX1K

* Patch by Steven Scholz, 25 Feb 2004:
Changed "Directory Hierarchy" section in README

* Patch by Masami Komiya, 25 Feb 2004:
Reduce copy count in nfs_read_reply() of NFS code

# a084f7da 24-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 24 Feb 2004:
Update NetBootFileXferSize in NFS code

* Patch by Scott McNutt, 24 Feb 2004:
fix packet length in NFS code

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 17ead040 23-Jul-2022 Tom Rini <trini@konsulko.com>

Audit <flash.h> inclusion

A large number of files include <flash.h> as it used to be how various
SPI flash related functions were found, or for other reasons entirely.
In order to migrate some further CONFIG symbols to Kconfig we need to
not include flash.h in cases where we don't have a NOR flash of some
sort enabled. Furthermore, in cases where we are in common code and it
doesn't make sense to try and further refactor the code itself in to new
files we need to guard this inclusion.

Signed-off-by: Tom Rini <trini@konsulko.com>

# bdbf7a05 18-May-2022 Andrea zi0Black Cappa <zi0Black@protonmail.com>

net: nfs: Fix CVE-2022-30767 (old CVE-2019-14196)

This patch mitigates the vulnerability identified via CVE-2019-14196.

The previous patch was bypassed/ineffective, and now the vulnerability
is identified via CVE-2022-30767. The patch removes the sanity check
introduced to mitigate CVE-2019-14196 since it's ineffective.
filefh3_length is changed to unsigned type integer, preventing negative
numbers from being used during comparison with positive values during
size sanity checks.

Signed-off-by: Andrea zi0Black Cappa <zi0Black@protonmail.com>

# eeda762a 11-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_NFS_TIMEOUT to Kconfig

This converts the following to Kconfig:
CONFIG_NFS_TIMEOUT

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

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>

# 0ee48252 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move flash_perror() to flash.h

This function belongs more in flash.h than common.h so move it.

Also remove the space before the bracket in some calls.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1045315d 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move get_ticks() function out of common.h

This function belongs in time.h so move it over and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 15eea9a1 02-Sep-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: nfs: remove superfluous conversions

rpc_pkt.u.call.data is an array of uint32_t. There is no need to convert
it to uint32_t *.

memcpy() expects void * as it 1st and 2nd argument. There is no point in
converting pointers to char * before passing them to memcpy().

In ntohl(data[1]) != 0 calling ntohl() is superfluous. If the value is
zero, does not depend on the byte order.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d14ee4e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14196: nfs: fix unbounded memcpy with a failed length check at nfs_lookup_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_lookup_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cf3a4f1e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14195: nfs: fix unbounded memcpy with unvalidated length at nfs_readlink_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_readlink_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# aa207cf3 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14194/CVE-2019-14198: nfs: fix unbounded memcpy with a failed length check at nfs_read_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_read_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 741a8a08 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: nfs: fix stack-based buffer overflow in some nfs_handler reply helper functions

This patch adds a check to nfs_handler to fix buffer overflow for CVE-2019-14197,
CVE-2019-14200, CVE-2019-14201, CVE-2019-14202, CVE-2019-14203 and CVE-2019-14204.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

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>

# faecf84a 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Always print basic info for nfs, just like tftp

nfs was only printing basic info about the transfer in the case of a
DEBUG build. Print the same level of detail as tftp always.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347e32b0 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Check subnet against the actual ip address in use for nfs

The check for sending to the gateway was not using the correct variable
for comparison, so it was reporting that packets are sent to the gateway
when they were not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d48d40a0 14-May-2018 Vasily Khoruzhick <anarsoul@gmail.com>

net: nfs: don't fail when nfs_read_reply returns -NFS_RPC_DROP

That can happen if duplicate UDP packet arrived, and that's not uncommon.
Anyway, we ignore packets with rpc_id lower than last we sent for other
requests, so it makes sense to do that for read request as well.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a73588fe 08-Sep-2016 Joe Hershberger <joe.hershberger@ni.com>

Revert "net: nfs: Use the tx buffer to construct rpc msgs"

This reverts commit 998372b4798fd7ebb666f571950df925b8d80f69.

This caused a data abort on some platform.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Guillaume GARDET <guillaume.gardet@free.fr>

# 1ff65d44 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Simplify rpc_add_credentials()

We use an empty hostname, so remove all the "processing" of the
known-to-be-empty hostname and just write 0's where needed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 998372b4 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use the tx buffer to construct rpc msgs

Instead of always allocating a huge temporary buffer on the stack and
then memcpy()ing the result into the transmit buffer, simply figure out
where in the transmit buffer the bytes will belong and write them there
directly as each message is built.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d89ff2df 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Move some prints to debug statements

Much of the information is verbose and derived directly from the
environment. Only output in debug mode. This also saves about 300 bytes
from the code size.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0517cc45 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use consistent names for the rpc_pkt

Use the same name throughout the nfs code and use the same member of the
union to avoid casts.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c629c45f 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Correct a comment

The buffer is of 32-bit elements, not bytes.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 051ed9af 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Consolidate handling of NFSv3 attributes

Instead of repeating the same large snippet for dealing with attributes
it should be shared with a helper function.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347a9015 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Fix lines that are too long

Fix complaints from checkpatch.pl.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 5280c769 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Share the file handle buffer for v2 / v3

The v3 handles can be larger than v2, but that doesn't mean we need a
separate buffer. Reuse the same (larger) buffer for both.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# b0baca98 29-Jul-2016 Guillaume GARDET <guillaume.gardet@free.fr>

net: NFS: Add NFSv3 support

This patch enables NFSv3 support.
If NFSv2 is available use it as usual.
If NFSv2 is not available, but NFSv3 is available, use NFSv3.
If NFSv2 and NFSv3 are not available, print an error message since NFSv4 is not supported.

Tested on iMX6 sabrelite with 4 Linux NFS servers:
* NFSv2 + NFSv3 + NFSv4 server: use NFSv2 protocol
* NFSv2 + NFSv3 server: use NFSv2 protocol
* NFSv3 + NFSv4 server: use NFSv3 protocol
* NFSv3 server: use NFSv3 protocol

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: Tom Rini <trini@konsulko.com>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f8b26c7a 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Remove separate buffer for default name

There is no reason to store the default filename in a separate buffer
only to immediately copy it to the main name buffer. Just write it there
directly and remove the other buffer.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e4ead4a2 01-Jul-2016 Ralf Hubert <r.hubert@technisat.de>

net: Fix incorrect RPC packets on 64-bit systems

This patch fixes incorrect RPC packet layout caused by
'long' type size difference on 64 and 32-bit architectures.

Signed-off-by: Ralf Hubert <r.hubert@technisat.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 69fd0d41 06-Jun-2016 Guillaume GARDET <guillaume.gardet@free.fr>

NFS: Add error message when U-Boot NFS version (V2) is not supported by NFS server

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 55d5fd9a 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Access mapped physmem in net functions

Previously the net functions would access memory assuming physmem did
not need to be mapped. In sandbox, that's not the case.

Now we map the physmem specified by the user in loadaddr to the buffer
that represents that space.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fa84fa70 11-Dec-2012 Matthias Brugger <matthias.bgg@gmail.com>

net: nfs: add dynamic wait period

This patch tackles the time out problem which leads to break the
boot process, when loading file over nfs. The patch does two things.

First of all, we just ignore messages that arrive with a rpc_id smaller
then the client id. We just interpret this messages as answers to
formaly timed out messages.

Second, when a time out occurs we double the time to wait, so that we
do not stress the server resending the last message.

Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
Tested-by: Enric Balletbo i Serra <eballetbo@gmail.com>

# 48a3e999 03-Jul-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: nfs: make NFS_TIMEOUT configurable

NFS_TIMEOUT is constant value defined in net/nfs.c. But sometimes it needs to adjust.
This patch enables to override NFS_TIMEOUT by defining CONFIG_NFS_TIMEOUT in a board specific config file.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c9f6c91b 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: nfs.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# aabb8cb0 09-Nov-2009 Evan Samanas <esamanas@xes-inc.com>

nfs: NfsTimeout() updates

- NfsTimeout() does not correctly update the NFS timeout value which
results in NfsTimeout() only being called once in certain situations.
This can result in the 'nfs' command hanging indefinetly. For
example, the command:

nfs 192.168.0.1:/home/user/file

will not exit until ctrl-c is pressed if 192.168.0.1 does not have an
NFS server running.

This issue is resolved by reinitializting the NFS timeout value inside
NfsTimeout() when a timeout occurs.

- Make the 'nfs' command print the 'T' character when a timeout occurs.
Previously there was no indication that timeouts were occuring.

- Mimic the 'tftpboot' command and when a download fails print "Retry
count exceeded; starting again", and restart the download taking the
'netretry' environment variable into account.

Signed-off-by: Evan Samanas <esamanas@xes-inc.com>
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

Tested on TQM8xxL.

Tested by: Wolfgang Denk <wd@denx.de>

Tested on MPC8527DS.

Tested by: Ed Swarthout <Ed.Swarthout@freescale.com>

# f64ef9bb 19-Nov-2009 Ed Swarthout <Ed.Swarthout@freescale.com>

fix nfs symlink name corruption

An off by one error may cause nfs readlink lookup fail if
nfs_path_buff has non-zero data from a previous use.

Loading: *** ERROR: File lookup fail

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# fe891ecf 31-Jan-2008 Hiroshi Ito <ito@mlb.co.jp>

NFS Timeout with large files.

Retry to send NFS packet before reaching timeout.

Signed-off-by: Hiroshi Ito <ito@mlb.co.jp>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# 29c29c02 23-Oct-2007 Guennadi Liakhovetski <lg@denx.de>

Fix typo in nfs.c

An obvious typo. Originally fixed in linkstation u-boot port.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>

# 3865b1fb 10-Jul-2007 Stefan Roese <sr@denx.de>

Fix some compile problems introduced by the latest CFG_CMD_xxx cleanup

Signed-off-by: Stefan Roese <sr@denx.de>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 23a7a32d 05-Aug-2005 Wolfgang Denk <wd@denx.de>

Fix return code of NFS command
Patch by Hiroshi Ito, 11 Dec 2004

# c43352cc 03-Aug-2005 Wolfgang Denk <wd@denx.de>

Fix endianess problem in TFTP / NFS default filenames
Patch by Hiroshi Ito, 06 Dec 2004

# a5725fab 28-Sep-2004 Wolfgang Denk <wd@denx.de>

* Patch by Ganapathi C, 04 Aug 2004:
Fix NFS timeout issue

# e94d2cd9 30-Jun-2004 Wolfgang Denk <wd@denx.de>

* Fix "cls" command when used with splash screen

* Increase NFS download timeout (now 1 min - 10 sec is to short for a
slow download of a big image)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# c3f9d493 13-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Yuli Barcohen, 4 Mar 2004:
Fix problems with GCC 3.3.x which changed handling of global
variables explicitly initialized to zero (now in .bss instead of
.data as before).

* Patch by Leon Kukovec, 02 Mar 2004:
add strswab() to fix IDE LBA capacity, firmware and model numbers
on little endian machines

* Patch by Masami Komiya, 02 Mar 2004:
- Remove get_ticks() from NFS code
- Add verification of RPC transaction ID

* Patch by Pierre Aubert, 02 Mar 2004:
cleanup for IDE and USB drivers for MPC5200

# 11dadd54 26-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Steven Scholz, 25 Feb 2004:
- Timeouts in FPGA code should be based on CFG_HZ
- Minor cleanup in code for Altera FPGA ACEX1K

* Patch by Steven Scholz, 25 Feb 2004:
Changed "Directory Hierarchy" section in README

* Patch by Masami Komiya, 25 Feb 2004:
Reduce copy count in nfs_read_reply() of NFS code

# a084f7da 24-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 24 Feb 2004:
Update NetBootFileXferSize in NFS code

* Patch by Scott McNutt, 24 Feb 2004:
fix packet length in NFS code

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# bdbf7a05 18-May-2022 Andrea zi0Black Cappa <zi0Black@protonmail.com>

net: nfs: Fix CVE-2022-30767 (old CVE-2019-14196)

This patch mitigates the vulnerability identified via CVE-2019-14196.

The previous patch was bypassed/ineffective, and now the vulnerability
is identified via CVE-2022-30767. The patch removes the sanity check
introduced to mitigate CVE-2019-14196 since it's ineffective.
filefh3_length is changed to unsigned type integer, preventing negative
numbers from being used during comparison with positive values during
size sanity checks.

Signed-off-by: Andrea zi0Black Cappa <zi0Black@protonmail.com>

# eeda762a 11-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_NFS_TIMEOUT to Kconfig

This converts the following to Kconfig:
CONFIG_NFS_TIMEOUT

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

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>

# 0ee48252 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move flash_perror() to flash.h

This function belongs more in flash.h than common.h so move it.

Also remove the space before the bracket in some calls.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1045315d 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move get_ticks() function out of common.h

This function belongs in time.h so move it over and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 15eea9a1 02-Sep-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: nfs: remove superfluous conversions

rpc_pkt.u.call.data is an array of uint32_t. There is no need to convert
it to uint32_t *.

memcpy() expects void * as it 1st and 2nd argument. There is no point in
converting pointers to char * before passing them to memcpy().

In ntohl(data[1]) != 0 calling ntohl() is superfluous. If the value is
zero, does not depend on the byte order.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d14ee4e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14196: nfs: fix unbounded memcpy with a failed length check at nfs_lookup_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_lookup_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cf3a4f1e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14195: nfs: fix unbounded memcpy with unvalidated length at nfs_readlink_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_readlink_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# aa207cf3 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14194/CVE-2019-14198: nfs: fix unbounded memcpy with a failed length check at nfs_read_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_read_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 741a8a08 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: nfs: fix stack-based buffer overflow in some nfs_handler reply helper functions

This patch adds a check to nfs_handler to fix buffer overflow for CVE-2019-14197,
CVE-2019-14200, CVE-2019-14201, CVE-2019-14202, CVE-2019-14203 and CVE-2019-14204.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

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>

# faecf84a 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Always print basic info for nfs, just like tftp

nfs was only printing basic info about the transfer in the case of a
DEBUG build. Print the same level of detail as tftp always.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347e32b0 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Check subnet against the actual ip address in use for nfs

The check for sending to the gateway was not using the correct variable
for comparison, so it was reporting that packets are sent to the gateway
when they were not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d48d40a0 14-May-2018 Vasily Khoruzhick <anarsoul@gmail.com>

net: nfs: don't fail when nfs_read_reply returns -NFS_RPC_DROP

That can happen if duplicate UDP packet arrived, and that's not uncommon.
Anyway, we ignore packets with rpc_id lower than last we sent for other
requests, so it makes sense to do that for read request as well.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a73588fe 08-Sep-2016 Joe Hershberger <joe.hershberger@ni.com>

Revert "net: nfs: Use the tx buffer to construct rpc msgs"

This reverts commit 998372b4798fd7ebb666f571950df925b8d80f69.

This caused a data abort on some platform.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Guillaume GARDET <guillaume.gardet@free.fr>

# 1ff65d44 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Simplify rpc_add_credentials()

We use an empty hostname, so remove all the "processing" of the
known-to-be-empty hostname and just write 0's where needed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 998372b4 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use the tx buffer to construct rpc msgs

Instead of always allocating a huge temporary buffer on the stack and
then memcpy()ing the result into the transmit buffer, simply figure out
where in the transmit buffer the bytes will belong and write them there
directly as each message is built.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d89ff2df 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Move some prints to debug statements

Much of the information is verbose and derived directly from the
environment. Only output in debug mode. This also saves about 300 bytes
from the code size.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0517cc45 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use consistent names for the rpc_pkt

Use the same name throughout the nfs code and use the same member of the
union to avoid casts.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c629c45f 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Correct a comment

The buffer is of 32-bit elements, not bytes.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 051ed9af 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Consolidate handling of NFSv3 attributes

Instead of repeating the same large snippet for dealing with attributes
it should be shared with a helper function.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347a9015 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Fix lines that are too long

Fix complaints from checkpatch.pl.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 5280c769 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Share the file handle buffer for v2 / v3

The v3 handles can be larger than v2, but that doesn't mean we need a
separate buffer. Reuse the same (larger) buffer for both.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# b0baca98 29-Jul-2016 Guillaume GARDET <guillaume.gardet@free.fr>

net: NFS: Add NFSv3 support

This patch enables NFSv3 support.
If NFSv2 is available use it as usual.
If NFSv2 is not available, but NFSv3 is available, use NFSv3.
If NFSv2 and NFSv3 are not available, print an error message since NFSv4 is not supported.

Tested on iMX6 sabrelite with 4 Linux NFS servers:
* NFSv2 + NFSv3 + NFSv4 server: use NFSv2 protocol
* NFSv2 + NFSv3 server: use NFSv2 protocol
* NFSv3 + NFSv4 server: use NFSv3 protocol
* NFSv3 server: use NFSv3 protocol

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: Tom Rini <trini@konsulko.com>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f8b26c7a 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Remove separate buffer for default name

There is no reason to store the default filename in a separate buffer
only to immediately copy it to the main name buffer. Just write it there
directly and remove the other buffer.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e4ead4a2 01-Jul-2016 Ralf Hubert <r.hubert@technisat.de>

net: Fix incorrect RPC packets on 64-bit systems

This patch fixes incorrect RPC packet layout caused by
'long' type size difference on 64 and 32-bit architectures.

Signed-off-by: Ralf Hubert <r.hubert@technisat.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 69fd0d41 06-Jun-2016 Guillaume GARDET <guillaume.gardet@free.fr>

NFS: Add error message when U-Boot NFS version (V2) is not supported by NFS server

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 55d5fd9a 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Access mapped physmem in net functions

Previously the net functions would access memory assuming physmem did
not need to be mapped. In sandbox, that's not the case.

Now we map the physmem specified by the user in loadaddr to the buffer
that represents that space.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fa84fa70 11-Dec-2012 Matthias Brugger <matthias.bgg@gmail.com>

net: nfs: add dynamic wait period

This patch tackles the time out problem which leads to break the
boot process, when loading file over nfs. The patch does two things.

First of all, we just ignore messages that arrive with a rpc_id smaller
then the client id. We just interpret this messages as answers to
formaly timed out messages.

Second, when a time out occurs we double the time to wait, so that we
do not stress the server resending the last message.

Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
Tested-by: Enric Balletbo i Serra <eballetbo@gmail.com>

# 48a3e999 03-Jul-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: nfs: make NFS_TIMEOUT configurable

NFS_TIMEOUT is constant value defined in net/nfs.c. But sometimes it needs to adjust.
This patch enables to override NFS_TIMEOUT by defining CONFIG_NFS_TIMEOUT in a board specific config file.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c9f6c91b 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: nfs.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# aabb8cb0 09-Nov-2009 Evan Samanas <esamanas@xes-inc.com>

nfs: NfsTimeout() updates

- NfsTimeout() does not correctly update the NFS timeout value which
results in NfsTimeout() only being called once in certain situations.
This can result in the 'nfs' command hanging indefinetly. For
example, the command:

nfs 192.168.0.1:/home/user/file

will not exit until ctrl-c is pressed if 192.168.0.1 does not have an
NFS server running.

This issue is resolved by reinitializting the NFS timeout value inside
NfsTimeout() when a timeout occurs.

- Make the 'nfs' command print the 'T' character when a timeout occurs.
Previously there was no indication that timeouts were occuring.

- Mimic the 'tftpboot' command and when a download fails print "Retry
count exceeded; starting again", and restart the download taking the
'netretry' environment variable into account.

Signed-off-by: Evan Samanas <esamanas@xes-inc.com>
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

Tested on TQM8xxL.

Tested by: Wolfgang Denk <wd@denx.de>

Tested on MPC8527DS.

Tested by: Ed Swarthout <Ed.Swarthout@freescale.com>

# f64ef9bb 19-Nov-2009 Ed Swarthout <Ed.Swarthout@freescale.com>

fix nfs symlink name corruption

An off by one error may cause nfs readlink lookup fail if
nfs_path_buff has non-zero data from a previous use.

Loading: *** ERROR: File lookup fail

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# fe891ecf 31-Jan-2008 Hiroshi Ito <ito@mlb.co.jp>

NFS Timeout with large files.

Retry to send NFS packet before reaching timeout.

Signed-off-by: Hiroshi Ito <ito@mlb.co.jp>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# 29c29c02 23-Oct-2007 Guennadi Liakhovetski <lg@denx.de>

Fix typo in nfs.c

An obvious typo. Originally fixed in linkstation u-boot port.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>

# 3865b1fb 10-Jul-2007 Stefan Roese <sr@denx.de>

Fix some compile problems introduced by the latest CFG_CMD_xxx cleanup

Signed-off-by: Stefan Roese <sr@denx.de>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 23a7a32d 05-Aug-2005 Wolfgang Denk <wd@denx.de>

Fix return code of NFS command
Patch by Hiroshi Ito, 11 Dec 2004

# c43352cc 03-Aug-2005 Wolfgang Denk <wd@denx.de>

Fix endianess problem in TFTP / NFS default filenames
Patch by Hiroshi Ito, 06 Dec 2004

# a5725fab 28-Sep-2004 Wolfgang Denk <wd@denx.de>

* Patch by Ganapathi C, 04 Aug 2004:
Fix NFS timeout issue

# e94d2cd9 30-Jun-2004 Wolfgang Denk <wd@denx.de>

* Fix "cls" command when used with splash screen

* Increase NFS download timeout (now 1 min - 10 sec is to short for a
slow download of a big image)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# c3f9d493 13-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Yuli Barcohen, 4 Mar 2004:
Fix problems with GCC 3.3.x which changed handling of global
variables explicitly initialized to zero (now in .bss instead of
.data as before).

* Patch by Leon Kukovec, 02 Mar 2004:
add strswab() to fix IDE LBA capacity, firmware and model numbers
on little endian machines

* Patch by Masami Komiya, 02 Mar 2004:
- Remove get_ticks() from NFS code
- Add verification of RPC transaction ID

* Patch by Pierre Aubert, 02 Mar 2004:
cleanup for IDE and USB drivers for MPC5200

# 11dadd54 26-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Steven Scholz, 25 Feb 2004:
- Timeouts in FPGA code should be based on CFG_HZ
- Minor cleanup in code for Altera FPGA ACEX1K

* Patch by Steven Scholz, 25 Feb 2004:
Changed "Directory Hierarchy" section in README

* Patch by Masami Komiya, 25 Feb 2004:
Reduce copy count in nfs_read_reply() of NFS code

# a084f7da 24-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 24 Feb 2004:
Update NetBootFileXferSize in NFS code

* Patch by Scott McNutt, 24 Feb 2004:
fix packet length in NFS code

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# eeda762a 11-Mar-2022 Tom Rini <trini@konsulko.com>

Convert CONFIG_NFS_TIMEOUT to Kconfig

This converts the following to Kconfig:
CONFIG_NFS_TIMEOUT

Cc: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

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>

# 0ee48252 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move flash_perror() to flash.h

This function belongs more in flash.h than common.h so move it.

Also remove the space before the bracket in some calls.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1045315d 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move get_ticks() function out of common.h

This function belongs in time.h so move it over and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 15eea9a1 02-Sep-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: nfs: remove superfluous conversions

rpc_pkt.u.call.data is an array of uint32_t. There is no need to convert
it to uint32_t *.

memcpy() expects void * as it 1st and 2nd argument. There is no point in
converting pointers to char * before passing them to memcpy().

In ntohl(data[1]) != 0 calling ntohl() is superfluous. If the value is
zero, does not depend on the byte order.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d14ee4e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14196: nfs: fix unbounded memcpy with a failed length check at nfs_lookup_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_lookup_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cf3a4f1e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14195: nfs: fix unbounded memcpy with unvalidated length at nfs_readlink_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_readlink_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# aa207cf3 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14194/CVE-2019-14198: nfs: fix unbounded memcpy with a failed length check at nfs_read_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_read_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 741a8a08 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: nfs: fix stack-based buffer overflow in some nfs_handler reply helper functions

This patch adds a check to nfs_handler to fix buffer overflow for CVE-2019-14197,
CVE-2019-14200, CVE-2019-14201, CVE-2019-14202, CVE-2019-14203 and CVE-2019-14204.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

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>

# faecf84a 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Always print basic info for nfs, just like tftp

nfs was only printing basic info about the transfer in the case of a
DEBUG build. Print the same level of detail as tftp always.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347e32b0 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Check subnet against the actual ip address in use for nfs

The check for sending to the gateway was not using the correct variable
for comparison, so it was reporting that packets are sent to the gateway
when they were not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d48d40a0 14-May-2018 Vasily Khoruzhick <anarsoul@gmail.com>

net: nfs: don't fail when nfs_read_reply returns -NFS_RPC_DROP

That can happen if duplicate UDP packet arrived, and that's not uncommon.
Anyway, we ignore packets with rpc_id lower than last we sent for other
requests, so it makes sense to do that for read request as well.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a73588fe 08-Sep-2016 Joe Hershberger <joe.hershberger@ni.com>

Revert "net: nfs: Use the tx buffer to construct rpc msgs"

This reverts commit 998372b4798fd7ebb666f571950df925b8d80f69.

This caused a data abort on some platform.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Guillaume GARDET <guillaume.gardet@free.fr>

# 1ff65d44 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Simplify rpc_add_credentials()

We use an empty hostname, so remove all the "processing" of the
known-to-be-empty hostname and just write 0's where needed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 998372b4 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use the tx buffer to construct rpc msgs

Instead of always allocating a huge temporary buffer on the stack and
then memcpy()ing the result into the transmit buffer, simply figure out
where in the transmit buffer the bytes will belong and write them there
directly as each message is built.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d89ff2df 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Move some prints to debug statements

Much of the information is verbose and derived directly from the
environment. Only output in debug mode. This also saves about 300 bytes
from the code size.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0517cc45 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use consistent names for the rpc_pkt

Use the same name throughout the nfs code and use the same member of the
union to avoid casts.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c629c45f 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Correct a comment

The buffer is of 32-bit elements, not bytes.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 051ed9af 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Consolidate handling of NFSv3 attributes

Instead of repeating the same large snippet for dealing with attributes
it should be shared with a helper function.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347a9015 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Fix lines that are too long

Fix complaints from checkpatch.pl.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 5280c769 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Share the file handle buffer for v2 / v3

The v3 handles can be larger than v2, but that doesn't mean we need a
separate buffer. Reuse the same (larger) buffer for both.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# b0baca98 29-Jul-2016 Guillaume GARDET <guillaume.gardet@free.fr>

net: NFS: Add NFSv3 support

This patch enables NFSv3 support.
If NFSv2 is available use it as usual.
If NFSv2 is not available, but NFSv3 is available, use NFSv3.
If NFSv2 and NFSv3 are not available, print an error message since NFSv4 is not supported.

Tested on iMX6 sabrelite with 4 Linux NFS servers:
* NFSv2 + NFSv3 + NFSv4 server: use NFSv2 protocol
* NFSv2 + NFSv3 server: use NFSv2 protocol
* NFSv3 + NFSv4 server: use NFSv3 protocol
* NFSv3 server: use NFSv3 protocol

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: Tom Rini <trini@konsulko.com>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f8b26c7a 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Remove separate buffer for default name

There is no reason to store the default filename in a separate buffer
only to immediately copy it to the main name buffer. Just write it there
directly and remove the other buffer.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e4ead4a2 01-Jul-2016 Ralf Hubert <r.hubert@technisat.de>

net: Fix incorrect RPC packets on 64-bit systems

This patch fixes incorrect RPC packet layout caused by
'long' type size difference on 64 and 32-bit architectures.

Signed-off-by: Ralf Hubert <r.hubert@technisat.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 69fd0d41 06-Jun-2016 Guillaume GARDET <guillaume.gardet@free.fr>

NFS: Add error message when U-Boot NFS version (V2) is not supported by NFS server

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 55d5fd9a 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Access mapped physmem in net functions

Previously the net functions would access memory assuming physmem did
not need to be mapped. In sandbox, that's not the case.

Now we map the physmem specified by the user in loadaddr to the buffer
that represents that space.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fa84fa70 11-Dec-2012 Matthias Brugger <matthias.bgg@gmail.com>

net: nfs: add dynamic wait period

This patch tackles the time out problem which leads to break the
boot process, when loading file over nfs. The patch does two things.

First of all, we just ignore messages that arrive with a rpc_id smaller
then the client id. We just interpret this messages as answers to
formaly timed out messages.

Second, when a time out occurs we double the time to wait, so that we
do not stress the server resending the last message.

Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
Tested-by: Enric Balletbo i Serra <eballetbo@gmail.com>

# 48a3e999 03-Jul-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: nfs: make NFS_TIMEOUT configurable

NFS_TIMEOUT is constant value defined in net/nfs.c. But sometimes it needs to adjust.
This patch enables to override NFS_TIMEOUT by defining CONFIG_NFS_TIMEOUT in a board specific config file.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c9f6c91b 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: nfs.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# aabb8cb0 09-Nov-2009 Evan Samanas <esamanas@xes-inc.com>

nfs: NfsTimeout() updates

- NfsTimeout() does not correctly update the NFS timeout value which
results in NfsTimeout() only being called once in certain situations.
This can result in the 'nfs' command hanging indefinetly. For
example, the command:

nfs 192.168.0.1:/home/user/file

will not exit until ctrl-c is pressed if 192.168.0.1 does not have an
NFS server running.

This issue is resolved by reinitializting the NFS timeout value inside
NfsTimeout() when a timeout occurs.

- Make the 'nfs' command print the 'T' character when a timeout occurs.
Previously there was no indication that timeouts were occuring.

- Mimic the 'tftpboot' command and when a download fails print "Retry
count exceeded; starting again", and restart the download taking the
'netretry' environment variable into account.

Signed-off-by: Evan Samanas <esamanas@xes-inc.com>
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

Tested on TQM8xxL.

Tested by: Wolfgang Denk <wd@denx.de>

Tested on MPC8527DS.

Tested by: Ed Swarthout <Ed.Swarthout@freescale.com>

# f64ef9bb 19-Nov-2009 Ed Swarthout <Ed.Swarthout@freescale.com>

fix nfs symlink name corruption

An off by one error may cause nfs readlink lookup fail if
nfs_path_buff has non-zero data from a previous use.

Loading: *** ERROR: File lookup fail

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# fe891ecf 31-Jan-2008 Hiroshi Ito <ito@mlb.co.jp>

NFS Timeout with large files.

Retry to send NFS packet before reaching timeout.

Signed-off-by: Hiroshi Ito <ito@mlb.co.jp>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# 29c29c02 23-Oct-2007 Guennadi Liakhovetski <lg@denx.de>

Fix typo in nfs.c

An obvious typo. Originally fixed in linkstation u-boot port.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>

# 3865b1fb 10-Jul-2007 Stefan Roese <sr@denx.de>

Fix some compile problems introduced by the latest CFG_CMD_xxx cleanup

Signed-off-by: Stefan Roese <sr@denx.de>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 23a7a32d 05-Aug-2005 Wolfgang Denk <wd@denx.de>

Fix return code of NFS command
Patch by Hiroshi Ito, 11 Dec 2004

# c43352cc 03-Aug-2005 Wolfgang Denk <wd@denx.de>

Fix endianess problem in TFTP / NFS default filenames
Patch by Hiroshi Ito, 06 Dec 2004

# a5725fab 28-Sep-2004 Wolfgang Denk <wd@denx.de>

* Patch by Ganapathi C, 04 Aug 2004:
Fix NFS timeout issue

# e94d2cd9 30-Jun-2004 Wolfgang Denk <wd@denx.de>

* Fix "cls" command when used with splash screen

* Increase NFS download timeout (now 1 min - 10 sec is to short for a
slow download of a big image)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wd@denx.de>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# c3f9d493 13-Mar-2004 Wolfgang Denk <wd@denx.de>

* Patch by Yuli Barcohen, 4 Mar 2004:
Fix problems with GCC 3.3.x which changed handling of global
variables explicitly initialized to zero (now in .bss instead of
.data as before).

* Patch by Leon Kukovec, 02 Mar 2004:
add strswab() to fix IDE LBA capacity, firmware and model numbers
on little endian machines

* Patch by Masami Komiya, 02 Mar 2004:
- Remove get_ticks() from NFS code
- Add verification of RPC transaction ID

* Patch by Pierre Aubert, 02 Mar 2004:
cleanup for IDE and USB drivers for MPC5200

# 11dadd54 26-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Steven Scholz, 25 Feb 2004:
- Timeouts in FPGA code should be based on CFG_HZ
- Minor cleanup in code for Altera FPGA ACEX1K

* Patch by Steven Scholz, 25 Feb 2004:
Changed "Directory Hierarchy" section in README

* Patch by Masami Komiya, 25 Feb 2004:
Reduce copy count in nfs_read_reply() of NFS code

# a084f7da 24-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiya, 24 Feb 2004:
Update NetBootFileXferSize in NFS code

* Patch by Scott McNutt, 24 Feb 2004:
fix packet length in NFS code

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wd@denx.de>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

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>

# 0ee48252 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move flash_perror() to flash.h

This function belongs more in flash.h than common.h so move it.

Also remove the space before the bracket in some calls.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1045315d 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move get_ticks() function out of common.h

This function belongs in time.h so move it over and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 15eea9a1 02-Sep-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: nfs: remove superfluous conversions

rpc_pkt.u.call.data is an array of uint32_t. There is no need to convert
it to uint32_t *.

memcpy() expects void * as it 1st and 2nd argument. There is no point in
converting pointers to char * before passing them to memcpy().

In ntohl(data[1]) != 0 calling ntohl() is superfluous. If the value is
zero, does not depend on the byte order.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d14ee4e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14196: nfs: fix unbounded memcpy with a failed length check at nfs_lookup_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_lookup_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cf3a4f1e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14195: nfs: fix unbounded memcpy with unvalidated length at nfs_readlink_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_readlink_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# aa207cf3 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14194/CVE-2019-14198: nfs: fix unbounded memcpy with a failed length check at nfs_read_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_read_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 741a8a08 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: nfs: fix stack-based buffer overflow in some nfs_handler reply helper functions

This patch adds a check to nfs_handler to fix buffer overflow for CVE-2019-14197,
CVE-2019-14200, CVE-2019-14201, CVE-2019-14202, CVE-2019-14203 and CVE-2019-14204.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

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>

# faecf84a 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Always print basic info for nfs, just like tftp

nfs was only printing basic info about the transfer in the case of a
DEBUG build. Print the same level of detail as tftp always.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347e32b0 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Check subnet against the actual ip address in use for nfs

The check for sending to the gateway was not using the correct variable
for comparison, so it was reporting that packets are sent to the gateway
when they were not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d48d40a0 14-May-2018 Vasily Khoruzhick <anarsoul@gmail.com>

net: nfs: don't fail when nfs_read_reply returns -NFS_RPC_DROP

That can happen if duplicate UDP packet arrived, and that's not uncommon.
Anyway, we ignore packets with rpc_id lower than last we sent for other
requests, so it makes sense to do that for read request as well.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a73588fe 08-Sep-2016 Joe Hershberger <joe.hershberger@ni.com>

Revert "net: nfs: Use the tx buffer to construct rpc msgs"

This reverts commit 998372b4798fd7ebb666f571950df925b8d80f69.

This caused a data abort on some platform.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Guillaume GARDET <guillaume.gardet@free.fr>

# 1ff65d44 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Simplify rpc_add_credentials()

We use an empty hostname, so remove all the "processing" of the
known-to-be-empty hostname and just write 0's where needed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 998372b4 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use the tx buffer to construct rpc msgs

Instead of always allocating a huge temporary buffer on the stack and
then memcpy()ing the result into the transmit buffer, simply figure out
where in the transmit buffer the bytes will belong and write them there
directly as each message is built.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d89ff2df 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Move some prints to debug statements

Much of the information is verbose and derived directly from the
environment. Only output in debug mode. This also saves about 300 bytes
from the code size.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0517cc45 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use consistent names for the rpc_pkt

Use the same name throughout the nfs code and use the same member of the
union to avoid casts.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c629c45f 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Correct a comment

The buffer is of 32-bit elements, not bytes.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 051ed9af 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Consolidate handling of NFSv3 attributes

Instead of repeating the same large snippet for dealing with attributes
it should be shared with a helper function.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347a9015 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Fix lines that are too long

Fix complaints from checkpatch.pl.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 5280c769 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Share the file handle buffer for v2 / v3

The v3 handles can be larger than v2, but that doesn't mean we need a
separate buffer. Reuse the same (larger) buffer for both.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# b0baca98 29-Jul-2016 Guillaume GARDET <guillaume.gardet@free.fr>

net: NFS: Add NFSv3 support

This patch enables NFSv3 support.
If NFSv2 is available use it as usual.
If NFSv2 is not available, but NFSv3 is available, use NFSv3.
If NFSv2 and NFSv3 are not available, print an error message since NFSv4 is not supported.

Tested on iMX6 sabrelite with 4 Linux NFS servers:
* NFSv2 + NFSv3 + NFSv4 server: use NFSv2 protocol
* NFSv2 + NFSv3 server: use NFSv2 protocol
* NFSv3 + NFSv4 server: use NFSv3 protocol
* NFSv3 server: use NFSv3 protocol

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: Tom Rini <trini@konsulko.com>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f8b26c7a 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Remove separate buffer for default name

There is no reason to store the default filename in a separate buffer
only to immediately copy it to the main name buffer. Just write it there
directly and remove the other buffer.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e4ead4a2 01-Jul-2016 Ralf Hubert <r.hubert@technisat.de>

net: Fix incorrect RPC packets on 64-bit systems

This patch fixes incorrect RPC packet layout caused by
'long' type size difference on 64 and 32-bit architectures.

Signed-off-by: Ralf Hubert <r.hubert@technisat.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 69fd0d41 06-Jun-2016 Guillaume GARDET <guillaume.gardet@free.fr>

NFS: Add error message when U-Boot NFS version (V2) is not supported by NFS server

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 55d5fd9a 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Access mapped physmem in net functions

Previously the net functions would access memory assuming physmem did
not need to be mapped. In sandbox, that's not the case.

Now we map the physmem specified by the user in loadaddr to the buffer
that represents that space.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fa84fa70 11-Dec-2012 Matthias Brugger <matthias.bgg@gmail.com>

net: nfs: add dynamic wait period

This patch tackles the time out problem which leads to break the
boot process, when loading file over nfs. The patch does two things.

First of all, we just ignore messages that arrive with a rpc_id smaller
then the client id. We just interpret this messages as answers to
formaly timed out messages.

Second, when a time out occurs we double the time to wait, so that we
do not stress the server resending the last message.

Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
Tested-by: Enric Balletbo i Serra <eballetbo@gmail.com>

# 48a3e999 03-Jul-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: nfs: make NFS_TIMEOUT configurable

NFS_TIMEOUT is constant value defined in net/nfs.c. But sometimes it needs to adjust.
This patch enables to override NFS_TIMEOUT by defining CONFIG_NFS_TIMEOUT in a board specific config file.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c9f6c91b 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: nfs.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# aabb8cb0 09-Nov-2009 Evan Samanas <esamanas@xes-inc.com>

nfs: NfsTimeout() updates

- NfsTimeout() does not correctly update the NFS timeout value which
results in NfsTimeout() only being called once in certain situations.
This can result in the 'nfs' command hanging indefinetly. For
example, the command:

nfs 192.168.0.1:/home/user/file

will not exit until ctrl-c is pressed if 192.168.0.1 does not have an
NFS server running.

This issue is resolved by reinitializting the NFS timeout value inside
NfsTimeout() when a timeout occurs.

- Make the 'nfs' command print the 'T' character when a timeout occurs.
Previously there was no indication that timeouts were occuring.

- Mimic the 'tftpboot' command and when a download fails print "Retry
count exceeded; starting again", and restart the download taking the
'netretry' environment variable into account.

Signed-off-by: Evan Samanas <esamanas@xes-inc.com>
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

Tested on TQM8xxL.

Tested by: Wolfgang Denk <wd@denx.de>

Tested on MPC8527DS.

Tested by: Ed Swarthout <Ed.Swarthout@freescale.com>

# f64ef9bb 19-Nov-2009 Ed Swarthout <Ed.Swarthout@freescale.com>

fix nfs symlink name corruption

An off by one error may cause nfs readlink lookup fail if
nfs_path_buff has non-zero data from a previous use.

Loading: *** ERROR: File lookup fail

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# fe891ecf 31-Jan-2008 Hiroshi Ito <ito@mlb.co.jp>

NFS Timeout with large files.

Retry to send NFS packet before reaching timeout.

Signed-off-by: Hiroshi Ito <ito@mlb.co.jp>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# 29c29c02 23-Oct-2007 Guennadi Liakhovetski <lg@denx.de>

Fix typo in nfs.c

An obvious typo. Originally fixed in linkstation u-boot port.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>

# 3865b1fb 10-Jul-2007 Stefan Roese <sr@denx.de>

Fix some compile problems introduced by the latest CFG_CMD_xxx cleanup

Signed-off-by: Stefan Roese <sr@denx.de>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 23a7a32d 05-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Fix return code of NFS command
Patch by Hiroshi Ito, 11 Dec 2004

# c43352cc 03-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Fix endianess problem in TFTP / NFS default filenames
Patch by Hiroshi Ito, 06 Dec 2004

# a5725fab 28-Sep-2004 Wolfgang Denk <wdenk>

* Patch by Ganapathi C, 04 Aug 2004:
Fix NFS timeout issue

# e94d2cd9 30-Jun-2004 Wolfgang Denk <wdenk>

* Fix "cls" command when used with splash screen

* Increase NFS download timeout (now 1 min - 10 sec is to short for a
slow download of a big image)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# c3f9d493 13-Mar-2004 Wolfgang Denk <wdenk>

* Patch by Yuli Barcohen, 4 Mar 2004:
Fix problems with GCC 3.3.x which changed handling of global
variables explicitly initialized to zero (now in .bss instead of
.data as before).

* Patch by Leon Kukovec, 02 Mar 2004:
add strswab() to fix IDE LBA capacity, firmware and model numbers
on little endian machines

* Patch by Masami Komiya, 02 Mar 2004:
- Remove get_ticks() from NFS code
- Add verification of RPC transaction ID

* Patch by Pierre Aubert, 02 Mar 2004:
cleanup for IDE and USB drivers for MPC5200

# 11dadd54 26-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Steven Scholz, 25 Feb 2004:
- Timeouts in FPGA code should be based on CFG_HZ
- Minor cleanup in code for Altera FPGA ACEX1K

* Patch by Steven Scholz, 25 Feb 2004:
Changed "Directory Hierarchy" section in README

* Patch by Masami Komiya, 25 Feb 2004:
Reduce copy count in nfs_read_reply() of NFS code

# a084f7da 24-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 24 Feb 2004:
Update NetBootFileXferSize in NFS code

* Patch by Scott McNutt, 24 Feb 2004:
fix packet length in NFS code

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 8e8ccfe1 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move the image globals into image.h

These three globals relate to image handling. Move them to the image
header file.

Signed-off-by: Simon Glass <sjg@chromium.org>

# bb872dd9 28-Dec-2019 Simon Glass <sjg@chromium.org>

image: Rename load_addr, save_addr, save_size

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>

# 0ee48252 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move flash_perror() to flash.h

This function belongs more in flash.h than common.h so move it.

Also remove the space before the bracket in some calls.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1045315d 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move get_ticks() function out of common.h

This function belongs in time.h so move it over and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 15eea9a1 02-Sep-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: nfs: remove superfluous conversions

rpc_pkt.u.call.data is an array of uint32_t. There is no need to convert
it to uint32_t *.

memcpy() expects void * as it 1st and 2nd argument. There is no point in
converting pointers to char * before passing them to memcpy().

In ntohl(data[1]) != 0 calling ntohl() is superfluous. If the value is
zero, does not depend on the byte order.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d14ee4e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14196: nfs: fix unbounded memcpy with a failed length check at nfs_lookup_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_lookup_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cf3a4f1e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14195: nfs: fix unbounded memcpy with unvalidated length at nfs_readlink_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_readlink_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# aa207cf3 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14194/CVE-2019-14198: nfs: fix unbounded memcpy with a failed length check at nfs_read_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_read_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 741a8a08 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: nfs: fix stack-based buffer overflow in some nfs_handler reply helper functions

This patch adds a check to nfs_handler to fix buffer overflow for CVE-2019-14197,
CVE-2019-14200, CVE-2019-14201, CVE-2019-14202, CVE-2019-14203 and CVE-2019-14204.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

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>

# faecf84a 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Always print basic info for nfs, just like tftp

nfs was only printing basic info about the transfer in the case of a
DEBUG build. Print the same level of detail as tftp always.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347e32b0 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Check subnet against the actual ip address in use for nfs

The check for sending to the gateway was not using the correct variable
for comparison, so it was reporting that packets are sent to the gateway
when they were not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d48d40a0 14-May-2018 Vasily Khoruzhick <anarsoul@gmail.com>

net: nfs: don't fail when nfs_read_reply returns -NFS_RPC_DROP

That can happen if duplicate UDP packet arrived, and that's not uncommon.
Anyway, we ignore packets with rpc_id lower than last we sent for other
requests, so it makes sense to do that for read request as well.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a73588fe 08-Sep-2016 Joe Hershberger <joe.hershberger@ni.com>

Revert "net: nfs: Use the tx buffer to construct rpc msgs"

This reverts commit 998372b4798fd7ebb666f571950df925b8d80f69.

This caused a data abort on some platform.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Guillaume GARDET <guillaume.gardet@free.fr>

# 1ff65d44 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Simplify rpc_add_credentials()

We use an empty hostname, so remove all the "processing" of the
known-to-be-empty hostname and just write 0's where needed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 998372b4 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use the tx buffer to construct rpc msgs

Instead of always allocating a huge temporary buffer on the stack and
then memcpy()ing the result into the transmit buffer, simply figure out
where in the transmit buffer the bytes will belong and write them there
directly as each message is built.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d89ff2df 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Move some prints to debug statements

Much of the information is verbose and derived directly from the
environment. Only output in debug mode. This also saves about 300 bytes
from the code size.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0517cc45 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use consistent names for the rpc_pkt

Use the same name throughout the nfs code and use the same member of the
union to avoid casts.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c629c45f 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Correct a comment

The buffer is of 32-bit elements, not bytes.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 051ed9af 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Consolidate handling of NFSv3 attributes

Instead of repeating the same large snippet for dealing with attributes
it should be shared with a helper function.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347a9015 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Fix lines that are too long

Fix complaints from checkpatch.pl.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 5280c769 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Share the file handle buffer for v2 / v3

The v3 handles can be larger than v2, but that doesn't mean we need a
separate buffer. Reuse the same (larger) buffer for both.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# b0baca98 29-Jul-2016 Guillaume GARDET <guillaume.gardet@free.fr>

net: NFS: Add NFSv3 support

This patch enables NFSv3 support.
If NFSv2 is available use it as usual.
If NFSv2 is not available, but NFSv3 is available, use NFSv3.
If NFSv2 and NFSv3 are not available, print an error message since NFSv4 is not supported.

Tested on iMX6 sabrelite with 4 Linux NFS servers:
* NFSv2 + NFSv3 + NFSv4 server: use NFSv2 protocol
* NFSv2 + NFSv3 server: use NFSv2 protocol
* NFSv3 + NFSv4 server: use NFSv3 protocol
* NFSv3 server: use NFSv3 protocol

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: Tom Rini <trini@konsulko.com>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f8b26c7a 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Remove separate buffer for default name

There is no reason to store the default filename in a separate buffer
only to immediately copy it to the main name buffer. Just write it there
directly and remove the other buffer.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e4ead4a2 01-Jul-2016 Ralf Hubert <r.hubert@technisat.de>

net: Fix incorrect RPC packets on 64-bit systems

This patch fixes incorrect RPC packet layout caused by
'long' type size difference on 64 and 32-bit architectures.

Signed-off-by: Ralf Hubert <r.hubert@technisat.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 69fd0d41 06-Jun-2016 Guillaume GARDET <guillaume.gardet@free.fr>

NFS: Add error message when U-Boot NFS version (V2) is not supported by NFS server

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 55d5fd9a 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Access mapped physmem in net functions

Previously the net functions would access memory assuming physmem did
not need to be mapped. In sandbox, that's not the case.

Now we map the physmem specified by the user in loadaddr to the buffer
that represents that space.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fa84fa70 11-Dec-2012 Matthias Brugger <matthias.bgg@gmail.com>

net: nfs: add dynamic wait period

This patch tackles the time out problem which leads to break the
boot process, when loading file over nfs. The patch does two things.

First of all, we just ignore messages that arrive with a rpc_id smaller
then the client id. We just interpret this messages as answers to
formaly timed out messages.

Second, when a time out occurs we double the time to wait, so that we
do not stress the server resending the last message.

Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
Tested-by: Enric Balletbo i Serra <eballetbo@gmail.com>

# 48a3e999 03-Jul-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: nfs: make NFS_TIMEOUT configurable

NFS_TIMEOUT is constant value defined in net/nfs.c. But sometimes it needs to adjust.
This patch enables to override NFS_TIMEOUT by defining CONFIG_NFS_TIMEOUT in a board specific config file.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c9f6c91b 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: nfs.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# aabb8cb0 09-Nov-2009 Evan Samanas <esamanas@xes-inc.com>

nfs: NfsTimeout() updates

- NfsTimeout() does not correctly update the NFS timeout value which
results in NfsTimeout() only being called once in certain situations.
This can result in the 'nfs' command hanging indefinetly. For
example, the command:

nfs 192.168.0.1:/home/user/file

will not exit until ctrl-c is pressed if 192.168.0.1 does not have an
NFS server running.

This issue is resolved by reinitializting the NFS timeout value inside
NfsTimeout() when a timeout occurs.

- Make the 'nfs' command print the 'T' character when a timeout occurs.
Previously there was no indication that timeouts were occuring.

- Mimic the 'tftpboot' command and when a download fails print "Retry
count exceeded; starting again", and restart the download taking the
'netretry' environment variable into account.

Signed-off-by: Evan Samanas <esamanas@xes-inc.com>
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

Tested on TQM8xxL.

Tested by: Wolfgang Denk <wd@denx.de>

Tested on MPC8527DS.

Tested by: Ed Swarthout <Ed.Swarthout@freescale.com>

# f64ef9bb 19-Nov-2009 Ed Swarthout <Ed.Swarthout@freescale.com>

fix nfs symlink name corruption

An off by one error may cause nfs readlink lookup fail if
nfs_path_buff has non-zero data from a previous use.

Loading: *** ERROR: File lookup fail

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# fe891ecf 31-Jan-2008 Hiroshi Ito <ito@mlb.co.jp>

NFS Timeout with large files.

Retry to send NFS packet before reaching timeout.

Signed-off-by: Hiroshi Ito <ito@mlb.co.jp>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# 29c29c02 23-Oct-2007 Guennadi Liakhovetski <lg@denx.de>

Fix typo in nfs.c

An obvious typo. Originally fixed in linkstation u-boot port.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>

# 3865b1fb 10-Jul-2007 Stefan Roese <sr@denx.de>

Fix some compile problems introduced by the latest CFG_CMD_xxx cleanup

Signed-off-by: Stefan Roese <sr@denx.de>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 23a7a32d 05-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Fix return code of NFS command
Patch by Hiroshi Ito, 11 Dec 2004

# c43352cc 03-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Fix endianess problem in TFTP / NFS default filenames
Patch by Hiroshi Ito, 06 Dec 2004

# a5725fab 28-Sep-2004 Wolfgang Denk <wdenk>

* Patch by Ganapathi C, 04 Aug 2004:
Fix NFS timeout issue

# e94d2cd9 30-Jun-2004 Wolfgang Denk <wdenk>

* Fix "cls" command when used with splash screen

* Increase NFS download timeout (now 1 min - 10 sec is to short for a
slow download of a big image)

# a3d991bd 15-Apr-2004 Wolfgang Denk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 Wolfgang Denk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# c3f9d493 13-Mar-2004 Wolfgang Denk <wdenk>

* Patch by Yuli Barcohen, 4 Mar 2004:
Fix problems with GCC 3.3.x which changed handling of global
variables explicitly initialized to zero (now in .bss instead of
.data as before).

* Patch by Leon Kukovec, 02 Mar 2004:
add strswab() to fix IDE LBA capacity, firmware and model numbers
on little endian machines

* Patch by Masami Komiya, 02 Mar 2004:
- Remove get_ticks() from NFS code
- Add verification of RPC transaction ID

* Patch by Pierre Aubert, 02 Mar 2004:
cleanup for IDE and USB drivers for MPC5200

# 11dadd54 26-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Steven Scholz, 25 Feb 2004:
- Timeouts in FPGA code should be based on CFG_HZ
- Minor cleanup in code for Altera FPGA ACEX1K

* Patch by Steven Scholz, 25 Feb 2004:
Changed "Directory Hierarchy" section in README

* Patch by Masami Komiya, 25 Feb 2004:
Reduce copy count in nfs_read_reply() of NFS code

# a084f7da 24-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiya, 24 Feb 2004:
Update NetBootFileXferSize in NFS code

* Patch by Scott McNutt, 24 Feb 2004:
fix packet length in NFS code

# cbd8a35c 23-Feb-2004 Wolfgang Denk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 1045315d 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move get_ticks() function out of common.h

This function belongs in time.h so move it over and add a comment.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# 15eea9a1 02-Sep-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: nfs: remove superfluous conversions

rpc_pkt.u.call.data is an array of uint32_t. There is no need to convert
it to uint32_t *.

memcpy() expects void * as it 1st and 2nd argument. There is no point in
converting pointers to char * before passing them to memcpy().

In ntohl(data[1]) != 0 calling ntohl() is superfluous. If the value is
zero, does not depend on the byte order.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d14ee4e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14196: nfs: fix unbounded memcpy with a failed length check at nfs_lookup_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_lookup_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cf3a4f1e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14195: nfs: fix unbounded memcpy with unvalidated length at nfs_readlink_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_readlink_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# aa207cf3 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14194/CVE-2019-14198: nfs: fix unbounded memcpy with a failed length check at nfs_read_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_read_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 741a8a08 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: nfs: fix stack-based buffer overflow in some nfs_handler reply helper functions

This patch adds a check to nfs_handler to fix buffer overflow for CVE-2019-14197,
CVE-2019-14200, CVE-2019-14201, CVE-2019-14202, CVE-2019-14203 and CVE-2019-14204.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

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>

# faecf84a 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Always print basic info for nfs, just like tftp

nfs was only printing basic info about the transfer in the case of a
DEBUG build. Print the same level of detail as tftp always.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347e32b0 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Check subnet against the actual ip address in use for nfs

The check for sending to the gateway was not using the correct variable
for comparison, so it was reporting that packets are sent to the gateway
when they were not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d48d40a0 14-May-2018 Vasily Khoruzhick <anarsoul@gmail.com>

net: nfs: don't fail when nfs_read_reply returns -NFS_RPC_DROP

That can happen if duplicate UDP packet arrived, and that's not uncommon.
Anyway, we ignore packets with rpc_id lower than last we sent for other
requests, so it makes sense to do that for read request as well.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a73588fe 08-Sep-2016 Joe Hershberger <joe.hershberger@ni.com>

Revert "net: nfs: Use the tx buffer to construct rpc msgs"

This reverts commit 998372b4798fd7ebb666f571950df925b8d80f69.

This caused a data abort on some platform.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Guillaume GARDET <guillaume.gardet@free.fr>

# 1ff65d44 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Simplify rpc_add_credentials()

We use an empty hostname, so remove all the "processing" of the
known-to-be-empty hostname and just write 0's where needed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 998372b4 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use the tx buffer to construct rpc msgs

Instead of always allocating a huge temporary buffer on the stack and
then memcpy()ing the result into the transmit buffer, simply figure out
where in the transmit buffer the bytes will belong and write them there
directly as each message is built.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d89ff2df 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Move some prints to debug statements

Much of the information is verbose and derived directly from the
environment. Only output in debug mode. This also saves about 300 bytes
from the code size.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0517cc45 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use consistent names for the rpc_pkt

Use the same name throughout the nfs code and use the same member of the
union to avoid casts.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c629c45f 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Correct a comment

The buffer is of 32-bit elements, not bytes.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 051ed9af 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Consolidate handling of NFSv3 attributes

Instead of repeating the same large snippet for dealing with attributes
it should be shared with a helper function.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347a9015 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Fix lines that are too long

Fix complaints from checkpatch.pl.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 5280c769 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Share the file handle buffer for v2 / v3

The v3 handles can be larger than v2, but that doesn't mean we need a
separate buffer. Reuse the same (larger) buffer for both.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# b0baca98 29-Jul-2016 Guillaume GARDET <guillaume.gardet@free.fr>

net: NFS: Add NFSv3 support

This patch enables NFSv3 support.
If NFSv2 is available use it as usual.
If NFSv2 is not available, but NFSv3 is available, use NFSv3.
If NFSv2 and NFSv3 are not available, print an error message since NFSv4 is not supported.

Tested on iMX6 sabrelite with 4 Linux NFS servers:
* NFSv2 + NFSv3 + NFSv4 server: use NFSv2 protocol
* NFSv2 + NFSv3 server: use NFSv2 protocol
* NFSv3 + NFSv4 server: use NFSv3 protocol
* NFSv3 server: use NFSv3 protocol

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: Tom Rini <trini@konsulko.com>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f8b26c7a 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Remove separate buffer for default name

There is no reason to store the default filename in a separate buffer
only to immediately copy it to the main name buffer. Just write it there
directly and remove the other buffer.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e4ead4a2 01-Jul-2016 Ralf Hubert <r.hubert@technisat.de>

net: Fix incorrect RPC packets on 64-bit systems

This patch fixes incorrect RPC packet layout caused by
'long' type size difference on 64 and 32-bit architectures.

Signed-off-by: Ralf Hubert <r.hubert@technisat.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 69fd0d41 06-Jun-2016 Guillaume GARDET <guillaume.gardet@free.fr>

NFS: Add error message when U-Boot NFS version (V2) is not supported by NFS server

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 55d5fd9a 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Access mapped physmem in net functions

Previously the net functions would access memory assuming physmem did
not need to be mapped. In sandbox, that's not the case.

Now we map the physmem specified by the user in loadaddr to the buffer
that represents that space.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fa84fa70 11-Dec-2012 Matthias Brugger <matthias.bgg@gmail.com>

net: nfs: add dynamic wait period

This patch tackles the time out problem which leads to break the
boot process, when loading file over nfs. The patch does two things.

First of all, we just ignore messages that arrive with a rpc_id smaller
then the client id. We just interpret this messages as answers to
formaly timed out messages.

Second, when a time out occurs we double the time to wait, so that we
do not stress the server resending the last message.

Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
Tested-by: Enric Balletbo i Serra <eballetbo@gmail.com>

# 48a3e999 03-Jul-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: nfs: make NFS_TIMEOUT configurable

NFS_TIMEOUT is constant value defined in net/nfs.c. But sometimes it needs to adjust.
This patch enables to override NFS_TIMEOUT by defining CONFIG_NFS_TIMEOUT in a board specific config file.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c9f6c91b 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: nfs.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# aabb8cb0 09-Nov-2009 Evan Samanas <esamanas@xes-inc.com>

nfs: NfsTimeout() updates

- NfsTimeout() does not correctly update the NFS timeout value which
results in NfsTimeout() only being called once in certain situations.
This can result in the 'nfs' command hanging indefinetly. For
example, the command:

nfs 192.168.0.1:/home/user/file

will not exit until ctrl-c is pressed if 192.168.0.1 does not have an
NFS server running.

This issue is resolved by reinitializting the NFS timeout value inside
NfsTimeout() when a timeout occurs.

- Make the 'nfs' command print the 'T' character when a timeout occurs.
Previously there was no indication that timeouts were occuring.

- Mimic the 'tftpboot' command and when a download fails print "Retry
count exceeded; starting again", and restart the download taking the
'netretry' environment variable into account.

Signed-off-by: Evan Samanas <esamanas@xes-inc.com>
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

Tested on TQM8xxL.

Tested by: Wolfgang Denk <wd@denx.de>

Tested on MPC8527DS.

Tested by: Ed Swarthout <Ed.Swarthout@freescale.com>

# f64ef9bb 19-Nov-2009 Ed Swarthout <Ed.Swarthout@freescale.com>

fix nfs symlink name corruption

An off by one error may cause nfs readlink lookup fail if
nfs_path_buff has non-zero data from a previous use.

Loading: *** ERROR: File lookup fail

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# fe891ecf 31-Jan-2008 Hiroshi Ito <ito@mlb.co.jp>

NFS Timeout with large files.

Retry to send NFS packet before reaching timeout.

Signed-off-by: Hiroshi Ito <ito@mlb.co.jp>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# 29c29c02 23-Oct-2007 Guennadi Liakhovetski <lg@denx.de>

Fix typo in nfs.c

An obvious typo. Originally fixed in linkstation u-boot port.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>

# 3865b1fb 10-Jul-2007 Stefan Roese <sr@denx.de>

Fix some compile problems introduced by the latest CFG_CMD_xxx cleanup

Signed-off-by: Stefan Roese <sr@denx.de>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 23a7a32d 05-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Fix return code of NFS command
Patch by Hiroshi Ito, 11 Dec 2004

# c43352cc 03-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Fix endianess problem in TFTP / NFS default filenames
Patch by Hiroshi Ito, 06 Dec 2004

# a5725fab 28-Sep-2004 wdenk <wdenk>

* Patch by Ganapathi C, 04 Aug 2004:
Fix NFS timeout issue

# e94d2cd9 30-Jun-2004 wdenk <wdenk>

* Fix "cls" command when used with splash screen

* Increase NFS download timeout (now 1 min - 10 sec is to short for a
slow download of a big image)

# a3d991bd 15-Apr-2004 wdenk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 wdenk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# c3f9d493 13-Mar-2004 wdenk <wdenk>

* Patch by Yuli Barcohen, 4 Mar 2004:
Fix problems with GCC 3.3.x which changed handling of global
variables explicitly initialized to zero (now in .bss instead of
.data as before).

* Patch by Leon Kukovec, 02 Mar 2004:
add strswab() to fix IDE LBA capacity, firmware and model numbers
on little endian machines

* Patch by Masami Komiya, 02 Mar 2004:
- Remove get_ticks() from NFS code
- Add verification of RPC transaction ID

* Patch by Pierre Aubert, 02 Mar 2004:
cleanup for IDE and USB drivers for MPC5200

# 11dadd54 26-Feb-2004 wdenk <wdenk>

* Patch by Steven Scholz, 25 Feb 2004:
- Timeouts in FPGA code should be based on CFG_HZ
- Minor cleanup in code for Altera FPGA ACEX1K

* Patch by Steven Scholz, 25 Feb 2004:
Changed "Directory Hierarchy" section in README

* Patch by Masami Komiya, 25 Feb 2004:
Reduce copy count in nfs_read_reply() of NFS code

# a084f7da 24-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiya, 24 Feb 2004:
Update NetBootFileXferSize in NFS code

* Patch by Scott McNutt, 24 Feb 2004:
fix packet length in NFS code

# cbd8a35c 23-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 15eea9a1 02-Sep-2019 Heinrich Schuchardt <xypron.glpk@gmx.de>

net: nfs: remove superfluous conversions

rpc_pkt.u.call.data is an array of uint32_t. There is no need to convert
it to uint32_t *.

memcpy() expects void * as it 1st and 2nd argument. There is no point in
converting pointers to char * before passing them to memcpy().

In ntohl(data[1]) != 0 calling ntohl() is superfluous. If the value is
zero, does not depend on the byte order.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 5d14ee4e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14196: nfs: fix unbounded memcpy with a failed length check at nfs_lookup_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_lookup_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# cf3a4f1e 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14195: nfs: fix unbounded memcpy with unvalidated length at nfs_readlink_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_readlink_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# aa207cf3 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE-2019-14194/CVE-2019-14198: nfs: fix unbounded memcpy with a failed length check at nfs_read_reply

This patch adds a check to rpc_pkt.u.reply.data at nfs_read_reply.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 741a8a08 29-Aug-2019 liucheng (G) <liucheng32@huawei.com>

CVE: nfs: fix stack-based buffer overflow in some nfs_handler reply helper functions

This patch adds a check to nfs_handler to fix buffer overflow for CVE-2019-14197,
CVE-2019-14200, CVE-2019-14201, CVE-2019-14202, CVE-2019-14203 and CVE-2019-14204.

Signed-off-by: Cheng Liu <liucheng32@huawei.com>
Reported-by: Fermín Serna <fermin@semmle.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

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>

# faecf84a 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Always print basic info for nfs, just like tftp

nfs was only printing basic info about the transfer in the case of a
DEBUG build. Print the same level of detail as tftp always.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347e32b0 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Check subnet against the actual ip address in use for nfs

The check for sending to the gateway was not using the correct variable
for comparison, so it was reporting that packets are sent to the gateway
when they were not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d48d40a0 14-May-2018 Vasily Khoruzhick <anarsoul@gmail.com>

net: nfs: don't fail when nfs_read_reply returns -NFS_RPC_DROP

That can happen if duplicate UDP packet arrived, and that's not uncommon.
Anyway, we ignore packets with rpc_id lower than last we sent for other
requests, so it makes sense to do that for read request as well.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# a73588fe 08-Sep-2016 Joe Hershberger <joe.hershberger@ni.com>

Revert "net: nfs: Use the tx buffer to construct rpc msgs"

This reverts commit 998372b4798fd7ebb666f571950df925b8d80f69.

This caused a data abort on some platform.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Guillaume GARDET <guillaume.gardet@free.fr>

# 1ff65d44 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Simplify rpc_add_credentials()

We use an empty hostname, so remove all the "processing" of the
known-to-be-empty hostname and just write 0's where needed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 998372b4 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use the tx buffer to construct rpc msgs

Instead of always allocating a huge temporary buffer on the stack and
then memcpy()ing the result into the transmit buffer, simply figure out
where in the transmit buffer the bytes will belong and write them there
directly as each message is built.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# d89ff2df 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Move some prints to debug statements

Much of the information is verbose and derived directly from the
environment. Only output in debug mode. This also saves about 300 bytes
from the code size.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0517cc45 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use consistent names for the rpc_pkt

Use the same name throughout the nfs code and use the same member of the
union to avoid casts.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c629c45f 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Correct a comment

The buffer is of 32-bit elements, not bytes.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 051ed9af 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Consolidate handling of NFSv3 attributes

Instead of repeating the same large snippet for dealing with attributes
it should be shared with a helper function.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 347a9015 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Fix lines that are too long

Fix complaints from checkpatch.pl.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 5280c769 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Share the file handle buffer for v2 / v3

The v3 handles can be larger than v2, but that doesn't mean we need a
separate buffer. Reuse the same (larger) buffer for both.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# b0baca98 29-Jul-2016 Guillaume GARDET <guillaume.gardet@free.fr>

net: NFS: Add NFSv3 support

This patch enables NFSv3 support.
If NFSv2 is available use it as usual.
If NFSv2 is not available, but NFSv3 is available, use NFSv3.
If NFSv2 and NFSv3 are not available, print an error message since NFSv4 is not supported.

Tested on iMX6 sabrelite with 4 Linux NFS servers:
* NFSv2 + NFSv3 + NFSv4 server: use NFSv2 protocol
* NFSv2 + NFSv3 server: use NFSv2 protocol
* NFSv3 + NFSv4 server: use NFSv3 protocol
* NFSv3 server: use NFSv3 protocol

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: Tom Rini <trini@konsulko.com>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# f8b26c7a 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Remove separate buffer for default name

There is no reason to store the default filename in a separate buffer
only to immediately copy it to the main name buffer. Just write it there
directly and remove the other buffer.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# e4ead4a2 01-Jul-2016 Ralf Hubert <r.hubert@technisat.de>

net: Fix incorrect RPC packets on 64-bit systems

This patch fixes incorrect RPC packet layout caused by
'long' type size difference on 64 and 32-bit architectures.

Signed-off-by: Ralf Hubert <r.hubert@technisat.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# 69fd0d41 06-Jun-2016 Guillaume GARDET <guillaume.gardet@free.fr>

NFS: Add error message when U-Boot NFS version (V2) is not supported by NFS server

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>

# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 55d5fd9a 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Access mapped physmem in net functions

Previously the net functions would access memory assuming physmem did
not need to be mapped. In sandbox, that's not the case.

Now we map the physmem specified by the user in loadaddr to the buffer
that represents that space.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fa84fa70 11-Dec-2012 Matthias Brugger <matthias.bgg@gmail.com>

net: nfs: add dynamic wait period

This patch tackles the time out problem which leads to break the
boot process, when loading file over nfs. The patch does two things.

First of all, we just ignore messages that arrive with a rpc_id smaller
then the client id. We just interpret this messages as answers to
formaly timed out messages.

Second, when a time out occurs we double the time to wait, so that we
do not stress the server resending the last message.

Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
Tested-by: Enric Balletbo i Serra <eballetbo@gmail.com>

# 48a3e999 03-Jul-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: nfs: make NFS_TIMEOUT configurable

NFS_TIMEOUT is constant value defined in net/nfs.c. But sometimes it needs to adjust.
This patch enables to override NFS_TIMEOUT by defining CONFIG_NFS_TIMEOUT in a board specific config file.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>

# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

# c9f6c91b 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: nfs.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>

# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>

# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>

# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# aabb8cb0 09-Nov-2009 Evan Samanas <esamanas@xes-inc.com>

nfs: NfsTimeout() updates

- NfsTimeout() does not correctly update the NFS timeout value which
results in NfsTimeout() only being called once in certain situations.
This can result in the 'nfs' command hanging indefinetly. For
example, the command:

nfs 192.168.0.1:/home/user/file

will not exit until ctrl-c is pressed if 192.168.0.1 does not have an
NFS server running.

This issue is resolved by reinitializting the NFS timeout value inside
NfsTimeout() when a timeout occurs.

- Make the 'nfs' command print the 'T' character when a timeout occurs.
Previously there was no indication that timeouts were occuring.

- Mimic the 'tftpboot' command and when a download fails print "Retry
count exceeded; starting again", and restart the download taking the
'netretry' environment variable into account.

Signed-off-by: Evan Samanas <esamanas@xes-inc.com>
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

Tested on TQM8xxL.

Tested by: Wolfgang Denk <wd@denx.de>

Tested on MPC8527DS.

Tested by: Ed Swarthout <Ed.Swarthout@freescale.com>

# f64ef9bb 19-Nov-2009 Ed Swarthout <Ed.Swarthout@freescale.com>

fix nfs symlink name corruption

An off by one error may cause nfs readlink lookup fail if
nfs_path_buff has non-zero data from a previous use.

Loading: *** ERROR: File lookup fail

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>

# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>

# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>

# fe891ecf 31-Jan-2008 Hiroshi Ito <ito@mlb.co.jp>

NFS Timeout with large files.

Retry to send NFS packet before reaching timeout.

Signed-off-by: Hiroshi Ito <ito@mlb.co.jp>

# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c

# 29c29c02 23-Oct-2007 Guennadi Liakhovetski <lg@denx.de>

Fix typo in nfs.c

An obvious typo. Originally fixed in linkstation u-boot port.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>

# 3865b1fb 10-Jul-2007 Stefan Roese <sr@denx.de>

Fix some compile problems introduced by the latest CFG_CMD_xxx cleanup

Signed-off-by: Stefan Roese <sr@denx.de>

# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>

# 23a7a32d 05-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Fix return code of NFS command
Patch by Hiroshi Ito, 11 Dec 2004

# c43352cc 03-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Fix endianess problem in TFTP / NFS default filenames
Patch by Hiroshi Ito, 06 Dec 2004

# a5725fab 28-Sep-2004 wdenk <wdenk>

* Patch by Ganapathi C, 04 Aug 2004:
Fix NFS timeout issue

# e94d2cd9 30-Jun-2004 wdenk <wdenk>

* Fix "cls" command when used with splash screen

* Increase NFS download timeout (now 1 min - 10 sec is to short for a
slow download of a big image)

# a3d991bd 15-Apr-2004 wdenk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)

# 4b9206ed 23-Mar-2004 wdenk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)

# c3f9d493 13-Mar-2004 wdenk <wdenk>

* Patch by Yuli Barcohen, 4 Mar 2004:
Fix problems with GCC 3.3.x which changed handling of global
variables explicitly initialized to zero (now in .bss instead of
.data as before).

* Patch by Leon Kukovec, 02 Mar 2004:
add strswab() to fix IDE LBA capacity, firmware and model numbers
on little endian machines

* Patch by Masami Komiya, 02 Mar 2004:
- Remove get_ticks() from NFS code
- Add verification of RPC transaction ID

* Patch by Pierre Aubert, 02 Mar 2004:
cleanup for IDE and USB drivers for MPC5200

# 11dadd54 26-Feb-2004 wdenk <wdenk>

* Patch by Steven Scholz, 25 Feb 2004:
- Timeouts in FPGA code should be based on CFG_HZ
- Minor cleanup in code for Altera FPGA ACEX1K

* Patch by Steven Scholz, 25 Feb 2004:
Changed "Directory Hierarchy" section in README

* Patch by Masami Komiya, 25 Feb 2004:
Reduce copy count in nfs_read_reply() of NFS code

# a084f7da 24-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiya, 24 Feb 2004:
Update NetBootFileXferSize in NFS code

* Patch by Scott McNutt, 24 Feb 2004:
fix packet length in NFS code

# cbd8a35c 23-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup

# 6ab12830 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Consolidate the parsing of bootfile

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>


# faecf84a 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Always print basic info for nfs, just like tftp

nfs was only printing basic info about the transfer in the case of a
DEBUG build. Print the same level of detail as tftp always.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 347e32b0 03-Jul-2018 Joe Hershberger <joe.hershberger@ni.com>

net: Check subnet against the actual ip address in use for nfs

The check for sending to the gateway was not using the correct variable
for comparison, so it was reporting that packets are sent to the gateway
when they were not.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# d48d40a0 14-May-2018 Vasily Khoruzhick <anarsoul@gmail.com>

net: nfs: don't fail when nfs_read_reply returns -NFS_RPC_DROP

That can happen if duplicate UDP packet arrived, and that's not uncommon.
Anyway, we ignore packets with rpc_id lower than last we sent for other
requests, so it makes sense to do that for read request as well.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# a73588fe 08-Sep-2016 Joe Hershberger <joe.hershberger@ni.com>

Revert "net: nfs: Use the tx buffer to construct rpc msgs"

This reverts commit 998372b4798fd7ebb666f571950df925b8d80f69.

This caused a data abort on some platform.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Guillaume GARDET <guillaume.gardet@free.fr>


# 1ff65d44 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Simplify rpc_add_credentials()

We use an empty hostname, so remove all the "processing" of the
known-to-be-empty hostname and just write 0's where needed.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 998372b4 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use the tx buffer to construct rpc msgs

Instead of always allocating a huge temporary buffer on the stack and
then memcpy()ing the result into the transmit buffer, simply figure out
where in the transmit buffer the bytes will belong and write them there
directly as each message is built.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# d89ff2df 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Move some prints to debug statements

Much of the information is verbose and derived directly from the
environment. Only output in debug mode. This also saves about 300 bytes
from the code size.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 0517cc45 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Use consistent names for the rpc_pkt

Use the same name throughout the nfs code and use the same member of the
union to avoid casts.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# c629c45f 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Correct a comment

The buffer is of 32-bit elements, not bytes.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 051ed9af 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Consolidate handling of NFSv3 attributes

Instead of repeating the same large snippet for dealing with attributes
it should be shared with a helper function.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 347a9015 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Fix lines that are too long

Fix complaints from checkpatch.pl.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 5280c769 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Share the file handle buffer for v2 / v3

The v3 handles can be larger than v2, but that doesn't mean we need a
separate buffer. Reuse the same (larger) buffer for both.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# b0baca98 29-Jul-2016 Guillaume GARDET <guillaume.gardet@free.fr>

net: NFS: Add NFSv3 support

This patch enables NFSv3 support.
If NFSv2 is available use it as usual.
If NFSv2 is not available, but NFSv3 is available, use NFSv3.
If NFSv2 and NFSv3 are not available, print an error message since NFSv4 is not supported.

Tested on iMX6 sabrelite with 4 Linux NFS servers:
* NFSv2 + NFSv3 + NFSv4 server: use NFSv2 protocol
* NFSv2 + NFSv3 server: use NFSv2 protocol
* NFSv3 + NFSv4 server: use NFSv3 protocol
* NFSv3 server: use NFSv3 protocol

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: Tom Rini <trini@konsulko.com>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# f8b26c7a 15-Aug-2016 Joe Hershberger <joe.hershberger@ni.com>

net: nfs: Remove separate buffer for default name

There is no reason to store the default filename in a separate buffer
only to immediately copy it to the main name buffer. Just write it there
directly and remove the other buffer.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# e4ead4a2 01-Jul-2016 Ralf Hubert <r.hubert@technisat.de>

net: Fix incorrect RPC packets on 64-bit systems

This patch fixes incorrect RPC packet layout caused by
'long' type size difference on 64 and 32-bit architectures.

Signed-off-by: Ralf Hubert <r.hubert@technisat.de>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# 69fd0d41 06-Jun-2016 Guillaume GARDET <guillaume.gardet@free.fr>

NFS: Add error message when U-Boot NFS version (V2) is not supported by NFS server

Signed-off-by: Guillaume GARDET <guillaume.gardet@free.fr>
Cc: joe.hershberger@ni.com
Acked-by: Joe Hershberger <joe.hershberger@ni.com>


# bc0571fc 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fix checkpatch.pl failures in net.c

Finish eliminating CamelCase from net.c and other failures

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 68c76a3a 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Clean up NFS variables and functions

Make a thorough pass through all variables and function names contained
within nfs.c and remove CamelCase and improve naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 1203fcce 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Cleanup internal packet buffer names

This patch cleans up the names of internal packet buffer names that are
used within the network stack and the functions that use them.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 0adb5b76 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Name ethaddr variables consistently

Use "_ethaddr" at the end of variables and drop CamelCase.
Make constant values actually 'const'.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 1411157d 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Fixup var names related to boot file

The variables around the bootfile were inconsistent and used CamelCase.
Update them to make the code more readable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 049a95a7 08-Apr-2015 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Change IPaddr_t to struct in_addr

This patch is simply clean-up to make the IPv4 type that is used match
what Linux uses. It also attempts to move all variables that are IP
addresses use good naming instead of CamelCase. No functional change.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 55d5fd9a 22-Mar-2015 Joe Hershberger <joe.hershberger@ni.com>

net: Access mapped physmem in net functions

Previously the net functions would access memory assuming physmem did
not need to be mapped. In sandbox, that's not the case.

Now we map the physmem specified by the user in loadaddr to the buffer
that represents that space.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fa84fa70 11-Dec-2012 Matthias Brugger <matthias.bgg@gmail.com>

net: nfs: add dynamic wait period

This patch tackles the time out problem which leads to break the
boot process, when loading file over nfs. The patch does two things.

First of all, we just ignore messages that arrive with a rpc_id smaller
then the client id. We just interpret this messages as answers to
formaly timed out messages.

Second, when a time out occurs we double the time to wait, so that we
do not stress the server resending the last message.

Signed-off-by: Matthias Brugger <matthias.bgg@gmail.com>
Tested-by: Enric Balletbo i Serra <eballetbo@gmail.com>


# 48a3e999 03-Jul-2012 Tetsuyuki Kobayashi <koba@kmckk.co.jp>

net: nfs: make NFS_TIMEOUT configurable

NFS_TIMEOUT is constant value defined in net/nfs.c. But sometimes it needs to adjust.
This patch enables to override NFS_TIMEOUT by defining CONFIG_NFS_TIMEOUT in a board specific config file.

Signed-off-by: Tetsuyuki Kobayashi <koba@kmckk.co.jp>


# ece223b5 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to separate the UDP handler from the ARP handler

Call a built-in dummy if none is registered... don't require
protocols to register a handler (eliminating dummies)
NetConsole now uses the ARP handler when waiting on arp
(instead of needing a #define hack in arp.c)
Clear handlers at the end of net loop

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# 22f6e99d 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: Refactor to protect access to the NetState variable

Changes to NetState now go through an accessor function called
net_set_state()

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# 594c26f8 23-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: Un-typedef IP_t

Rename IP header related things to IP_UDP. The existing definition
of IP_t includes UDP header, so name it to accurately describe the
structure.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>


# c9f6c91b 15-May-2012 Joe Hershberger <joe.hershberger@ni.com>

net: cosmetic: nfs.* checkpatch compliance

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>


# ea45cb0a 02-Dec-2011 Matthias Weisser <weisserm@arcor.de>

net: Make sure IPaddr_t is 32 bits in size

When building u-boot as 64 bit application (e.g. sandbox) ulong might be
64 bits in size. This breaks network code as IPaddr_t is 64 bytes in
size then and an IPv4 address is 32 bits in size. This patch makes sure
that IPaddr_t is always 32 bits in size. Also some warnings introduced
by this patch are fixed.

Signed-off-by: Matthias Weisser <weisserm@arcor.de>
Acked-by: Mike Frysinger <vapier@gentoo.org>


# e2a53458 02-Oct-2011 Mike Frysinger <vapier@gentoo.org>

net: drop !NET_MULTI code

This is long over due. All but two net drivers have been converted, but
those have now been dropped.

The only thing left to do is actually delete all references to NET_MULTI
and code that is compiled when that is not defined. So here we scrub the
core code.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>


# 03eb129f 18-Apr-2011 Luca Ceresoli <luca.ceresoli@comelit.it>

NET: pass source IP address to packet handlers

This is needed for the upcoming TFTP server implementation.

This also simplifies PingHandler() and fixes rxhand_f documentation.

Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>


# 6ac59c55 03-Nov-2009 Mike Frysinger <vapier@gentoo.org>

net: pull CONFIG checks out of source and into makefile

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# aabb8cb0 09-Nov-2009 Evan Samanas <esamanas@xes-inc.com>

nfs: NfsTimeout() updates

- NfsTimeout() does not correctly update the NFS timeout value which
results in NfsTimeout() only being called once in certain situations.
This can result in the 'nfs' command hanging indefinetly. For
example, the command:

nfs 192.168.0.1:/home/user/file

will not exit until ctrl-c is pressed if 192.168.0.1 does not have an
NFS server running.

This issue is resolved by reinitializting the NFS timeout value inside
NfsTimeout() when a timeout occurs.

- Make the 'nfs' command print the 'T' character when a timeout occurs.
Previously there was no indication that timeouts were occuring.

- Mimic the 'tftpboot' command and when a download fails print "Retry
count exceeded; starting again", and restart the download taking the
'netretry' environment variable into account.

Signed-off-by: Evan Samanas <esamanas@xes-inc.com>
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>

Tested on TQM8xxL.

Tested by: Wolfgang Denk <wd@denx.de>

Tested on MPC8527DS.

Tested by: Ed Swarthout <Ed.Swarthout@freescale.com>


# f64ef9bb 19-Nov-2009 Ed Swarthout <Ed.Swarthout@freescale.com>

fix nfs symlink name corruption

An off by one error may cause nfs readlink lookup fail if
nfs_path_buff has non-zero data from a previous use.

Loading: *** ERROR: File lookup fail

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>


# 0ebf04c6 23-Jul-2009 Robin Getz <rgetz@blackfin.uclinux.org>

minor debug cleanups in ./net

Minor ./net cleanups - no functional changes
- change #ifdef DEBUG printf(); #endif to just debug()
- changed __FUNCTION__ to __func__
- got rid of extra whitespace between function and opening brace
- removed unnecessary braces on if statements

gcc dead code elimination should make this functionally/size equivalent
when DEBUG is not defined. (confirmed on Blackfin, with gcc 4.3.3).

Signed-off-by: Robin Getz <rgetz@blackfin.uclinux.org>

Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# b6446b67 16-Feb-2009 Mike Frysinger <vapier@gentoo.org>

convert print_IPaddr() to %pI4

Now that our printf functions support the %pI4 modifier like the kernel,
let's drop the inflexible print_IPaddr() function and covert over to the
%pI4 modifier.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
CC: Ben Warren <biggerbadderben@gmail.com>


# 6d0f6bcf 16-Oct-2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

rename CFG_ macros to CONFIG_SYS

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>


# 49f3bdbb 01-Oct-2008 Bartlomiej Sieka <tur@semihalf.com>

net: express the first argument to NetSetTimeout() in milliseconds

Enforce millisecond semantics of the first argument to NetSetTimeout() --
the change is transparent for well-behaving boards (CFG_HZ == 1000 and
get_timer() countiing in milliseconds).

Rationale for this patch is to enable millisecond granularity for
network-related timeouts, which is needed for the upcoming automatic
software update feature.

Summary of changes:
- do not scale the first argument to NetSetTimeout() by CFG_HZ
- change timeout values used in the networking code to milliseconds

Signed-off-by: Rafal Czubak <rcz@semihalf.com>
Signed-off-by: Bartlomiej Sieka <tur@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>


# fe891ecf 31-Jan-2008 Hiroshi Ito <ito@mlb.co.jp>

NFS Timeout with large files.

Retry to send NFS packet before reaching timeout.

Signed-off-by: Hiroshi Ito <ito@mlb.co.jp>


# 079c2c4f 17-Nov-2007 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

Fix warning differ in signedness in net/net.c and net/nfs.c


# 29c29c02 23-Oct-2007 Guennadi Liakhovetski <lg@denx.de>

Fix typo in nfs.c

An obvious typo. Originally fixed in linkstation u-boot port.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>


# 3865b1fb 10-Jul-2007 Stefan Roese <sr@denx.de>

Fix some compile problems introduced by the latest CFG_CMD_xxx cleanup

Signed-off-by: Stefan Roese <sr@denx.de>


# 643d1ab2 09-Jul-2007 Jon Loeliger <jdl@freescale.com>

net/: Remove obsolete references to CONFIG_COMMANDS

Signed-off-by: Jon Loeliger <jdl@freescale.com>


# 6e2115ac 11-Jun-2007 Jon Loeliger <jdl@jdl.com>

net/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).

This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
#if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>


# 23a7a32d 05-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Fix return code of NFS command
Patch by Hiroshi Ito, 11 Dec 2004


# c43352cc 03-Aug-2005 Wolfgang Denk <wd@pollux.denx.de>

Fix endianess problem in TFTP / NFS default filenames
Patch by Hiroshi Ito, 06 Dec 2004


# a5725fab 28-Sep-2004 wdenk <wdenk>

* Patch by Ganapathi C, 04 Aug 2004:
Fix NFS timeout issue


# e94d2cd9 30-Jun-2004 wdenk <wdenk>

* Fix "cls" command when used with splash screen

* Increase NFS download timeout (now 1 min - 10 sec is to short for a
slow download of a big image)


# a3d991bd 15-Apr-2004 wdenk <wdenk>

Patches by Pantelis Antoniou, 30 Mar 2004:
add networking support for VLANs (802.1q), and CDP (Cisco Discovery Protocol)


# 4b9206ed 23-Mar-2004 wdenk <wdenk>

* Patches by Thomas Viehweger, 16 Mar 2004:
- show PCI clock frequency on MPC8260 systems
- add FCC_PSMR_RMII flag for HiP7 processors
- in do_jffs2_fsload(), take load address from load_addr if not set
explicit, update load_addr otherwise
- replaced printf by putc/puts when no formatting is needed
(smaller code size, faster execution)


# c3f9d493 13-Mar-2004 wdenk <wdenk>

* Patch by Yuli Barcohen, 4 Mar 2004:
Fix problems with GCC 3.3.x which changed handling of global
variables explicitly initialized to zero (now in .bss instead of
.data as before).

* Patch by Leon Kukovec, 02 Mar 2004:
add strswab() to fix IDE LBA capacity, firmware and model numbers
on little endian machines

* Patch by Masami Komiya, 02 Mar 2004:
- Remove get_ticks() from NFS code
- Add verification of RPC transaction ID

* Patch by Pierre Aubert, 02 Mar 2004:
cleanup for IDE and USB drivers for MPC5200


# 11dadd54 26-Feb-2004 wdenk <wdenk>

* Patch by Steven Scholz, 25 Feb 2004:
- Timeouts in FPGA code should be based on CFG_HZ
- Minor cleanup in code for Altera FPGA ACEX1K

* Patch by Steven Scholz, 25 Feb 2004:
Changed "Directory Hierarchy" section in README

* Patch by Masami Komiya, 25 Feb 2004:
Reduce copy count in nfs_read_reply() of NFS code


# a084f7da 24-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiya, 24 Feb 2004:
Update NetBootFileXferSize in NFS code

* Patch by Scott McNutt, 24 Feb 2004:
fix packet length in NFS code


# cbd8a35c 23-Feb-2004 wdenk <wdenk>

* Patch by Masami Komiy, 22 Feb 2004:
Add support for NFS for file download

* Minor code cleanup