iPXE
Macros | Functions | Variables
icmpv6.c File Reference

ICMPv6 protocol. More...

#include <string.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/in.h>
#include <ipxe/iobuf.h>
#include <ipxe/tcpip.h>
#include <ipxe/ping.h>
#include <ipxe/icmpv6.h>

Go to the source code of this file.

Macros

#define EHOSTUNREACH_ROUTE   __einfo_error ( EINFO_EHOSTUNREACH_ROUTE )
 
#define EINFO_EHOSTUNREACH_ROUTE
 
#define EHOSTUNREACH_PROHIBITED   __einfo_error ( EINFO_EHOSTUNREACH_PROHIBITED )
 
#define EINFO_EHOSTUNREACH_PROHIBITED
 
#define EHOSTUNREACH_ADDRESS   __einfo_error ( EINFO_EHOSTUNREACH_ADDRESS )
 
#define EINFO_EHOSTUNREACH_ADDRESS
 
#define EHOSTUNREACH_PORT   __einfo_error ( EINFO_EHOSTUNREACH_PORT )
 
#define EINFO_EHOSTUNREACH_PORT
 
#define EHOSTUNREACH_CODE(code)
 
#define ETIMEDOUT_HOP   __einfo_error ( EINFO_ETIMEDOUT_HOP )
 
#define EINFO_ETIMEDOUT_HOP
 
#define ETIMEDOUT_REASSEMBLY   __einfo_error ( EINFO_ETIMEDOUT_REASSEMBLY )
 
#define EINFO_ETIMEDOUT_REASSEMBLY
 
#define ETIMEDOUT_CODE(code)
 
#define EPROTO_BAD_HEADER   __einfo_error ( EINFO_EPROTO_BAD_HEADER )
 
#define EINFO_EPROTO_BAD_HEADER
 
#define EPROTO_NEXT_HEADER   __einfo_error ( EINFO_EPROTO_NEXT_HEADER )
 
#define EINFO_EPROTO_NEXT_HEADER
 
#define EPROTO_OPTION   __einfo_error ( EINFO_EPROTO_OPTION )
 
#define EINFO_EPROTO_OPTION
 
#define EPROTO_CODE(code)
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int icmpv6_rx_echo_request (struct io_buffer *iobuf, struct net_device *netdev __unused, struct sockaddr_in6 *sin6_src, struct sockaddr_in6 *sin6_dest __unused)
 Process received ICMPv6 echo request packet. More...
 
static int icmpv6_rx_echo_reply (struct io_buffer *iobuf, struct net_device *netdev __unused, struct sockaddr_in6 *sin6_src, struct sockaddr_in6 *sin6_dest __unused)
 Process received ICMPv6 echo reply packet. More...
 
static struct icmpv6_handlericmpv6_handler (unsigned int type)
 Identify ICMPv6 handler. More...
 
static int icmpv6_rx (struct io_buffer *iobuf, struct net_device *netdev, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum)
 Process a received packet. More...
 

Variables

struct icmp_echo_protocol icmpv6_echo_protocol __icmp_echo_protocol
 ICMPv6 echo protocol. More...
 
struct icmpv6_handler icmpv6_echo_request_handler __icmpv6_handler
 ICMPv6 echo request handler. More...
 
struct tcpip_protocol icmpv6_protocol __tcpip_protocol
 ICMPv6 TCP/IP protocol. More...
 

Detailed Description

ICMPv6 protocol.

Definition in file icmpv6.c.

Macro Definition Documentation

◆ EHOSTUNREACH_ROUTE

#define EHOSTUNREACH_ROUTE   __einfo_error ( EINFO_EHOSTUNREACH_ROUTE )

Definition at line 42 of file icmpv6.c.

◆ EINFO_EHOSTUNREACH_ROUTE

#define EINFO_EHOSTUNREACH_ROUTE
Value:
"No route to destination" )
#define EINFO_EHOSTUNREACH
Definition: errno.h:404
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 44 of file icmpv6.c.

◆ EHOSTUNREACH_PROHIBITED

