Subversion Repositories Kolibri OS

Rev

Rev 5984 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5984 Rev 6078
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: 5976 $
17
$Revision: 6011 $
18
 
18
 
19
;-----------------------------------------------------------------;
19
;-----------------------------------------------------------------;
20
;                                                                 ;
20
;                                                                 ;
Line 29... Line 29...
29
;                                                                 ;
29
;                                                                 ;
30
;  OUT: /                                                         ;
30
;  OUT: /                                                         ;
31
;                                                                 ;
31
;                                                                 ;
32
;-----------------------------------------------------------------;
32
;-----------------------------------------------------------------;
33
align 4
33
align 4
34
TCP_input:
34
tcp_input:
Line 35... Line 35...
35
 
35
 
36
; record the current time
36
; record the current time
37
        push    [timer_ticks]           ; in 1/100 seconds
37
        push    [timer_ticks]           ; in 1/100 seconds
38
        push    ebx ecx esi edx         ; mind the order (see TCP_queue_entry struct)
38
        push    ebx ecx esi edx         ; mind the order (see TCP_queue_entry struct)
Line 55... Line 55...
55
 
55
 
56
  .fail:
56
  .fail:
57
        pop     edi
57
        pop     edi
Line 58... Line 58...
58
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP incoming queue is full, discarding packet!\n"
58
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP incoming queue is full, discarding packet!\n"
59
 
59
 
Line 60... Line 60...
60
        call    NET_ptr_to_num4
60
        call    net_ptr_to_num4
61
        inc     [TCP_segments_missed + edi]
61
        inc     [TCP_segments_missed + edi]
62
 
62
 
Line 63... Line 63...
63
        add     esp, sizeof.TCP_queue_entry - 4
63
        add     esp, sizeof.TCP_queue_entry - 4
64
        call    NET_BUFF_free
64
        call    net_buff_free
Line 65... Line 65...
65
        ret
65
        ret
66
 
66
 
67
 
67
 
68
 
68
 
Line 109... Line 109...
109
        jnz     .checksum_ok
109
        jnz     .checksum_ok
Line 110... Line 110...
110
 
110
 
111
        push    ecx esi
111
        push    ecx esi
112
        pushw   [esi + TCP_header.Checksum]
112
        pushw   [esi + TCP_header.Checksum]
113
        mov     [esi + TCP_header.Checksum], 0
113
        mov     [esi + TCP_header.Checksum], 0
114
        TCP_checksum (edi+IPv4_header.SourceAddress), (edi+IPv4_header.DestinationAddress)
114
        tcp_checksum (edi+IPv4_header.SourceAddress), (edi+IPv4_header.DestinationAddress)
115
        pop     cx                              ; previous checksum
115
        pop     cx                              ; previous checksum
116
        cmp     cx, dx
116
        cmp     cx, dx
117
        pop     edx ecx
117
        pop     edx ecx
118
        jne     .drop_no_socket
118
        jne     .drop_no_socket
Line 232... Line 232...
232
        lea     ecx, [ebx + SOCKET.mutex]
232
        lea     ecx, [ebx + SOCKET.mutex]
233
        call    mutex_unlock
233
        call    mutex_unlock
234
        popa
234
        popa
Line 235... Line 235...
235
 
235
 
236
        push    ecx edx esi edi
236
        push    ecx edx esi edi
237
        call    SOCKET_fork
237
        call    socket_fork
Line 238... Line 238...
238
        pop     edi esi edx ecx
238
        pop     edi esi edx ecx
239
 
239
 
Line 310... Line 310...
310
 
310
 
311
        xor     eax, eax
311
        xor     eax, eax
312
        lodsw
312
        lodsw
313
        rol     ax, 8
313
        rol     ax, 8
314
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Maxseg=%u\n", eax
314
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Maxseg=%u\n", eax
315
        call    TCP_mss
315
        call    tcp_mss
316
       @@:
316
       @@:
Line 317... Line 317...
317
        jmp     .opt_loop
317
        jmp     .opt_loop
Line 471... Line 471...
471
 
471
 
472
; Delete acknowledged bytes from send buffer
472
; Delete acknowledged bytes from send buffer
473
        pusha
473
        pusha
474
        mov     ecx, eax
474
        mov     ecx, eax
475
        lea     eax, [ebx + STREAM_SOCKET.snd]
475
        lea     eax, [ebx + STREAM_SOCKET.snd]
476
        call    SOCKET_ring_free
476
        call    socket_ring_free
