iPXE
tftp.c File Reference

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.

Detailed Description

TFTP protocol.

Definition in file tftp.c.

Macro Definition Documentation

◆ EINVAL_BLKSIZE

#define EINVAL_BLKSIZE   __einfo_error ( EINFO_EINVAL_BLKSIZE )

Definition at line 60 of file tftp.c.

Referenced by tftp_process_blksize().

◆ EINFO_EINVAL_BLKSIZE

#define EINFO_EINVAL_BLKSIZE
Value:
( EINFO_EINVAL, 0x01, "Invalid blksize" )
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition errno.h:181
#define EINFO_EINVAL
Definition errno.h:430

Definition at line 61 of file tftp.c.

61#define EINFO_EINVAL_BLKSIZE __einfo_uniqify \
62 ( EINFO_EINVAL, 0x01, "Invalid blksize" )

◆ EINVAL_TSIZE

#define EINVAL_TSIZE   __einfo_error ( EINFO_EINVAL_TSIZE )

Definition at line 63 of file tftp.c.

Referenced by tftp_process_tsize().

◆ EINFO_EINVAL_TSIZE

#define EINFO_EINVAL_TSIZE
Value:
( EINFO_EINVAL, 0x02, "Invalid tsize" )

Definition at line 64 of file tftp.c.

64#define EINFO_EINVAL_TSIZE __einfo_uniqify \
65 ( EINFO_EINVAL, 0x02, "Invalid tsize" )

◆ EINVAL_MC_NO_PORT

#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().

◆ EINFO_EINVAL_MC_NO_PORT

#define EINFO_EINVAL_MC_NO_PORT
Value:
( EINFO_EINVAL, 0x03, "Missing multicast port" )

Definition at line 67 of file tftp.c.

67#define EINFO_EINVAL_MC_NO_PORT __einfo_uniqify \
68 ( EINFO_EINVAL, 0x03, "Missing multicast port" )

◆ EINVAL_MC_NO_MC

#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().

◆ EINFO_EINVAL_MC_NO_MC

#define EINFO_EINVAL_MC_NO_MC
Value:
( EINFO_EINVAL, 0x04, "Missing multicast mc" )

Definition at line 70 of file tftp.c.

70#define EINFO_EINVAL_MC_NO_MC __einfo_uniqify \
71 ( EINFO_EINVAL, 0x04, "Missing multicast mc" )

◆ EINVAL_MC_INVALID_MC

#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().

◆ EINFO_EINVAL_MC_INVALID_MC

#define EINFO_EINVAL_MC_INVALID_MC
Value:
( EINFO_EINVAL, 0x05, "Missing multicast IP" )

Definition at line 73 of file tftp.c.

73#define EINFO_EINVAL_MC_INVALID_MC __einfo_uniqify \
74 ( EINFO_EINVAL, 0x05, "Missing multicast IP" )

◆ EINVAL_MC_INVALID_IP

#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().

◆ EINFO_EINVAL_MC_INVALID_IP

#define EINFO_EINVAL_MC_INVALID_IP
Value:
( EINFO_EINVAL, 0x06, "Invalid multicast IP" )

Definition at line 76 of file tftp.c.

76#define EINFO_EINVAL_MC_INVALID_IP __einfo_uniqify \
77 ( EINFO_EINVAL, 0x06, "Invalid multicast IP" )

◆ EINVAL_MC_INVALID_PORT

#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().

◆ EINFO_EINVAL_MC_INVALID_PORT

#define EINFO_EINVAL_MC_INVALID_PORT
Value:
( EINFO_EINVAL, 0x07, "Invalid multicast port" )

Definition at line 79 of file tftp.c.

79#define EINFO_EINVAL_MC_INVALID_PORT __einfo_uniqify \
80 ( EINFO_EINVAL, 0x07, "Invalid multicast port" )

◆ ENOENT_NOT_FOUND

#define ENOENT_NOT_FOUND   __einfo_error ( EINFO_ENOENT_NOT_FOUND )

Definition at line 81 of file tftp.c.

Referenced by tftp_errcode_to_rc().

◆ EINFO_ENOENT_NOT_FOUND

#define EINFO_ENOENT_NOT_FOUND
Value:
( EINFO_ENOENT, 0x01, "Not found" )
#define EINFO_ENOENT
Definition errno.h:516

Definition at line 82 of file tftp.c.

82#define EINFO_ENOENT_NOT_FOUND __einfo_uniqify \
83 ( EINFO_ENOENT, 0x01, "Not found" )

◆ MTFTP_MAX_TIMEOUTS

#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().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

TFTP request flags.

Enumerator
TFTP_FL_SEND_ACK 

Send ACK packets.

TFTP_FL_RRQ_SIZES 

Request blksize and tsize options.

TFTP_FL_RRQ_MULTICAST 

Request multicast option.

TFTP_FL_MTFTP_RECOVERY 

Perform MTFTP recovery on timeout.

Definition at line 153 of file tftp.c.

153 {
154 /** Send ACK packets */
155 TFTP_FL_SEND_ACK = 0x0001,
156 /** Request blksize and tsize options */
157 TFTP_FL_RRQ_SIZES = 0x0002,
158 /** Request multicast option */
159 TFTP_FL_RRQ_MULTICAST = 0x0004,
160 /** Perform MTFTP recovery on timeout */
161 TFTP_FL_MTFTP_RECOVERY = 0x0008,
162};
@ TFTP_FL_RRQ_MULTICAST
Request multicast option.
Definition tftp.c:159
@ TFTP_FL_MTFTP_RECOVERY
Perform MTFTP recovery on timeout.
Definition tftp.c:161
@ TFTP_FL_SEND_ACK
Send ACK packets.
Definition tftp.c:155
@ TFTP_FL_RRQ_SIZES
Request blksize and tsize options.
Definition tftp.c:157

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ FEATURE()

FEATURE ( FEATURE_PROTOCOL ,
"TFTP" ,
DHCP_EB_FEATURE_TFTP ,
1  )

◆ tftp_free()

void tftp_free ( struct refcnt * refcnt)
static

Free TFTP request.

Parameters
refcntReference counter

Definition at line 185 of file tftp.c.

185 {
186 struct tftp_request *tftp =
188
189 uri_put ( tftp->uri );
190 bitmap_free ( &tftp->bitmap );
191 free ( tftp );
192}
static void bitmap_free(struct bitmap *bitmap)
Free bitmap resources.
Definition bitmap.h:58
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
A reference counter.
Definition refcnt.h:27
A TFTP request.
Definition tftp.c:90
struct uri * uri
URI being fetched.
Definition tftp.c:97
struct bitmap bitmap
Block bitmap.
Definition tftp.c:135
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition uri.h:206

References tftp_request::bitmap, bitmap_free(), container_of, free, tftp_request::uri, and uri_put().

Referenced by tftp_core_open().

◆ tftp_done()

void tftp_done ( struct tftp_request * tftp,
int rc )
static

Mark TFTP request as complete.

Parameters
tftpTFTP connection
rcReturn status code

Definition at line 200 of file tftp.c.

200 {
201
202 DBGC ( tftp, "TFTP %p finished with status %d (%s)\n",
203 tftp, rc, strerror ( rc ) );
204
205 /* Stop the retry timer */
206 stop_timer ( &tftp->timer );
207
208 /* Close all data transfer interfaces */
209 intf_shutdown ( &tftp->socket, rc );
210 intf_shutdown ( &tftp->mc_socket, rc );
211 intf_shutdown ( &tftp->xfer, rc );
212}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define DBGC(...)
Definition compiler.h:505
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition interface.c:279
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition retry.c:118
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
struct interface socket
Transport layer interface.
Definition tftp.c:99
struct retry_timer timer
Retransmission timer.
Definition tftp.c:149
struct interface xfer
Data transfer interface.
Definition tftp.c:94
struct interface mc_socket
Multicast transport layer interface.
Definition tftp.c:101

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().

