iPXE
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)
 FILE_SECBOOT (PERMITTED)
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.

Variables

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

Detailed Description

ICMPv4 protocol.

Definition in file icmpv4.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ icmpv4_rx()

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 52 of file icmpv4.c.

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

References __unused, 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, netdev, rc, tcpip_chksum(), icmp_header::type, and 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 AF_INET
IPv4 Internet addresses.
Definition socket.h:64

ICMPv4 echo protocol.

Definition at line 40 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:52
#define IP_ICMP
Definition in.h:13

ICMPv4 TCP/IP protocol.

Definition at line 101 of file icmpv4.c.

101 {
102 .name = "ICMPv4",
103 .rx = icmpv4_rx,
104 .tcpip_proto = IP_ICMP,
105};