icmpv6.h
Go to the documentation of this file.
1 /**
2  * @file icmpv6.h
3  * @brief ICMPv6 (Internet Control Message Protocol Version 6)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.0
29  **/
30 
31 #ifndef _ICMPV6_H
32 #define _ICMPV6_H
33 
34 //Dependencies
35 #include "core/net.h"
36 
37 //ICMPv6 statistics support
38 #ifndef ICMPV6_STATS_SUPPORT
39 #if (IP_MIB_SUPPORT == ENABLED)
40  #define ICMPV6_STATS_SUPPORT ENABLED
41 #else
42  #define ICMPV6_STATS_SUPPORT DISABLED
43 #endif
44 #elif (ICMPV6_STATS_SUPPORT != ENABLED && ICMPV6_STATS_SUPPORT != DISABLED)
45  #error ICMPV6_STATS_SUPPORT parameter is not valid
46 #endif
47 
48 //ICMPv6 statistics
49 #if (ICMPV6_STATS_SUPPORT == ENABLED)
50  #define ICMPV6_STATS_INC_COUNTER32(name, value) interface->netContext->icmpv6Stats.name += value
51 #else
52  #define ICMPV6_STATS_INC_COUNTER32(name, value)
53 #endif
54 
55 //C++ guard
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 
61 /**
62  * @brief ICMPv6 message type
63  *
64  * The type field indicates the type of the message. Its
65  * value determines the format of the remaining data
66  *
67  **/
68 
69 typedef enum
70 {
87 
88 
89 /**
90  * @brief Destination Unreachable message codes
91  **/
92 
93 typedef enum
94 {
101 
102 
103 /**
104  * @brief Time Exceeded message codes
105  **/
106 
107 typedef enum
108 {
112 
113 
114 /**
115  * @brief Parameter Problem message codes
116  **/
117 typedef enum
118 {
123 
124 
125 //CC-RX, CodeWarrior or Win32 compiler?
126 #if defined(__CCRX__)
127  #pragma pack
128 #elif defined(__CWCC__) || defined(_WIN32)
129  #pragma pack(push, 1)
130 #endif
131 
132 
133 /**
134  * @brief ICMPv6 header
135  **/
136 
138 {
139  uint8_t type; //0
140  uint8_t code; //1
141  uint16_t checksum; //2-3
142  uint8_t data[]; //4
144 
145 
146 /**
147  * @brief ICMPv6 Error message
148  **/
149 
150 typedef __packed_struct
151 {
152  uint8_t type; //0
153  uint8_t code; //1
154  uint16_t checksum; //2-3
155  uint32_t parameter; //4-7
156  uint8_t data[]; //8
158 
159 
160 /**
161  * @brief ICMPv6 Destination Unreachable message
162  *
163  * A Destination Unreachable message is generated in response to a
164  * packet that cannot be delivered to its destination address for
165  * reasons other than congestion
166  *
167  **/
168 
169 typedef __packed_struct
170 {
171  uint8_t type; //0
172  uint8_t code; //1
173  uint16_t checksum; //2-3
174  uint32_t unused; //4-7
175  uint8_t data[]; //8
177 
178 
179 /**
180  * @brief ICMPv6 Packet Too Big message
181  *
182  * A Packet Too Big message is sent by a router in response
183  * to a packet that it cannot forward because the packet is
184  * larger than the MTU of the outgoing link
185  *
186  **/
187 
188 typedef __packed_struct
189 {
190  uint8_t type; //0
191  uint8_t code; //1
192  uint16_t checksum; //2-3
193  uint32_t mtu; //4-7
194  uint8_t data[]; //8
196 
197 
198 /**
199  * @brief ICMPv6 Time Exceeded message
200  *
201  * A Time Exceeded message is sent by a router when it receives
202  * a packet with a Hop Limit of zero
203  *
204  **/
205 
206 typedef __packed_struct
207 {
208  uint8_t type; //0
209  uint8_t code; //1
210  uint16_t checksum; //2-3
211  uint32_t unused; //4-7
212  uint8_t data[]; //8
214 
215 
216 /**
217  * @brief ICMPv6 Parameter Problem message
218  *
219  * A Parameter Problem message is sent by an IPv6 node when it finds a
220  * problem with a field in the IPv6 header or extension headers such
221  * that it cannot complete processing the packet
222  *
223  **/
224 
225 typedef __packed_struct
226 {
227  uint8_t type; //0
228  uint8_t code; //1
229  uint16_t checksum; //2-3
230  uint32_t pointer; //4-7
231  uint8_t data[]; //8
233 
234 
235 /**
236  * @brief ICMPv6 Echo Request and Echo Reply messages
237  *
238  * Every node must implement an ICMPv6 Echo responder function that
239  * receives Echo Requests and sends corresponding Echo Replies
240  *
241  **/
242 
243 typedef __packed_struct
244 {
245  uint8_t type; //0
246  uint8_t code; //1
247  uint16_t checksum; //2-3
248  uint16_t identifier; //4-6
249  uint16_t sequenceNumber; //7-8
250  uint8_t data[]; //8
252 
253 
254 //CC-RX, CodeWarrior or Win32 compiler?
255 #if defined(__CCRX__)
256  #pragma unpack
257 #elif defined(__CWCC__) || defined(_WIN32)
258  #pragma pack(pop)
259 #endif
260 
261 //ICMPv6 related functions
263 
265  bool_t enable);
266 
267 void icmpv6ProcessMessage(NetInterface *interface,
268  const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
269  size_t offset, const NetRxAncillary *ancillary);
270 
272  const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
273  size_t offset);
274 
276  const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
277  size_t offset);
278 
279 void icmpv6ProcessEchoRequest(NetInterface *interface,
280  const Ipv6PseudoHeader *requestPseudoHeader, const NetBuffer *request,
281  size_t requestOffset);
282 
283 error_t icmpv6SendErrorMessage(NetInterface *interface, uint8_t type,
284  uint8_t code, uint32_t parameter, const NetBuffer *ipPacket,
285  size_t ipPacketOffset);
286 
292 
293 //C++ guard
294 #ifdef __cplusplus
295 }
296 #endif
297 
298 #endif
@ ICMPV6_TYPE_ROUTER_ADV
Definition: icmpv6.h:81
@ ICMPV6_TYPE_PACKET_TOO_BIG
Definition: icmpv6.h:72
@ ICMPV6_TYPE_DEST_UNREACHABLE
Definition: icmpv6.h:71
uint32_t pointer
Definition: icmpv6.h:230
void icmpv6DumpDestUnreachableMessage(const Icmpv6DestUnreachableMessage *message)
Dump ICMPv6 Destination Unreachable message.
Definition: icmpv6.c:700
int bool_t
Definition: compiler_port.h:63
void icmpv6DumpPacketTooBigMessage(const Icmpv6PacketTooBigMessage *message)
Dump ICMPv6 Packet Too Big message.
Definition: icmpv6.c:714
typedef __packed_struct
ICMPv6 header.
Definition: icmpv6.h:138
Icmpv6EchoMessage
Definition: icmpv6.h:251
Icmpv6DestUnreachableCode
Destination Unreachable message codes.
Definition: icmpv6.h:94
uint32_t parameter
Definition: icmpv6.h:155
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t message[]
Definition: chap.h:154
uint16_t checksum
Definition: icmpv6.h:141
void icmpv6ProcessDestUnreachable(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Destination Unreachable message processing.
Definition: icmpv6.c:273
@ ICMPV6_CODE_INVALID_HEADER_FIELD
Definition: icmpv6.h:119
Icmpv6TimeExceededMessage
Definition: icmpv6.h:213
Icmpv6ErrorMessage
Definition: icmpv6.h:157
error_t icmpv6EnableMulticastEchoRequests(NetInterface *interface, bool_t enable)
Enable support for multicast ICMPv6 Echo Request messages.
Definition: icmpv6.c:94
uint8_t type
Definition: coap_common.h:176
Icmpv6Type
ICMPv6 message type.
Definition: icmpv6.h:70
Icmpv6ParamProblemCode
Parameter Problem message codes.
Definition: icmpv6.h:118
@ ICMPV6_TYPE_MCAST_LISTENER_QUERY
Definition: icmpv6.h:77
@ ICMPV6_CODE_UNKNOWN_NEXT_HEADER
Definition: icmpv6.h:120
uint8_t ipPacket[]
Definition: ndp.h:431
@ ICMPV6_TYPE_ECHO_REQUEST
Definition: icmpv6.h:75
uint32_t unused
Definition: icmpv6.h:174
@ ICMPV6_TYPE_ECHO_REPLY
Definition: icmpv6.h:76
Icmpv6ParamProblemMessage
Definition: icmpv6.h:232
error_t
Error codes.
Definition: error.h:43
@ ICMPV6_CODE_REASSEMBLY_TIME_EXCEEDED
Definition: icmpv6.h:110
@ ICMPV6_CODE_ADDR_UNREACHABLE
Definition: icmpv6.h:98
#define Ipv6PseudoHeader
Definition: ipv6.h:42
@ ICMPV6_TYPE_REDIRECT
Definition: icmpv6.h:84
@ ICMPV6_TYPE_MCAST_LISTENER_REPORT_V1
Definition: icmpv6.h:78
void icmpv6ProcessMessage(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Incoming ICMPv6 message processing.
Definition: icmpv6.c:123
@ ICMPV6_CODE_UNKNOWN_IPV6_OPTION
Definition: icmpv6.h:121
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:40
uint16_t sequenceNumber
Definition: icmpv6.h:249
error_t icmpv6SendErrorMessage(NetInterface *interface, uint8_t type, uint8_t code, uint32_t parameter, const NetBuffer *ipPacket, size_t ipPacketOffset)
Send an ICMPv6 Error message.
Definition: icmpv6.c:521
@ ICMPV6_CODE_HOP_LIMIT_EXCEEDED
Definition: icmpv6.h:109
@ ICMPV6_TYPE_NEIGHBOR_ADV
Definition: icmpv6.h:83
void icmpv6ProcessPacketTooBig(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Packet Too Big message processing.
Definition: icmpv6.c:309
uint8_t data[]
Definition: icmpv6.h:142
void icmpv6DumpMessage(const Icmpv6Header *message)
Dump ICMPv6 message for debugging purpose.
Definition: icmpv6.c:686
uint32_t mtu
Definition: icmpv6.h:193
@ ICMPV6_TYPE_ROUTER_SOL
Definition: icmpv6.h:80
@ ICMPV6_CODE_BEYOND_SCOPE_OF_SRC_ADDR
Definition: icmpv6.h:97
error_t icmpv6EnableEchoRequests(NetInterface *interface, bool_t enable)
Enable support for ICMPv6 Echo Request messages.
Definition: icmpv6.c:66
Icmpv6TimeExceededCode
Time Exceeded message codes.
Definition: icmpv6.h:108
void icmpv6ProcessEchoRequest(NetInterface *interface, const Ipv6PseudoHeader *requestPseudoHeader, const NetBuffer *request, size_t requestOffset)
Echo Request message processing.
Definition: icmpv6.c:374
@ ICMPV6_TYPE_MCAST_LISTENER_DONE_V1
Definition: icmpv6.h:79
@ ICMPV6_CODE_ADMIN_PROHIBITED
Definition: icmpv6.h:96
@ ICMPV6_CODE_PORT_UNREACHABLE
Definition: icmpv6.h:99
Icmpv6DestUnreachableMessage
Definition: icmpv6.h:176
@ ICMPV6_CODE_NO_ROUTE_TO_DEST
Definition: icmpv6.h:95
uint16_t identifier
Definition: icmpv6.h:248
uint8_t code
Definition: icmpv6.h:140
@ ICMPV6_TYPE_PARAM_PROBLEM
Definition: icmpv6.h:74
@ ICMPV6_TYPE_MCAST_LISTENER_REPORT_V2
Definition: icmpv6.h:85
Icmpv6Header
Definition: icmpv6.h:143
TCP/IP stack core.
@ ICMPV6_TYPE_NEIGHBOR_SOL
Definition: icmpv6.h:82
void icmpv6DumpEchoMessage(const Icmpv6EchoMessage *message)
Dump ICMPv6 Echo Request or Echo Reply message.
Definition: icmpv6.c:729
void icmpv6DumpErrorMessage(const Icmpv6ErrorMessage *message)
Dump generic ICMPv6 Error message.
Definition: icmpv6.c:745
@ ICMPV6_TYPE_TIME_EXCEEDED
Definition: icmpv6.h:73
Icmpv6PacketTooBigMessage
Definition: icmpv6.h:195