1
10
13
14
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
178
179
184
185
186
187
188
189
190
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
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
279
280
281
282
283
284
285
286
287
292
293
294
295
296
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
330
331
332
333
334
335
336
337
338
339
340
344
345
346
347
348
349
350
351
352
353
354
355
359
360
361
362
363
364
365
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
387
388
389
390
391
392
393
394
395
396
397
402
403
404
405
406
410
411
412
413
417
418
419
420
421
422
423
424
425
429
430
431
435
436
437
441
442
443
445
449
450
451
455
456
457
458
463
468
469
470
471
472
473
474
475
476
477
478
479
489
490
491
492
493
497
498
499
500
507
508
509
510
516
517
518
524
525
526
532
533
534
535
536
537
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
570
571
572
580
581
582
583
584
585
586
587
588
589
590
591
593
594
595
596
597
598
599
600
601
602
603
604
611
612
613
619
620
621
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#include "nx_icmp.h"
#include "nx_igmp.h"
#ifdef FEATURE_NX_IPV6
#include "nx_ipv6.h"
#include "nx_icmpv6.h"
/* ... */#endif
#ifdef NX_IPSEC_ENABLE
#include "nx_ipsec.h"
#endif
...
...
VOID _nx_ip_thread_entry(ULONG ip_ptr_value)
{
TX_INTERRUPT_SAVE_AREA
NX_IP_DRIVER driver_request;
NX_IP *ip_ptr;
ULONG ip_events;
NX_PACKET *packet_ptr;
UINT i;
UINT index;
ULONG foo;
#ifdef FEATURE_NX_IPV6
NXD_IPV6_ADDRESS *interface_ipv6_address;
#endif
NX_THREAD_EXTENSION_PTR_GET(ip_ptr, NX_IP, ip_ptr_value)
tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
ip_ptr -> nx_ip_initialize_done = NX_TRUE;
for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++)
{
if ((ip_ptr -> nx_ip_interface[i].nx_interface_valid) && (ip_ptr -> nx_ip_interface[i].nx_interface_link_driver_entry))
{
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
ip_ptr -> nx_ip_interface[i].nx_interface_capability_flag = 0;/* ... */
#endif
ip_ptr -> nx_ip_interface[i].nx_interface_link_up = NX_TRUE;
driver_request.nx_ip_driver_ptr = ip_ptr;
driver_request.nx_ip_driver_command = NX_LINK_INTERFACE_ATTACH;
driver_request.nx_ip_driver_interface = &(ip_ptr -> nx_ip_interface[i]);
(ip_ptr -> nx_ip_interface[i].nx_interface_link_driver_entry)(&driver_request);
#ifdef NX_ENABLE_TCPIP_OFFLOAD
if (ip_ptr -> nx_ip_interface[i].nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCPIP_OFFLOAD)
{
ip_ptr -> nx_ip_interface[i].nx_interface_capability_flag |= NX_INTERFACE_CAPABILITY_CHECKSUM_ALL;
}if (ip_ptr -> nx_ip_interface[i].nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCPIP_OFFLOAD) { ... }
/* ... */#endif
/* ... */
driver_request.nx_ip_driver_ptr = ip_ptr;
driver_request.nx_ip_driver_command = NX_LINK_INITIALIZE;
NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_IO_DRIVER_INITIALIZE, ip_ptr, 0, 0, 0, NX_TRACE_INTERNAL_EVENTS, 0, 0);
/* ... */
(ip_ptr -> nx_ip_interface[i].nx_interface_link_driver_entry)(&driver_request);
driver_request.nx_ip_driver_ptr = ip_ptr;
driver_request.nx_ip_driver_command = NX_LINK_ENABLE;
NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_IO_DRIVER_LINK_ENABLE, ip_ptr, 0, 0, 0, NX_TRACE_INTERNAL_EVENTS, 0, 0);
(ip_ptr -> nx_ip_interface[i].nx_interface_link_driver_entry)(&driver_request);
#ifdef FEATURE_NX_IPV6
interface_ipv6_address = ip_ptr -> nx_ip_interface[i].nxd_interface_ipv6_address_list_head;
while (interface_ipv6_address)
{
ULONG multicast_address[4];
SET_SOLICITED_NODE_MULTICAST_ADDRESS(multicast_address, interface_ipv6_address -> nxd_ipv6_address);
_nx_ipv6_multicast_join(ip_ptr, multicast_address, &ip_ptr -> nx_ip_interface[i]);
interface_ipv6_address = interface_ipv6_address -> nxd_ipv6_address_next;
}while (interface_ipv6_address) { ... }
#ifndef NX_DISABLE_ICMPV6_ROUTER_SOLICITATION
if (ip_ptr -> nx_ipv6_packet_receive)
{
ULONG address[4];
address[0] = 0xFF020000;
address[1] = 0;
address[2] = 0;
address[3] = 1;
_nx_ipv6_multicast_join(ip_ptr, address, &ip_ptr -> nx_ip_interface[i]);
}if (ip_ptr -> nx_ipv6_packet_receive) { ... }
/* ... */#endif/* ... */
#endif
}if ((ip_ptr -> nx_ip_interface[i].nx_interface_valid) && (ip_ptr -> nx_ip_interface[i].nx_interface_link_driver_entry)) { ... }
}for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++) { ... }
for (;;)
{
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
tx_event_flags_get(&(ip_ptr -> nx_ip_events), NX_IP_ALL_EVENTS, TX_OR_CLEAR, &ip_events, TX_WAIT_FOREVER);
tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
#ifdef NX_DRIVER_DEFERRED_PROCESSING
if (ip_events & NX_IP_DRIVER_PACKET_EVENT)
{
while (ip_ptr -> nx_ip_driver_deferred_packet_head)
{
TX_DISABLE
packet_ptr = ip_ptr -> nx_ip_driver_deferred_packet_head;
ip_ptr -> nx_ip_driver_deferred_packet_head = packet_ptr -> nx_packet_queue_next;
if (ip_ptr -> nx_ip_driver_deferred_packet_head == NX_NULL)
{
ip_ptr -> nx_ip_driver_deferred_packet_tail = NX_NULL;
}if (ip_ptr -> nx_ip_driver_deferred_packet_head == NX_NULL) { ... }
TX_RESTORE
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
if (ip_ptr -> nx_ip_driver_deferred_packet_handler)
{
(ip_ptr -> nx_ip_driver_deferred_packet_handler)(ip_ptr, packet_ptr);
}if (ip_ptr -> nx_ip_driver_deferred_packet_handler) { ... }
}while (ip_ptr -> nx_ip_driver_deferred_packet_head) { ... }
ip_events = ip_events & ~(NX_IP_DRIVER_PACKET_EVENT);
if (!ip_events)
{
continue;
}if (!ip_events) { ... }
}if (ip_events & NX_IP_DRIVER_PACKET_EVENT) { ... }
/* ... */#endif
if (ip_events & NX_IP_RECEIVE_EVENT)
{
while (ip_ptr -> nx_ip_deferred_received_packet_head)
{
TX_DISABLE
packet_ptr = ip_ptr -> nx_ip_deferred_received_packet_head;
ip_ptr -> nx_ip_deferred_received_packet_head = packet_ptr -> nx_packet_queue_next;
if (ip_ptr -> nx_ip_deferred_received_packet_head == NX_NULL)
{
ip_ptr -> nx_ip_deferred_received_packet_tail = NX_NULL;
}if (ip_ptr -> nx_ip_deferred_received_packet_head == NX_NULL) { ... }
TX_RESTORE
_nx_ip_packet_receive(ip_ptr, packet_ptr);
}while (ip_ptr -> nx_ip_deferred_received_packet_head) { ... }
ip_events = ip_events & ~(NX_IP_RECEIVE_EVENT);
if (!ip_events)
{
continue;
}if (!ip_events) { ... }
}if (ip_events & NX_IP_RECEIVE_EVENT) { ... }
if (ip_events & NX_IP_TCP_EVENT)
{
(ip_ptr -> nx_ip_tcp_queue_process)(ip_ptr);
ip_events = ip_events & ~(NX_IP_TCP_EVENT);
if (!ip_events)
{
continue;
}if (!ip_events) { ... }
}if (ip_events & NX_IP_TCP_EVENT) { ... }
if (ip_events & NX_IP_FAST_EVENT)
{
/* ... */
#ifdef FEATURE_NX_IPV6
#ifndef NX_DISABLE_IPV6_DAD
if (ip_ptr -> nx_ip_icmpv6_packet_process)
{
for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++)
{
interface_ipv6_address = ip_ptr -> nx_ip_interface[i].nxd_interface_ipv6_address_list_head;
if (interface_ipv6_address &&
interface_ipv6_address -> nxd_ipv6_address_DupAddrDetectTransmit == NX_IPV6_DAD_TRANSMITS)
{
/* ... */
_nx_icmpv6_send_ns(ip_ptr,
interface_ipv6_address -> nxd_ipv6_address,
0, interface_ipv6_address, 0, &ip_ptr -> nx_ipv6_nd_cache[0]);
interface_ipv6_address -> nxd_ipv6_address_DupAddrDetectTransmit--;
}if (interface_ipv6_address && interface_ipv6_address -> nxd_ipv6_address_DupAddrDetectTransmit == NX_IPV6_DAD_TRANSMITS) { ... }
}for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++) { ... }
}if (ip_ptr -> nx_ip_icmpv6_packet_process) { ... }
/* ... */#endif
if (ip_ptr -> nx_nd_cache_fast_periodic_update)
{
ip_ptr -> nx_nd_cache_fast_periodic_update(ip_ptr);
}if (ip_ptr -> nx_nd_cache_fast_periodic_update) { ... }
/* ... */
#endif
if (ip_ptr -> nx_ip_tcp_fast_periodic_processing)
{
(ip_ptr -> nx_ip_tcp_fast_periodic_processing)(ip_ptr);
}if (ip_ptr -> nx_ip_tcp_fast_periodic_processing) { ... }
ip_events = ip_events & ~(NX_IP_FAST_EVENT);
if (!ip_events)
{
continue;
}if (!ip_events) { ... }
}if (ip_events & NX_IP_FAST_EVENT) { ... }
if (ip_events & NX_IP_PERIODIC_EVENT)
{
#ifndef NX_DISABLE_IPV4
if (ip_ptr -> nx_ip_arp_periodic_update)
{
(ip_ptr -> nx_ip_arp_periodic_update)(ip_ptr);
}if (ip_ptr -> nx_ip_arp_periodic_update) { ... }
if (ip_ptr -> nx_ip_rarp_periodic_update)
{
(ip_ptr -> nx_ip_rarp_periodic_update)(ip_ptr);
}if (ip_ptr -> nx_ip_rarp_periodic_update) { ... }
if (ip_ptr -> nx_ip_igmp_periodic_processing)
{
(ip_ptr -> nx_ip_igmp_periodic_processing)(ip_ptr);
}if (ip_ptr -> nx_ip_igmp_periodic_processing) { ... }
/* ... */#endif
/* ... */
if (ip_ptr -> nx_ip_fragment_timeout_check)
{
(ip_ptr -> nx_ip_fragment_timeout_check)(ip_ptr);
}if (ip_ptr -> nx_ip_fragment_timeout_check) { ... }
if (ip_ptr -> nx_ip_tcp_periodic_processing)
{
(ip_ptr -> nx_ip_tcp_periodic_processing)(ip_ptr);
}if (ip_ptr -> nx_ip_tcp_periodic_processing) { ... }
#ifdef FEATURE_NX_IPV6
#ifndef NX_DISABLE_IPV6_DAD
if (ip_ptr -> nx_ip_icmpv6_packet_process)
{
_nx_icmpv6_perform_DAD(ip_ptr);
}if (ip_ptr -> nx_ip_icmpv6_packet_process) { ... }
/* ... */#endif
if (ip_ptr -> nx_nd_cache_slow_periodic_update)
{
ip_ptr -> nx_nd_cache_slow_periodic_update(ip_ptr);
}if (ip_ptr -> nx_nd_cache_slow_periodic_update) { ... }
_nxd_ipv6_prefix_router_timer_tick(ip_ptr);
#ifndef NX_DISABLE_ICMPV6_ROUTER_SOLICITATION
_nxd_ipv6_router_solicitation_check(ip_ptr);
#endif
#ifdef NX_IPSEC_ENABLE
_nx_ipsec_sa_lifetime_tick(ip_ptr);
#endif
#ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
if (ip_ptr -> nx_destination_table_periodic_update)
{
/* ... */
ip_ptr -> nx_destination_table_periodic_update(ip_ptr);
}if (ip_ptr -> nx_destination_table_periodic_update) { ... }
/* ... */#endif
/* ... */
#endif
ip_events = ip_events & ~(NX_IP_PERIODIC_EVENT);
if (!ip_events)
{
continue;
}if (!ip_events) { ... }
}if (ip_events & NX_IP_PERIODIC_EVENT) { ... }
#ifdef NX_IPSEC_ENABLE
if (ip_events & NX_IP_HW_DONE_EVENT)
{
_nx_ipsec_hw_packet_process(ip_ptr);
}if (ip_events & NX_IP_HW_DONE_EVENT) { ... }
/* ... */#endif
#ifndef NX_DISABLE_IPV4
if ((ip_events & NX_IP_ARP_REC_EVENT) && (ip_ptr -> nx_ip_arp_queue_process))
{
(ip_ptr -> nx_ip_arp_queue_process)(ip_ptr);
}if ((ip_events & NX_IP_ARP_REC_EVENT) && (ip_ptr -> nx_ip_arp_queue_process)) { ... }
if ((ip_events & NX_IP_RARP_REC_EVENT) && (ip_ptr -> nx_ip_rarp_queue_process))
{
(ip_ptr -> nx_ip_rarp_queue_process)(ip_ptr);
}if ((ip_events & NX_IP_RARP_REC_EVENT) && (ip_ptr -> nx_ip_rarp_queue_process)) { ... }
if (ip_events & NX_IP_IGMP_EVENT)
{
(ip_ptr -> nx_ip_igmp_queue_process)(ip_ptr);
}if (ip_events & NX_IP_IGMP_EVENT) { ... }
if (ip_events & NX_IP_IGMP_ENABLE_EVENT)
{
/* ... */
for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++)
{
if (ip_ptr -> nx_ip_interface[i].nx_interface_valid)
{
driver_request.nx_ip_driver_ptr = ip_ptr;
driver_request.nx_ip_driver_command = NX_LINK_MULTICAST_JOIN;
driver_request.nx_ip_driver_physical_address_msw = NX_IP_MULTICAST_UPPER;
driver_request.nx_ip_driver_physical_address_lsw = NX_IP_MULTICAST_LOWER | (NX_ALL_HOSTS_ADDRESS & NX_IP_MULTICAST_MASK);
driver_request.nx_ip_driver_interface = &(ip_ptr -> nx_ip_interface[i]);
NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_IO_DRIVER_MULTICAST_JOIN, ip_ptr, 0, 0, 0, NX_TRACE_INTERNAL_EVENTS, 0, 0);
(ip_ptr -> nx_ip_interface[i].nx_interface_link_driver_entry)(&driver_request);
}if (ip_ptr -> nx_ip_interface[i].nx_interface_valid) { ... }
}for (i = 0; i < NX_MAX_PHYSICAL_INTERFACES; i++) { ... }
}if (ip_events & NX_IP_IGMP_ENABLE_EVENT) { ... }
/* ... */#endif
if (ip_events & NX_IP_UNFRAG_EVENT)
{
if (ip_ptr -> nx_ip_fragment_assembly)
{
(ip_ptr -> nx_ip_fragment_assembly)(ip_ptr);
}if (ip_ptr -> nx_ip_fragment_assembly) { ... }
}if (ip_events & NX_IP_UNFRAG_EVENT) { ... }
#ifndef NX_DISABLE_IPV4
if (ip_events & NX_IP_ICMP_EVENT)
{
(ip_ptr -> nx_ip_icmp_queue_process)(ip_ptr);
}if (ip_events & NX_IP_ICMP_EVENT) { ... }
/* ... */#endif
if (ip_events & NX_IP_DRIVER_DEFERRED_EVENT)
{
for (index = 0; index < NX_MAX_PHYSICAL_INTERFACES; index++)
{
if (ip_ptr -> nx_ip_interface[index].nx_interface_valid)
{
/* ... */
driver_request.nx_ip_driver_ptr = ip_ptr;
driver_request.nx_ip_driver_command = NX_LINK_DEFERRED_PROCESSING;
driver_request.nx_ip_driver_interface = &(ip_ptr -> nx_ip_interface[index]);
driver_request.nx_ip_driver_return_ptr = &foo;
(ip_ptr -> nx_ip_interface[index].nx_interface_link_driver_entry)(&driver_request);
}if (ip_ptr -> nx_ip_interface[index].nx_interface_valid) { ... }
}for (index = 0; index < NX_MAX_PHYSICAL_INTERFACES; index++) { ... }
}if (ip_events & NX_IP_DRIVER_DEFERRED_EVENT) { ... }
if (ip_events & NX_IP_TCP_CLEANUP_DEFERRED)
{
/* ... */
(ip_ptr -> nx_tcp_deferred_cleanup_check)(ip_ptr);
}if (ip_events & NX_IP_TCP_CLEANUP_DEFERRED) { ... }
if (ip_events & NX_IP_LINK_STATUS_EVENT)
{
_nx_ip_deferred_link_status_process(ip_ptr);
}if (ip_events & NX_IP_LINK_STATUS_EVENT) { ... }
}for (;;) { ... }
}{ ... }