Subversion Repositories Kolibri OS

Rev

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

Rev 5000 Rev 5133
Line 1... Line 1...
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
2
;;                                                                 ;;
3
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved.    ;;
3
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved.    ;;
4
;; Distributed under terms of the GNU General Public License       ;;
4
;; Distributed under terms of the GNU General Public License       ;;
5
;;                                                                 ;;
5
;;                                                                 ;;
6
;;  Part of the TCP/IP network stack for KolibriOS                 ;;
6
;;  Part of the TCP/IP network stack for KolibriOS                 ;;
7
;;                                                                 ;;
7
;;                                                                 ;;
8
;;   Written by hidnplayr@kolibrios.org                            ;;
8
;;   Written by hidnplayr@kolibrios.org                            ;;
9
;;                                                                 ;;
9
;;                                                                 ;;
10
;;    Based on the code of 4.4BSD                                  ;;
10
;;    Based on the algorithms used in 4.4BSD                       ;;
11
;;                                                                 ;;
11
;;                                                                 ;;
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: 5000 $
17
$Revision: 5133 $
18
 
18
 
19
;-----------------------------------------------------------------
19
;-----------------------------------------------------------------
20
;
20
;
Line 529... Line 529...
529
; - The acknowledgment field equals the largest unacknowledged sequence number. This means no data is acknowledged by this segment.
529
; - The acknowledgment field equals the largest unacknowledged sequence number. This means no data is acknowledged by this segment.
530
        mov     eax, [edx + TCP_header.AckNumber]
530
        mov     eax, [edx + TCP_header.AckNumber]
531
        cmp     eax, [ebx + TCP_SOCKET.SND_UNA]
531
        cmp     eax, [ebx + TCP_SOCKET.SND_UNA]
532
        jne     .not_uni_xfer
532
        jne     .not_uni_xfer
Line 533... Line 533...
533
 
533
 
534
; - The reassembly list of out-of-order segments for the connection is empty (seg_next equals tp).
-
 
535
 
534
; - The reassembly list of out-of-order segments for the connection is empty.
536
;;; TODO
-
 
537
 
535
        cmp     [ebx + TCP_SOCKET.seg_next], 0
Line 538... Line 536...
538
;       jnz     .not_uni_xfer
536
        jne     .not_uni_xfer
Line 539... Line 537...
539
 
537
 
Line 838... Line 836...
838
 
836
 
839
        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
840
        pop     word [ebx + TCP_SOCKET.SND_SCALE]
838
        pop     word [ebx + TCP_SOCKET.SND_SCALE]
Line 841... Line 839...
841
       @@:
839
       @@:
Line 842... Line 840...
842
 
840
 
843
;;; TODO: call TCP_reassemble
841
        call    TCP_reassemble
844
 
842
 
Line 1092... Line 1090...
1092
        sub     [ebx + TCP_SOCKET.SND_WND], ecx
1090
        sub     [ebx + TCP_SOCKET.SND_WND], ecx
1093
        call    SOCKET_ring_free
1091
        call    SOCKET_ring_free
1094
        pop     ebx edx ecx
1092
        pop     ebx edx ecx
Line 1095... Line 1093...
1095
 
1093
 
1096
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: our FIN is acked\n"
1094
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: our FIN is acked\n"
1097
        stc
-
 
1098
 
1095
        or      [temp_bits], TCP_BIT_FIN_IS_ACKED
Line 1099... Line 1096...
1099
        jmp     .wakeup
1096
        jmp     .wakeup
Line 1100... Line 1097...
1100
 
1097
 
Line 1107... Line 1104...
1107
        pop     ebx
1104
        pop     ebx
1108
        sub     [ebx + TCP_SOCKET.SND_WND], ecx
1105
        sub     [ebx + TCP_SOCKET.SND_WND], ecx
1109
        pop     edx ecx
1106
        pop     edx ecx
Line 1110... Line 1107...
1110
 
1107
 
1111
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: our FIN is not acked\n"
-
 
Line 1112... Line 1108...
1112
        clc
1108
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: our FIN is not acked\n"
1113
 
1109
 
Line 1114... Line 1110...
1114
;----------------------------------------
1110
;----------------------------------------
1115
; Wake up process waiting on send buffer
-
 
1116
 
-
 
1117
  .wakeup:
