Subversion Repositories Kolibri OS

Rev

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

Rev 1733 Rev 1763
Line -... Line 1...
-
 
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
2
;;                                                                 ;;
-
 
3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved.    ;;
-
 
4
;; Distributed under terms of the GNU General Public License       ;;
-
 
5
;;                                                                 ;;
-
 
6
;;  Part of the tcp/ip network stack for KolibriOS                 ;;
-
 
7
;;                                                                 ;;
-
 
8
;;   Written by hidnplayr@kolibrios.org                            ;;
-
 
9
;;                                                                 ;;
-
 
10
;;    Based on the code of 4.4BSD                                  ;;
-
 
11
;;                                                                 ;;
-
 
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
-
 
13
;;             Version 2, June 1991                                ;;
-
 
14
;;                                                                 ;;
-
 
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
 
16
 
-
 
17
$Revision: 1763 $
-
 
18
 
1
;-----------------------------------------------------------------
19
;-----------------------------------------------------------------
2
;
20
;
3
; TCP_input:
21
; TCP_input:
4
;
22
;
5
;  IN:  [esp] = ptr to buffer
23
;  IN:  [esp] = ptr to buffer
Line 337... Line 355...
337
;---------------------------------
355
;---------------------------------
338
; Packet is a pure ACK, process it
356
; Packet is a pure ACK, process it
Line 339... Line 357...
339
 
357
 
Line 340... Line 358...
340
; Update RTT estimators
358
; Update RTT estimators
Line -... Line 359...
-
 
359
 
341
 
360
;;; TODO
342
; Delete acknowledged bytes from send buffer
361
 
343
 
362
; Delete acknowledged bytes from send buffer
344
	pusha
363
	pusha
345
	mov	ecx, eax
364
	mov	ecx, eax
Line 346... Line 365...
346
	lea	eax, [ebx + STREAM_SOCKET.snd]
365
	lea	eax, [ebx + STREAM_SOCKET.snd]
347
	call	SOCKET_ring_free
366
	call	SOCKET_ring_free
348
	popa
-
 
349
 
367
	popa
Line 350... Line 368...
350
; update window pointers
368
 
351
	mov	eax, [edx + TCP_segment.AckNumber]
369
; update window pointers
Line 352... Line 370...
352
	dec	eax
370
	mov	eax, [edx + TCP_segment.AckNumber]
-
 
371
	mov	[ebx + TCP_SOCKET.SND_UNA], eax
353
	mov	[ebx + TCP_SOCKET.SND_WL1], eax
372
 
354
 
373
; Stop retransmit timer
Line 355... Line 374...
355
; Stop retransmit timer
374
	mov	[ebx + TCP_SOCKET.timer_ack], 0
356
	mov	[ebx + TCP_SOCKET.timer_ack], 0
-
 
357
 
375
 
358
; Awaken waiting processes
376
; Awaken waiting processes
359
	mov	eax, ebx
-
 
360
	call	SOCKET_notify_owner
377
	mov	[ebx + SOCKET.lock], 0
Line 361... Line 378...
361
 
378
	mov	eax, ebx
362
;; Generate more output     FIXME
379
	call	SOCKET_notify_owner
Line 363... Line 380...
363
;;        mov     eax, ebx
380
 
Line 385... Line 402...
385
 
402
 
Line 386... Line 403...
386
; Complete processing of received data
403
; Complete processing of received data
Line -... Line 404...
-
 
404
 
387
 
405
	DEBUGF	1,"header prediction: we are receiver\nreceiving %u bytes of data\n", ecx
388
	DEBUGF	1,"header prediction: we are receiver\nreceiving %u bytes of data\n", ecx
406
 
389
 
407
	add	[ebx + TCP_SOCKET.RCV_NXT], ecx 	; Update sequence number with number of bytes we have copied
390
	pusha
408
 
Line 391... Line 409...
391
	add	esi, edx
409
	add	esi, edx
392
	lea	eax, [ebx + STREAM_SOCKET.rcv]
410
	lea	eax, [ebx + STREAM_SOCKET.rcv]
393
	call	SOCKET_ring_write			; Add the data to the socket buffer
-
 
Line 394... Line -...
394
 
-
 
395
	mov	eax, ebx
411
	call	SOCKET_ring_write			; Add the data to the socket buffer
Line 396... Line 412...
396
	call	SOCKET_notify_owner
412
 
Line 413... Line 429...
413
 
429
 
