Subversion Repositories Kolibri OS

Rev

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

Rev 1530 Rev 1533
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: 1530 $
19
$Revision: 1533 $
20
 
20
 
21
; Socket states
21
; Socket states
22
TCB_CLOSED		equ 0
22
TCB_CLOSED		equ 0
Line 264... Line 264...
264
	pop	esi
264
	pop	esi
Line 265... Line 265...
265
 
265
 
Line -... Line 266...
-
 
266
}	; returns in dx only
-
 
267
 
-
 
268
 
-
 
269
macro	TCP_sendseqinit ptr {
-
 
270
 
-
 
271
	push	edi			;;;; i dont like this static use of edi
-
 
272
	mov	edi, [ptr + TCP_SOCKET.ISS]
-
 
273
	mov	[ptr + TCP_SOCKET.SND_UP], edi
-
 
274
	mov	[ptr + TCP_SOCKET.SND_MAX], edi
-
 
275
	mov	[ptr + TCP_SOCKET.SND_NXT], edi
-
 
276
	mov	[ptr + TCP_SOCKET.SND_UNA], edi
-
 
277
	pop	edi
-
 
278
 
-
 
279
}
-
 
280
 
-
 
281
macro	TCP_rcvseqinit ptr {
-
 
282
 
-
 
283
	push	edi
-
 
284
	mov	edi, [ptr + TCP_SOCKET.IRS]
-
 
285
	inc	edi
-
 
286
	mov	[ptr + TCP_SOCKET.RCV_NXT], edi
-
 
287
	mov	[ptr + TCP_SOCKET.RCV_ADV], edi
-
 
288
	pop	edi
-
 
289
 
Line 266... Line 290...
266
}	; returns in dx only
290
}
267
 
291
 
268
 
292
 
269
 
293
 
Line 418... Line 442...
418
	;;;; do something with eax
442
	;;;; do something with eax
Line 419... Line 443...
419
 
443
 
420
;-----------------------------------
444
;-----------------------------------
Line 421... Line 445...
421
; Is this socket a listening socket?
445
; Is this socket a listening socket?
422
 
446
 
Line 423... Line 447...
423
;        test    [ebx + SOCKET.options], SO_ACCEPTCON
447
	test	[ebx + SOCKET.options], SO_ACCEPTCON
424
;        jnz     .listening_socket                       ;;;;; TODO
448
;        jnz     .listening_socket                       ;;;;; TODO
Line 475... Line 499...
475
	test	[edx + TCP_segment.Flags], TH_SYN
499
	test	[edx + TCP_segment.Flags], TH_SYN
476
	jz	@f
500
	jz	@f
Line 477... Line 501...
477
 
501
 
478
	movzx	eax, word[edi+2]
502
	movzx	eax, word[edi+2]
479
	rol	ax, 8
503
	rol	ax, 8
Line 480... Line 504...
480
	DEBUGF	1,"Maxseg: %u", ax
504
	DEBUGF	1,"Maxseg: %u\n", ax
Line 481... Line 505...
481
 
505
 
482
	mov	[ebx + TCP_SOCKET.t_maxseg], eax
506
	mov	[ebx + TCP_SOCKET.t_maxseg], eax
Line 491... Line 515...
491
	jne	.no_options
515
	jne	.no_options
Line 492... Line 516...
492
 
516
 
493
	test	[edx + TCP_segment.Flags], TH_SYN
517
	test	[edx + TCP_segment.Flags], TH_SYN
Line 494... Line 518...
494
	jz	@f
518
	jz	@f
Line 495... Line 519...
495
 
519
 
496
	DEBUGF	1,"Got window option"
520
	DEBUGF	1,"Got window option\n"
497
 
521
 
498
	;;;;;
522
	;;;;;
Line 503... Line 527...
503
 
527
 
504
  .opt_timestamp:
528
  .opt_timestamp:
505
	cmp	byte [edi+1], 10
529
	cmp	byte [edi+1], 10
Line 506... Line 530...
506
	jne	.no_options
530
	jne	.no_options
Line 507... Line 531...
507
 
531
 
Line 508... Line 532...
508
	DEBUGF	1,"Got timestamp option"
532
	DEBUGF	1,"Got timestamp option\n"
509
 
533
 
Line 530... Line 554...
530
;      If the packets are in order (data queue is empty), add the data to the socket buffer and request a delayed ACK
554
;      If the packets are in order (data queue is empty), add the data to the socket buffer and request a delayed ACK
Line 531... Line 555...
531
 
555
 
532
	cmp	[ebx + TCP_SOCKET.t_state], TCB_ESTABLISHED
556
	cmp	[ebx + TCP_SOCKET.t_state], TCB_ESTABLISHED
Line -... Line 557...
-
 