1111
; Wake up process waiting on send buffer
1118
 
1112
 
Line 1119... Line 1113...
1119
        pushf                   ; Keep the flags (Carry flag)
1113
  .wakeup:
1120
        mov     eax, ebx
-
 
1121
        call    SOCKET_notify
1114
        mov     eax, ebx
1122
 
1115
        call    SOCKET_notify
1123
; Update TCPS
1116
 
1124
 
1117
; Update TCPS
1125
        mov     eax, [edx + TCP_header.AckNumber]
1118
        mov     eax, [edx + TCP_header.AckNumber]
1126
        mov     [ebx + TCP_SOCKET.SND_UNA], eax
1119
        mov     [ebx + TCP_SOCKET.SND_UNA], eax
Line 1127... Line -...
1127
        cmp     eax, [ebx + TCP_SOCKET.SND_NXT]
-
 
1128
        jb      @f
-
 
1129
        mov     [ebx + TCP_SOCKET.SND_NXT], eax
1120
        cmp     eax, [ebx + TCP_SOCKET.SND_NXT]
1130
       @@:
1121
        jb      @f
1131
 
1122
        mov     [ebx + TCP_SOCKET.SND_NXT], eax
Line 1132... Line 1123...
1132
        popf
1123
       @@:
Line 1151... Line 1142...
1151
        dd      .ack_processed  ; TCPS_FIN_WAIT_2
1142
        dd      .ack_processed  ; TCPS_FIN_WAIT_2
1152
        dd      .ack_tw         ; TCPS_TIMED_WAIT
1143
        dd      .ack_tw         ; TCPS_TIMED_WAIT
Line 1153... Line 1144...
1153
 
1144
 
-
 
1145
 
1154
 
1146
  .ack_fw1:
Line 1155... Line 1147...
1155
  .ack_fw1:
1147
        test    [temp_bits], TCP_BIT_FIN_IS_ACKED
1156
        jnc     .ack_processed
1148
        jz      .ack_processed
1157
 
1149
 
1158
        test    [ebx + SOCKET.state], SS_CANTRCVMORE
1150
        test    [ebx + SOCKET.state], SS_CANTRCVMORE
Line 1164... Line 1156...
1164
       @@:
1156
       @@:
1165
        mov     [ebx + TCP_SOCKET.t_state], TCPS_FIN_WAIT_2
1157
        mov     [ebx + TCP_SOCKET.t_state], TCPS_FIN_WAIT_2
1166
        jmp     .ack_processed
1158
        jmp     .ack_processed
Line 1167... Line 1159...
1167
 
1159
 
-
 
1160
  .ack_c:
1168
  .ack_c:
1161
        test    [temp_bits], TCP_BIT_FIN_IS_ACKED
Line 1169... Line 1162...
1169
        jnc     .ack_processed
1162
        jz      .ack_processed
1170
 
1163
 
