iPXE
Data Structures | Functions | Variables
udp.c File Reference

UDP protocol. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <byteswap.h>
#include <errno.h>
#include <ipxe/tcpip.h>
#include <ipxe/iobuf.h>
#include <ipxe/xfer.h>
#include <ipxe/open.h>
#include <ipxe/uri.h>
#include <ipxe/netdevice.h>
#include <ipxe/udp.h>

Go to the source code of this file.

Data Structures

struct  udp_connection
 A UDP connection. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static LIST_HEAD (udp_conns)
 List of registered UDP connections. More...
 
static int udp_port_available (int port)
 Check if local UDP port is available. More...
 
static int udp_open_common (struct interface *xfer, struct sockaddr *peer, struct sockaddr *local, int promisc)
 Open a UDP connection. More...
 
int udp_open (struct interface *xfer, struct sockaddr *peer, struct sockaddr *local)
 Open a UDP connection. More...
 
int udp_open_promisc (struct interface *xfer)
 Open a promiscuous UDP connection. More...
 
static void udp_close (struct udp_connection *udp, int rc)
 Close a UDP connection. More...
 
static int udp_tx (struct udp_connection *udp, struct io_buffer *iobuf, struct sockaddr_tcpip *src, struct sockaddr_tcpip *dest, struct net_device *netdev)
 Transmit data via a UDP connection to a specified address. More...
 
static struct udp_connectionudp_demux (struct sockaddr_tcpip *local)
 Identify UDP connection by local address. More...
 
static int udp_rx (struct io_buffer *iobuf, struct net_device *netdev __unused, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum)
 Process a received packet. More...
 
static struct io_bufferudp_xfer_alloc_iob (struct udp_connection *udp, size_t len)
 Allocate I/O buffer for UDP. More...
 
static int udp_xfer_deliver (struct udp_connection *udp, struct io_buffer *iobuf, struct xfer_metadata *meta)
 Deliver datagram as I/O buffer. More...
 
static int udp_open_uri (struct interface *xfer, struct uri *uri)
 Open UDP URI. More...
 

Variables

static struct interface_descriptor udp_xfer_desc
 UDP data transfer interface descriptor. More...
 
struct tcpip_protocol udp_protocol __tcpip_protocol
 ICMPv4 TCP/IP protocol. More...
 
static struct interface_operation udp_xfer_operations []
 UDP data transfer interface operations. More...
 
struct socket_opener udp_ipv4_socket_opener __socket_opener
 UDP IPv4 socket opener. More...
 
int udp_sock_dgram = UDP_SOCK_DGRAM
 Linkage hack. More...
 
struct uri_opener udp_uri_opener __uri_opener
 UDP URI opener. More...
 

Detailed Description

UDP protocol.

Definition in file udp.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ LIST_HEAD()

static LIST_HEAD ( udp_conns  )
static

List of registered UDP connections.

◆ udp_port_available()

static int udp_port_available ( int  port)
static

Check if local UDP port is available.

Parameters
portLocal port number
Return values
portLocal port number, or negative error

Definition at line 56 of file udp.c.

56  {
57  struct udp_connection *udp;
58 
59  list_for_each_entry ( udp, &udp_conns, list ) {
60  if ( udp->local.st_port == htons ( port ) )
61  return -EADDRINUSE;
62  }
63  return port;
64 }
#define EADDRINUSE
Address already in use.
Definition: errno.h:303
struct list_head list
List of UDP connections.
Definition: udp.c:30
A UDP connection.
Definition: udp.c:26
u8 port
Port number.
Definition: CIB_PRM.h:31
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
uint16_t st_port
TCP/IP port.
Definition: tcpip.h:81
struct sockaddr_tcpip local
Local socket address.
Definition: udp.c:36
#define htons(value)
Definition: byteswap.h:135

References EADDRINUSE, htons, udp_connection::list, list_for_each_entry, udp_connection::local, port, and sockaddr_tcpip::st_port.

Referenced by udp_open_common().

◆ udp_open_common()

