Subversion Repositories Kolibri OS

Rev

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

Rev 6907 Rev 6908
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: 6907 $
17
$Revision: 6908 $
18
 
18
 
19
TCP_BIT_NEEDOUTPUT      = 1 shl 0
19
TCP_BIT_NEEDOUTPUT      = 1 shl 0
20
TCP_BIT_TIMESTAMP       = 1 shl 1
20
TCP_BIT_TIMESTAMP       = 1 shl 1
Line 35... Line 35...
35
;  OUT: /                                                         ;
35
;  OUT: /                                                         ;
36
;                                                                 ;
36
;                                                                 ;
37
;-----------------------------------------------------------------;
37
;-----------------------------------------------------------------;
38
align 4
38
align 4
39
tcp_input:
39
tcp_input:
40
        DEBUGF 1, "tcp_input!\n"
-
 
-
 
40
 
41
; record the current time
41
; record the current time
42
        push    [timer_ticks]           ; in 1/100 seconds
42
        push    [timer_ticks]           ; in 1/100 seconds
43
        push    ebx ecx esi edx         ; mind the order (see TCP_queue_entry struct)
43
        push    ebx ecx esi edx         ; mind the order (see TCP_queue_entry struct)
44
        mov     esi, esp
44
        mov     esi, esp
Line 52... Line 52...
52
 
52
 
53
        xor     edx, edx
53
        xor     edx, edx
54
        mov     eax, [TCP_input_event]
54
        mov     eax, [TCP_input_event]
55
        mov     ebx, [eax + EVENT.id]
55
        mov     ebx, [eax + EVENT.id]
56
        xor     esi, esi
-
 
57
;        DEBUGF  1, "Raising Event on TCP input\n"
56
        xor     esi, esi
Line 58... Line 57...
58
        call    raise_event
57
        call    raise_event
Line 59... Line 58...
59
 
58
 
Line 95... Line 94...
95
 
94
 
96
  .wait:
95
  .wait:
97
        mov     eax, [TCP_input_event]
96
        mov     eax, [TCP_input_event]
98
        mov     ebx, [eax + EVENT.id]
97
        mov     ebx, [eax + EVENT.id]
99
        call    wait_event
-
 
Line 100... Line 98...
100
        DEBUGF 1, "Woke up with tcp_input_event\n"
98
        call    wait_event
101
 
99
 
Line 102... Line 100...
102
  .loop:
100
  .loop:
Line 109... Line 107...
109
        mov     ebx, [esi + TCP_queue_entry.device_ptr]
107
        mov     ebx, [esi + TCP_queue_entry.device_ptr]
110
        mov     ecx, [esi + TCP_queue_entry.segment_size]
108
        mov     ecx, [esi + TCP_queue_entry.segment_size]
111
        mov     edi, [esi + TCP_queue_entry.ip_ptr]                     ; ptr to ipv4 header
109
        mov     edi, [esi + TCP_queue_entry.ip_ptr]                     ; ptr to ipv4 header
112
        mov     esi, [esi + TCP_queue_entry.segment_ptr]                ; change esi last
110
        mov     esi, [esi + TCP_queue_entry.segment_ptr]                ; change esi last
Line 113... Line 111...
113
 
111
 
Line 114... Line 112...
114
        DEBUGF  1, "TCP_input: size=%u time=%d\n", ecx, [timer_ticks]
112
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: size=%u time=%d\n", ecx, [timer_ticks]
Line 115... Line 113...
115
 
113
 
Line 139... Line 137...
139
        jb      .drop_no_socket                 ; If not, drop the packet
137
        jb      .drop_no_socket                 ; If not, drop the packet
140
        mov     [dataoffset], eax
138
        mov     [dataoffset], eax
Line 141... Line 139...
141
 
139
 
142
        sub     ecx, eax                                                ; substract TCP header size from total segment size
140
        sub     ecx, eax                                                ; substract TCP header size from total segment size
143
        jb      .drop_no_socket                                         ; If total segment size is less then the advertised header size, drop packet
141
        jb      .drop_no_socket                                         ; If total segment size is less then the advertised header size, drop packet
Line 144... Line 142...
144
        DEBUGF  1, "TCP_input: %u bytes of data\n", ecx
142
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: %u bytes of data\n", ecx
145
 
143
 
Line 146... Line 144...
146
;-------------------------------------------
144
;-------------------------------------------
Line 201... Line 199...
201
        pusha
199
        pusha
202
        mov     ecx, socket_mutex
200
        mov     ecx, socket_mutex
203
        call    mutex_unlock
201
        call    mutex_unlock
204
        popa
202
        popa
Line 205... Line 203...
205
 
203
 
Line 206... Line 204...
206
        DEBUGF  1, "TCP_input: socket ptr=%x state=%u flags=%x\n", ebx, [ebx + TCP_SOCKET.t_state], [edx + TCP_header.Flags]:2
