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
96
97
98
99
100
101
102
103
104
105
109
110
111
112
113
114
115
116
117
118
119
120
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
250
251
252
253
254
255
256
257
258
259
260
261
262
267
268
269
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
293
294
295
296
297
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
346
351
352
353
354
355
356
357
358
360
361
362
363
364
365
366
367
368
369
370
371
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_packet.h"
#include "nx_ipv6.h"
#include "nx_icmpv6.h"
#ifdef NX_IPSEC_ENABLE
#include "nx_ipsec.h"
#endif
#ifdef FEATURE_NX_IPV6
...
VOID _nx_icmpv6_process_echo_request(NX_IP *ip_ptr, NX_PACKET *packet_ptr)
{
UINT status;
ULONG tmp;
USHORT checksum;
#if defined(NX_DISABLE_ICMPV6_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE)
UINT compute_checksum = 1;
#endif
NX_ICMPV6_HEADER *header_ptr;
NX_IPV6_HEADER *ipv6_header;
ULONG hop_limit = 255;
NXD_ADDRESS dest_addr;
NX_INTERFACE *interface_ptr;
#ifdef NX_IPSEC_ENABLE
ULONG data_offset;
VOID *sa = NX_NULL;
NXD_ADDRESS src_addr;
UINT ret;/* ... */
#endif
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
#ifndef NX_DISABLE_RX_SIZE_CHECKING
if (packet_ptr -> nx_packet_length < sizeof(NX_ICMPV6_ECHO))
{
#ifndef NX_DISABLE_ICMP_INFO
ip_ptr -> nx_ip_icmp_invalid_packets++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (packet_ptr -> nx_packet_length < sizeof(NX_ICMPV6_ECHO)) { ... }
/* ... */#endif
header_ptr = (NX_ICMPV6_HEADER *)packet_ptr -> nx_packet_prepend_ptr;
ipv6_header = (NX_IPV6_HEADER *)packet_ptr -> nx_packet_ip_header;
if (IPv6_Address_Type(ipv6_header -> nx_ip_header_destination_ip) & IPV6_ADDRESS_MULTICAST)
{
interface_ptr = packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_attached;
status = _nxd_ipv6_interface_find(ip_ptr, ipv6_header -> nx_ip_header_source_ip,
&packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr, interface_ptr);
if (status != NX_SUCCESS)
{
_nx_packet_release(packet_ptr);
return;
}if (status != NX_SUCCESS) { ... }
}if (IPv6_Address_Type(ipv6_header -> nx_ip_header_destination_ip) & IPV6_ADDRESS_MULTICAST) { ... }
else
{
if (packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_state != NX_IPV6_ADDR_STATE_VALID)
{
_nx_packet_release(packet_ptr);
return;
}if (packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_state != NX_IPV6_ADDR_STATE_VALID) { ... }
}else { ... }
if (CHECK_UNSPECIFIED_ADDRESS(ipv6_header -> nx_ip_header_source_ip))
{
_nx_packet_release(packet_ptr);
return;
}if (CHECK_UNSPECIFIED_ADDRESS(ipv6_header -> nx_ip_header_source_ip)) { ... }
#ifndef NX_DISABLE_ICMP_INFO
ip_ptr -> nx_ip_pings_received++;/* ... */
#endif
dest_addr.nxd_ip_version = NX_IP_VERSION_V6;
dest_addr.nxd_ip_address.v6[0] = ipv6_header -> nx_ip_header_source_ip[0];
dest_addr.nxd_ip_address.v6[1] = ipv6_header -> nx_ip_header_source_ip[1];
dest_addr.nxd_ip_address.v6[2] = ipv6_header -> nx_ip_header_source_ip[2];
dest_addr.nxd_ip_address.v6[3] = ipv6_header -> nx_ip_header_source_ip[3];
#ifdef NX_IPSEC_ENABLE
src_addr.nxd_ip_version = NX_IP_VERSION_V6;
COPY_IPV6_ADDRESS(packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address,
src_addr.nxd_ip_address.v6);
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_ICMPV6,
0,
0,
&data_offset, &sa, (NX_ICMPV6_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_IPv6_PACKET + data_offset))
{
_nx_packet_release(packet_ptr);
return;
}if ((ULONG)(packet_ptr -> nx_packet_prepend_ptr - packet_ptr -> nx_packet_data_start) < (NX_IPv6_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
header_ptr -> nx_icmpv6_header_type = NX_ICMPV6_ECHO_REPLY_TYPE;
#ifdef NX_DISABLE_ICMPV6_TX_CHECKSUM
compute_checksum = 0;
#endif
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
if (packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_attached -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_ICMPV6_TX_CHECKSUM)
{
compute_checksum = 0;
}if (packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_attached -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_ICMPV6_TX_CHECKSUM) { ... }
/* ... */#endif
#ifdef NX_IPSEC_ENABLE
if ((packet_ptr -> nx_packet_ipsec_sa_ptr != NX_NULL) && (((NX_IPSEC_SA *)(packet_ptr -> nx_packet_ipsec_sa_ptr)) -> nx_ipsec_sa_encryption_method != NX_CRYPTO_NONE))
{
compute_checksum = 1;
}if ((packet_ptr -> nx_packet_ipsec_sa_ptr != NX_NULL) && (((NX_IPSEC_SA *)(packet_ptr -> nx_packet_ipsec_sa_ptr)) -> nx_ipsec_sa_encryption_method != NX_CRYPTO_NONE)) { ... }
/* ... */#endif
#if defined(NX_DISABLE_ICMPV6_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE)
if (compute_checksum)
#endif
{
checksum = header_ptr -> nx_icmpv6_header_checksum;
NX_CHANGE_USHORT_ENDIAN(checksum);
tmp = ((USHORT)(~checksum) & 0xFFFF);
tmp -= (NX_ICMPV6_ECHO_REQUEST_TYPE << 8);
if (tmp > (ULONG)0x80000000)
{
tmp = (tmp & 0xFFFF) - 1;
}if (tmp > (ULONG)0x80000000) { ... }
tmp += (ULONG)(header_ptr -> nx_icmpv6_header_type << 8);
/* ... */
if ((IPv6_Address_Type(ipv6_header -> nx_ip_header_destination_ip) &
IPV6_ADDRESS_MULTICAST) == IPV6_ADDRESS_MULTICAST)
{
header_ptr -> nx_icmpv6_header_checksum = 0;
tmp = _nx_ip_checksum_compute(packet_ptr,
NX_PROTOCOL_ICMPV6,
(UINT)packet_ptr -> nx_packet_length,
packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address,
ipv6_header -> nx_ip_header_source_ip);
tmp = ~tmp;
header_ptr -> nx_icmpv6_header_checksum = (USHORT)(tmp);
NX_CHANGE_USHORT_ENDIAN(header_ptr -> nx_icmpv6_header_checksum);
hop_limit = 255;
}if ((IPv6_Address_Type(ipv6_header -> nx_ip_header_destination_ip) & IPV6_ADDRESS_MULTICAST) == IPV6_ADDRESS_MULTICAST) { ... }
else
{
hop_limit = ip_ptr -> nx_ipv6_hop_limit;
tmp = (tmp >> 16) + (tmp & 0xFFFF);
tmp = (tmp >> 16) + (tmp & 0xFFFF);
header_ptr -> nx_icmpv6_header_checksum = (USHORT)(~tmp);
NX_CHANGE_USHORT_ENDIAN(header_ptr -> nx_icmpv6_header_checksum);
}else { ... }
...}
#if defined(NX_DISABLE_ICMPV6_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY)
else
{
header_ptr -> nx_icmpv6_header_checksum = 0;
if ((IPv6_Address_Type(ipv6_header -> nx_ip_header_destination_ip) &
IPV6_ADDRESS_MULTICAST) == IPV6_ADDRESS_MULTICAST)
{
hop_limit = 255;
}if ((IPv6_Address_Type(ipv6_header -> nx_ip_header_destination_ip) & IPV6_ADDRESS_MULTICAST) == IPV6_ADDRESS_MULTICAST) { ... }
else
{
hop_limit = ip_ptr -> nx_ipv6_hop_limit;
}else { ... }
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
packet_ptr -> nx_packet_interface_capability_flag |= NX_INTERFACE_CAPABILITY_ICMPV6_TX_CHECKSUM;
#endif
}else { ... }
/* ... */#endif
#ifndef NX_DISABLE_ICMP_INFO
ip_ptr -> nx_ip_pings_responded_to++;/* ... */
#endif
_nx_ipv6_packet_send(ip_ptr, packet_ptr, NX_PROTOCOL_ICMPV6,
packet_ptr -> nx_packet_length, hop_limit,
packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address,
dest_addr.nxd_ip_address.v6);
}_nx_icmpv6_process_echo_request (NX_IP *ip_ptr, NX_PACKET *packet_ptr) { ... }
/* ... */
#endif