#define EHOSTUNREACH_PROHIBITED   __einfo_error ( EINFO_EHOSTUNREACH_PROHIBITED )

Definition at line 47 of file icmpv6.c.

◆ EINFO_EHOSTUNREACH_PROHIBITED

#define EINFO_EHOSTUNREACH_PROHIBITED
Value:
"Communication administratively prohibited" )
#define EINFO_EHOSTUNREACH
Definition: errno.h:404
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 49 of file icmpv6.c.

◆ EHOSTUNREACH_ADDRESS

#define EHOSTUNREACH_ADDRESS   __einfo_error ( EINFO_EHOSTUNREACH_ADDRESS )

Definition at line 52 of file icmpv6.c.

◆ EINFO_EHOSTUNREACH_ADDRESS

#define EINFO_EHOSTUNREACH_ADDRESS
Value:
"Address unreachable" )
#define EINFO_EHOSTUNREACH
Definition: errno.h:404
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 54 of file icmpv6.c.

◆ EHOSTUNREACH_PORT

#define EHOSTUNREACH_PORT   __einfo_error ( EINFO_EHOSTUNREACH_PORT )

Definition at line 57 of file icmpv6.c.

◆ EINFO_EHOSTUNREACH_PORT

#define EINFO_EHOSTUNREACH_PORT
Value:
"Port unreachable" )
#define EINFO_EHOSTUNREACH
Definition: errno.h:404
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 59 of file icmpv6.c.

◆ EHOSTUNREACH_CODE

#define EHOSTUNREACH_CODE (   code)
Value:
EUNIQ ( EINFO_EHOSTUNREACH, ( (code) & 0x1f ), \
#define EHOSTUNREACH_ROUTE
Definition: icmpv6.c:42
#define EHOSTUNREACH_PROHIBITED
Definition: icmpv6.c:47
#define EINFO_EHOSTUNREACH
Definition: errno.h:404
#define EHOSTUNREACH_PORT
Definition: icmpv6.c:57
uint8_t code
Response code.
Definition: scsi.h:16
#define EUNIQ(einfo_base, uniq,...)
Disambiguate a base error based on non-constant information.
Definition: errno.h:225
#define EHOSTUNREACH_ADDRESS
Definition: icmpv6.c:52

Definition at line 62 of file icmpv6.c.

◆ ETIMEDOUT_HOP

#define ETIMEDOUT_HOP   __einfo_error ( EINFO_ETIMEDOUT_HOP )

Definition at line 67 of file icmpv6.c.

◆ EINFO_ETIMEDOUT_HOP

#define EINFO_ETIMEDOUT_HOP
Value:
"Hop limit exceeded in transit" )
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 69 of file icmpv6.c.

◆ ETIMEDOUT_REASSEMBLY

#define ETIMEDOUT_REASSEMBLY   __einfo_error ( EINFO_ETIMEDOUT_REASSEMBLY )

Definition at line 72 of file icmpv6.c.

◆ EINFO_ETIMEDOUT_REASSEMBLY

#define EINFO_ETIMEDOUT_REASSEMBLY
Value:
"Fragment reassembly time exceeded" )
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 74 of file icmpv6.c.

◆ ETIMEDOUT_CODE

#define ETIMEDOUT_CODE (   code)
Value:
EUNIQ ( EINFO_ETIMEDOUT, ( (code) & 0x1f ), \
#define EINFO_ETIMEDOUT
Definition: errno.h:670
#define ETIMEDOUT_HOP
Definition: icmpv6.c:67
uint8_t code
Response code.
Definition: scsi.h:16
#define ETIMEDOUT_REASSEMBLY
Definition: icmpv6.c:72
#define EUNIQ(einfo_base, uniq,...)
Disambiguate a base error based on non-constant information.
Definition: errno.h:225

Definition at line 77 of file icmpv6.c.

◆ EPROTO_BAD_HEADER

#define EPROTO_BAD_HEADER   __einfo_error ( EINFO_EPROTO_BAD_HEADER )

Definition at line 81 of file icmpv6.c.

◆ EINFO_EPROTO_BAD_HEADER

#define EINFO_EPROTO_BAD_HEADER
Value:
"Erroneous header field" )
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180
#define EINFO_EPROTO
Definition: errno.h:625

