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-2024 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.4.4
29  **/
30 
31 #ifndef _ICMPV6_H
32 #define _ICMPV6_H
33 
34 //Dependencies
35 #include "core/net.h"
36 
37 //C++ guard
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 
43 /**
44  * @brief ICMPv6 message type
45  *
46  * The type field indicates the type of the message. Its
47  * value determines the format of the remaining data
48  *
49  **/
50 
51 typedef enum
52 {
69 
70 
71 /**
72  * @brief Destination Unreachable message codes
73  **/
74 
75 typedef enum
76 {
83 
84 
85 /**
86  * @brief Time Exceeded message codes
87  **/
88 
89 typedef enum
90 {
94 
95 
96 /**
97  * @brief Parameter Problem message codes
98  **/
99 typedef enum
100 {
105 
106 
107 //CC-RX, CodeWarrior or Win32 compiler?
108 #if defined(__CCRX__)
109  #pragma pack
110 #elif defined(__CWCC__) || defined(_WIN32)
111  #pragma pack(push, 1)
112 #endif
113 
114 
115 /**
116  * @brief ICMPv6 header
117  **/
118 
120 {
121  uint8_t type; //0
122  uint8_t code; //1
123  uint16_t checksum; //2-3
124  uint8_t data[]; //4
126 
127 
128 /**
129  * @brief ICMPv6 Error message
130  **/
131 
132 typedef __packed_struct
133 {
134  uint8_t type; //0
135  uint8_t code; //1
136  uint16_t checksum; //2-3
137  uint32_t parameter; //4-7
138  uint8_t data[]; //8
140 
141 
142 /**
143  * @brief ICMPv6 Destination Unreachable message
144  *
145  * A Destination Unreachable message is generated in response to a
146  * packet that cannot be delivered to its destination address for
147  * reasons other than congestion
148  *
149  **/
150 
151 typedef __packed_struct
152 {
153  uint8_t type; //0
154  uint8_t code; //1
155  uint16_t checksum; //2-3
156  uint32_t unused; //4-7
157  uint8_t data[]; //8
159 
160 
161 /**
162  * @brief ICMPv6 Packet Too Big message
163  *
164  * A Packet Too Big message is sent by a router in response
165  * to a packet that it cannot forward because the packet is
166  * larger than the MTU of the outgoing link
167  *
168  **/
169 
170 typedef __packed_struct
171 {
172  uint8_t type; //0
173  uint8_t code; //1
174  uint16_t checksum; //2-3
175  uint32_t mtu; //4-7
176  uint8_t data[]; //8
178 
179 
180 /**
181  * @brief ICMPv6 Time Exceeded message
182  *
183  * A Time Exceeded message is sent by a router when it receives
184  * a packet with a Hop Limit of zero
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 unused; //4-7
194  uint8_t data[]; //8
196 
197 
198 /**
199  * @brief ICMPv6 Parameter Problem message
200  *
201  * A Parameter Problem message is sent by an IPv6 node when it finds a
202  * problem with a field in the IPv6 header or extension headers such
203  * that it cannot complete processing the packet
204  *
205  **/
206 
207 typedef __packed_struct
208 {
209  uint8_t type; //0
210  uint8_t code; //1
211  uint16_t checksum; //2-3
212  uint32_t pointer; //4-7
213  uint8_t data[]; //8
215 
216 
217 /**
218  * @brief ICMPv6 Echo Request and Echo Reply messages
219  *
220  * Every node must implement an ICMPv6 Echo responder function that
221  * receives Echo Requests and sends corresponding Echo Replies
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  uint16_t identifier; //4-6
231  uint16_t sequenceNumber; //7-8
232  uint8_t data[]; //8
234 
235 
236 //CC-RX, CodeWarrior or Win32 compiler?
237 #if defined(__CCRX__)
238  #pragma unpack
239 #elif defined(__CWCC__) || defined(_WIN32)
240  #pragma pack(pop)
241 #endif
242 
243 //ICMPv6 related functions
245 
247  bool_t enable);
248 
249 void icmpv6ProcessMessage(NetInterface *interface,
250  const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
251  size_t offset, const NetRxAncillary *ancillary);
252 
254  const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
255  size_t offset);
256 
258  const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
259  size_t offset);
260 
261 void icmpv6ProcessEchoRequest(NetInterface *interface,
262  const Ipv6PseudoHeader *requestPseudoHeader, const NetBuffer *request,
263  size_t requestOffset);
264 
265 error_t icmpv6SendErrorMessage(NetInterface *interface, uint8_t type,
266  uint8_t code, uint32_t parameter, const NetBuffer *ipPacket,
267  size_t ipPacketOffset);
268 
274 
275 //C++ guard
276 #ifdef __cplusplus
277 }
278 #endif
279 
280 #endif
@ ICMPV6_TYPE_ROUTER_ADV
Definition: icmpv6.h:63
@ ICMPV6_TYPE_PACKET_TOO_BIG
Definition: icmpv6.h:54
@ ICMPV6_TYPE_DEST_UNREACHABLE
Definition: icmpv6.h:53
uint32_t pointer
Definition: icmpv6.h:212
void icmpv6DumpDestUnreachableMessage(const Icmpv6DestUnreachableMessage *message)
Dump ICMPv6 Destination Unreachable message.
Definition: icmpv6.c:686
int bool_t
Definition: compiler_port.h:53
void icmpv6DumpPacketTooBigMessage(const Icmpv6PacketTooBigMessage *message)
Dump ICMPv6 Packet Too Big message.
Definition: icmpv6.c:700
typedef __packed_struct
ICMPv6 header.
Definition: icmpv6.h:120
Icmpv6EchoMessage
Definition: icmpv6.h:233
Icmpv6DestUnreachableCode
Destination Unreachable message codes.
Definition: icmpv6.h:76
uint32_t parameter
Definition: icmpv6.h:137
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:123
void icmpv6ProcessDestUnreachable(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Destination Unreachable message processing.
Definition: icmpv6.c:267
@ ICMPV6_CODE_INVALID_HEADER_FIELD
Definition: icmpv6.h:101
Icmpv6TimeExceededMessage
Definition: icmpv6.h:195
Icmpv6ErrorMessage
Definition: icmpv6.h:139
error_t icmpv6EnableMulticastEchoRequests(NetInterface *interface, bool_t enable)
Enable support for multicast ICMPv6 Echo Request messages.
Definition: icmpv6.c:95
uint8_t type
Definition: coap_common.h:176
Icmpv6Type
ICMPv6 message type.
Definition: icmpv6.h:52
Icmpv6ParamProblemCode
Parameter Problem message codes.
Definition: icmpv6.h:100
@ ICMPV6_TYPE_MCAST_LISTENER_QUERY
Definition: icmpv6.h:59
@ ICMPV6_CODE_UNKNOWN_NEXT_HEADER
Definition: icmpv6.h:102
uint8_t ipPacket[]
Definition: ndp.h:431
@ ICMPV6_TYPE_ECHO_REQUEST
Definition: icmpv6.h:57
uint32_t unused
Definition: icmpv6.h:156
@ ICMPV6_TYPE_ECHO_REPLY
Definition: icmpv6.h:58
Icmpv6ParamProblemMessage
Definition: icmpv6.h:214
error_t
Error codes.
Definition: error.h:43
@ ICMPV6_CODE_REASSEMBLY_TIME_EXCEEDED
Definition: icmpv6.h:92
@ ICMPV6_CODE_ADDR_UNREACHABLE
Definition: icmpv6.h:80
#define Ipv6PseudoHeader
Definition: ipv6.h:42
@ ICMPV6_TYPE_REDIRECT
Definition: icmpv6.h:66
@ ICMPV6_TYPE_MCAST_LISTENER_REPORT_V1
Definition: icmpv6.h:60
void icmpv6ProcessMessage(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Incoming ICMPv6 message processing.
Definition: icmpv6.c:124
@ ICMPV6_CODE_UNKNOWN_IPV6_OPTION
Definition: icmpv6.h:103
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:36
uint16_t sequenceNumber
Definition: icmpv6.h:231
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:506
@ ICMPV6_CODE_HOP_LIMIT_EXCEEDED
Definition: icmpv6.h:91
@ ICMPV6_TYPE_NEIGHBOR_ADV
Definition: icmpv6.h:65
void icmpv6ProcessPacketTooBig(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Packet Too Big message processing.
Definition: icmpv6.c:303
uint8_t data[]
Definition: icmpv6.h:124
void icmpv6DumpMessage(const Icmpv6Header *message)
Dump ICMPv6 message for debugging purpose.
Definition: icmpv6.c:672
uint32_t mtu
Definition: icmpv6.h:175
@ ICMPV6_TYPE_ROUTER_SOL
Definition: icmpv6.h:62
@ ICMPV6_CODE_BEYOND_SCOPE_OF_SRC_ADDR
Definition: icmpv6.h:79
error_t icmpv6EnableEchoRequests(NetInterface *interface, bool_t enable)
Enable support for ICMPv6 Echo Request messages.
Definition: icmpv6.c:67
Icmpv6TimeExceededCode
Time Exceeded message codes.
Definition: icmpv6.h:90
void icmpv6ProcessEchoRequest(NetInterface *interface, const Ipv6PseudoHeader *requestPseudoHeader, const NetBuffer *request, size_t requestOffset)
Echo Request message processing.
Definition: icmpv6.c:368
@ ICMPV6_TYPE_MCAST_LISTENER_DONE_V1
Definition: icmpv6.h:61
@ ICMPV6_CODE_ADMIN_PROHIBITED
Definition: icmpv6.h:78
@ ICMPV6_CODE_PORT_UNREACHABLE
Definition: icmpv6.h:81
Icmpv6DestUnreachableMessage
Definition: icmpv6.h:158
@ ICMPV6_CODE_NO_ROUTE_TO_DEST
Definition: icmpv6.h:77
uint16_t identifier
Definition: icmpv6.h:230
uint8_t code
Definition: icmpv6.h:122
@ ICMPV6_TYPE_PARAM_PROBLEM
Definition: icmpv6.h:56
@ ICMPV6_TYPE_MCAST_LISTENER_REPORT_V2
Definition: icmpv6.h:67
Icmpv6Header
Definition: icmpv6.h:125
TCP/IP stack core.
@ ICMPV6_TYPE_NEIGHBOR_SOL
Definition: icmpv6.h:64
void icmpv6DumpEchoMessage(const Icmpv6EchoMessage *message)
Dump ICMPv6 Echo Request or Echo Reply message.
Definition: icmpv6.c:715
void icmpv6DumpErrorMessage(const Icmpv6ErrorMessage *message)
Dump generic ICMPv6 Error message.
Definition: icmpv6.c:731
@ ICMPV6_TYPE_TIME_EXCEEDED
Definition: icmpv6.h:55
Icmpv6PacketTooBigMessage
Definition: icmpv6.h:177