204
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: socket ptr=%x state=%u flags=%x\n", ebx, [ebx + TCP_SOCKET.t_state], [edx + TCP_header.Flags]:2
207
 
205
 
Line 208... Line 206...
208
;----------------------------
206
;----------------------------
Line 217... Line 215...
217
        pusha
215
        pusha
218
        lea     ecx, [ebx + SOCKET.mutex]
216
        lea     ecx, [ebx + SOCKET.mutex]
219
        call    mutex_lock
217
        call    mutex_lock
220
        popa
218
        popa
Line 221... Line 219...
221
 
219
 
Line 222... Line 220...
222
        DEBUGF  1, "TCP_input: socket locked\n"
220
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: socket locked\n"
223
 
221
 
Line 224... Line 222...
224
;---------------------------
222
;---------------------------
Line 243... Line 241...
243
;-----------------------------------------------------------------------------------
241
;-----------------------------------------------------------------------------------
Line 244... Line 242...
244
 
242
 
245
        test    [ebx + SOCKET.options], SO_ACCEPTCON
243
        test    [ebx + SOCKET.options], SO_ACCEPTCON
Line 246... Line 244...
246
        jz      .no_accept
244
        jz      .no_accept
Line 247... Line 245...
247
 
245
 
Line 248... Line 246...
248
        DEBUGF  1, "TCP_input: Accepting new connection\n"
246
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Accepting new connection\n"
249
 
247
 
Line 300... Line 298...
300
 
298
 
301
        mov     ecx, [dataoffset]
299
        mov     ecx, [dataoffset]
302
        cmp     ecx, sizeof.TCP_header          ; Does header contain any options?
300
        cmp     ecx, sizeof.TCP_header          ; Does header contain any options?
Line 303... Line 301...
303
        je      .no_options
301
        je      .no_options
Line 304... Line 302...
304
 
302
 
305
        DEBUGF  1, "TCP_input: Segment has options\n"
303
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Segment has options\n"
Line 306... Line 304...
306
 
304
 
Line 323... Line 321...
323
        je      .opt_sack_permit
321
        je      .opt_sack_permit
324
;        cmp     al, TCP_OPT_SACK
322
;        cmp     al, TCP_OPT_SACK
325
;        je      .opt_sack
323
;        je      .opt_sack
326
        cmp     al, TCP_OPT_TIMESTAMP
324
        cmp     al, TCP_OPT_TIMESTAMP
327
        je      .opt_timestamp
325
        je      .opt_timestamp
328
        DEBUGF  1, "TCP_input: unknown option:%u\n", al
326
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: unknown option:%u\n", al
329
        jmp     .no_options                     ; If we reach here, some unknown options were received, skip them all!
327
        jmp     .no_options                     ; If we reach here, some unknown options were received, skip them all!
Line 330... Line 328...
330
 
328
 
331
  .opt_maxseg:
329
  .opt_maxseg:
332
        lodsb
330
        lodsb
Line 337... Line 335...
337
        jz      @f
335
        jz      @f
Line 338... Line 336...
338
 
336
 
339
        xor     eax, eax
337
        xor     eax, eax
340
        lodsw
338
        lodsw
341
        rol     ax, 8
339
        rol     ax, 8
342
        DEBUGF  1, "TCP_input: Maxseg=%u\n", eax
340
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Maxseg=%u\n", eax
343
        call    tcp_mss
341
        call    tcp_mss
344
       @@:
342
       @@:
Line 351... Line 349...
351
        jne     .no_options
349
        jne     .no_options
Line 352... Line 350...
352
 
350
 
353
        test    [edx + TCP_header.Flags], TH_SYN
351
        test    [edx + TCP_header.Flags], TH_SYN
Line 354... Line 352...
354
        jz      @f
352
        jz      @f
355
 
353
 
Line 356... Line 354...
356
        DEBUGF  1, "TCP_input: Got window scale option\n"
354
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Got window scale option\n"
357
        or      [ebx + TCP_SOCKET.t_flags], TF_RCVD_SCALE
355
        or      [ebx + TCP_SOCKET.t_flags], TF_RCVD_SCALE
358
 
356
 
Line 370... Line 368...
370
        jne     .no_options
368
        jne     .no_options
Line 371... Line 369...
371
 
369
 
372
        test    [edx + TCP_header.Flags], TH_SYN
370
        test    [edx + TCP_header.Flags], TH_SYN
Line 373... Line 371...
373
        jz      @f
371
        jz      @f
374
 
372
 
Line 375... Line 373...
375
        DEBUGF  1, "TCP_input: Selective Acknowledgement permitted\n"
373
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Selective Acknowledgement permitted\n"
376
        or      [ebx + TCP_SOCKET.t_flags], TF_SACK_PERMIT
374
        or      [ebx + TCP_SOCKET.t_flags], TF_SACK_PERMIT
Line 382... Line 380...
382
  .opt_timestamp:
380
  .opt_timestamp:
383
        lodsb
381
        lodsb