Definition at line 83 of file icmpv6.c.

◆ EPROTO_NEXT_HEADER

#define EPROTO_NEXT_HEADER   __einfo_error ( EINFO_EPROTO_NEXT_HEADER )

Definition at line 86 of file icmpv6.c.

◆ EINFO_EPROTO_NEXT_HEADER

#define EINFO_EPROTO_NEXT_HEADER
Value:
"Unrecognised next header type" )
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180
#define EINFO_EPROTO
Definition: errno.h:625

Definition at line 88 of file icmpv6.c.

◆ EPROTO_OPTION

#define EPROTO_OPTION   __einfo_error ( EINFO_EPROTO_OPTION )

Definition at line 91 of file icmpv6.c.

◆ EINFO_EPROTO_OPTION

#define EINFO_EPROTO_OPTION
Value:
"Unrecognised IPv6 option" )
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180
#define EINFO_EPROTO
Definition: errno.h:625

Definition at line 93 of file icmpv6.c.

◆ EPROTO_CODE

#define EPROTO_CODE (   code)
Value:
EUNIQ ( EINFO_EPROTO, ( (code) & 0x1f ), \
#define EPROTO_BAD_HEADER
Definition: icmpv6.c:81
uint8_t code
Response code.
Definition: scsi.h:16
#define EUNIQ(einfo_base, uniq,...)
Disambiguate a base error based on non-constant information.
Definition: errno.h:225
#define EPROTO_OPTION
Definition: icmpv6.c:91
#define EPROTO_NEXT_HEADER
Definition: icmpv6.c:86
#define EINFO_EPROTO
Definition: errno.h:625

Definition at line 96 of file icmpv6.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ icmpv6_rx_echo_request()

static int icmpv6_rx_echo_request ( struct io_buffer iobuf,
struct net_device *netdev  __unused,
struct sockaddr_in6 sin6_src,
struct sockaddr_in6 *sin6_dest  __unused 
)
static

Process received ICMPv6 echo request packet.

Parameters
iobufI/O buffer
netdevNetwork device
sin6_srcSource socket address
sin6_destDestination socket address
Return values
rcReturn status code

Definition at line 111 of file icmpv6.c.

114  {
115  struct sockaddr_tcpip *st_src =
116  ( ( struct sockaddr_tcpip * ) sin6_src );
117 
118  return icmp_rx_echo_request ( iobuf, st_src, &icmpv6_echo_protocol );
119 }
TCP/IP socket address.
Definition: tcpip.h:75
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:165

References icmp_rx_echo_request().

◆ icmpv6_rx_echo_reply()

static int icmpv6_rx_echo_reply ( struct io_buffer iobuf,
struct net_device *netdev  __unused,
struct sockaddr_in6 sin6_src,
struct sockaddr_in6 *sin6_dest  __unused 
)
static

Process received ICMPv6 echo reply packet.

Parameters
iobufI/O buffer
netdevNetwork device
sin6_srcSource socket address
sin6_destDestination socket address
Return values
rcReturn status code

Definition at line 136 of file icmpv6.c.

139  {
140  struct sockaddr_tcpip *st_src =
141  ( ( struct sockaddr_tcpip * ) sin6_src );
142 
143  return icmp_rx_echo_reply ( iobuf, st_src );
144 }
TCP/IP socket address.
Definition: tcpip.h:75
int icmp_rx_echo_reply(struct io_buffer *iobuf, struct sockaddr_tcpip *st_src)
Process a received ICMP echo request.
Definition: icmp.c:196

References icmp_rx_echo_reply().

◆ icmpv6_handler()

static struct icmpv6_handler* icmpv6_handler ( unsigned int  type)
static

Identify ICMPv6 handler.

Parameters
typeICMPv6 type
Return values
handlerICMPv6 handler, or NULL if not found

Definition at line 158 of file icmpv6.c.

158  {
159  struct icmpv6_handler *handler;
160 
162  if ( handler->type == type )
163  return handler;
164  }
165  return NULL;
166 }
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
unsigned int type
Type.
Definition: icmpv6.h:21
uint32_t type
Operating system type.
Definition: ena.h:12
An ICMPv6 handler.
Definition: icmpv6.h:19
#define ICMPV6_HANDLERS
ICMPv6 handler table.
Definition: icmpv6.h:38
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References for_each_table_entry, ICMPV6_HANDLERS, NULL, type, and icmpv6_handler::type.

