Subversion Repositories Kolibri OS

Rev

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

Rev 1716 Rev 1719
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: 1716 $
19
$Revision: 1719 $
20
 
20
 
21
; Socket states
21
; Socket states
22
TCB_CLOSED		equ 0
22
TCB_CLOSED		equ 0
Line 570... Line 570...
570
	jz	.not_uni_xfer
570
	jz	.not_uni_xfer
Line 571... Line 571...
571
 
571
 
572
	mov	eax, [edx + TCP_segment.SequenceNumber]
572
	mov	eax, [edx + TCP_segment.SequenceNumber]
573
	cmp	eax, [ebx + TCP_SOCKET.RCV_NXT]
573
	cmp	eax, [ebx + TCP_SOCKET.RCV_NXT]
574
	jne	.not_uni_xfer
-
 
-
 
574
	jne	.not_uni_xfer
-
 
575
	DEBUGF	1,"TCP_segment.window=%u\n", [edx + TCP_segment.Window]:4
575
 
576
	DEBUGF	1,"TCP_SOCKET.SND_WND=%u\n", [ebx + TCP_SOCKET.SND_WND]:4
576
	mov	eax, dword [edx + TCP_segment.Window]
577
	mov	eax, dword [edx + TCP_segment.Window]
577
	cmp	eax, [ebx + TCP_SOCKET.SND_WND]
578
	cmp	eax, [ebx + TCP_SOCKET.SND_WND]
Line 578... Line 579...
578
	jne	.not_uni_xfer
579
	jne	.not_uni_xfer
Line 611... Line 612...
611
; Packet is a pure ACK, process it
612
; Packet is a pure ACK, process it
Line 612... Line 613...
612
 
613
 
Line 613... Line 614...
613
; Update RTT estimators
614
; Update RTT estimators
-
 
615
 
614
 
616
; Delete acknowledged bytes from send buffer
615
; Delete acknowledged bytes from send buffer
617
	pusha
616
	mov	ecx, eax
618
	mov	ecx, eax
-
 
619
	lea	eax, [ebx + STREAM_SOCKET.snd]
Line 617... Line 620...
617
	lea	eax, [ebx + STREAM_SOCKET.snd]
620
	call	SOCKET_ring_free
618
	call	SOCKET_ring_free
621
	popa
619
 
622
 
620
; update window pointers
623
; update window pointers
Line 627... Line 630...
627
 
630
 
628
; Awaken waiting processes
631
; Awaken waiting processes
629
	mov	eax, ebx
632
	mov	eax, ebx
Line 630... Line 633...
630
	call	SOCKET_notify_owner
633
	call	SOCKET_notify_owner
631
 
634
 
632
;; Generate more output
635
;; Generate more output                  FIXME
633
;;        mov     eax, ebx
636
;;        mov     eax, ebx
634
;;        call    TCP_output
637
;;        call    TCP_output
635
;;
638
;;
Line 636... Line 639...
636
;;        jmp     .drop
639
;;        jmp     .drop
637
	jmp	.step6
640
	jmp	.ack_processed
Line 638... Line 641...
638
 
641
 
Line 645... Line 648...
645
; - The acknowledgment field equals the largest unacknowledged sequence number. This means no data is acknowledged by this segment.
648
; - The acknowledgment field equals the largest unacknowledged sequence number. This means no data is acknowledged by this segment.
646
	mov	eax, [edx + TCP_segment.AckNumber]
649
	mov	eax, [edx + TCP_segment.AckNumber]
647
	cmp	eax, [ebx + TCP_SOCKET.SND_UNA]
650
	cmp	eax, [ebx + TCP_SOCKET.SND_UNA]
648
	jne	.not_uni_xfer
651
	jne	.not_uni_xfer
Line 649... Line 652...
649
 
652
 
-
 
653
; - The reassembly list of out-of-order segments for the connection is empty (seg_next equals tp).
-
 
654
 
Line 650... Line 655...
650
; - The reassembly list of out-of-order segments for the connection is empty (seg_next equals tp). ;;;;;;;
655
;;;;;;;     TODO
Line 651... Line 656...
651
 
656
 
652
	jnz	.not_uni_xfer
657
	jnz	.not_uni_xfer
Line 653... Line 658...
653
 
658
 
Line -... Line 659...
-
 
659
;-------------------------------------
654
;-------------------------------------
660
; Complete processing of received data
655
; Complete processing of received data
661
 
656
 
662
	DEBUGF	1,"header prediction: we are receiver\nreceiving %u bytes of data\n", ecx
Line 657... Line 663...
657
	DEBUGF	1,"header prediction: we are receiver\nreceiving %u bytes of data\n", ecx
663
 
658
 
