Subversion Repositories Kolibri OS

Rev

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

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