iPXE
Functions | Variables
xfer.c File Reference

Data transfer interfaces. More...

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ipxe/iobuf.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int xfer_vredirect (struct interface *intf, int type, va_list args)
 Send redirection event. More...
 
size_t xfer_window (struct interface *intf)
 Check flow control window. More...
 
void xfer_window_changed (struct interface *intf)
 Report change of flow control window. More...
 
struct io_bufferxfer_alloc_iob (struct interface *intf, size_t len)
 Allocate I/O buffer. More...
 
int xfer_deliver (struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
 Deliver datagram. More...
 
int xfer_redirect (struct interface *intf, int type,...)
 Send redirection event. More...
 
int xfer_deliver_iob (struct interface *intf, struct io_buffer *iobuf)
 Deliver datagram as I/O buffer without metadata. More...
 
int xfer_deliver_raw_meta (struct interface *intf, const void *data, size_t len, struct xfer_metadata *meta)
 Deliver datagram as raw data. More...
 
int xfer_deliver_raw (struct interface *intf, const void *data, size_t len)
 Deliver datagram as raw data without metadata. More...
 
int xfer_vprintf (struct interface *intf, const char *format, va_list args)
 Deliver formatted string. More...
 
int xfer_printf (struct interface *intf, const char *format,...)
 Deliver formatted string. More...
 
int xfer_seek (struct interface *intf, off_t offset)
 Seek to position. More...
 
int xfer_check_order (struct xfer_metadata *meta, size_t *pos, size_t len)
 Check that data is delivered strictly in order. More...
 

Variables

static struct xfer_metadata dummy_metadata
 Dummy transfer metadata. More...
 

Detailed Description

Data transfer interfaces.

Definition in file xfer.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ xfer_vredirect()

int xfer_vredirect ( struct interface intf,
int  type,
va_list  args 
)

Send redirection event.

Parameters
intfData transfer interface
typeNew location type
argsRemaining arguments depend upon location type
Return values
rcReturn status code

Definition at line 62 of file xfer.c.

62  {
63  struct interface tmp;
64  struct interface *dest;
65  xfer_vredirect_TYPE ( void * ) *op =
67  void *object = intf_object ( dest );
68  int rc;
69 
70  DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " redirect\n",
71  INTF_INTF_DBG ( intf, dest ) );
72 
73  if ( op ) {
74  rc = op ( object, type, args );
75  } else {
76  /* Default is to reopen the interface as instructed,
77  * then send xfer_window_changed() messages to both
78  * new child and parent interfaces. Since our
79  * original child interface is likely to be closed and
80  * unplugged as a result of the call to
81  * xfer_vreopen(), we create a temporary interface in
82  * order to be able to send xfer_window_changed() to
83  * the parent.
84  *
85  * If redirection fails, then send intf_close() to the
86  * parent interface.
87  */
88  intf_temp_init ( &tmp, intf );
89  intf_plug ( &tmp, dest );
90  rc = xfer_vreopen ( dest, type, args );
91  if ( rc == 0 ) {
94  } else {
95  intf_close ( &tmp, rc );
96  }
97  intf_unplug ( &tmp );
98  }
99 
100  if ( rc != 0 ) {
101  DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " redirect "
102  "failed: %s\n", INTF_INTF_DBG ( intf, dest ),
103  strerror ( rc ) );
104  }
105 
106  intf_put ( dest );
107  return rc;
108 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:146
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
#define INTF_INTF_FMT
printf() format string for INTF_INTF_DBG()
Definition: interface.h:297
#define INTF_INTF_DBG(intf, dest)
printf() arguments for representing an object interface pair
Definition: interface.h:306
uint32_t type
Operating system type.
Definition: ena.h:12
#define INTF_COL(intf)
Find debugging colourisation for an object interface.
Definition: interface.h:281
#define DBGC(...)
Definition: compiler.h:505
int xfer_vredirect(struct interface *intf, int type, va_list args)
Send redirection event.
Definition: xfer.c:62
#define xfer_vredirect_TYPE(object_type)
Definition: xfer.h:69
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:159
struct interface * intf
Original interface.
Definition: interface.h:158
unsigned long tmp
Definition: linux_pci.h:53
An object interface.
Definition: interface.h:124
static void * dest
Definition: strings.h:176
void intf_unplug(struct interface *intf)
Unplug an object interface.
Definition: interface.c:117
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int xfer_vreopen(struct interface *intf, int type, va_list args)
Reopen location.
Definition: open.c:224
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:149
#define intf_get_dest_op_no_passthru(intf, type, dest)
Get object interface destination and operation method (without pass-through)
Definition: interface.h:257
static void intf_temp_init(struct interface *intf, struct interface *original)
Initialise a temporary outbound-only object interface.
Definition: interface.h:232
void intf_plug(struct interface *intf, struct interface *dest)
Plug an object interface into a new destination object interface.
Definition: interface.c:83

