Rev 7974 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3545 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
7974 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2004-2020. All rights reserved. ;; |
3545 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;; Part of the TCP/IP network stack for KolibriOS ;; |
||
7 | ;; ;; |
||
8 | ;; Written by hidnplayr@kolibrios.org ;; |
||
9 | ;; ;; |
||
10 | ;; Based on the code of 4.4BSD ;; |
||
11 | ;; ;; |
||
12 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
13 | ;; Version 2, June 1991 ;; |
||
14 | ;; ;; |
||
15 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
16 | |||
4850 | mario79 | 17 | $Revision: 8026 $ |
3545 | hidnplayr | 18 | |
19 | align 4 |
||
20 | iglobal |
||
21 | TCP_backoff db 0,1,2,3,4,5,6,6,6,6,6,6,6 |
||
22 | endg |
||
23 | |||
6011 | hidnplayr | 24 | macro tcp_checksum IP1, IP2 { |
3545 | hidnplayr | 25 | |
26 | ;------------- |
||
27 | ; Pseudoheader |
||
28 | |||
29 | ; protocol type |
||
30 | mov edx, IP_PROTO_TCP |
||
31 | |||
32 | ; source address |
||
33 | add dl, byte [IP1+1] |
||
34 | adc dh, byte [IP1+0] |
||
35 | adc dl, byte [IP1+3] |
||
36 | adc dh, byte [IP1+2] |
||
37 | |||
38 | ; destination address |
||
39 | adc dl, byte [IP2+1] |
||
40 | adc dh, byte [IP2+0] |
||
41 | adc dl, byte [IP2+3] |
||
42 | adc dh, byte [IP2+2] |
||
43 | |||
44 | ; size |
||
45 | adc dl, cl |
||
46 | adc dh, ch |
||
47 | |||
48 | adc edx, 0 |
||
49 | |||
50 | ;--------------------- |
||
51 | ; Real header and data |
||
52 | |||
53 | push esi |
||
54 | call checksum_1 |
||
55 | call checksum_2 |
||
56 | pop esi |
||
57 | |||
58 | } ; returns in dx only |
||
59 | |||
60 | |||
61 | |||
62 | |||
6011 | hidnplayr | 63 | macro tcp_sendseqinit ptr { |
3545 | hidnplayr | 64 | |
6011 | hidnplayr | 65 | push edi ;;;; FIXME: i dont like this static use of edi |
3545 | hidnplayr | 66 | mov edi, [ptr + TCP_SOCKET.ISS] |
67 | mov [ptr + TCP_SOCKET.SND_UP], edi |
||
68 | mov [ptr + TCP_SOCKET.SND_MAX], edi |
||
69 | mov [ptr + TCP_SOCKET.SND_NXT], edi |
||
70 | mov [ptr + TCP_SOCKET.SND_UNA], edi |
||
71 | pop edi |
||
72 | |||
73 | } |
||
74 | |||
75 | |||
76 | |||
6011 | hidnplayr | 77 | macro tcp_rcvseqinit ptr { |
3545 | hidnplayr | 78 | |
79 | push edi |
||
80 | mov edi, [ptr + TCP_SOCKET.IRS] |
||
6476 | hidnplayr | 81 | inc edi ; SYN ocupies a sequence number |
3545 | hidnplayr | 82 | mov [ptr + TCP_SOCKET.RCV_NXT], edi |
83 | mov [ptr + TCP_SOCKET.RCV_ADV], edi |
||
84 | pop edi |
||
85 | |||
86 | } |
||
87 | |||
88 | |||
89 | |||
6011 | hidnplayr | 90 | macro tcp_init_socket socket { |
3545 | hidnplayr | 91 | |
7680 | hidnplayr | 92 | ; new tcp control block |
93 | |||
3545 | hidnplayr | 94 | mov [socket + TCP_SOCKET.t_maxseg], TCP_mss_default |
95 | mov [socket + TCP_SOCKET.t_flags], TF_REQ_SCALE or TF_REQ_TSTMP |
||
96 | |||
97 | mov [socket + TCP_SOCKET.t_srtt], TCP_time_srtt_default |
||
98 | mov [socket + TCP_SOCKET.t_rttvar], TCP_time_rtt_default * 4 |
||
99 | mov [socket + TCP_SOCKET.t_rttmin], TCP_time_re_min |
||
100 | ;;; TODO: TCP_time_rangeset |
||
101 | |||
102 | mov [socket + TCP_SOCKET.SND_CWND], TCP_max_win shl TCP_max_winshift |
||
103 | mov [socket + TCP_SOCKET.SND_SSTHRESH], TCP_max_win shl TCP_max_winshift |
||
104 | |||
7974 | hidnplayr | 105 | mov [socket + TCP_SOCKET.RCV_SCALE], 0 |
106 | mov [socket + TCP_SOCKET.SND_SCALE], 0 |
||
3545 | hidnplayr | 107 | |
108 | } |
||
109 | |||
110 | |||
5976 | hidnplayr | 111 | ;-----------------------------------------------------------------; |
112 | ; ; |
||
6011 | hidnplayr | 113 | ; tcp_pull_out_of_band ; |
5976 | hidnplayr | 114 | ; ; |
115 | ; IN: eax = ? ; |
||
116 | ; ebx = socket ptr ; |
||
117 | ; edx = tcp packet ptr ; |
||
118 | ; ; |
||
119 | ; OUT: / ; |
||
120 | ; ; |
||
121 | ;-----------------------------------------------------------------; |
||
3545 | hidnplayr | 122 | align 4 |
6011 | hidnplayr | 123 | tcp_pull_out_of_band: |
3545 | hidnplayr | 124 | |
6011 | hidnplayr | 125 | DEBUGF DEBUG_NETWORK_VERBOSE, "tcp_pull_out_of_band\n" |
3545 | hidnplayr | 126 | |
127 | ;;;; 1282-1305 |
||
128 | |||
129 | ret |
||
130 | |||
131 | |||
132 | |||
5976 | hidnplayr | 133 | ;-----------------------------------------------------------------; |
134 | ; ; |
||
6011 | hidnplayr | 135 | ; tcp_drop ; |
5976 | hidnplayr | 136 | ; ; |
137 | ; IN: eax = socket ptr ; |
||
138 | ; ebx = error number ; |
||
139 | ; ; |
||
140 | ; OUT: eax = socket ptr ; |
||
141 | ; ; |
||
142 | ;-----------------------------------------------------------------; |
||
3545 | hidnplayr | 143 | align 4 |
7974 | hidnplayr | 144 | tcp_drop: |
3545 | hidnplayr | 145 | |
7974 | hidnplayr | 146 | ;;; TODO: check if error code is "Connection timed out' and handle accordingly |
147 | |||
6011 | hidnplayr | 148 | DEBUGF DEBUG_NETWORK_VERBOSE, "tcp_drop: %x\n", eax |
3545 | hidnplayr | 149 | |
150 | cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED |
||
151 | jb .no_syn_received |
||
152 | |||
153 | mov [eax + TCP_SOCKET.t_state], TCPS_CLOSED |
||
154 | |||
4365 | hidnplayr | 155 | push eax |
6011 | hidnplayr | 156 | call tcp_output |
4365 | hidnplayr | 157 | pop eax |
3545 | hidnplayr | 158 | |
7974 | hidnplayr | 159 | inc [TCPS_drops] |
3545 | hidnplayr | 160 | |
7974 | hidnplayr | 161 | mov [eax + SOCKET.errorcode], ebx |
6011 | hidnplayr | 162 | jmp tcp_close |
3545 | hidnplayr | 163 | |
164 | .no_syn_received: |
||
7974 | hidnplayr | 165 | inc [TCPS_conndrops] |
3545 | hidnplayr | 166 | |
7974 | hidnplayr | 167 | mov [eax + SOCKET.errorcode], ebx |
168 | jmp tcp_close |
||
3545 | hidnplayr | 169 | |
170 | |||
5976 | hidnplayr | 171 | ;-----------------------------------------------------------------; |
172 | ; ; |
||
6011 | hidnplayr | 173 | ; tcp_disconnect ; |
5976 | hidnplayr | 174 | ; ; |
175 | ; IN: eax = socket ptr ; |
||
176 | ; ; |
||
177 | ; OUT: eax = socket ptr / 0 ; |
||
178 | ; ; |
||
179 | ;-----------------------------------------------------------------; |
||
4366 | hidnplayr | 180 | align 4 |
6011 | hidnplayr | 181 | tcp_disconnect: |
3545 | hidnplayr | 182 | |
4366 | hidnplayr | 183 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_disconnect: %x\n", eax |
3545 | hidnplayr | 184 | |
4366 | hidnplayr | 185 | cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED |
6011 | hidnplayr | 186 | jb tcp_close ; Connection not yet synchronised, just get rid of the socket |
3545 | hidnplayr | 187 | |
8026 | hidnplayr | 188 | test [eax + SOCKET.options], SO_LINGER |
189 | jz .nolinger |
||
190 | |||
4366 | hidnplayr | 191 | ; TODO: implement LINGER |
8026 | hidnplayr | 192 | ; cmp [eax + SOCKET.so_linger], 0 |
193 | ; je TCP_drop |
||
3545 | hidnplayr | 194 | |
8026 | hidnplayr | 195 | .nolinger: |
6011 | hidnplayr | 196 | call socket_is_disconnecting |
8026 | hidnplayr | 197 | |
198 | push eax |
||
199 | add eax, STREAM_SOCKET.rcv |
||
200 | mov ecx, [eax + RING_BUFFER.size] |
||
201 | call socket_ring_free |
||
202 | pop eax |
||
203 | |||
6011 | hidnplayr | 204 | call tcp_usrclosed |
4366 | hidnplayr | 205 | |
206 | test eax, eax |
||
207 | jz @f |
||
208 | push eax |
||
6011 | hidnplayr | 209 | call tcp_output |
4366 | hidnplayr | 210 | pop eax |
211 | @@: |
||
212 | ret |
||
213 | |||
214 | |||
5976 | hidnplayr | 215 | ;-----------------------------------------------------------------; |
216 | ; ; |
||
6011 | hidnplayr | 217 | ; tcp_close ; |
5976 | hidnplayr | 218 | ; ; |
219 | ; IN: eax = socket ptr ; |
||
220 | ; ; |
||
221 | ; OUT: / ; |
||
222 | ; ; |
||
223 | ;-----------------------------------------------------------------; |
||
3545 | hidnplayr | 224 | align 4 |
6011 | hidnplayr | 225 | tcp_close: |
3545 | hidnplayr | 226 | |
3556 | hidnplayr | 227 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_close: %x\n", eax |
3545 | hidnplayr | 228 | |
229 | ;;; TODO: update RTT and mean deviation |
||
230 | ;;; TODO: update slow start threshold |
||
231 | |||
6011 | hidnplayr | 232 | call socket_is_disconnected |
233 | call socket_free |
||
3545 | hidnplayr | 234 | |
6476 | hidnplayr | 235 | inc [TCPS_closed] |
236 | |||
4366 | hidnplayr | 237 | xor eax, eax |
3545 | hidnplayr | 238 | ret |
239 | |||
240 | |||
241 | |||
5976 | hidnplayr | 242 | ;-----------------------------------------------------------------; |
243 | ; ; |
||
6011 | hidnplayr | 244 | ; tcp_outflags ; |
5976 | hidnplayr | 245 | ; ; |
246 | ; IN: eax = socket ptr ; |
||
247 | ; ; |
||
248 | ; OUT: edx = flags ; |
||
249 | ; ; |
||
250 | ;-----------------------------------------------------------------; |
||
3545 | hidnplayr | 251 | align 4 |
6011 | hidnplayr | 252 | tcp_outflags: |
3545 | hidnplayr | 253 | |
254 | mov edx, [eax + TCP_SOCKET.t_state] |
||
6011 | hidnplayr | 255 | movzx edx, byte[edx + .flaglist] |
3545 | hidnplayr | 256 | |
3556 | hidnplayr | 257 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_outflags: socket=%x flags=%x\n", eax, dl |
3545 | hidnplayr | 258 | |
259 | ret |
||
260 | |||
261 | .flaglist: |
||
262 | db TH_RST + TH_ACK ; TCPS_CLOSED |
||
263 | db 0 ; TCPS_LISTEN |
||
264 | db TH_SYN ; TCPS_SYN_SENT |
||
265 | db TH_SYN + TH_ACK ; TCPS_SYN_RECEIVED |
||
266 | db TH_ACK ; TCPS_ESTABLISHED |
||
267 | db TH_ACK ; TCPS_CLOSE_WAIT |
||
268 | db TH_FIN + TH_ACK ; TCPS_FIN_WAIT_1 |
||
269 | db TH_FIN + TH_ACK ; TCPS_CLOSING |
||
270 | db TH_FIN + TH_ACK ; TCPS_LAST_ACK |
||
271 | db TH_ACK ; TCPS_FIN_WAIT_2 |
||
6476 | hidnplayr | 272 | db TH_ACK ; TCPS_TIME_WAIT |
3545 | hidnplayr | 273 | |
274 | |||
5976 | hidnplayr | 275 | ;-----------------------------------------------------------------; |
276 | ; ; |
||
277 | ; TCP_respond: Fast way to send an ACK/RST/keepalive segment. ; |
||
278 | ; ; |
||
279 | ; IN: ebx = socket ptr ; |
||
280 | ; cl = flags ; |
||
281 | ; ; |
||
282 | ; OUT: / ; |
||
283 | ; ; |
||
284 | ;-----------------------------------------------------------------; |
||
3545 | hidnplayr | 285 | align 4 |
6011 | hidnplayr | 286 | tcp_respond: |
3545 | hidnplayr | 287 | |
3556 | hidnplayr | 288 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_respond_socket: socket=%x flags=%x\n", ebx, cl |
3545 | hidnplayr | 289 | |
290 | ;--------------------- |
||
291 | ; Create the IP packet |
||
292 | |||
293 | push cx ebx |
||
294 | mov edx, [ebx + IP_SOCKET.LocalIP] |
||
5842 | hidnplayr | 295 | mov edi, [ebx + IP_SOCKET.RemoteIP] |
296 | mov al, [ebx + IP_SOCKET.ttl] |
||
297 | mov ah, IP_PROTO_TCP |
||
298 | mov ecx, sizeof.TCP_header |
||
5584 | hidnplayr | 299 | mov ebx, [ebx + IP_SOCKET.device] |
6011 | hidnplayr | 300 | call ipv4_output |
3545 | hidnplayr | 301 | jz .error |
302 | pop esi cx |
||
5522 | hidnplayr | 303 | push eax |
3545 | hidnplayr | 304 | |
305 | ;----------------------------------------------- |
||
306 | ; Fill in the TCP header by using the socket ptr |
||
307 | |||
308 | mov ax, [esi + TCP_SOCKET.LocalPort] |
||
309 | stosw |
||
310 | mov ax, [esi + TCP_SOCKET.RemotePort] |
||
311 | stosw |
||
312 | mov eax, [esi + TCP_SOCKET.SND_NXT] |
||
313 | bswap eax |
||
314 | stosd |
||
315 | mov eax, [esi + TCP_SOCKET.RCV_NXT] |
||
316 | bswap eax |
||
317 | stosd |
||
318 | mov al, 0x50 ; Dataoffset: 20 bytes (TCP_header.DataOffset) |
||
319 | stosb |
||
320 | mov al, cl |
||
321 | stosb |
||
7098 | ashmew2 | 322 | mov eax, SOCKET_BUFFER_SIZE |
323 | sub eax, [esi + STREAM_SOCKET.rcv.size] |
||
324 | cmp eax, TCP_max_win |
||
325 | jbe .lessthanmax |
||
326 | mov eax, TCP_max_win |
||
8026 | hidnplayr | 327 | .lessthanmax: |
7098 | ashmew2 | 328 | mov cl, [esi + TCP_SOCKET.RCV_SCALE] |
329 | shr eax, cl |
||
330 | |||
6913 | ashmew2 | 331 | xchg al, ah |
3545 | hidnplayr | 332 | stosw ; window |
333 | xor eax, eax |
||
334 | stosd ; checksum + urgentpointer |
||
335 | |||
336 | ;--------------------- |
||
337 | ; Fill in the checksum |
||
338 | |||
339 | .checksum: |
||
340 | sub edi, sizeof.TCP_header |
||
341 | mov ecx, sizeof.TCP_header |
||
342 | xchg esi, edi |
||
6011 | hidnplayr | 343 | tcp_checksum (edi + IP_SOCKET.LocalIP), (edi + IP_SOCKET.RemoteIP) |
3545 | hidnplayr | 344 | mov [esi+TCP_header.Checksum], dx |
345 | |||
346 | ;-------------------- |
||
347 | ; And send the segment |
||
348 | |||
349 | call [ebx + NET_DEVICE.transmit] |
||
3644 | hidnplayr | 350 | test eax, eax |
351 | jnz @f |
||
6011 | hidnplayr | 352 | call net_ptr_to_num4 |
3644 | hidnplayr | 353 | inc [TCP_segments_tx + edi] |
354 | @@: |
||
3545 | hidnplayr | 355 | ret |
356 | |||
357 | .error: |
||
3556 | hidnplayr | 358 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_respond_socket: failed\n" |
3545 | hidnplayr | 359 | add esp, 2 + 4 |
360 | |||
361 | ret |
||
362 | |||
363 | |||
5976 | hidnplayr | 364 | ;-----------------------------------------------------------------; |
365 | ; ; |
||
6011 | hidnplayr | 366 | ; tcp_respond_segment ; |
5976 | hidnplayr | 367 | ; ; |
368 | ; IN: ebx = device ptr ; |
||
369 | ; edx = segment ptr (a previously received segment) ; |
||
370 | ; edi = ptr to IPv4 header ; |
||
371 | ; cl = flags ; |
||
372 | ; ; |
||
373 | ; OUT: / ; |
||
374 | ; ; |
||
375 | ;-----------------------------------------------------------------; |
||
3545 | hidnplayr | 376 | align 4 |
6011 | hidnplayr | 377 | tcp_respond_segment: |
3545 | hidnplayr | 378 | |
5842 | hidnplayr | 379 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_respond_segment: frame=%x flags=%x\n", edx, cl |
3545 | hidnplayr | 380 | |
381 | ;--------------------- |
||
382 | ; Create the IP packet |
||
383 | |||
384 | push cx edx |
||
5842 | hidnplayr | 385 | mov edx, [edi + IPv4_header.DestinationAddress] |
386 | mov edi, [edi + IPv4_header.SourceAddress] |
||
3545 | hidnplayr | 387 | mov ecx, sizeof.TCP_header |
5842 | hidnplayr | 388 | mov ax, IP_PROTO_TCP shl 8 + 128 |
6011 | hidnplayr | 389 | call ipv4_output |
3545 | hidnplayr | 390 | jz .error |
391 | pop esi cx |
||
392 | |||
5522 | hidnplayr | 393 | push eax |
3545 | hidnplayr | 394 | |
395 | ;--------------------------------------------------- |
||
396 | ; Fill in the TCP header by using a received segment |
||
397 | |||
398 | mov ax, [esi + TCP_header.DestinationPort] |
||
399 | stosw |
||
400 | mov ax, [esi + TCP_header.SourcePort] |
||
401 | stosw |
||
402 | mov eax, [esi + TCP_header.AckNumber] |
||
403 | bswap eax |
||
404 | stosd |
||
405 | xor eax, eax |
||
406 | stosd |
||
407 | mov al, 0x50 ; Dataoffset: 20 bytes (sizeof.TCP_header/4 shl 4) |
||
408 | stosb |
||
409 | mov al, cl |
||
410 | stosb |
||
411 | mov ax, 1280 |
||
412 | rol ax, 8 |
||
413 | stosw ; window |
||
414 | xor eax, eax |
||
415 | stosd ; checksum + urgentpointer |
||
416 | |||
417 | ;--------------------- |
||
418 | ; Fill in the checksum |
||
419 | |||
420 | lea esi, [edi - sizeof.TCP_header] |
||
421 | mov ecx, sizeof.TCP_header |
||
6011 | hidnplayr | 422 | tcp_checksum (esi - sizeof.IPv4_header + IPv4_header.DestinationAddress),\ ; FIXME |
3545 | hidnplayr | 423 | (esi - sizeof.IPv4_header + IPv4_header.SourceAddress) |
424 | mov [esi + TCP_header.Checksum], dx |
||
425 | |||
426 | ;-------------------- |
||
427 | ; And send the segment |
||
428 | |||
429 | call [ebx + NET_DEVICE.transmit] |
||
3644 | hidnplayr | 430 | test eax, eax |
431 | jnz @f |
||
6011 | hidnplayr | 432 | call net_ptr_to_num4 |
3644 | hidnplayr | 433 | inc [TCP_segments_tx + edi] |
434 | @@: |
||
3545 | hidnplayr | 435 | ret |
436 | |||
437 | .error: |
||
3556 | hidnplayr | 438 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_respond_segment: failed\n" |
3545 | hidnplayr | 439 | add esp, 2+4 |
440 | |||
441 | ret |
||
442 | |||
443 | |||
6011 | hidnplayr | 444 | macro tcpt_rangeset timer, value, min, max { |
3545 | hidnplayr | 445 | |
446 | local .min |
||
447 | local .max |
||
448 | local .done |
||
449 | |||
450 | cmp value, min |
||
451 | jb .min |
||
452 | cmp value, max |
||
453 | ja .max |
||
454 | mov timer, value |
||
455 | jmp .done |
||
456 | .min: |
||
6512 | hidnplayr | 457 | mov timer, min |
3545 | hidnplayr | 458 | jmp .done |
459 | .max: |
||
6512 | hidnplayr | 460 | mov timer, max |
3545 | hidnplayr | 461 | .done: |
462 | } |
||
463 | |||
5976 | hidnplayr | 464 | ;-----------------------------------------------------------------; |
465 | ; ; |
||
6011 | hidnplayr | 466 | ; tcp_set_persist ; |
5976 | hidnplayr | 467 | ; ; |
468 | ;-----------------------------------------------------------------; |
||
3545 | hidnplayr | 469 | align 4 |
6011 | hidnplayr | 470 | tcp_set_persist: |
3545 | hidnplayr | 471 | |
3556 | hidnplayr | 472 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_set_persist\n" |
3545 | hidnplayr | 473 | |
474 | ; First, check if retransmit timer is not set, retransmit and persist are mutually exclusive |
||
475 | |||
3600 | hidnplayr | 476 | test [eax + TCP_SOCKET.timer_flags], timer_flag_retransmission |
477 | jnz .exit |
||
3545 | hidnplayr | 478 | |
479 | ; calculate RTO |
||
480 | push ebx |
||
481 | mov ebx, [eax + TCP_SOCKET.t_srtt] |
||
482 | shr ebx, 2 |
||
483 | add ebx, [eax + TCP_SOCKET.t_rttvar] |
||
484 | shr ebx, 1 |
||
485 | |||
486 | mov cl, [eax + TCP_SOCKET.t_rxtshift] |
||
487 | shl ebx, cl |
||
488 | |||
489 | ; Start/restart persistance timer. |
||
490 | |||
6011 | hidnplayr | 491 | tcpt_rangeset [eax + TCP_SOCKET.timer_persist], ebx, TCP_time_pers_min, TCP_time_pers_max |
3600 | hidnplayr | 492 | or [ebx + TCP_SOCKET.timer_flags], timer_flag_persist |
3545 | hidnplayr | 493 | pop ebx |
494 | |||
495 | cmp [eax + TCP_SOCKET.t_rxtshift], TCP_max_rxtshift |
||
496 | jae @f |
||
497 | inc [eax + TCP_SOCKET.t_rxtshift] |
||
498 | @@: |
||
3600 | hidnplayr | 499 | .exit: |
3545 | hidnplayr | 500 | |
501 | ret |
||
502 | |||
503 | |||
504 | |||
5976 | hidnplayr | 505 | ;-----------------------------------------------------------------; |
506 | ; ; |
||
6011 | hidnplayr | 507 | ; tcp_xmit_timer: Calculate new smoothed RTT. ; |
5976 | hidnplayr | 508 | ; ; |
509 | ; IN: eax = rtt ; |
||
510 | ; ebx = socket ptr ; |
||
511 | ; ; |
||
512 | ; OUT: / ; |
||
513 | ; ; |
||
514 | ;-----------------------------------------------------------------; |
||
3545 | hidnplayr | 515 | align 4 |
6011 | hidnplayr | 516 | tcp_xmit_timer: |
3545 | hidnplayr | 517 | |
5976 | hidnplayr | 518 | DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_xmit_timer: socket=0x%x rtt=%d0ms\n", ebx, eax |
3545 | hidnplayr | 519 | |
6476 | hidnplayr | 520 | inc [TCPS_rttupdated] |
3545 | hidnplayr | 521 | |
522 | cmp [ebx + TCP_SOCKET.t_rtt], 0 |
||
523 | je .no_rtt_yet |
||
524 | |||
525 | ; srtt is stored as a fixed point with 3 bits after the binary point. |
||
526 | ; The following magic is equivalent of the smoothing algorithm in rfc793 with an alpha of .875 |
||
527 | ; (srtt = rtt/8 + srtt*7/8 in fixed point) |
||
528 | ; Adjust rtt to origin 0. |
||
529 | |||
530 | push ecx |
||
531 | mov ecx, [ebx + TCP_SOCKET.t_srtt] |
||
532 | shr ecx, TCP_RTT_SHIFT |
||
533 | sub eax, ecx |
||
534 | dec eax |
||
535 | pop ecx |
||
536 | |||
537 | add [ebx + TCP_SOCKET.t_srtt], eax |
||
538 | ja @f |
||
539 | mov [ebx + TCP_SOCKET.t_srtt], 1 |
||
540 | @@: |
||
541 | |||
542 | ; We accumulate a smoothed rtt variance (actually, a smoothed mean difference), |
||
543 | ; then set the retransmit timer to smoothed rtt + 4 times the smoothed variance. |
||
544 | ; rttvar is stored as fixed point with 2 bits after the binary point. |
||
545 | ; The following is equivalent to rfc793 smoothing with an alpha of .75 |
||
546 | ; (rttvar = rttvar*3/4 + delta/4) (delta = eax) |
||
547 | |||
548 | ; get abs(eax) |
||
549 | push edx |
||
550 | cdq |
||
551 | xor eax, edx |
||
552 | sub eax, edx |
||
553 | |||
554 | mov edx, [ebx + TCP_SOCKET.t_rttvar] |
||
555 | shr edx, TCP_RTTVAR_SHIFT |
||
556 | sub eax, edx |
||
557 | pop edx |
||
558 | |||
559 | add [ebx + TCP_SOCKET.t_rttvar], eax |
||
560 | ja @f |
||
561 | mov [ebx + TCP_SOCKET.t_rttvar], 1 |
||
562 | @@: |
||
563 | ret |
||
564 | |||
565 | |||
566 | .no_rtt_yet: |
||
567 | push ecx |
||
568 | mov ecx, eax |
||
569 | shl ecx, TCP_RTT_SHIFT |
||
570 | mov [ebx + TCP_SOCKET.t_srtt], ecx |
||
571 | |||
572 | shl eax, TCP_RTTVAR_SHIFT - 1 |
||
573 | mov [ebx + TCP_SOCKET.t_rttvar], eax |
||
574 | pop ecx |
||
575 | |||
576 | ret |
||
577 | |||
578 | |||
5976 | hidnplayr | 579 | ;-----------------------------------------------------------------; |
580 | ; ; |
||
6011 | hidnplayr | 581 | ; tcp_mss: Update maximum segment size ; |
5976 | hidnplayr | 582 | ; ; |
583 | ; IN: eax = max segment size ; |
||
584 | ; ebx = socket ptr ; |
||
585 | ; ; |
||
586 | ; OUT: / ; |
||
587 | ; ; |
||
588 | ;-----------------------------------------------------------------; |
||
3545 | hidnplayr | 589 | align 4 |
6011 | hidnplayr | 590 | tcp_mss: |
3545 | hidnplayr | 591 | |
5976 | hidnplayr | 592 | cmp eax, 1420 ; FIXME |
3545 | hidnplayr | 593 | jbe @f |
594 | mov eax, 1420 |
||
595 | @@: |
||
596 | mov [ebx + TCP_SOCKET.t_maxseg], eax |
||
597 | |||
598 | |||
599 | ret |
||
600 | |||
601 | |||
602 | |||
5976 | hidnplayr | 603 | ;-----------------------------------------------------------------; |
604 | ; ; |
||
6011 | hidnplayr | 605 | ; tcp_reassemble ; |
5976 | hidnplayr | 606 | ; ; |
607 | ; IN: ebx = socket ptr ; |
||
608 | ; edx = segment ptr ; |
||
609 | ; ; |
||
610 | ; OUT: / ; |
||
611 | ; ; |
||
612 | ;-----------------------------------------------------------------; |
||
3545 | hidnplayr | 613 | align 4 |
6011 | hidnplayr | 614 | tcp_reassemble: |
3545 | hidnplayr | 615 | |
5976 | hidnplayr | 616 | ;;;;; TODO |
3545 | hidnplayr | 617 | |
618 | ret |
||
619 |