◆ tftp_reopen()

int tftp_reopen ( struct tftp_request * tftp)
static

Reopen TFTP socket.

Parameters
tftpTFTP connection
Return values
rcReturn status code

Definition at line 220 of file tftp.c.

220 {
221 struct sockaddr_tcpip server;
222 int rc;
223
224 /* Close socket */
225 intf_restart ( &tftp->socket, 0 );
226
227 /* Disable ACK sending. */
228 tftp->flags &= ~TFTP_FL_SEND_ACK;
229
230 /* Reset peer address */
231 memset ( &tftp->peer, 0, sizeof ( tftp->peer ) );
232
233 /* Open socket */
234 memset ( &server, 0, sizeof ( server ) );
235 server.st_port = htons ( tftp->port );
236 if ( ( rc = xfer_open_named_socket ( &tftp->socket, SOCK_DGRAM,
237 ( struct sockaddr * ) &server,
238 tftp->uri->host, NULL ) ) != 0 ) {
239 DBGC ( tftp, "TFTP %p could not open socket: %s\n",
240 tftp, strerror ( rc ) );
241 return rc;
242 }
243
244 return 0;
245}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
#define SOCK_DGRAM
Definition socket.h:30
#define htons(value)
Definition byteswap.h:136
void * memset(void *dest, int character, size_t len) __nonnull
void intf_restart(struct interface *intf, int rc)
Shut down and restart an object interface.
Definition interface.c:344
int xfer_open_named_socket(struct interface *xfer, int semantics, struct sockaddr *peer, const char *name, struct sockaddr *local)
Open named socket.
Definition resolv.c:403
TCP/IP socket address.
Definition tcpip.h:76
Generalized socket address structure.
Definition socket.h:97
struct sockaddr_tcpip peer
Peer address.
Definition tftp.c:128
unsigned int port
Server port.
Definition tftp.c:122
unsigned int flags
Request flags.
Definition tftp.c:130
const char * host
Host name.
Definition uri.h:77

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().

◆ tftp_reopen_mc()

int tftp_reopen_mc ( struct tftp_request * tftp,
struct sockaddr * local )
static

Reopen TFTP multicast socket.

Parameters
tftpTFTP connection
localLocal socket address
Return values
rcReturn status code

Definition at line 254 of file tftp.c.

