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

◆ 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 103 of file ping.c.

103  {
104  struct icmp_echo *echo = iobuf->data;
105  struct ping_connection *ping;
106  struct xfer_metadata meta;
107  int rc;
108 
109  /* Sanity check: should already have been checked by ICMP layer */
110  assert ( iob_len ( iobuf ) >= sizeof ( *echo ) );
111 
112  /* Identify connection */
113  ping = ping_demux ( ntohs ( echo->ident ) );
114  DBGC ( ping, "PING %p reply id %#04x seq %#04x\n",
115  ping, ntohs ( echo->ident ), ntohs ( echo->sequence ) );
116  if ( ! ping ) {
117  rc = -ENOTCONN;
118  goto discard;
119  }
120 
121  /* Strip header, construct metadata, and pass data to upper layer */
122  iob_pull ( iobuf, sizeof ( *echo ) );
123  memset ( &meta, 0, sizeof ( meta ) );
124  meta.src = ( ( struct sockaddr * ) st_src );
125  meta.flags = XFER_FL_ABS_OFFSET;
126  meta.offset = ntohs ( echo->sequence );
127  return xfer_deliver ( &ping->xfer, iob_disown ( iobuf ), &meta );
128 
129  discard:
130  free_iob ( iobuf );
131  return rc;
132 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
Data transfer metadata.
Definition: xfer.h:22
An ICMP echo request/reply.
Definition: icmp.h:29
#define XFER_FL_ABS_OFFSET
Offset is absolute.
Definition: xfer.h:47
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define DBGC(...)
Definition: compiler.h:505
A ping connection.
Definition: ping.c:51
#define ntohs(value)
Definition: byteswap.h:136
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
static struct ping_connection * ping_demux(unsigned int port)
Identify ping connection by local port number.
Definition: ping.c:75
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int meta(WINDOW *, bool)
#define ENOTCONN
The socket is not connected.
Definition: errno.h:569
Generalized socket address structure.
Definition: socket.h:96
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
void * data
Start of data.
Definition: iobuf.h:48
int ping(const char *hostname, unsigned long timeout, size_t len, unsigned int count, int quiet)
Ping a host.
Definition: pingmgmt.c:69
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.