384
        cmp     al, 10                          ; length must be 10
382
        cmp     al, 10                          ; length must be 10
385
        jne     .no_options
383
        jne     .no_options
Line 386... Line 384...
386
 
384
 
Line 387... Line 385...
387
        DEBUGF  1, "TCP_input: Got timestamp option\n"
385
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Got timestamp option\n"
388
 
386
 
389
        test    [edx + TCP_header.Flags], TH_SYN
387
        test    [edx + TCP_header.Flags], TH_SYN
390
        jz      @f
388
        jz      @f
Line 407... Line 405...
407
        test    eax, eax
405
        test    eax, eax
408
        jz      .no_paws
406
        jz      .no_paws
409
        cmp     eax, [ebx + TCP_SOCKET.ts_val]
407
        cmp     eax, [ebx + TCP_SOCKET.ts_val]
410
        jbe     .no_paws
408
        jbe     .no_paws
Line 411... Line 409...
411
 
409
 
Line 412... Line 410...
412
        DEBUGF  1, "TCP_input: PAWS: detected an old segment\n"
410
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: PAWS: detected an old segment\n"
413
 
411
 
Line 414... Line 412...
414
        mov     eax, [timestamp]
412
        mov     eax, [timestamp]
Line 497... Line 495...
497
; - The acknowledgment field in the segment is greater than the largest unacknowledged sequence number.
495
; - The acknowledgment field in the segment is greater than the largest unacknowledged sequence number.
Line 498... Line 496...
498
 
496
 
499
        sub     eax, [ebx + TCP_SOCKET.SND_UNA]
497
        sub     eax, [ebx + TCP_SOCKET.SND_UNA]
Line 500... Line 498...
500
        jbe     .not_uni_xfer
498
        jbe     .not_uni_xfer
Line 501... Line 499...
501
 
499
 
502
        DEBUGF  1, "TCP_input: Header prediction: we are sender\n"
500
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Header prediction: we are sender\n"
Line 503... Line 501...
503
 
501
 
Line 581... Line 579...
581
        cmp     [ebx + TCP_SOCKET.seg_next], 0
579
        cmp     [ebx + TCP_SOCKET.seg_next], 0
582
        jne     .not_uni_xfer
580
        jne     .not_uni_xfer
Line 583... Line 581...
583
 
581
 
Line 584... Line 582...
584
; Complete processing of received data
582
; Complete processing of received data
Line 585... Line 583...
585
 
583
 
586
        DEBUGF  1, "TCP_input: Header prediction: we are receiving %u bytes\n", ecx
584
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Header prediction: we are receiving %u bytes\n", ecx
587
 
585
 
588
        mov     esi, [dataoffset]
586
        mov     esi, [dataoffset]
589
        add     esi, edx
587
        add     esi, edx
Line 590... Line 588...
590
        lea     eax, [ebx + STREAM_SOCKET.rcv]
588
        lea     eax, [ebx + STREAM_SOCKET.rcv]
591
        call    socket_ring_write                       ; Add the data to the socket buffer
-
 
592
        add     [ebx + TCP_SOCKET.RCV_NXT], ecx         ; Update sequence number with number of bytes we have copied
589
        call    socket_ring_write                       ; Add the data to the socket buffer
Line 593... Line 590...
593
 
590
        add     [ebx + TCP_SOCKET.RCV_NXT], ecx         ; Update sequence number with number of bytes we have copied
Line 594... Line 591...
594
        mov     eax, ebx
591
 
Line 605... Line 602...
605
; TCP segment processing, the slow way
602
; TCP segment processing, the slow way
606
;
603
;
607
;-----------------------------------------------------------------------------------
604
;-----------------------------------------------------------------------------------
Line 608... Line 605...
608
 
605
 
609
  .not_uni_xfer:
606
  .not_uni_xfer:
Line 610... Line 607...
610
        DEBUGF  1, "TCP_input: Header prediction failed\n"
607
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Header prediction failed\n"
Line 611... Line 608...
611
 
608
 
612
; Calculate receive window size
609
; Calculate receive window size
613
 
610
 
614
        push    edx
611
        push    edx
615
        mov     eax, SOCKET_BUFFER_SIZE
612
        mov     eax, SOCKET_BUFFER_SIZE
616
        sub     eax, [ebx + STREAM_SOCKET.rcv.size]
613
        sub     eax, [ebx + STREAM_SOCKET.rcv.size]
617
        DEBUGF  1, "Space in receive buffer=%d\n", eax
614
        DEBUGF  DEBUG_NETWORK_VERBOSE, "Space in receive buffer=%d\n", eax
618
        mov     edx, [ebx + TCP_SOCKET.RCV_ADV]
615
        mov     edx, [ebx + TCP_SOCKET.RCV_ADV]
619
        sub     edx, [ebx + TCP_SOCKET.RCV_NXT]
616
        sub     edx, [ebx + TCP_SOCKET.RCV_NXT]