Line 414... Line 430...
414
	DEBUGF	1,"Header prediction failed\n"
430
	DEBUGF	1,"Header prediction failed\n"
Line 415... Line 431...
415
 
431
 
Line 416... Line 432...
416
; Calculate receive window size
432
; Calculate receive window size
417
 
433
 
Line 418... Line 434...
418
;;;;
434
;;;; TODO: 444
Line 538... Line 554...
538
	push	[edx + TCP_segment.SequenceNumber]
554
	push	[edx + TCP_segment.SequenceNumber]
539
	pop	[ebx + TCP_SOCKET.IRS]
555
	pop	[ebx + TCP_SOCKET.IRS]
Line 540... Line 556...
540
 
556
 
Line 541... Line 557...
541
	TCP_rcvseqinit ebx
557
	TCP_rcvseqinit ebx
Line 542... Line 558...
542
 
558
 
543
	mov	[ebx + TCP_SOCKET.t_flags], TF_ACKNOW
559
	or	[ebx + TCP_SOCKET.t_flags], TF_ACKNOW
544
 
560
 
Line 606... Line 622...
606
;--------------------------------------------
622
;--------------------------------------------
607
; Protection Against Wrapped Sequence Numbers
623
; Protection Against Wrapped Sequence Numbers
Line 608... Line 624...
608
 
624
 
Line 609... Line 625...
609
; First, check if timestamp is present
625
; First, check if timestamp is present
Line 610... Line 626...
610
 
626
 
Line 611... Line 627...
611
;;;; TODO
627
;;;; TODO 602
Line 626... Line 642...
626
 
642
 
Line 627... Line 643...
627
; check for duplicate data at beginning of segment
643
; check for duplicate data at beginning of segment
628
 
644
 
629
	mov	eax, [ebx + TCP_SOCKET.RCV_NXT]
645
	mov	eax, [ebx + TCP_SOCKET.RCV_NXT]
-
 
646
	sub	eax, [edx + TCP_segment.SequenceNumber]
-
 
647
	jle	.no_duplicate
Line 630... Line 648...
630
	sub	eax, [edx + TCP_segment.SequenceNumber]
648
 
631
	jz	.no_duplicate
649
	DEBUGF	1,"Uh oh.. %x bytes of duplicate data!\n", eax
Line 632... Line 650...
632
 
650
 
Line 633... Line 651...
633
	test	[edx + TCP_segment.Flags], TH_SYN
651
	test	[edx + TCP_segment.Flags], TH_SYN
634
	jz	.no_drop
652
	jz	.no_dup_syn
Line 641... Line 659...
641
	cmp	[edx + TCP_segment.UrgentPointer], 1
659
	cmp	[edx + TCP_segment.UrgentPointer], 1
642
	jl	@f
660
	jl	@f
Line 643... Line 661...
643
 
661
 
Line 644... Line 662...
644
	dec	[edx + TCP_segment.UrgentPointer]
662
	dec	[edx + TCP_segment.UrgentPointer]
645
 
663
 
Line 646... Line 664...
646
	jmp	.no_drop
664
	jmp	.no_dup_syn
647
       @@:
665
       @@:
648
 
666
 
649
	and	[edx + TCP_segment.Flags], not (TH_URG)
667
	and	[edx + TCP_segment.Flags], not (TH_URG)
Line 650... Line 668...
650
	dec	eax
668
	dec	eax
Line 651... Line 669...
651
	jz	.no_duplicate
669
	jz	.no_duplicate
Line 826... Line 844...
826
 
844
 
Line 827... Line 845...
827
;;; Close the socket
845
;;; Close the socket
Line 828... Line -...
828
 
-
 
Line -... Line 846...
-
 
846
 
-
 
847
	jmp	.drop
Line 829... Line 848...
829
	jmp	.drop
848
 
830
 
849
 
Line 831... Line 850...
831
  .rst_skip:
850
 
Line 855... Line -...
855
 
-
 
856
 
874
 
857
 
875
 
Line 858... Line 876...
858
 
876
 
859
 
877
 
Line 874... Line 892...
874
 
892
 
875
	mov	eax, [edx + TCP_segment.AckNumber]
893
	mov	eax, [edx + TCP_segment.AckNumber]
876
	cmp	eax, [ebx + TCP_SOCKET.SND_UNA]
894
	cmp	eax, [ebx + TCP_SOCKET.SND_UNA]
Line 877... Line -...
877
	jg	.not_dup_ack
-
 
878
 
-
 