References DBGC, dest, interface::intf, intf_close(), INTF_COL, intf_get_dest_op_no_passthru, INTF_INTF_DBG, INTF_INTF_FMT, intf_object(), intf_plug(), intf_put(), intf_temp_init(), intf_unplug(), op, rc, strerror(), tmp, type, xfer_vredirect(), xfer_vredirect_TYPE, xfer_vreopen(), and xfer_window_changed().

Referenced by xfer_redirect(), and xfer_vredirect().

◆ xfer_window()

size_t xfer_window ( struct interface intf)

Check flow control window.

Parameters
intfData transfer interface
Return values
lenLength of window

Definition at line 116 of file xfer.c.

116  {
117  struct interface *dest;
118  xfer_window_TYPE ( void * ) *op =
120  void *object = intf_object ( dest );
121  size_t len;
122 
123  if ( op ) {
124  len = op ( object );
125  } else {
126  /* Default is to provide an unlimited window */
127  len = ~( ( size_t ) 0 );
128  }
129 
130  intf_put ( dest );
131  return len;
132 }
__SIZE_TYPE__ size_t
Definition: stdint.h:6
size_t xfer_window(struct interface *intf)
Check flow control window.
Definition: xfer.c:116
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:159
struct interface * intf
Original interface.
Definition: interface.h:158
An object interface.
Definition: interface.h:124
static void * dest
Definition: strings.h:176
#define xfer_window_TYPE(object_type)
Definition: xfer.h:73
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
uint32_t len
Length.
Definition: ena.h:14
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:149
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:269

References dest, interface::intf, intf_get_dest_op, intf_object(), intf_put(), len, op, xfer_window(), and xfer_window_TYPE.

Referenced by efi_local_step(), fc_port_window_changed(), fcpcmd_send_wrdata(), http_step(), hw_step(), ipair_window_changed(), iscsi_tx_step(), nfs_mount_step(), nfs_pm_step(), nfs_step(), pinger_window_changed(), pxenv_tftp_open(), sanpath_step(), scsidev_step(), scsidev_window(), syslogs_window_changed(), tcp_xmit_sack(), tftp_send_packet(), tftp_send_rrq(), tls_cipherstream_window(), tls_plainstream_window(), tls_tx_step(), xcm_step(), and xfer_window().

◆ xfer_window_changed()

void xfer_window_changed ( struct interface intf)

Report change of flow control window.

Parameters
intfData transfer interface

Note that this method is used to indicate only unsolicited changes in the flow control window. In particular, this method must not be called as part of the response to xfer_deliver(), since that could easily lead to an infinite loop. Callers of xfer_deliver() should assume that the flow control window will have changed without generating an xfer_window_changed() message.

Definition at line 146 of file xfer.c.

146  {
147 
149 }
void xfer_window_changed(struct interface *intf)
Report change of flow control window.
Definition: xfer.c:146
struct interface * intf
Original interface.
Definition: interface.h:158
void intf_poke(struct interface *intf, void(type)(struct interface *intf))
Poke an object interface.
Definition: interface.c:420

References interface::intf, intf_poke(), and xfer_window_changed().