Referenced by icmpv6_rx().

◆ icmpv6_rx()

static int icmpv6_rx ( struct io_buffer iobuf,
struct net_device netdev,
struct sockaddr_tcpip st_src,
struct sockaddr_tcpip st_dest,
uint16_t  pshdr_csum 
)
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 178 of file icmpv6.c.

180  {
181  struct sockaddr_in6 *sin6_src = ( ( struct sockaddr_in6 * ) st_src );
182  struct sockaddr_in6 *sin6_dest = ( ( struct sockaddr_in6 * ) st_dest );
183  struct icmp_header *icmp = iobuf->data;
184  size_t len = iob_len ( iobuf );
185  struct icmpv6_handler *handler;
186  unsigned int csum;
187  int rc;
188 
189  /* Sanity check */
190  if ( len < sizeof ( *icmp ) ) {
191  DBGC ( netdev, "ICMPv6 packet too short at %zd bytes (min %zd "
192  "bytes)\n", len, sizeof ( *icmp ) );
193  rc = -EINVAL;
194  goto done;
195  }
196 
197  /* Verify checksum */
198  csum = tcpip_continue_chksum ( pshdr_csum, icmp, len );
199  if ( csum != 0 ) {
200  DBGC ( netdev, "ICMPv6 checksum incorrect (is %04x, should be "
201  "0000)\n", csum );
202  DBGC_HDA ( netdev, 0, icmp, len );
203  rc = -EINVAL;
204  goto done;
205  }
206 
207  /* Identify handler */
208  handler = icmpv6_handler ( icmp->type );
209  if ( ! handler ) {
210  switch ( icmp->type ) {
212  rc = -EHOSTUNREACH_CODE ( icmp->code );
213  break;
215  rc = -ERANGE;
216  break;
218  rc = -ETIMEDOUT_CODE ( icmp->code );
219  break;
221  rc = -EPROTO_CODE ( icmp->code );
222  break;
223  default:
224  DBGC ( netdev, "ICMPv6 unrecognised type %d code %d\n",
225  icmp->type, icmp->code );
226  rc = -ENOTSUP;
227  break;
228  };
229  goto done;
230  }
231 
232  /* Pass to handler */
233  if ( ( rc = handler->rx ( iob_disown ( iobuf ), netdev, sin6_src,
234  sin6_dest ) ) != 0 ) {
235  DBGC ( netdev, "ICMPv6 could not handle type %d: %s\n",
236  icmp->type, strerror ( rc ) );
237  goto done;
238  }
239 
240  done:
241  free_iob ( iobuf );
242  return rc;
243 }
#define ETIMEDOUT_CODE(code)
Definition: icmpv6.c:77
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int(* rx)(struct io_buffer *iobuf, struct net_device *netdev, struct sockaddr_in6 *sin6_src, struct sockaddr_in6 *sin6_dest)
Process received packet.
Definition: icmpv6.h:32
uint8_t code
Code.
Definition: icmp.h:23
#define ICMPV6_PACKET_TOO_BIG
ICMPv6 packet too big.
Definition: icmpv6.h:47
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define ICMPV6_DESTINATION_UNREACHABLE
ICMPv6 destination unreachable.
Definition: icmpv6.h:44
#define DBGC(...)
Definition: compiler.h:505
#define EHOSTUNREACH_CODE(code)
Definition: icmpv6.c:62
#define EPROTO_CODE(code)
Definition: icmpv6.c:96
uint8_t type
Type.
Definition: icmp.h:21
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:212
#define DBGC_HDA(...)
Definition: compiler.h:506
static struct net_device * netdev
Definition: gdbudp.c:52
#define ICMPV6_PARAMETER_PROBLEM
ICMPv6 parameter problem.
Definition: icmpv6.h:53
#define ERANGE
Result too large.
Definition: errno.h:639
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
static struct icmpv6_handler * icmpv6_handler(unsigned int type)
Identify ICMPv6 handler.
Definition: icmpv6.c:158
uint32_t len
Length.
Definition: ena.h:14
An ICMPv6 handler.
Definition: icmpv6.h:19
void * data
Start of data.
Definition: iobuf.h:48
An ICMP header.
Definition: icmp.h:19
IPv6 socket address.
Definition: in.h:115
#define ICMPV6_TIME_EXCEEDED
ICMPv6 time exceeded.
Definition: icmpv6.h:50
struct bofm_section_header done
Definition: bofm_test.c:46
uint16_t tcpip_continue_chksum(uint16_t partial, const void *data, size_t len)
Calculate continued TCP/IP checkum.
Definition: x86_tcpip.c:45