1171
        mov     [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT
1164
        mov     [ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT
1172
        mov     eax, ebx
1165
        mov     eax, ebx
Line 1176... Line 1169...
1176
        mov     eax, ebx
1169
        mov     eax, ebx
1177
        call    SOCKET_is_disconnected
1170
        call    SOCKET_is_disconnected
1178
        jmp     .ack_processed
1171
        jmp     .ack_processed
Line 1179... Line 1172...
1179
 
1172
 
-
 
1173
  .ack_la:
1180
  .ack_la:
1174
        test    [temp_bits], TCP_BIT_FIN_IS_ACKED
Line 1181... Line 1175...
1181
        jnc     .ack_processed
1175
        jz      .ack_processed
1182
 
1176
 
1183
        push    ebx
1177
        push    ebx
1184
        lea     ecx, [ebx + SOCKET.mutex]
1178
        lea     ecx, [ebx + SOCKET.mutex]
Line 1250... Line 1244...
1250
        pusha
1244
        pusha
1251
        mov     eax, ebx
1245
        mov     eax, ebx
1252
        call    SOCKET_notify
1246
        call    SOCKET_notify
1253
        popa
1247
        popa
Line 1254... Line 1248...
1254
 
1248
 
Line 1255... Line 1249...
1255
        jmp     .trim_then_step6
1249
        jmp     .trim
1256
 
1250
 
Line 1257... Line 1251...
1257
;------------
1251
;------------
Line 1343... Line 1337...
1343
 
1337
 
Line 1344... Line 1338...
1344
;;; TODO: reassemble packets queue
1338
;;; TODO: reassemble packets queue
1345
 
1339
 
1346
        mov     eax, [ebx + TCP_SOCKET.t_rtt]
1340
        mov     eax, [ebx + TCP_SOCKET.t_rtt]
1347
        test    eax, eax
1341
        test    eax, eax
1348
        je      .trim_then_step6
1342
        je      .trim
Line 1349... Line 1343...
1349
        call    TCP_xmit_timer
1343
        call    TCP_xmit_timer
Line 1350... Line 1344...
1350
        jmp     .trim_then_step6
1344
        jmp     .trim
1351
 
1345
 
1352
  .simultaneous_open:
1346
  .simultaneous_open:
Line 1353... Line 1347...
1353
 
1347
 
1354
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: simultaneous open\n"
1348
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: simultaneous open\n"
Line 1355... Line 1349...
1355
; We have received a syn but no ACK, so we are having a simultaneous open..
1349
; We have received a syn but no ACK, so we are having a simultaneous open..
1356
        mov     [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
-
 
1357
 
1350
        mov     [ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
Line 1358... Line 1351...
1358
;-------------------------------------
1351
 
1359
; Common processing for receipt of SYN
1352
;-------------------------------------
1360
 
1353
; Common processing for receipt of SYN
Line 1370... Line 1363...
1370
        mov     ecx, [ebx + TCP_SOCKET.RCV_WND]
1363
        mov     ecx, [ebx + TCP_SOCKET.RCV_WND]
1371
        and     [edx + TCP_header.Flags], not (TH_FIN)
1364
        and     [edx + TCP_header.Flags], not (TH_FIN)
1372
;;; TODO: update stats
1365
;;; TODO: update stats
Line 1373... Line 1366...
1373
 
1366
 
1374
  .dont_trim:
-
 
1375
 
1367
  .dont_trim:
1376
        mov     eax, [edx + TCP_header.SequenceNumber]
1368
        mov     eax, [edx + TCP_header.SequenceNumber]
1377
        mov     [ebx + TCP_SOCKET.RCV_UP], eax
1369
        mov     [ebx + TCP_SOCKET.RCV_UP], eax
1378
        dec     eax
1370
        dec     eax
Line 1379... Line -...
1379
        mov     [ebx + TCP_SOCKET.SND_WL1], eax
-
 
1380
 
-
 
1381
;-------
-
 
1382
; step 6
1371
        mov     [ebx + TCP_SOCKET.SND_WL1], eax
1383
 
-
 
1384
  .ack_processed:
1372
 
Line 1385... Line 1373...
1385
 
1373
  .ack_processed:
1386
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: ACK processed\n"
1374
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: ACK processed\n"
Line 1585... Line 1573...
1585
 
1573
 
1586
        test    [temp_bits], TCP_BIT_NEEDOUTPUT
1574
        test    [temp_bits], TCP_BIT_NEEDOUTPUT
Line 1587... Line 1575...
1587
        jnz     .need_output
1575
        jnz     .need_output
1588
 
1576
 
1589
        test    [eax + TCP_SOCKET.t_flags], TF_ACKNOW
1577
        test    [eax + TCP_SOCKET.t_flags], TF_ACKNOW
Line 1590... Line 1578...
1590
        jz      .dumpit
1578
        jz      .done
1591
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: ACK now!\n"
1579
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: ACK now!\n"
1592
 
1580
 
Line 1593... Line 1581...
1593
  .need_output:
1581
  .need_output:
1594
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: need output\n"
1582
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: need output\n"
Line 1595... Line 1583...
1595
        call    TCP_output
1583
        call    TCP_output
1596
 
1584
 
Line 1612... Line 1600...
1612
        lea     ecx, [ebx + SOCKET.mutex]
1600
        lea     ecx, [ebx + SOCKET.mutex]
1613
        call    mutex_unlock
1601
        call    mutex_unlock
1614
        pop     eax edx
1602
        pop     eax edx
Line 1615... Line 1603...
1615
 
1603
 
1616
        test    [edx + TCP_header.Flags], TH_RST
1604
        test    [edx + TCP_header.Flags], TH_RST
Line 1617... Line 1605...
1617
        jnz     .dumpit
1605
        jnz     .done
1618
 
1606
 
Line 1619... Line 1607...
1619
        or      [eax + TCP_SOCKET.t_flags], TF_ACKNOW
1607
        or      [eax + TCP_SOCKET.t_flags], TF_ACKNOW
Line 1626... Line 1614...
1626
        lea     ecx, [ebx + SOCKET.mutex]
1614
        lea     ecx, [ebx + SOCKET.mutex]
1627
        call    mutex_unlock
1615
        call    mutex_unlock
1628
        pop     edx ebx
1616
        pop     edx ebx
Line 1629... Line 1617...
1629
 
1617
 
1630
        test    [edx + TCP_header.Flags], TH_RST
1618
        test    [edx + TCP_header.Flags], TH_RST
Line 1631... Line 1619...
1631
        jnz     .dumpit
1619
        jnz     .done
Line 1632... Line 1620...
1632
 
1620
 
1633
        ;;; if its a multicast/broadcast, also drop
1621
        ;;; if its a multicast/broadcast, also drop
Line 1634... Line 1622...
1634
 
1622
 
1635
        test    [edx + TCP_header.Flags], TH_ACK
1623
        test    [edx + TCP_header.Flags], TH_ACK
1636
        jnz     .respond_ack
1624
        jnz     .respond_ack
Line 1637... Line 1625...
1637
 
1625
 
1638
        test    [edx + TCP_header.Flags], TH_SYN
1626
        test    [edx + TCP_header.Flags], TH_SYN
Line 1639... Line 1627...
1639
        jnz     .respond_syn
1627
        jnz     .respond_syn
Line 1654... Line 1642...
1654
        mov     cl, TH_RST + TH_ACK
1642
        mov     cl, TH_RST + TH_ACK
1655
        call    TCP_respond
1643
        call    TCP_respond
1656
        pop     ebx
1644
        pop     ebx
1657
        jmp     .destroy_new_socket
1645
        jmp     .destroy_new_socket
Line -... Line 1646...
-
 
1646
 
1658
 
1647
;-----------------------------------------
Line -... Line 1648...
-
 
1648
; The connection has no associated socket
1659
  .no_socket:
1649
 
1660
 
1650
  .no_socket:
1661
        pusha
1651
        pusha
1662
        mov     ecx, socket_mutex
1652
        mov     ecx, socket_mutex
Line 1685... Line 1675...
1685
  .respond_seg_syn:
1675
  .respond_seg_syn:
1686
        mov     cl, TH_RST + TH_ACK
1676
        mov     cl, TH_RST + TH_ACK
1687
        call    TCP_respond_segment
1677
        call    TCP_respond_segment
1688
        jmp     .drop_no_socket
1678
        jmp     .drop_no_socket
Line 1689... Line 1679...
1689
 
1679
 
1690
;-----
1680
;------------------------------------------------
Line 1691... Line 1681...
1691
; Drop
1681
; Unlock socket mutex and prepare to drop segment
1692
 
1682
 
Line 1693... Line 1683...
1693
  .drop:
1683
  .drop:
1694
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Dropping segment\n"
1684
        DEBUGF  DEBUG_NETWORK_VERBOSE, "TCP_input: Dropping segment\n"
1695
 
1685
 
1696
        pusha
1686
        pusha
Line -... Line 1687...
-
 
1687
        lea     ecx, [ebx + SOCKET.mutex]
-
 
1688
        call    mutex_unlock
-
 
1689
        popa
1697
        lea     ecx, [ebx + SOCKET.mutex]
1690
 
1698
        call    mutex_unlock
1691
;--------------------------------------------
1699
        popa
1692
; Destroy the newly created socket if needed
Line 1700... Line 1693...
1700
 
1693
 
1701
  .destroy_new_socket:
1694
  .destroy_new_socket:
Line -... Line 1695...
-
 
1695
        test    [temp_bits], TCP_BIT_DROPSOCKET
-
 
1696
        jz      .drop_no_socket
-
 
1697
 
1702
        test    [temp_bits], TCP_BIT_DROPSOCKET
1698
        mov     eax, ebx
1703
        jz      .drop_no_socket
1699
        call    SOCKET_free
Line 1704... Line 1700...
1704
 
1700
 
1705
        mov     eax, ebx
1701
;------------------