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.

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 ( 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 
) [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.

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(), icmp_header::type, and type.

                                                      {
        struct icmp_header *icmp = iobuf->data;
        size_t len = iob_len ( iobuf );
        unsigned int csum;
        unsigned int type;
        int rc;

        /* Sanity check */
        if ( len < sizeof ( *icmp ) ) {
                DBG ( "ICMP packet too short at %zd bytes (min %zd bytes)\n",
                      len, sizeof ( *icmp ) );
                rc = -EINVAL;
                goto discard;
        }

        /* Verify checksum */
        csum = tcpip_chksum ( icmp, len );
        if ( csum != 0 ) {
                DBG ( "ICMP checksum incorrect (is %04x, should be 0000)\n",
                      csum );
                DBG_HD ( icmp, len );
                rc = -EINVAL;
                goto discard;
        }

        /* Handle ICMP packet */
        type = icmp->type;
        switch ( type ) {
        case ICMP_ECHO_REQUEST:
                return icmp_rx_echo_request ( iobuf, st_src,
                                              &icmpv4_echo_protocol );
        case ICMP_ECHO_REPLY:
                return icmp_rx_echo_reply ( iobuf, st_src );
        default:
                DBG ( "ICMP ignoring type %d\n", type );
                rc = 0;
                break;
        }

 discard:
        free_iob ( iobuf );
        return rc;
}

Variable Documentation

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,
}

ICMPv4 echo protocol.

Definition at line 39 of file icmpv4.c.

struct tcpip_protocol icmpv4_protocol __tcpip_protocol
Initial value:
 {
        .name = "ICMPv4",
        .rx = icmpv4_rx,
        .tcpip_proto = IP_ICMP,
}

ICMPv4 TCP/IP protocol.

Definition at line 100 of file icmpv4.c.