557
	jnz	.not_uni_xfer
-
 
558
 
533
	jnz	.not_uni_xfer
559
	DEBUGF	1,"1\n"
534
 
560
 
Line -... Line 561...
-
 
561
	test	[edx + TCP_segment.Flags], TH_SYN + TH_FIN + TH_RST + TH_URG
-
 
562
	jnz	.not_uni_xfer
535
	test	[edx + TCP_segment.Flags], TH_SYN + TH_FIN + TH_RST + TH_URG
563
 
536
	jnz	.not_uni_xfer
564
	DEBUGF	1,"2\n"
Line -... Line 565...
-
 
565
 
-
 
566
	test	[edx + TCP_segment.Flags], TH_ACK
537
 
567
	jz	.not_uni_xfer
538
	test	[edx + TCP_segment.Flags], TH_ACK
568
 
539
	jz	.not_uni_xfer
569
	DEBUGF	1,"3\n"
Line -... Line 570...
-
 
570
 
-
 
571
	mov	eax, [edx + TCP_segment.SequenceNumber]
540
 
572
	cmp	eax, [ebx + TCP_SOCKET.RCV_NXT]
541
	mov	eax, [edx + TCP_segment.SequenceNumber]
573
	jne	.not_uni_xfer
542
	cmp	eax, [ebx + TCP_SOCKET.RCV_NXT]
574
 
-
 
575
	DEBUGF	1,"4\n"
-
 
576
 
Line 543... Line 577...
543
	jne	.not_uni_xfer
577
;;        movzx   eax, [edx + TCP_segment.Window] ;;;;; (should use pre-calculated value isntead: todo: figure out where to store it)
544
 
578
;;        cmp     eax, [ebx + TCP_SOCKET.SND_WND]
545
	movzx	eax, [edx + TCP_segment.Window] ;;;;; (should use pre-calculated value isntead: todo: figure out where to store it)
579
;;        jne     .not_uni_xfer
Line 582... Line 616...
582
; Update RTT estimators
616
; Update RTT estimators
Line 583... Line 617...
583
 
617
 
584
; Delete acknowledged bytes from send buffer
618
; Delete acknowledged bytes from send buffer
Line 585... Line 619...
585
; notice how ecx already holds number of bytes ack-ed
619
; notice how ecx already holds number of bytes ack-ed
586
 
620
 
Line 587... Line 621...
587
	lea	eax, [ebx + snd]
621
	lea	eax, [ebx + STREAM_SOCKET.snd]
588
	call	SOCKET_ring_free
622
	call	SOCKET_ring_free
Line 618... Line 652...
618
; Complete processing of received data
652
; Complete processing of received data
Line 619... Line 653...
619
 
653
 
Line 620... Line 654...
620
	DEBUGF	1,"header prediction: we are receiver\nreceiving %u bytes of data\n", ecx
654
	DEBUGF	1,"header prediction: we are receiver\nreceiving %u bytes of data\n", ecx
621
 
655
 
622
	add	esi, edx
656
	add	esi, edx
-
 
657
	lea	eax, [ebx + STREAM_SOCKET.rcv]
-
 
658
	call	SOCKET_ring_write			; Add the data to the socket buffer
-
 
659
 
Line 623... Line 660...
623
	lea	eax, [ebx + rcv]
660
	mov	eax, ebx
624
	call	SOCKET_ring_add 			; Add the data to the socket buffer
661
	call	SOCKET_notify_owner
Line 625... Line 662...
625
 
662
 
Line 631... Line 668...
631
;----------------------------------------------------
668
;----------------------------------------------------
632
; Header prediction failed, doing it the slow way..     ;;;;; current implementation of header prediction destroys some regs (ecx) !!
669
; Header prediction failed, doing it the slow way..     ;;;;; current implementation of header prediction destroys some regs (ecx) !!
Line 633... Line 670...
633
 
670
 
Line 634... Line 671...
634
  .not_uni_xfer:
671
  .not_uni_xfer:
Line 635... Line 672...
635
 
672
 
636
	DEBUGF	1,"Header prediction failed\n"
673
	DEBUGF	1,"Header prediction failed\n"		; time to do it the "slow" way :)
Line 637... Line 674...
637
 
674
 
Line 638... Line -...
638
;------------------------------
-
 
639
; Calculate receive window size
-
 
640
 
-
 
641
	;;;;
-
 
642
 
-
 
643
;-------------------------
675
;------------------------------
644
; TCP slow input procedure
676
; Calculate receive window size
Line 645... Line 677...
645
 
677
 
646
	DEBUGF	1,"TCP slow input procedure\n"
678
	;;;;
Line 647... Line 679...
647
 
679
 
648
	cmp	[ebx + TCP_SOCKET.t_state], TCB_LISTEN
