icmp.h
Go to the documentation of this file.
1 /**
2  * @file icmp.h
3  * @brief ICMP (Internet Control Message Protocol)
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 _ICMP_H
32 #define _ICMP_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 ICMP 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 {
67 
68 
69 /**
70  * @brief Destination Unreachable message codes
71  **/
72 
73 typedef enum
74 {
82 
83 
84 /**
85  * @brief Time Exceeded message codes
86  **/
87 
88 typedef enum
89 {
93 
94 
95 //CC-RX, CodeWarrior or Win32 compiler?
96 #if defined(__CCRX__)
97  #pragma pack
98 #elif defined(__CWCC__) || defined(_WIN32)
99  #pragma pack(push, 1)
100 #endif
101 
102 
103 /**
104  * @brief ICMP header
105  **/
106 
108 {
109  uint8_t type; //0
110  uint8_t code; //1
111  uint16_t checksum; //2-3
112  uint8_t data[]; //4
114 
115 
116 /**
117  * @brief ICMP Error message
118  **/
119 
120 typedef __packed_struct
121 {
122  uint8_t type; //0
123  uint8_t code; //1
124  uint16_t checksum; //2-3
125  uint8_t parameter; //4
126  uint8_t unused[3]; //5-7
127  uint8_t data[]; //8
129 
130 
131 /**
132  * @brief ICMP Destination Unreachable message
133  **/
134 
135 typedef __packed_struct
136 {
137  uint8_t type; //0
138  uint8_t code; //1
139  uint16_t checksum; //2-3
140  uint32_t unused; //4-7
141  uint8_t data[]; //8
143 
144 
145 /**
146  * @brief ICMP Time Exceeded message
147  **/
148 
149 typedef __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 ICMP Parameter Problem message
161  **/
162 
163 typedef __packed_struct
164 {
165  uint8_t type; //0
166  uint8_t code; //1
167  uint16_t checksum; //2-3
168  uint8_t pointer; //4
169  uint8_t unused[3]; //5-7
170  uint8_t data[]; //8
172 
173 
174 /**
175  * @brief ICMP Echo Request and Echo Reply messages
176  **/
177 
178 typedef __packed_struct
179 {
180  uint8_t type; //0
181  uint8_t code; //1
182  uint16_t checksum; //2-3
183  uint16_t identifier; //4-5
184  uint16_t sequenceNumber; //6-7
185  uint8_t data[]; //8
187 
188 
189 //CC-RX, CodeWarrior or Win32 compiler?
190 #if defined(__CCRX__)
191  #pragma unpack
192 #elif defined(__CWCC__) || defined(_WIN32)
193  #pragma pack(pop)
194 #endif
195 
196 //ICMP related functions
198 
200  bool_t enable);
201 
202 void icmpProcessMessage(NetInterface *interface,
203  const Ipv4PseudoHeader *requestPseudoHeader, const NetBuffer *buffer,
204  size_t offset);
205 
206 void icmpProcessEchoRequest(NetInterface *interface,
207  const Ipv4PseudoHeader *requestPseudoHeader, const NetBuffer *request,
208  size_t requestOffset);
209 
210 error_t icmpSendErrorMessage(NetInterface *interface, uint8_t type,
211  uint8_t code, uint8_t parameter, const NetBuffer *ipPacket,
212  size_t ipPacketOffset);
213 
214 void icmpUpdateInStats(uint8_t type);
215 void icmpUpdateOutStats(uint8_t type);
216 
217 void icmpDumpMessage(const IcmpHeader *message);
220 
221 //C++ guard
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif
uint16_t checksum
Definition: icmp.h:111
uint16_t sequenceNumber
Definition: icmp.h:184
@ ICMP_TYPE_ADDR_MASK_REQUEST
Definition: icmp.h:64
int bool_t
Definition: compiler_port.h:53
uint8_t pointer
Definition: icmp.h:168
error_t icmpEnableEchoRequests(NetInterface *interface, bool_t enable)
Enable support for ICMP Echo Request messages.
Definition: icmp.c:57
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t message[]
Definition: chap.h:154
@ ICMP_CODE_PROTOCOL_UNREACHABLE
Definition: icmp.h:77
uint8_t type
Definition: coap_common.h:176
@ ICMP_TYPE_TIME_EXCEEDED
Definition: icmp.h:58
uint8_t unused[3]
Definition: icmp.h:126
typedef __packed_struct
ICMP header.
Definition: icmp.h:108
uint8_t parameter
Definition: icmp.h:125
@ ICMP_CODE_NET_UNREACHABLE
Definition: icmp.h:75
@ ICMP_TYPE_PARAM_PROBLEM
Definition: icmp.h:59
IcmpDestUnreachableCode
Destination Unreachable message codes.
Definition: icmp.h:74
IcmpTimeExceededMessage
Definition: icmp.h:156
uint8_t ipPacket[]
Definition: ndp.h:431
IcmpHeader
Definition: icmp.h:113
error_t icmpEnableBroadcastEchoRequests(NetInterface *interface, bool_t enable)
Enable support for broadcast ICMP Echo Request messages.
Definition: icmp.c:84
error_t
Error codes.
Definition: error.h:43
@ ICMP_TYPE_REDIRECT
Definition: icmp.h:56
@ ICMP_CODE_HOST_UNREACHABLE
Definition: icmp.h:76
@ ICMP_TYPE_TIMESTAMP_REPLY
Definition: icmp.h:61
@ ICMP_TYPE_SOURCE_QUENCH
Definition: icmp.h:55
error_t icmpSendErrorMessage(NetInterface *interface, uint8_t type, uint8_t code, uint8_t parameter, const NetBuffer *ipPacket, size_t ipPacketOffset)
Send an ICMP Error message.
Definition: icmp.c:338
#define NetInterface
Definition: net.h:36
IcmpParamProblemMessage
Definition: icmp.h:171
void icmpUpdateInStats(uint8_t type)
Update ICMP input statistics.
Definition: icmp.c:441
IcmpEchoMessage
Definition: icmp.h:186
void icmpUpdateOutStats(uint8_t type)
Update ICMP output statistics.
Definition: icmp.c:516
@ ICMP_TYPE_ECHO_REQUEST
Definition: icmp.h:57
#define Ipv4PseudoHeader
Definition: ipv4.h:39
void icmpDumpEchoMessage(const IcmpEchoMessage *message)
Dump ICMP Echo Request or Echo Reply message.
Definition: icmp.c:609
IcmpTimeExceededCode
Time Exceeded message codes.
Definition: icmp.h:89
@ ICMP_CODE_SOURCE_ROUTE_FAILED
Definition: icmp.h:80
uint16_t identifier
Definition: icmp.h:183
@ ICMP_TYPE_INFO_REPLY
Definition: icmp.h:63
IcmpErrorMessage
Definition: icmp.h:128
@ ICMP_TYPE_DEST_UNREACHABLE
Definition: icmp.h:54
uint8_t code
Definition: icmp.h:110
@ ICMP_TYPE_ECHO_REPLY
Definition: icmp.h:53
void icmpProcessEchoRequest(NetInterface *interface, const Ipv4PseudoHeader *requestPseudoHeader, const NetBuffer *request, size_t requestOffset)
Echo Request message processing.
Definition: icmp.c:193
void icmpDumpMessage(const IcmpHeader *message)
Dump ICMP message for debugging purpose.
Definition: icmp.c:595
@ ICMP_CODE_FRAG_NEEDED_AND_DF_SET
Definition: icmp.h:79
@ ICMP_TYPE_ADDR_MASK_REPLY
Definition: icmp.h:65
@ ICMP_CODE_PORT_UNREACHABLE
Definition: icmp.h:78
@ ICMP_CODE_TTL_EXCEEDED
Definition: icmp.h:90
IcmpDestUnreachableMessage
Definition: icmp.h:142
void icmpProcessMessage(NetInterface *interface, const Ipv4PseudoHeader *requestPseudoHeader, const NetBuffer *buffer, size_t offset)
Incoming ICMP message processing.
Definition: icmp.c:111
void icmpDumpErrorMessage(const IcmpErrorMessage *message)
Dump generic ICMP Error message.
Definition: icmp.c:625
TCP/IP stack core.
@ ICMP_TYPE_INFO_REQUEST
Definition: icmp.h:62
uint8_t data[]
Definition: icmp.h:112
IcmpType
ICMP message type.
Definition: icmp.h:52
@ ICMP_TYPE_TIMESTAMP_REQUEST
Definition: icmp.h:60
@ ICMP_CODE_REASSEMBLY_TIME_EXCEEDED
Definition: icmp.h:91