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-2023 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.2.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 //CodeWarrior or Win32 compiler?
108 #if defined(__CWCC__) || defined(_WIN32)
109  #pragma pack(push, 1)
110 #endif
111 
112 
113 /**
114  * @brief ICMPv6 header
115  **/
116 
117 typedef __start_packed struct
118 {
119  uint8_t type; //0
120  uint8_t code; //1
121  uint16_t checksum; //2-3
122  uint8_t data[]; //4
124 
125 
126 /**
127  * @brief ICMPv6 Error message
128  **/
129 
130 typedef __start_packed struct
131 {
132  uint8_t type; //0
133  uint8_t code; //1
134  uint16_t checksum; //2-3
135  uint32_t parameter; //4-7
136  uint8_t data[]; //8
138 
139 
140 /**
141  * @brief ICMPv6 Destination Unreachable message
142  *
143  * A Destination Unreachable message is generated in response to a
144  * packet that cannot be delivered to its destination address for
145  * reasons other than congestion
146  *
147  **/
148 
149 typedef __start_packed struct
150 {
151  uint8_t type; //0
152  uint8_t code; //1
153  uint16_t checksum; //2-3
154  uint32_t unused; //4-7
155  uint8_t data[]; //8
157 
158 
159 /**
160  * @brief ICMPv6 Packet Too Big message
161  *
162  * A Packet Too Big message is sent by a router in response
163  * to a packet that it cannot forward because the packet is
164  * larger than the MTU of the outgoing link
165  *
166  **/
167 
168 typedef __start_packed struct
169 {
170  uint8_t type; //0
171  uint8_t code; //1
172  uint16_t checksum; //2-3
173  uint32_t mtu; //4-7
174  uint8_t data[]; //8
176 
177 
178 /**
179  * @brief ICMPv6 Time Exceeded message
180  *
181  * A Time Exceeded message is sent by a router when it receives
182  * a packet with a Hop Limit of zero
183  *
184  **/
185 
186 typedef __start_packed struct
187 {
188  uint8_t type; //0
189  uint8_t code; //1
190  uint16_t checksum; //2-3
191  uint32_t unused; //4-7
192  uint8_t data[]; //8
194 
195 
196 /**
197  * @brief ICMPv6 Parameter Problem message
198  *
199  * A Parameter Problem message is sent by an IPv6 node when it finds a
200  * problem with a field in the IPv6 header or extension headers such
201  * that it cannot complete processing the packet
202  *
203  **/
204 
205 typedef __start_packed struct
206 {
207  uint8_t type; //0
208  uint8_t code; //1
209  uint16_t checksum; //2-3
210  uint32_t pointer; //4-7
211  uint8_t data[]; //8
213 
214 
215 /**
216  * @brief ICMPv6 Echo Request and Echo Reply messages
217  *
218  * Every node must implement an ICMPv6 Echo responder function that
219  * receives Echo Requests and sends corresponding Echo Replies
220  *
221  **/
222 
223 typedef __start_packed struct
224 {
225  uint8_t type; //0
226  uint8_t code; //1
227  uint16_t checksum; //2-3
228  uint16_t identifier; //4-6
229  uint16_t sequenceNumber; //7-8
230  uint8_t data[]; //8
232 
233 
234 //CodeWarrior or Win32 compiler?
235 #if defined(__CWCC__) || defined(_WIN32)
236  #pragma pack(pop)
237 #endif
238 
239 //ICMPv6 related functions
241 
243  bool_t enable);
244 
245 void icmpv6ProcessMessage(NetInterface *interface,
246  Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset,
247  uint8_t hopLimit);
248 
250  Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset);
251 
253  Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset);
254 
255 void icmpv6ProcessEchoRequest(NetInterface *interface,
256  Ipv6PseudoHeader *requestPseudoHeader, const NetBuffer *request,
257  size_t requestOffset);
258 
259 error_t icmpv6SendErrorMessage(NetInterface *interface, uint8_t type,
260  uint8_t code, uint32_t parameter, const NetBuffer *ipPacket,
261  size_t ipPacketOffset);
262 
268 
269 //C++ guard
270 #ifdef __cplusplus
271 }
272 #endif
273 
274 #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:210
void icmpv6DumpDestUnreachableMessage(const Icmpv6DestUnreachableMessage *message)
Dump ICMPv6 Destination Unreachable message.
Definition: icmpv6.c:685
int bool_t
Definition: compiler_port.h:53
void icmpv6DumpPacketTooBigMessage(const Icmpv6PacketTooBigMessage *message)
Dump ICMPv6 Packet Too Big message.
Definition: icmpv6.c:699
void icmpv6ProcessMessage(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, uint8_t hopLimit)
Incoming ICMPv6 message processing.
Definition: icmpv6.c:123
Icmpv6DestUnreachableCode
Destination Unreachable message codes.
Definition: icmpv6.h:76
uint32_t parameter
Definition: icmpv6.h:135
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
__start_packed struct @5 Icmpv6ParamProblemMessage
ICMPv6 Parameter Problem message.
uint16_t checksum
Definition: icmpv6.h:121
@ ICMPV6_CODE_INVALID_HEADER_FIELD
Definition: icmpv6.h:101
@ ICMPV6_TYPE_MULTICAST_LISTENER_REPORT_V1
Definition: icmpv6.h:60
Icmpv6Type
ICMPv6 message type.
Definition: icmpv6.h:52
error_t icmpv6EnableMulticastEchoRequest(NetInterface *interface, bool_t enable)
Enable support for multicast Echo Request messages.
Definition: icmpv6.c:95
Icmpv6ParamProblemCode
Parameter Problem message codes.
Definition: icmpv6.h:100
__start_packed struct @0 Icmpv6Header
ICMPv6 header.
@ ICMPV6_CODE_UNKNOWN_NEXT_HEADER
Definition: icmpv6.h:102
uint8_t ipPacket[]
Definition: ndp.h:429
@ ICMPV6_TYPE_ECHO_REQUEST
Definition: icmpv6.h:57
uint32_t unused
Definition: icmpv6.h:154
@ ICMPV6_TYPE_ECHO_REPLY
Definition: icmpv6.h:58
void icmpv6ProcessEchoRequest(NetInterface *interface, Ipv6PseudoHeader *requestPseudoHeader, const NetBuffer *request, size_t requestOffset)
Echo Request message processing.
Definition: icmpv6.c:367
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
__start_packed struct @4 Icmpv6TimeExceededMessage
ICMPv6 Time Exceeded message.
@ ICMPV6_CODE_UNKNOWN_IPV6_OPTION
Definition: icmpv6.h:103
#define NetInterface
Definition: net.h:36
uint16_t sequenceNumber
Definition: icmpv6.h:229
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:505
uint8_t type
Definition: icmpv6.h:119
@ ICMPV6_CODE_HOP_LIMIT_EXCEEDED
Definition: icmpv6.h:91
__start_packed struct _Ipv4Header __end_packed
@ ICMPV6_TYPE_NEIGHBOR_ADV
Definition: icmpv6.h:65
void icmpv6ProcessDestUnreachable(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Destination Unreachable message processing.
Definition: icmpv6.c:268
@ ICMPV6_TYPE_MULTICAST_LISTENER_QUERY
Definition: icmpv6.h:59
uint8_t data[]
Definition: icmpv6.h:122
void icmpv6DumpMessage(const Icmpv6Header *message)
Dump ICMPv6 message for debugging purpose.
Definition: icmpv6.c:671
uint32_t mtu
Definition: icmpv6.h:173
void icmpv6ProcessPacketTooBig(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Packet Too Big message processing.
Definition: icmpv6.c:303
__start_packed struct @6 Icmpv6EchoMessage
ICMPv6 Echo Request and Echo Reply messages.
error_t icmpv6EnableEchoRequest(NetInterface *interface, bool_t enable)
Enable support for Echo Request messages.
Definition: icmpv6.c:68
@ ICMPV6_TYPE_ROUTER_SOL
Definition: icmpv6.h:62
@ ICMPV6_CODE_BEYOND_SCOPE_OF_SRC_ADDR
Definition: icmpv6.h:79
__start_packed struct @3 Icmpv6PacketTooBigMessage
ICMPv6 Packet Too Big message.
Icmpv6TimeExceededCode
Time Exceeded message codes.
Definition: icmpv6.h:90
@ ICMPV6_TYPE_MULTICAST_LISTENER_REPORT_V2
Definition: icmpv6.h:67
uint8_t message[]
Definition: chap.h:152
@ ICMPV6_CODE_ADMIN_PROHIBITED
Definition: icmpv6.h:78
@ ICMPV6_CODE_PORT_UNREACHABLE
Definition: icmpv6.h:81
@ ICMPV6_CODE_NO_ROUTE_TO_DEST
Definition: icmpv6.h:77
uint16_t identifier
Definition: icmpv6.h:228
uint8_t code
Definition: icmpv6.h:120
@ ICMPV6_TYPE_PARAM_PROBLEM
Definition: icmpv6.h:56
TCP/IP stack core.
__start_packed struct @2 Icmpv6DestUnreachableMessage
ICMPv6 Destination Unreachable message.
@ ICMPV6_TYPE_NEIGHBOR_SOL
Definition: icmpv6.h:64
void icmpv6DumpEchoMessage(const Icmpv6EchoMessage *message)
Dump ICMPv6 Echo Request or Echo Reply message.
Definition: icmpv6.c:714
void icmpv6DumpErrorMessage(const Icmpv6ErrorMessage *message)
Dump generic ICMPv6 Error message.
Definition: icmpv6.c:730
@ ICMPV6_TYPE_TIME_EXCEEDED
Definition: icmpv6.h:55
__start_packed struct @1 Icmpv6ErrorMessage
ICMPv6 Error message.
@ ICMPV6_TYPE_MULTICAST_LISTENER_DONE_V1
Definition: icmpv6.h:61