Subversion Repositories Kolibri OS

Rev

Rev 4423 | Rev 5594 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4423 Rev 5565
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;  Part of the TCP/IP network stack for KolibriOS                 ;;
6
;;  Part of the TCP/IP network stack for KolibriOS                 ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;   Written by hidnplayr@kolibrios.org                            ;;
8
;;   Written by hidnplayr@kolibrios.org                            ;;
Line 12... Line 12...
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;             Version 2, June 1991                                ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                                 ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 16... Line 16...
16
 
16
 
Line 17... Line 17...
17
$Revision: 3289 $
17
$Revision: 5522 $
18
 
18
 
19
;-----------------------------------------------------------------
19
;-----------------------------------------------------------------
20
;
20
;
Line 88... Line 88...
88
        test    ecx, ecx
88
        test    ecx, ecx
89
        jnz     .no_zero_window
89
        jnz     .no_zero_window
Line 90... Line 90...
90
 
90
 
91
        cmp     ebx, [eax + STREAM_SOCKET.snd.size]
91
        cmp     ebx, [eax + STREAM_SOCKET.snd.size]
92
        jae     @f
-
 
93
 
92
        jae     @f
94
        and     dl, not (TH_FIN)
-
 
95
 
93
        and     dl, not (TH_FIN)
-
 
94
       @@:
96
       @@:
95
 
97
        inc     ecx
96
        inc     ecx
Line 98... Line 97...
98
        jmp     .no_force
97
        jmp     .no_force
99
 
98
 
Line 111... Line 110...
111
        jb      @f
110
        jb      @f
112
        mov     esi, ecx
111
        mov     esi, ecx
113
       @@:
112
       @@:
114
        sub     esi, ebx
113
        sub     esi, ebx
Line 115... Line -...
115
 
-
 
116
 
114
 
117
;------------------------
115
;------------------------
Line 118... Line 116...
118
; check for window shrink (107)
116
; check for window shrink (107)
119
 
117
 
Line 144... Line 142...
144
;---------------------------
142
;---------------------------
145
; Send one segment at a time (124)
143
; Send one segment at a time (124)
Line 146... Line 144...
146
 
144
 
147
        cmp     esi, [eax + TCP_SOCKET.t_maxseg]
145
        cmp     esi, [eax + TCP_SOCKET.t_maxseg]
148
        jbe     @f
-
 
149
 
146
        jbe     @f
150
        mov     esi, [eax + TCP_SOCKET.t_maxseg]
147
        mov     esi, [eax + TCP_SOCKET.t_maxseg]
151
        or      [temp_bits], TCP_BIT_SENDALOT
148
        or      [temp_bits], TCP_BIT_SENDALOT
Line 152... Line 149...
152
       @@:
149
       @@:
Line 158... Line 155...
158
        add     edi, esi
155
        add     edi, esi
159
        sub     edi, [eax + TCP_SOCKET.SND_UNA]
156
        sub     edi, [eax + TCP_SOCKET.SND_UNA]
160
        cmp     edi, [eax + STREAM_SOCKET.snd.size]
157
        cmp     edi, [eax + STREAM_SOCKET.snd.size]
161
        jae     @f
158
        jae     @f
162
        and     dl, not (TH_FIN)
159
        and     dl, not (TH_FIN)
163
 
-
 
164
       @@:
160
       @@:
Line 165... Line 161...
165
 
161
 
166
;-------------------------------
162
;-------------------------------
Line 401... Line 397...
401
 
397
 
402
        mov     esi, [eax + TCP_SOCKET.t_maxseg]
398
        mov     esi, [eax + TCP_SOCKET.t_maxseg]
403
        or      [temp_bits], TCP_BIT_SENDALOT
399
        or      [temp_bits], TCP_BIT_SENDALOT
Line -... Line 400...
-
 
400
  .no_overflow:
-
 
401
 
-
 
402
; Update stats
-
 
403
        test    esi, esi
-
 
404
        jz      .zero_data
-
 
405
 
-
 
406
        cmp     [eax + TCP_SOCKET.t_force], 1
-
 
407
        jne     @f
-
 
408
        cmp     esi, 1
-
 
409
        jne     @f
-
 
410
        inc     [TCPS_sndprobe]
-
 
411
        jmp     .eos
-
 
412
  @@:
-
 
413
 
-
 
414
        mov     ebx, [eax + TCP_SOCKET.SND_NXT]
-
 
415
        cmp     ebx, [eax + TCP_SOCKET.SND_MAX]
-
 
416
        jae     @f
-
 
417
        inc     [TCPS_sndrexmitpack]
-
 
418
        add     [TCPS_sndrexmitbyte], esi
-
 
419
        jmp     .eos
-
 
420
  @@:
-
 
421
        inc     [TCPS_sndpack]
-
 
422
        add     [TCPS_sndbyte], esi
-
 
423
        jmp     .eos
-
 
424
 
-
 
425
  .zero_data:
-
 
426
        test    [eax + TCP_SOCKET.t_flags], TF_ACKNOW
-
 
427
        jz      @f
-
 
428
        inc     [TCPS_sndacks]
-
 
429
        jmp     .eos
-
 
430
  @@:
-
 
431
        test    dl, TH_SYN + TH_FIN + TH_RST
-
 
432
        jz      @f
-
 
433
        inc     [TCPS_sndctrl]
-
 
434
        jmp     .eos
-
 
435
  @@:
-
 
436
        mov     ebx, [eax + TCP_SOCKET.SND_UP]
-
 
