1
10
13
14
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
176
177
178
179
180
181
182
183
184
189
190
191
196
197
198
199
200
201
202
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
260
261
262
263
264
265
266
267
268
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_packet.h"
#include "nx_ip.h"
#include "nx_icmp.h"
#ifdef NX_IPSEC_ENABLE
#include "nx_ipsec.h"
#endif
#ifndef NX_DISABLE_IPV4...
...
VOID _nx_icmpv4_process_echo_request(NX_IP *ip_ptr, NX_PACKET *packet_ptr)
{
NX_ICMPV4_HEADER *header_ptr;
ULONG checksum;
ULONG old_m;
#if defined(NX_DISABLE_ICMPV4_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE)
ULONG compute_checksum = 1;
#endif
NX_IPV4_HEADER *ipv4_header;
ULONG next_hop_address = NX_NULL;
#ifdef NX_IPSEC_ENABLE
ULONG data_offset;
VOID *sa = NX_NULL;
NXD_ADDRESS src_addr;
NXD_ADDRESS dest_addr;
UINT ret;/* ... */
#endif
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
header_ptr = (NX_ICMPV4_HEADER *)packet_ptr -> nx_packet_prepend_ptr;
ipv4_header = (NX_IPV4_HEADER *)packet_ptr -> nx_packet_ip_header;
#ifndef NX_DISABLE_ICMP_INFO
ip_ptr -> nx_ip_pings_received++;/* ... */
#endif
header_ptr -> nx_icmpv4_header_type = NX_ICMP_ECHO_REPLY_TYPE;
#ifdef NX_IPSEC_ENABLE
src_addr.nxd_ip_version = NX_IP_VERSION_V4;
src_addr.nxd_ip_address.v4 = packet_ptr -> nx_packet_address.nx_packet_interface_ptr -> nx_interface_ip_address;
dest_addr.nxd_ip_version = NX_IP_VERSION_V4;
dest_addr.nxd_ip_address.v4 = ipv4_header -> nx_ip_header_source_ip;
if (ip_ptr -> nx_ip_packet_egress_sa_lookup != NX_NULL)
{
ret = ip_ptr -> nx_ip_packet_egress_sa_lookup(ip_ptr,
&src_addr,
&dest_addr,
NX_PROTOCOL_ICMP,
0,
0,
&data_offset, &sa, (NX_ICMP_ECHO_REPLY_TYPE << 8));
if (ret == NX_IPSEC_TRAFFIC_PROTECT)
{
if ((ULONG)(packet_ptr -> nx_packet_prepend_ptr - packet_ptr -> nx_packet_data_start) <
(NX_IPv4_PACKET + data_offset))
{
_nx_packet_release(packet_ptr);
return;
}if ((ULONG)(packet_ptr -> nx_packet_prepend_ptr - packet_ptr -> nx_packet_data_start) < (NX_IPv4_PACKET + data_offset)) { ... }
packet_ptr -> nx_packet_ipsec_sa_ptr = sa;
}if (ret == NX_IPSEC_TRAFFIC_PROTECT) { ... }
else if (ret == NX_IPSEC_TRAFFIC_DROP || ret == NX_IPSEC_TRAFFIC_PENDING_IKEV2)
{
_nx_packet_release(packet_ptr);
return;
}else if (ret == NX_IPSEC_TRAFFIC_DROP || ret == NX_IPSEC_TRAFFIC_PENDING_IKEV2) { ... }
else
{
/* ... */
packet_ptr -> nx_packet_ipsec_sa_ptr = NX_NULL;
}else { ... }
}if (ip_ptr -> nx_ip_packet_egress_sa_lookup != NX_NULL) { ... }
/* ... */#endif
#ifdef NX_DISABLE_ICMPV4_TX_CHECKSUM
compute_checksum = 0;
#endif
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
if (packet_ptr -> nx_packet_address.nx_packet_interface_ptr -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_ICMPV4_TX_CHECKSUM)
{
compute_checksum = 0;
}if (packet_ptr -> nx_packet_address.nx_packet_interface_ptr -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_ICMPV4_TX_CHECKSUM) { ... }
/* ... */#endif
#ifdef NX_IPSEC_ENABLE
if ((sa != NX_NULL) && (((NX_IPSEC_SA *)sa) -> nx_ipsec_sa_encryption_method != NX_CRYPTO_NONE))
{
compute_checksum = 1;
}if ((sa != NX_NULL) && (((NX_IPSEC_SA *)sa) -> nx_ipsec_sa_encryption_method != NX_CRYPTO_NONE)) { ... }
/* ... */#endif
#if defined(NX_DISABLE_ICMPV4_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE)
if (compute_checksum)
#endif
{
/* ... */
NX_CHANGE_USHORT_ENDIAN(header_ptr -> nx_icmpv4_header_checksum);
checksum = header_ptr -> nx_icmpv4_header_checksum;
old_m = (ULONG)(NX_ICMP_ECHO_REQUEST_TYPE << 8);
checksum = ((~checksum) & 0xFFFF) + ((~old_m) & 0xFFFF);
checksum = (checksum >> 16) + (checksum & 0xFFFF);
checksum = (checksum >> 16) + (checksum & 0xFFFF);
header_ptr -> nx_icmpv4_header_checksum = (~checksum & NX_LOWER_16_MASK);
/* ... */
NX_CHANGE_USHORT_ENDIAN(header_ptr -> nx_icmpv4_header_checksum);
...}
#if defined(NX_DISABLE_ICMPV4_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY)
else
{
header_ptr -> nx_icmpv4_header_checksum = 0;
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
packet_ptr -> nx_packet_interface_capability_flag |= NX_INTERFACE_CAPABILITY_ICMPV4_TX_CHECKSUM;
#endif
}else { ... }
/* ... */#endif
_nx_ip_route_find(ip_ptr, ipv4_header -> nx_ip_header_source_ip,
&packet_ptr -> nx_packet_address.nx_packet_interface_ptr,
&next_hop_address);
NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_ICMP_RECEIVE, ip_ptr, ipv4_header -> nx_ip_header_source_ip, packet_ptr, 0, NX_TRACE_INTERNAL_EVENTS, 0, 0);
#ifndef NX_DISABLE_ICMP_INFO
ip_ptr -> nx_ip_pings_responded_to++;/* ... */
#endif
_nx_ip_packet_send(ip_ptr, packet_ptr, ipv4_header -> nx_ip_header_source_ip,
NX_IP_NORMAL, NX_IP_TIME_TO_LIVE, NX_IP_ICMP, NX_FRAGMENT_OKAY, next_hop_address);
}{ ... }
#endif/* ... */