879
	DEBUGF	1,"Duplicate ACK\n"
895
	jg	.not_dup_ack
880
 
896
 
Line 881... Line 897...
881
	test	ecx, ecx
897
	test	ecx, ecx
882
	jnz	.ack_processed
898
	jnz	.reset_dupacks
883
 
899
 
-
 
900
	mov	eax, dword [edx + TCP_segment.Window]
-
 
901
	cmp	eax, [ebx + TCP_SOCKET.SND_WND]
-
 
902
	jne	.reset_dupacks
-
 
903
 
-
 
904
	DEBUGF	1,"Processing a duplicate ACK..\n"
-
 
905
 
-
 
906
	cmp	[ebx + TCP_SOCKET.timer_retransmission], 10000 ;;;;
-
 
907
	jg	@f
-
 
908
 
Line -... Line 909...
-
 
909
	mov	eax, [edx + TCP_segment.AckNumber]
-
 
910
	cmp	eax, [ebx + TCP_SOCKET.SND_UNA]
884
	mov	eax, dword [edx + TCP_segment.Window]
911
	je	.dup_ack
Line -... Line 912...
-
 
912
 
-
 
913
       @@:
-
 
914
	mov	[ebx + TCP_SOCKET.t_dupacks], 0
885
	cmp	eax, [ebx + TCP_SOCKET.SND_WND]
915
	jmp	.not_dup_ack
-
 
916
 
-
 
917
  .dup_ack:
-
 
918
	inc	[ebx + TCP_SOCKET.t_dupacks]
-
 
919
	cmp	[ebx + TCP_SOCKET.t_dupacks], TCP_re_xmit_thresh
-
 
920
	jne	.no_re_xmit
-
 
921
 
-
 
922
	push	[ebx + TCP_SOCKET.SND_NXT]		; >>>>
-
 
923
 
-
 
924
	mov	eax, [ebx + TCP_SOCKET.SND_WND]
-
 
925
	cmp	eax, [ebx + TCP_SOCKET.SND_CWND]
-
 
926
	cmovg	eax, [ebx + TCP_SOCKET.SND_CWND]
-
 
927
	shr	eax, 1
-
 
928
	push	edx
-
 
929
	xor	edx, edx
-
 
930
	div	[ebx + TCP_SOCKET.t_maxseg]
-
 
931
	cmp	eax, 2
-
 
932
	jge	@f
-
 
933
	mov	ax, 2
-
 
934
       @@:
-
 
935
	mul	[ebx + TCP_SOCKET.t_maxseg]
-
 
936
	pop	edx
-
 
937
	mov	[ebx + TCP_SOCKET.SND_SSTHRESH], eax
-
 
938
 
-
 
939
	mov	[ebx + TCP_SOCKET.timer_retransmission], 0	; turn off retransmission timer
-
 
940
	mov	[ebx + TCP_SOCKET.t_rtt], 0
-
 
941
	mov	eax, [edx + TCP_segment.AckNumber]
-
 
942
	mov	[ebx + TCP_SOCKET.SND_NXT], eax
-
 
943
	mov	eax, [ebx + TCP_SOCKET.t_maxseg]
-
 
944
	mov	[ebx + TCP_SOCKET.SND_CWND], eax
-
 
945
 
-
 
946
	mov	eax, ebx
-
 
947
	call	TCP_output					; retransmit missing segment
-
 
948
 
-
 
949
	push	edx
-
 
950
	xor	edx, edx
-
 
951
	mov	eax, [ebx + TCP_SOCKET.t_maxseg]
-
 
952
	mul	[ebx + TCP_SOCKET.t_dupacks]
-
 
953
	pop	edx
-
 
954
	add	eax, [ebx + TCP_SOCKET.SND_SSTHRESH]
-
 
955
	mov	[ebx + TCP_SOCKET.SND_CWND], eax
-
 
956
 
Line 886... Line -...
886
	jne	.ack_processed
-
 
887
 
957
	pop	eax					; <<<<
Line 888... Line -...
888
; Process the duplicate ACK
-
 
Line -... Line 958...
-
 
958
	cmp	eax, [ebx + TCP_SOCKET.SND_NXT]
-
 
959
	jl	@f
-
 
960
	mov	[ebx + TCP_SOCKET.SND_NXT], eax
889
 
961
       @@:
-
 
962
 
-
 
963
	jmp	.drop
-
 
964
 
-
 
965
 
-
 
966
  .no_re_xmit:
-
 
967
	jle	.not_dup_ack