680
	cmp	[ebx + TCP_SOCKET.t_state], TCB_LISTEN
Line 649... Line 681...
649
	je	.LISTEN
681
	je	.LISTEN
Line 650... Line 682...
650
 
682
 
Line 651... Line 683...
651
	cmp	[ebx + TCP_SOCKET.t_state], TCB_SYN_SENT
683
	cmp	[ebx + TCP_SOCKET.t_state], TCB_SYN_SENT
Line 679... Line 711...
679
	jnz	.drop_with_reset
711
	jnz	.drop_with_reset
Line 680... Line 712...
680
 
712
 
681
	test	[edx + TCP_segment.Flags], TH_SYN
713
	test	[edx + TCP_segment.Flags], TH_SYN
Line 682... Line 714...
682
	jz	.drop
714
	jz	.drop
-
 
715
 
-
 
716
	cmp	esi, 0xffffff		; destination ip = 255.255.255.255 ?
683
 
717
	jz	.drop
Line 684... Line 718...
684
	; TODO: find sender ip address somewhere!
718
 
685
	; TODO: check if it's a broadcast or multicast, and drop if so
719
	; TODO: check if it's a broadcast or multicast, and drop if so
Line 704... Line 738...
704
	mov	[eax + TCP_SOCKET.t_state], TCB_SYN_RECEIVED
738
	mov	[eax + TCP_SOCKET.t_state], TCB_SYN_RECEIVED
705
	mov	[eax + TCP_SOCKET.t_flags], TF_ACKNOW
739
	mov	[eax + TCP_SOCKET.t_flags], TF_ACKNOW