Line 477... Line 477...
477
        popa
477
        popa
Line 478... Line 478...
478
 
478
 
479
; Update RTT estimators
479
; Update RTT estimators
480
 
480
 
481
        test    [temp_bits], TCP_BIT_TIMESTAMP
481
        test    [temp_bits], TCP_BIT_TIMESTAMP
482
        jz      .no_timestamp_rtt
482
        jz      .no_timestamp_rtt
483
        mov     eax, [timestamp]
483
        mov     eax, [timestamp]
484
        sub     eax, [ebx + TCP_SOCKET.ts_ecr]
484
        sub     eax, [ebx + TCP_SOCKET.ts_ecr]
485
        inc     eax
485
        inc     eax
Line 486... Line 486...
486
        call    TCP_xmit_timer
486
        call    tcp_xmit_timer
487
        jmp     .rtt_done
487
        jmp     .rtt_done
488
  .no_timestamp_rtt:
488
  .no_timestamp_rtt:
489
 
489
 
490
        cmp     [ebx + TCP_SOCKET.t_rtt], 0
490
        cmp     [ebx + TCP_SOCKET.t_rtt], 0
491
        je      .rtt_done
491
        je      .rtt_done
492
        mov     eax, [edx + TCP_header.AckNumber]
492
        mov     eax, [edx + TCP_header.AckNumber]
493
        cmp     eax, [ebx + TCP_SOCKET.t_rtseq]
493
        cmp     eax, [ebx + TCP_SOCKET.t_rtseq]
Line 494... Line 494...
494
        jbe     .rtt_done
494
        jbe     .rtt_done
495
        mov     eax, [ebx + TCP_SOCKET.t_rtt]
495
        mov     eax, [ebx + TCP_SOCKET.t_rtt]
496
        call    TCP_xmit_timer
496
        call    tcp_xmit_timer
Line 509... Line 509...
509
        call    mutex_unlock
509
        call    mutex_unlock
510
        popa
510
        popa
Line 511... Line 511...
511
 
511
 
512
; Awaken waiting processes
512
; Awaken waiting processes
513
        mov     eax, ebx
513
        mov     eax, ebx
Line 514... Line 514...
514
        call    SOCKET_notify
514
        call    socket_notify
515
 
515
 
Line 516... Line 516...
516
; Generate more output
516
; Generate more output
Line 517... Line 517...
517
        call    TCP_output
517
        call    tcp_output
518
 
518
 
Line 538... Line 538...
538
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Header prediction: we are receiving %u bytes\n", ecx
538
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Header prediction: we are receiving %u bytes\n", ecx
Line 539... Line 539...
539
 
539
 
540
        mov     esi, [dataoffset]
540
        mov     esi, [dataoffset]
541
        add     esi, edx
541
        add     esi, edx
542
        lea     eax, [ebx + STREAM_SOCKET.rcv]
542
        lea     eax, [ebx + STREAM_SOCKET.rcv]
543
        call    SOCKET_ring_write                       ; Add the data to the socket buffer
543
        call    socket_ring_write                       ; Add the data to the socket buffer
Line 544... Line 544...
544
        add     [ebx + TCP_SOCKET.RCV_NXT], ecx         ; Update sequence number with number of bytes we have copied
544
        add     [ebx + TCP_SOCKET.RCV_NXT], ecx         ; Update sequence number with number of bytes we have copied
545
 
545
 
Line 546... Line 546...
546
        mov     eax, ebx
546
        mov     eax, ebx
Line 547... Line 547...
547
        call    SOCKET_notify
547
        call    socket_notify
Line 659... Line 659...
659
        jbe     .not_terminated
659
        jbe     .not_terminated
660
        test    ecx, ecx
660
        test    ecx, ecx
661
        jz      .not_terminated
661
        jz      .not_terminated
Line 662... Line 662...
662
 
662
 
663
        mov     eax, ebx
663
        mov     eax, ebx
664
        call    TCP_close
664
        call    tcp_close
665
        inc     [TCPS_rcvafterclose]
665
        inc     [TCPS_rcvafterclose]
Line 666... Line 666...
666
        jmp     .respond_seg_reset
666
        jmp     .respond_seg_reset
667
 
667
 
Line 689... Line 689...
689
        jne     .no_new_request
689
        jne     .no_new_request