664
	pusha
-
 
665
	add	esi, edx
Line 659... Line 666...
659
	add	esi, edx
666
	lea	eax, [ebx + STREAM_SOCKET.rcv]
660
	lea	eax, [ebx + STREAM_SOCKET.rcv]
667
	call	SOCKET_ring_write			; Add the data to the socket buffer
Line 661... Line 668...
661
	call	SOCKET_ring_write			; Add the data to the socket buffer
668
 
Line 765... Line 772...
765
	jz	@f
772
	jz	@f
Line 766... Line 773...
766
 
773
 
767
	mov	eax, [edx + TCP_segment.AckNumber]
774
	mov	eax, [edx + TCP_segment.AckNumber]
768
	cmp	eax, [ebx + TCP_SOCKET.ISS]
775
	cmp	eax, [ebx + TCP_SOCKET.ISS]
769
	jle	.drop_with_reset
-
 
770
 
-
 
771
;        mov     eax, [edx + TCP_segment.AckNumber]
776
	jle	.drop_with_reset
772
	cmp	eax, [ebx + TCP_SOCKET.SND_MAX]
777
	cmp	eax, [ebx + TCP_SOCKET.SND_MAX]
773
	jg	.drop_with_reset
778
	jg	.drop_with_reset
Line 774... Line 779...
774
       @@:
779
       @@:
775
 
780
 
Line 776... Line 781...
776
	test	[edx + TCP_segment.Flags], TH_RST
781
	test	[edx + TCP_segment.Flags], TH_RST
777
	jz	@f
782
	jz	@f
Line -... Line 783...
-
 
783
 
778
 
784
	test	[edx + TCP_segment.Flags], TH_ACK
779
	test	[edx + TCP_segment.Flags], TH_ACK
785
	jz	.drop
Line 780... Line 786...
780
	jz	.drop
786
 
781
 
787
	mov	eax, ebx
Line 853... Line 859...
853
	; TODO: 592
859
	; TODO: 592
854
	mov	cx, [ebx + TCP_SOCKET.RCV_WND]
860
	mov	cx, [ebx + TCP_SOCKET.RCV_WND]
855
	; TODO...
861
	; TODO...
856
       @@:
862
       @@:
857
	;;;;;
863
	;;;;;
858
	jmp	.step6
864
	jmp	.ack_processed
Line 859... Line 865...
859
 
865
 
Line 860... Line 866...
860
 
866
 
Line 865... Line 871...
865
 
871
 
Line 866... Line 872...
866
	DEBUGF	1,"Trimming window\n"
872
	DEBUGF	1,"Trimming window\n"
867
 
873
 
868
	mov	eax, [ebx + TCP_SOCKET.RCV_NXT]
-
 
869
	sub	eax, [edx + TCP_segment.SequenceNumber]
-
 
870
 
874
	mov	eax, [ebx + TCP_SOCKET.RCV_NXT]
Line 871... Line 875...
871
	test	eax, eax
875
	sub	eax, [edx + TCP_segment.SequenceNumber]
872
	jz	.no_duplicate
876
	jz	.no_duplicate
Line 1062... Line 1066...
1062
; handle SYN-full and ACK-less segments
1066
; handle SYN-full and ACK-less segments
Line 1063... Line 1067...
1063
 
1067
 
1064
	test	[edx + TCP_segment.Flags], TH_SYN
1068
	test	[edx + TCP_segment.Flags], TH_SYN
Line -... Line 1069...
-
 
1069
	jz	@f
1065
	jz	@f
1070
 
1066
 
1071
	mov	eax, ebx
Line 1067... Line 1072...
1067
	mov	ebx, ECONNRESET
1072
	mov	ebx, ECONNRESET
Line 1068... Line 1073...
1068
	call	TCP_drop
1073
	call	TCP_drop
1069
 
1074
 
1070
	jmp	.drop_with_reset
1075
	jmp	.drop_with_reset
-
 
1076
 
1071
 
1077
	test	[edx + TCP_segment.Flags], TH_ACK
1072
	test	[edx + TCP_segment.Flags], TH_ACK
1078
	jz	.drop
Line 1073... Line 1079...
1073
	jz	.drop
1079
      @@:
1074
      @@:
-
 
1075
;----------------
1080
 
Line 1076... Line 1081...
1076
; Process the ACK
1081
;---------------
Line 1077... Line 1082...
1077
 
1082
; ACK processing
Line 1078... Line 1083...
1078
	cmp	[ebx + TCP_SOCKET.t_state], TCB_SYN_RECEIVED
1083
 
Line 1079... Line 1084...
1079
	jg	.ack_dup
1084
	cmp	[ebx + TCP_SOCKET.t_state], TCB_SYN_RECEIVED
