|
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. | |
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) | |
| FILE_SECBOOT (PERMITTED) | |
| FEATURE (FEATURE_PROTOCOL, "TFTP", DHCP_EB_FEATURE_TFTP, 1) | |
| static void | tftp_free (struct refcnt *refcnt) |
| Free TFTP request. | |
| static void | tftp_done (struct tftp_request *tftp, int rc) |
| Mark TFTP request as complete. | |
| static int | tftp_reopen (struct tftp_request *tftp) |
| Reopen TFTP socket. | |
| static int | tftp_reopen_mc (struct tftp_request *tftp, struct sockaddr *local) |
| Reopen TFTP multicast socket. | |
| static int | tftp_presize (struct tftp_request *tftp, size_t filesize) |
| Presize TFTP receive buffers and block bitmap. | |
| void | tftp_set_mtftp_address (struct in_addr address) |
| Set MTFTP multicast address. | |
| void | tftp_set_mtftp_port (unsigned int port) |
| Set MTFTP multicast port. | |
| static int | tftp_send_rrq (struct tftp_request *tftp) |
| Transmit RRQ. | |
| static int | tftp_send_ack (struct tftp_request *tftp) |
| Transmit ACK. | |
| static int | tftp_send_error (struct tftp_request *tftp, int errcode, const char *errmsg) |
| Transmit ERROR (Abort) | |
| static int | tftp_send_packet (struct tftp_request *tftp) |
| Transmit next relevant packet. | |
| static void | tftp_timer_expired (struct retry_timer *timer, int fail) |
| Handle TFTP retransmission timer expiry. | |
| static int | tftp_process_blksize (struct tftp_request *tftp, char *value) |
| Process TFTP "blksize" option. | |
| static int | tftp_process_tsize (struct tftp_request *tftp, char *value) |
| Process TFTP "tsize" option. | |
| static int | tftp_process_multicast (struct tftp_request *tftp, char *value) |
| Process TFTP "multicast" option. | |
| static int | tftp_process_option (struct tftp_request *tftp, const char *name, char *value) |
| Process TFTP option. | |
| static int | tftp_rx_oack (struct tftp_request *tftp, void *buf, size_t len) |
| Receive OACK. | |
| static int | tftp_rx_data (struct tftp_request *tftp, struct io_buffer *iobuf) |
| Receive DATA. | |
| static int | tftp_errcode_to_rc (unsigned int errcode) |
| Convert TFTP error code to return status code. | |
| static int | tftp_rx_error (struct tftp_request *tftp, void *buf, size_t len) |
| Receive ERROR. | |
| static int | tftp_rx (struct tftp_request *tftp, struct io_buffer *iobuf, struct xfer_metadata *meta) |
| Receive new data. | |
| static int | tftp_socket_deliver (struct tftp_request *tftp, struct io_buffer *iobuf, struct xfer_metadata *meta) |
| Receive new data via socket. | |
| static size_t | tftp_xfer_window (struct tftp_request *tftp) |
| Check flow control window. | |
| static void | tftp_close (struct tftp_request *tftp, int rc) |
| Terminate download. | |
| 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. | |
| static int | tftp_open (struct interface *xfer, struct uri *uri) |
| Initiate TFTP download. | |
| static int | tftm_open (struct interface *xfer, struct uri *uri) |
| Initiate TFTM download. | |
| static int | mtftp_open (struct interface *xfer, struct uri *uri) |
| Initiate MTFTP download. | |
| static int | tftp_apply_settings (void) |
| Apply TFTP configuration settings. | |
Variables | |
| static struct profiler tftp_client_profiler | __profiler |
| Client profiler. | |
| struct errortab tftp_errors[] | __errortab |
| Human-readable error messages. | |
| static struct sockaddr_in | tftp_mtftp_socket |
| MTFTP multicast receive address. | |
| static struct tftp_option | tftp_options [] |
| Recognised TFTP options. | |
| static struct interface_operation | tftp_socket_operations [] |
| TFTP socket operations. | |
| static struct interface_descriptor | tftp_socket_desc |
| TFTP socket interface descriptor. | |
| static struct interface_operation | tftp_mc_socket_operations [] |
| TFTP multicast socket operations. | |
| static struct interface_descriptor | tftp_mc_socket_desc |
| TFTP multicast socket interface descriptor. | |
| static struct interface_operation | tftp_xfer_operations [] |
| TFTP data transfer interface operations. | |
| static struct interface_descriptor | tftp_xfer_desc |
| TFTP data transfer interface descriptor. | |
| struct uri_opener tftp_uri_opener | __uri_opener |
| TFTP URI opener. | |
| struct settings_applicator tftp_settings_applicator | __settings_applicator |
| TFTP settings applicator. | |
TFTP protocol.
Definition in file tftp.c.
| #define EINVAL_BLKSIZE __einfo_error ( EINFO_EINVAL_BLKSIZE ) |
Definition at line 60 of file tftp.c.
Referenced by tftp_process_blksize().
| #define EINFO_EINVAL_BLKSIZE |
Definition at line 61 of file tftp.c.
| #define EINVAL_TSIZE __einfo_error ( EINFO_EINVAL_TSIZE ) |
Definition at line 63 of file tftp.c.
Referenced by tftp_process_tsize().
| #define EINFO_EINVAL_TSIZE |
Definition at line 64 of file tftp.c.
| #define EINVAL_MC_NO_PORT __einfo_error ( EINFO_EINVAL_MC_NO_PORT ) |
Definition at line 66 of file tftp.c.
Referenced by tftp_process_multicast().
| #define EINFO_EINVAL_MC_NO_PORT |
Definition at line 67 of file tftp.c.
| #define EINVAL_MC_NO_MC __einfo_error ( EINFO_EINVAL_MC_NO_MC ) |
Definition at line 69 of file tftp.c.
Referenced by tftp_process_multicast().
| #define EINFO_EINVAL_MC_NO_MC |
Definition at line 70 of file tftp.c.
| #define EINVAL_MC_INVALID_MC __einfo_error ( EINFO_EINVAL_MC_INVALID_MC ) |
Definition at line 72 of file tftp.c.
Referenced by tftp_process_multicast().
| #define EINFO_EINVAL_MC_INVALID_MC |
Definition at line 73 of file tftp.c.
| #define EINVAL_MC_INVALID_IP __einfo_error ( EINFO_EINVAL_MC_INVALID_IP ) |
Definition at line 75 of file tftp.c.
Referenced by tftp_process_multicast().
| #define EINFO_EINVAL_MC_INVALID_IP |
Definition at line 76 of file tftp.c.
| #define EINVAL_MC_INVALID_PORT __einfo_error ( EINFO_EINVAL_MC_INVALID_PORT ) |
Definition at line 78 of file tftp.c.
Referenced by tftp_process_multicast().
| #define EINFO_EINVAL_MC_INVALID_PORT |
Definition at line 79 of file tftp.c.
| #define ENOENT_NOT_FOUND __einfo_error ( EINFO_ENOENT_NOT_FOUND ) |
Definition at line 81 of file tftp.c.
Referenced by tftp_errcode_to_rc().
| #define EINFO_ENOENT_NOT_FOUND |
Definition at line 82 of file tftp.c.
| #define MTFTP_MAX_TIMEOUTS 3 |
Maximum number of MTFTP open requests before falling back to TFTP.
Definition at line 165 of file tftp.c.
Referenced by tftp_timer_expired().
| anonymous enum |
TFTP request flags.
Definition at line 153 of file tftp.c.
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
| FILE_SECBOOT | ( | PERMITTED | ) |
| FEATURE | ( | FEATURE_PROTOCOL | , |
| "TFTP" | , | ||
| DHCP_EB_FEATURE_TFTP | , | ||
| 1 | ) |
References DHCP_EB_FEATURE_TFTP, and FEATURE_PROTOCOL.
|
static |
Free TFTP request.
| refcnt | Reference counter |
Definition at line 185 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 200 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 220 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 254 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 282 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 329 of file tftp.c.
References address, and tftp_mtftp_socket.
| void tftp_set_mtftp_port | ( | unsigned int | port | ) |
Set MTFTP multicast port.
| port | Multicast port |
Definition at line 338 of file tftp.c.
References htons, port, and tftp_mtftp_socket.
|
static |
Transmit RRQ.
| tftp | TFTP connection |
| rc | Return status code |
Definition at line 348 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 401 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 435 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 469 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 500 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 567 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 588 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 609 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, 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 698 of file tftp.c.
References DBGC, name, option::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 722 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 798 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 883 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 900 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 931 of file tftp.c.
References common, io_buffer::data, DBGC, done, EINVAL, free_iob(), htons, 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 997 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 1045 of file tftp.c.
References tftp_request::blksize.
|
static |
Terminate download.
| tftp | TFTP connection |
| rc | Reason for close |
Definition at line 1061 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 1087 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 1149 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 1168 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 1188 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 1212 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 318 of file tftp.c.
Referenced by mtftp_open(), tftp_set_mtftp_address(), and tftp_set_mtftp_port().
|
static |
Recognised TFTP options.
Definition at line 683 of file tftp.c.
Referenced by tftp_process_option().
|
static |
TFTP socket operations.
|
static |
TFTP socket interface descriptor.
Definition at line 1027 of file tftp.c.
Referenced by tftp_core_open().
|
static |
TFTP multicast socket operations.
|
static |
TFTP multicast socket interface descriptor.
Definition at line 1036 of file tftp.c.
Referenced by tftp_core_open().
|
static |
TFTP data transfer interface operations.
Definition at line 1071 of file tftp.c.
|
static |
TFTP data transfer interface descriptor.
Definition at line 1077 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.