620
        DEBUGF  1, "Current advertised window=%d\n", edx
617
        DEBUGF  DEBUG_NETWORK_VERBOSE, "Current advertised window=%d\n", edx
621
        cmp     eax, edx
618
        cmp     eax, edx
622
        jg      @f
619
        jg      @f
623
        mov     eax, edx
620
        mov     eax, edx
624
       @@:
621
       @@:
Line 625... Line 622...
625
        DEBUGF  1, "Receive window size=%d\n", eax
622
        DEBUGF  DEBUG_NETWORK_VERBOSE, "Receive window size=%d\n", eax
Line 647... Line 644...
647
 
644
 
648
        mov     eax, [ebx + TCP_SOCKET.RCV_NXT]
645
        mov     eax, [ebx + TCP_SOCKET.RCV_NXT]
649
        sub     eax, [edx + TCP_header.SequenceNumber]
646
        sub     eax, [edx + TCP_header.SequenceNumber]
Line 650... Line 647...
650
        jle     .no_duplicate
647
        jle     .no_duplicate
Line 651... Line 648...
651
 
648
 
Line 652... Line 649...
652
        DEBUGF  1, "TCP_input: %u bytes duplicate data!\n", eax
649
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: %u bytes duplicate data!\n", eax
653
 
650
 
Line 654... Line 651...
654
; Check for duplicate SYN
651
; Check for duplicate SYN
Line 655... Line 652...
655
 
652
 
656
        test    [edx + TCP_header.Flags], TH_SYN
653
        test    [edx + TCP_header.Flags], TH_SYN
Line 657... Line 654...
657
        jz      .no_dup_syn
654
        jz      .no_dup_syn
Line 701... Line 698...
701
  .dup_processed:
698
  .dup_processed:
Line 702... Line 699...
702
 
699
 
703
;-----------------------------------------------
700
;-----------------------------------------------
Line 704... Line 701...
704
; Remove duplicate data and update urgent offset
701
; Remove duplicate data and update urgent offset
Line 705... Line 702...
705
 
702
 
Line 706... Line 703...
706
        DEBUGF  1, "TCP_input: trimming duplicate data\n"
703
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: trimming duplicate data\n"
707
 
704
 
Line 741... Line 738...
741
        add     eax, ecx
738
        add     eax, ecx
742
        sub     eax, [ebx + TCP_SOCKET.RCV_NXT]
739
        sub     eax, [ebx + TCP_SOCKET.RCV_NXT]
743
        sub     eax, [ebx + TCP_SOCKET.RCV_WND]         ; eax now holds the number of bytes to drop
740
        sub     eax, [ebx + TCP_SOCKET.RCV_WND]         ; eax now holds the number of bytes to drop
744
        jle     .no_excess_data
741
        jle     .no_excess_data
Line 745... Line 742...
745
 
742
 
Line 746... Line 743...
746
        DEBUGF  1, "%d bytes beyond right edge of window\n", eax
743
        DEBUGF  DEBUG_NETWORK_VERBOSE, "%d bytes beyond right edge of window\n", eax
Line 747... Line 744...
747
 
744
 
748
        inc     [TCPS_rcvpackafterwin]
745
        inc     [TCPS_rcvpackafterwin]
Line 779... Line 776...
779
 
776
 
780
        or      [ebx + TCP_SOCKET.t_flags], TF_ACKNOW
777
        or      [ebx + TCP_SOCKET.t_flags], TF_ACKNOW
781
        inc     [TCPS_rcvwinprobe]
778
        inc     [TCPS_rcvwinprobe]
782
  .dont_drop_all:
779
  .dont_drop_all:
783
        add     [TCPS_rcvbyteafterwin], eax
780
        add     [TCPS_rcvbyteafterwin], eax
Line 784... Line 781...
784
        DEBUGF  1, "Trimming %u bytes from the right of the window\n"
781
        DEBUGF  DEBUG_NETWORK_VERBOSE, "Trimming %u bytes from the right of the window\n"
Line 785... Line 782...
785
 
782
 
786
; remove data from the right side of window (decrease data length)
783
; remove data from the right side of window (decrease data length)
Line 807... Line 804...
807
        dec     eax
804
        dec     eax
808
       @@:
805
       @@:
809
        sub     eax, ecx
806
        sub     eax, ecx
810
        jae     .no_timestamp
807
        jae     .no_timestamp
Line 811... Line 808...
811
 
808
 
Line 812... Line 809...
812
        DEBUGF  1, "Recording timestamp\n"
809
        DEBUGF  DEBUG_NETWORK_VERBOSE, "Recording timestamp\n"
813
 
810
 
814
        mov     eax, [timestamp]
811
        mov     eax, [timestamp]
815
        mov     [ebx + TCP_SOCKET.ts_recent_age], eax
812
        mov     [ebx + TCP_SOCKET.ts_recent_age], eax