Line -... Line 1085...
-
 
1085
	jnz	.no_syn_rcv
-
 
1086
 
-
 
1087
	DEBUGF	1,"TCP state = syn received\n"
Line -... Line 1088...
-
 
1088
 
Line -... Line 1089...
-
 
1089
	;;;;;  801-815
-
 
1090
 
-
 
1091
  .no_syn_rcv:
-
 
1092
 
-
 
1093
; check for duplicate ACK
-
 
1094
 
-
 
1095
	mov	eax, [edx + TCP_segment.AckNumber]
-
 
1096
	cmp	eax, [ebx + TCP_SOCKET.SND_UNA]
-
 
1097
	jg	.not_dup_ack
-
 
1098
 
-
 
1099
	DEBUGF	1,"Duplicate ACK\n"
-
 
1100
 
-
 
1101
	test	ecx, ecx
-
 
1102
	jnz	.ack_processed
1080
	jl	.ack_nodup
1103
 
-
 
1104
	mov	eax, dword [edx + TCP_segment.Window]
-
 
1105
	cmp	eax, [ebx + TCP_SOCKET.SND_WND]
Line 1081... Line -...
1081
 
-
 
Line 1082... Line 1106...
1082
	DEBUGF	1,"TCP state = syn received\n"
1106
	jne	.ack_processed
1083
 
1107
 
1084
	;;;;;
1108
; Process the duplicate ACK
Line 1085... Line 1109...
1085
 
1109
 
Line 1086... Line 1110...
1086
  .ack_nodup:
1110
	;;;;; 833 - 878
Line 1121... Line 1145...
1121
 
1145
 
1122
;------------------------------------------
1146
;------------------------------------------
Line 1123... Line 1147...
1123
; Remove acknowledged data from send buffer
1147
; Remove acknowledged data from send buffer
1124
 
-
 
1125
	pusha
1148
 
1126
; Delete acknowledged bytes from send buffer
1149
	pusha
-
 
1150
	mov	ecx, [edx + TCP_segment.AckNumber]
1127
	mov	ecx, [edx + TCP_segment.AckNumber]
1151
	sub	ecx, [ebx + TCP_SOCKET.SND_UNA] 	; ecx now holds number of bytes acked
1128
	sub	ecx, [ebx + TCP_SOCKET.SND_UNA]
1152
 
1129
	lea	eax, [ebx + STREAM_SOCKET.snd]
1153
	lea	eax, [ebx + STREAM_SOCKET.snd]
Line -... Line 1154...
-
 
1154
	call	SOCKET_ring_free
-
 
1155
	popa
Line -... Line 1156...
-
 
1156
 
1130
	call	SOCKET_ring_free
1157
;---------------------------------------
1131
	popa
-
 
Line -... Line 1158...
-
 
1158
; Wake up process waiting on send buffer
Line 1132... Line 1159...
1132
 
1159
 
1133
 
1160
	mov	eax, ebx
Line 1134... Line 1161...
1134
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  code missing (943?)
1161
	call	SOCKET_notify_owner
1135
 
1162
 
1136
 
1163
; Update TCB
1137
 
1164
 
Line 1138... Line -...
1138
	mov	eax, [edx + TCP_segment.AckNumber]
-
 
1139
	mov	[ebx + TCP_SOCKET.SND_UNA], eax
-
 
1140
 
1165
	mov	eax, [edx + TCP_segment.AckNumber]
1141
	cmp	eax, [ebx + TCP_SOCKET.SND_NXT]
-
 
1142
	jl	@f
-
 
1143
	mov	[ebx + TCP_SOCKET.SND_NXT], eax
1166
	mov	[ebx + TCP_SOCKET.SND_UNA], eax
Line 1144... Line 1167...
1144
       @@:
1167
 
1145
 
-
 
1146
 
1168
	cmp	eax, [ebx + TCP_SOCKET.SND_NXT]
Line 1147... Line 1169...
1147
;---------------------------------------
1169
	jl	@f
1148
; Wake up process waiting on send buffer
1170
	mov	[ebx + TCP_SOCKET.SND_NXT], eax
1149
 
1171
       @@:
1150
	mov	eax, ebx
1172
 
1151
	call	SOCKET_notify_owner
1173
; General ACK handling complete
1152
 
1174
; Now do the state-specific ones
1153
	mov	eax, [ebx + TCP_SOCKET.t_state]
1175
 
1154
	shl	eax, 2
1176
	mov	eax, [ebx + TCP_SOCKET.t_state]
1155
	jmp	dword [eax + .ACK_sw_list]
1177
	jmp	dword [eax*4 + .ACK_sw_list]
1156
 
1178
 
1157
  .ACK_sw_list:
