iPXE
|
TFTP protocol. More...
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <byteswap.h>
#include <errno.h>
#include <assert.h>
#include <ipxe/refcnt.h>
#include <ipxe/iobuf.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
#include <ipxe/uri.h>
#include <ipxe/tcpip.h>
#include <ipxe/retry.h>
#include <ipxe/features.h>
#include <ipxe/bitmap.h>
#include <ipxe/settings.h>
#include <ipxe/dhcp.h>
#include <ipxe/profile.h>
#include <ipxe/errortab.h>
#include <ipxe/tftp.h>
Go to the source code of this file.
Data Structures | |
struct | tftp_request |
A TFTP request. More... | |
struct | tftp_option |
A TFTP option. More... | |
Macros | |
#define | EINVAL_BLKSIZE __einfo_error ( EINFO_EINVAL_BLKSIZE ) |
#define | EINFO_EINVAL_BLKSIZE |
#define | EINVAL_TSIZE __einfo_error ( EINFO_EINVAL_TSIZE ) |
#define | EINFO_EINVAL_TSIZE |
#define | EINVAL_MC_NO_PORT __einfo_error ( EINFO_EINVAL_MC_NO_PORT ) |
#define | EINFO_EINVAL_MC_NO_PORT |
#define | EINVAL_MC_NO_MC __einfo_error ( EINFO_EINVAL_MC_NO_MC ) |
#define | EINFO_EINVAL_MC_NO_MC |
#define | EINVAL_MC_INVALID_MC __einfo_error ( EINFO_EINVAL_MC_INVALID_MC ) |
#define | EINFO_EINVAL_MC_INVALID_MC |
#define | EINVAL_MC_INVALID_IP __einfo_error ( EINFO_EINVAL_MC_INVALID_IP ) |
#define | EINFO_EINVAL_MC_INVALID_IP |
#define | EINVAL_MC_INVALID_PORT __einfo_error ( EINFO_EINVAL_MC_INVALID_PORT ) |
#define | EINFO_EINVAL_MC_INVALID_PORT |
#define | ENOENT_NOT_FOUND __einfo_error ( EINFO_ENOENT_NOT_FOUND ) |
#define | EINFO_ENOENT_NOT_FOUND |
#define | MTFTP_MAX_TIMEOUTS 3 |
Maximum number of MTFTP open requests before falling back to TFTP. More... | |
Enumerations | |
enum | { TFTP_FL_SEND_ACK = 0x0001, TFTP_FL_RRQ_SIZES = 0x0002, TFTP_FL_RRQ_MULTICAST = 0x0004, TFTP_FL_MTFTP_RECOVERY = 0x0008 } |
TFTP request flags. More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
FEATURE (FEATURE_PROTOCOL, "TFTP", DHCP_EB_FEATURE_TFTP, 1) | |
static void | tftp_free (struct refcnt *refcnt) |
Free TFTP request. More... | |
static void | tftp_done (struct tftp_request *tftp, int rc) |
Mark TFTP request as complete. More... | |
static int | tftp_reopen (struct tftp_request *tftp) |
Reopen TFTP socket. More... | |
static int | tftp_reopen_mc (struct tftp_request *tftp, struct sockaddr *local) |
Reopen TFTP multicast socket. More... | |
static int | tftp_presize (struct tftp_request *tftp, size_t filesize) |
Presize TFTP receive buffers and block bitmap. More... | |
void | tftp_set_mtftp_address (struct in_addr address) |
Set MTFTP multicast address. More... | |
void | tftp_set_mtftp_port (unsigned int port) |
Set MTFTP multicast port. More... | |
static int | tftp_send_rrq (struct tftp_request *tftp) |
Transmit RRQ. More... | |
static int | tftp_send_ack (struct tftp_request *tftp) |
Transmit ACK. More... | |
static int | tftp_send_error (struct tftp_request *tftp, int errcode, const char *errmsg) |
Transmit ERROR (Abort) More... | |
static int | tftp_send_packet (struct tftp_request *tftp) |
Transmit next relevant packet. More... | |
static void | tftp_timer_expired (struct retry_timer *timer, int fail) |
Handle TFTP retransmission timer expiry. More... | |
static int | tftp_process_blksize (struct tftp_request *tftp, char *value) |
Process TFTP "blksize" option. More... | |
static int | tftp_process_tsize (struct tftp_request *tftp, char *value) |
Process TFTP "tsize" option. More... | |
static int | tftp_process_multicast (struct tftp_request *tftp, char *value) |
Process TFTP "multicast" option. More... | |
static int | tftp_process_option (struct tftp_request *tftp, const char *name, char *value) |
Process TFTP option. More... | |
static int | tftp_rx_oack (struct tftp_request *tftp, void *buf, size_t len) |
Receive OACK. More... | |
static int | tftp_rx_data (struct tftp_request *tftp, struct io_buffer *iobuf) |
Receive DATA. More... | |
static int | tftp_errcode_to_rc (unsigned int errcode) |
Convert TFTP error code to return status code. More... | |
static int | tftp_rx_error (struct tftp_request *tftp, void *buf, size_t len) |
Receive ERROR. More... | |
static int | tftp_rx (struct tftp_request *tftp, struct io_buffer *iobuf, struct xfer_metadata *meta) |
Receive new data. More... | |
static int | tftp_socket_deliver (struct tftp_request *tftp, struct io_buffer *iobuf, struct xfer_metadata *meta) |
Receive new data via socket. More... | |
static size_t | tftp_xfer_window (struct tftp_request *tftp) |
Check flow control window. More... | |
static void | tftp_close (struct tftp_request *tftp, int rc) |
Terminate download. More... | |
static int | tftp_core_open (struct interface *xfer, struct uri *uri, unsigned int default_port, struct sockaddr *multicast, unsigned int flags) |
Initiate TFTP/TFTM/MTFTP download. More... | |
static int | tftp_open (struct interface *xfer, struct uri *uri) |
Initiate TFTP download. More... | |
static int | tftm_open (struct interface *xfer, struct uri *uri) |
Initiate TFTM download. More... | |
static int | mtftp_open (struct interface *xfer, struct uri *uri) |
Initiate MTFTP download. More... | |
static int | tftp_apply_settings (void) |
Apply TFTP configuration settings. More... | |
Variables | |
static struct profiler tftp_client_profiler | __profiler |
Client profiler. More... | |
struct errortab tftp_errors [] | __errortab |
Human-readable error messages. More... | |
static struct sockaddr_in | tftp_mtftp_socket |
MTFTP multicast receive address. More... | |
static struct tftp_option | tftp_options [] |
Recognised TFTP options. More... | |
static struct interface_operation | tftp_socket_operations [] |
TFTP socket operations. More... | |
static struct interface_descriptor | tftp_socket_desc |
TFTP socket interface descriptor. More... | |
static struct interface_operation | tftp_mc_socket_operations [] |
TFTP multicast socket operations. More... | |
static struct interface_descriptor | tftp_mc_socket_desc |
TFTP multicast socket interface descriptor. More... | |
static struct interface_operation | tftp_xfer_operations [] |
TFTP data transfer interface operations. More... | |
static struct interface_descriptor | tftp_xfer_desc |
TFTP data transfer interface descriptor. More... | |
struct uri_opener tftp_uri_opener | __uri_opener |
TFTP URI opener. More... | |
struct settings_applicator tftp_settings_applicator | __settings_applicator |
TFTP settings applicator. More... | |
TFTP protocol.
Definition in file tftp.c.
#define EINVAL_BLKSIZE __einfo_error ( EINFO_EINVAL_BLKSIZE ) |
#define EINFO_EINVAL_BLKSIZE |
#define EINVAL_TSIZE __einfo_error ( EINFO_EINVAL_TSIZE ) |
#define EINFO_EINVAL_TSIZE |
#define EINVAL_MC_NO_PORT __einfo_error ( EINFO_EINVAL_MC_NO_PORT ) |
#define EINFO_EINVAL_MC_NO_PORT |
#define EINVAL_MC_NO_MC __einfo_error ( EINFO_EINVAL_MC_NO_MC ) |
#define EINFO_EINVAL_MC_NO_MC |
#define EINVAL_MC_INVALID_MC __einfo_error ( EINFO_EINVAL_MC_INVALID_MC ) |
#define EINFO_EINVAL_MC_INVALID_MC |
#define EINVAL_MC_INVALID_IP __einfo_error ( EINFO_EINVAL_MC_INVALID_IP ) |
#define EINFO_EINVAL_MC_INVALID_IP |
#define EINVAL_MC_INVALID_PORT __einfo_error ( EINFO_EINVAL_MC_INVALID_PORT ) |
#define EINFO_EINVAL_MC_INVALID_PORT |
#define ENOENT_NOT_FOUND __einfo_error ( EINFO_ENOENT_NOT_FOUND ) |
#define EINFO_ENOENT_NOT_FOUND |
#define MTFTP_MAX_TIMEOUTS 3 |
anonymous enum |
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
FEATURE | ( | FEATURE_PROTOCOL | , |
"TFTP" | , | ||
DHCP_EB_FEATURE_TFTP | , | ||
1 | |||
) |
|
static |
Free TFTP request.
refcnt | Reference counter |
Definition at line 184 of file tftp.c.
References tftp_request::bitmap, bitmap_free(), container_of, free, tftp_request::uri, and uri_put().
Referenced by tftp_core_open().
|
static |
Mark TFTP request as complete.
tftp | TFTP connection |
rc | Return status code |
Definition at line 199 of file tftp.c.
References DBGC, intf_shutdown(), tftp_request::mc_socket, rc, tftp_request::socket, stop_timer(), strerror(), tftp_request::timer, and tftp_request::xfer.
Referenced by tftp_close(), tftp_core_open(), tftp_rx_data(), tftp_rx_error(), tftp_rx_oack(), and tftp_timer_expired().
|
static |
Reopen TFTP socket.
tftp | TFTP connection |
rc | Return status code |
Definition at line 219 of file tftp.c.
References DBGC, tftp_request::flags, uri::host, htons, intf_restart(), memset(), NULL, tftp_request::peer, tftp_request::port, rc, SOCK_DGRAM, tftp_request::socket, sockaddr_tcpip::st_port, strerror(), TFTP_FL_SEND_ACK, tftp_request::uri, and xfer_open_named_socket().
Referenced by tftp_core_open(), and tftp_timer_expired().
|
static |
Reopen TFTP multicast socket.
tftp | TFTP connection |
local | Local socket address |
rc | Return status code |
Definition at line 253 of file tftp.c.
References DBGC, intf_restart(), tftp_request::mc_socket, rc, SOCK_DGRAM, strerror(), and xfer_open_socket().
Referenced by tftp_core_open(), and tftp_process_multicast().
|
static |
Presize TFTP receive buffers and block bitmap.
tftp | TFTP connection |
filesize | Known minimum file size |
rc | Return status code |
Definition at line 281 of file tftp.c.
References tftp_request::bitmap, bitmap_resize(), tftp_request::blksize, DBGC, EINVAL, tftp_request::filesize, rc, strerror(), tftp_request::xfer, and xfer_seek().
Referenced by tftp_rx_data(), and tftp_rx_oack().
void tftp_set_mtftp_address | ( | struct in_addr | address | ) |
Set MTFTP multicast address.
address | Multicast IPv4 address |
Definition at line 328 of file tftp.c.
References address, sockaddr_in::sin_addr, and tftp_mtftp_socket.
void tftp_set_mtftp_port | ( | unsigned int | port | ) |
Set MTFTP multicast port.
port | Multicast port |
Definition at line 337 of file tftp.c.
References htons, port, sockaddr_in::sin_port, and tftp_mtftp_socket.
|
static |
Transmit RRQ.
tftp | TFTP connection |
rc | Return status code |
Definition at line 347 of file tftp.c.
References blksize, DBGC, ENOMEM, tftp_request::flags, htons, iob_put, iob_tailroom(), len, tftp_rrq::opcode, uri::path, snprintf(), tftp_request::socket, strlen(), io_buffer::tail, TFTP_FL_RRQ_MULTICAST, TFTP_FL_RRQ_SIZES, TFTP_MAX_BLKSIZE, TFTP_RRQ, tftp_request::uri, tftp_request::xfer, xfer_alloc_iob(), xfer_deliver_iob(), and xfer_window().
Referenced by tftp_send_packet().
|
static |
Transmit ACK.
tftp | TFTP connection |
rc | Return status code |
Definition at line 400 of file tftp.c.
References tftp_request::bitmap, bitmap_first_gap(), block, tftp_ack::block, DBGC2, ENOMEM, htons, iob_put, meta(), tftp_ack::opcode, tftp_request::peer, tftp_request::socket, TFTP_ACK, xfer_alloc_iob(), and xfer_deliver().
Referenced by tftp_send_packet().
|
static |
Transmit ERROR (Abort)
tftp | TFTP connection |
errcode | TFTP error code |
errmsg | Error message string |
rc | Return status code |
Definition at line 434 of file tftp.c.
References DBGC2, ENOMEM, errcode, tftp_error::errcode, errmsg, tftp_error::errmsg, htons, iob_put, meta(), tftp_error::opcode, tftp_request::peer, tftp_request::socket, strcpy(), strlen(), TFTP_ERROR, xfer_alloc_iob(), and xfer_deliver().
Referenced by tftp_close().
|
static |
Transmit next relevant packet.
tftp | TFTP connection |
rc | Return status code |
Definition at line 468 of file tftp.c.
References tftp_request::flags, tftp_request::peer, tftp_request::socket, sockaddr_tcpip::st_family, start_timer(), start_timer_nodelay(), stop_timer(), TFTP_FL_SEND_ACK, tftp_send_ack(), tftp_send_rrq(), tftp_request::timer, and xfer_window().
Referenced by tftp_rx_data(), tftp_rx_oack(), and tftp_timer_expired().
|
static |
Handle TFTP retransmission timer expiry.
timer | Retry timer |
fail | Failure indicator |
Definition at line 499 of file tftp.c.
References tftp_request::bitmap, bitmap_free(), container_of, DBGC, ETIMEDOUT, tftp_request::flags, intf_restart(), tftp_request::mc_socket, memset(), MTFTP_MAX_TIMEOUTS, tftp_request::mtftp_timeouts, tftp_request::peer, tftp_request::port, rc, sockaddr_tcpip::st_family, start_timer_nodelay(), tftp_done(), TFTP_FL_MTFTP_RECOVERY, TFTP_FL_RRQ_SIZES, TFTP_PORT, tftp_reopen(), tftp_send_packet(), and tftp_request::timer.
Referenced by tftp_core_open().
|
static |
Process TFTP "blksize" option.
tftp | TFTP connection |
value | Option value |
rc | Return status code |
Definition at line 566 of file tftp.c.
References tftp_request::blksize, DBGC, EINVAL_BLKSIZE, end, strtoul(), and value.
|
static |
Process TFTP "tsize" option.
tftp | TFTP connection |
value | Option value |
rc | Return status code |
Definition at line 587 of file tftp.c.
References DBGC, EINVAL_TSIZE, end, strtoul(), tftp_request::tsize, and value.
|
static |
Process TFTP "multicast" option.
tftp | TFTP connection |
value | Option value |
rc | Return status code |
Definition at line 608 of file tftp.c.
References addr, AF_INET, DBGC, EINVAL_MC_INVALID_IP, EINVAL_MC_INVALID_MC, EINVAL_MC_INVALID_PORT, EINVAL_MC_NO_MC, EINVAL_MC_NO_PORT, tftp_request::flags, htons, if(), inet_aton(), inet_ntoa(), ntohs, port, rc, sa, sin, strchr(), strtoul(), TFTP_FL_SEND_ACK, tftp_reopen_mc(), and value.
|
static |
Process TFTP option.
tftp | TFTP connection |
name | Option name |
value | Option value |
rc | Return status code |
Definition at line 697 of file tftp.c.
References DBGC, option::name, name, strcasecmp(), tftp_options, and value.
Referenced by tftp_rx_oack().
|
static |
Receive OACK.
tftp | TFTP connection |
buf | Temporary data buffer |
len | Length of temporary data buffer |
rc | Return status code |
Definition at line 721 of file tftp.c.
References tftp_oack::data, DBGC, DBGC_HD, done, EINVAL, end, len, name, next, rc, strnlen(), tftp_done(), tftp_presize(), tftp_process_option(), tftp_send_packet(), tftp_request::tsize, and value.
Referenced by tftp_rx().
|
static |
Receive DATA.
tftp | TFTP connection |
iobuf | I/O buffer |
rc | Return status code |
Takes ownership of I/O buffer.
Definition at line 797 of file tftp.c.
References tftp_request::bitmap, bitmap_first_gap(), bitmap_full(), bitmap_set(), tftp_request::blksize, block, data, io_buffer::data, data_len, DBGC, done, EINVAL, free_iob(), iob_disown, iob_len(), iob_pull, memset(), meta(), ntohs, offset, profile_start(), profile_stop(), rc, strerror(), tftp_done(), tftp_presize(), tftp_send_packet(), tftp_request::xfer, xfer_deliver(), and XFER_FL_ABS_OFFSET.
Referenced by tftp_rx().
|
static |
Convert TFTP error code to return status code.
errcode | TFTP error code |
rc | Return status code |
Definition at line 882 of file tftp.c.
References EACCES, ENOENT_NOT_FOUND, ENOTSUP, ENOTTY, errcode, TFTP_ERR_ACCESS_DENIED, TFTP_ERR_FILE_NOT_FOUND, and TFTP_ERR_ILLEGAL_OP.
Referenced by tftp_rx_error().
|
static |
Receive ERROR.
tftp | TFTP connection |
buf | Temporary data buffer |
len | Length of temporary data buffer |
rc | Return status code |
Definition at line 899 of file tftp.c.
References DBGC, EINVAL, error, len, ntohs, rc, tftp_done(), and tftp_errcode_to_rc().
Referenced by tftp_rx().
|
static |
Receive new data.
tftp | TFTP connection |
iobuf | I/O buffer |
meta | Transfer metadata |
rc | Return status code |
Definition at line 930 of file tftp.c.
References common, io_buffer::data, DBGC, done, EINVAL, free_iob(), htons, if(), iob_disown, iob_len(), len, memcmp(), memcpy(), meta(), ntohs, tftp_request::peer, profile_start(), rc, sockaddr_tcpip::st_family, sockaddr_tcpip::st_port, TFTP_DATA, TFTP_ERROR, TFTP_OACK, tftp_rx_data(), tftp_rx_error(), and tftp_rx_oack().
Referenced by tftp_socket_deliver().
|
static |
Receive new data via socket.
tftp | TFTP connection |
iobuf | I/O buffer |
meta | Transfer metadata |
rc | Return status code |
Definition at line 996 of file tftp.c.
References tftp_request::flags, meta(), TFTP_FL_SEND_ACK, and tftp_rx().
|
static |
Check flow control window.
tftp | TFTP connection |
len | Length of window |
Definition at line 1044 of file tftp.c.
References tftp_request::blksize.
|
static |
Terminate download.
tftp | TFTP connection |
rc | Reason for close |
Definition at line 1060 of file tftp.c.
References rc, tftp_done(), and tftp_send_error().
Referenced by pxenv_tftp_close().
|
static |
Initiate TFTP/TFTM/MTFTP download.
xfer | Data transfer interface |
uri | Uniform Resource Identifier |
rc | Return status code |
Definition at line 1086 of file tftp.c.
References tftp_request::blksize, DBGC, EINVAL, ENOMEM, flags, tftp_request::flags, uri::host, intf_init(), intf_plug_plug(), tftp_request::mc_socket, uri::path, tftp_request::port, rc, ref_init, ref_put, tftp_request::refcnt, tftp_request::socket, start_timer_nodelay(), strerror(), TFTP_DEFAULT_BLKSIZE, tftp_done(), tftp_free(), tftp_mc_socket_desc, tftp_reopen(), tftp_reopen_mc(), tftp_socket_desc, tftp_timer_expired(), tftp_xfer_desc, tftp_request::timer, tftp_request::uri, uri_get(), uri_port(), tftp_request::xfer, and zalloc().
Referenced by mtftp_open(), tftm_open(), and tftp_open().
Initiate TFTP download.
xfer | Data transfer interface |
uri | Uniform Resource Identifier |
rc | Return status code |
Definition at line 1148 of file tftp.c.
References NULL, tftp_core_open(), TFTP_FL_RRQ_SIZES, TFTP_PORT, and tftp_request::xfer.
Referenced by pxenv_tftp_open().
Initiate TFTM download.
xfer | Data transfer interface |
uri | Uniform Resource Identifier |
rc | Return status code |
Definition at line 1167 of file tftp.c.
References NULL, tftp_core_open(), TFTP_FL_RRQ_MULTICAST, TFTP_FL_RRQ_SIZES, and TFTP_PORT.
Initiate MTFTP download.
xfer | Data transfer interface |
uri | Uniform Resource Identifier |
rc | Return status code |
Definition at line 1187 of file tftp.c.
References MTFTP_PORT, tftp_core_open(), TFTP_FL_MTFTP_RECOVERY, and tftp_mtftp_socket.
|
static |
Apply TFTP configuration settings.
rc | Return status code |
Definition at line 1211 of file tftp.c.
References churi(), DBGC, ENOMEM, fetch_ipv4_setting(), inet_ntoa(), NULL, parse_uri(), in_addr::s_addr, snprintf(), and uri_put().
|
static |
struct errortab tftp_errors [] __errortab |
Human-readable error messages.
|
static |
MTFTP multicast receive address.
This is treated as a global configuration parameter.
Definition at line 317 of file tftp.c.
Referenced by mtftp_open(), tftp_set_mtftp_address(), and tftp_set_mtftp_port().
|
static |
Recognised TFTP options.
Definition at line 682 of file tftp.c.
Referenced by tftp_process_option().
|
static |
TFTP socket operations.
|
static |
TFTP socket interface descriptor.
Definition at line 1026 of file tftp.c.
Referenced by tftp_core_open().
|
static |
TFTP multicast socket operations.
|
static |
TFTP multicast socket interface descriptor.
Definition at line 1035 of file tftp.c.
Referenced by tftp_core_open().
|
static |
TFTP data transfer interface operations.
|
static |
TFTP data transfer interface descriptor.
Definition at line 1076 of file tftp.c.
Referenced by tftp_core_open().
struct uri_opener mtftp_uri_opener __uri_opener |
TFTP URI opener.
MTFTP URI opener.
TFTM URI opener.
struct settings_applicator tftp_settings_applicator __settings_applicator |
TFTP settings applicator.