static int udp_open_common ( struct interface xfer,
struct sockaddr peer,
struct sockaddr local,
int  promisc 
)
static

Open a UDP connection.

Parameters
xferData transfer interface
peerPeer socket address, or NULL
localLocal socket address, or NULL
promiscSocket is promiscuous
Return values
rcReturn status code

Definition at line 75 of file udp.c.

77  {
78  struct sockaddr_tcpip *st_peer = ( struct sockaddr_tcpip * ) peer;
79  struct sockaddr_tcpip *st_local = ( struct sockaddr_tcpip * ) local;
80  struct udp_connection *udp;
81  int port;
82  int rc;
83 
84  /* Allocate and initialise structure */
85  udp = zalloc ( sizeof ( *udp ) );
86  if ( ! udp )
87  return -ENOMEM;
88  DBGC ( udp, "UDP %p allocated\n", udp );
89  ref_init ( &udp->refcnt, NULL );
90  intf_init ( &udp->xfer, &udp_xfer_desc, &udp->refcnt );
91  if ( st_peer )
92  memcpy ( &udp->peer, st_peer, sizeof ( udp->peer ) );
93  if ( st_local )
94  memcpy ( &udp->local, st_local, sizeof ( udp->local ) );
95 
96  /* Bind to local port */
97  if ( ! promisc ) {
98  port = tcpip_bind ( st_local, udp_port_available );
99  if ( port < 0 ) {
100  rc = port;
101  DBGC ( udp, "UDP %p could not bind: %s\n",
102  udp, strerror ( rc ) );
103  goto err;
104  }
105  udp->local.st_port = htons ( port );
106  DBGC ( udp, "UDP %p bound to port %d\n",
107  udp, ntohs ( udp->local.st_port ) );
108  }
109 
110  /* Attach parent interface, transfer reference to connection
111  * list and return
112  */
113  intf_plug_plug ( &udp->xfer, xfer );
114  list_add ( &udp->list, &udp_conns );
115  return 0;
116 
117  err:
118  ref_put ( &udp->refcnt );
119  return rc;
120 }
TCP/IP socket address.
Definition: tcpip.h:75
struct interface xfer
Data transfer interface.
Definition: udp.c:33
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int udp_port_available(int port)
Check if local UDP port is available.
Definition: udp.c:56
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
#define DBGC(...)
Definition: compiler.h:505
static struct interface_descriptor udp_xfer_desc
UDP data transfer interface descriptor.
Definition: udp.c:47
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:102
struct refcnt refcnt
Reference counter.
Definition: udp.c:28
#define ntohs(value)
Definition: byteswap.h:136
struct list_head list
List of UDP connections.
Definition: udp.c:30
int tcpip_bind(struct sockaddr_tcpip *st_local, int(*available)(int port))
Bind to local TCP/IP port.
Definition: tcpip.c:214
#define ENOMEM
Not enough space.
Definition: errno.h:534
A UDP connection.
Definition: udp.c:26
void * memcpy(void *dest, const void *src, size_t len) __nonnull
u8 port
Port number.
Definition: CIB_PRM.h:31
uint16_t st_port
TCP/IP port.
Definition: tcpip.h:81
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
struct sockaddr_tcpip local
Local socket address.
Definition: udp.c:36
struct sockaddr_tcpip peer
Remote socket address.
Definition: udp.c:38
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:173
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define htons(value)
Definition: byteswap.h:135
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References DBGC, ENOMEM, htons, intf_init(), intf_plug_plug(), udp_connection::list, list_add, udp_connection::local, memcpy(), ntohs, NULL, udp_connection::peer, port, rc, ref_init, ref_put, udp_connection::refcnt, sockaddr_tcpip::st_port, strerror(), tcpip_bind(), udp_port_available(), udp_xfer_desc, udp_connection::xfer, and zalloc().

Referenced by udp_open(), and udp_open_promisc().

◆ udp_open()

int udp_open ( struct interface xfer,
struct sockaddr peer,
struct sockaddr local 
)

Open a UDP connection.

