iPXE
icmp.h File Reference

ICMP protocol. More...

#include <stdint.h>
#include <ipxe/iobuf.h>
#include <ipxe/socket.h>
#include <ipxe/tcpip.h>
#include <ipxe/tables.h>

Go to the source code of this file.

Data Structures

struct  icmp_header
 An ICMP header. More...
struct  icmp_echo
 An ICMP echo request/reply. More...
struct  icmp_echo_protocol
 An ICMP echo protocol. More...

Macros

#define ICMP_ECHO_PROTOCOLS   __table ( struct icmp_echo_protocol, "icmp_echo_protocols" )
 ICMP echo protocol table.
#define __icmp_echo_protocol   __table_entry ( ICMP_ECHO_PROTOCOLS, 01 )
 Declare an ICMP echo protocol.
#define ICMP_ECHO_REPLY   0
#define ICMP_ECHO_REQUEST   8

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int icmp_tx_echo_request (struct io_buffer *iobuf, struct sockaddr_tcpip *st_dest)
 Transmit ICMP echo request.
int icmp_rx_echo_request (struct io_buffer *iobuf, struct sockaddr_tcpip *st_src, struct icmp_echo_protocol *echo_protocol)
 Process a received ICMP echo request.
int icmp_rx_echo_reply (struct io_buffer *iobuf, struct sockaddr_tcpip *st_src)
 Process a received ICMP echo request.

Detailed Description

ICMP protocol.

Definition in file icmp.h.

Macro Definition Documentation

◆ ICMP_ECHO_PROTOCOLS

#define ICMP_ECHO_PROTOCOLS   __table ( struct icmp_echo_protocol, "icmp_echo_protocols" )

ICMP echo protocol table.

Definition at line 56 of file icmp.h.

56#define ICMP_ECHO_PROTOCOLS \
57 __table ( struct icmp_echo_protocol, "icmp_echo_protocols" )

Referenced by icmp_echo_protocol().

◆ __icmp_echo_protocol

struct icmp_echo_protocol icmpv6_echo_protocol __icmp_echo_protocol   __table_entry ( ICMP_ECHO_PROTOCOLS, 01 )

Declare an ICMP echo protocol.

ICMPv6 echo protocol.

ICMPv4 echo protocol.

Definition at line 60 of file icmp.h.

◆ ICMP_ECHO_REPLY

#define ICMP_ECHO_REPLY   0

Definition at line 62 of file icmp.h.

Referenced by icmpv4_rx().

◆ ICMP_ECHO_REQUEST

#define ICMP_ECHO_REQUEST   8

Definition at line 63 of file icmp.h.

Referenced by icmpv4_rx().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ icmp_tx_echo_request()

int icmp_tx_echo_request ( struct io_buffer * iobuf,
struct sockaddr_tcpip * st_dest )
extern

Transmit ICMP echo request.

Parameters
iobufI/O buffer
st_destDestination socket address
Return values
rcReturn status code

Definition at line 106 of file icmp.c.

107 {
108 struct icmp_echo *echo = iobuf->data;
109 struct icmp_echo_protocol *echo_protocol;
110 int rc;
111
112 /* Identify ICMP echo protocol */
113 echo_protocol = icmp_echo_protocol ( st_dest->st_family );
114 if ( ! echo_protocol ) {
115 DBGC ( icmpcol ( st_dest ), "ICMP TX echo request unknown "
116 "address family %d\n", st_dest->st_family );
117 free_iob ( iobuf );
118 return -ENOTSUP;
119 }
120
121 /* Set type */
122 echo->icmp.type = echo_protocol->request;
123
124 /* Transmit request */
125 DBGC ( icmpcol ( st_dest ), "ICMP TX echo request id %04x seq %04x\n",
126 ntohs ( echo->ident ), ntohs ( echo->sequence ) );
127 if ( ( rc = icmp_tx_echo ( iobuf, st_dest, echo_protocol ) ) != 0 )
128 return rc;
129
130 return 0;
131}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
#define DBGC(...)
Definition compiler.h:530
#define ENOTSUP
Operation not supported.
Definition errno.h:633
static struct icmp_echo_protocol * icmp_echo_protocol(sa_family_t family)
Identify ICMP echo protocol.
Definition icmp.c:49
static int icmp_tx_echo(struct io_buffer *iobuf, struct sockaddr_tcpip *st_dest, struct icmp_echo_protocol *echo_protocol)
Transmit ICMP echo packet.
Definition icmp.c:79
static uint32_t icmpcol(struct sockaddr_tcpip *st_peer)
Determine debugging colour for ICMP debug messages.
Definition icmp.c:66
#define ntohs(value)
Definition byteswap.h:137
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition iobuf.c:153
int echo(void)
Definition kb.c:133
An ICMP echo protocol.
Definition icmp.h:42
uint8_t request
Request type.
Definition icmp.h:46
An ICMP echo request/reply.
Definition icmp.h:30
void * data
Start of data.
Definition iobuf.h:113
sa_family_t st_family
Socket address family (part of struct sockaddr).
Definition tcpip.h:78