255 {
256 int rc;
257
258 /* Close multicast socket */
259 intf_restart ( &tftp->mc_socket, 0 );
260
261 /* Open multicast socket. We never send via this socket, so
262 * use the local address as the peer address (since the peer
263 * address cannot be NULL).
264 */
265 if ( ( rc = xfer_open_socket ( &tftp->mc_socket, SOCK_DGRAM,
266 local, local ) ) != 0 ) {
267 DBGC ( tftp, "TFTP %p could not open multicast "
268 "socket: %s\n", tftp, strerror ( rc ) );
269 return rc;
270 }
271
272 return 0;
273}
int xfer_open_socket(struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
Open socket.
Definition open.c:143

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().

◆ tftp_presize()

int tftp_presize ( struct tftp_request * tftp,
size_t filesize )
static

Presize TFTP receive buffers and block bitmap.

Parameters
tftpTFTP connection
filesizeKnown minimum file size
Return values
rcReturn status code

Definition at line 282 of file tftp.c.

282 {
283 unsigned int num_blocks;
284 int rc;
285
286 /* Do nothing if we are already large enough */
287 if ( filesize <= tftp->filesize )
288 return 0;
289
290 /* Record filesize */
291 tftp->filesize = filesize;
292
293 /* Notify recipient of file size */
294 xfer_seek ( &tftp->xfer, filesize );
295 xfer_seek ( &tftp->xfer, 0 );
296
297 /* Calculate expected number of blocks. Note that files whose
298 * length is an exact multiple of the blocksize will have a
299 * trailing zero-length block, which must be included.
300 */
301 if ( tftp->blksize == 0 )
302 return -EINVAL;
303 num_blocks = ( ( filesize / tftp->blksize ) + 1 );
304 if ( ( rc = bitmap_resize ( &tftp->bitmap, num_blocks ) ) != 0 ) {
305 DBGC ( tftp, "TFTP %p could not resize bitmap to %d blocks: "
306 "%s\n", tftp, num_blocks, strerror ( rc ) );
307 return rc;
308 }
309
310 return 0;
311}
int bitmap_resize(struct bitmap *bitmap, unsigned int new_length)
Resize bitmap.
Definition bitmap.c:43
#define EINVAL
Invalid argument.
Definition errno.h:429
unsigned int blksize
Data block size.
Definition tftp.c:109
size_t filesize
Maximum known length.
Definition tftp.c:147
int xfer_seek(struct interface *intf, off_t offset)
Seek to position.
Definition xfer.c:352

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().

◆ tftp_set_mtftp_address()

void tftp_set_mtftp_address ( struct in_addr address)

Set MTFTP multicast address.

Parameters
addressMulticast IPv4 address

Definition at line 329 of file tftp.c.

329 {
330 tftp_mtftp_socket.sin_addr = address;
331}
uint64_t address
Base address.
Definition ena.h:13
static struct sockaddr_in tftp_mtftp_socket
MTFTP multicast receive address.
Definition tftp.c:318

References address, and tftp_mtftp_socket.

◆ tftp_set_mtftp_port()

void tftp_set_mtftp_port ( unsigned int port)

Set MTFTP multicast port.

Parameters
portMulticast port

Definition at line 338 of file tftp.c.

338 {
339 tftp_mtftp_socket.sin_port = htons ( port );
340}
u8 port
Port number.
Definition CIB_PRM.h:3

References htons, port, and tftp_mtftp_socket.

◆ tftp_send_rrq()

int tftp_send_rrq ( struct tftp_request * tftp)
static

Transmit RRQ.

Parameters
tftpTFTP connection
Return values
rcReturn status code

Definition at line 348 of file tftp.c.

348 {
349 const char *path = ( tftp->uri->path + 1 /* skip '/' */ );
350 struct tftp_rrq *rrq;
351 size_t len;
352 struct io_buffer *iobuf;
353 size_t blksize;
354
355 DBGC ( tftp, "TFTP %p requesting \"%s\"\n", tftp, path );
356
357 /* Allocate buffer */
358 len = ( sizeof ( *rrq ) + strlen ( path ) + 1 /* NUL */
359 + 5 + 1 /* "octet" + NUL */
360 + 7 + 1 + 5 + 1 /* "blksize" + NUL + ddddd + NUL */
361 + 5 + 1 + 1 + 1 /* "tsize" + NUL + "0" + NUL */
362 + 9 + 1 + 1 /* "multicast" + NUL + NUL */ );
363 iobuf = xfer_alloc_iob ( &tftp->socket, len );
364 if ( ! iobuf )
365 return -ENOMEM;
366
367 /* Determine block size */
368 blksize = xfer_window ( &tftp->xfer );
371
372 /* Build request */
373 rrq = iob_put ( iobuf, sizeof ( *rrq ) );
374 rrq->opcode = htons ( TFTP_RRQ );
375 iob_put ( iobuf, snprintf ( iobuf->tail, iob_tailroom ( iobuf ),
376 "%s%coctet", path, 0 ) + 1 );
377 if ( tftp->flags & TFTP_FL_RRQ_SIZES ) {
378 iob_put ( iobuf, snprintf ( iobuf->tail,
379 iob_tailroom ( iobuf ),
380 "blksize%c%zd%ctsize%c0",
381 0, blksize, 0, 0 ) + 1 );
382 }
383 if ( tftp->flags & TFTP_FL_RRQ_MULTICAST ) {
384 iob_put ( iobuf, snprintf ( iobuf->tail,
385 iob_tailroom ( iobuf ),
386 "multicast%c", 0 ) + 1 );
387 }
388
389 /* RRQ always goes to the address specified in the initial
390 * xfer_open() call
391 */
392 return xfer_deliver_iob ( &tftp->socket, iobuf );
393}
ring len
Length.
Definition dwmac.h:226
#define ENOMEM
Not enough space.
Definition errno.h:535
#define iob_put(iobuf, len)
Definition iobuf.h:125
static size_t iob_tailroom(struct io_buffer *iobuf)
Calculate available space at end of an I/O buffer.
Definition iobuf.h:180
uint32_t blksize
Cipher block size.
Definition pccrr.h:1
size_t strlen(const char *src)
Get length of string.
Definition string.c:244
A persistent I/O buffer.
Definition iobuf.h:38
void * tail
End of data.
Definition iobuf.h:55
A TFTP read request (RRQ) packet.
Definition tftp.h:38
uint16_t opcode
Definition tftp.h:39
const char * path
Path (after URI decoding)
Definition uri.h:81
#define TFTP_MAX_BLKSIZE
Definition tftp.h:17
#define TFTP_RRQ
Read request opcode.
Definition tftp.h:19
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition xfer.c:117
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
Definition xfer.c:159
int xfer_deliver_iob(struct interface *intf, struct io_buffer *iobuf)
Deliver datagram as I/O buffer without metadata.
Definition xfer.c:256

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().

◆ tftp_send_ack()

int tftp_send_ack ( struct tftp_request * tftp)
static

Transmit ACK.

Parameters
tftpTFTP connection
Return values
rcReturn status code

Definition at line 401 of file tftp.c.

401 {
402 struct tftp_ack *ack;
403 struct io_buffer *iobuf;
404 struct xfer_metadata meta = {
405 .dest = ( struct sockaddr * ) &tftp->peer,
406 };
407 unsigned int block;
408
409 /* Determine next required block number */
410 block = bitmap_first_gap ( &tftp->bitmap );
411 DBGC2 ( tftp, "TFTP %p sending ACK for block %d\n", tftp, block );
412
413 /* Allocate buffer */
414 iobuf = xfer_alloc_iob ( &tftp->socket, sizeof ( *ack ) );
415 if ( ! iobuf )
416 return -ENOMEM;
417
418 /* Build ACK */
419 ack = iob_put ( iobuf, sizeof ( *ack ) );
420 ack->opcode = htons ( TFTP_ACK );
421 ack->block = htons ( block );
422
423 /* ACK always goes to the peer recorded from the RRQ response */
424 return xfer_deliver ( &tftp->socket, iobuf, &meta );
425}
static unsigned int bitmap_first_gap(struct bitmap *bitmap)
Get first gap within bitmap.
Definition bitmap.h:70
uint8_t meta
Metadata flags.
Definition ena.h:3
#define DBGC2(...)
Definition compiler.h:522
uint8_t block[3][8]
DES-encrypted blocks.
Definition mschapv2.h:1
A TFTP acknowledgement (ACK) packet.
Definition tftp.h:51
uint16_t block
Definition tftp.h:53
uint16_t opcode
Definition tftp.h:52
Data transfer metadata.
Definition xfer.h:23
#define TFTP_ACK
Data block acknowledgement opcode.
Definition tftp.h:22
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition xfer.c:195

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().

◆ tftp_send_error()

int tftp_send_error ( struct tftp_request * tftp,
int errcode,
const char * errmsg )
static

Transmit ERROR (Abort)

Parameters
tftpTFTP connection
errcodeTFTP error code
errmsgError message string
Return values
rcReturn status code

Definition at line 435 of file tftp.c.

436 {
437 struct tftp_error *err;
438 struct io_buffer *iobuf;
439 struct xfer_metadata meta = {
440 .dest = ( struct sockaddr * ) &tftp->peer,
441 };
442 size_t msglen;
443
444 DBGC2 ( tftp, "TFTP %p sending ERROR %d: %s\n", tftp, errcode,
445 errmsg );
446
447 /* Allocate buffer */
448 msglen = sizeof ( *err ) + strlen ( errmsg ) + 1 /* NUL */;
449 iobuf = xfer_alloc_iob ( &tftp->socket, msglen );
450 if ( ! iobuf )
451 return -ENOMEM;
452
453 /* Build ERROR */
454 err = iob_put ( iobuf, msglen );
455 err->opcode = htons ( TFTP_ERROR );
456 err->errcode = htons ( errcode );
457 strcpy ( err->errmsg, errmsg );
458
459 /* ERR always goes to the peer recorded from the RRQ response */
460 return xfer_deliver ( &tftp->socket, iobuf, &meta );
461}
char * strcpy(char *dest, const char *src)
Copy string.
Definition string.c:347
A TFTP error (ERROR) packet.
Definition tftp.h:57
char errmsg[0]
Definition tftp.h:60
uint16_t errcode
Definition tftp.h:59
uint16_t opcode
Definition tftp.h:58
char errmsg[0]
Definition tftp.h:2
#define TFTP_ERROR
Error opcode.
Definition tftp.h:23
uint16_t errcode
Definition tftp.h:1

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().

◆ tftp_send_packet()

int tftp_send_packet ( struct tftp_request * tftp)
static

Transmit next relevant packet.

Parameters
tftpTFTP connection
Return values
rcReturn status code

Definition at line 469 of file tftp.c.

469 {
470
471 /* Update retransmission timer. While name resolution takes place the
472 * window is zero. Avoid unnecessary delay after name resolution
473 * completes by retrying immediately.
474 */
475 stop_timer ( &tftp->timer );
476 if ( xfer_window ( &tftp->socket ) ) {
477 start_timer ( &tftp->timer );
478 } else {
479 start_timer_nodelay ( &tftp->timer );
480 }
481
482 /* Send RRQ or ACK as appropriate */
483 if ( ! tftp->peer.st_family ) {
484 return tftp_send_rrq ( tftp );
485 } else {
486 if ( tftp->flags & TFTP_FL_SEND_ACK ) {
487 return tftp_send_ack ( tftp );
488 } else {
489 return 0;
490 }
491 }
492}
void start_timer(struct retry_timer *timer)
Start timer.
Definition retry.c:94
static void start_timer_nodelay(struct retry_timer *timer)
Start timer with no delay.
Definition retry.h:100
sa_family_t st_family
Socket address family (part of struct sockaddr)
Definition tcpip.h:78
static int tftp_send_rrq(struct tftp_request *tftp)
Transmit RRQ.
Definition tftp.c:348
static int tftp_send_ack(struct tftp_request *tftp)
Transmit ACK.
Definition tftp.c:401

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().

◆ tftp_timer_expired()

void tftp_timer_expired ( struct retry_timer * timer,
int fail )
static

Handle TFTP retransmission timer expiry.

Parameters
timerRetry timer
failFailure indicator

Definition at line 500 of file tftp.c.

500 {
501 struct tftp_request *tftp =
503 int rc;
504
505 /* If we are doing MTFTP, attempt the various recovery strategies */
506 if ( tftp->flags & TFTP_FL_MTFTP_RECOVERY ) {
507 if ( tftp->peer.st_family ) {
508 /* If we have received any response from the server,
509 * try resending the RRQ to restart the download.
510 */
511 DBGC ( tftp, "TFTP %p attempting reopen\n", tftp );
512 if ( ( rc = tftp_reopen ( tftp ) ) != 0 )
513 goto err;
514 } else {
515 /* Fall back to plain TFTP after several attempts */
516 tftp->mtftp_timeouts++;
517 DBGC ( tftp, "TFTP %p timeout %d waiting for MTFTP "
518 "open\n", tftp, tftp->mtftp_timeouts );
519
520 if ( tftp->mtftp_timeouts > MTFTP_MAX_TIMEOUTS ) {
521 DBGC ( tftp, "TFTP %p falling back to plain "
522 "TFTP\n", tftp );
523 tftp->flags = TFTP_FL_RRQ_SIZES;
524
525 /* Close multicast socket */
526 intf_restart ( &tftp->mc_socket, 0 );
527
528 /* Reset retry timer */
529 start_timer_nodelay ( &tftp->timer );
530
531 /* The blocksize may change: discard
532 * the block bitmap
533 */
534 bitmap_free ( &tftp->bitmap );
535 memset ( &tftp->bitmap, 0,
536 sizeof ( tftp->bitmap ) );
537
538 /* Reopen on standard TFTP port */
539 tftp->port = TFTP_PORT;
540 if ( ( rc = tftp_reopen ( tftp ) ) != 0 )
541 goto err;
542 }
543 }
544 } else {
545 /* Not doing MTFTP (or have fallen back to plain
546 * TFTP); fail as per normal.
547 */
548 if ( fail ) {
549 rc = -ETIMEDOUT;
550 goto err;
551 }
552 }
553 tftp_send_packet ( tftp );
554 return;
555
556 err:
557 tftp_done ( tftp, rc );
558}
#define ETIMEDOUT
Connection timed out.
Definition errno.h:670
unsigned int mtftp_timeouts
MTFTP timeout count.
Definition tftp.c:132
A timer.
Definition timer.h:29
static int tftp_reopen(struct tftp_request *tftp)
Reopen TFTP socket.
Definition tftp.c:220
#define MTFTP_MAX_TIMEOUTS
Maximum number of MTFTP open requests before falling back to TFTP.
Definition tftp.c:165
static void tftp_done(struct tftp_request *tftp, int rc)
Mark TFTP request as complete.
Definition tftp.c:200
static int tftp_send_packet(struct tftp_request *tftp)
Transmit next relevant packet.
Definition tftp.c:469
#define TFTP_PORT
Default TFTP server port.
Definition tftp.h:15

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().

◆ tftp_process_blksize()

int tftp_process_blksize ( struct tftp_request * tftp,
char * value )
static

Process TFTP "blksize" option.

Parameters
tftpTFTP connection
valueOption value
Return values
rcReturn status code

Definition at line 567 of file tftp.c.

567 {
568 char *end;
569
570 tftp->blksize = strtoul ( value, &end, 10 );
571 if ( *end ) {
572 DBGC ( tftp, "TFTP %p got invalid blksize \"%s\"\n",
573 tftp, value );
574 return -EINVAL_BLKSIZE;
575 }
576 DBGC ( tftp, "TFTP %p blksize=%d\n", tftp, tftp->blksize );
577
578 return 0;
579}
pseudo_bit_t value[0x00020]
Definition arbel.h:2
uint32_t end
Ending offset.
Definition netvsc.h:7
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition string.c:485
#define EINVAL_BLKSIZE
Definition tftp.c:60

References tftp_request::blksize, DBGC, EINVAL_BLKSIZE, end, strtoul(), and value.

◆ tftp_process_tsize()

int tftp_process_tsize ( struct tftp_request * tftp,
char * value )
static

Process TFTP "tsize" option.

Parameters
tftpTFTP connection
valueOption value
Return values
rcReturn status code

Definition at line 588 of file tftp.c.

588 {
589 char *end;
590
591 tftp->tsize = strtoul ( value, &end, 10 );
592 if ( *end ) {
593 DBGC ( tftp, "TFTP %p got invalid tsize \"%s\"\n",
594 tftp, value );
595 return -EINVAL_TSIZE;
596 }
597 DBGC ( tftp, "TFTP %p tsize=%ld\n", tftp, tftp->tsize );
598
599 return 0;
600}
unsigned long tsize
File size.
Definition tftp.c:116
#define EINVAL_TSIZE
Definition tftp.c:63

References DBGC, EINVAL_TSIZE, end, strtoul(), tftp_request::tsize, and value.

◆ tftp_process_multicast()

int tftp_process_multicast ( struct tftp_request * tftp,
char * value )
static

Process TFTP "multicast" option.

Parameters
tftpTFTP connection
valueOption value
Return values
rcReturn status code

Definition at line 609 of file tftp.c.

609 {
610 union {
611 struct sockaddr sa;
612 struct sockaddr_in sin;
613 } socket;
614 char *addr;
615 char *port;
616 char *port_end;
617 char *mc;
618 char *mc_end;
619 int rc;
620
621 /* Split value into "addr,port,mc" fields */
622 addr = value;
623 port = strchr ( addr, ',' );
624 if ( ! port ) {
625 DBGC ( tftp, "TFTP %p multicast missing port,mc\n", tftp );
626 return -EINVAL_MC_NO_PORT;
627 }
628 *(port++) = '\0';
629 mc = strchr ( port, ',' );
630 if ( ! mc ) {
631 DBGC ( tftp, "TFTP %p multicast missing mc\n", tftp );
632 return -EINVAL_MC_NO_MC;
633 }
634 *(mc++) = '\0';
635
636 /* Parse parameters */
637 if ( strtoul ( mc, &mc_end, 0 ) == 0 )
638 tftp->flags &= ~TFTP_FL_SEND_ACK;
639 if ( *mc_end ) {
640 DBGC ( tftp, "TFTP %p multicast invalid mc %s\n", tftp, mc );
641 return -EINVAL_MC_INVALID_MC;
642 }
643 DBGC ( tftp, "TFTP %p is%s the master client\n",
644 tftp, ( ( tftp->flags & TFTP_FL_SEND_ACK ) ? "" : " not" ) );
645 if ( *addr && *port ) {
646 socket.sin.sin_family = AF_INET;
647 if ( inet_aton ( addr, &socket.sin.sin_addr ) == 0 ) {
648 DBGC ( tftp, "TFTP %p multicast invalid IP address "
649 "%s\n", tftp, addr );
650 return -EINVAL_MC_INVALID_IP;
651 }
652 DBGC ( tftp, "TFTP %p multicast IP address %s\n",
653 tftp, inet_ntoa ( socket.sin.sin_addr ) );
654 socket.sin.sin_port = htons ( strtoul ( port, &port_end, 0 ) );
655 if ( *port_end ) {
656 DBGC ( tftp, "TFTP %p multicast invalid port %s\n",
657 tftp, port );
659 }
660 DBGC ( tftp, "TFTP %p multicast port %d\n",
661 tftp, ntohs ( socket.sin.sin_port ) );
662 if ( ( rc = tftp_reopen_mc ( tftp, &socket.sa ) ) != 0 )
663 return rc;
664 }
665
666 return 0;
667}
uint32_t addr
Buffer address.
Definition dwmac.h:9
#define AF_INET
IPv4 Internet addresses.
Definition socket.h:64
#define ntohs(value)
Definition byteswap.h:137
char * inet_ntoa(struct in_addr in)
Convert IPv4 address to dotted-quad notation.
Definition ipv4.c:814
int inet_aton(const char *string, struct in_addr *in)
Parse IPv4 address.
Definition ipv4.c:787
char * strchr(const char *src, int character)
Find character within a string.
Definition string.c:272
IPv4 socket address.
Definition in.h:85
struct sockaddr sa
Definition syslog.c:57
struct sockaddr_in sin
Definition syslog.c:59
#define EINVAL_MC_NO_PORT
Definition tftp.c:66
#define EINVAL_MC_INVALID_MC
Definition tftp.c:72
#define EINVAL_MC_INVALID_PORT
Definition tftp.c:78
static int tftp_reopen_mc(struct tftp_request *tftp, struct sockaddr *local)
Reopen TFTP multicast socket.
Definition tftp.c:254
#define EINVAL_MC_INVALID_IP
Definition tftp.c:75
#define EINVAL_MC_NO_MC
Definition tftp.c:69

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.

◆ tftp_process_option()

int tftp_process_option ( struct tftp_request * tftp,
const char * name,
char * value )
static

Process TFTP option.

Parameters
tftpTFTP connection
nameOption name
valueOption value
Return values
rcReturn status code

Definition at line 698 of file tftp.c.

699 {
700 struct tftp_option *option;
701
702 for ( option = tftp_options ; option->name ; option++ ) {
703 if ( strcasecmp ( name, option->name ) == 0 )
704 return option->process ( tftp, value );
705 }
706
707 DBGC ( tftp, "TFTP %p received unknown option \"%s\" = \"%s\"\n",
708 tftp, name, value );
709
710 /* Unknown options should be silently ignored */
711 return 0;
712}
const char * name
Definition ath9k_hw.c:1986
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition string.c:209
A long option, as used for getopt_long()
Definition getopt.h:25
const char * name
Long name of this option.
Definition getopt.h:27
A TFTP option.
Definition tftp.c:670
static struct tftp_option tftp_options[]
Recognised TFTP options.
Definition tftp.c:683

References DBGC, name, option::name, strcasecmp(), tftp_options, and value.

Referenced by tftp_rx_oack().

◆ tftp_rx_oack()

int tftp_rx_oack ( struct tftp_request * tftp,
void * buf,
size_t len )
static

Receive OACK.

Parameters
tftpTFTP connection
bufTemporary data buffer
lenLength of temporary data buffer
Return values
rcReturn status code

Definition at line 722 of file tftp.c.

722 {
723 struct tftp_oack *oack = buf;
724 char *end = buf + len;
725 char *name;
726 char *value;
727 char *next;
728 int rc = 0;
729
730 /* Sanity check */
731 if ( len < sizeof ( *oack ) ) {
732 DBGC ( tftp, "TFTP %p received underlength OACK packet "
733 "length %zd\n", tftp, len );
734 rc = -EINVAL;
735 goto done;
736 }
737
738 /* Process each option in turn */
739 for ( name = oack->data ; name < end ; name = next ) {
740
741 /* Parse option name and value
742 *
743 * We treat parsing errors as non-fatal, because there
744 * exists at least one TFTP server (IBM Tivoli PXE
745 * Server 5.1.0.3) that has been observed to send
746 * malformed OACKs containing trailing garbage bytes.
747 */
748 value = ( name + strnlen ( name, ( end - name ) ) + 1 );
749 if ( value > end ) {
750 DBGC ( tftp, "TFTP %p received OACK with malformed "
751 "option name:\n", tftp );
752 DBGC_HD ( tftp, oack, len );
753 break;
754 }
755 if ( value == end ) {
756 DBGC ( tftp, "TFTP %p received OACK missing value "
757 "for option \"%s\"\n", tftp, name );
758 DBGC_HD ( tftp, oack, len );
759 break;
760 }
761 next = ( value + strnlen ( value, ( end - value ) ) + 1 );
762 if ( next > end ) {
763 DBGC ( tftp, "TFTP %p received OACK with malformed "
764 "value for option \"%s\":\n", tftp, name );
765 DBGC_HD ( tftp, oack, len );
766 break;
767 }
768
769 /* Process option */
770 if ( ( rc = tftp_process_option ( tftp, name, value ) ) != 0 )
771 goto done;
772 }
773
774 /* Process tsize information, if available */
775 if ( tftp->tsize ) {
776 if ( ( rc = tftp_presize ( tftp, tftp->tsize ) ) != 0 )
777 goto done;
778 }
779
780 /* Request next data block */
781 tftp_send_packet ( tftp );
782
783 done:
784 if ( rc )
785 tftp_done ( tftp, rc );
786 return rc;
787}
struct bofm_section_header done
Definition bofm_test.c:46
uint32_t next
Next descriptor address.
Definition dwmac.h:11
#define DBGC_HD(...)
Definition compiler.h:507
size_t strnlen(const char *src, size_t max)
Get length of string.
Definition string.c:256
A TFTP options acknowledgement (OACK) packet.
Definition tftp.h:64
char data[0]
Definition tftp.h:66
static int tftp_presize(struct tftp_request *tftp, size_t filesize)
Presize TFTP receive buffers and block bitmap.
Definition tftp.c:282
static int tftp_process_option(struct tftp_request *tftp, const char *name, char *value)
Process TFTP option.
Definition tftp.c:698

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().

◆ tftp_rx_data()

int tftp_rx_data ( struct tftp_request * tftp,
struct io_buffer * iobuf )
static

Receive DATA.

Parameters
tftpTFTP connection
iobufI/O buffer
Return values
rcReturn status code

Takes ownership of I/O buffer.

Definition at line 798 of file tftp.c.

799 {
800 struct tftp_data *data = iobuf->data;
801 struct xfer_metadata meta;
802 unsigned int block;
804 size_t data_len;
805 int rc;
806
807 /* Sanity check */
808 if ( iob_len ( iobuf ) < sizeof ( *data ) ) {
809 DBGC ( tftp, "TFTP %p received underlength DATA packet "
810 "length %zd\n", tftp, iob_len ( iobuf ) );
811 rc = -EINVAL;
812 goto done;
813 }
814
815 /* Calculate block number */
816 block = ( ( bitmap_first_gap ( &tftp->bitmap ) + 1 ) & ~0xffff );
817 if ( data->block == 0 && block == 0 ) {
818 DBGC ( tftp, "TFTP %p received data block 0\n", tftp );
819 rc = -EINVAL;
820 goto done;
821 }
822 block += ( ntohs ( data->block ) - 1 );
823
824 /* Stop profiling server turnaround if applicable */
825 if ( block )
826 profile_stop ( &tftp_server_profiler );
827
828 /* Extract data */
829 offset = ( block * tftp->blksize );
830 iob_pull ( iobuf, sizeof ( *data ) );
831 data_len = iob_len ( iobuf );
832 if ( data_len > tftp->blksize ) {
833 DBGC ( tftp, "TFTP %p received overlength DATA packet "
834 "length %zd\n", tftp, data_len );
835 rc = -EINVAL;
836 goto done;
837 }
838
839 /* Deliver data */
840 memset ( &meta, 0, sizeof ( meta ) );
841 meta.flags = XFER_FL_ABS_OFFSET;
842 meta.offset = offset;
843 if ( ( rc = xfer_deliver ( &tftp->xfer, iob_disown ( iobuf ),
844 &meta ) ) != 0 ) {
845 DBGC ( tftp, "TFTP %p could not deliver data: %s\n",
846 tftp, strerror ( rc ) );
847 goto done;
848 }
849
850 /* Ensure block bitmap is ready */
851 if ( ( rc = tftp_presize ( tftp, ( offset + data_len ) ) ) != 0 )
852 goto done;
853
854 /* Mark block as received */
855 bitmap_set ( &tftp->bitmap, block );
856
857 /* Acknowledge block */
858 tftp_send_packet ( tftp );
859
860 /* Stop profiling client turnaround */
861 profile_stop ( &tftp_client_profiler );
862
863 /* Start profiling server turnaround */
864 profile_start ( &tftp_server_profiler );
865
866 /* If all blocks have been received, finish. */
867 if ( bitmap_full ( &tftp->bitmap ) )
868 tftp_done ( tftp, 0 );
869
870 done:
871 free_iob ( iobuf );
872 if ( rc )
873 tftp_done ( tftp, rc );
874 return rc;
875}
signed long off_t
Definition stdint.h:8
void bitmap_set(struct bitmap *bitmap, unsigned int bit)
Set bit in bitmap.
Definition bitmap.c:94
static int bitmap_full(struct bitmap *bitmap)
Check to see if bitmap is full.
Definition bitmap.h:82
uint16_t offset
Offset to command line.
Definition bzimage.h:3
uint8_t data[48]
Additional event data.
Definition ena.h:11
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition profile.h:174
static void profile_start(struct profiler *profiler)
Start profiling.
Definition profile.h:161
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition iobuf.h:217
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:160
#define iob_pull(iobuf, len)
Definition iobuf.h:107
void * data
Start of data.
Definition iobuf.h:53
A TFTP data (DATA) packet.
Definition tftp.h:44
uint32_t data_len
Microcode data size (or 0 to indicate 2000 bytes)
Definition ucode.h:15
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition xfer.h:48

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().

◆ tftp_errcode_to_rc()

int tftp_errcode_to_rc ( unsigned int errcode)
static

Convert TFTP error code to return status code.

Parameters
errcodeTFTP error code
Return values
rcReturn status code

Definition at line 883 of file tftp.c.

883 {
884 switch ( errcode ) {
886 case TFTP_ERR_ACCESS_DENIED: return -EACCES;
887 case TFTP_ERR_ILLEGAL_OP: return -ENOTTY;
888 default: return -ENOTSUP;
889 }
890}
#define ENOTSUP
Operation not supported.
Definition errno.h:590
#define EACCES
Permission denied.
Definition errno.h:299
#define ENOTTY
Inappropriate I/O control operation.
Definition errno.h:595
#define ENOENT_NOT_FOUND
Definition tftp.c:81
#define TFTP_ERR_ACCESS_DENIED
Access violation.
Definition tftp.h:27
#define TFTP_ERR_ILLEGAL_OP
Illegal TFTP operation.
Definition tftp.h:29
#define TFTP_ERR_FILE_NOT_FOUND
File not found.
Definition tftp.h:26

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().

◆ tftp_rx_error()

int tftp_rx_error ( struct tftp_request * tftp,
void * buf,
size_t len )
static

Receive ERROR.

Parameters
tftpTFTP connection
bufTemporary data buffer
lenLength of temporary data buffer
Return values
rcReturn status code

Definition at line 900 of file tftp.c.

900 {
901 struct tftp_error *error = buf;
902 int rc;
903
904 /* Sanity check */
905 if ( len < sizeof ( *error ) ) {
906 DBGC ( tftp, "TFTP %p received underlength ERROR packet "
907 "length %zd\n", tftp, len );
908 return -EINVAL;
909 }
910
911 DBGC ( tftp, "TFTP %p received ERROR packet with code %d, message "
912 "\"%s\"\n", tftp, ntohs ( error->errcode ), error->errmsg );
913
914 /* Determine final operation result */
915 rc = tftp_errcode_to_rc ( ntohs ( error->errcode ) );
916
917 /* Close TFTP request */
918 tftp_done ( tftp, rc );
919
920 return 0;
921}
struct arbelprm_completion_with_error error
Definition arbel.h:1
static int tftp_errcode_to_rc(unsigned int errcode)
Convert TFTP error code to return status code.
Definition tftp.c:883

References DBGC, EINVAL, error, len, ntohs, rc, tftp_done(), and tftp_errcode_to_rc().

Referenced by tftp_rx().

◆ tftp_rx()

int tftp_rx ( struct tftp_request * tftp,
struct io_buffer * iobuf,
struct xfer_metadata * meta )
static

Receive new data.

Parameters
tftpTFTP connection
iobufI/O buffer
metaTransfer metadata
Return values
rcReturn status code

Definition at line 931 of file tftp.c.

933 {
934 struct sockaddr_tcpip *st_src;
935 struct tftp_common *common = iobuf->data;
936 size_t len = iob_len ( iobuf );
937 int rc = -EINVAL;
938
939 /* Start profiling client turnaround */
940 profile_start ( &tftp_client_profiler );
941
942 /* Sanity checks */
943 if ( len < sizeof ( *common ) ) {
944 DBGC ( tftp, "TFTP %p received underlength packet length "
945 "%zd\n", tftp, len );
946 goto done;
947 }
948 if ( ! meta->src ) {
949 DBGC ( tftp, "TFTP %p received packet without source port\n",
950 tftp );
951 goto done;
952 }
953
954 /* Filter by TID. Set TID on first response received */
955 st_src = ( struct sockaddr_tcpip * ) meta->src;
956 if ( ! tftp->peer.st_family ) {
957 memcpy ( &tftp->peer, st_src, sizeof ( tftp->peer ) );
958 DBGC ( tftp, "TFTP %p using remote port %d\n", tftp,
959 ntohs ( tftp->peer.st_port ) );
960 } else if ( memcmp ( &tftp->peer, st_src,
961 sizeof ( tftp->peer ) ) != 0 ) {
962 DBGC ( tftp, "TFTP %p received packet from wrong source (got "
963 "%d, wanted %d)\n", tftp, ntohs ( st_src->st_port ),
964 ntohs ( tftp->peer.st_port ) );
965 goto done;
966 }
967
968 switch ( common->opcode ) {
969 case htons ( TFTP_OACK ):
970 rc = tftp_rx_oack ( tftp, iobuf->data, len );
971 break;
972 case htons ( TFTP_DATA ):
973 rc = tftp_rx_data ( tftp, iob_disown ( iobuf ) );
974 break;
975 case htons ( TFTP_ERROR ):
976 rc = tftp_rx_error ( tftp, iobuf->data, len );
977 break;
978 default:
979 DBGC ( tftp, "TFTP %p received strange packet type %d\n",
980 tftp, ntohs ( common->opcode ) );
981 break;
982 };
983
984 done:
985 free_iob ( iobuf );
986 return rc;
987}
struct ib_cm_common common
Definition ib_mad.h:0
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
uint16_t st_port
TCP/IP port.
Definition tcpip.h:82
The common header of all TFTP packets.
Definition tftp.h:70
static int tftp_rx_oack(struct tftp_request *tftp, void *buf, size_t len)
Receive OACK.
Definition tftp.c:722
static int tftp_rx_data(struct tftp_request *tftp, struct io_buffer *iobuf)
Receive DATA.
Definition tftp.c:798
static int tftp_rx_error(struct tftp_request *tftp, void *buf, size_t len)
Receive ERROR.
Definition tftp.c:900
#define TFTP_DATA
Data block opcode.
Definition tftp.h:21
#define TFTP_OACK
Options acknowledgement opcode.
Definition tftp.h:24

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().

◆ tftp_socket_deliver()

int tftp_socket_deliver ( struct tftp_request * tftp,
struct io_buffer * iobuf,
struct xfer_metadata * meta )
static

Receive new data via socket.

Parameters
tftpTFTP connection
iobufI/O buffer
metaTransfer metadata
Return values
rcReturn status code

Definition at line 997 of file tftp.c.

999 {
1000
1001 /* Enable sending ACKs when we receive a unicast packet. This
1002 * covers three cases:
1003 *
1004 * 1. Standard TFTP; we should always send ACKs, and will
1005 * always receive a unicast packet before we need to send the
1006 * first ACK.
1007 *
1008 * 2. RFC2090 multicast TFTP; the only unicast packets we will
1009 * receive are the OACKs; enable sending ACKs here (before
1010 * processing the OACK) and disable it when processing the
1011 * multicast option if we are not the master client.
1012 *
1013 * 3. MTFTP; receiving a unicast datagram indicates that we
1014 * are the "master client" and should send ACKs.
1015 */
1016 tftp->flags |= TFTP_FL_SEND_ACK;
1017
1018 return tftp_rx ( tftp, iobuf, meta );
1019}
static int tftp_rx(struct tftp_request *tftp, struct io_buffer *iobuf, struct xfer_metadata *meta)
Receive new data.
Definition tftp.c:931

References tftp_request::flags, meta, TFTP_FL_SEND_ACK, and tftp_rx().

◆ tftp_xfer_window()

size_t tftp_xfer_window ( struct tftp_request * tftp)
static

Check flow control window.

Parameters
tftpTFTP connection
Return values
lenLength of window

Definition at line 1045 of file tftp.c.

1045 {
1046
1047 /* We abuse this data-xfer method to convey the blocksize to
1048 * the caller. This really should be done using some kind of
1049 * stat() method, but we don't yet have the facility to do
1050 * that.
1051 */
1052 return tftp->blksize;
1053}

References tftp_request::blksize.

◆ tftp_close()

void tftp_close ( struct tftp_request * tftp,
int rc )
static

Terminate download.

Parameters
tftpTFTP connection
rcReason for close

Definition at line 1061 of file tftp.c.

1061 {
1062
1063 /* Abort download */
1064 tftp_send_error ( tftp, 0, "TFTP Aborted" );
1065
1066 /* Close TFTP request */
1067 tftp_done ( tftp, rc );
1068}
static int tftp_send_error(struct tftp_request *tftp, int errcode, const char *errmsg)
Transmit ERROR (Abort)
Definition tftp.c:435

References rc, tftp_done(), and tftp_send_error().

Referenced by pxenv_tftp_close().

◆ tftp_core_open()

int tftp_core_open ( struct interface * xfer,
struct uri * uri,
unsigned int default_port,
struct sockaddr * multicast,
unsigned int flags )
static

Initiate TFTP/TFTM/MTFTP download.

Parameters
xferData transfer interface
uriUniform Resource Identifier
Return values
rcReturn status code

Definition at line 1087 of file tftp.c.

1090 {
1091 struct tftp_request *tftp;
1092 int rc;
1093
1094 /* Sanity checks */
1095 if ( ! uri->host )
1096 return -EINVAL;
1097 if ( ! uri->path )
1098 return -EINVAL;
1099 if ( uri->path[0] != '/' )
1100 return -EINVAL;
1101
1102 /* Allocate and populate TFTP structure */
1103 tftp = zalloc ( sizeof ( *tftp ) );
1104 if ( ! tftp )
1105 return -ENOMEM;
1106 ref_init ( &tftp->refcnt, tftp_free );
1107 intf_init ( &tftp->xfer, &tftp_xfer_desc, &tftp->refcnt );
1108 intf_init ( &tftp->socket, &tftp_socket_desc, &tftp->refcnt );
1109 intf_init ( &tftp->mc_socket, &tftp_mc_socket_desc, &tftp->refcnt );
1110 timer_init ( &tftp->timer, tftp_timer_expired, &tftp->refcnt );
1111 tftp->uri = uri_get ( uri );
1113 tftp->flags = flags;
1114
1115 /* Open socket */
1116 tftp->port = uri_port ( tftp->uri, default_port );
1117 if ( ( rc = tftp_reopen ( tftp ) ) != 0 )
1118 goto err;
1119
1120 /* Open multicast socket */
1121 if ( multicast ) {
1122 if ( ( rc = tftp_reopen_mc ( tftp, multicast ) ) != 0 )
1123 goto err;
1124 }
1125
1126 /* Start timer to initiate RRQ */
1127 start_timer_nodelay ( &tftp->timer );
1128
1129 /* Attach to parent interface, mortalise self, and return */
1130 intf_plug_plug ( &tftp->xfer, xfer );
1131 ref_put ( &tftp->refcnt );
1132 return 0;
1133
1134 err:
1135 DBGC ( tftp, "TFTP %p could not create request: %s\n",
1136 tftp, strerror ( rc ) );
1137 tftp_done ( tftp, rc );
1138 ref_put ( &tftp->refcnt );
1139 return rc;
1140}
uint8_t flags
Flags.
Definition ena.h:7
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition interface.c:108
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition refcnt.h:65
struct refcnt refcnt
Reference count.
Definition tftp.c:92
A Uniform Resource Identifier.
Definition uri.h:65
static struct interface_descriptor tftp_xfer_desc
TFTP data transfer interface descriptor.
Definition tftp.c:1077
static void tftp_free(struct refcnt *refcnt)
Free TFTP request.
Definition tftp.c:185
static void tftp_timer_expired(struct retry_timer *timer, int fail)
Handle TFTP retransmission timer expiry.
Definition tftp.c:500
static struct interface_descriptor tftp_socket_desc
TFTP socket interface descriptor.
Definition tftp.c:1027
static struct interface_descriptor tftp_mc_socket_desc
TFTP multicast socket interface descriptor.
Definition tftp.c:1036
#define TFTP_DEFAULT_BLKSIZE
Default TFTP data block size.
Definition tftp.h:16
unsigned int uri_port(const struct uri *uri, unsigned int default_port)
Get port from URI.
Definition uri.c:457
static struct uri * uri_get(struct uri *uri)
Increment URI reference count.
Definition uri.h:195

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().

◆ tftp_open()

int tftp_open ( struct interface * xfer,
struct uri * uri )
static

Initiate TFTP download.

Parameters
xferData transfer interface
uriUniform Resource Identifier
Return values
rcReturn status code

Definition at line 1149 of file tftp.c.

1149 {
1150 return tftp_core_open ( xfer, uri, TFTP_PORT, NULL,
1152
1153}
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.
Definition tftp.c:1087

References NULL, tftp_core_open(), TFTP_FL_RRQ_SIZES, TFTP_PORT, and tftp_request::xfer.

Referenced by pxenv_tftp_open().

◆ tftm_open()

int tftm_open ( struct interface * xfer,
struct uri * uri )
static

Initiate TFTM download.

Parameters
xferData transfer interface
uriUniform Resource Identifier
Return values
rcReturn status code

Definition at line 1168 of file tftp.c.

1168 {
1169 return tftp_core_open ( xfer, uri, TFTP_PORT, NULL,
1172
1173}

References NULL, tftp_core_open(), TFTP_FL_RRQ_MULTICAST, TFTP_FL_RRQ_SIZES, and TFTP_PORT.

◆ mtftp_open()

int mtftp_open ( struct interface * xfer,
struct uri * uri )
static

Initiate MTFTP download.

Parameters
xferData transfer interface
uriUniform Resource Identifier
Return values
rcReturn status code

Definition at line 1188 of file tftp.c.

1188 {
1189 return tftp_core_open ( xfer, uri, MTFTP_PORT,
1190 ( struct sockaddr * ) &tftp_mtftp_socket,
1192}
#define MTFTP_PORT
Default MTFTP server port.
Definition tftp.h:35

References MTFTP_PORT, tftp_core_open(), TFTP_FL_MTFTP_RECOVERY, and tftp_mtftp_socket.

◆ tftp_apply_settings()

int tftp_apply_settings ( void )
static

Apply TFTP configuration settings.

Return values
rcReturn status code

Definition at line 1212 of file tftp.c.

1212 {
1213 static struct in_addr tftp_server = { 0 };
1214 struct in_addr new_tftp_server;
1215 char uri_string[32];
1216 struct uri *uri;
1217
1218 /* Retrieve TFTP server setting */
1219 fetch_ipv4_setting ( NULL, &next_server_setting, &new_tftp_server );
1220
1221 /* If TFTP server setting has changed, set the current working
1222 * URI to match. Do it only when the TFTP server has changed
1223 * to try to minimise surprises to the user, who probably
1224 * won't expect the CWURI to change just because they updated
1225 * an unrelated setting and triggered all the settings
1226 * applicators.
1227 */
1228 if ( new_tftp_server.s_addr &&
1229 ( new_tftp_server.s_addr != tftp_server.s_addr ) ) {
1230 DBGC ( &tftp_server, "TFTP server changed %s => ",
1231 inet_ntoa ( tftp_server ) );
1232 DBGC ( &tftp_server, "%s\n", inet_ntoa ( new_tftp_server ) );
1233 snprintf ( uri_string, sizeof ( uri_string ),
1234 "tftp://%s/", inet_ntoa ( new_tftp_server ) );
1235 uri = parse_uri ( uri_string );
1236 if ( ! uri )
1237 return -ENOMEM;
1238 churi ( uri );
1239 uri_put ( uri );
1240 tftp_server = new_tftp_server;
1241 }
1242
1243 return 0;
1244}
void churi(struct uri *uri)
Change working URI.
Definition cwuri.c:46
int fetch_ipv4_setting(struct settings *settings, const struct setting *setting, struct in_addr *inp)
Fetch value of IPv4 address setting.
Definition settings.c:913
IP address structure.
Definition in.h:42
uint32_t s_addr
Definition in.h:43
struct uri * parse_uri(const char *uri_string)
Parse URI.
Definition uri.c:297

References churi(), DBGC, ENOMEM, fetch_ipv4_setting(), inet_ntoa(), NULL, parse_uri(), in_addr::s_addr, snprintf(), and uri_put().

Variable Documentation

◆ __profiler

struct profiler tftp_server_profiler __profiler
static
Initial value:
=
{ .name = "tftp.client" }

Client profiler.

Server profiler.

Definition at line 168 of file tftp.c.

169 { .name = "tftp.client" };

◆ __errortab

struct errortab tftp_errors [] __errortab
Initial value:
= {
}
#define __einfo_errortab(einfo)
Definition errortab.h:24
#define EINFO_ENOENT_NOT_FOUND
Definition tftp.c:82

Human-readable error messages.

Definition at line 176 of file tftp.c.

◆ tftp_mtftp_socket

struct sockaddr_in tftp_mtftp_socket
static
Initial value:
= {
.sin_family = AF_INET,
.sin_addr.s_addr = htonl ( 0xefff0101 ),
.sin_port = htons ( 3001 ),
}
#define htonl(value)
Definition byteswap.h:134

MTFTP multicast receive address.

This is treated as a global configuration parameter.

Definition at line 318 of file tftp.c.

318 {
319 .sin_family = AF_INET,
320 .sin_addr.s_addr = htonl ( 0xefff0101 ),
321 .sin_port = htons ( 3001 ),
322};

Referenced by mtftp_open(), tftp_set_mtftp_address(), and tftp_set_mtftp_port().

◆ tftp_options

struct tftp_option tftp_options[]
static
Initial value:
= {
{ "blksize", tftp_process_blksize },
{ "tsize", tftp_process_tsize },
{ "multicast", tftp_process_multicast },
{ NULL, NULL }
}
static int tftp_process_blksize(struct tftp_request *tftp, char *value)
Process TFTP "blksize" option.
Definition tftp.c:567
static int tftp_process_tsize(struct tftp_request *tftp, char *value)
Process TFTP "tsize" option.
Definition tftp.c:588
static int tftp_process_multicast(struct tftp_request *tftp, char *value)
Process TFTP "multicast" option.
Definition tftp.c:609

Recognised TFTP options.

Definition at line 683 of file tftp.c.

683 {
684 { "blksize", tftp_process_blksize },
685 { "tsize", tftp_process_tsize },
686 { "multicast", tftp_process_multicast },
687 { NULL, NULL }
688};

Referenced by tftp_process_option().

◆ tftp_socket_operations

struct interface_operation tftp_socket_operations[]
static
Initial value:
= {
}
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition interface.h:33
static int tftp_socket_deliver(struct tftp_request *tftp, struct io_buffer *iobuf, struct xfer_metadata *meta)
Receive new data via socket.
Definition tftp.c:997

TFTP socket operations.

Definition at line 1022 of file tftp.c.

1022 {
1024};

◆ tftp_socket_desc

struct interface_descriptor tftp_socket_desc
static
Initial value:
=
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition interface.h:81
static struct interface_operation tftp_socket_operations[]
TFTP socket operations.
Definition tftp.c:1022

TFTP socket interface descriptor.

Definition at line 1027 of file tftp.c.

Referenced by tftp_core_open().

◆ tftp_mc_socket_operations

struct interface_operation tftp_mc_socket_operations[]
static
Initial value:
= {
}

TFTP multicast socket operations.

Definition at line 1031 of file tftp.c.

1031 {
1033};

◆ tftp_mc_socket_desc

struct interface_descriptor tftp_mc_socket_desc
static
Initial value:
=
static struct interface_operation tftp_mc_socket_operations[]
TFTP multicast socket operations.
Definition tftp.c:1031

TFTP multicast socket interface descriptor.

Definition at line 1036 of file tftp.c.

Referenced by tftp_core_open().

◆ tftp_xfer_operations

struct interface_operation tftp_xfer_operations[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition interface.c:250
static void tftp_close(struct tftp_request *tftp, int rc)
Terminate download.
Definition tftp.c:1061
static size_t tftp_xfer_window(struct tftp_request *tftp)
Check flow control window.
Definition tftp.c:1045

TFTP data transfer interface operations.

Definition at line 1071 of file tftp.c.

1071 {
1074};

◆ tftp_xfer_desc

struct interface_descriptor tftp_xfer_desc
static
Initial value:
=
static struct interface_operation tftp_xfer_operations[]
TFTP data transfer interface operations.
Definition tftp.c:1071

TFTP data transfer interface descriptor.

Definition at line 1077 of file tftp.c.

Referenced by tftp_core_open().

◆ __uri_opener

struct uri_opener mtftp_uri_opener __uri_opener
Initial value:
= {
.scheme = "tftp",
.open = tftp_open,
}
static int tftp_open(struct interface *xfer, struct uri *uri)
Initiate TFTP download.
Definition tftp.c:1149

TFTP URI opener.

MTFTP URI opener.

TFTM URI opener.

Definition at line 1156 of file tftp.c.

1156 {
1157 .scheme = "tftp",
1158 .open = tftp_open,
1159};

◆ __settings_applicator

struct settings_applicator tftp_settings_applicator __settings_applicator
Initial value:
= {
}
static int tftp_apply_settings(void)
Apply TFTP configuration settings.
Definition tftp.c:1212

TFTP settings applicator.

Definition at line 1247 of file tftp.c.

1247 {
1248 .apply = tftp_apply_settings,
1249};