Parameters
xferData transfer interface
peerPeer socket address
localLocal socket address, or NULL
Return values
rcReturn status code

Definition at line 130 of file udp.c.

131  {
132  return udp_open_common ( xfer, peer, local, 0 );
133 }
struct interface xfer
Data transfer interface.
Definition: udp.c:33
struct sockaddr_tcpip local
Local socket address.
Definition: udp.c:36
static int udp_open_common(struct interface *xfer, struct sockaddr *peer, struct sockaddr *local, int promisc)
Open a UDP connection.
Definition: udp.c:75
struct sockaddr_tcpip peer
Remote socket address.
Definition: udp.c:38

References udp_connection::local, udp_connection::peer, udp_open_common(), and udp_connection::xfer.

◆ udp_open_promisc()

int udp_open_promisc ( struct interface xfer)

Open a promiscuous UDP connection.

Parameters
xferData transfer interface
Return values
rcReturn status code

Promiscuous UDP connections are required in order to support the PXE API.

Definition at line 144 of file udp.c.

144  {
145  return udp_open_common ( xfer, NULL, NULL, 1 );
146 }
struct interface xfer
Data transfer interface.
Definition: udp.c:33
static int udp_open_common(struct interface *xfer, struct sockaddr *peer, struct sockaddr *local, int promisc)
Open a UDP connection.
Definition: udp.c:75
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References NULL, udp_open_common(), and udp_connection::xfer.

Referenced by efi_pxe_udp_open(), and pxenv_udp_open().

◆ udp_close()

static void udp_close ( struct udp_connection udp,
int  rc 
)
static

Close a UDP connection.

Parameters
udpUDP connection
rcReason for close

Definition at line 154 of file udp.c.

154  {
155 
156  /* Close data transfer interface */
157  intf_shutdown ( &udp->xfer, rc );
158 
159  /* Remove from list of connections and drop list's reference */
160  list_del ( &udp->list );
161  ref_put ( &udp->refcnt );
162 
163  DBGC ( udp, "UDP %p closed\n", udp );
164 }
struct interface xfer
Data transfer interface.
Definition: udp.c:33
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_shutdown(struct interface *intf, int rc)
Shut down an object interface.
Definition: interface.c:273
#define DBGC(...)
Definition: compiler.h:505
struct refcnt refcnt
Reference counter.
Definition: udp.c:28
struct list_head list
List of UDP connections.
Definition: udp.c:30
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

References DBGC, intf_shutdown(), udp_connection::list, list_del, rc, ref_put, udp_connection::refcnt, and udp_connection::xfer.

◆ udp_tx()

static int udp_tx ( struct udp_connection udp,
struct io_buffer iobuf,
struct sockaddr_tcpip src,
struct sockaddr_tcpip dest,
struct net_device netdev 
)
static

Transmit data via a UDP connection to a specified address.

Parameters
udpUDP connection
iobufI/O buffer
srcSource address, or NULL to use default
destDestination address, or NULL to use default
netdevNetwork device, or NULL to use default
Return values
rcReturn status code

Definition at line 176 of file udp.c.