690
;        mov     edx, [ebx + TCP_SOCKET.RCV_NXT]
690
;        mov     edx, [ebx + TCP_SOCKET.RCV_NXT]
691
;        cmp     edx, [edx + TCP_header.SequenceNumber]
691
;        cmp     edx, [edx + TCP_header.SequenceNumber]
692
;        add     edx, 64000      ; TCP_ISSINCR   FIXME
692
;        add     edx, 64000      ; TCP_ISSINCR   FIXME
693
        mov     eax, ebx
693
        mov     eax, ebx
694
        call    TCP_close
694
        call    tcp_close
695
        jmp     .findpcb        ; FIXME: skip code for unscaling window, ...
695
        jmp     .findpcb        ; FIXME: skip code for unscaling window, ...
696
  .no_new_request:
696
  .no_new_request:
Line 697... Line 697...
697
 
697
 
698
; If window is closed, we can only take segments at window edge, and have to drop data and PUSH from
698
; If window is closed, we can only take segments at window edge, and have to drop data and PUSH from
Line 777... Line 777...
777
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Closing connection\n"
777
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Closing connection\n"
Line 778... Line 778...
778
 
778
 
779
        mov     [ebx + TCP_SOCKET.t_state], TCPS_CLOSED
779
        mov     [ebx + TCP_SOCKET.t_state], TCPS_CLOSED
780
;;; TODO: update stats (tcp drops)
780
;;; TODO: update stats (tcp drops)
781
        mov     eax, ebx
781
        mov     eax, ebx
782
        call    TCP_close
782
        call    tcp_close
Line 783... Line 783...
783
        jmp     .drop_no_socket
783
        jmp     .drop_no_socket
784
 
784
 
Line 785... Line 785...
785
  .rst_close:
785
  .rst_close:
786
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Closing with reset\n"
786
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Closing with reset\n"
787
 
787
 
Line 788... Line 788...
788
        mov     eax, ebx
788
        mov     eax, ebx
Line 789... Line 789...
789
        call    TCP_close
789
        call    tcp_close
Line 797... Line 797...
797
        test    [edx + TCP_header.Flags], TH_SYN
797
        test    [edx + TCP_header.Flags], TH_SYN
798
        jz      .not_syn_full
798
        jz      .not_syn_full
Line 799... Line 799...
799
 
799
 
800
        mov     eax, ebx
800
        mov     eax, ebx
801
        mov     ebx, ECONNRESET
801
        mov     ebx, ECONNRESET
802
        call    TCP_drop
802
        call    tcp_drop
803
        jmp     .drop_with_reset
803
        jmp     .drop_with_reset
Line 804... Line 804...
804
  .not_syn_full:
804
  .not_syn_full:
805
 
805
 
Line 822... Line 822...
822
        ja      .drop_with_reset
822
        ja      .drop_with_reset
Line 823... Line 823...
823
 
823
 
Line 824... Line 824...
824
;;; TODO: update stats
824
;;; TODO: update stats
825
 
825
 
826
        mov     eax, ebx
826
        mov     eax, ebx
Line 827... Line 827...
827
        call    SOCKET_is_connected
827
        call    socket_is_connected
Line 828... Line 828...
828
        mov     [ebx + TCP_SOCKET.t_state], TCPS_ESTABLISHED
828
        mov     [ebx + TCP_SOCKET.t_state], TCPS_ESTABLISHED
Line 836... Line 836...
836
 
836
 
837
        push    word [ebx + TCP_SOCKET.requested_s_scale]       ; Set send and receive scale factors to the received values
837
        push    word [ebx + TCP_SOCKET.requested_s_scale]       ; Set send and receive scale factors to the received values
838
        pop     word [ebx + TCP_SOCKET.SND_SCALE]
838
        pop     word [ebx + TCP_SOCKET.SND_SCALE]
Line 839... Line 839...
839
       @@:
839
       @@:
Line 840... Line 840...
840
 
840
 
841
        call    TCP_reassemble
841
        call    tcp_reassemble
842
 
842
 
Line 914... Line 914...
914
        lea     ecx, [ebx + SOCKET.mutex]
914
        lea     ecx, [ebx + SOCKET.mutex]
915
        call    mutex_unlock
915
        call    mutex_unlock
Line 916... Line 916...
916
 
916
 
917
; retransmit missing segment
917
; retransmit missing segment
918
        mov     eax, [esp]
918
        mov     eax, [esp]
Line 919... Line 919...
919
        call    TCP_output
919
        call    tcp_output
920
 
920
 
921
; Lock the socket again
921
; Lock the socket again
922
        mov     ecx, [esp]
922
        mov     ecx, [esp]
