Subversion Repositories Kolibri OS

Rev

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

Rev 3270 Rev 3275
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: 3270 $
17
$Revision: 3275 $
18
 
18
 
19
;-----------------------------------------------------------------
19
;-----------------------------------------------------------------
20
;
20
;
Line 52... Line 52...
52
        ret
52
        ret
Line 53... Line 53...
53
 
53
 
54
  .fail:
54
  .fail:
Line -... Line 55...
-
 
55
        DEBUGF  2, "TCP incoming queue is full, discarding packet!\n"
-
 
56
 
55
        DEBUGF  2, "TCP incoming queue is full, discarding packet!\n"
57
        inc     [TCP_segments_missed]   ; FIXME: use correct interface
56
 
58
 
57
        add     esp, sizeof.TCP_queue_entry - 8
59
        add     esp, sizeof.TCP_queue_entry - 8
58
        call    kernel_free
60
        call    kernel_free
59
        add     esp, 4
61
        add     esp, 4
Line 138... Line 140...
138
        mov     si, [edx + TCP_header.DestinationPort]
140
        mov     si, [edx + TCP_header.DestinationPort]
Line 139... Line 141...
139
 
141
 
140
  .socket_loop:
142
  .socket_loop:
141
        mov     ebx, [ebx + SOCKET.NextPtr]
143
        mov     ebx, [ebx + SOCKET.NextPtr]
142
        or      ebx, ebx
144
        or      ebx, ebx
Line 143... Line 145...
143
        jz      .drop_with_reset_no_socket
145
        jz      .respond_seg_reset
144
 
146
 
Line 145... Line 147...
145
        cmp     [ebx + SOCKET.Domain], AF_INET4
147
        cmp     [ebx + SOCKET.Domain], AF_INET4
