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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
181
182
183
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
210
211
212
213
214
215
216
217
218
219
220
221
222
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
266
267
268
269
270
271
272
273
274
279
280
281
286
287
288
289
290
298
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
343
344
345
353
354
355
356
357
358
359
360
363
364
365
366
367
368
369
370
371
373
374
375
379
384
385
386
387
388
389
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
420
421
422
423
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
446
447
448
449
450
451
452
453
454
455
458
459
460
461
462
463
464
465
466
468
469
470
471
472
473
474
476
477
478
479
480
481
482
483
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
518
519
520
521
522
523
524
526
527
528
529
530
531
532
533
535
536
537
538
539
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
565
566
567
568
569
570
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
597
598
599
600
601
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
637
638
639
640
641
642
643
644
645
646
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
707
708
709
710
711
712
713
714
715
716
717
718
720
721
722
723
724
725
726
727
728
729
730
731
734
735
736
737
738
739
740
741
742
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
766
767
768
769
770
771
772
774
775
776
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
819
820
821
822
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
855
856
857
858
860
861
862
863
864
865
866
867
868
869
870
871
873
874
875
876
877
883
890
891
892
898
899
900
901
902
903
904
905
906
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
932
933
934
935
936
937
938
939
940
941
942
943
944
945
951
957
958
959
960
961
962
963
964
965
966
967
968
969
970
977
978
979
980
981
982
983
984
985
986
987
988
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1017
1018
1019
1020
1026
1027
1028
1029
1030
1031
1032
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_tcp.h"
#include "nx_packet.h"
#include "nx_ip.h"
#ifdef FEATURE_NX_IPV6
#include "nx_ipv6.h"
#endif
#ifdef NX_IPSEC_ENABLE
#include "nx_ipsec.h"
#endif
...
...
VOID _nx_tcp_packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr)
{
UINT index;
UINT port;
ULONG *source_ip = NX_NULL;
ULONG *dest_ip = NX_NULL;
UINT source_port;
NX_TCP_SOCKET *socket_ptr;
NX_TCP_HEADER *tcp_header_ptr;
struct NX_TCP_LISTEN_STRUCT *listen_ptr;
VOID (*listen_callback)(NX_TCP_SOCKET *socket_ptr, UINT port);
ULONG option_words;
ULONG mss = 0;
ULONG checksum;
NX_INTERFACE *interface_ptr = NX_NULL;
#if defined(NX_DISABLE_TCP_RX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE)
UINT compute_checksum = 1;
#endif
ULONG queued_count;
NX_PACKET *queued_ptr;
NX_PACKET *queued_prev_ptr;
ULONG *queued_source_ip;
UINT queued_source_port;
UINT is_a_RST_request;
UINT is_valid_option_flag = NX_TRUE;
UINT status;
#ifdef NX_ENABLE_TCP_WINDOW_SCALING
ULONG rwin_scale = 0xFF;
#endif
#ifdef NX_DISABLE_TCP_RX_CHECKSUM
compute_checksum = 0;
#endif
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
#ifndef NX_DISABLE_IPV4
if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4)
{
NX_IPV4_HEADER *ip_header_ptr;
ip_header_ptr = (NX_IPV4_HEADER *)packet_ptr -> nx_packet_ip_header;
source_ip = &ip_header_ptr -> nx_ip_header_source_ip;
dest_ip = &ip_header_ptr -> nx_ip_header_destination_ip;
mss = 536;
interface_ptr = packet_ptr -> nx_packet_address.nx_packet_interface_ptr;
}if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6)
{
NX_IPV6_HEADER *ipv6_header;
ipv6_header = (NX_IPV6_HEADER *)packet_ptr -> nx_packet_ip_header;
source_ip = &ipv6_header -> nx_ip_header_source_ip[0];
dest_ip = &ipv6_header -> nx_ip_header_destination_ip[0];
mss = 1220;
interface_ptr = packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr -> nxd_ipv6_address_attached;
}if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
if (interface_ptr -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCP_RX_CHECKSUM)
{
compute_checksum = 0;
}if (interface_ptr -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCP_RX_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_TCP_RX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE)
if (compute_checksum)
#endif
{
checksum = _nx_ip_checksum_compute(packet_ptr, NX_PROTOCOL_TCP,
(UINT)packet_ptr -> nx_packet_length,
source_ip, dest_ip);
checksum = NX_LOWER_16_MASK & ~checksum;
if (checksum != 0)
{
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_invalid_packets++;
ip_ptr -> nx_ip_tcp_checksum_errors++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (checksum != 0) { ... }
...}
tcp_header_ptr = (NX_TCP_HEADER *)packet_ptr -> nx_packet_prepend_ptr;
/* ... */
NX_CHANGE_ULONG_ENDIAN(tcp_header_ptr -> nx_tcp_header_word_0);
NX_CHANGE_ULONG_ENDIAN(tcp_header_ptr -> nx_tcp_sequence_number);
NX_CHANGE_ULONG_ENDIAN(tcp_header_ptr -> nx_tcp_acknowledgment_number);
NX_CHANGE_ULONG_ENDIAN(tcp_header_ptr -> nx_tcp_header_word_3);
NX_CHANGE_ULONG_ENDIAN(tcp_header_ptr -> nx_tcp_header_word_4);
option_words = (tcp_header_ptr -> nx_tcp_header_word_3 >> 28) - 5;
#ifndef NX_DISABLE_RX_SIZE_CHECKING
if (((INT)option_words < 0) || (packet_ptr -> nx_packet_length < (sizeof(NX_TCP_HEADER) + (option_words << 2))))
{
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_invalid_packets++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (((INT)option_words < 0) || (packet_ptr -> nx_packet_length < (sizeof(NX_TCP_HEADER) + (option_words << 2)))) { ... }
/* ... */#endif
if (option_words)
{
status = _nx_tcp_mss_option_get((packet_ptr -> nx_packet_prepend_ptr + sizeof(NX_TCP_HEADER)), option_words * (ULONG)sizeof(ULONG), &mss);
if (status == NX_FALSE)
{
is_valid_option_flag = NX_FALSE;
}if (status == NX_FALSE) { ... }
else
{
if (mss == 0)
{
#ifndef NX_DISABLE_IPV4
if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4)
{
mss = 536;
}if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6)
{
mss = 1220;
}if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
}if (mss == 0) { ... }
}else { ... }
#ifdef NX_ENABLE_TCP_WINDOW_SCALING
status = _nx_tcp_window_scaling_option_get((packet_ptr -> nx_packet_prepend_ptr + sizeof(NX_TCP_HEADER)), option_words * (ULONG)sizeof(ULONG), &rwin_scale);
if (status == NX_FALSE)
{
is_valid_option_flag = NX_FALSE;
}if (status == NX_FALSE) { ... }
/* ... */#endif
}if (option_words) { ... }
port = (UINT)(tcp_header_ptr -> nx_tcp_header_word_0 & NX_LOWER_16_MASK);
source_port = (UINT)(tcp_header_ptr -> nx_tcp_header_word_0 >> NX_SHIFT_BY_16);
index = (UINT)((port + (port >> 8)) & NX_TCP_PORT_TABLE_MASK);
socket_ptr = ip_ptr -> nx_ip_tcp_port_table[index];
if (socket_ptr)
{
INT find_a_match;
do
{
find_a_match = 0;
if ((socket_ptr -> nx_tcp_socket_port == port) &&
(socket_ptr -> nx_tcp_socket_connect_port == source_port))
{
if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == packet_ptr -> nx_packet_ip_version)
{
#ifndef NX_DISABLE_IPV4
if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4)
{
if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v4 == *source_ip)
{
find_a_match = 1;
}if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v4 == *source_ip) { ... }
}if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6)
{
if (CHECK_IPV6_ADDRESSES_SAME(socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v6, source_ip))
{
find_a_match = 1;
}if (CHECK_IPV6_ADDRESSES_SAME(socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v6, source_ip)) { ... }
}if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
}if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == packet_ptr -> nx_packet_ip_version) { ... }
if (find_a_match)
{
/* ... */
ip_ptr -> nx_ip_tcp_port_table[index] = socket_ptr;
if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_SYN_BIT)
{
/* ... */
socket_ptr -> nx_tcp_socket_peer_mss = mss;
if ((mss > socket_ptr -> nx_tcp_socket_mss) && socket_ptr -> nx_tcp_socket_mss)
{
socket_ptr -> nx_tcp_socket_connect_mss = socket_ptr -> nx_tcp_socket_mss;
}if ((mss > socket_ptr -> nx_tcp_socket_mss) && socket_ptr -> nx_tcp_socket_mss) { ... }
else if ((socket_ptr -> nx_tcp_socket_state != NX_TCP_SYN_SENT) ||
(socket_ptr -> nx_tcp_socket_connect_mss > mss))
{
socket_ptr -> nx_tcp_socket_connect_mss = mss;
}else if ((socket_ptr -> nx_tcp_socket_state != NX_TCP_SYN_SENT) || (socket_ptr -> nx_tcp_socket_connect_mss > mss)) { ... }
socket_ptr -> nx_tcp_socket_connect_mss2 =
socket_ptr -> nx_tcp_socket_connect_mss * socket_ptr -> nx_tcp_socket_connect_mss;
#ifdef NX_ENABLE_TCP_WINDOW_SCALING
/* ... */
socket_ptr -> nx_tcp_snd_win_scale_value = rwin_scale;/* ... */
#endif
}if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_SYN_BIT) { ... }
_nx_tcp_socket_packet_process(socket_ptr, packet_ptr);
return;
}if (find_a_match) { ... }
}if ((socket_ptr -> nx_tcp_socket_port == port) && (socket_ptr -> nx_tcp_socket_connect_port == source_port)) { ... }
socket_ptr = socket_ptr -> nx_tcp_socket_bound_next;
...} while (socket_ptr != ip_ptr -> nx_ip_tcp_port_table[index]);
}if (socket_ptr) { ... }
if (is_valid_option_flag == NX_FALSE)
{
/* ... */
_nx_tcp_no_connection_reset(ip_ptr, packet_ptr, tcp_header_ptr);
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_invalid_packets++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (is_valid_option_flag == NX_FALSE) { ... }
#ifdef NX_ENABLE_TCP_MSS_CHECK
/* ... */
if (mss < NX_TCP_MSS_MINIMUM)
{
_nx_tcp_no_connection_reset(ip_ptr, packet_ptr, tcp_header_ptr);
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_invalid_packets++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (mss < NX_TCP_MSS_MINIMUM) { ... }
/* ... */#endif
/* ... */
if ((!(tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_ACK_BIT)) &&
(ip_ptr -> nx_ip_tcp_active_listen_requests))
{
#ifndef NX_DISABLE_IPV4
if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4)
{
/* ... */
if ((*source_ip == *dest_ip) && (source_port == port))
{
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_invalid_packets++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if ((*source_ip == *dest_ip) && (source_port == port)) { ... }
/* ... */
if (
((*source_ip & NX_IP_CLASS_D_MASK) == NX_IP_CLASS_D_TYPE) ||
(((*source_ip & interface_ptr -> nx_interface_ip_network_mask) == interface_ptr -> nx_interface_ip_network) &&
((*source_ip & ~(interface_ptr -> nx_interface_ip_network_mask)) == ~(interface_ptr -> nx_interface_ip_network_mask))) ||
(*source_ip == interface_ptr -> nx_interface_ip_network) ||
(*source_ip == NX_IP_LIMITED_BROADCAST)
)
{
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_invalid_packets++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (/* Check for Multicast address */ ((*source_ip & NX_IP_CLASS_D_MASK) == NX_IP_CLASS_D_TYPE) || /* Check for subnet-directed broadcast */ (((*source_ip & interface_ptr -> nx_interface_ip_network_mask) == interface_ptr -> nx_interface_ip_network) && ((*source_ip & ~(interface_ptr -> nx_interface_ip_network_mask)) == ~(interface_ptr -> nx_interface_ip_network_mask))) || /* Check for local subnet address */ (*source_ip == interface_ptr -> nx_interface_ip_network) || /* Check for limited broadcast */ (*source_ip == NX_IP_LIMITED_BROADCAST)) { ... }
}if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6)
{
/* ... */
if ((CHECK_IPV6_ADDRESSES_SAME(source_ip, dest_ip)) && (source_port == port))
{
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_invalid_packets++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if ((CHECK_IPV6_ADDRESSES_SAME(source_ip, dest_ip)) && (source_port == port)) { ... }
/* ... */
if (IPv6_Address_Type(source_ip) & IPV6_ADDRESS_MULTICAST)
{
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_invalid_packets++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (IPv6_Address_Type(source_ip) & IPV6_ADDRESS_MULTICAST) { ... }
}if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
listen_ptr = ip_ptr -> nx_ip_tcp_active_listen_requests;
do
{
if (listen_ptr -> nx_tcp_listen_port == port)
{
/* ... */
if ((!(tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_SYN_BIT)) &&
(!(tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT)))
{
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_receive_packets_dropped++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if ((!(tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_SYN_BIT)) && (!(tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT))) { ... }
#ifndef NX_DISABLE_TCP_INFO
if ((tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_SYN_BIT))
{
ip_ptr -> nx_ip_tcp_passive_connections++;
ip_ptr -> nx_ip_tcp_connections++;
}if ((tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_SYN_BIT)) { ... }
/* ... */#endif
/* ... */
if ((listen_ptr -> nx_tcp_listen_socket_ptr) &&
((tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT) == NX_NULL))
{
/* ... */
socket_ptr = listen_ptr -> nx_tcp_listen_socket_ptr;
#ifndef NX_DISABLE_EXTENDED_NOTIFY_SUPPORT
/* ... */
if (socket_ptr -> nx_tcp_socket_syn_received_notify)
{
NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
if ((socket_ptr -> nx_tcp_socket_syn_received_notify)(socket_ptr, packet_ptr) != NX_TRUE)
{
_nx_packet_release(packet_ptr);
return;
}if ((socket_ptr -> nx_tcp_socket_syn_received_notify)(socket_ptr, packet_ptr) != NX_TRUE) { ... }
}if (socket_ptr -> nx_tcp_socket_syn_received_notify) { ... }
/* ... */#endif
NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_TCP_SYN_RECEIVE, ip_ptr, socket_ptr, packet_ptr, tcp_header_ptr -> nx_tcp_sequence_number, NX_TRACE_INTERNAL_EVENTS, 0, 0);
/* ... */
listen_ptr -> nx_tcp_listen_socket_ptr = NX_NULL;
#ifndef NX_DISABLE_IPV4
if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4)
{
/* ... */
socket_ptr -> nx_tcp_socket_connect_interface = interface_ptr;
socket_ptr -> nx_tcp_socket_next_hop_address = NX_NULL;
_nx_ip_route_find(ip_ptr, *source_ip, &socket_ptr -> nx_tcp_socket_connect_interface,
&socket_ptr -> nx_tcp_socket_next_hop_address);
socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version = NX_IP_VERSION_V4;
socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v4 = *source_ip;
}if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6)
{
socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version = NX_IP_VERSION_V6;
COPY_IPV6_ADDRESS(source_ip, socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v6);
socket_ptr -> nx_tcp_socket_ipv6_addr = packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr;
socket_ptr -> nx_tcp_socket_connect_interface = interface_ptr;
}if (packet_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
socket_ptr -> nx_tcp_socket_connect_port = source_port;
socket_ptr -> nx_tcp_socket_rx_sequence = tcp_header_ptr -> nx_tcp_sequence_number;
socket_ptr -> nx_tcp_socket_peer_mss = mss;
#ifdef NX_ENABLE_TCP_WINDOW_SCALING
/* ... */
socket_ptr -> nx_tcp_snd_win_scale_value = rwin_scale;/* ... */
#endif
socket_ptr -> nx_tcp_socket_tx_slow_start_threshold = socket_ptr -> nx_tcp_socket_tx_window_advertised;
socket_ptr -> nx_tcp_socket_tx_window_congestion = mss;
socket_ptr -> nx_tcp_socket_tx_outstanding_bytes = 0;
index = (UINT)((port + (port >> 8)) & NX_TCP_PORT_TABLE_MASK);
if (ip_ptr -> nx_ip_tcp_port_table[index])
{
/* ... */
socket_ptr -> nx_tcp_socket_bound_next =
ip_ptr -> nx_ip_tcp_port_table[index];
socket_ptr -> nx_tcp_socket_bound_previous =
(ip_ptr -> nx_ip_tcp_port_table[index]) -> nx_tcp_socket_bound_previous;
((ip_ptr -> nx_ip_tcp_port_table[index]) -> nx_tcp_socket_bound_previous) -> nx_tcp_socket_bound_next =
socket_ptr;
(ip_ptr -> nx_ip_tcp_port_table[index]) -> nx_tcp_socket_bound_previous = socket_ptr;
}if (ip_ptr -> nx_ip_tcp_port_table[index]) { ... }
else
{
/* ... */
socket_ptr -> nx_tcp_socket_bound_next = socket_ptr;
socket_ptr -> nx_tcp_socket_bound_previous = socket_ptr;
ip_ptr -> nx_ip_tcp_port_table[index] = socket_ptr;
}else { ... }
listen_callback = listen_ptr -> nx_tcp_listen_callback;
_nx_packet_release(packet_ptr);
/* ... */
if (socket_ptr -> nx_tcp_socket_state == NX_TCP_SYN_RECEIVED)
{
NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_TCP_STATE_CHANGE, ip_ptr, socket_ptr, socket_ptr -> nx_tcp_socket_state, socket_ptr -> nx_tcp_socket_state, NX_TRACE_INTERNAL_EVENTS, 0, 0);
/* ... */
socket_ptr -> nx_tcp_socket_rx_sequence++;
socket_ptr -> nx_tcp_socket_tx_sequence++;
socket_ptr -> nx_tcp_socket_timeout = socket_ptr -> nx_tcp_socket_timeout_rate;
socket_ptr -> nx_tcp_socket_timeout_retries = 0;
_nx_tcp_packet_send_syn(socket_ptr, (socket_ptr -> nx_tcp_socket_tx_sequence - 1));
}if (socket_ptr -> nx_tcp_socket_state == NX_TCP_SYN_RECEIVED) { ... }
if (listen_callback)
{
(listen_callback)(socket_ptr, port);
}if (listen_callback) { ... }
}if ((listen_ptr -> nx_tcp_listen_socket_ptr) && ((tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT) == NX_NULL)) { ... }
else
{
/* ... */
if (!(tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT))
{
NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_TCP_SYN_RECEIVE, ip_ptr, NX_NULL, packet_ptr, tcp_header_ptr -> nx_tcp_sequence_number, NX_TRACE_INTERNAL_EVENTS, 0, 0);
}if (!(tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT)) { ... }
queued_count = listen_ptr -> nx_tcp_listen_queue_current;
queued_ptr = listen_ptr -> nx_tcp_listen_queue_head;
queued_prev_ptr = queued_ptr;
is_a_RST_request = NX_FALSE;
while (queued_count--)
{
queued_source_port = (UINT)(*((ULONG *)queued_ptr -> nx_packet_prepend_ptr) >> NX_SHIFT_BY_16);
#ifndef NX_DISABLE_IPV4
if (queued_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4)
{
queued_source_ip = (ULONG *)(((ULONG *)queued_ptr -> nx_packet_prepend_ptr) - 2);
if ((*queued_source_ip == *source_ip) && (queued_source_port == source_port))
{
if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT)
{
is_a_RST_request = NX_TRUE;
}if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT) { ... }
else
{
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_receive_packets_dropped++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}else { ... }
}if ((*queued_source_ip == *source_ip) && (queued_source_port == source_port)) { ... }
}if (queued_ptr -> nx_packet_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (queued_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6)
{
queued_source_ip = (ULONG *)(((ULONG *)queued_ptr -> nx_packet_prepend_ptr) - 8);
if ((CHECK_IPV6_ADDRESSES_SAME(queued_source_ip, source_ip)) && (queued_source_port == source_port))
{
if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT)
{
is_a_RST_request = NX_TRUE;
}if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT) { ... }
else
{
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_receive_packets_dropped++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}else { ... }
}if ((CHECK_IPV6_ADDRESSES_SAME(queued_source_ip, source_ip)) && (queued_source_port == source_port)) { ... }
}if (queued_ptr -> nx_packet_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
/* ... */
if (is_a_RST_request)
{
if (queued_ptr == listen_ptr -> nx_tcp_listen_queue_head)
{
listen_ptr -> nx_tcp_listen_queue_head = queued_ptr -> nx_packet_queue_next;
}if (queued_ptr == listen_ptr -> nx_tcp_listen_queue_head) { ... }
else
{
queued_prev_ptr -> nx_packet_queue_next = queued_ptr -> nx_packet_queue_next;
}else { ... }
if (queued_ptr == listen_ptr -> nx_tcp_listen_queue_tail)
{
listen_ptr -> nx_tcp_listen_queue_tail = queued_prev_ptr;
}if (queued_ptr == listen_ptr -> nx_tcp_listen_queue_tail) { ... }
_nx_packet_release(queued_ptr);
listen_ptr -> nx_tcp_listen_queue_current--;
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_receive_packets_dropped++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (is_a_RST_request) { ... }
queued_prev_ptr = queued_ptr;
queued_ptr = queued_ptr -> nx_packet_queue_next;
}while (queued_count--) { ... }
if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT)
{
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_receive_packets_dropped++;/* ... */
#endif
_nx_packet_release(packet_ptr);
return;
}if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT) { ... }
packet_ptr -> nx_packet_queue_next = NX_NULL;
if (listen_ptr -> nx_tcp_listen_queue_head)
{
(listen_ptr -> nx_tcp_listen_queue_tail) -> nx_packet_queue_next = packet_ptr;
}if (listen_ptr -> nx_tcp_listen_queue_head) { ... }
else
{
listen_ptr -> nx_tcp_listen_queue_head = packet_ptr;
}else { ... }
listen_ptr -> nx_tcp_listen_queue_tail = packet_ptr;
listen_ptr -> nx_tcp_listen_queue_current++;
NX_PACKET_DEBUG(NX_PACKET_TCP_LISTEN_QUEUE, __LINE__, packet_ptr);
if (listen_ptr -> nx_tcp_listen_queue_current > listen_ptr -> nx_tcp_listen_queue_maximum)
{
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_connections_dropped++;
ip_ptr -> nx_ip_tcp_connections--;
ip_ptr -> nx_ip_tcp_receive_packets_dropped++;/* ... */
#endif
packet_ptr = listen_ptr -> nx_tcp_listen_queue_head;
listen_ptr -> nx_tcp_listen_queue_head = (listen_ptr -> nx_tcp_listen_queue_head) -> nx_packet_queue_next;
listen_ptr -> nx_tcp_listen_queue_current--;
/* ... */
_nx_packet_release(packet_ptr);
}if (listen_ptr -> nx_tcp_listen_queue_current > listen_ptr -> nx_tcp_listen_queue_maximum) { ... }
}else { ... }
return;
}if (listen_ptr -> nx_tcp_listen_port == port) { ... }
listen_ptr = listen_ptr -> nx_tcp_listen_next;
...} while (listen_ptr != ip_ptr -> nx_ip_tcp_active_listen_requests);
}if ((!(tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_ACK_BIT)) && (ip_ptr -> nx_ip_tcp_active_listen_requests)) { ... }
#ifndef NX_DISABLE_TCP_INFO
if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_SYN_BIT)
{
ip_ptr -> nx_ip_tcp_connections_dropped++;
}if (tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_SYN_BIT) { ... }
ip_ptr -> nx_ip_tcp_receive_packets_dropped++;/* ... */
#endif
if (!(tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT))
{
_nx_tcp_no_connection_reset(ip_ptr, packet_ptr, tcp_header_ptr);
}if (!(tcp_header_ptr -> nx_tcp_header_word_3 & NX_TCP_RST_BIT)) { ... }
_nx_packet_release(packet_ptr);
return;
}{ ... }