Referenced by aoedev_config_done(), fcoe_expired(), fcoe_reset(), fcpdev_examine(), http_step(), ib_cmrc_changed(), iscsi_rx_login_response(), scsidev_ready(), srp_login_rsp(), tcp_rx(), tls_new_finished(), tls_tx_step(), xfer_vredirect(), and xfer_window_changed().

◆ xfer_alloc_iob()

struct io_buffer* xfer_alloc_iob ( struct interface intf,
size_t  len 
)

Allocate I/O buffer.

Parameters
intfData transfer interface
lenI/O buffer payload length
Return values
iobufI/O buffer

Definition at line 158 of file xfer.c.

158  {
159  struct interface *dest;
160  xfer_alloc_iob_TYPE ( void * ) *op =
162  void *object = intf_object ( dest );
163  struct io_buffer *iobuf;
164 
165  DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " alloc_iob %zd\n",
166  INTF_INTF_DBG ( intf, dest ), len );
167 
168  if ( op ) {
169  iobuf = op ( object, len );
170  } else {
171  /* Default is to allocate an I/O buffer with no
172  * reserved space.
173  */
174  iobuf = alloc_iob ( len );
175  }
176 
177  if ( ! iobuf ) {
178  DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " alloc_iob "
179  "failed\n", INTF_INTF_DBG ( intf, dest ) );
180  }
181 
182  intf_put ( dest );
183  return iobuf;
184 }
#define INTF_INTF_FMT
printf() format string for INTF_INTF_DBG()
Definition: interface.h:297
#define INTF_INTF_DBG(intf, dest)
printf() arguments for representing an object interface pair
Definition: interface.h:306
#define INTF_COL(intf)
Find debugging colourisation for an object interface.
Definition: interface.h:281
#define DBGC(...)
Definition: compiler.h:505
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
Definition: xfer.c:158
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:159
struct interface * intf
Original interface.
Definition: interface.h:158
An object interface.
Definition: interface.h:124
static void * dest
Definition: strings.h:176
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
uint32_t len
Length.
Definition: ena.h:14
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:149
#define xfer_alloc_iob_TYPE(object_type)
Definition: xfer.h:82
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:269
A persistent I/O buffer.
Definition: iobuf.h:33

References alloc_iob(), DBGC, dest, interface::intf, INTF_COL, intf_get_dest_op, INTF_INTF_DBG, INTF_INTF_FMT, intf_object(), intf_put(), len, op, xfer_alloc_iob(), and xfer_alloc_iob_TYPE.

Referenced by dhcp_tx(), dhcpv6_tx(), efi_local_step(), efi_pxe_udp_write(), fc_xchg_alloc_iob(), fcpcmd_send_cmnd(), fcpcmd_send_wrdata(), ipair_tx(), iscsi_tx_data_out(), iscsi_tx_login_request(), pinger_expired(), pxenv_udp_write(), slam_tx_nack(), srp_cmd(), srp_login(), tftp_send_ack(), tftp_send_error(), tftp_send_rrq(), tls_send_plaintext(), xfer_alloc_iob(), xfer_deliver_raw_meta(), and xfer_seek().

◆ xfer_deliver()

int xfer_deliver ( struct interface intf,
struct io_buffer iobuf,
struct xfer_metadata meta 
)

Deliver datagram.

Parameters
intfData transfer interface
iobufDatagram I/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 194 of file xfer.c.

