1
10
13
14
20
21
22
23
24
25
26
27
28
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
106
107
108
109
110
111
112
113
114
119
120
121
122
123
124
125
126
130
131
132
133
134
135
136
137
138
147
148
149
155
156
157
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
188
189
190
191
193
199
200
202
203
204
209
210
213
214
215
216
217
218
219
220
221
222
224
229
230
231
232
233
234
235
240
241
242
243
244
245
250
251
253
254
255
256
257
258
259
260
261
262
263
264
265
266
273
274
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
341
342
343
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
369
370
371
372
373
374
375
376
377
378
379
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_packet.h"
#include "nx_ip.h"
#include "nx_ipv6.h"
#include "nx_icmpv6.h"
5 includes
#ifdef NX_IPSEC_ENABLE
#include "nx_ipsec.h"
#endif
#ifdef FEATURE_NX_IPV6
#ifndef NX_DISABLE_ICMPV6_ERROR_MESSAGE
...
VOID _nx_icmpv6_send_error_message(NX_IP *ip_ptr, NX_PACKET *offending_packet,
ULONG word1, ULONG error_pointer)
{
NX_PACKET *pkt_ptr;
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_ERROR *icmpv6_error;
UINT bytes_to_copy, i;
ULONG *src_ip, *dest_ip;
ULONG *src_packet, *dest_packet;
UINT payload;
#ifdef NX_IPSEC_ENABLE
VOID *sa = NX_NULL;
UINT ret = 0;
ULONG data_offset;
NXD_ADDRESS src_addr;
NXD_ADDRESS dest_addr;/* ... */
#endif
NX_PACKET_DEBUG(__FILE__, __LINE__, offending_packet);
if (ip_ptr -> nx_ip_icmpv6_packet_process == NX_NULL)
{
return;
}if (ip_ptr -> nx_ip_icmpv6_packet_process == NX_NULL) { ... }
src_ip = (((NX_IPV6_HEADER *)(offending_packet -> nx_packet_ip_header)) -> nx_ip_header_source_ip);
dest_ip = (((NX_IPV6_HEADER *)(offending_packet -> nx_packet_ip_header)) -> nx_ip_header_destination_ip);
if (CHECK_UNSPECIFIED_ADDRESS(src_ip))
{
/* ... */
return;
}if (CHECK_UNSPECIFIED_ADDRESS(src_ip)) { ... }
if (_nx_packet_allocate(ip_ptr -> nx_ip_default_packet_pool, &pkt_ptr, NX_IPv6_ICMP_PACKET, NX_NO_WAIT))
{
return;
}if (_nx_packet_allocate(ip_ptr -> nx_ip_default_packet_pool, &pkt_ptr, NX_IPv6_ICMP_PACKET, NX_NO_WAIT)) { ... }
if ((UINT)(pkt_ptr -> nx_packet_data_end - pkt_ptr -> nx_packet_prepend_ptr) < sizeof(NX_ICMPV6_ERROR))
{
_nx_packet_release(pkt_ptr);
return;
}if ((UINT)(pkt_ptr -> nx_packet_data_end - pkt_ptr -> nx_packet_prepend_ptr) < sizeof(NX_ICMPV6_ERROR)) { ... }
NX_PACKET_DEBUG(__FILE__, __LINE__, pkt_ptr);
pkt_ptr -> nx_packet_ip_version = NX_IP_VERSION_V6;
icmpv6_error = (NX_ICMPV6_ERROR *)(pkt_ptr -> nx_packet_prepend_ptr);
icmpv6_error -> nx_icmpv6_error_header.nx_icmpv6_header_type = (UCHAR)((word1 >> 24) & 0xFF);
icmpv6_error -> nx_icmpv6_error_header.nx_icmpv6_header_code = (UCHAR)((word1 >> 16) & 0xFF);
icmpv6_error -> nx_icmpv6_error_header.nx_icmpv6_header_checksum = 0;
icmpv6_error -> nx_icmpv6_error_pointer = error_pointer;
NX_CHANGE_ULONG_ENDIAN(icmpv6_error -> nx_icmpv6_error_pointer);
/* ... */
bytes_to_copy = (UINT)(offending_packet -> nx_packet_append_ptr - offending_packet -> nx_packet_ip_header);
/* ... */
if ((bytes_to_copy + sizeof(NX_ICMPV6_ERROR) + sizeof(NX_IPV6_HEADER)) >= NX_MINIMUM_IPV6_PATH_MTU)
{
bytes_to_copy = (UINT)(NX_MINIMUM_IPV6_PATH_MTU - (sizeof(NX_IPV6_HEADER) + sizeof(NX_ICMPV6_ERROR)));
}if ((bytes_to_copy + sizeof(NX_ICMPV6_ERROR) + sizeof(NX_IPV6_HEADER)) >= NX_MINIMUM_IPV6_PATH_MTU) { ... }
/* ... */
payload = pkt_ptr -> nx_packet_pool_owner -> nx_packet_pool_payload_size;
if (((INT)((bytes_to_copy + sizeof(NX_IPV6_HEADER) + sizeof(NX_ICMPV6_ERROR) + NX_PHYSICAL_HEADER) - payload)) > 0)
{
bytes_to_copy = (UINT)(payload - (sizeof(NX_IPV6_HEADER) + sizeof(NX_ICMPV6_ERROR) + NX_PHYSICAL_HEADER));
}if (((INT)((bytes_to_copy + sizeof(NX_IPV6_HEADER) + sizeof(NX_ICMPV6_ERROR) + NX_PHYSICAL_HEADER) - payload)) > 0) { ... }
/* ... */
pkt_ptr -> nx_packet_length = bytes_to_copy + (ULONG)sizeof(NX_ICMPV6_ERROR);
pkt_ptr -> nx_packet_append_ptr = pkt_ptr -> nx_packet_prepend_ptr + pkt_ptr -> nx_packet_length;
src_packet = (ULONG *)(offending_packet -> nx_packet_ip_header);
dest_packet = (ULONG *)NX_UCHAR_POINTER_ADD(icmpv6_error, sizeof(NX_ICMPV6_ERROR));
/* ... */
for (i = 0; i < 10; i++)
{
NX_CHANGE_ULONG_ENDIAN(*src_packet);
src_packet++;
}for (i = 0; i < 10; i++) { ... }
src_packet = (ULONG *)(offending_packet -> nx_packet_ip_header);
for (; (INT)bytes_to_copy > 0; bytes_to_copy -= 4)
{
*dest_packet++ = *src_packet++;
}for (; (INT)bytes_to_copy > 0; bytes_to_copy -= 4) { ... }
src_packet = (ULONG *)(offending_packet -> nx_packet_ip_header);
for (i = 0; i < 10; i++)
{
NX_CHANGE_ULONG_ENDIAN(*src_packet);
src_packet++;
}for (i = 0; i < 10; i++) { ... }
/* ... */
if (IPv6_Address_Type(dest_ip) & IPV6_ADDRESS_MULTICAST)
{
if (_nxd_ipv6_interface_find(ip_ptr, dest_ip,
&pkt_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr,
NX_NULL))
{
_nx_packet_release(pkt_ptr);
return;
}if (_nxd_ipv6_interface_find(ip_ptr, dest_ip, &pkt_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr, NX_NULL)) { ... }
}if (IPv6_Address_Type(dest_ip) & IPV6_ADDRESS_MULTICAST) { ... }
else
{
/* ... */
pkt_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr = offending_packet -> nx_packet_address.nx_packet_ipv6_address_ptr;
}else { ... }
/* ... */
if ((pkt_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr == NX_NULL) ||
(pkt_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_state != NX_IPV6_ADDR_STATE_VALID))
{
_nx_packet_release(pkt_ptr);
return;
}if ((pkt_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr == NX_NULL) || (pkt_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_state != NX_IPV6_ADDR_STATE_VALID)) { ... }
#ifdef NX_IPSEC_ENABLE
if (ip_ptr -> nx_ip_packet_egress_sa_lookup != NX_NULL)
{
src_addr.nxd_ip_version = NX_IP_VERSION_V6;
COPY_IPV6_ADDRESS(pkt_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address,
src_addr.nxd_ip_address.v6);
dest_addr.nxd_ip_version = NX_IP_VERSION_V6;
COPY_IPV6_ADDRESS(src_ip, dest_addr.nxd_ip_address.v6);
ret = ip_ptr -> nx_ip_packet_egress_sa_lookup(ip_ptr,
&src_addr,
&dest_addr,
NX_PROTOCOL_ICMPV6,
0,
0,
&data_offset, &sa,
((word1 >> 16) & 0xFFFF));
if (ret == NX_IPSEC_TRAFFIC_BYPASS)
{
sa = NX_NULL;
data_offset = 0;
}if (ret == NX_IPSEC_TRAFFIC_BYPASS) { ... }
else if (ret == NX_IPSEC_TRAFFIC_DROP || ret == NX_IPSEC_TRAFFIC_PENDING_IKEV2)
{
_nx_packet_release(pkt_ptr);
return;
}else if (ret == NX_IPSEC_TRAFFIC_DROP || ret == NX_IPSEC_TRAFFIC_PENDING_IKEV2) { ... }
...}
pkt_ptr -> nx_packet_ipsec_sa_ptr = sa;
/* ... */
#endif
#ifdef NX_DISABLE_ICMPV6_TX_CHECKSUM
compute_checksum = 0;
#endif
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
if (pkt_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 (pkt_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 ((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_ICMPV6_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE)
if (compute_checksum)
#endif
{
checksum = _nx_ip_checksum_compute(pkt_ptr, NX_PROTOCOL_ICMPV6,
(UINT)pkt_ptr -> nx_packet_length,
pkt_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address,
src_ip);
icmpv6_error -> nx_icmpv6_error_header.nx_icmpv6_header_checksum = (USHORT)(~checksum);
NX_CHANGE_USHORT_ENDIAN(icmpv6_error -> nx_icmpv6_error_header.nx_icmpv6_header_checksum);
...}
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
else
{
pkt_ptr -> nx_packet_interface_capability_flag |= NX_INTERFACE_CAPABILITY_ICMPV6_TX_CHECKSUM;
}else { ... }
/* ... */#endif
_nx_ipv6_packet_send(ip_ptr, pkt_ptr, NX_PROTOCOL_ICMPV6, pkt_ptr -> nx_packet_length, 255,
pkt_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address,
src_ip);
return;
}_nx_icmpv6_send_error_message (NX_IP *ip_ptr, NX_PACKET *offending_packet, ULONG word1, ULONG error_pointer) { ... }
/* ... */#endif /* ... */
#endif