Line 953... Line 953...
953
        lea     ecx, [ebx + SOCKET.mutex]
953
        lea     ecx, [ebx + SOCKET.mutex]
954
        call    mutex_unlock
954
        call    mutex_unlock
Line 955... Line 955...
955
 
955
 
956
; retransmit missing segment
956
; retransmit missing segment
957
        mov     eax, [esp]
957
        mov     eax, [esp]
Line 958... Line 958...
958
        call    TCP_output
958
        call    tcp_output
959
 
959
 
960
; Lock the socket again
960
; Lock the socket again
961
        mov     ecx, [esp]
961
        mov     ecx, [esp]
Line 1003... Line 1003...
1003
        test    [temp_bits], TCP_BIT_TIMESTAMP
1003
        test    [temp_bits], TCP_BIT_TIMESTAMP
1004
        jz      .timestamp_not_present
1004
        jz      .timestamp_not_present
1005
        mov     eax, [timestamp]
1005
        mov     eax, [timestamp]
1006
        sub     eax, [ebx + TCP_SOCKET.ts_ecr]
1006
        sub     eax, [ebx + TCP_SOCKET.ts_ecr]
1007
        inc     eax
1007
        inc     eax
1008
        call    TCP_xmit_timer
1008
        call    tcp_xmit_timer
1009
        jmp     .rtt_done_
1009
        jmp     .rtt_done_
Line 1010... Line 1010...
1010
 
1010
 
1011
; If no timestamp but transmit timer is running and timed sequence number was acked,
1011
; If no timestamp but transmit timer is running and timed sequence number was acked,
1012
; update smoothed RTT. Since we now have an RTT measurement, cancel the timer backoff
1012
; update smoothed RTT. Since we now have an RTT measurement, cancel the timer backoff
Line 1018... Line 1018...
1018
        cmp     eax, [ebx + TCP_SOCKET.t_rtseq]
1018
        cmp     eax, [ebx + TCP_SOCKET.t_rtseq]
1019
        jbe     .rtt_done_
1019
        jbe     .rtt_done_
1020
        mov     eax, [ebx + TCP_SOCKET.t_rtt]
1020
        mov     eax, [ebx + TCP_SOCKET.t_rtt]
1021
        test    eax, eax
1021
        test    eax, eax
1022
        jz      .rtt_done_
1022
        jz      .rtt_done_
1023
        call    TCP_xmit_timer
1023
        call    tcp_xmit_timer
Line 1024... Line 1024...
1024
 
1024
 
Line 1025... Line 1025...
1025
  .rtt_done_:
1025
  .rtt_done_:
1026
 
1026
 
Line 1083... Line 1083...
1083
 
1083
 
1084
        push    ecx edx ebx
1084
        push    ecx edx ebx
1085
        mov     ecx, [ebx + STREAM_SOCKET.snd.size]
1085
        mov     ecx, [ebx + STREAM_SOCKET.snd.size]
1086
        lea     eax, [ebx + STREAM_SOCKET.snd]
1086
        lea     eax, [ebx + STREAM_SOCKET.snd]
1087
        sub     [ebx + TCP_SOCKET.SND_WND], ecx
1087
        sub     [ebx + TCP_SOCKET.SND_WND], ecx
1088
        call    SOCKET_ring_free
1088
        call    socket_ring_free
Line 1089... Line 1089...
1089
        pop     ebx edx ecx
1089
        pop     ebx edx ecx
1090
 
1090
 
1091
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: our FIN is acked\n"
1091
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: our FIN is acked\n"
Line 1095... Line 1095...
1095
  .finiacked:
1095
  .finiacked:
Line 1096... Line 1096...
1096
 
1096
 
1097
        push    ecx edx ebx
1097
        push    ecx edx ebx
1098
        mov     ecx, edi
1098
        mov     ecx, edi
1099
        lea     eax, [ebx + STREAM_SOCKET.snd]
1099
        lea     eax, [ebx + STREAM_SOCKET.snd]
1100
        call    SOCKET_ring_free
1100
        call    socket_ring_free
1101
        pop     ebx
1101
        pop     ebx
1102
        sub     [ebx + TCP_SOCKET.SND_WND], ecx
1102
        sub     [ebx + TCP_SOCKET.SND_WND], ecx
Line 1103... Line 1103...
1103
        pop     edx ecx
1103
        pop     edx ecx
Line 1107... Line 1107...
1107
;----------------------------------------
1107
;----------------------------------------
1108
; Wake up process waiting on send buffer
1108
; Wake up process waiting on send buffer
Line 1109... Line 1109...
1109
 
