iPXE
Functions
ping.h File Reference

ICMP ping protocol. More...

#include <ipxe/iobuf.h>
#include <ipxe/tcpip.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int ping_rx (struct io_buffer *iobuf, struct sockaddr_tcpip *st_src)
 Process ICMP ping reply.

Detailed Description

ICMP ping protocol.

Definition in file ping.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int ping_rx ( struct io_buffer iobuf,
struct sockaddr_tcpip st_src 
)

Process ICMP ping reply.

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

Definition at line 103 of file ping.c.

References assert, io_buffer::data, DBGC, echo(), ENOTCONN, xfer_metadata::flags, free_iob(), icmp_echo::ident, iob_disown, iob_len(), iob_pull, memset(), ntohs, xfer_metadata::offset, ping(), ping_demux(), rc, icmp_echo::sequence, xfer_metadata::src, ping_connection::xfer, xfer_deliver(), and XFER_FL_ABS_OFFSET.

                                                                       {
        struct icmp_echo *echo = iobuf->data;
        struct ping_connection *ping;
        struct xfer_metadata meta;
        int rc;

        /* Sanity check: should already have been checked by ICMP layer */
        assert ( iob_len ( iobuf ) >= sizeof ( *echo ) );

        /* Identify connection */
        ping = ping_demux ( ntohs ( echo->ident ) );
        DBGC ( ping, "PING %p reply id %#04x seq %#04x\n",
               ping, ntohs ( echo->ident ), ntohs ( echo->sequence ) );
        if ( ! ping ) {
                rc = -ENOTCONN;
                goto discard;
        }

        /* Strip header, construct metadata, and pass data to upper layer */
        iob_pull ( iobuf, sizeof ( *echo ) );
        memset ( &meta, 0, sizeof ( meta ) );
        meta.src = ( ( struct sockaddr * ) st_src );
        meta.flags = XFER_FL_ABS_OFFSET;
        meta.offset = ntohs ( echo->sequence );
        return xfer_deliver ( &ping->xfer, iob_disown ( iobuf ), &meta );

 discard:
        free_iob ( iobuf );
        return rc;
}