summaryrefslogtreecommitdiff
path: root/lib/libstand/tftp.c
Commit message (Collapse)AuthorAgeFilesLines
* Move lib/libstand to sys/boot/libsaWarner Losh2017-10-121-785/+0
| | | | | | | | | | Move the sources to sys/boot. Make adjustments related to the move. Kill LIBSTAND_SRC since it's no longer needed. Sponsored by: Netflix Notes: svn path=/head/; revision=324551
* libstand: tftp_open() can leak pkt on errorToomas Soome2017-09-121-0/+1
| | | | | | | | | | The memory can be leaked if we will have pkt set and will get an error during tftp_open() processing. Differential Revision: https://reviews.freebsd.org/D12202 Notes: svn path=/head/; revision=323496
* loader: network read reworkToomas Soome2017-05-061-33/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current read from network is working from up to down - we have some protocol needing the data from the network, so we build the buffer space for that protocol, add the extra space for headers and pass this buffer down to be filled by nif get call in hope, we have guessed the incoming packet size right. Amazingly enough this approach mostly does work, but not always... So, this update does work from down to up - we allocate buffer (based on MTU or frame size info), fill it up, and pass on for upper layers. The obvious problem is that when we should free the buffer - if at all. In the current implementation the upper layer will free the packet on error or when the packet is no longer needed. While working on the issue, the additional issue did pop up - the bios implementation does not have generic get/put interface but is using pxe udpsend/udpreceive instead. So the udp calls are gone and undi interface is implemented instead. Which in turn means slight other changes as we do not need to have duplicated pxe implementation and can just use dev_net. To align packet content, the actual read from nic is using shifted buffer by ETHER_ALIGN (2). Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D10232 Notes: svn path=/head/; revision=317887
* Netboot: allow both tftpfs and nfs in both pxeboot and loader.efiBaptiste Daroussin2016-08-311-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add a new 'netproto' variable which can be set for now to NET_TFTP or NET_NFS (default to NET_NONE) From the dhcp options if one sets the root-path option to: "ip:path", the loader will consider it is booting over NFS (meaning same behaviour as the default current behaviour) if the dhcp option "tftp server address" is set (option 150) the loader will consider it is booting over tftpfs, it will then consider the root-path options with 2 possible case 1. "path" then the IP of the tftp server will be the one passed by the option 150, and the files will be retrieved under "path" on the tftp server 2. "ip:path" then the IP of the tftp server will be the one passed in the option "overwritting the IP from the option 150. We could not "abuse" the rootpath option in the form or tftp://ip:path because this is already used for other purpose by iPXE preventing any chainload from iPXE to the FreeBSD loader. Given at each open(), the loader loops over all available filesystems and keep the "best" error, we needed to prevent tftpfs to fallback on nfs and vice versa. the tftpfs and nfs implementation in libstand now return EINVAL early if 'netproto' for that purpose. Reviewed by: tsoome Relnotes: yes Sponsored by: Gandi.net Differential Revision: https://reviews.freebsd.org/D7628 Notes: svn path=/head/; revision=305125
* recvtftp() is broken for large files, report file sizeToomas Soome2016-08-311-2/+4
| | | | | | | | | | | | | | | | The tftp download for large files will cause internal block id to wrap to 0 as the data type is unsigned short. Also provide file size information for stat. PR: 200500 Reported by: tsoome Reviewed by: allanjude Approved by: allanjude (mentor) Differential Revision: https://reviews.freebsd.org/D7660 Notes: svn path=/head/; revision=305116
* pxeboot: make the tftp loader use the option root-path directiveBaptiste Daroussin2015-12-161-3/+17
| | | | | | | | | | | | | | | | | | | | | | | pxeboot in tftp loader mode (when built with LOADER_TFTP_SUPPORT) now prefix all the path to open with the path obtained via the option 'root-path' directive. This allows to be able to use the traditional content /boot out of box. Meaning it now works pretty much like all other loaders. It simplifies hosting hosting multiple version of FreeBSD on a tftp server. As a consequence, pxeboot does not look anymore for a pxeboot.4th (which was never provided) Note: that pxeboot in tftp loader mode is not built by default. Reviewed by: rpokala Relnotes: yes Sponsored by: Gandi.net Differential Revision: https://reviews.freebsd.org/D4590 Notes: svn path=/head/; revision=292344
* Add a divisor parameter to twiddle() so that callers can request that outputIan Lepore2014-12-221-3/+1
| | | | | | | | | | | | | | | only happen on every Nth call. Update the existing twiddle() calls done in various IO loops to roughly reflect the relative IO sizes. That is, tftp and nfs call twiddle() on every 1K block, ufs on every filesystem block, so the network calls now use a much larger divisor than disk IO calls. Also add a new twiddle_divisor() function that allows an application to set a global divisor that is applied on top of the per-call divisors. Nothing calls this yet, but loader(8) will be using it to further throttle the cursor for slow serial consoles. Notes: svn path=/head/; revision=276079
* Unbreak zfsloader with LOADER_TFTP_SUPPORT onAlexander Kabaev2013-10-091-2/+6
| | | | | | | | | | | | | Only accept 'net' and 'pxe' devices as underlying transport in tftp.c on x86. Prior to this change tftp code would attempt to send packets over any boot device, including zfs one with predictably sad results. Approved by: re (gjb) MFC After: 1 month Notes: svn path=/head/; revision=256244
* Add placeholder code for prepending pathnames to tftp.Ed Schouten2011-12-221-0/+7
| | | | | | | | | | | | | | | At work we have a single tftp server that provides installation data for a variety of operating systems. I'd rather place our FreeBSD-related files in a subdirectory, instead of the root. It would be nice if this setting could be run-time configurable, but at least in our specific case, this is not possible, as pxeboot is chainloaded through pxelinux. Sponsored by: Kumina bv Notes: svn path=/head/; revision=228798
* Fixes to newer tftp code in libstand:Craig Rodrigues2011-06-241-51/+132
| | | | | | | | | | | | | | | | | | | | | (1) Coding style changes. (2) If the server does not acknowledge any blocksize option, revert to the default blocksize of 512 bytes. (3) Send ACK if the first packet happens to be the last packet. (4) Do not accept blocksize greater than what was requested. (5) Drop any unwanted OACK received if a tftp transfer is already in progress. (6) Terminate incomplete transfers with a special no-error ERROR packet. Otherwise we rely on the tftp server to time out, which it does eventually, after re-sending the last packet several times and spamming the system log about it every time. This idea is borrowed from the PXE client, which does exactly that. Submitted by: Alexander Kabaev <kan@FreeBSD.org> Reviewed and Tested by: Santhanakrishnan Balraj <sbalraj at juniper dot net> Notes: svn path=/head/; revision=223488
* Bring back following change which was undone in previous commit:Craig Rodrigues2011-06-151-4/+4
| | | | | | | | | | | | | | | | | | | | | | ------------------------------------------------------------------------ r172854 | marius | 2007-10-21 10:03:18 -0700 (Sun, 21 Oct 2007) | 16 lines Changed paths: M /head/lib/libstand/tftp.c - Given that we tell the compiler that struct ip is packed and 32-bit aligned, GCC 4.2.1 also generates code for sendudp() that assumes this alignment. GCC 4.2.1 however doesn't 32-bit align wbuf, causing the loader to crash due to an unaligned access of wbuf in sendudp() when netbooting sparc64. Solve this by specifying wbuf as packed and 32-bit aligned, too. As for lastdata and readudp() this currently is no issue when compiled with GCC 4.2.1, though give lastdata the same treatment as wbuf for consistency and possibility of being affected in the future. [1] - Sprinkle const on a lookup table. ------------------------------------------------------------------------ Notes: svn path=/head/; revision=223128
* (1) When sending the TFTP RRQ packet to read a file,Craig Rodrigues2011-06-151-35/+229
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | send along the "blksize" option specified in RFC2348, and the "tsize" option specified in RFC2349. Add code to parse the TFTP Option Acknowledgement (OACK) packet as specified in RFC2347. For TFTP servers which support the "blksize" option, we can specify a TFTP Data block size larger than the default 512 bytes specified in RFC1350. This offers greater read performance when downloading files. We request an initial size of 1428 bytes, which is less than the Ethernet MTU of 1500 bytes. If the TFTP server sends back an OACK packet, then use the block size specified in the OACK packet. Most times it is usually the same value as what we request. If the TFTP server supports RFC2348, we will see performance improvements by transferring files over TFTP with larger block sizes. If we do not get back an OACK packet, then we most likely we are interoperating with a legacy TFTP server that does not support TFTP extension options, so default to the block size of 512 bytes. (2) If the "tftp.blksize" environment variable is set, then take that value and use it when sending the TFTP RRQ packet, instead of 1428. This allows us to set different values of "tftp.blksize" in the loader, so that we can test out different TFTP block sizes at run time. Obtained from: Juniper Networks Fixed by: rodrigc Notes: svn path=/head/; revision=223124
* Currently tftp code in the loader retransmits the previous packet if it ↵Craig Rodrigues2011-06-151-0/+4
| | | | | | | | | | | | | receives any unwanted packet(non-tftp). Change this to retransmit the packet(request or ack) only after a timeout. Obtained from: Juniper Networks Fixed by: Santhanakrishnan Balraj <sbalraj at juniper dot net> Notes: svn path=/head/; revision=223123
* Added sendrecv_tftp function instead of sendrecv for use by tftp.Craig Rodrigues2011-06-151-2/+55
| | | | | | | | | | | | | | In sendrecv_tftp: * Upon receving an unexpected block of data or error, resend the ACK immediately instead of waiting till the expiry of receive data timeout to resend the ACK. * change the receive timeout value between retries to be 2xMINTMO. Obtained from: Juniper Networks Fixed by: Santhanakrishnan Balraj <sbalraj at juniper dot net> Notes: svn path=/head/; revision=223122
* Rename DEBUG macro to TFTP_DEBUG, to be more consistent withCraig Rodrigues2011-05-031-5/+5
| | | | | | | debug macros in other files. Notes: svn path=/head/; revision=221366
* Switch to ANSI function prototypes in a few places.Craig Rodrigues2011-05-031-31/+11
| | | | | | | Get rid of some unused parameter warnings. Notes: svn path=/head/; revision=221358
* Fix minor issues in libstand.Ed Schouten2009-05-311-1/+1
| | | | | | | | | | - Don't call tftp_makereq() with too many arguments. - Don't forget to close one of the comments. Submitted by: Pawel Worach Notes: svn path=/head/; revision=193189
* - Given that we tell the compiler that struct ip is packed and 32-bitMarius Strobl2007-10-211-4/+4
| | | | | | | | | | | | | | | | | | | | aligned, GCC 4.2.1 also generates code for sendudp() that assumes this alignment. GCC 4.2.1 however doesn't 32-bit align wbuf, causing the loader to crash due to an unaligned access of wbuf in sendudp() when netbooting sparc64. Solve this by specifying wbuf as packed and 32-bit aligned, too. As for lastdata and readudp() this currently is no issue when compiled with GCC 4.2.1, though give lastdata the same treatment as wbuf for consistency and possibility of being affected in the future. [1] - Sprinkle const on a lookup table. Reported by: marcel [1] Submitted by: yongari [1] Reviewed by: marcel [1] MFC after: 5 days Notes: svn path=/head/; revision=172854
* Don't add integers to void pointers.Stefan Farfeleder2004-10-031-1/+1
| | | | Notes: svn path=/head/; revision=136093
* Fix a machine check abort caused by the EFI loader trying to open aMarcel Moolenaar2003-03-031-1/+2
| | | | | | | | | | | | | | | | | | | | | file in the NFS file system when the underlying device is not a network device. A Sparc64 specific hack for this exact problem was already present (nfs.c:1.9, tftp.c:1.10), but the problem is not specific to Sparc64. The hack has been promoted to a non-i386 test because on non-i386 architectures it's either impossible to have non-network devices coexist in the same loader with the NFS FS, or network and non-network device coexist and NFS filesystems can only be used on top of network devices. I believe i386 pxeboot is where this does not hold. The root cause of this problem is in open.c where each file system is tried until no more file systems exist or a file system returns success. There's no notion of a list of valid file systems given the underlying device and the non-existence of a file can cause the invalid combination to be tried. Notes: svn path=/head/; revision=111776
* Add a hack (kludge?) to avoid trying to access files backed by diskJake Burkholder2002-07-071-0/+4
| | | | | | | devices as though they were backed by network devices. Notes: svn path=/head/; revision=99558
* Remove 'register' keyword.David E. O'Brien2002-03-211-4/+4
| | | | Notes: svn path=/head/; revision=92913
* Add __FBSDID()s to libstandMatthew Dillon2001-09-301-2/+3
| | | | Notes: svn path=/head/; revision=84221
* Reset errno so that subsequent TFTP requests don't fail after theMike Heffner2001-06-301-0/+2
| | | | | | | | | | first failure. PR: misc/25502 MFC after: 2 weeks Notes: svn path=/head/; revision=79034
* The shortest valid TFTP packet is 4 bytes, not 8.Mike Smith2001-05-281-1/+1
| | | | | | | | | PR: misc/25503 Submitted by: Jim Browne <jbrowne@jbrowne.com> MFC after: 1 week Notes: svn path=/head/; revision=77369
* When TFTP tries to open a file, it is expecting struct open_filePaul Saab2000-12-081-0/+3
| | | | | | | | | | | member f_devdata to be a pointer to a socket number. When currdev is "pxe", that assumption is correct. When currdev is "disk*", that assumption is incorrect. Submitted by: Jim Browne <jbrowne@jbrowne.com> Notes: svn path=/head/; revision=69739
* Add a readdir function to the loader fsops vector, and implement theJonathan Lemon2000-04-291-1/+8
| | | | | | | functionality for some of the filesystesms. Notes: svn path=/head/; revision=59766
* Break out sendudp and readudp from net.c. This is for PXE, so itPaul Saab2000-04-081-1/+2
| | | | | | | can use its own UDP interface. Notes: svn path=/head/; revision=59086
* Path arguments to *_open functions should be const, but we were manglingMike Smith1998-09-181-4/+11
| | | | | | | | | them. Submitted by: write-protected text segment in BTX Notes: svn path=/head/; revision=39468
* This is libstand; a support library for standalone executables (eg. bootstrapMike Smith1998-08-201-0/+400
modules). Obtained from: NetBSD, with some architectural changes and many additions. Notes: svn path=/cvs2svn/branches/MSMITH/; revision=38451