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
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
132
133
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
156
157
158
159
160
161
162
163
164
165
166
167
168
169
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
207
208
209
210
211
212
213
214
215
216
217
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
274
275
276
277
278
279
280
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
316
317
318
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
350
351
353
354
355
356
357
358
359
360
361
362
363
364
369
370
371
372
373
374
375
376
377
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
416
420
421
422
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_packet.h"
#include "nx_ip.h"
#include "nx_tcp.h"
#ifdef FEATURE_NX_IPV6
#include "nx_ipv6.h"
#endif
#ifdef NX_IPSEC_ENABLE
#include "nx_ipsec.h"
#endif
...
...
VOID _nx_tcp_socket_retransmit(NX_IP *ip_ptr, NX_TCP_SOCKET *socket_ptr, UINT need_fast_retransmit)
{
NX_PACKET *packet_ptr;
ULONG window;
ULONG original_acknowledgment_number;
ULONG original_header_word_3;
ULONG original_header_word_4;
ULONG available;
ULONG window_size;
/* ... */
if (socket_ptr -> nx_tcp_socket_tx_window_advertised == 0)
{
packet_ptr = socket_ptr -> nx_tcp_socket_transmit_sent_head;
if (packet_ptr)
{
NX_TCP_HEADER *header_ptr = (NX_TCP_HEADER *)packet_ptr -> nx_packet_prepend_ptr;
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_3);
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_sequence_number);
socket_ptr -> nx_tcp_socket_zero_window_probe_data = *(packet_ptr -> nx_packet_prepend_ptr + ((header_ptr -> nx_tcp_header_word_3 >> 28) << 2));
socket_ptr -> nx_tcp_socket_zero_window_probe_has_data = NX_TRUE;
socket_ptr -> nx_tcp_socket_zero_window_probe_sequence = header_ptr -> nx_tcp_sequence_number;
socket_ptr -> nx_tcp_socket_zero_window_probe_failure = 0;
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_sequence_number);
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_3);
}if (packet_ptr) { ... }
else if (socket_ptr -> nx_tcp_socket_zero_window_probe_has_data == NX_FALSE)
{
return;
}else if (socket_ptr -> nx_tcp_socket_zero_window_probe_has_data == NX_FALSE) { ... }
/* ... */
socket_ptr -> nx_tcp_socket_timeout_retries++;
socket_ptr -> nx_tcp_socket_zero_window_probe_failure++;
socket_ptr -> nx_tcp_socket_timeout = socket_ptr -> nx_tcp_socket_timeout_rate <<
(socket_ptr -> nx_tcp_socket_timeout_retries * socket_ptr -> nx_tcp_socket_timeout_shift);
_nx_tcp_packet_send_probe(socket_ptr, socket_ptr -> nx_tcp_socket_zero_window_probe_sequence,
socket_ptr -> nx_tcp_socket_zero_window_probe_data);
return;
}if (socket_ptr -> nx_tcp_socket_tx_window_advertised == 0) { ... }
else if (socket_ptr -> nx_tcp_socket_zero_window_probe_has_data == NX_TRUE)
{
socket_ptr -> nx_tcp_socket_zero_window_probe_has_data = NX_FALSE;
}else if (socket_ptr -> nx_tcp_socket_zero_window_probe_has_data == NX_TRUE) { ... }
socket_ptr -> nx_tcp_socket_timeout_retries++;
if ((need_fast_retransmit == NX_TRUE) || (socket_ptr -> nx_tcp_socket_fast_recovery == NX_FALSE))
{
window = socket_ptr -> nx_tcp_socket_tx_outstanding_bytes >> 1;
if (window < (socket_ptr -> nx_tcp_socket_connect_mss << 1))
{
window = socket_ptr -> nx_tcp_socket_connect_mss << 1;
}if (window < (socket_ptr -> nx_tcp_socket_connect_mss << 1)) { ... }
socket_ptr -> nx_tcp_socket_tx_slow_start_threshold = window;
socket_ptr -> nx_tcp_socket_tx_window_congestion = socket_ptr -> nx_tcp_socket_connect_mss;
if (need_fast_retransmit == NX_TRUE)
{
socket_ptr -> nx_tcp_socket_tx_window_congestion += window + (socket_ptr -> nx_tcp_socket_connect_mss << 1);
socket_ptr -> nx_tcp_socket_fast_recovery = NX_TRUE;
socket_ptr -> nx_tcp_socket_tx_sequence_recover = socket_ptr -> nx_tcp_socket_tx_sequence - 1;
}if (need_fast_retransmit == NX_TRUE) { ... }
}if ((need_fast_retransmit == NX_TRUE) || (socket_ptr -> nx_tcp_socket_fast_recovery == NX_FALSE)) { ... }
socket_ptr -> nx_tcp_socket_timeout = socket_ptr -> nx_tcp_socket_timeout_rate <<
(socket_ptr -> nx_tcp_socket_timeout_retries * socket_ptr -> nx_tcp_socket_timeout_shift);
available = socket_ptr -> nx_tcp_socket_tx_window_congestion;
packet_ptr = socket_ptr -> nx_tcp_socket_transmit_sent_head;
/* ... */
while (packet_ptr && (packet_ptr -> nx_packet_queue_next == (NX_PACKET *)NX_DRIVER_TX_DONE))
{
ULONG checksum;
NX_TCP_HEADER *header_ptr;
ULONG *source_ip = NX_NULL, *dest_ip = NX_NULL;
NX_PACKET *next_ptr;
#if defined(NX_DISABLE_TCP_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE)
UINT compute_checksum = 1;
#endif
#ifdef NX_DISABLE_TCP_TX_CHECKSUM
compute_checksum = 0;
#endif
if (packet_ptr -> nx_packet_length > (available + sizeof(NX_TCP_HEADER)))
{
break;
}if (packet_ptr -> nx_packet_length > (available + sizeof(NX_TCP_HEADER))) { ... }
available -= (packet_ptr -> nx_packet_length - (ULONG)sizeof(NX_TCP_HEADER));
next_ptr = packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next;
#ifndef NX_DISABLE_IPV4
if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V4)
{
packet_ptr -> nx_packet_ip_version = NX_IP_VERSION_V4;
source_ip = &socket_ptr -> nx_tcp_socket_connect_interface -> nx_interface_ip_address;
dest_ip = &socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v4;
}if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V6)
{
packet_ptr -> nx_packet_ip_version = NX_IP_VERSION_V6;
source_ip = socket_ptr -> nx_tcp_socket_ipv6_addr -> nxd_ipv6_address;
dest_ip = socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v6;
}if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
header_ptr = (NX_TCP_HEADER *)packet_ptr -> nx_packet_prepend_ptr;
original_acknowledgment_number = header_ptr -> nx_tcp_acknowledgment_number;
original_header_word_3 = header_ptr -> nx_tcp_header_word_3;
original_header_word_4 = header_ptr -> nx_tcp_header_word_4;
header_ptr -> nx_tcp_acknowledgment_number = socket_ptr -> nx_tcp_socket_rx_sequence;
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_acknowledgment_number);
#ifdef NX_ENABLE_TCP_WINDOW_SCALING
window_size = socket_ptr -> nx_tcp_socket_rx_window_current >> socket_ptr -> nx_tcp_rcv_win_scale_value;
if (window_size > 0xFFFF)
{
window_size = 0xFFFF;
}if (window_size > 0xFFFF) { ... }
/* ... */#else
window_size = socket_ptr -> nx_tcp_socket_rx_window_current;
#endif
header_ptr -> nx_tcp_header_word_3 = NX_TCP_HEADER_SIZE | NX_TCP_ACK_BIT | NX_TCP_PSH_BIT | window_size;
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_3);
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_4);
socket_ptr -> nx_tcp_socket_rx_sequence_acked = socket_ptr -> nx_tcp_socket_rx_sequence;
socket_ptr -> nx_tcp_socket_rx_window_last_sent = socket_ptr -> nx_tcp_socket_rx_window_current;
header_ptr -> nx_tcp_header_word_4 = header_ptr -> nx_tcp_header_word_4 & 0x0000FFFF;
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_4);
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
if (socket_ptr -> nx_tcp_socket_connect_interface -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCP_TX_CHECKSUM)
{
compute_checksum = 0;
}if (socket_ptr -> nx_tcp_socket_connect_interface -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCP_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_TCP_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE)
if (compute_checksum)
#endif
{
checksum = _nx_ip_checksum_compute(packet_ptr, NX_PROTOCOL_TCP,
packet_ptr -> nx_packet_length,
source_ip, dest_ip);
checksum = ~checksum & NX_LOWER_16_MASK;
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_4);
header_ptr -> nx_tcp_header_word_4 = header_ptr -> nx_tcp_header_word_4 | (checksum << NX_SHIFT_BY_16);
NX_CHANGE_ULONG_ENDIAN(header_ptr -> nx_tcp_header_word_4);
...}
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
else
{
packet_ptr -> nx_packet_interface_capability_flag |= NX_INTERFACE_CAPABILITY_TCP_TX_CHECKSUM;
}else { ... }
/* ... */#endif
/* ... */
if ((header_ptr -> nx_tcp_acknowledgment_number == original_acknowledgment_number) &&
(header_ptr -> nx_tcp_header_word_3 == original_header_word_3) &&
(header_ptr -> nx_tcp_header_word_4 == original_header_word_4))
{
packet_ptr -> nx_packet_identical_copy = NX_TRUE;
}if ((header_ptr -> nx_tcp_acknowledgment_number == original_acknowledgment_number) && (header_ptr -> nx_tcp_header_word_3 == original_header_word_3) && (header_ptr -> nx_tcp_header_word_4 == original_header_word_4)) { ... }
#ifndef NX_DISABLE_TCP_INFO
ip_ptr -> nx_ip_tcp_retransmit_packets++;
socket_ptr -> nx_tcp_socket_retransmit_packets++;/* ... */
#endif
NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_TCP_RETRY, ip_ptr, socket_ptr, packet_ptr, socket_ptr -> nx_tcp_socket_timeout_retries, NX_TRACE_INTERNAL_EVENTS, 0, 0);
packet_ptr -> nx_packet_queue_next = NX_NULL;
/* ... */
#ifndef NX_DISABLE_IPV4
if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V4)
{
_nx_ip_packet_send(ip_ptr, packet_ptr,
socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v4,
socket_ptr -> nx_tcp_socket_type_of_service,
socket_ptr -> nx_tcp_socket_time_to_live, NX_IP_TCP,
socket_ptr -> nx_tcp_socket_fragment_enable,
socket_ptr -> nx_tcp_socket_next_hop_address);
}if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V6)
{
packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr = socket_ptr -> nx_tcp_socket_ipv6_addr;
_nx_ipv6_packet_send(ip_ptr, packet_ptr, NX_PROTOCOL_TCP,
packet_ptr -> nx_packet_length, ip_ptr -> nx_ipv6_hop_limit,
socket_ptr -> nx_tcp_socket_ipv6_addr -> nxd_ipv6_address,
socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_address.v6);
}if (socket_ptr -> nx_tcp_socket_connect_ip.nxd_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
if ((next_ptr == (NX_PACKET *)NX_PACKET_ENQUEUED) ||
(socket_ptr -> nx_tcp_socket_fast_recovery == NX_TRUE))
{
break;
}if ((next_ptr == (NX_PACKET *)NX_PACKET_ENQUEUED) || (socket_ptr -> nx_tcp_socket_fast_recovery == NX_TRUE)) { ... }
else
{
packet_ptr = next_ptr;
}else { ... }
}while (packet_ptr && (packet_ptr -> nx_packet_queue_next == (NX_PACKET *)NX_DRIVER_TX_DONE)) { ... }
}{ ... }