Line 824... Line 821...
824
;-----------------------------------------------------------------------------------
821
;-----------------------------------------------------------------------------------
Line 825... Line 822...
825
 
822
 
826
        test    [edx + TCP_header.Flags], TH_RST
823
        test    [edx + TCP_header.Flags], TH_RST
Line 827... Line 824...
827
        jz      .no_rst
824
        jz      .no_rst
Line 828... Line 825...
828
 
825
 
829
        DEBUGF  1, "TCP_input: Got an RST flag\n"
826
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Got an RST flag\n"
830
 
827
 
Line 846... Line 843...
846
        dd      .econnreset     ; TCPS_FIN_WAIT_2
843
        dd      .econnreset     ; TCPS_FIN_WAIT_2
847
        dd      .rst_close      ; TCPS_TIME_WAIT
844
        dd      .rst_close      ; TCPS_TIME_WAIT
Line 848... Line 845...
848
 
845
 
849
;-----------------------------------------------------------------------------------
846
;-----------------------------------------------------------------------------------
850
  .econnrefused:
847
  .econnrefused:
851
        DEBUGF  1, "TCP_input: Connection refused\n"
848
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Connection refused\n"
852
        mov     [ebx + SOCKET.errorcode], ECONNREFUSED
849
        mov     [ebx + SOCKET.errorcode], ECONNREFUSED
Line 853... Line 850...
853
        jmp     .close
850
        jmp     .close
854
 
851
 
855
;-----------------------------------------------------------------------------------
852
;-----------------------------------------------------------------------------------
856
  .econnreset:
853
  .econnreset:
857
        DEBUGF  1, "TCP_input: Connection reset\n"
854
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Connection reset\n"
858
        mov     [ebx + SOCKET.errorcode], ECONNRESET
855
        mov     [ebx + SOCKET.errorcode], ECONNRESET
859
  .close:
856
  .close:
860
        DEBUGF  1, "TCP_input: Closing connection\n"
857
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Closing connection\n"
Line 861... Line 858...
861
        mov     [ebx + TCP_SOCKET.t_state], TCPS_CLOSED
858
        mov     [ebx + TCP_SOCKET.t_state], TCPS_CLOSED
Line 862... Line 859...
862
        inc     [TCPS_drops]
859
        inc     [TCPS_drops]
863
 
860
 
864
 
861
 
865
        jmp     .drop
862
        jmp     .drop
Line 866... Line 863...
866
 
863
 
867
;-----------------------------------------------------------------------------------
864
;-----------------------------------------------------------------------------------
Line 902... Line 899...
902
 
899
 