References icmp_header::code, io_buffer::data, DBGC, DBGC_HDA, done, EHOSTUNREACH_CODE, EINVAL, ENOTSUP, EPROTO_CODE, ERANGE, ETIMEDOUT_CODE, free_iob(), ICMPV6_DESTINATION_UNREACHABLE, icmpv6_handler(), ICMPV6_PACKET_TOO_BIG, ICMPV6_PARAMETER_PROBLEM, ICMPV6_TIME_EXCEEDED, iob_disown, iob_len(), len, netdev, rc, icmpv6_handler::rx, strerror(), tcpip_continue_chksum(), and icmp_header::type.

Variable Documentation

◆ __icmp_echo_protocol

struct icmp_echo_protocol icmpv6_echo_protocol __icmp_echo_protocol
Initial value:
= {
.family = AF_INET6,
.request = ICMPV6_ECHO_REQUEST,
.tcpip_protocol = &icmpv6_protocol,
.net_checksum = 1,
}
#define AF_INET6
IPv6 Internet addresses.
Definition: socket.h:64
#define ICMPV6_ECHO_REPLY
ICMPv6 echo reply.
Definition: icmpv6.h:59
#define ICMPV6_ECHO_REQUEST
ICMPv6 echo request.
Definition: icmpv6.h:56

ICMPv6 echo protocol.

Definition at line 100 of file icmpv6.c.

◆ __icmpv6_handler

struct icmpv6_handler icmpv6_echo_reply_handler __icmpv6_handler
Initial value:
= {
}
#define ICMPV6_ECHO_REQUEST
ICMPv6 echo request.
Definition: icmpv6.h:56
static int icmpv6_rx_echo_request(struct io_buffer *iobuf, struct net_device *netdev __unused, struct sockaddr_in6 *sin6_src, struct sockaddr_in6 *sin6_dest __unused)
Process received ICMPv6 echo request packet.
Definition: icmpv6.c:111

ICMPv6 echo request handler.

ICMPv6 echo reply handler.

Definition at line 122 of file icmpv6.c.

◆ __tcpip_protocol

struct tcpip_protocol icmpv6_protocol __tcpip_protocol
Initial value:
= {
.name = "ICMPv6",
.rx = icmpv6_rx,
.tcpip_proto = IP_ICMP6,
}
#define IP_ICMP6
Definition: in.h:15
static int icmpv6_rx(struct io_buffer *iobuf, struct net_device *netdev, struct sockaddr_tcpip *st_src, struct sockaddr_tcpip *st_dest, uint16_t pshdr_csum)
Process a received packet.
Definition: icmpv6.c:178

ICMPv6 TCP/IP protocol.

ICMPv4 TCP/IP protocol.

Definition at line 246 of file icmpv6.c.