References io_buffer::data, DBGC, echo(), ENOTSUP, free_iob(), icmp_echo_protocol(), icmp_tx_echo(), icmpcol(), ntohs, rc, icmp_echo_protocol::request, and sockaddr_tcpip::st_family.

Referenced by ping_deliver().

◆ icmp_rx_echo_request()

int icmp_rx_echo_request ( struct io_buffer * iobuf,
struct sockaddr_tcpip * st_src,
struct icmp_echo_protocol * echo_protocol )
extern

Process a received ICMP echo request.

Parameters
iobufI/O buffer
st_srcSource socket address
echo_protocolICMP echo protocol
Return values
rcReturn status code

Definition at line 170 of file icmp.c.

172 {
173 struct icmp_echo *echo;
174 int rc;
175
176 /* Sanity check */
177 if ( iob_len ( iobuf ) < sizeof ( *echo ) ) {
178 DBGC ( icmpcol ( st_src ), "ICMP RX echo request too short at "
179 "%zd bytes (min %zd bytes)\n",
180 iob_len ( iobuf ), sizeof ( *echo ) );
181 free_iob ( iobuf );
182 return -EINVAL;
183 }
184 echo = iobuf->data;
185 DBGC ( icmpcol ( st_src ), "ICMP RX echo request id %04x seq %04x\n",
186 ntohs ( echo->ident ), ntohs ( echo->sequence ) );
187
188 /* Transmit echo reply */
189 if ( ( rc = icmp_tx_echo_reply ( iobuf, st_src, echo_protocol ) ) != 0 )
190 return rc;
191
192 return 0;
193}
#define EINVAL
Invalid argument.
Definition errno.h:472
static int icmp_tx_echo_reply(struct io_buffer *iobuf, struct sockaddr_tcpip *st_dest, struct icmp_echo_protocol *echo_protocol)
Transmit ICMP echo reply.
Definition icmp.c:140
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition iobuf.h:220

References io_buffer::data, DBGC, echo(), EINVAL, free_iob(), icmp_tx_echo_reply(), icmpcol(), iob_len(), ntohs, and rc.

Referenced by icmpv4_rx(), and icmpv6_rx_echo_request().

◆ icmp_rx_echo_reply()

int icmp_rx_echo_reply ( struct io_buffer * iobuf,
struct sockaddr_tcpip * st_src )
extern

Process a received ICMP echo request.

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

Definition at line 202 of file icmp.c.

203 {
204 struct icmp_echo *echo;
205 int rc;
206
207 /* Sanity check */
208 if ( iob_len ( iobuf ) < sizeof ( *echo ) ) {
209 DBGC ( icmpcol ( st_src ), "ICMP RX echo reply too short at "
210 "%zd bytes (min %zd bytes)\n",
211 iob_len ( iobuf ), sizeof ( *echo ) );
212 free_iob ( iobuf );
213 return -EINVAL;
214 }
215 echo = iobuf->data;
216 DBGC ( icmpcol ( st_src ), "ICMP RX echo reply id %04x seq %04x\n",
217 ntohs ( echo->ident ), ntohs ( echo->sequence ) );
218
219 /* Deliver to ping protocol */
220 if ( ( rc = ping_rx ( iobuf, st_src ) ) != 0 )
221 return rc;
222
223 return 0;
224}
__weak int ping_rx(struct io_buffer *iobuf, struct sockaddr_tcpip *st_src __unused)
Receive ping reply (when no ping protocol is present).
Definition icmp.c:233

References io_buffer::data, DBGC, echo(), EINVAL, free_iob(), icmpcol(), iob_len(), ntohs, ping_rx(), and rc.

Referenced by icmpv4_rx(), and icmpv6_rx_echo_reply().