iPXE
Data Structures | Defines | Functions
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...

Defines

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


Define Documentation

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

ICMP echo protocol table.

Definition at line 55 of file icmp.h.

Referenced by icmp_echo_protocol().

Declare an ICMP echo protocol.

ICMPv6 echo protocol.

ICMPv4 echo protocol.

Definition at line 59 of file icmp.h.

#define ICMP_ECHO_REPLY   0

Definition at line 61 of file icmp.h.

Referenced by icmpv4_rx().

#define ICMP_ECHO_REQUEST   8

Definition at line 62 of file icmp.h.

Referenced by icmpv4_rx().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int icmp_tx_echo_request ( struct io_buffer iobuf,
struct sockaddr_tcpip st_dest 
)

Transmit ICMP echo request.

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

Definition at line 105 of file icmp.c.

References io_buffer::data, DBGC, echo(), ENOTSUP, free_iob(), icmp_echo::icmp, icmp_echo_protocol(), icmp_tx_echo(), icmpcol(), icmp_echo::ident, ntohs, rc, icmp_echo_protocol::request, icmp_echo::sequence, sockaddr_tcpip::st_family, and icmp_header::type.

Referenced by ping_deliver().

                                                            {
        struct icmp_echo *echo = iobuf->data;
        struct icmp_echo_protocol *echo_protocol;
        int rc;

        /* Identify ICMP echo protocol */
        echo_protocol = icmp_echo_protocol ( st_dest->st_family );
        if ( ! echo_protocol ) {
                DBGC ( icmpcol ( st_dest ), "ICMP TX echo request unknown "
                       "address family %d\n", st_dest->st_family );
                free_iob ( iobuf );
                return -ENOTSUP;
        }

        /* Set type */
        echo->icmp.type = echo_protocol->request;

        /* Transmit request */
        DBGC ( icmpcol ( st_dest ), "ICMP TX echo request id %04x seq %04x\n",
               ntohs ( echo->ident ), ntohs ( echo->sequence ) );
        if ( ( rc = icmp_tx_echo ( iobuf, st_dest, echo_protocol ) ) != 0 )
                return rc;

        return 0;
}
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.

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

Definition at line 165 of file icmp.c.

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

Referenced by icmpv4_rx(), and icmpv6_rx_echo_request().

                                                                      {
        struct icmp_echo *echo = iobuf->data;
        int rc;

        /* Sanity check */
        if ( iob_len ( iobuf ) < sizeof ( *echo ) ) {
                DBGC ( icmpcol ( st_src ), "ICMP RX echo request too short at "
                       "%zd bytes (min %zd bytes)\n",
                       iob_len ( iobuf ), sizeof ( *echo ) );
                free_iob ( iobuf );
                return -EINVAL;
        }
        DBGC ( icmpcol ( st_src ), "ICMP RX echo request id %04x seq %04x\n",
               ntohs ( echo->ident ), ntohs ( echo->sequence ) );

        /* Transmit echo reply */
        if ( ( rc = icmp_tx_echo_reply ( iobuf, st_src, echo_protocol ) ) != 0 )
                return rc;

        return 0;
}
int icmp_rx_echo_reply ( struct io_buffer iobuf,
struct sockaddr_tcpip st_src 
)

Process a received ICMP echo request.

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

Definition at line 196 of file icmp.c.

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

Referenced by icmpv4_rx(), and icmpv6_rx_echo_reply().

                                                         {
        struct icmp_echo *echo = iobuf->data;
        int rc;

        /* Sanity check */
        if ( iob_len ( iobuf ) < sizeof ( *echo ) ) {
                DBGC ( icmpcol ( st_src ), "ICMP RX echo reply too short at "
                       "%zd bytes (min %zd bytes)\n",
                       iob_len ( iobuf ), sizeof ( *echo ) );
                free_iob ( iobuf );
                return -EINVAL;
        }
        DBGC ( icmpcol ( st_src ), "ICMP RX echo reply id %04x seq %04x\n",
               ntohs ( echo->ident ), ntohs ( echo->sequence ) );

        /* Deliver to ping protocol */
        if ( ( rc = ping_rx ( iobuf, st_src ) ) != 0 )
                return rc;

        return 0;
}