178  {
179  struct udp_header *udphdr;
180  size_t len;
181  int rc;
182 
183  /* Check we can accommodate the header */
184  if ( ( rc = iob_ensure_headroom ( iobuf,
185  MAX_LL_NET_HEADER_LEN ) ) != 0 ) {
186  free_iob ( iobuf );
187  return rc;
188  }
189 
190  /* Fill in default values if not explicitly provided */
191  if ( ! src )
192  src = &udp->local;
193  if ( ! dest )
194  dest = &udp->peer;
195 
196  /* Add the UDP header */
197  udphdr = iob_push ( iobuf, sizeof ( *udphdr ) );
198  len = iob_len ( iobuf );
199  udphdr->dest = dest->st_port;
200  udphdr->src = src->st_port;
201  udphdr->len = htons ( len );
202  udphdr->chksum = 0;
203  udphdr->chksum = tcpip_chksum ( udphdr, len );
204 
205  /* Dump debugging information */
206  DBGC2 ( udp, "UDP %p TX %d->%d len %d\n", udp,
207  ntohs ( udphdr->src ), ntohs ( udphdr->dest ),
208  ntohs ( udphdr->len ) );
209 
210  /* Send it to the next layer for processing */
211  if ( ( rc = tcpip_tx ( iobuf, &udp_protocol, src, dest, netdev,
212  &udphdr->chksum ) ) != 0 ) {
213  DBGC ( udp, "UDP %p could not transmit packet: %s\n",
214  udp, strerror ( rc ) );
215  return rc;
216  }
217 
218  return 0;
219 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint16_t chksum
Checksum.
Definition: udp.h:37
#define iob_push(iobuf, len)
Definition: iobuf.h:80
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#define DBGC(...)
Definition: compiler.h:505
#define ntohs(value)
Definition: byteswap.h:136
uint16_t src
Source port.
Definition: udp.h:31
uint16_t len
Length.
Definition: udp.h:35
#define MAX_LL_NET_HEADER_LEN
Maximum combined length of a link-layer and network-layer header.
Definition: netdevice.h:58
static struct net_device * netdev
Definition: gdbudp.c:52
static void * dest
Definition: strings.h:176
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
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:151
uint16_t dest
Destination port.
Definition: udp.h:33
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
struct sockaddr_tcpip local
Local socket address.
Definition: udp.c:36
struct sockaddr_tcpip peer
Remote socket address.
Definition: udp.c:38
UDP constants.
Definition: udp.h:29
int tcpip_tx(struct io_buffer *iobuf, struct tcpip_protocol *tcpip_protocol, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest, struct net_device *netdev, uint16_t *trans_csum)
Transmit a TCP/IP packet.
Definition: tcpip.c:91
int iob_ensure_headroom(struct io_buffer *iobuf, size_t len)
Ensure I/O buffer has sufficient headroom.
Definition: iobuf.c:183
uint16_t tcpip_chksum(const void *data, size_t len)
Calculate TCP/IP checkum.
Definition: tcpip.c:203
#define htons(value)
Definition: byteswap.h:135

References udp_header::chksum, DBGC, DBGC2, udp_header::dest, dest, free_iob(), htons, iob_ensure_headroom(), iob_len(), iob_push, len, udp_header::len, udp_connection::local, MAX_LL_NET_HEADER_LEN, netdev, ntohs, udp_connection::peer, rc, udp_header::src, src, strerror(), tcpip_chksum(), and tcpip_tx().

Referenced by udp_xfer_deliver().

◆ udp_demux()

static struct udp_connection* udp_demux ( struct sockaddr_tcpip local)
static

Identify UDP connection by local address.

Parameters
localLocal address
Return values
udpUDP connection, or NULL

Definition at line 227 of file udp.c.

227  {
228  static const struct sockaddr_tcpip empty_sockaddr = { .pad = { 0, } };
229  struct udp_connection *udp;
230 
231  list_for_each_entry ( udp, &udp_conns, list ) {
232  if ( ( ( udp->local.st_family == local->st_family ) ||
233  ( udp->local.st_family == 0 ) ) &&
234  ( ( udp->local.st_port == local->st_port ) ||
235  ( udp->local.st_port == 0 ) ) &&
236  ( ( memcmp ( udp->local.pad, local->pad,
237  sizeof ( udp->local.pad ) ) == 0 ) ||
238  ( memcmp ( udp->local.pad, empty_sockaddr.pad,
239  sizeof ( udp->local.pad ) ) == 0 ) ) ) {
240  return udp;
241  }
242  }
243  return NULL;
244 }
TCP/IP socket address.
Definition: tcpip.h:75
char pad[sizeof(struct sockaddr) -(sizeof(sa_family_t)+sizeof(uint16_t)+sizeof(uint16_t)+sizeof(uint16_t))]
Padding.
Definition: tcpip.h:98
sa_family_t st_family
Socket address family (part of struct sockaddr)
Definition: tcpip.h:77
struct list_head list
List of UDP connections.
Definition: udp.c:30
A UDP connection.
Definition: udp.c:26
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
uint16_t st_port
TCP/IP port.
Definition: tcpip.h:81
struct sockaddr_tcpip local
Local socket address.
Definition: udp.c:36
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:113
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References udp_connection::list, list_for_each_entry, udp_connection::local, memcmp(), NULL, sockaddr_tcpip::pad, sockaddr_tcpip::st_family, and sockaddr_tcpip::st_port.

Referenced by udp_rx().

◆ udp_rx()

static int udp_rx ( struct io_buffer iobuf,
struct net_device *netdev  __unused,
struct sockaddr_tcpip st_src,
struct sockaddr_tcpip st_dest,
uint16_t  pshdr_csum 
)
static

Process a received packet.

Parameters
iobufI/O buffer
netdevNetwork device
st_srcPartially-filled source address
st_destPartially-filled destination address
pshdr_csumPseudo-header checksum
Return values
rcReturn status code

Definition at line 256 of file udp.c.

259  {
260  struct udp_header *udphdr = iobuf->data;
261  struct udp_connection *udp;
262  struct xfer_metadata meta;
263  size_t ulen;
264  unsigned int csum;
265  int rc = 0;
266 
267  /* Sanity check packet */
268  if ( iob_len ( iobuf ) < sizeof ( *udphdr ) ) {
269  DBG ( "UDP packet too short at %zd bytes (min %zd bytes)\n",
270  iob_len ( iobuf ), sizeof ( *udphdr ) );
271 
272  rc = -EINVAL;
273  goto done;
274  }
275  ulen = ntohs ( udphdr->len );
276  if ( ulen < sizeof ( *udphdr ) ) {
277  DBG ( "UDP length too short at %zd bytes "
278  "(header is %zd bytes)\n", ulen, sizeof ( *udphdr ) );
279  rc = -EINVAL;
280  goto done;
281  }
282  if ( ulen > iob_len ( iobuf ) ) {
283  DBG ( "UDP length too long at %zd bytes (packet is %zd "
284  "bytes)\n", ulen, iob_len ( iobuf ) );
285  rc = -EINVAL;
286  goto done;
287  }
288  if ( udphdr->chksum ) {
289  csum = tcpip_continue_chksum ( pshdr_csum, iobuf->data, ulen );
290  if ( csum != 0 ) {
291  DBG ( "UDP checksum incorrect (is %04x including "
292  "checksum field, should be 0000)\n", csum );
293  rc = -EINVAL;
294  goto done;
295  }
296  }
297 
298  /* Parse parameters from header and strip header */
299  st_src->st_port = udphdr->src;
300  st_dest->st_port = udphdr->dest;
301  udp = udp_demux ( st_dest );
302  iob_unput ( iobuf, ( iob_len ( iobuf ) - ulen ) );
303  iob_pull ( iobuf, sizeof ( *udphdr ) );
304 
305  /* Dump debugging information */
306  DBGC2 ( udp, "UDP %p RX %d<-%d len %zd\n", udp,
307  ntohs ( udphdr->dest ), ntohs ( udphdr->src ), ulen );
308 
309  /* Ignore if no matching connection found */
310  if ( ! udp ) {
311  DBG ( "No UDP connection listening on port %d\n",
312  ntohs ( udphdr->dest ) );
313  rc = -ENOTCONN;
314  goto done;
315  }
316 
317  /* Pass data to application */
318  memset ( &meta, 0, sizeof ( meta ) );
319  meta.src = ( struct sockaddr * ) st_src;
320  meta.dest = ( struct sockaddr * ) st_dest;
321  rc = xfer_deliver ( &udp->xfer, iob_disown ( iobuf ), &meta );
322 
323  done:
324  free_iob ( iobuf );
325  return rc;
326 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:98
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct interface xfer
Data transfer interface.
Definition: udp.c:33
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
Data transfer metadata.
Definition: xfer.h:22
uint16_t chksum
Checksum.
Definition: udp.h:37
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#define ntohs(value)
Definition: byteswap.h:136
uint16_t src
Source port.
Definition: udp.h:31
uint16_t len
Length.
Definition: udp.h:35
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:208
A UDP connection.
Definition: udp.c:26
int meta(WINDOW *, bool)
#define ENOTCONN
The socket is not connected.
Definition: errno.h:569
uint16_t st_port
TCP/IP port.
Definition: tcpip.h:81
Generalized socket address structure.
Definition: socket.h:96
#define iob_unput(iobuf, len)
Definition: iobuf.h:131
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
static struct udp_connection * udp_demux(struct sockaddr_tcpip *local)
Identify UDP connection by local address.
Definition: udp.c:227
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:193
uint16_t dest
Destination port.
Definition: udp.h:33
#define DBGC2(...)
Definition: compiler.h:522
void * data
Start of data.
Definition: iobuf.h:44
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
UDP constants.
Definition: udp.h:29
struct bofm_section_header done
Definition: bofm_test.c:46
uint16_t tcpip_continue_chksum(uint16_t partial, const void *data, size_t len)
Calculate continued TCP/IP checkum.
Definition: x86_tcpip.c:45
void * memset(void *dest, int character, size_t len) __nonnull

References udp_header::chksum, io_buffer::data, DBG, DBGC2, udp_header::dest, done, EINVAL, ENOTCONN, free_iob(), iob_disown, iob_len(), iob_pull, iob_unput, udp_header::len, memset(), meta(), ntohs, rc, udp_header::src, sockaddr_tcpip::st_port, tcpip_continue_chksum(), udp_demux(), udp_connection::xfer, and xfer_deliver().

◆ udp_xfer_alloc_iob()

static struct io_buffer* udp_xfer_alloc_iob ( struct udp_connection udp,
size_t  len 
)
static

Allocate I/O buffer for UDP.

Parameters
udpUDP connection
lenPayload size
Return values
iobufI/O buffer, or NULL

Definition at line 349 of file udp.c.

350  {
351  struct io_buffer *iobuf;
352 
353  iobuf = alloc_iob ( MAX_LL_NET_HEADER_LEN + len );
354  if ( ! iobuf ) {
355  DBGC ( udp, "UDP %p cannot allocate buffer of length %zd\n",
356  udp, len );
357  return NULL;
358  }
360  return iobuf;
361 }
#define DBGC(...)
Definition: compiler.h:505
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
#define MAX_LL_NET_HEADER_LEN
Maximum combined length of a link-layer and network-layer header.
Definition: netdevice.h:58
#define iob_reserve(iobuf, len)
Definition: iobuf.h:63
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A persistent I/O buffer.
Definition: iobuf.h:32

References alloc_iob(), DBGC, iob_reserve, len, MAX_LL_NET_HEADER_LEN, and NULL.

◆ udp_xfer_deliver()

static int udp_xfer_deliver ( struct udp_connection udp,
struct io_buffer iobuf,
struct xfer_metadata meta 
)
static

Deliver datagram as I/O buffer.

Parameters
udpUDP connection
iobufDatagram I/O buffer
metaData transfer metadata
Return values
rcReturn status code

Definition at line 371 of file udp.c.

373  {
374 
375  /* Transmit data, if possible */
376  return udp_tx ( udp, iobuf, ( ( struct sockaddr_tcpip * ) meta->src ),
377  ( ( struct sockaddr_tcpip * ) meta->dest ),
378  meta->netdev );
379 }
TCP/IP socket address.
Definition: tcpip.h:75
int meta(WINDOW *, bool)
static int udp_tx(struct udp_connection *udp, struct io_buffer *iobuf, struct sockaddr_tcpip *src, struct sockaddr_tcpip *dest, struct net_device *netdev)
Transmit data via a UDP connection to a specified address.
Definition: udp.c:176

References meta(), and udp_tx().

◆ udp_open_uri()

static int udp_open_uri ( struct interface xfer,
struct uri uri 
)
static

Open UDP URI.

Parameters
xferData transfer interface
uriURI
Return values
rcReturn status code

Definition at line 423 of file udp.c.

423  {
424  struct sockaddr_tcpip peer;
425 
426  /* Sanity check */
427  if ( ! uri->host )
428  return -EINVAL;
429 
430  memset ( &peer, 0, sizeof ( peer ) );
431  peer.st_port = htons ( uri_port ( uri, 0 ) );
432  return xfer_open_named_socket ( xfer, SOCK_DGRAM,
433  ( struct sockaddr * ) &peer,
434  uri->host, NULL );
435 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
TCP/IP socket address.
Definition: tcpip.h:75
#define SOCK_DGRAM
Definition: socket.h:29
Generalized socket address structure.
Definition: socket.h:96
const char * host
Host name.
Definition: uri.h:62
unsigned int uri_port(const struct uri *uri, unsigned int default_port)
Get port from URI.
Definition: uri.c:441
A Uniform Resource Identifier.
Definition: uri.h:50
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define htons(value)
Definition: byteswap.h:135
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:402
void * memset(void *dest, int character, size_t len) __nonnull

References EINVAL, uri::host, htons, memset(), NULL, SOCK_DGRAM, sockaddr_tcpip::st_port, uri_port(), and xfer_open_named_socket().

Variable Documentation

◆ udp_xfer_desc

static struct interface_descriptor udp_xfer_desc
static
Initial value:
=
A UDP connection.
Definition: udp.c:26
static struct interface_operation udp_xfer_operations[]
UDP data transfer interface operations.
Definition: udp.c:382
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:65

UDP data transfer interface descriptor.

Definition at line 47 of file udp.c.

Referenced by udp_open_common().

◆ __tcpip_protocol

struct tcpip_protocol udp_protocol __tcpip_protocol
Initial value:
= {
.name = "UDP",
.rx = udp_rx,
.tcpip_proto = IP_UDP,
}
#define TCPIP_NEGATIVE_ZERO_CSUM
Negative zero checksum value.
Definition: tcpip.h:30
#define IP_UDP
Definition: in.h:14
static int udp_rx(struct io_buffer *iobuf, struct net_device *netdev __unused, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum)
Process a received packet.
Definition: udp.c:256

ICMPv4 TCP/IP protocol.

ICMPv4 TCP/IP protocol.

Definition at line 48 of file udp.c.

◆ udp_xfer_operations

struct interface_operation udp_xfer_operations[]
static
Initial value:
= {
}
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:244
static void udp_close(struct udp_connection *udp, int rc)
Close a UDP connection.
Definition: udp.c:154
struct io_buffer * xfer_alloc_iob(struct interface *intf, size_t len)
Allocate I/O buffer.
Definition: xfer.c:157
A UDP connection.
Definition: udp.c:26
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:193
static int udp_xfer_deliver(struct udp_connection *udp, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram as I/O buffer.
Definition: udp.c:371
static struct io_buffer * udp_xfer_alloc_iob(struct udp_connection *udp, size_t len)
Allocate I/O buffer for UDP.
Definition: udp.c:349

UDP data transfer interface operations.

Definition at line 382 of file udp.c.

◆ __socket_opener

struct socket_opener udp_ipv6_socket_opener __socket_opener
Initial value:
= {
.semantics = UDP_SOCK_DGRAM,
.family = AF_INET,
.open = udp_open,
}
#define UDP_SOCK_DGRAM
Definition: socket.h:28
int udp_open(struct interface *xfer, struct sockaddr *peer, struct sockaddr *local)
Open a UDP connection.
Definition: udp.c:130
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:63

UDP IPv4 socket opener.

UDP IPv6 socket opener.

Definition at line 400 of file udp.c.

◆ __uri_opener

struct uri_opener udp_uri_opener __uri_opener
Initial value:
= {
.scheme = "udp",
.open = udp_open_uri,
}
static int udp_open_uri(struct interface *xfer, struct uri *uri)
Open UDP URI.
Definition: udp.c:423

UDP URI opener.

Definition at line 438 of file udp.c.