1179
  .ACK_sw_list:
1158
	dd	.step6		;TCB_CLOSED
1180
	dd	.ack_processed	;TCB_CLOSED
-
 
1181
	dd	.ack_processed	;TCB_LISTEN
-
 
1182
	dd	.ack_processed	;TCB_SYN_SENT
-
 
1183
	dd	.ack_processed	;TCB_SYN_RECEIVED
Line -... Line 1184...
-
 
1184
	dd	.ack_processed	;TCB_ESTABLISHED
Line 1159... Line 1185...
1159
	dd	.step6		;TCB_LISTEN
1185
	dd	.ack_processed	;TCB_CLOSE_WAIT
Line -... Line 1186...
-
 
1186
	dd	.ack_fw1	;TCB_FIN_WAIT_1
Line 1160... Line 1187...
1160
	dd	.step6		;TCB_SYN_SENT
1187
	dd	.ack_c		;TCB_CLOSING
Line -... Line 1188...
-
 
1188
	dd	.ack_la 	;TCB_LAST_ACK
Line 1161... Line 1189...
1161
	dd	.step6		;TCB_SYN_RECEIVED
1189
	dd	.ack_processed	;TCB_FIN_WAIT_2
Line 1162... Line 1190...
1162
	dd	.step6		;TCB_ESTABLISHED
1190
	dd	.ack_tw 	;TCB_TIMED_WAIT
Line 1163... Line 1191...
1163
	dd	.step6		;TCB_CLOSE_WAIT
1191
 
Line 1164... Line -...
1164
	dd	._963		;TCB_FIN_WAIT_1
-
 
Line -... Line 1192...
-
 
1192
 
Line 1165... Line 1193...
1165
	dd	._958		;TCB_CLOSING
1193
  .ack_fw1:
Line 1166... Line 1194...
1166
	dd	._999		;TCB_LAST_ACK
1194
 
Line 1167... Line 1195...
1167
	dd	.step6		;TCB_FIN_WAIT_2
1195
;;; TODO: 963
Line 1168... Line 1196...
1168
	dd	._1010		;TCB_TIMED_WAIT
1196
 
Line 1169... Line 1197...
1169
 
1197
	jmp	.ack_processed
1170
 
1198
 
Line 1171... Line 1199...
1171
  ._963:
1199
  .ack_c:
Line 1381... Line 1409...
1381
 
1409
 
Line 1382... Line 1410...
1382
	mov	[ebx + SOCKET.lock], 0
1410
	mov	[ebx + SOCKET.lock], 0
Line 1383... Line 1411...
1383
 
1411
 
1384
	;;; if debug enabled, output packet
1412
	;;; if debug enabled, output packet
Line 1385... Line 1413...
1385
 
1413
 
1386
	;test    ;;;needoutput = 1
1414
	;test    needoutput, needoutput
1387
	;jnz     .outputnow
-
 
1388
 
-
 
1389
	test	[ebx + TCP_SOCKET.t_flags], TF_ACKNOW
-
 
1390
	jnz	.ack_now
-
 
1391
 
-
 
1392
	call	kernel_free
-
 
Line 1393... Line 1415...
1393
	add	esp, 4
1415
	;jz      .dumpit
Line 1394... Line 1416...
1394
	ret
1416
 
1395
 
1417
	test	[ebx + TCP_SOCKET.t_flags], TF_ACKNOW
1396
  .ack_now:
1418
	jz	.dumpit
1397
 
1419
 
Line -... Line 1420...
-
 
1420
	DEBUGF	1,"ACK now!\n"
-
 
1421
 
1398
	DEBUGF	1,"ACK now!\n"
1422
	push	ebx
1399
 
1423
	mov	eax, ebx
1400
	push	ebx
1424
	call	TCP_output
Line 1401... Line 1425...
1401
	mov	eax, ebx
1425
	pop	ebx
Line 2008... Line 2032...
2008
;
2032
;
2009
;-------------------------
2033
;-------------------------
2010
align 4
2034
align 4
2011
TCP_close:
2035
TCP_close:
Line -... Line 2036...
-
 
2036
 
-
 
2037
	DEBUGF	1,"TCP_close\n"
2012
 
2038
 
2013
;;; TODO: update RTT and mean deviation
2039
;;; TODO: update RTT and mean deviation
2014
;;; TODO: update slow start threshold
2040
;;; TODO: update slow start threshold
Line -... Line 2041...
-
 
2041
;;; TODO: release connection resources
-
 
2042
 
-
 
2043
; Now, mark the socket as being disconnected
-
 
2044
 
2015
;;; TODO: release connection resources
2045
	mov	[eax + SOCKET.state], 0 ;;; FIXME