1109
 
1110
  .wakeup:
1110
  .wakeup:
1111
        mov     eax, ebx
1111
        mov     eax, ebx
Line 1112... Line 1112...
1112
        call    SOCKET_notify
1112
        call    socket_notify
1113
 
1113
 
1114
; Update TCPS
1114
; Update TCPS
1115
        mov     eax, [edx + TCP_header.AckNumber]
1115
        mov     eax, [edx + TCP_header.AckNumber]
Line 1145... Line 1145...
1145
        jz      .ack_processed
1145
        jz      .ack_processed
Line 1146... Line 1146...
1146
 
1146
 
1147
        test    [ebx + SOCKET.state], SS_CANTRCVMORE
1147
        test    [ebx + SOCKET.state], SS_CANTRCVMORE
1148
        jnz     @f
1148
        jnz     @f
1149
        mov     eax, ebx
1149
        mov     eax, ebx
1150
        call    SOCKET_is_disconnected
1150
        call    socket_is_disconnected
1151
        mov     [ebx + TCP_SOCKET.timer_timed_wait], TCP_time_max_idle
1151
        mov     [ebx + TCP_SOCKET.timer_timed_wait], TCP_time_max_idle
1152
        or      [ebx + TCP_SOCKET.timer_flags], timer_flag_wait
1152
        or      [ebx + TCP_SOCKET.timer_flags], timer_flag_wait
1153
       @@:
1153
       @@:
1154
        mov     [ebx + TCP_SOCKET.t_state], TCPS_FIN_WAIT_2
1154
        mov     [ebx + TCP_SOCKET.t_state], TCPS_FIN_WAIT_2
Line 1158... Line 1158...
1158
        test    [temp_bits], TCP_BIT_FIN_IS_ACKED
1158
        test    [temp_bits], TCP_BIT_FIN_IS_ACKED
1159
        jz      .ack_processed
1159
        jz      .ack_processed
Line 1160... Line 1160...
1160
 
1160
 