437
        cmp     ebx, [eax + TCP_SOCKET.SND_UNA]
-
 
438
        jb      @f
-
 
439
        inc     [TCPS_sndurg]
-
 
440
        jmp     .eos
-
 
441
  @@:
-
 
442
        inc     [TCPS_sndwinup]
-
 
443
 
404
  .no_overflow:
444
  .eos:
405
 
445
 
406
;----------------------------------------------------
446
;----------------------------------------------------
Line 407... Line 447...
407
; Calculate the receive window.
447
; Calculate the receive window.
Line 467... Line 507...
467
        mov     eax, [eax + IP_SOCKET.RemoteIP] ; dest ip
507
        mov     eax, [eax + IP_SOCKET.RemoteIP] ; dest ip
468
        mov     di, IP_PROTO_TCP shl 8 + 128
508
        mov     di, IP_PROTO_TCP shl 8 + 128
469
        call    IPv4_output
509
        call    IPv4_output
470
        jz      .ip_error
510
        jz      .ip_error
Line 471... Line 511...
471
 
511
 
472
;-----------------------------------------
512
;------------------------------------------
Line 473... Line 513...
473
; Move TCP header from stack to TCP packet
513
; Move TCP header from stack to TCP segment
474
 
514
 
475
        push    ecx
515
        push    ecx
476
        mov     ecx, [esp + 4]
516
        mov     ecx, [esp + 4]
Line 480... Line 520...
480
        pop     ecx                     ; full TCP packet size
520
        pop     ecx                     ; full TCP packet size
Line 481... Line 521...
481
 
521
 
482
        pop     esi                     ; headersize
522
        pop     esi                     ; headersize
Line 483... Line -...
483
        add     esp, esi                ; remove it from stack
-
 
484
 
523
        add     esp, esi                ; remove it from stack
Line 485... Line 524...
485
        push    edx                     ; packet size for send proc
524
 
486
        push    eax                     ; packet ptr for send proc
525
        push    eax                     ; packet ptr for send proc
487
 
526
 
Line 495... Line 534...
495
 
534
 
496
; eax = ptr to ring struct
535
; eax = ptr to ring struct
497
; ecx = buffer size
536
; ecx = buffer size
Line 498... Line 537...
498
; edi = ptr to buffer
537
; edi = ptr to buffer
Line 499... Line 538...
499
 
538
 
500
        mov     eax, [esp + 16]                 ; get socket ptr
539
        mov     eax, [esp + 12]                 ; get socket ptr
501
 
540
 
502
        push    edx
541
        push    edx
503
        push    [eax + TCP_SOCKET.SND_NXT]      ; we'll need this for timing the transmission
542
        push    [eax + TCP_SOCKET.SND_NXT]      ; we'll need this for timing the transmission
504
        test    ecx, ecx
543
        test    ecx, ecx
505
        jz      .nodata
544
        jz      .nodata
506
        mov     edx, [eax + TCP_SOCKET.SND_NXT]
545
        mov     edx, [eax + TCP_SOCKET.SND_NXT]
507
        add     [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number <<< CHECKME
546
        add     [eax + TCP_SOCKET.SND_NXT], ecx ; update sequence number
508
        sub     edx, [eax + TCP_SOCKET.SND_UNA] ; offset
547
        sub     edx, [eax + TCP_SOCKET.SND_UNA] ; offset
509
        add     eax, STREAM_SOCKET.snd
548
        add     eax, STREAM_SOCKET.snd
510
        call    SOCKET_ring_read
549
        call    SOCKET_ring_read
511
  .nodata:
550
  .nodata:
512
        pop     edi
551
        pop     edi
Line 513... Line 552...
513
        pop     esi                             ; begin of data
552
        pop     esi                             ; begin of data
514
        pop     ecx                             ; full packet size
553
        pop     ecx                             ; full packet size
Line 515... Line 554...
515
        mov     eax, [esp + 12]                 ; socket ptr
554
        mov     eax, [esp + 8]                  ; socket ptr
Line 534... Line 573...
534
 
573
 
535
        cmp     [eax + TCP_SOCKET.t_rtt], 0                     ; are we currently timing anything?
574
        cmp     [eax + TCP_SOCKET.t_rtt], 0                     ; are we currently timing anything?
536
        je      @f
575
        je      @f
537
        mov     [eax + TCP_SOCKET.t_rtt], 1                     ; nope, start transmission timer
576
        mov     [eax + TCP_SOCKET.t_rtt], 1                     ; nope, start transmission timer
538
        mov     [eax + TCP_SOCKET.t_rtseq], edi
577
        mov     [eax + TCP_SOCKET.t_rtseq], edi
539
;TODO: update stats
578
        inc     [TCPS_segstimed]
Line 540... Line 579...
540
       @@:
579
       @@:
541
 
580
 
542
; set retransmission timer if not already set, and not doing an ACK or keepalive probe
581
; set retransmission timer if not already set, and not doing an ACK or keepalive probe
Line 582... Line 621...
582
        pop     ecx
621
        pop     ecx
583
        pop     eax
622
        pop     eax
Line 584... Line 623...
584
 
623
 
585
        call    NET_ptr_to_num4
624
        call    NET_ptr_to_num4
-
 
625
        inc     [TCP_segments_tx + edi]
Line 586... Line 626...
586
        inc     [TCP_segments_tx + edi]
626
        inc     [TCPS_sndtotal]
587
 
627
 
588
; update advertised receive window
628
; update advertised receive window
589
        test    ecx, ecx
629
        test    ecx, ecx