196  {
197  struct interface *dest;
198  xfer_deliver_TYPE ( void * ) *op =
200  void *object = intf_object ( dest );
201  int rc;
202 
203  DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT " deliver %zd\n",
204  INTF_INTF_DBG ( intf, dest ), iob_len ( iobuf ) );
205 
206  if ( op ) {
207  rc = op ( object, iobuf, meta );
208  } else {
209  /* Default is to discard the I/O buffer */
210  free_iob ( iobuf );
211  rc = -EPIPE;
212  }
213 
214  if ( rc != 0 ) {
215  DBGC ( INTF_COL ( intf ), "INTF " INTF_INTF_FMT
216  " deliver failed: %s\n",
217  INTF_INTF_DBG ( intf, dest ), strerror ( rc ) );
218  }
219 
220  intf_put ( dest );
221  return rc;
222 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define INTF_INTF_FMT
printf() format string for INTF_INTF_DBG()
Definition: interface.h:297
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define INTF_INTF_DBG(intf, dest)
printf() arguments for representing an object interface pair
Definition: interface.h:306
#define EPIPE
Broken pipe.
Definition: errno.h:619
#define INTF_COL(intf)
Find debugging colourisation for an object interface.
Definition: interface.h:281
#define DBGC(...)
Definition: compiler.h:505
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:159
#define xfer_deliver_TYPE(object_type)
Definition: xfer.h:88
struct interface * intf
Original interface.
Definition: interface.h:158
An object interface.
Definition: interface.h:124
static void * dest
Definition: strings.h:176
int meta(WINDOW *, bool)
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:149
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:269

References DBGC, dest, EPIPE, free_iob(), interface::intf, INTF_COL, intf_get_dest_op, INTF_INTF_DBG, INTF_INTF_FMT, intf_object(), intf_put(), iob_len(), meta(), op, rc, strerror(), xfer_deliver(), and xfer_deliver_TYPE.

Referenced by dhcp_tx(), efi_pxe_udp_write(), fc_xchg_rx(), fcpcmd_send_cmnd(), fcpcmd_send_wrdata(), http_conn_socket_deliver(), http_content_deliver(), peerblk_deliver(), peermux_block_deliver(), ping_rx(), pinger_expired(), pxenv_udp_write(), slam_mc_socket_deliver(), tftp_rx_data(), tftp_send_ack(), tftp_send_error(), udp_rx(), xfer_buffer(), xfer_deliver(), xfer_deliver_iob(), xfer_deliver_raw_meta(), and xfer_seek().

◆ xfer_redirect()

int xfer_redirect ( struct interface intf,
int  type,
  ... 
)

Send redirection event.

Parameters
intfData transfer interface
typeNew location type
...Remaining arguments depend upon location type
Return values
rcReturn status code

Definition at line 238 of file xfer.c.

