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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
133
134
135
136
137
138
139
140
141
142
143
144
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
181
182
183
184
185
186
187
188
189
190
195
201
202
203
204
205
206
207
208
209
210
218
219
220
221
222
223
224
230
231
232
233
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
275
276
277
278
279
280
281
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
306
307
308
309
310
311
312
313
314
315
316
317
321
322
323
324
325
326
327
328
329
330
331
332
333
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
382
383
384
385
386
387
388
389
390
391
392
405
406
407
408
409
416
417
418
419
420
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
452
453
455
456
457
458
459
460
461
462
463
464
465
466
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
544
545
546
547
548
549
550
551
558
559
560
561
562
563
564
565
566
567
573
574
575
576
577
578
579
580
581
582
583
584
585
586
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#include "nx_ipv6.h"
#include "nx_packet.h"
#include "nx_icmpv6.h"
5 includes
#ifdef FEATURE_NX_IPV6
...
VOID _nx_ipv6_packet_send(NX_IP *ip_ptr, NX_PACKET *packet_ptr,
ULONG protocol, ULONG payload_size, ULONG hop_limit,
ULONG *src_address, ULONG *dest_address)
{
UINT status = NX_SUCCESS;
ULONG address_type;
UINT next_hop_mtu;
ULONG fragment = NX_TRUE;
#ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
NX_IPV6_DESTINATION_ENTRY *next_hop_dest_entry_ptr;
#endif
NX_IP_DRIVER driver_request;
NX_PACKET *remove_packet;
NX_PACKET *packet_copy;
UINT same_address;
NX_INTERFACE *if_ptr;
NX_IPV6_DESTINATION_ENTRY *dest_entry_ptr;
if_ptr = packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_attached;
NX_ASSERT(if_ptr != NX_NULL);
#ifdef NX_ENABLE_TCPIP_OFFLOAD
if (if_ptr -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCPIP_OFFLOAD)
{
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_invalid_transmit_packets++;/* ... */
#endif
_nx_packet_transmit_release(packet_ptr);
return;
}if (if_ptr -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCPIP_OFFLOAD) { ... }
/* ... */#endif
if (_nx_ipv6_header_add(ip_ptr, &packet_ptr, protocol, payload_size,
hop_limit, src_address, dest_address, &fragment) != NX_SUCCESS)
{
return;
}if (_nx_ipv6_header_add(ip_ptr, &packet_ptr, protocol, payload_size, hop_limit, src_address, dest_address, &fragment) != NX_SUCCESS) { ... }
#ifdef NX_ENABLE_IP_PACKET_FILTER
if (ip_ptr -> nx_ip_packet_filter)
{
if (ip_ptr -> nx_ip_packet_filter((VOID *)(packet_ptr -> nx_packet_prepend_ptr),
NX_IP_PACKET_OUT) != NX_SUCCESS)
{
_nx_packet_transmit_release(packet_ptr);
return;
}if (ip_ptr -> nx_ip_packet_filter((VOID *)(packet_ptr -> nx_packet_prepend_ptr), NX_IP_PACKET_OUT) != NX_SUCCESS) { ... }
}if (ip_ptr -> nx_ip_packet_filter) { ... }
if (ip_ptr -> nx_ip_packet_filter_extended)
{
if (ip_ptr -> nx_ip_packet_filter_extended(ip_ptr, packet_ptr, NX_IP_PACKET_OUT) != NX_SUCCESS)
{
_nx_packet_transmit_release(packet_ptr);
return;
}if (ip_ptr -> nx_ip_packet_filter_extended(ip_ptr, packet_ptr, NX_IP_PACKET_OUT) != NX_SUCCESS) { ... }
}if (ip_ptr -> nx_ip_packet_filter_extended) { ... }
/* ... */#endif
next_hop_mtu = if_ptr -> nx_interface_ip_mtu_size;
packet_ptr -> nx_packet_ip_header = packet_ptr -> nx_packet_prepend_ptr;
same_address = (UINT)CHECK_IPV6_ADDRESSES_SAME(dest_address, src_address);
if (same_address == 1)
{
address_type = IPV6_ADDRESS_LOOPBACK;
}if (same_address == 1) { ... }
else
{
address_type = IPv6_Address_Type(dest_address);
}else { ... }
if (address_type == IPV6_ADDRESS_LOOPBACK)
{
if (_nx_packet_copy(packet_ptr, &packet_copy, ip_ptr -> nx_ip_default_packet_pool, NX_NO_WAIT) == NX_SUCCESS)
{
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
if (packet_copy -> nx_packet_interface_capability_flag)
{
_nx_ip_packet_checksum_compute(packet_copy);
}if (packet_copy -> nx_packet_interface_capability_flag) { ... }
/* ... */#endif
packet_copy -> nx_packet_address.nx_packet_interface_ptr = packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_attached;
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_total_packets_sent++;
ip_ptr -> nx_ip_total_bytes_sent += packet_ptr -> nx_packet_length - (ULONG)sizeof(NX_IPV6_HEADER);/* ... */
#endif
_nx_ip_packet_deferred_receive(ip_ptr, packet_copy);
}if (_nx_packet_copy(packet_ptr, &packet_copy, ip_ptr -> nx_ip_default_packet_pool, NX_NO_WAIT) == NX_SUCCESS) { ... }
#ifndef NX_DISABLE_IP_INFO
else
{
ip_ptr -> nx_ip_send_packets_dropped++;
ip_ptr -> nx_ip_transmit_resource_errors++;
}else { ... }
/* ... */#endif
_nx_packet_transmit_release(packet_ptr);
return;
}if (address_type == IPV6_ADDRESS_LOOPBACK) { ... }
driver_request.nx_ip_driver_ptr = ip_ptr;
driver_request.nx_ip_driver_command = NX_LINK_PACKET_SEND;
driver_request.nx_ip_driver_packet = packet_ptr;
driver_request.nx_ip_driver_interface = NX_NULL;
if (if_ptr -> nx_interface_address_mapping_needed)
{
if ((dest_address[0] & (ULONG)0xFF000000) == (ULONG)0xFF000000)
{
driver_request.nx_ip_driver_physical_address_msw = 0x00003333;
driver_request.nx_ip_driver_physical_address_lsw = dest_address[3];
driver_request.nx_ip_driver_interface = if_ptr;
#ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
/* ... */
status = _nx_icmpv6_dest_table_find(ip_ptr, dest_address, &dest_entry_ptr, 0, 0);
if (status == NX_SUCCESS)
{
next_hop_mtu = dest_entry_ptr -> nx_ipv6_destination_entry_path_mtu;
}if (status == NX_SUCCESS) { ... }
/* ... */
#endif
}if ((dest_address[0] & (ULONG)0xFF000000) == (ULONG)0xFF000000) { ... }
else
{
ND_CACHE_ENTRY *NDCacheEntry = NX_NULL;
ULONG next_hop_address[4];
SET_UNSPECIFIED_ADDRESS(next_hop_address);
status = _nx_icmpv6_dest_table_find(ip_ptr, dest_address, &dest_entry_ptr, 0, 0);
if (status != NX_SUCCESS)
{
/* ... */
if (_nxd_ipv6_search_onlink(ip_ptr, dest_address))
{
COPY_IPV6_ADDRESS(dest_address, next_hop_address);
status = _nx_icmpv6_dest_table_add(ip_ptr, dest_address, &dest_entry_ptr,
next_hop_address, if_ptr -> nx_interface_ip_mtu_size,
NX_WAIT_FOREVER, packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr);
if (status == NX_SUCCESS)
{
NDCacheEntry = dest_entry_ptr -> nx_ipv6_destination_entry_nd_entry;
}if (status == NX_SUCCESS) { ... }
}if (_nxd_ipv6_search_onlink(ip_ptr, dest_address)) { ... }
else if (_nxd_ipv6_router_lookup(ip_ptr, if_ptr, next_hop_address, (void **)&NDCacheEntry) == NX_SUCCESS)
{
status = _nx_icmpv6_dest_table_add(ip_ptr, dest_address, &dest_entry_ptr,
next_hop_address, if_ptr -> nx_interface_ip_mtu_size,
NX_WAIT_FOREVER, packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr);
if ((status == NX_SUCCESS) && !NDCacheEntry)
{
NDCacheEntry = dest_entry_ptr -> nx_ipv6_destination_entry_nd_entry;
}if ((status == NX_SUCCESS) && !NDCacheEntry) { ... }
}else if (_nxd_ipv6_router_lookup(ip_ptr, if_ptr, next_hop_address, /*lint -e{929}*/ (void **)&NDCacheEntry) == NX_SUCCESS) { ... }
if (status)
{
_nx_packet_transmit_release(packet_ptr);
return;
}if (status) { ... }
}if (status != NX_SUCCESS) { ... }
else
{
NDCacheEntry = dest_entry_ptr -> nx_ipv6_destination_entry_nd_entry;
COPY_IPV6_ADDRESS(dest_entry_ptr -> nx_ipv6_destination_entry_next_hop, next_hop_address);
NX_ASSERT(NDCacheEntry -> nx_nd_cache_nd_status != ND_CACHE_STATE_INVALID);
}else { ... }
/* ... */
if ((NDCacheEntry -> nx_nd_cache_nd_status >= ND_CACHE_STATE_REACHABLE) &&
(NDCacheEntry -> nx_nd_cache_nd_status <= ND_CACHE_STATE_PROBE))
{
UCHAR *mac_addr;
mac_addr = NDCacheEntry -> nx_nd_cache_mac_addr;
driver_request.nx_ip_driver_physical_address_msw = ((ULONG)mac_addr[0] << 8) | mac_addr[1];
driver_request.nx_ip_driver_physical_address_lsw =
((ULONG)mac_addr[2] << 24) | ((ULONG)mac_addr[3] << 16) | ((ULONG)mac_addr[4] << 8) | mac_addr[5];
driver_request.nx_ip_driver_interface = if_ptr;
#ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
/* ... */
next_hop_mtu = dest_entry_ptr -> nx_ipv6_destination_entry_path_mtu;
status = _nx_icmpv6_dest_table_find(ip_ptr, next_hop_address, &next_hop_dest_entry_ptr, 0, 0);
if (status == NX_SUCCESS)
{
if ((next_hop_dest_entry_ptr -> nx_ipv6_destination_entry_path_mtu > 0) &&
(next_hop_mtu > next_hop_dest_entry_ptr -> nx_ipv6_destination_entry_path_mtu))
{
next_hop_mtu = next_hop_dest_entry_ptr -> nx_ipv6_destination_entry_path_mtu;
}if ((next_hop_dest_entry_ptr -> nx_ipv6_destination_entry_path_mtu > 0) && (next_hop_mtu > next_hop_dest_entry_ptr -> nx_ipv6_destination_entry_path_mtu)) { ... }
}if (status == NX_SUCCESS) { ... }
/* ... */
#endif
if (NDCacheEntry -> nx_nd_cache_nd_status == ND_CACHE_STATE_STALE)
{
NDCacheEntry -> nx_nd_cache_nd_status = ND_CACHE_STATE_DELAY;
NDCacheEntry -> nx_nd_cache_timer_tick = NX_DELAY_FIRST_PROBE_TIME;
}if (NDCacheEntry -> nx_nd_cache_nd_status == ND_CACHE_STATE_STALE) { ... }
}if ((NDCacheEntry -> nx_nd_cache_nd_status >= ND_CACHE_STATE_REACHABLE) && (NDCacheEntry -> nx_nd_cache_nd_status <= ND_CACHE_STATE_PROBE)) { ... }
else
{
/* ... */
packet_ptr -> nx_packet_queue_next = NX_NULL;
if (NDCacheEntry -> nx_nd_cache_packet_waiting_head == NX_NULL)
{
if (ip_ptr -> nx_ip_icmpv6_packet_process)
{
NDCacheEntry -> nx_nd_cache_packet_waiting_head = packet_ptr;
NDCacheEntry -> nx_nd_cache_packet_waiting_tail = packet_ptr;
NDCacheEntry -> nx_nd_cache_packet_waiting_queue_length = 1;
NX_PACKET_DEBUG(NX_PACKET_ND_WAITING_QUEUE, __LINE__, packet_ptr);
NDCacheEntry -> nx_nd_cache_outgoing_address = packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr;
NDCacheEntry -> nx_nd_cache_interface_ptr = if_ptr;
if (NDCacheEntry -> nx_nd_cache_nd_status == ND_CACHE_STATE_CREATED)
{
NDCacheEntry -> nx_nd_cache_nd_status = ND_CACHE_STATE_INCOMPLETE;
}if (NDCacheEntry -> nx_nd_cache_nd_status == ND_CACHE_STATE_CREATED) { ... }
/* ... */
_nx_icmpv6_send_ns(ip_ptr, next_hop_address,
1, packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr, 0, NDCacheEntry);
NDCacheEntry -> nx_nd_cache_num_solicit = NX_MAX_MULTICAST_SOLICIT - 1;
NDCacheEntry -> nx_nd_cache_timer_tick = ip_ptr -> nx_ipv6_retrans_timer_ticks;
}if (ip_ptr -> nx_ip_icmpv6_packet_process) { ... }
else
{
_nx_packet_transmit_release(packet_ptr);
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_transmit_resource_errors++;
ip_ptr -> nx_ip_send_packets_dropped++;/* ... */
#endif
}else { ... }
return;
}if (NDCacheEntry -> nx_nd_cache_packet_waiting_head == NX_NULL) { ... }
NDCacheEntry -> nx_nd_cache_packet_waiting_tail -> nx_packet_queue_next = packet_ptr;
NDCacheEntry -> nx_nd_cache_packet_waiting_tail = packet_ptr;
NDCacheEntry -> nx_nd_cache_packet_waiting_queue_length++;
NX_PACKET_DEBUG(NX_PACKET_ND_WAITING_QUEUE, __LINE__, packet_ptr);
if (NDCacheEntry -> nx_nd_cache_packet_waiting_queue_length > NX_ND_MAX_QUEUE_DEPTH)
{
remove_packet = NDCacheEntry -> nx_nd_cache_packet_waiting_head;
NDCacheEntry -> nx_nd_cache_packet_waiting_head = remove_packet -> nx_packet_queue_next;
NDCacheEntry -> nx_nd_cache_packet_waiting_queue_length--;
_nx_packet_transmit_release(remove_packet);
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_transmit_resource_errors++;
ip_ptr -> nx_ip_send_packets_dropped++;/* ... */
#endif
}if (NDCacheEntry -> nx_nd_cache_packet_waiting_queue_length > NX_ND_MAX_QUEUE_DEPTH) { ... }
return;
}else { ... }
}else { ... }
}if (if_ptr -> nx_interface_address_mapping_needed) { ... }
else
{
driver_request.nx_ip_driver_physical_address_msw = 0;
driver_request.nx_ip_driver_physical_address_lsw = 0;
driver_request.nx_ip_driver_interface = if_ptr;
}else { ... }
if (packet_ptr -> nx_packet_length > next_hop_mtu)
{
#ifndef NX_DISABLE_FRAGMENTATION
#ifdef NX_IPSEC_ENABLE
if (fragment == NX_TRUE)
{
#endif
_nx_ipv6_fragment_process(&driver_request, next_hop_mtu);
#ifdef NX_IPSEC_ENABLE
}if (fragment == NX_TRUE) { ... }
else
{
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_send_packets_dropped++;/* ... */
#endif
_nx_packet_transmit_release(packet_ptr);
}else { ... }
#endif
/* ... */
#else
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_send_packets_dropped++;/* ... */
#endif
_nx_packet_transmit_release(packet_ptr);/* ... */
#endif
return;
}if (packet_ptr -> nx_packet_length > next_hop_mtu) { ... }
#ifndef NX_DISABLE_IP_INFO
ip_ptr -> nx_ip_total_packets_sent++;
ip_ptr -> nx_ip_total_bytes_sent += packet_ptr -> nx_packet_length - (ULONG)sizeof(NX_IPV6_HEADER);/* ... */
#endif
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
NX_ASSERT(if_ptr -> nx_interface_link_driver_entry != NX_NULL);
(if_ptr -> nx_interface_link_driver_entry)(&driver_request);
}_nx_ipv6_packet_send (NX_IP *ip_ptr, NX_PACKET *packet_ptr, ULONG protocol, ULONG payload_size, ULONG hop_limit, ULONG *src_address, ULONG *dest_address) { ... }
/* ... */
#endif