iPXE
Functions
ping.h File Reference

ICMP ping protocol. More...

#include <ipxe/iobuf.h>
#include <ipxe/tcpip.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
int ping_rx (struct io_buffer *iobuf, struct sockaddr_tcpip *st_src)
 Process ICMP ping reply. More...
 

Detailed Description

ICMP ping protocol.

Definition in file ping.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ ping_rx()

int ping_rx ( struct io_buffer iobuf,
struct sockaddr_tcpip st_src 
)

Process ICMP ping reply.

Parameters
iobufI/O buffer
st_srcSource address
Return values
rcReturn status code

Definition at line 104 of file ping.c.

104  {
105  struct icmp_echo *echo = iobuf->data;
106  struct ping_connection *ping;
107  struct xfer_metadata meta;
108  int rc;
109 
110  /* Sanity check: should already have been checked by ICMP layer */
111  assert ( iob_len ( iobuf ) >= sizeof ( *echo ) );
112 
113  /* Identify connection */
114  ping = ping_demux ( ntohs ( echo->ident ) );
115  DBGC ( ping, "PING %p reply id %#04x seq %#04x\n",
116  ping, ntohs ( echo->ident ), ntohs ( echo->sequence ) );
117  if ( ! ping ) {
118  rc = -ENOTCONN;
119  goto discard;
120  }
121 
122  /* Strip header, construct metadata, and pass data to upper layer */
123  iob_pull ( iobuf, sizeof ( *echo ) );
124  memset ( &meta, 0, sizeof ( meta ) );
125  meta.src = ( ( struct sockaddr * ) st_src );
126  meta.flags = XFER_FL_ABS_OFFSET;
127  meta.offset = ntohs ( echo->sequence );
128  return xfer_deliver ( &ping->xfer, iob_disown ( iobuf ), &meta );
129 
130  discard:
131  free_iob ( iobuf );
132  return rc;
133 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:107
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
Data transfer metadata.
Definition: xfer.h:23
An ICMP echo request/reply.
Definition: icmp.h:30
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition: xfer.h:48
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:153
#define DBGC(...)
Definition: compiler.h:505
A ping connection.
Definition: ping.c:52
#define ntohs(value)
Definition: byteswap.h:137
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:217
static struct ping_connection * ping_demux(unsigned int port)
Identify ping connection by local port number.
Definition: ping.c:76
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define ENOTCONN
The socket is not connected.
Definition: errno.h:570
Generalized socket address structure.
Definition: socket.h:97
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:160
int xfer_deliver(struct interface *intf, struct io_buffer *iobuf, struct xfer_metadata *meta)
Deliver datagram.
Definition: xfer.c:195
void * data
Start of data.
Definition: iobuf.h:53
uint8_t meta
Metadata flags.
Definition: ena.h:14
int ping(const char *hostname, unsigned long timeout, size_t len, unsigned int count, int quiet)
Ping a host.
Definition: pingmgmt.c:70
void * memset(void *dest, int character, size_t len) __nonnull
int echo(void)
Definition: kb.c:133

References assert(), io_buffer::data, DBGC, echo(), ENOTCONN, free_iob(), iob_disown, iob_len(), iob_pull, memset(), meta, ntohs, ping(), ping_demux(), rc, xfer_deliver(), and XFER_FL_ABS_OFFSET.