238  {
239  va_list args;
240  int rc;
241 
242  va_start ( args, type );
243  rc = xfer_vredirect ( intf, type, args );
244  va_end ( args );
245  return rc;
246 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:9
uint32_t type
Operating system type.
Definition: ena.h:12
int xfer_vredirect(struct interface *intf, int type, va_list args)
Send redirection event.
Definition: xfer.c:62
struct interface * intf
Original interface.
Definition: interface.h:158
__builtin_va_list va_list
Definition: stdarg.h:6
#define va_start(ap, last)
Definition: stdarg.h:7

References interface::intf, rc, type, va_end, va_start, and xfer_vredirect().

Referenced by http_redirect(), and named_resolv_done().

◆ xfer_deliver_iob()

int xfer_deliver_iob ( struct interface intf,
struct io_buffer iobuf 
)

Deliver datagram as I/O buffer without metadata.

Parameters
intfData transfer interface
iobufDatagram I/O buffer
Return values
rcReturn status code

Definition at line 255 of file xfer.c.

255  {
256  return xfer_deliver ( intf, iobuf, &dummy_metadata );
257 }
struct interface * intf
Original interface.
Definition: interface.h:158
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
static struct xfer_metadata dummy_metadata
Dummy transfer metadata.
Definition: xfer.c:46

References dummy_metadata, interface::intf, and xfer_deliver().

Referenced by dhcpv6_tx(), efi_local_step(), fc_xchg_tx(), fcoe_rx(), http_rx_chunk_data(), http_rx_transfer_identity(), http_tx_request(), ib_cmrc_complete_recv(), imux_rx_tcp(), ipair_tx(), iscsi_tx_data_out(), iscsi_tx_login_request(), nfs_deliver(), oncrpc_call(), slam_tx_nack(), srp_cmd(), srp_login(), tcp_rx_data(), tftp_send_rrq(), tls_new_data(), and tls_send_plaintext().

◆ xfer_deliver_raw_meta()

int xfer_deliver_raw_meta ( struct interface intf,
const void *  data,
size_t  len,
struct xfer_metadata meta 
)

Deliver datagram as raw data.

Parameters
intfData transfer interface
dataData
lenLength of data
metaData transfer metadata
Return values
rcReturn status code

Definition at line 268 of file xfer.c.

269  {
270  struct io_buffer *iobuf;
271 
272  iobuf = xfer_alloc_iob ( intf, len );
273  if ( ! iobuf )
274  return -ENOMEM;
275 
276  memcpy ( iob_put ( iobuf, len ), data, len );
277  return xfer_deliver ( intf, iobuf, meta );
278 }
#define iob_put(iobuf, len)
Definition: iobuf.h:120
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
Definition: xfer.c:158
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int meta(WINDOW *, bool)
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
A persistent I/O buffer.
Definition: iobuf.h:33

References data, ENOMEM, iob_put, len, memcpy(), meta(), xfer_alloc_iob(), and xfer_deliver().

Referenced by dns_send_packet(), fc_els_tx(), fc_ns_query_step(), peerdisc_socket_tx(), and xfer_deliver_raw().

◆ xfer_deliver_raw()

int xfer_deliver_raw ( struct interface intf,
const void *  data,
size_t  len 
)

Deliver datagram as raw data without metadata.

Parameters
intfData transfer interface
dataData
lenLength of data
Return values
rcReturn status code

Definition at line 288 of file xfer.c.

288  {
289  return xfer_deliver_raw_meta ( intf, data, len, &dummy_metadata );
290 }
int xfer_deliver_raw_meta(struct interface *intf, const void *data, size_t len, struct xfer_metadata *meta)
Deliver datagram as raw data.
Definition: xfer.c:268
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
static struct xfer_metadata dummy_metadata
Dummy transfer metadata.
Definition: xfer.c:46

References data, dummy_metadata, len, and xfer_deliver_raw_meta().

Referenced by fcoe_fip_rx_els_response(), hw_step(), ib_cmrc_changed(), iscsi_tx_bhs(), ntp_request(), slam_finished(), xcm_step(), xfer_vprintf(), xsmp_tx_session(), and xsmp_tx_xve().

◆ xfer_vprintf()

int xfer_vprintf ( struct interface intf,
const char *  format,
va_list  args 
)

Deliver formatted string.

Parameters
intfData transfer interface
formatFormat string
argsArguments corresponding to the format string
Return values
rcReturn status code

Definition at line 300 of file xfer.c.

301  {
302  va_list args_tmp;
303  char *buf;
304  int len;
305  int rc;
306 
307  /* Create temporary string */
308  va_copy ( args_tmp, args );
309  len = vasprintf ( &buf, format, args );
310  va_end ( args_tmp );
311  if ( len < 0 ) {
312  rc = len;
313  goto err_asprintf;
314  }
315 
316  /* Transmit string */
317  if ( ( rc = xfer_deliver_raw ( intf, buf, len ) ) != 0 )
318  goto err_deliver;
319 
320  err_deliver:
321  free ( buf );
322  err_asprintf:
323  return rc;
324 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:9
#define va_copy(dest, src)
Definition: stdarg.h:10
int xfer_deliver_raw(struct interface *intf, const void *data, size_t len)
Deliver datagram as raw data without metadata.
Definition: xfer.c:288
int vasprintf(char **strp, const char *fmt, va_list args)
Write a formatted string to newly allocated memory.
Definition: asprintf.c:17
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
uint32_t len
Length.
Definition: ena.h:14
__builtin_va_list va_list
Definition: stdarg.h:6
int const char * format
Definition: xfer.h:104

References format, free, len, rc, va_copy, va_end, vasprintf(), and xfer_deliver_raw().

Referenced by xfer_printf().

◆ xfer_printf()

int xfer_printf ( struct interface intf,
const char *  format,
  ... 
)

Deliver formatted string.

Parameters
intfData transfer interface
formatFormat string
...Arguments corresponding to the format string
Return values
rcReturn status code

Definition at line 334 of file xfer.c.

334  {
335  va_list args;
336  int rc;
337 
338  va_start ( args, format );
339  rc = xfer_vprintf ( intf, format, args );
340  va_end ( args );
341  return rc;
342 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define va_end(ap)
Definition: stdarg.h:9
int xfer_vprintf(struct interface *intf, const char *format, va_list args)
Deliver formatted string.
Definition: xfer.c:300
__builtin_va_list va_list
Definition: stdarg.h:6
#define va_start(ap, last)
Definition: stdarg.h:7
int const char * format
Definition: xfer.h:104

References format, rc, va_end, va_start, and xfer_vprintf().

Referenced by ftp_next_state(), and syslog_send().

◆ xfer_seek()

int xfer_seek ( struct interface intf,
off_t  offset 
)

Seek to position.

Parameters
intfData transfer interface
offsetOffset to new position
Return values
rcReturn status code

Definition at line 351 of file xfer.c.

351  {
352  struct io_buffer *iobuf;
353  struct xfer_metadata meta = {
354  .flags = XFER_FL_ABS_OFFSET,
355  .offset = offset,
356  };
357 
358  DBGC ( INTF_COL ( intf ), "INTF " INTF_FMT " seek to %ld\n",
359  INTF_DBG ( intf ), offset );
360 
361  /* Allocate and send a zero-length data buffer */
362  iobuf = xfer_alloc_iob ( intf, 0 );
363  if ( ! iobuf )
364  return -ENOMEM;
365 
366  return xfer_deliver ( intf, iobuf, &meta );
367 }
Data transfer metadata.
Definition: xfer.h:22
#define INTF_DBG(intf)
printf() arguments for representing an object interface
Definition: interface.h:292
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition: xfer.h:47
#define INTF_COL(intf)
Find debugging colourisation for an object interface.
Definition: interface.h:281
#define DBGC(...)
Definition: compiler.h:505
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
Definition: xfer.c:158
#define ENOMEM
Not enough space.
Definition: errno.h:534
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
int meta(WINDOW *, bool)
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:194
#define INTF_FMT
printf() format string for INTF_DBG()
Definition: interface.h:284
A persistent I/O buffer.
Definition: iobuf.h:33

References DBGC, ENOMEM, INTF_COL, INTF_DBG, INTF_FMT, meta(), offset, xfer_alloc_iob(), xfer_deliver(), and XFER_FL_ABS_OFFSET.

Referenced by efi_local_step(), ftp_reply(), http_rx_chunk_len(), http_rx_headers(), nfs_deliver(), peermux_info_close(), slam_pull_header(), and tftp_presize().

◆ xfer_check_order()

int xfer_check_order ( struct xfer_metadata meta,
size_t pos,
size_t  len 
)

Check that data is delivered strictly in order.

Parameters
metaData transfer metadata
posCurrent position
lenLength of data
Return values
rcReturn status code

Definition at line 377 of file xfer.c.

377  {
378  size_t new_pos;
379 
380  /* Allow out-of-order zero-length packets (as used by xfer_seek()) */
381  if ( len == 0 )
382  return 0;
383 
384  /* Calculate position of this delivery */
385  new_pos = *pos;
386  if ( meta->flags & XFER_FL_ABS_OFFSET )
387  new_pos = 0;
388  new_pos += meta->offset;
389 
390  /* Fail if delivery position is not equal to current position */
391  if ( new_pos != *pos )
392  return -EPROTO;
393 
394  /* Update current position */
395  *pos += len;
396 
397  return 0;
398 }
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition: xfer.h:47
#define EPROTO
Protocol error.
Definition: errno.h:624
int meta(WINDOW *, bool)
uint32_t len
Length.
Definition: ena.h:14

References EPROTO, len, meta(), and XFER_FL_ABS_OFFSET.

Referenced by peerblk_raw_rx().

Variable Documentation

◆ dummy_metadata

struct xfer_metadata dummy_metadata
static

Dummy transfer metadata.

This gets passed to xfer_interface::deliver() and equivalents when no metadata is available.

Definition at line 46 of file xfer.c.

Referenced by xfer_deliver_iob(), and xfer_deliver_raw().