Line 243... Line 245...
243
        mov     [ebx + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle
245
        mov     [ebx + TCP_SOCKET.timer_keepalive], TCP_time_keep_idle
Line 244... Line 246...
244
 
246
 
245
;--------------------
247
;--------------------
Line 246... Line 248...
246
; Process TCP options
248
; Process TCP options
Line 247... Line 249...
247
 
249
 
248
        push    ecx     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
250
        push    ecx
249
 
251
 
Line 374... Line 376...
374
  .no_paws:
376
  .no_paws:
375
        jmp     .opt_loop
377
        jmp     .opt_loop
Line 376... Line 378...
376
 
378
 
Line 377... Line 379...
377
  .no_options:
379
  .no_options:
Line 378... Line 380...
378
 
380
 
379
        pop     ecx;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
381
        pop     ecx
Line 380... Line 382...
380
 
382
 
Line 476... Line 478...
476
        mov     [ebx + TCP_SOCKET.SND_UNA], eax
478
        mov     [ebx + TCP_SOCKET.SND_UNA], eax
Line 477... Line 479...
477
 
479
 
478
; Stop retransmit timer
480
; Stop retransmit timer
Line 479... Line 481...
479
        mov     [ebx + TCP_SOCKET.timer_retransmission], 0
481
        mov     [ebx + TCP_SOCKET.timer_retransmission], 0
480
 
482
 
481
; Awaken waiting processes
483
; Unlock the socket
482
        pusha
484
        pusha
483
        lea     ecx, [ebx + SOCKET.mutex]
485
        lea     ecx, [ebx + SOCKET.mutex]
Line -... Line 486...
-
 
486
        call    mutex_unlock
484
        call    mutex_unlock
487
        popa
485
        popa
488
 
Line 486... Line 489...
486
 
489
; Awaken waiting processes
487
        mov     eax, ebx
490
        mov     eax, ebx
Line 525... Line 528...
525
 
528
 
Line 526... Line 529...
526
        or      [ebx + TCP_SOCKET.t_flags], TF_DELACK   ; Set delayed ack flag
529
        or      [ebx + TCP_SOCKET.t_flags], TF_DELACK   ; Set delayed ack flag
Line 527... Line -...
527
 
-
 
528
        jmp     .drop
-
 
529
 
-
 
530
 
-
 
531
 
-
 
532
 
530
 
533
 
531
        jmp     .drop
Line 534... Line 532...
534
 
532
 
Line 552... Line 550...
552
       @@:
550
       @@:
553
        DEBUGF  1,"Receive window size=%d\n", eax
551
        DEBUGF  1,"Receive window size=%d\n", eax
554
        mov     [ebx + TCP_SOCKET.RCV_WND], eax
552
        mov     [ebx + TCP_SOCKET.RCV_WND], eax
555
        pop     edx
553
        pop     edx
Line 556... Line 554...
556
 
554
 
Line 557... Line 555...
557
; If listen or Syn sent, go to that specific code right away
555
; If we are in listen or syn_sent state, go to that specific code right away
558
 
556
 
Line 559... Line 557...
559
        cmp     [ebx + TCP_SOCKET.t_state], TCPS_LISTEN
557
        cmp     [ebx + TCP_SOCKET.t_state], TCPS_LISTEN
560
        je      .LISTEN
558
        je      .LISTEN
Line 561... Line -...
561
 
-
 
562
        cmp     [ebx + TCP_SOCKET.t_state], TCPS_SYN_SENT
-
 
563
        je      .SYN_SENT
559
 
564
 
560
        cmp     [ebx + TCP_SOCKET.t_state], TCPS_SYN_SENT
Line 565... Line 561...
565
        DEBUGF  1,"TCP_input: state is not listen or syn_sent\n"
561
        je      .SYN_SENT
Line 637... Line 633...
637
        jz      .not_terminated
633
        jz      .not_terminated
Line 638... Line 634...
638
 
634
 
639
        mov     eax, ebx
635
        mov     eax, ebx
640
        call    TCP_close
636
        call    TCP_close
641
;;;TODO: update stats
637
;;;TODO: update stats
Line 642... Line 638...
642
        jmp     .drop_with_reset_no_socket
638
        jmp     .respond_seg_reset
643
 
639
 
Line 644... Line 640...
644
;----------------------------------------
640
;----------------------------------------
Line 895... Line 891...
895
        mov     eax, [edx + TCP_header.AckNumber]
891
        mov     eax, [edx + TCP_header.AckNumber]
896
        mov     [ebx + TCP_SOCKET.SND_NXT], eax
892
        mov     [ebx + TCP_SOCKET.SND_NXT], eax
897
        mov     eax, [ebx + TCP_SOCKET.t_maxseg]
893
        mov     eax, [ebx + TCP_SOCKET.t_maxseg]
898
        mov     [ebx + TCP_SOCKET.SND_CWND], eax
894
        mov     [ebx + TCP_SOCKET.SND_CWND], eax
Line -... Line 895...
-
 
895
 
899
 
896
; Unlock the socket
900
        mov     eax, ebx
897
        push    ebx
-
 
898
        lea     ecx, [ebx + SOCKET.mutex]
Line -... Line 899...
-
 
899
        call    mutex_unlock
-
 
900
 
-
 
901
; retransmit missing segment
-
 
902
        mov     eax, [esp]
-
 
903
        call    TCP_output
-
 
904
 
-
 
905
; Lock the socket again
-
 
906
        mov     ecx, [esp]
901
        call    TCP_output                                      ; retransmit missing segment
907
        add     ecx, SOCKET.mutex
-
 
908
        call    mutex_lock
-
 
909
        pop     ebx 
902
 
910
 
903
        push    edx
911
; Continue processing
904
        xor     edx, edx
912
        xor     edx, edx
905
        mov     eax, [ebx + TCP_SOCKET.t_maxseg]
-
 
906
        mul     [ebx + TCP_SOCKET.t_dupacks]
913
        mov     eax, [ebx + TCP_SOCKET.t_maxseg]
907
        pop     edx
914
        mul     [ebx + TCP_SOCKET.t_dupacks]
Line 908... Line 915...
908
        add     eax, [ebx + TCP_SOCKET.SND_SSTHRESH]
915
        add     eax, [ebx + TCP_SOCKET.SND_SSTHRESH]
909
        mov     [ebx + TCP_SOCKET.SND_CWND], eax
916
        mov     [ebx + TCP_SOCKET.SND_CWND], eax
Line 923... Line 930...
923
        DEBUGF  1,"TCP_input: Increasing congestion window\n"
930
        DEBUGF  1,"TCP_input: Increasing congestion window\n"
Line 924... Line 931...
924
 
931
 
925
        mov     eax, [ebx + TCP_SOCKET.t_maxseg]
932
        mov     eax, [ebx + TCP_SOCKET.t_maxseg]
Line -... Line 933...
-
 
933
        add     [ebx + TCP_SOCKET.SND_CWND], eax
-
 
934
 
-
 
935
; Unlock the socket
-
 
936
        push    ebx
-
 
937
        lea     ecx, [ebx + SOCKET.mutex]
-
 
938
        call    mutex_unlock
926
        add     [ebx + TCP_SOCKET.SND_CWND], eax
939
 
927
 
940
; retransmit missing segment
Line -... Line 941...
-
 
941
        mov     eax, [esp]
-
 
942
        call    TCP_output
-
 
943
 
-
 
944
; Lock the socket again
-
 
945
        mov     ecx, [esp]
-
 
946
        add     ecx, SOCKET.mutex
928
        mov     eax, ebx
947
        call    mutex_lock
Line 929... Line 948...
929
        call    TCP_output
948
        pop     ebx
Line 1075... Line 1094...
1075
;----------------------------------------
1094
;----------------------------------------
1076
; Wake up process waiting on send buffer
1095
; Wake up process waiting on send buffer
Line 1077... Line 1096...
1077
 
1096
 
Line 1078... Line 1097...
1078
  .wakeup:
1097
  .wakeup:
1079
 
1098
 
1080
        pushf                   ; Why?
1099
        pushf                   ; Keep the flags (Carry flag)
Line 1081... Line 1100...
1081
        mov     eax, ebx
1100
        mov     eax, ebx
Line 1092... Line 1111...
1092
 
1111
 
Line 1093... Line 1112...
1093
        popf
1112
        popf
1094
 
1113
 
-
 
1114
; General ACK handling complete
Line 1095... Line 1115...
1095
; General ACK handling complete
1115
; Now do the state-specific ones
1096
; Now do the state-specific ones
1116
; Carry flag is set when our FIN is acked
Line 1097... Line 1117...
1097
 
1117
 
Line 1148... Line 1168...
1148
 
1168
 
1149
  .reset_dupacks:               ; We got a new ACK, reset duplicate ACK counter
1169
  .reset_dupacks:               ; We got a new ACK, reset duplicate ACK counter
1150
        mov     [ebx + TCP_SOCKET.t_dupacks], 0
1170
        mov     [ebx + TCP_SOCKET.t_dupacks], 0
Line -... Line 1171...
-
 
1171
        jmp     .ack_processed
-
 
1172
 
Line 1151... Line -...
1151
        jmp     .ack_processed
-
 
1152
 
-
 
1153
 
-
 
1154
 
1173
;-------
1155
 
1174
; LISTEN
Line 1156... Line 1175...
1156
 
1175
 
Line 1157... Line 1176...
1157
 
1176
align 4
Line 1201... Line 1220...
1201
 
1220
 
Line 1202... Line 1221...
1202
;;;        call    SOCKET_notify_owner
1221
;;;        call    SOCKET_notify_owner
Line 1203... Line -...
1203
 
-
 
1204
        jmp     .trim_then_step6
-
 
1205
                                   
-
 
1206
 
-
 
1207
 
-
 
1208
 
-
 
1209
 
-
 
1210
 
-
 
1211
 
-
 
1212
 
1222
 
1213
 
1223
        jmp     .trim_then_step6
Line 1214... Line 1224...
1214
 
1224
 
1215
;------------
1225
;------------
Line 1322... Line 1332...
1322
        mov     eax, [edx + TCP_header.SequenceNumber]
1332
        mov     eax, [edx + TCP_header.SequenceNumber]
1323
        mov     [ebx + TCP_SOCKET.RCV_UP], eax
1333
        mov     [ebx + TCP_SOCKET.RCV_UP], eax
1324
        dec     eax
1334
        dec     eax
1325
        mov     [ebx + TCP_SOCKET.SND_WL1], eax
1335
        mov     [ebx + TCP_SOCKET.SND_WL1], eax
Line -... Line 1336...
-
 
1336
 
-
 
1337
;-------
Line 1326... Line -...
1326
 
-
 
1327
 
1338
; step 6
Line 1328... Line 1339...
1328
 
1339
 
Line 1329... Line 1340...
1329
  .ack_processed:       ; (step 6)
1340
  .ack_processed:
1330
 
1341
 
Line 1494... Line 1505...
1494
        jnz     .dumpit
1505
        jnz     .dumpit
Line 1495... Line 1506...
1495
 
1506
 
1496
        or      [eax + TCP_SOCKET.t_flags], TF_ACKNOW
1507
        or      [eax + TCP_SOCKET.t_flags], TF_ACKNOW
Line 1497... Line -...
1497
        jmp     .need_output
-
 
1498
 
-
 
1499
 
1508
        jmp     .need_output
1500
 
1509
 
Line 1501... Line 1510...
1501
  .drop_with_reset:
1510
  .drop_with_reset:
1502
        DEBUGF  1,"TCP_input: Drop with reset\n"
1511
        DEBUGF  1,"TCP_input: Drop with reset\n"
Line 1536... Line 1545...
1536
        jz      .dumpit
1545
        jz      .dumpit
1537
        DEBUGF  1,"TCP_input: ACK now!\n"
1546
        DEBUGF  1,"TCP_input: ACK now!\n"
Line 1538... Line 1547...
1538
 
1547
 
1539
  .need_output:
1548
  .need_output:
1540
        DEBUGF  1,"TCP_input: need output\n"
-
 
1541
 
1549
        DEBUGF  1,"TCP_input: need output\n"
Line 1542... Line 1550...
1542
        call    TCP_output
1550
        call    TCP_output
1543
 
1551
 
Line 1544... Line 1552...
1544
  .dumpit:
1552
  .dumpit:
1545
        DEBUGF  1,"TCP_input: dumping\n"
1553
        DEBUGF  1,"TCP_input: dumping\n"
1546
 
-
 
1547
        call    kernel_free
1554
 
Line -... Line 1555...
-
 
1555
        call    kernel_free
-
 
1556
        add     esp, 4
Line 1548... Line 1557...
1548
        add     esp, 4
1557
        ret
1549
 
1558
 
1550
        ret
1559
;---------
1551
 
1560
; Respond
1552
 
1561
 
1553
  .respond_ack:
1562
  .respond_ack:
Line 1554... Line -...
1554
        push    ebx
-
 
1555
        mov     cl, TH_RST
1563
        push    ebx
1556
        call    TCP_respond
1564
        mov     cl, TH_RST
1557
        pop     ebx
1565
        call    TCP_respond
1558
        jmp     .destroy_new_socket
1566
        pop     ebx
1559
 
1567
        jmp     .destroy_new_socket
1560
 
1568
 
Line -... Line 1569...
-
 
1569
  .respond_syn:
-
 
1570
        push    ebx
-
 
1571
        mov     cl, TH_RST + TH_ACK
Line -... Line 1572...
-
 
1572
        call    TCP_respond
-
 
1573
        pop     ebx
-
 
1574
        jmp     .destroy_new_socket
-
 
1575
 
-
 
1576
  .respond_seg_reset:
-
 
1577
        test    [edx + TCP_header.Flags], TH_RST
-
 
1578
        jnz     .drop_no_socket
-
 
1579
 
-
 
1580
        ;;; TODO: if its a multicast/broadcast, also drop
-
 
1581
 
-
 
1582
        test    [edx + TCP_header.Flags], TH_ACK
-
 
1583
        jnz     .respond_seg_ack
-
 
1584
 
-
 
1585
        test    [edx + TCP_header.Flags], TH_SYN
-
 
1586
        jnz     .respond_seg_syn
-
 
1587
 
-
 
1588
        jmp     .drop_no_socket
-
 
1589
 
-
 
1590
  .respond_seg_ack:
Line 1561... Line 1591...
1561
  .respond_syn:
1591
        mov     cl, TH_RST
1562
        push    ebx
1592
        call    TCP_respond_segment
Line 1563... Line 1593...
1563
        mov     cl, TH_RST + TH_ACK
1593
        jmp     .drop_no_socket
1564
        call    TCP_respond
-
 
1565
        pop     ebx
1594
 
Line 1566... Line 1595...
1566
        jmp     .destroy_new_socket
1595
  .respond_seg_syn:
1567
 
1596
        mov     cl, TH_RST + TH_ACK
1568
 
1597
        call    TCP_respond_segment
1569
 
1598
        jmp     .drop_no_socket
Line 1570... Line 1599...
1570
;-----
1599
 
1571
; Drop
-
 
1572
 
1600
;-----
1573
  .drop:
1601
; Drop
Line 1574... Line 1602...
1574
 
1602
 
1575
        DEBUGF  1,"TCP_input: Dropping packet\n"
1603
  .drop:
Line 1590... Line 1618...
1590
  .drop_no_socket:
1618
  .drop_no_socket:
1591
        DEBUGF  1,"TCP_input: Drop (no socket)\n"
1619
        DEBUGF  1,"TCP_input: Drop (no socket)\n"
Line 1592... Line 1620...
1592
 
1620
 
1593
        call    kernel_free
1621
        call    kernel_free
1594
        add     esp, 4
-
 
1595
 
1622
        add     esp, 4
1596
        ret
-
 
1597
 
-
 
1598
  .drop_with_reset_no_socket:
-
 
1599
        DEBUGF  1,"TCP_input: Drop with reset (no socket)\n"
-
 
1600
 
-
 
1601
        test    [edx + TCP_header.Flags], TH_RST
-
 
1602
        jnz     .drop_no_socket
-
 
1603
 
-
 
1604
        ;;; TODO: if its a multicast/broadcast, also drop
-
 
1605
 
-
 
1606
        test    [edx + TCP_header.Flags], TH_ACK
-
 
1607
        jnz     .respond_seg_ack
-
 
1608
 
-
 
1609
        test    [edx + TCP_header.Flags], TH_SYN
-
 
1610
        jnz     .respond_seg_syn
-
 
1611
 
-
 
1612
        jmp     .drop_no_socket
-
 
1613
 
-
 
1614
  .respond_seg_ack:
-
 
1615
 
-
 
1616
        mov     cl, TH_RST
-
 
1617
        call    TCP_respond_segment
-
 
1618
        jmp     .drop_no_socket
-
 
1619
 
-
 
1620
  .respond_seg_syn:
-
 
1621
 
-
 
1622
        mov     cl, TH_RST + TH_ACK
-
 
1623
        call    TCP_respond_segment
-
 
1624
        jmp     .drop_no_socket
1623
        ret