706
	mov	[eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval
740
	mov	[eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval
Line 707... Line 741...
707
 
741
 
708
	mov	ebx, eax
-
 
709
 
742
	mov	ebx, eax
Line 710... Line 743...
710
	jmp	.trim_then_step6
743
	jmp	.trim_then_step6
711
 
744
 
Line 723... Line 756...
723
 
756
 
724
	mov	eax, [edx + TCP_segment.AckNumber]
757
	mov	eax, [edx + TCP_segment.AckNumber]
725
	cmp	eax, [ebx + TCP_SOCKET.ISS]
758
	cmp	eax, [ebx + TCP_SOCKET.ISS]
Line 726... Line -...
726
	jle	.drop_with_reset
-
 
727
 
-
 
728
	DEBUGF	1,"snd_max = %x\n", [ebx + TCP_SOCKET.SND_MAX]	 ;;; TODO: set this, but where?
759
	jle	.drop_with_reset
729
 
760
 
730
;        mov     eax, [edx + TCP_segment.AckNumber]
761
;        mov     eax, [edx + TCP_segment.AckNumber]
731
;;        cmp     eax, [ebx + TCP_SOCKET.SND_MAX]
762
	cmp	eax, [ebx + TCP_SOCKET.SND_MAX]
Line 732... Line 763...
732
;;        jg      .drop_with_reset
763
	jg	.drop_with_reset
733
       @@:
764
       @@:
Line 765... Line 796...
765
	mov	[ebx + TCP_SOCKET.timer_retransmission], 0	; disable retransmission
796
	mov	[ebx + TCP_SOCKET.timer_retransmission], 0	; disable retransmission
Line 766... Line 797...
766
 
797
 
767
	push	[edx + TCP_segment.SequenceNumber]
798
	push	[edx + TCP_segment.SequenceNumber]
Line 768... Line 799...
768
	pop	[ebx + TCP_SOCKET.IRS]
799
	pop	[ebx + TCP_SOCKET.IRS]
Line 769... Line 800...
769
 
800
 
Line 770... Line 801...
770
;;; TODO: tcp_rcvseqinit
801
	TCP_rcvseqinit ebx
771
 
802
 
Line 779... Line 810...
779
	jz	.simultaneous_open
810
	jz	.simultaneous_open
Line 780... Line 811...
780
 
811
 
Line 781... Line 812...
781
	DEBUGF	1,"TCP: active open\n"
812
	DEBUGF	1,"TCP: active open\n"
782
 
813
 
Line 783... Line 814...
783
; TODO: update stats
814
; TODO: update stats
Line 784... Line 815...
784
; TODO: set socket state to connected
815
; TODO: set general socket state to connected
785
 
816
 
Line 819... Line 850...
819
 
850
 
Line 820... Line -...
820
 
-
 
821
 
-
 
822
  .trim_then_step6:
851
 
823
 
852
 
Line -... Line 853...
-
 
853
  .trim_then_step6:
-
 
854
 
824
	DEBUGF	1,"Trimming window\n"
855
;----------------------------
825
 
856
; trim any data not in window
Line 826... Line 857...
826
;----------------------------
857
 
827
; trim any data not in window
858
	DEBUGF	1,"Trimming window\n"
Line 828... Line 859...
828
 
859
 
829
	mov	eax, [ebx + TCP_SOCKET.RCV_NXT]
860
	mov	eax, [ebx + TCP_SOCKET.RCV_NXT]
Line 830... Line 861...
830
	sub	eax, [edx + TCP_segment.SequenceNumber]
861
	sub	eax, [edx + TCP_segment.SequenceNumber]
Line 846... Line 877...
846
	jmp	.no_drop
877
	jmp	.no_drop
847
       @@:
878
       @@:
Line 848... Line 879...
848
 
879
 
849
	and	[edx + TCP_segment.Flags], not (TH_URG)
880
	and	[edx + TCP_segment.Flags], not (TH_URG)
850
	dec	eax
-
 
-
 
881
	dec	eax
851
 
882
	jz	.no_duplicate
Line 852... Line 883...
852
  .no_drop:
883
  .no_drop:
Line 853... Line 884...
853
 
884
 
Line 854... Line 885...
854
	DEBUGF	1,"Going to drop %u bytes of data", eax
885
	DEBUGF	1,"Going to drop %u out of %u bytes\n", eax, ecx
855
 
886
 
Line 893... Line 924...
893
	cmp	[edx + TCP_segment.Flags], TH_ACK
924
	cmp	[edx + TCP_segment.Flags], TH_ACK
894
	jz	.drop_after_ack
925
	jz	.drop_after_ack
Line 895... Line 926...
895
 
926
 
Line 896... Line 927...
896
  .duplicate:
927
  .duplicate:
Line 897... Line 928...
897
 
928
 
898
	DEBUGF	1,"Duplicate received"
929
	DEBUGF	1,"Duplicate received\n"
Line 899... Line 930...
899
 
930
 
Line 922... Line 953...
922
 
953
 
923
;--------------------------------------------------
954
;--------------------------------------------------
Line 924... Line 955...
924
; Handle data that arrives after process terminates
955
; Handle data that arrives after process terminates
925
 
956
 
Line 926... Line 957...
926
	cmp	[ebx + SOCKET.PID], 0
957
	cmp	[ebx + SOCKET.PID], 0
927
	jge	@f
958
	jg	@f
Line 928... Line 959...
928
 
959
 
Line 934... Line 965...
934
 
965
 
935
	;;; Close the socket
966
	;;; Close the socket
Line 936... Line 967...
936
	;;; update stats
967
	;;; update stats
937
 
-
 
938
	jmp	.drop_with_reset
968
 
Line 939... Line 969...
939
 
969
	jmp	.drop_with_reset
940
       @@:
970
       @@:
Line 1037... Line 1067...
1037
 
1067
 
1038
	cmp	[ebx + TCP_SOCKET.t_state], TCB_SYN_RECEIVED
1068
	cmp	[ebx + TCP_SOCKET.t_state], TCB_SYN_RECEIVED
1039
	jg	.ack_dup
1069
	jg	.ack_dup
Line -... Line 1070...
-
 
1070
	jl	.ack_nodup
-
 
1071
 
1040
	jl	.ack_nodup
1072
	DEBUGF	1,"TCP state = syn received"
Line 1041... Line 1073...
1041
 
1073
 
Line -... Line 1074...
-
 
1074
	;;;;;
-
 
1075
 
1042
	;;;;;
1076
  .ack_dup:
Line 1043... Line 1077...
1043
 
1077
 
Line 1044... Line 1078...
1044
  .ack_dup:
1078
	DEBUGF	1,"Duplicate ACK"
Line -... Line 1079...
-
 
1079
 
-
 
1080
	;;;;
1045
 
1081
 
1046
	;;;;
1082
  .ack_nodup:
1047
 
1083
 
Line 1048... Line 1084...
1048
  .ack_nodup:
1084
	;;;; 887
Line 1067... Line 1103...
1067
	cmp	eax, [edx + TCP_segment.AckNumber]
1103
	cmp	eax, [edx + TCP_segment.AckNumber]
1068
	je	.all_outstanding
1104
	je	.all_outstanding
1069
	mov	[ebx + TCP_SOCKET.timer_retransmission], 120 ;;;; TODO: correct this value
1105
	mov	[ebx + TCP_SOCKET.timer_retransmission], 120 ;;;; TODO: correct this value
1070
  .all_outstanding:
1106
  .all_outstanding:
Line 1071... Line -...
1071
 
-
 
1072
 
1107
 
1073
;-------------------------------------------
1108
;-------------------------------------------
Line 1074... Line 1109...
1074
; Open congestion window in response to ACKs
1109
; Open congestion window in response to ACKs
Line 1075... Line 1110...
1075
 
1110
 
1076
	;;;;
1111
	;;;;
Line 1077... Line 1112...
1077
 
1112
 
1078
 
1113
 
1079
;------------------------------------------
1114
;------------------------------------------
Line 1080... Line 1115...
1080
; Remove acknowledged data from send buffer
1115
; Remove acknowledged data from send buffer
1081
 
1116
 
Line 1082... Line 1117...
1082
	lea	eax, [ebx + snd]
1117
	xor	ecx, ecx	;;;;;;
Line 1194... Line 1229...
1194
; Ignore bogus urgent offsets
1229
; Ignore bogus urgent offsets
Line 1195... Line 1230...
1195
 
1230
 
Line 1196... Line 1231...
1196
	;;; 1040-1050
1231
	;;; 1040-1050
1197
 
1232
 
1198
	movzx	eax, [edx + TCP_segment.UrgentPointer]
1233
	movzx	eax, [edx + TCP_segment.UrgentPointer]
1199
	add	eax, [ebx + rcv.size]
1234
	add	eax, [ebx + STREAM_SOCKET.rcv + RING_BUFFER.size]
Line 1200... Line 1235...
1200
	cmp	eax, SOCKET_MAXDATA
1235
	cmp	eax, SOCKET_MAXDATA
1201
	jle	.not_urgent
1236
	jle	.not_urgent
Line 1214... Line 1249...
1214
;--------------------------------
1249
;--------------------------------
1215
; process the data in the segment
1250
; process the data in the segment
Line 1216... Line 1251...
1216
 
1251
 
Line 1217... Line 1252...
1217
  .do_data:
1252
  .do_data:
Line 1218... Line 1253...
1218
 
1253
 
1219
	DEBUGF	1,"TCP: do data:\n"
1254
	DEBUGF	1,"TCP: do data\n"
Line 1220... Line 1255...
1220
 
1255
 
1221
	test	[edx + TCP_segment.Flags], TH_FIN
1256
	test	[edx + TCP_segment.Flags], TH_FIN
Line -... Line 1257...
-
 
1257
	jnz	.process_fin
-
 
1258
 
-
 
1259
	cmp	[ebx + TCP_SOCKET.t_state], TCB_FIN_WAIT_1
1222
	jnz	.process_fin
1260
	jge	.dont_do_data
Line -... Line 1261...
-
 
1261
 
-
 
1262
	test	ecx, ecx
-
 
1263
	jz	.final_processing
-
 
1264
 
-
 
1265
	DEBUGF	1,"Processing data in segment\n"
-
 
1266
 
1223
 
1267
;; TODO: check if data is in sequence !
-
 
1268
 
-
 
1269
	movzx	eax, [edx + TCP_segment.DataOffset]		;;; todo: remember this in.. edi ?
-
 
1270
	and	eax, 0xf0
-
 
1271
	shr	al, 2
-
 
1272
 
-
 
1273
	lea	esi, [edx + eax]
-
 
1274
 
-
 
1275
	or	[ebx + TCP_SOCKET.t_flags], TF_DELACK
-
 
1276
	add	[ebx + TCP_SOCKET.RCV_NXT], ecx 	 ;;; right ?
Line 1224... Line 1277...
1224
	test	[ebx + TCP_SOCKET.t_state], TCB_FIN_WAIT_1
1277
 
Line 1225... Line 1278...
1225
	jge	.dont_do_data
1278
	lea	eax, [ebx + STREAM_SOCKET.rcv]
Line 1246... Line 1299...
1246
 
1299
 
1247
  .FIN_sw_list:
1300
  .FIN_sw_list:
1248
	dd	.no_fin 	;TCB_CLOSED
1301
	dd	.no_fin 	;TCB_CLOSED
1249
	dd	.no_fin 	;TCB_LISTEN
1302
	dd	.no_fin 	;TCB_LISTEN
1250
	dd	.no_fin 	;TCB_SYN_SENT
1303
	dd	.no_fin 	;TCB_SYN_SENT
1251
	dd	._1131		;TCB_SYN_RECEIVED
1304
	dd	.fin_syn_est	;TCB_SYN_RECEIVED
1252
	dd	._1131		;TCB_ESTABLISHED
1305
	dd	.fin_syn_est	;TCB_ESTABLISHED
1253
	dd	.no_fin 	;TCB_CLOSE_WAIT
1306
	dd	.no_fin 	;TCB_CLOSE_WAIT
1254
	dd	._1139		;TCB_FIN_WAIT_1
1307
	dd	.fin_wait1	;TCB_FIN_WAIT_1
1255
	dd	.no_fin 	;TCB_CLOSING
1308
	dd	.no_fin 	;TCB_CLOSING
1256
	dd	.no_fin 	;TCB_LAST_ACK
1309
	dd	.no_fin 	;TCB_LAST_ACK
1257
	dd	._1147		;TCB_FIN_WAIT_2
1310
	dd	.fin_wait2	;TCB_FIN_WAIT_2
-
 
1311
	dd	.fin_timed	;TCB_TIMED_WAIT
-
 
1312
 
Line -... Line 1313...
-
 
1313
 
Line -... Line 1314...
-
 
1314
 
-
 
1315
  .fin_syn_est:
-
 
1316
 
Line 1258... Line 1317...
1258
	dd	._1156		;TCB_TIMED_WAIT
1317
	jmp	.final_processing
Line 1259... Line 1318...
1259
 
1318
 
Line 1260... Line 1319...
1260
 
1319
  .fin_wait1:
Line 1261... Line 1320...
1261
 
1320
 
Line -... Line 1321...
-
 
1321
	jmp	.final_processing
Line 1262... Line 1322...
1262
  ._1131:
1322
 
Line 1263... Line 1323...
1263
 
1323
  .fin_wait2:
1264
  ._1139:
1324
 
Line 1265... Line 1325...
1265
 
1325
	jmp	.final_processing
Line 1266... Line 1326...
1266
  ._1147:
1326
 
Line -... Line 1327...
-
 
1327
  .fin_timed:
-
 
1328
 
1267
 
1329
	jmp	.final_processing
Line 1268... Line 1330...
1268
  ._1156:
1330
 
1269
 
1331
  .no_fin:
Line 1270... Line 1332...
1270
 
1332
 
1271
  .no_fin:
1333
;-----------------
Line 1272... Line -...
1272
 
-
 
1273
;-----------------
1334
; Final processing
1274
; Final processing
1335
 
1275
 
1336
  .final_processing:
Line 1276... Line 1337...
1276
  .final_processing:
1337
 
Line 1297... Line 1358...
1297
	push	ebx
1358
	push	ebx
1298
	mov	eax, ebx
1359
	mov	eax, ebx
1299
	call	TCP_output
1360
	call	TCP_output
1300
	pop	ebx
1361
	pop	ebx
Line 1301... Line -...
1301
 
-
 
1302
	mov	[ebx + SOCKET.lock], 0
1362
 
1303
	call	kernel_free
1363
	call	kernel_free
1304
	add	esp, 4
1364
	add	esp, 4
Line 1305... Line 1365...
1305
	ret
1365
	ret
Line 1320... Line 1380...
1320
	push	ebx
1380
	push	ebx
1321
	mov	eax, ebx
1381
	mov	eax, ebx
1322
	call	TCP_output
1382
	call	TCP_output
1323
	pop	ebx
1383
	pop	ebx
Line 1324... Line -...
1324
 
-
 
1325
	mov	[ebx + SOCKET.lock], 0
1384
 
1326
	call	kernel_free
1385
	call	kernel_free
1327
	add	esp, 4
1386
	add	esp, 4
Line 1345... Line 1404...
1345
	jnz	.respond_ack
1404
	jnz	.respond_ack
Line 1346... Line 1405...
1346
 
1405
 
1347
	test	[edx + TCP_segment.Flags], TH_SYN
1406
	test	[edx + TCP_segment.Flags], TH_SYN
Line 1348... Line -...
1348
	jnz	.respond_syn
-
 
1349
 
1407
	jnz	.respond_syn
1350
	mov	[ebx + SOCKET.lock], 0
1408
 
1351
	call	kernel_free
1409
	call	kernel_free
Line 1352... Line 1410...
1352
	add	esp, 4
1410
	add	esp, 4
Line 1353... Line 1411...
1353
	ret
1411
	ret
Line -... Line 1412...
-
 
1412
 
1354
 
1413
  .respond_ack:
-
 
1414
 
Line 1355... Line 1415...
1355
  .respond_ack:
1415
	mov	dl, TH_RST
Line 1356... Line 1416...
1356
 
1416
 
Line 1357... Line 1417...
1357
	;;;;
1417
	push	ebx
Line -... Line 1418...
-
 
1418
	call	TCP_respond_segment
1358
 
1419
	pop	ebx
-
 
1420
 
Line 1359... Line 1421...
1359
	call	TCP_respond_segment
1421
	jmp	.destroy_new_socket
Line 1360... Line 1422...
1360
 
1422
 
1361
	jmp	.destroy_new_socket
1423
 
Line 1381... Line 1443...
1381
 
1443
 
Line 1382... Line 1444...
1382
  .destroy_new_socket:
1444
  .destroy_new_socket:
Line 1383... Line -...
1383
 
-
 
1384
	;;;; kill the newly created socket
1445
 
1385
 
1446
	;;;; kill the newly created socket
1386
	mov	[ebx + SOCKET.lock], 0
1447
 
Line 1471... Line 1532...
1471
	jz	.no_persist_timeout
1532
	jz	.no_persist_timeout
Line 1472... Line 1533...
1472
 
1533
 
1473
	test	ecx, ecx
1534
	test	ecx, ecx
Line 1474... Line 1535...
1474
	jnz	.no_zero_window
1535
	jnz	.no_zero_window
1475
 
1536
 
Line 1476... Line 1537...
1476
	cmp	ebx, [eax + snd.size]
1537
	cmp	ebx, [eax + STREAM_SOCKET.snd + RING_BUFFER.size]
Line 1477... Line 1538...
1477
	jge	@f
1538
	jge	@f
Line 1489... Line 1550...
1489
 
1550
 
Line 1490... Line 1551...
1490
  .no_persist_timeout:
1551
  .no_persist_timeout:
Line 1491... Line 1552...
1491
 
1552
 
1492
;;;106
1553
;;;106
1493
 
1554
 
1494
	mov	esi, [eax + snd.size]
1555
	mov	esi, [eax + STREAM_SOCKET.snd + RING_BUFFER.size]
1495
	cmp	esi, ecx
1556
	cmp	esi, ecx
1496
	jl	@f
1557
	jl	@f
Line 1534... Line 1595...
1534
;;; 128
1595
;;; 128
Line 1535... Line 1596...
1535
 
1596
 
1536
	mov	edi, [eax + TCP_SOCKET.SND_NXT]
1597
	mov	edi, [eax + TCP_SOCKET.SND_NXT]
1537
	add	edi, esi	; len
1598
	add	edi, esi	; len
1538
	sub	edi, [eax + TCP_SOCKET.SND_UNA]
1599
	sub	edi, [eax + TCP_SOCKET.SND_UNA]
1539
	add	edi, [eax + snd.size]
1600
	add	edi, [eax + STREAM_SOCKET.snd + RING_BUFFER.size]
1540
	cmp	edi, 0
1601
	cmp	edi, 0
Line 1541... Line 1602...
1541
	jle	@f
1602
	jle	@f
Line 1547... Line 1608...
1547
 
1608
 
1548
; set ecx to space available in receive buffer
1609
; set ecx to space available in receive buffer
Line 1549... Line 1610...
1549
; From now on, ecx will be the window we advertise to the other end
1610
; From now on, ecx will be the window we advertise to the other end
1550
 
1611
 
Line 1551... Line 1612...
1551
	mov	ecx, SOCKET_MAXDATA
1612
	mov	ecx, SOCKET_MAXDATA
1552
	sub	ecx, [eax + rcv.size]
1613
	sub	ecx, [eax + STREAM_SOCKET.rcv + RING_BUFFER.size]
Line 1553... Line 1614...
1553
 
1614
 
Line 1704... Line 1765...
1704
	; edx = flags
1765
	; edx = flags
1705
	; ecx = data size
1766
	; ecx = data size
1706
	; edi = header size
1767
	; edi = header size
1707
	; esi = snd ring buff ptr
1768
	; esi = snd ring buff ptr
Line -... Line 1769...
-
 
1769
 
-
 
1770
	mov	ecx, [eax + STREAM_SOCKET.snd + RING_BUFFER.size]
-
 
1771
	cmp	ecx, [eax + TCP_SOCKET.t_maxseg]			;;; right?
1708
 
1772
	jle	@f
-
 
1773
	mov	ecx, [eax + TCP_SOCKET.t_maxseg]
1709
	xor	ecx, ecx	;;;;;
1774
       @@:
Line 1710... Line 1775...
1710
	add	ecx, edi	; total TCP segment size
1775
	add	ecx, edi	; total TCP segment size
1711
 
1776
 
Line 1736... Line 1801...
1736
	push	edi	; header size
1801
	push	edi		; header size
Line 1737... Line 1802...
1737
 
1802
 
1738
; Create the IP packet
1803
; Create the IP packet
1739
	mov	ebx, [eax + IP_SOCKET.LocalIP]	; source ip
1804
	mov	ebx, [eax + IP_SOCKET.LocalIP]	; source ip
1740
	mov	eax, [eax + IP_SOCKET.RemoteIP] ; dest ip
-
 
1741
;        mov     ecx,                            ; data length
-
 
1742
;        mov     dx,                             ; fragment id
1805
	mov	eax, [eax + IP_SOCKET.RemoteIP] ; dest ip
1743
	mov	di, IP_PROTO_TCP shl 8 + 128
1806
	mov	di, IP_PROTO_TCP shl 8 + 128
1744
	call	IPv4_output
1807
	call	IPv4_output
Line 1745... Line 1808...
1745
	jz	.fail
1808
	jz	.fail
1746
 
1809
 
Line 1747... Line -...
1747
;-----------------------------------------
-
 
1748
; Move TCP header from stack to TCP packet
-
 
1749
 
-
 
1750
;        pop     ecx                     ; header size
1810
;-----------------------------------------
1751
;        mov     esi, esp
-
 
1752
;        add     esp, ecx
-
 
1753
;        shr     ecx, 2
1811
; Move TCP header from stack to TCP packet
1754
;        rep     movsd
1812
 
1755
 
1813
	push	ecx
1756
	mov	ecx, [esp]
1814
	mov	ecx, [esp+4]
-
 
1815
	lea	esi, [esp+4+4]
Line 1757... Line 1816...
1757
	lea	esi, [esp+4]
1816
	shr	ecx, 2
1758
	shr	ecx, 2
1817
	rep	movsd
Line 1759... Line -...
1759
	rep	movsd
-
 
1760
 
1818
	pop	ecx		; full TCP packet size
-
 
1819
 
Line 1761... Line 1820...
1761
	pop	ecx
1820
	pop	esi		; headersize
-
 
1821
	add	esp, esi
1762
	add	esp, ecx
1822
 
-
 
1823
	mov	[esp + 4], eax		; packet ptr
Line 1763... Line 1824...
1763
 
1824
	mov	[esp + 4+4], edx	; packet size
1764
	mov	[esp + 4+4], edx	; packet size
1825
 
Line 1765... Line 1826...
1765
	mov	[esp + 4], eax		; packet ptr
1826
	mov	edx, edi		; begin of data
1766
 
1827
	sub	edx, esi		; begin of packet (edi = begin of data)
1767
	mov	edx, edi
1828
	push	ecx
Line 1768... Line 1829...
1768
	sub	edx, ecx
1829
	sub	ecx, esi		; data size
1769
 
1830
 
1770
;--------------
1831
;--------------
1771
; Copy the data
1832
; Copy the data
1772
 
1833
 
1773
; eax = ptr to ring struct
1834
; eax = ptr to ring struct
Line -... Line 1835...
-
 
1835
; ecx = buffer size
-
 
1836
; edi = ptr to buffer
-
 
1837
 
-
 
1838
	mov	eax, [esp+4]		  ; socket ptr
-
 
1839
	push	edx
-
 
1840
	add	eax, STREAM_SOCKET.snd
-
 
1841
	call	SOCKET_ring_read
-
 
1842
	pop	esi ecx
-
 
1843
	pop	eax
-
 
1844
 
-
 
1845
	test	[esi + TCP_segment.Flags], TH_SYN + TH_FIN
-
 
1846
	jz	@f
-
 
1847
	inc	[eax + TCP_SOCKET.SND_NXT]
-
 
1848
	;;; TODO: update sentfin flag
-
 
1849
       @@:
-
 
1850
 
-
 
1851
;;        add     [eax + TCP_SOCKET.SND_NXT], ecx
-
 
1852
 
1774
; ecx = buffer size
1853
	mov	edx, [eax + TCP_SOCKET.SND_NXT]
1775
; edi = ptr to buffer
1854
	cmp	edx, [eax + TCP_SOCKET.SND_MAX]
Line 1776... Line 1855...
1776
 
1855
	jle	@f
Line 1777... Line 1856...
1777
	mov	eax, [esp]		; socket ptr
1856
	mov	[eax + TCP_SOCKET.SND_MAX], edx
1778
	push	ecx edx
1857
 
Line 1967... Line 2046...
1967
	mov	ebx, [edx - 20 + IPv4_Packet.SourceAddress]	 ;;;; and what if ip packet had options?!
2046
	mov	ebx, [edx - 20 + IPv4_Packet.SourceAddress]	 ;;;; and what if ip packet had options?!
1968
	mov	eax, [edx - 20 + IPv4_Packet.DestinationAddress]   ;;;
2047
	mov	eax, [edx - 20 + IPv4_Packet.DestinationAddress]   ;;;
1969
	mov	ecx, TCP_segment.Data
2048
	mov	ecx, TCP_segment.Data
1970
	mov	di , IP_PROTO_TCP shl 8 + 128
2049
	mov	di , IP_PROTO_TCP shl 8 + 128
1971
	call	IPv4_output
2050
	call	IPv4_output
1972
	test	edi, edi
-
 
1973
	jz	.error
2051
	jz	.error
1974
 
-
 
1975
	pop	esi cx
2052
	pop	esi cx
-
 
2053
 
1976
	push	edx eax
2054
	push	edx eax
Line 1977... Line 2055...
1977
 
2055
 
1978
;---------------------------------------------------
2056
;---------------------------------------------------