Rev 1534 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1534 | Rev 1536 | ||
---|---|---|---|
Line 14... | Line 14... | ||
14 | ;; GNU GENERAL PUBLIC LICENSE ;; |
14 | ;; GNU GENERAL PUBLIC LICENSE ;; |
15 | ;; Version 2, June 1991 ;; |
15 | ;; Version 2, June 1991 ;; |
16 | ;; ;; |
16 | ;; ;; |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 18... | Line 18... | ||
18 | 18 | ||
Line 19... | Line 19... | ||
19 | $Revision: 1534 $ |
19 | $Revision: 1536 $ |
20 | 20 | ||
21 | ; Socket states |
21 | ; Socket states |
22 | TCB_CLOSED equ 0 |
22 | TCB_CLOSED equ 0 |
Line 88... | Line 88... | ||
88 | .Checksum dw ? |
88 | .Checksum dw ? |
89 | .UrgentPointer dw ? |
89 | .UrgentPointer dw ? |
90 | .Data: ; ..or options |
90 | .Data: ; ..or options |
91 | ends |
91 | ends |
Line 92... | Line -... | ||
92 | - | ||
93 | struct tcp_in_queue_entry |
- | |
94 | .data_ptr dd ? |
- | |
95 | .data_size dd ? |
- | |
96 | .offset dd ? |
- | |
97 | .size: |
- | |
98 | ends |
- | |
99 | - | ||
100 | struct tcp_out_queue_entry |
- | |
101 | .data_ptr dd ? |
- | |
102 | .data_size dd ? |
- | |
103 | - | ||
104 | .size: |
- | |
105 | ends |
- | |
106 | 92 | ||
107 | align 4 |
93 | align 4 |
108 | uglobal |
94 | uglobal |
109 | TCP_segments_tx rd IP_MAX_INTERFACES |
95 | TCP_segments_tx rd IP_MAX_INTERFACES |
110 | TCP_segments_rx rd IP_MAX_INTERFACES |
96 | TCP_segments_rx rd IP_MAX_INTERFACES |
Line 555... | Line 541... | ||
555 | ; If the packets are in order (data queue is empty), add the data to the socket buffer and request a delayed ACK |
541 | ; If the packets are in order (data queue is empty), add the data to the socket buffer and request a delayed ACK |
Line 556... | Line 542... | ||
556 | 542 | ||
557 | cmp [ebx + TCP_SOCKET.t_state], TCB_ESTABLISHED |
543 | cmp [ebx + TCP_SOCKET.t_state], TCB_ESTABLISHED |
Line 558... | Line -... | ||
558 | jnz .not_uni_xfer |
- | |
559 | - | ||
560 | DEBUGF 1,"1\n" |
544 | jnz .not_uni_xfer |
561 | 545 | ||
Line 562... | Line -... | ||
562 | test [edx + TCP_segment.Flags], TH_SYN + TH_FIN + TH_RST + TH_URG |
- | |
563 | jnz .not_uni_xfer |
- | |
564 | 546 | test [edx + TCP_segment.Flags], TH_SYN + TH_FIN + TH_RST + TH_URG |
|
565 | DEBUGF 1,"2\n" |
547 | jnz .not_uni_xfer |
Line 566... | Line -... | ||
566 | - | ||
567 | test [edx + TCP_segment.Flags], TH_ACK |
- | |
568 | jz .not_uni_xfer |
548 | |
569 | 549 | test [edx + TCP_segment.Flags], TH_ACK |
|
570 | DEBUGF 1,"3\n" |
550 | jz .not_uni_xfer |
Line 571... | Line -... | ||
571 | - | ||
572 | mov eax, [edx + TCP_segment.SequenceNumber] |
- | |
573 | cmp eax, [ebx + TCP_SOCKET.RCV_NXT] |
551 | |
574 | jne .not_uni_xfer |
552 | mov eax, [edx + TCP_segment.SequenceNumber] |
575 | 553 | cmp eax, [ebx + TCP_SOCKET.RCV_NXT] |
|
576 | DEBUGF 1,"4\n" |
- | |
577 | - | ||
Line 578... | Line 554... | ||
578 | ;; movzx eax, [edx + TCP_segment.Window] ;;;;; (should use pre-calculated value isntead: todo: figure out where to store it) |
554 | jne .not_uni_xfer |
579 | ;; cmp eax, [ebx + TCP_SOCKET.SND_WND] |
555 | |
580 | ;; jne .not_uni_xfer |
556 | movzx eax, [edx + TCP_segment.Window] ;;;;; (should use pre-calculated value instead: todo: figure out where to store it) |
Line 581... | Line -... | ||
581 | - | ||
582 | DEBUGF 1,"5\n" |
- | |
583 | 557 | cmp eax, [ebx + TCP_SOCKET.SND_WND] |
|
584 | mov eax, [ebx + TCP_SOCKET.SND_NXT] |
558 | jne .not_uni_xfer |
Line 585... | Line 559... | ||
585 | cmp eax, [ebx + TCP_SOCKET.SND_MAX] |
559 | |
586 | jne .not_uni_xfer |
560 | mov eax, [ebx + TCP_SOCKET.SND_NXT] |
587 | 561 | cmp eax, [ebx + TCP_SOCKET.SND_MAX] |
|
588 | DEBUGF 1,"6\n" |
562 | jne .not_uni_xfer |
589 | 563 | ||
Line 590... | Line -... | ||
590 | ;--------------------------------------- |
- | |
591 | ; check if we are sender in the uni-xfer |
- | |
592 | 564 | ;--------------------------------------- |
|
593 | ; If the following 4 conditions are all true, this segment is a pure ACK. |
565 | ; check if we are sender in the uni-xfer |
594 | ; |
566 | |
595 | ; - The segment contains no data. |
567 | ; If the following 4 conditions are all true, this segment is a pure ACK. |
596 | test ecx, ecx |
568 | ; |
Line 597... | Line -... | ||
597 | jnz .not_sender |
- | |
598 | - | ||
599 | DEBUGF 1,"7\n" |
569 | ; - The segment contains no data. |
600 | 570 | test ecx, ecx |
|
601 | ; - The congestion window is greater than or equal to the current send window. |
571 | jnz .not_sender |
602 | ; This test is true only if the window is fully open, that is, the connection is not in the middle of slow start or congestion avoidance. |
572 | |
Line 603... | Line -... | ||
603 | mov eax, [ebx + TCP_SOCKET.SND_CWND] |
- | |
604 | cmp eax, [ebx + TCP_SOCKET.SND_WND] |
- | |
605 | jl .not_uni_xfer |
573 | ; - The congestion window is greater than or equal to the current send window. |
606 | 574 | ; This test is true only if the window is fully open, that is, the connection is not in the middle of slow start or congestion avoidance. |
|
607 | DEBUGF 1,"8\n" |
575 | mov eax, [ebx + TCP_SOCKET.SND_CWND] |
Line 608... | Line 576... | ||
608 | 576 | cmp eax, [ebx + TCP_SOCKET.SND_WND] |
|
Line 623... | Line 591... | ||
623 | ; Packet is a pure ACK, process it |
591 | ; Packet is a pure ACK, process it |
Line 624... | Line 592... | ||
624 | 592 | ||
Line 625... | Line 593... | ||
625 | ; Update RTT estimators |
593 | ; Update RTT estimators |
626 | 594 | ||
627 | ; Delete acknowledged bytes from send buffer |
- | |
628 | ; notice how ecx already holds number of bytes ack-ed |
595 | ; Delete acknowledged bytes from send buffer |
629 | 596 | mov ecx, eax |
|
Line -... | Line 597... | ||
- | 597 | lea eax, [ebx + STREAM_SOCKET.snd] |
|
- | 598 | call SOCKET_ring_free |
|
- | 599 | ||
- | 600 | ; update window pointers |
|
- | 601 | mov eax, [edx + TCP_segment.AckNumber] |
|
630 | lea eax, [ebx + STREAM_SOCKET.snd] |
602 | dec eax |
631 | call SOCKET_ring_free |
603 | mov [ebx + TCP_SOCKET.SND_WL1], eax |
Line 632... | Line 604... | ||
632 | 604 | ||
633 | ; Stop retransmit timer |
605 | ; Stop retransmit timer |
634 | mov [ebx + TCP_SOCKET.timer_ack], 0 |
606 | mov [ebx + TCP_SOCKET.timer_ack], 0 |
Line 635... | Line 607... | ||
635 | 607 | ||
- | 608 | ; Awaken waiting processes |
|
636 | ; Awaken waiting processes |
609 | mov eax, ebx |
637 | mov eax, ebx |
610 | call SOCKET_notify_owner |
- | 611 | ||
638 | call SOCKET_notify_owner |
612 | ;; Generate more output |
Line 639... | Line 613... | ||
639 | 613 | ;; mov eax, ebx |
|
640 | ; Generate more output |
614 | ;; call TCP_output |
Line 641... | Line 615... | ||
641 | call TCP_output |
615 | ;; |
642 | 616 | ;; jmp .drop |
|
Line 643... | Line -... | ||
643 | jmp .drop |
- | |
644 | - | ||
645 | ;------------------------------------------------- |
617 | jmp .step6 |
646 | ; maybe we are the receiver in the uni-xfer then.. |
618 | |
647 | 619 | ;------------------------------------------------- |
|
648 | .not_sender: |
620 | ; maybe we are the receiver in the uni-xfer then.. |
Line 1082... | Line 1054... | ||
1082 | 1054 | ||
Line 1083... | Line 1055... | ||
1083 | DEBUGF 1,"TCP state = syn received\n" |
1055 | DEBUGF 1,"TCP state = syn received\n" |
Line 1084... | Line 1056... | ||
1084 | 1056 | ||
Line 1085... | Line 1057... | ||
1085 | ;;;;; |
1057 | ;;;;; |
Line 1086... | Line -... | ||
1086 | - | ||
Line 1087... | Line -... | ||
1087 | .ack_dup: |
- | |
Line 1088... | Line 1058... | ||
1088 | 1058 | ||
Line 1089... | Line 1059... | ||
1089 | DEBUGF 1,"Duplicate ACK\n" |
1059 | .ack_nodup: |
Line 1090... | Line 1060... | ||
1090 | 1060 | ||
1091 | ;;;; |
1061 | DEBUGF 1,"New ACK\n" |
1092 | 1062 | ||
Line 1123... | Line 1093... | ||
1123 | 1093 | ||
1124 | 1094 | ||
Line 1125... | Line 1095... | ||
1125 | ;------------------------------------------ |
1095 | ;------------------------------------------ |
- | 1096 | ; Remove acknowledged data from send buffer |
|
1126 | ; Remove acknowledged data from send buffer |
1097 | |
1127 | 1098 | pusha |
|
1128 | push ecx |
1099 | ; Delete acknowledged bytes from send buffer |
1129 | mov ecx, [edx + TCP_segment.AckNumber] ;;; |
1100 | mov ecx, [edx + TCP_segment.AckNumber] |
1130 | sub ecx, [ebx + TCP_SOCKET.SND_UNA] ;;; |
1101 | sub ecx, [ebx + TCP_SOCKET.SND_UNA] |
- | 1102 | lea eax, [ebx + STREAM_SOCKET.snd] |
|
- | 1103 | call SOCKET_ring_free |
|
- | 1104 | popa |
|
- | 1105 | ||
- | 1106 | ||
- | 1107 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; code missing (943?) |
|
- | 1108 | ||
- | 1109 | mov eax, [edx + TCP_segment.AckNumber] |
|
- | 1110 | mov [ebx + TCP_SOCKET.SND_UNA], eax |
|
- | 1111 | ||
- | 1112 | cmp eax, [ebx + TCP_SOCKET.SND_NXT] |
|
- | 1113 | jl @f |
|
- | 1114 | mov [ebx + TCP_SOCKET.SND_NXT], eax |
|
Line 1131... | Line 1115... | ||
1131 | lea eax, [ebx + STREAM_SOCKET.snd] |
1115 | @@: |
1132 | call SOCKET_ring_free ;;;; 943 - 956 |
1116 | |
Line 1133... | Line 1117... | ||
1133 | pop ecx |
1117 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 1174... | Line 1158... | ||
1174 | ._1010: |
1158 | ._1010: |
Line 1175... | Line 1159... | ||
1175 | 1159 | ||
Line 1176... | Line -... | ||
1176 | jmp .step6 |
- | |
1177 | - | ||
1178 | 1160 | jmp .step6 |
|
Line 1179... | Line 1161... | ||
1179 | 1161 | ||
Line 1180... | Line 1162... | ||
1180 | align 4 |
1162 | |
1181 | .step6: |
1163 | .step6: |
Line 1182... | Line 1164... | ||
1182 | 1164 | ||
1183 | DEBUGF 1,"step 6\n" |
1165 | DEBUGF 1,"step 6\n" |
Line 1184... | Line 1166... | ||
1184 | 1166 | ||
1185 | ;-------------------------- |
1167 | ;---------------------------------------------- |
1186 | ; update window information |
- | |
1187 | - | ||
1188 | test [edx + TCP_segment.Flags], TH_ACK |
- | |
1189 | jz .no_window_update |
- | |
1190 | - | ||
1191 | mov eax, [ebx + TCP_SOCKET.SND_WL1] |
- | |
1192 | cmp eax, [edx + TCP_segment.SequenceNumber] |
1168 | ; check if we need to update window information |
1193 | 1169 | ||
Line 1194... | Line 1170... | ||
1194 | ;;;; 1021 |
1170 | test [edx + TCP_segment.Flags], TH_ACK |
1195 | 1171 | jz .no_window_update |
|
- | 1172 | ||
- | 1173 | mov eax, [ebx + TCP_SOCKET.SND_WL1] |
|
1196 | ;---------------------------------- |
1174 | cmp eax, [edx + TCP_segment.SequenceNumber] |
- | 1175 | jl .update_window |
|
- | 1176 | jg @f |
|
- | 1177 | ||
- | 1178 | mov eax, [ebx + TCP_SOCKET.SND_WL2] |
|
Line 1197... | Line 1179... | ||
1197 | ; Keep track of pure window updates |
1179 | cmp eax, [edx + TCP_segment.AckNumber] |
1198 | 1180 | jl .update_window |
|
1199 | test ecx, ecx |
1181 | jg .no_window_update |
Line 1200... | Line 1182... | ||
1200 | jz @f |
1182 | @@: |
Line 1201... | Line 1183... | ||
1201 | 1183 | ||
Line -... | Line 1184... | ||
- | 1184 | mov eax, [ebx + TCP_SOCKET.SND_WL2] ;;;; |
|
- | 1185 | cmp eax, [edx + TCP_segment.AckNumber] |
|
- | 1186 | jne .no_window_update |
|
- | 1187 | ||
- | 1188 | movzx eax, [edx + TCP_segment.Window] |
|
- | 1189 | cmp eax, [ebx + TCP_SOCKET.SND_WND] |
|
- | 1190 | jle .no_window_update |
|
- | 1191 | ||
- | 1192 | .update_window: |
|
- | 1193 | ||
1202 | mov eax, [ebx + TCP_SOCKET.SND_WL2] |
1194 | DEBUGF 1,"Updating window\n" |
- | 1195 | ||
- | 1196 | ;---------------------------------- |
|
- | 1197 | ; Keep track of pure window updates |
|
- | 1198 | ||
- | 1199 | ; test ecx, ecx |
|
- | 1200 | ; jz @f |
|
- | 1201 | ; |
|
- | 1202 | ; mov eax, [ebx + TCP_SOCKET.SND_WL2] |
|
1203 | cmp eax, [edx + TCP_segment.AckNumber] |
1203 | ; cmp eax, [edx + TCP_segment.AckNumber] |
1204 | jne @f |
1204 | ; jne @f |
1205 | 1205 | ; |
|
1206 | ;; mov eax, tiwin |
1206 | ; ;; mov eax, tiwin |
1207 | cmp eax, [ebx + TCP_SOCKET.SND_WND] |
1207 | ; cmp eax, [ebx + TCP_SOCKET.SND_WND] |
Line 1208... | Line 1208... | ||
1208 | jle @f |
1208 | ; jle @f |
1209 | 1209 | ; |
|
Line 1210... | Line 1210... | ||
1210 | ;;; update stats |
1210 | ; ;;; update stats |
1211 | 1211 | ; |
|
Line 1212... | Line 1212... | ||
1212 | @@: |
1212 | ; @@: |
Line 1213... | Line 1213... | ||
1213 | 1213 | ||
Line 1494... | Line 1494... | ||
1494 | ;----------------------------------------------------------------- |
1494 | ;----------------------------------------------------------------- |
1495 | ; |
1495 | ; |
1496 | ; TCP_output |
1496 | ; TCP_output |
1497 | ; |
1497 | ; |
1498 | ; IN: eax = socket pointer |
1498 | ; IN: eax = socket pointer |
1499 | ;; esi = ptr to data |
- | |
1500 | ;; ecx = number of data bytes |
- | |
1501 | ; |
1499 | ; |
1502 | ; OUT: / |
1500 | ; OUT: / |
1503 | ; |
1501 | ; |
1504 | ;----------------------------------------------------------------- |
1502 | ;----------------------------------------------------------------- |
1505 | align 4 |
1503 | align 4 |
Line 1847... | Line 1845... | ||
1847 | 1845 | ||
1848 | ; eax = ptr to ring struct |
1846 | ; eax = ptr to ring struct |
1849 | ; ecx = buffer size |
1847 | ; ecx = buffer size |
Line -... | Line 1848... | ||
- | 1848 | ; edi = ptr to buffer |
|
1850 | ; edi = ptr to buffer |
1849 | |
1851 | 1850 | ; test ecx, ecx |
|
1852 | mov eax, [esp+4] ; socket ptr |
1851 | mov eax, [esp+4] ; socket ptr |
- | 1852 | add [eax + TCP_SOCKET.SND_NXT], ecx |
|
1853 | push edx |
1853 | add eax, STREAM_SOCKET.snd |
- | 1854 | push edx |
|
1854 | add eax, STREAM_SOCKET.snd |
1855 | call SOCKET_ring_read |
1855 | call SOCKET_ring_read |
1856 | pop esi |
Line 1856... | Line 1857... | ||
1856 | pop esi ecx |
1857 | pop ecx |
1857 | pop eax |
1858 | pop eax |
1858 | 1859 | ||
1859 | test [esi + TCP_segment.Flags], TH_SYN + TH_FIN |
1860 | test [esi + TCP_segment.Flags], TH_SYN + TH_FIN |
1860 | jz @f |
1861 | jz @f |
Line 1861... | Line -... | ||
1861 | inc [eax + TCP_SOCKET.SND_NXT] |
- | |
1862 | ;;; TODO: update sentfin flag |
- | |
1863 | @@: |
1862 | inc [eax + TCP_SOCKET.SND_NXT] |
1864 | 1863 | ;;; TODO: update sentfin flag |
|
1865 | ;; add [eax + TCP_SOCKET.SND_NXT], ecx |
1864 | @@: |
1866 | 1865 | ||
Line 1891... | Line 1890... | ||
1891 | 1890 | ||
1892 | 1891 | ||
1893 | .fail: |
1892 | .fail: |
1894 | pop ecx |
1893 | pop ecx |
1895 | add esp, ecx |
1894 | add esp, ecx |
1896 | add esp, 4+4+8+4 |
1895 | add esp, 4+8 |