1161
        mov     [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT
1161
        mov     [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT
1162
        mov     eax, ebx
1162
        mov     eax, ebx
1163
        call    TCP_cancel_timers
1163
        call    tcp_cancel_timers
1164
        mov     [ebx + TCP_SOCKET.timer_timed_wait], 2 * TCP_time_MSL
1164
        mov     [ebx + TCP_SOCKET.timer_timed_wait], 2 * TCP_time_MSL
1165
        or      [ebx + TCP_SOCKET.timer_flags], timer_flag_wait
1165
        or      [ebx + TCP_SOCKET.timer_flags], timer_flag_wait
1166
        mov     eax, ebx
1166
        mov     eax, ebx
1167
        call    SOCKET_is_disconnected
1167
        call    socket_is_disconnected
Line 1168... Line 1168...
1168
        jmp     .ack_processed
1168
        jmp     .ack_processed
1169
 
1169
 
1170
  .ack_la:
1170
  .ack_la:
Line 1175... Line 1175...
1175
        lea     ecx, [ebx + SOCKET.mutex]
1175
        lea     ecx, [ebx + SOCKET.mutex]
1176
        call    mutex_unlock
1176
        call    mutex_unlock
1177
        pop     ebx
1177
        pop     ebx
Line 1178... Line 1178...
1178
 
1178
 
1179
        mov     eax, ebx
1179
        mov     eax, ebx
1180
        call    TCP_close
1180
        call    tcp_close
Line 1181... Line 1181...
1181
        jmp     .drop_no_socket
1181
        jmp     .drop_no_socket
1182
 
1182
 
1183
  .ack_tw:
1183
  .ack_tw:
Line 1222... Line 1222...
1222
        mov     eax, [TCP_sequence_num]
1222
        mov     eax, [TCP_sequence_num]
1223
        add     [TCP_sequence_num], 64000 / 2
1223
        add     [TCP_sequence_num], 64000 / 2
1224
        mov     [ebx + TCP_SOCKET.ISS], eax
1224
        mov     [ebx + TCP_SOCKET.ISS], eax
1225
        mov     [ebx + TCP_SOCKET.SND_NXT], eax
1225
        mov     [ebx + TCP_SOCKET.SND_NXT], eax
Line 1226... Line 1226...
1226
 
1226
 
1227
        TCP_sendseqinit ebx
1227
        tcp_sendseqinit ebx
Line 1228... Line 1228...
1228
        TCP_rcvseqinit ebx
1228
        tcp_rcvseqinit ebx
1229
 
1229
 
1230
        mov     [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
1230
        mov     [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
1231
        or      [ebx + TCP_SOCKET.t_flags], TF_ACKNOW
1231
        or      [ebx + TCP_SOCKET.t_flags], TF_ACKNOW
Line 1232... Line 1232...
1232
        mov     [ebx + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval  ;;;; macro
1232
        mov     [ebx + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval  ;;;; macro
1233
        or      [ebx + TCP_SOCKET.timer_flags], timer_flag_keepalive
1233
        or      [ebx + TCP_SOCKET.timer_flags], timer_flag_keepalive
1234
 
1234
 
1235
        lea     eax, [ebx + STREAM_SOCKET.snd]
1235
        lea     eax, [ebx + STREAM_SOCKET.snd]
Line 1236... Line 1236...
1236
        call    SOCKET_ring_create
1236
        call    socket_ring_create
1237
        test    eax, eax
1237
        test    eax, eax
1238
        jz      .drop
1238
        jz      .drop
1239
 
1239
 
Line 1240... Line 1240...
1240
        lea     eax, [ebx + STREAM_SOCKET.rcv]
1240
        lea     eax, [ebx + STREAM_SOCKET.rcv]
Line 1241... Line 1241...
1241
        call    SOCKET_ring_create
1241
        call    socket_ring_create
1242
        test    eax, eax
1242
        test    eax, eax
1243
        jz      .drop
1243
        jz      .drop
1244
 
1244
 
Line 1245... Line 1245...
1245
        and     [temp_bits], not TCP_BIT_DROPSOCKET
1245
        and     [temp_bits], not TCP_BIT_DROPSOCKET
Line 1246... Line 1246...
1246
 
1246
 
Line 1276... Line 1276...
1276
        test    [edx + TCP_header.Flags], TH_ACK
1276
        test    [edx + TCP_header.Flags], TH_ACK
1277
        jz      .drop
1277
        jz      .drop
Line 1278... Line 1278...
1278
 
1278
 
1279
        mov     eax, ebx
1279
        mov     eax, ebx
1280
        mov     ebx, ECONNREFUSED
1280
        mov     ebx, ECONNREFUSED
Line 1281... Line 1281...
1281
        call    TCP_drop
1281
        call    tcp_drop
1282
 
1282
 
Line 1283... Line 1283...
1283
        jmp     .drop
1283
        jmp     .drop
Line 1304... Line 1304...
1304
        and     [ebx + TCP_SOCKET.timer_flags], not timer_flag_retransmission   ; disable retransmission timer
1304
        and     [ebx + TCP_SOCKET.timer_flags], not timer_flag_retransmission   ; disable retransmission timer
Line 1305... Line 1305...
1305
 
1305
 
1306
        push    [edx + TCP_header.SequenceNumber]
1306
        push    [edx + TCP_header.SequenceNumber]
Line 1307... Line 1307...
1307
        pop     [ebx + TCP_SOCKET.IRS]
1307
        pop     [ebx + TCP_SOCKET.IRS]
Line 1308... Line 1308...
1308
 
1308
 
Line 1309... Line 1309...
1309
        TCP_rcvseqinit ebx
1309
        tcp_rcvseqinit ebx
1310
 
1310
 
Line 1322... Line 1322...
1322
;;; TODO: update stats
1322
;;; TODO: update stats
Line 1323... Line 1323...
1323
 
1323
 
1324
; set socket state to connected
1324
; set socket state to connected
1325
        push    eax
1325
        push    eax
1326
        mov     eax, ebx
1326
        mov     eax, ebx
1327
        call    SOCKET_is_connected
1327
        call    socket_is_connected
1328
        pop     eax
1328
        pop     eax
Line 1329... Line 1329...
1329
        mov     [ebx + TCP_SOCKET.t_state], TCPS_ESTABLISHED
1329
        mov     [ebx + TCP_SOCKET.t_state], TCPS_ESTABLISHED
1330
 
1330
 
Line 1341... Line 1341...
1341
;;; TODO: reassemble packets queue
1341
;;; TODO: reassemble packets queue
Line 1342... Line 1342...
1342
 
1342
 
1343
        mov     eax, [ebx + TCP_SOCKET.t_rtt]
1343
        mov     eax, [ebx + TCP_SOCKET.t_rtt]
1344
        test    eax, eax
1344
        test    eax, eax
1345
        je      .trim
1345
        je      .trim
1346
        call    TCP_xmit_timer
1346
        call    tcp_xmit_timer
Line 1347... Line 1347...
1347
        jmp     .trim
1347
        jmp     .trim
Line 1348... Line 1348...
1348
 
1348
 
Line 1483... Line 1483...
1483
 
1483
 
1484
        pusha
1484
        pusha
1485
        mov     esi, [dataoffset]
1485
        mov     esi, [dataoffset]
1486
        add     esi, edx
1486
        add     esi, edx
1487
        lea     eax, [ebx + STREAM_SOCKET.rcv]
1487
        lea     eax, [ebx + STREAM_SOCKET.rcv]
1488
        call    SOCKET_ring_write                       ; Add the data to the socket buffer
1488
        call    socket_ring_write                       ; Add the data to the socket buffer
1489
        add     [ebx + TCP_SOCKET.RCV_NXT], ecx         ; Update sequence number with number of bytes we have copied
1489
        add     [ebx + TCP_SOCKET.RCV_NXT], ecx         ; Update sequence number with number of bytes we have copied
Line 1490... Line 1490...
1490
        popa
1490
        popa
1491
 
1491
 
1492
; Wake up the sleeping process
1492
; Wake up the sleeping process
Line 1493... Line 1493...
1493
        mov     eax, ebx
1493
        mov     eax, ebx
Line 1494... Line 1494...
1494
        call    SOCKET_notify
1494
        call    socket_notify
1495
 
1495
 
1496
        jmp     .data_done
1496
        jmp     .data_done
Line 1497... Line 1497...
1497
 
1497
 
Line 1498... Line 1498...
1498
  .out_of_order:
1498
  .out_of_order:
Line 1499... Line 1499...
1499
        DEBUGF  DEBUG_NETWORK_VERBOSE,  "TCP data is out of order!\nSequencenumber is %u, we expected %u.\n", \
1499
        DEBUGF  DEBUG_NETWORK_VERBOSE,  "TCP data is out of order!\nSequencenumber is %u, we expected %u.\n", \
1500
        [edx + TCP_header.SequenceNumber], [ebx + TCP_SOCKET.RCV_NXT]
1500
        [edx + TCP_header.SequenceNumber], [ebx + TCP_SOCKET.RCV_NXT]
1501
 
1501
 
1502
; Uh-oh, some data is out of order, lets call TCP reassemble for help
1502
; Uh-oh, some data is out of order, lets call TCP reassemble for help
Line 1520... Line 1520...
1520
        jae     .not_first_fin
1520
        jae     .not_first_fin
Line 1521... Line 1521...
1521
 
1521
 
Line 1522... Line 1522...
1522
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: First FIN for this connection\n"
1522
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: First FIN for this connection\n"
1523
 
1523
 
Line 1524... Line 1524...
1524
        mov     eax, ebx
1524
        mov     eax, ebx
1525
        call    SOCKET_cant_recv_more
1525
        call    socket_cant_recv_more
Line 1526... Line 1526...
1526
 
1526
 
Line 1554... Line 1554...
1554
        jmp     .final_processing
1554
        jmp     .final_processing
Line 1555... Line 1555...
1555
 
1555
 
1556
  .fin_wait2:
1556
  .fin_wait2:
1557
        mov     [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT
1557
        mov     [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT
1558
        mov     eax, ebx
1558
        mov     eax, ebx
1559
        call    TCP_cancel_timers
1559
        call    tcp_cancel_timers
Line 1560... Line 1560...
1560
        call    SOCKET_is_disconnected
1560
        call    socket_is_disconnected
1561
 
1561
 
1562
  .fin_timed:
1562
  .fin_timed:
Line 1581... Line 1581...
1581
        jz      .done
1581
        jz      .done
1582
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: ACK now!\n"
1582
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: ACK now!\n"
Line 1583... Line 1583...
1583
 
1583
 
1584
  .need_output:
1584
  .need_output:
1585
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: need output\n"
1585
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: need output\n"
Line 1586... Line 1586...
1586
        call    TCP_output
1586
        call    tcp_output
1587
 
1587
 
Line 1588... Line 1588...
1588
  .done:
1588
  .done:
1589
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: dumping\n"
1589
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: dumping\n"
Line 1590... Line 1590...
1590
 
1590
 
1591
        call    NET_BUFF_free
1591
        call    net_buff_free
Line 1619... Line 1619...
1619
        pop     edx ebx
1619
        pop     edx ebx
Line 1620... Line 1620...
1620
 
1620
 
1621
        test    [edx + TCP_header.Flags], TH_RST
1621
        test    [edx + TCP_header.Flags], TH_RST
Line 1622... Line 1622...
1622
        jnz     .done
1622
        jnz     .done
Line 1623... Line 1623...
1623
 
1623
 
1624
        ;;; if its a multicast/broadcast, also drop
1624
; TODO: if its a multicast/broadcast, also drop
Line 1625... Line 1625...
1625
 
1625
 
Line 1634... Line 1634...
1634
; Respond
1634
; Respond
Line 1635... Line 1635...
1635
 
1635
 
1636
  .respond_ack:
1636
  .respond_ack:
1637
        push    ebx
1637
        push    ebx
1638
        mov     cl, TH_RST
1638
        mov     cl, TH_RST
1639
        call    TCP_respond
1639
        call    tcp_respond
1640
        pop     ebx
1640
        pop     ebx
Line 1641... Line 1641...
1641
        jmp     .destroy_new_socket
1641
        jmp     .destroy_new_socket
1642
 
1642
 
1643
  .respond_syn:
1643
  .respond_syn:
1644
        push    ebx
1644
        push    ebx
1645
        mov     cl, TH_RST + TH_ACK
1645
        mov     cl, TH_RST + TH_ACK
1646
        call    TCP_respond
1646
        call    tcp_respond
Line 1647... Line 1647...
1647
        pop     ebx
1647
        pop     ebx
1648
        jmp     .destroy_new_socket
1648
        jmp     .destroy_new_socket
Line 1658... Line 1658...
1658
 
1658
 
1659
  .respond_seg_reset:
1659
  .respond_seg_reset:
1660
        test    [edx + TCP_header.Flags], TH_RST
1660
        test    [edx + TCP_header.Flags], TH_RST
Line 1661... Line 1661...
1661
        jnz     .drop_no_socket
1661
        jnz     .drop_no_socket
Line 1662... Line 1662...
1662
 
1662
 
1663
        ;;; TODO: if its a multicast/broadcast, also drop
1663
; TODO: if its a multicast/broadcast, also drop
Line 1664... Line 1664...
1664
 
1664
 
Line 1671... Line 1671...
1671
        jmp     .drop_no_socket
1671
        jmp     .drop_no_socket
Line 1672... Line 1672...
1672
 
1672
 
1673
  .respond_seg_ack:
1673
  .respond_seg_ack:
1674
        mov     cl, TH_RST
1674
        mov     cl, TH_RST
1675
        xor     ebx, ebx                ; FIXME: find a way to get the receiving device ptr
1675
        xor     ebx, ebx                ; FIXME: find a way to get the receiving device ptr
1676
        call    TCP_respond_segment
1676
        call    tcp_respond_segment
Line 1677... Line 1677...
1677
        jmp     .drop_no_socket
1677
        jmp     .drop_no_socket
1678
 
1678
 
1679
  .respond_seg_syn:
1679
  .respond_seg_syn:
1680
        mov     cl, TH_RST + TH_ACK
1680
        mov     cl, TH_RST + TH_ACK
1681
        xor     ebx, ebx                ; FIXME: find a way to get the receiving device ptr
1681
        xor     ebx, ebx                ; FIXME: find a way to get the receiving device ptr
Line 1682... Line 1682...
1682
        call    TCP_respond_segment
1682
        call    tcp_respond_segment
1683
        jmp     .drop_no_socket
1683
        jmp     .drop_no_socket
Line 1699... Line 1699...
1699
  .destroy_new_socket:
1699
  .destroy_new_socket:
1700
        test    [temp_bits], TCP_BIT_DROPSOCKET
1700
        test    [temp_bits], TCP_BIT_DROPSOCKET
1701
        jz      .drop_no_socket
1701
        jz      .drop_no_socket
Line 1702... Line 1702...
1702
 
1702
 
1703
        mov     eax, ebx
1703
        mov     eax, ebx
Line 1704... Line 1704...
1704
        call    SOCKET_free
1704
        call    socket_free
1705
 
1705
 
Line 1706... Line 1706...
1706
;------------------
1706
;------------------
1707
; Drop the segment
1707
; Drop the segment
Line 1708... Line 1708...
1708
 
1708
 
1709
  .drop_no_socket:
1709
  .drop_no_socket:
Line 1710... Line 1710...
1710
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Drop (no socket)\n"
1710
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Drop (no socket)\n"