#include <string.h>
#include <errno.h>
#include <gpxe/iobuf.h>
#include <gpxe/in.h>
#include <gpxe/tcpip.h>
#include <gpxe/icmp.h>
Go to the source code of this file.
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| static int | icmp_rx (struct io_buffer *iobuf, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum __unused) |
| Process a received packet. | |
Variables | |
| struct tcpip_protocol icmp_protocol | __tcpip_protocol |
| ICMP TCP/IP protocol. | |
Definition in file icmp.c.
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| static int icmp_rx | ( | struct io_buffer * | iobuf, | |
| struct sockaddr_tcpip * | st_src, | |||
| struct sockaddr_tcpip * | st_dest, | |||
| uint16_t pshdr_csum | __unused | |||
| ) | [static] |
Process a received packet.
| iobuf | I/O buffer | |
| st_src | Partially-filled source address | |
| st_dest | Partially-filled destination address | |
| pshdr_csum | Pseudo-header checksum |
| rc | Return status code |
Definition at line 45 of file icmp.c.
References icmp_header::chksum, io_buffer::data, DBG, DBG_HD, EINVAL, free_iob(), ICMP_ECHO_REQUEST, ICMP_ECHO_RESPONSE, iob_disown, iob_len(), NULL, strerror(), tcpip_chksum(), tcpip_tx(), and icmp_header::type.
00047 { 00048 struct icmp_header *icmp = iobuf->data; 00049 size_t len = iob_len ( iobuf ); 00050 unsigned int csum; 00051 int rc; 00052 00053 /* Sanity check */ 00054 if ( len < sizeof ( *icmp ) ) { 00055 DBG ( "ICMP packet too short at %zd bytes (min %zd bytes)\n", 00056 len, sizeof ( *icmp ) ); 00057 rc = -EINVAL; 00058 goto done; 00059 } 00060 00061 /* Verify checksum */ 00062 csum = tcpip_chksum ( icmp, len ); 00063 if ( csum != 0 ) { 00064 DBG ( "ICMP checksum incorrect (is %04x, should be 0000)\n", 00065 csum ); 00066 DBG_HD ( icmp, len ); 00067 rc = -EINVAL; 00068 goto done; 00069 } 00070 00071 /* We respond only to pings */ 00072 if ( icmp->type != ICMP_ECHO_REQUEST ) { 00073 DBG ( "ICMP ignoring type %d\n", icmp->type ); 00074 rc = 0; 00075 goto done; 00076 } 00077 00078 DBG ( "ICMP responding to ping\n" ); 00079 00080 /* Change type to response and recalculate checksum */ 00081 icmp->type = ICMP_ECHO_RESPONSE; 00082 icmp->chksum = 0; 00083 icmp->chksum = tcpip_chksum ( icmp, len ); 00084 00085 /* Transmit the response */ 00086 if ( ( rc = tcpip_tx ( iob_disown ( iobuf ), &icmp_protocol, st_dest, 00087 st_src, NULL, NULL ) ) != 0 ) { 00088 DBG ( "ICMP could not transmit ping response: %s\n", 00089 strerror ( rc ) ); 00090 goto done; 00091 } 00092 00093 done: 00094 free_iob ( iobuf ); 00095 return rc; 00096 }
struct tcpip_protocol icmp_protocol __tcpip_protocol [read] |
1.5.7.1