903
        cmp     [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
900
        cmp     [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
904
        jb      .ack_processed                                  ; states: closed, listen, syn_sent
901
        jb      .ack_processed                                  ; states: closed, listen, syn_sent
Line 905... Line 902...
905
        ja      .no_syn_rcv                                     ; established, fin_wait_1, fin_wait_2, close_wait, closing, last_ack, time_wait
902
        ja      .no_syn_rcv                                     ; established, fin_wait_1, fin_wait_2, close_wait, closing, last_ack, time_wait
Line 906... Line 903...
906
 
903
 
907
        DEBUGF  1, "TCP_input: state=syn_received\n"
904
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: state=syn_received\n"
908
 
905
 
909
        mov     eax, [edx + TCP_header.AckNumber]
906
        mov     eax, [edx + TCP_header.AckNumber]
Line 955... Line 952...
955
        mov     eax, dword[edx + TCP_header.Window]
952
        mov     eax, dword[edx + TCP_header.Window]
956
        cmp     eax, [ebx + TCP_SOCKET.SND_WND]
953
        cmp     eax, [ebx + TCP_SOCKET.SND_WND]
957
        jne     .reset_dupacks
954
        jne     .reset_dupacks
Line 958... Line 955...
958
 
955
 
959
        inc     [TCPS_rcvdupack]
956
        inc     [TCPS_rcvdupack]
Line 960... Line 957...
960
        DEBUGF  1, "TCP_input: Processing duplicate ACK\n"
957
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Processing duplicate ACK\n"
961
 
958
 
962
; If we have outstanding data, other than a window probe, this is a completely duplicate ACK
959
; If we have outstanding data, other than a window probe, this is a completely duplicate ACK
Line 976... Line 973...
976
        inc     [ebx + TCP_SOCKET.t_dupacks]
973
        inc     [ebx + TCP_SOCKET.t_dupacks]
977
        cmp     [ebx + TCP_SOCKET.t_dupacks], TCP_re_xmit_thresh
974
        cmp     [ebx + TCP_SOCKET.t_dupacks], TCP_re_xmit_thresh
978
        jb      .dup_ack_complete
975
        jb      .dup_ack_complete
979
        ja      .another_lost
976
        ja      .another_lost
Line 980... Line 977...
980
 
977
 
Line 981... Line 978...
981
        DEBUGF  1, "TCP_input: Re-transmitting lost segment\n"
978
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Re-transmitting lost segment\n"
Line 982... Line 979...
982
 
979
 
983
        push    [ebx + TCP_SOCKET.SND_NXT]              ; >>>>
980
        push    [ebx + TCP_SOCKET.SND_NXT]              ; >>>>
Line 1039... Line 1036...
1039
        mov     [ebx + TCP_SOCKET.SND_NXT], eax
1036
        mov     [ebx + TCP_SOCKET.SND_NXT], eax
1040
       @@:
1037
       @@:
1041
        jmp     .drop
1038
        jmp     .drop
Line 1042... Line 1039...
1042
 
1039
 
1043
  .another_lost:
1040
  .another_lost:
Line 1044... Line 1041...
1044
        DEBUGF  1, "TCP_input: Increasing congestion window\n"
1041
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Increasing congestion window\n"
1045
 
1042
 
Line 1046... Line 1043...
1046
        mov     eax, [ebx + TCP_SOCKET.t_maxseg]
1043
        mov     eax, [ebx + TCP_SOCKET.t_maxseg]
Line 1097... Line 1094...
1097
 
1094
 
1098
        mov     edi, [edx + TCP_header.AckNumber]
1095
        mov     edi, [edx + TCP_header.AckNumber]
1099
        sub     edi, [ebx + TCP_SOCKET.SND_UNA]         ; now we got the number of acked bytes in edi
1096
        sub     edi, [ebx + TCP_SOCKET.SND_UNA]         ; now we got the number of acked bytes in edi
1100
        inc     [TCPS_rcvackpack]
1097
        inc     [TCPS_rcvackpack]
1101
        add     [TCPS_rcvackbyte], edi
1098
        add     [TCPS_rcvackbyte], edi
Line 1102... Line 1099...
1102
        DEBUGF  1, "TCP_input: acceptable ACK for %u bytes\n", edi
1099
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: acceptable ACK for %u bytes\n", edi
1103
 
1100
 
1104
;-----------------------------------------------------------------------------------
1101
;-----------------------------------------------------------------------------------
1105
;
1102
;
Line 1206... Line 1203...
1206
        sub     [ebx + TCP_SOCKET.SND_WND], ecx
1203
        sub     [ebx + TCP_SOCKET.SND_WND], ecx
1207
        lea     eax, [ebx + STREAM_SOCKET.snd]
1204
        lea     eax, [ebx + STREAM_SOCKET.snd]
1208
        call    socket_ring_free
1205
        call    socket_ring_free
1209
        pop     ebx edx ecx
1206
        pop     ebx edx ecx
Line 1210... Line 1207...
1210
 
1207
 
1211
        DEBUGF  1, "TCP_input: our FIN is acked\n"
1208
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: our FIN is acked\n"
1212
        or      [temp_bits], TCP_BIT_FIN_IS_ACKED
1209
        or      [temp_bits], TCP_BIT_FIN_IS_ACKED
1213
        jmp     .ack_complete
1210
        jmp     .ack_complete
Line 1214... Line 1211...
1214
  .no_fin_ack:
1211
  .no_fin_ack:
Line 1332... Line 1329...
1332
; Initiation of Passive Open?
1329
; Initiation of Passive Open?
1333
;
1330
;
1334
;-----------------------------------------------------------------------------------
1331
;-----------------------------------------------------------------------------------
Line 1335... Line 1332...
1335
 
1332
 
1336
  .state_listen:
1333
  .state_listen:
Line 1337... Line 1334...
1337
        DEBUGF  1, "TCP_input: state=listen\n"
1334
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: state=listen\n"
1338
 
1335
 
Line 1339... Line 1336...
1339
        test    [edx + TCP_header.Flags], TH_RST
1336
        test    [edx + TCP_header.Flags], TH_RST
Line 1398... Line 1395...
1398
; Completion of active open?
1395
; Completion of active open?
1399
;
1396
;
1400
;-----------------------------------------------------------------------------------
1397
;-----------------------------------------------------------------------------------
Line 1401... Line 1398...
1401
 
1398
 
1402
  .state_syn_sent:
1399
  .state_syn_sent:
Line 1403... Line 1400...
1403
        DEBUGF  1, "TCP_input: state=syn_sent\n"
1400
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: state=syn_sent\n"
1404
 
1401
 
Line 1405... Line 1402...
1405
        test    [edx + TCP_header.Flags], TH_ACK
1402
        test    [edx + TCP_header.Flags], TH_ACK
Line 1458... Line 1455...
1458
        jbe     .simultaneous_open
1455
        jbe     .simultaneous_open
Line 1459... Line 1456...
1459
 
1456
 
1460
        test    [edx + TCP_header.Flags], TH_ACK
1457
        test    [edx + TCP_header.Flags], TH_ACK
Line 1461... Line 1458...
1461
        jz      .simultaneous_open
1458
        jz      .simultaneous_open
Line 1462... Line 1459...
1462
 
1459
 
Line 1463... Line 1460...
1463
        DEBUGF  1, "TCP_input: active open\n"
1460
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: active open\n"
Line 1499... Line 1496...
1499
; Simultaneous open (We have received a SYN but no ACK)
1496
; Simultaneous open (We have received a SYN but no ACK)
1500
;
1497
;
1501
;-----------------------------------------------------------------------------------
1498
;-----------------------------------------------------------------------------------
Line 1502... Line 1499...
1502
 
1499
 
1503
  .simultaneous_open:
1500
  .simultaneous_open:
1504
        DEBUGF  1, "TCP_input: simultaneous open\n"
1501
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: simultaneous open\n"
Line 1505... Line 1502...
1505
        mov     [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
1502
        mov     [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
1506
 
1503
 
1507
;-----------------------------------------------------------------------------------
1504
;-----------------------------------------------------------------------------------
Line 1519... Line 1516...
1519
; Drop any received data that doesnt fit in the receive window.
1516
; Drop any received data that doesnt fit in the receive window.
Line 1520... Line 1517...
1520
 
1517
 
1521
        cmp     ecx, [ebx + TCP_SOCKET.RCV_WND]
1518
        cmp     ecx, [ebx + TCP_SOCKET.RCV_WND]
Line 1522... Line 1519...
1522
        jbe     .dont_trim
1519
        jbe     .dont_trim
1523
 
1520
 
1524
        DEBUGF  1, "TCP_input: received data does not fit in window, trimming %u bytes\n", eax
1521
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: received data does not fit in window, trimming %u bytes\n", eax
1525
        inc     [TCPS_rcvpackafterwin]
1522
        inc     [TCPS_rcvpackafterwin]
Line 1526... Line 1523...
1526
        sub     ecx, [ebx + TCP_SOCKET.RCV_WND]
1523
        sub     ecx, [ebx + TCP_SOCKET.RCV_WND]
Line 1540... Line 1537...
1540
; Update window information (step 6 in RFC793)
1537
; Update window information (step 6 in RFC793)
1541
;
1538
;
1542
;-----------------------------------------------------------------------------------
1539
;-----------------------------------------------------------------------------------
Line 1543... Line 1540...
1543
 
1540
 
1544
  .ack_processed:
1541
  .ack_processed:
Line 1545... Line 1542...
1545
        DEBUGF  1, "TCP_input: ACK processed\n"
1542
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: ACK processed\n"
Line 1546... Line 1543...
1546
 
1543
 
1547
; dont look at window if no ACK
1544
; dont look at window if no ACK
Line 1592... Line 1589...
1592
        cmp     eax, [ebx + TCP_SOCKET.max_sndwnd]
1589
        cmp     eax, [ebx + TCP_SOCKET.max_sndwnd]
1593
        jbe     @f
1590
        jbe     @f
1594
        mov     [ebx + TCP_SOCKET.max_sndwnd], eax
1591
        mov     [ebx + TCP_SOCKET.max_sndwnd], eax
1595
       @@:
1592
       @@:
Line 1596... Line 1593...
1596
 
1593
 
Line 1597... Line 1594...
1597
        DEBUGF  1, "TCP_input: Updating window to %u\n", eax
1594
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Updating window to %u\n", eax
1598
 
1595
 
Line 1599... Line 1596...
1599
        push    [edx + TCP_header.SequenceNumber]
1596
        push    [edx + TCP_header.SequenceNumber]
Line 1688... Line 1685...
1688
        call    socket_notify
1685
        call    socket_notify
Line 1689... Line 1686...
1689
 
1686
 
Line 1690... Line 1687...
1690
        jmp     .data_done
1687
        jmp     .data_done
1691
 
1688
 
1692
  .out_of_order:
1689
  .out_of_order:
Line 1693... Line 1690...
1693
        DEBUGF  1,  "TCP data is out of order!\nSequencenumber is %u, we expected %u.\n", \
1690
        DEBUGF  DEBUG_NETWORK_VERBOSE,  "TCP data is out of order!\nSequencenumber is %u, we expected %u.\n", \
Line 1694... Line 1691...
1694
        [edx + TCP_header.SequenceNumber], [ebx + TCP_SOCKET.RCV_NXT]
1691
        [edx + TCP_header.SequenceNumber], [ebx + TCP_SOCKET.RCV_NXT]
Line 1710... Line 1707...
1710
;-----------------------------------------------------------------------------------
1707
;-----------------------------------------------------------------------------------
Line 1711... Line 1708...
1711
 
1708
 
1712
        test    [edx + TCP_header.Flags], TH_FIN
1709
        test    [edx + TCP_header.Flags], TH_FIN
Line 1713... Line 1710...
1713
        jz      .final_processing
1710
        jz      .final_processing
Line 1714... Line 1711...
1714
 
1711
 
1715
        DEBUGF  1, "TCP_input: Processing FIN\n"
1712
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Processing FIN\n"
Line 1716... Line 1713...
1716
 
1713
 
Line 1717... Line 1714...
1717
        cmp     [ebx + TCP_SOCKET.t_state], TCPS_TIME_WAIT
1714
        cmp     [ebx + TCP_SOCKET.t_state], TCPS_TIME_WAIT
1718
        jae     .not_first_fin
1715
        jae     .not_first_fin
Line 1719... Line 1716...
1719
 
1716
 
Line 1776... Line 1773...
1776
; Finally, drop the segment
1773
; Finally, drop the segment
1777
;
1774
;
1778
;-----------------------------------------------------------------------------------
1775
;-----------------------------------------------------------------------------------
Line 1779... Line 1776...
1779
 
1776
 
1780
  .final_processing:
1777
  .final_processing:
Line 1781... Line 1778...
1781
        DEBUGF  1, "TCP_input: Final processing\n"
1778
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Final processing\n"
1782
 
1779
 
1783
        push    ebx
1780
        push    ebx
1784
        lea     ecx, [ebx + SOCKET.mutex]
1781
        lea     ecx, [ebx + SOCKET.mutex]
Line 1788... Line 1785...
1788
        test    [temp_bits], TCP_BIT_NEEDOUTPUT
1785
        test    [temp_bits], TCP_BIT_NEEDOUTPUT
1789
        jnz     .need_output
1786
        jnz     .need_output
Line 1790... Line 1787...
1790
 
1787
 
1791
        test    [eax + TCP_SOCKET.t_flags], TF_ACKNOW
1788
        test    [eax + TCP_SOCKET.t_flags], TF_ACKNOW
1792
        jz      .done
1789
        jz      .done
Line 1793... Line 1790...
1793
        DEBUGF  1, "TCP_input: ACK now!\n"
1790
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: ACK now!\n"
1794
 
1791
 
1795
  .need_output:
1792
  .need_output:
Line 1796... Line 1793...
1796
        DEBUGF  1, "TCP_input: need output\n"
1793
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: need output\n"
1797
        call    tcp_output
1794
        call    tcp_output
Line 1798... Line 1795...
1798
 
1795
 
1799
  .done:
1796
  .done:
Line 1800... Line 1797...
1800
        DEBUGF  1, "TCP_input: dumping\n"
1797
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: dumping\n"
Line 1808... Line 1805...
1808
;
1805
;
1809
;-----------------------------------------------------------------------------------
1806
;-----------------------------------------------------------------------------------
Line 1810... Line 1807...
1810
 
1807
 
1811
;-----------------------------------------------------------------------------------
1808
;-----------------------------------------------------------------------------------
1812
  .drop_after_ack:
1809
  .drop_after_ack:
Line 1813... Line 1810...
1813
        DEBUGF  1, "TCP_input: Drop after ACK\n"
1810
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Drop after ACK\n"
1814
 
1811
 
1815
        push    edx ebx
1812
        push    edx ebx
1816
        lea     ecx, [ebx + SOCKET.mutex]
1813
        lea     ecx, [ebx + SOCKET.mutex]
Line 1823... Line 1820...
1823
        or      [eax + TCP_SOCKET.t_flags], TF_ACKNOW
1820
        or      [eax + TCP_SOCKET.t_flags], TF_ACKNOW
1824
        jmp     .need_output
1821
        jmp     .need_output
Line 1825... Line 1822...
1825
 
1822
 
1826
;-----------------------------------------------------------------------------------
1823
;-----------------------------------------------------------------------------------
1827
  .drop_with_reset:
1824
  .drop_with_reset:
Line 1828... Line 1825...
1828
        DEBUGF  1, "TCP_input: Drop with reset\n"
1825
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Drop with reset\n"
1829
 
1826
 
1830
        push    ebx edx
1827
        push    ebx edx
1831
        lea     ecx, [ebx + SOCKET.mutex]
1828
        lea     ecx, [ebx + SOCKET.mutex]
Line 1895... Line 1892...
1895
 
1892
 
1896
;------------------------------------------------
1893
;------------------------------------------------
Line 1897... Line 1894...
1897
; Unlock socket mutex and prepare to drop segment
1894
; Unlock socket mutex and prepare to drop segment
1898
 
1895
 
Line 1899... Line 1896...
1899
  .drop:
1896
  .drop:
1900
        DEBUGF  1, "TCP_input: Dropping segment\n"
1897
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Dropping segment\n"
1901
 
1898
 
1902
        pusha
1899
        pusha
Line 1916... Line 1913...
1916
 
1913
 
1917
;------------------
1914
;------------------
Line 1918... Line 1915...
1918
; Drop the segment
1915
; Drop the segment
1919
 
1916
 
Line 1920... Line 1917...
1920
  .drop_no_socket:
1917
  .drop_no_socket:
1921
        DEBUGF  1, "TCP_input: Drop (no socket)\n"
1918
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Drop (no socket)\n"
Line 1922... Line 1919...
1922
 
1919