iPXE
Functions | Variables
icmpv4.c File Reference

ICMPv4 protocol. More...

#include <string.h>
#include <errno.h>
#include <ipxe/iobuf.h>
#include <ipxe/in.h>
#include <ipxe/tcpip.h>
#include <ipxe/icmp.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int icmpv4_rx (struct io_buffer *iobuf, struct net_device *netdev __unused, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest __unused, uint16_t pshdr_csum __unused)
 Process a received packet. More...
 

Variables

struct icmp_echo_protocol icmpv4_echo_protocol __icmp_echo_protocol
 ICMPv4 echo protocol. More...
 
struct tcpip_protocol icmpv4_protocol __tcpip_protocol
 ICMPv4 TCP/IP protocol. More...
 

Detailed Description

ICMPv4 protocol.

Definition in file icmpv4.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ icmpv4_rx()

static int icmpv4_rx ( struct io_buffer iobuf,
struct net_device *netdev  __unused,
struct sockaddr_tcpip st_src,
struct sockaddr_tcpip *st_dest  __unused,
uint16_t pshdr_csum  __unused 
)
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 51 of file icmpv4.c.

55  {
56  struct icmp_header *icmp = iobuf->data;
57  size_t len = iob_len ( iobuf );
58  unsigned int csum;
59  unsigned int type;
60  int rc;
61 
62  /* Sanity check */
63  if ( len < sizeof ( *icmp ) ) {
64  DBG ( "ICMP packet too short at %zd bytes (min %zd bytes)\n",
65  len, sizeof ( *icmp ) );
66  rc = -EINVAL;
67  goto discard;
68  }
69 
70  /* Verify checksum */
71  csum = tcpip_chksum ( icmp, len );
72  if ( csum != 0 ) {
73  DBG ( "ICMP checksum incorrect (is %04x, should be 0000)\n",
74  csum );
75  DBG_HD ( icmp, len );
76  rc = -EINVAL;
77  goto discard;
78  }
79 
80  /* Handle ICMP packet */
81  type = icmp->type;
82  switch ( type ) {
83  case ICMP_ECHO_REQUEST:
84  return icmp_rx_echo_request ( iobuf, st_src,
85  &icmpv4_echo_protocol );
86  case ICMP_ECHO_REPLY:
87  return icmp_rx_echo_reply ( iobuf, st_src );
88  default:
89  DBG ( "ICMP ignoring type %d\n", type );
90  rc = 0;
91  break;
92  }
93 
94  discard:
95  free_iob ( iobuf );
96  return rc;
97 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBG_HD(...)
Definition: compiler.h:500
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
uint8_t type
Type.
Definition: ena.h:16
uint8_t type
Type.
Definition: icmp.h:21
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
#define ICMP_ECHO_REQUEST
Definition: icmp.h:62
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:44
An ICMP header.
Definition: icmp.h:19
#define ICMP_ECHO_REPLY
Definition: icmp.h:61
int icmp_rx_echo_reply(struct io_buffer *iobuf, struct sockaddr_tcpip *st_src)
Process a received ICMP echo request.
Definition: icmp.c:196
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.
Definition: icmp.c:165
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
uint16_t tcpip_chksum(const void *data, size_t len)
Calculate TCP/IP checkum.
Definition: tcpip.c:203

References io_buffer::data, DBG, DBG_HD, EINVAL, free_iob(), ICMP_ECHO_REPLY, ICMP_ECHO_REQUEST, icmp_rx_echo_reply(), icmp_rx_echo_request(), iob_len(), len, rc, tcpip_chksum(), type, and icmp_header::type.

Variable Documentation

◆ __icmp_echo_protocol

struct icmp_echo_protocol icmpv4_echo_protocol __icmp_echo_protocol
Initial value:
= {
.family = AF_INET,
.request = ICMP_ECHO_REQUEST,
.reply = ICMP_ECHO_REPLY,
.tcpip_protocol = &icmpv4_protocol,
.net_checksum = 0,
}
#define ICMP_ECHO_REQUEST
Definition: icmp.h:62
#define ICMP_ECHO_REPLY
Definition: icmp.h:61
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:63

ICMPv4 echo protocol.

Definition at line 39 of file icmpv4.c.

◆ __tcpip_protocol

struct tcpip_protocol icmpv4_protocol __tcpip_protocol
Initial value:
= {
.name = "ICMPv4",
.rx = icmpv4_rx,
.tcpip_proto = IP_ICMP,
}
static int icmpv4_rx(struct io_buffer *iobuf, struct net_device *netdev __unused, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest __unused, uint16_t pshdr_csum __unused)
Process a received packet.
Definition: icmpv4.c:51
#define IP_ICMP
Definition: in.h:12

ICMPv4 TCP/IP protocol.

Definition at line 100 of file icmpv4.c.