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-2020 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 1.9.8
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 {
68 } Icmpv6Type;
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 
240 //ICMPv6 related functions
242 
243 void icmpv6ProcessMessage(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader,
244  const NetBuffer *buffer, size_t offset, uint8_t hopLimit);
245 
247  Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset);
248 
250  Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset);
251 
252 void icmpv6ProcessEchoRequest(NetInterface *interface, Ipv6PseudoHeader *requestPseudoHeader,
253  const NetBuffer *request, size_t requestOffset);
254 
255 error_t icmpv6SendErrorMessage(NetInterface *interface, uint8_t type, uint8_t code,
256  uint32_t parameter, const NetBuffer *ipPacket, size_t ipPacketOffset);
257 
263 
264 //C++ guard
265 #ifdef __cplusplus
266 }
267 #endif
268 
269 #endif
uint32_t pointer
Definition: icmpv6.h:210
void icmpv6DumpDestUnreachableMessage(const Icmpv6DestUnreachableMessage *message)
Dump ICMPv6 Destination Unreachable message.
Definition: icmpv6.c:645
int bool_t
Definition: compiler_port.h:49
void icmpv6DumpPacketTooBigMessage(const Icmpv6PacketTooBigMessage *message)
Dump ICMPv6 Packet Too Big message.
Definition: icmpv6.c:659
void icmpv6ProcessMessage(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, uint8_t hopLimit)
Incoming ICMPv6 message processing.
Definition: icmpv6.c:95
__start_packed struct @72 Icmpv6DestUnreachableMessage
ICMPv6 Destination Unreachable message.
Icmpv6DestUnreachableCode
Destination Unreachable message codes.
Definition: icmpv6.h:75
uint32_t parameter
Definition: icmpv6.h:135
__start_packed struct @70 Icmpv6Header
ICMPv6 header.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:88
uint16_t checksum
Definition: icmpv6.h:121
__start_packed struct @74 Icmpv6TimeExceededMessage
ICMPv6 Time Exceeded message.
Icmpv6Type
ICMPv6 message type.
Definition: icmpv6.h:51
error_t icmpv6EnableMulticastEchoRequest(NetInterface *interface, bool_t enable)
Enable support for multicast Echo Request messages.
Definition: icmpv6.c:68
Icmpv6ParamProblemCode
Parameter Problem message codes.
Definition: icmpv6.h:99
uint8_t ipPacket[]
Definition: ndp.h:430
uint32_t unused
Definition: icmpv6.h:154
void icmpv6ProcessEchoRequest(NetInterface *interface, Ipv6PseudoHeader *requestPseudoHeader, const NetBuffer *request, size_t requestOffset)
Echo Request message processing.
Definition: icmpv6.c:338
error_t
Error codes.
Definition: error.h:42
#define Ipv6PseudoHeader
Definition: ipv6.h:42
__start_packed struct @71 Icmpv6ErrorMessage
ICMPv6 Error message.
#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:468
uint8_t type
Definition: icmpv6.h:119
__start_packed struct _Ipv4Header __end_packed
__start_packed struct @75 Icmpv6ParamProblemMessage
ICMPv6 Parameter Problem message.
void icmpv6ProcessDestUnreachable(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Destination Unreachable message processing.
Definition: icmpv6.c:239
uint8_t data[]
Definition: icmpv6.h:122
void icmpv6DumpMessage(const Icmpv6Header *message)
Dump ICMPv6 message for debugging purpose.
Definition: icmpv6.c:631
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:274
__start_packed struct @76 Icmpv6EchoMessage
ICMPv6 Echo Request and Echo Reply messages.
Icmpv6TimeExceededCode
Time Exceeded message codes.
Definition: icmpv6.h:89
__start_packed struct @73 Icmpv6PacketTooBigMessage
ICMPv6 Packet Too Big message.
uint8_t message[]
Definition: chap.h:152
uint16_t identifier
Definition: icmpv6.h:228
uint8_t code
Definition: icmpv6.h:120
TCP/IP stack core.
void icmpv6DumpEchoMessage(const Icmpv6EchoMessage *message)
Dump ICMPv6 Echo Request or Echo Reply message.
Definition: icmpv6.c:674
void icmpv6DumpErrorMessage(const Icmpv6ErrorMessage *message)
Dump generic ICMPv6 Error message.
Definition: icmpv6.c:690