-
 
968
 
-
 
969
	DEBUGF	1,"Increasing congestion window\n"
Line -... Line 970...
-
 
970
 
Line 890... Line 971...
890
	;;;;; 833 - 878
971
	mov	eax, [ebx + TCP_SOCKET.t_maxseg]
891
 
972
	add	[ebx + TCP_SOCKET.SND_CWND], eax
892
;;;        call    TCP_output
973
 
Line -... Line 974...
-
 
974
	mov	eax, ebx
-
 
975
	call	TCP_output
-
 
976
 
-
 
977
	jmp	.drop
-
 
978
 
-
 
979
 
-
 
980
 
-
 
981
 
-
 
982
 
-
 
983
 
-
 
984
  .not_dup_ack:
-
 
985
 
-
 
986
;-------------------------------------------------
-
 
987
; If the congestion window was inflated to account
893
	jmp	.drop
988
; for the other side's cached packets, retract it
-
 
989
 
-
 
990
	mov	eax, [ebx + TCP_SOCKET.SND_SSTHRESH]
-
 
991
	cmp	eax, [ebx + TCP_SOCKET.SND_CWND]
-
 
992
	jg	@f
-
 
993
	cmp	[ebx + TCP_SOCKET.t_dupacks], TCP_re_xmit_thresh
-
 
994
	jle	@f
Line -... Line 995...
-
 
995
	mov	[ebx + TCP_SOCKET.SND_CWND], eax
Line -... Line 996...
-
 
996
       @@:
-
 
997
 
Line 894... Line 998...
894
 
998
	mov	[ebx + TCP_SOCKET.t_dupacks], 0
895
  .not_dup_ack:
999
 
Line 896... Line 1000...
896
 
1000
	mov	eax, [edx + TCP_segment.AckNumber]
Line 897... Line 1001...
897
	DEBUGF	1,"new ACK\n"
1001
	cmp	eax, [ebx + TCP_SOCKET.SND_MAX]
Line 898... Line 1002...
898
 
1002
	jle	@f
899
 
1003
 
Line 935... Line 1039...
935
 
1039
 
936
 
1040
 
Line -... Line 1041...
-
 
1041
;-------------------------------------------
-
 
1042
; Open congestion window in response to ACKs
-
 
1043
 
-
 
1044
	mov	esi, [ebx + TCP_SOCKET.SND_CWND]
937
;-------------------------------------------
1045
	mov	eax, [ebx + TCP_SOCKET.t_maxseg]
-
 
1046
 
-
 
1047
	cmp	esi, [ebx + TCP_SOCKET.SND_SSTHRESH]
-
 
1048
	jle	@f
-
 
1049
	push	edx
-
 
1050
	push	eax
-
 
1051
	mul	eax
-
 
1052
	div	esi
-
 
1053
	pop	edx
-
 
1054
	shr	edx, 3
Line -... Line 1055...
-
 
1055
	add	eax, edx
-
 
1056
	pop	edx
-
 
1057
       @@:
-
 
1058
 
-
 
1059
	add	esi, eax
-
 
1060
 
-
 
1061
	push	ecx
-
 
1062
	mov	cl, [ebx + TCP_SOCKET.SND_SCALE]
-
 
1063
	mov	eax, TCP_max_win
-
 
1064
	shl	eax, cl
-
 
1065
	pop	ecx
Line 938... Line 1066...
938
; Open congestion window in response to ACKs
1066
 
939
 
1067
	cmp	esi, eax
Line 940... Line 1068...
940
	;;;;
1068
	cmovg	esi, eax
941
 
1069
	mov	[ebx + TCP_SOCKET.SND_CWND], esi
942
 
-
 
943
 
-
 
944
 
1070
 
945
 
1071
 
946
 
1072
 
-
 
1073
 
-
 
1074
 
Line 947... Line 1075...
947
 
1075
 
Line 948... Line 1076...
948
 
1076
 
949
;------------------------------------------
1077
;------------------------------------------
Line -... Line 1103...
-
 
1103
 
975
 
1104
 
976
 
1105
 
Line 977... Line 1106...
977
 
1106
 
978
 
1107
 
Line 1014... Line 1143...
1014
 
1143
 
Line -... Line 1144...
-
 
1144
	jmp	.ack_processed
Line 1015... Line 1145...
1015
	jmp	.ack_processed
1145
 
Line 1016... Line 1146...
1016
 
1146
 
Line 1017... Line 1147...
1017
 
1147