Subversion Repositories Kolibri OS

Rev

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

Rev 1542 Rev 1543
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: 1542 $
19
$Revision: 1543 $
20
 
20
 
21
; Socket states
21
; Socket states
22
TCB_CLOSED		equ 0
22
TCB_CLOSED		equ 0
Line 354... Line 354...
354
  .no_timestamp:
354
  .no_timestamp:
Line 355... Line 355...
355
 
355
 
356
;-------------------------------------------
356
;-------------------------------------------
Line 357... Line 357...
357
; Convert Big-endian values to little endian
357
; Convert Big-endian values to little endian
358
 
358
 
Line 359... Line 359...
359
	ntohld	[edx + TCP_segment.SequenceNumber]
359
	ntohd	[edx + TCP_segment.SequenceNumber]
360
	ntohld	[edx + TCP_segment.AckNumber]
360
	ntohd	[edx + TCP_segment.AckNumber]
361
 
361
 
362
	ntohlw	[edx + TCP_segment.Window]
362
	ntohw	[edx + TCP_segment.Window]
Line 363... Line 363...
363
	ntohlw	[edx + TCP_segment.UrgentPointer]
363
	ntohw	[edx + TCP_segment.UrgentPointer]
364
	ntohlw	[edx + TCP_segment.SourcePort]
364
	ntohw	[edx + TCP_segment.SourcePort]
Line 365... Line 365...
365
	ntohlw	[edx + TCP_segment.DestinationPort]
365
	ntohw	[edx + TCP_segment.DestinationPort]
Line 376... Line 376...
376
  .socket_loop:
376
  .socket_loop:
377
	mov	ebx, [ebx + SOCKET.NextPtr]
377
	mov	ebx, [ebx + SOCKET.NextPtr]
378
	or	ebx, ebx
378
	or	ebx, ebx
379
	jz	.drop_with_reset
379
	jz	.drop_with_reset
Line -... Line 380...
-
 
380
 
-
 
381
	cmp	[ebx + SOCKET.Domain], AF_INET4
-
 
382
	jne	.socket_loop
380
 
383
 
381
	cmp	[ebx + SOCKET.Protocol], IP_PROTO_TCP	  ;;; We should also check if family is AF_INET
384
	cmp	[ebx + SOCKET.Protocol], IP_PROTO_TCP
Line 382... Line 385...
382
	jne	.socket_loop
385
	jne	.socket_loop
383
 
386
 
384
	mov	ax, [edx + TCP_segment.DestinationPort]
387
	mov	ax, [edx + TCP_segment.DestinationPort]
Line 385... Line 388...
385
	cmp	[ebx + TCP_SOCKET.LocalPort], ax
388
	cmp	[ebx + TCP_SOCKET.LocalPort], ax
386
	jne	.socket_loop
389
	jne	.socket_loop
387
 
390
 
388
	mov	eax, [ebx + IP_SOCKET.RemoteIP]
391
	mov	eax, [ebx + IP_SOCKET.RemoteIP]
389
	cmp	eax, edi			; sender IP
392
	cmp	eax, edi			; edi is source ip from packet
390
	je	@f
393
	je	@f
Line 415... Line 418...
415
;;        call    wait_mutex
418
;;        call    wait_mutex
416
;;        sub     ebx, SOCKET.lock
419
;;        sub     ebx, SOCKET.lock
Line 417... Line 420...
417
 
420
 
Line 418... Line 421...
418
	DEBUGF	1,"Socket locked\n"
421
	DEBUGF	1,"Socket locked\n"
419
 
422
 
Line 420... Line 423...
420
;----------------------------------------------------------------------------------------
423
;---------------------------------------
421
; unscale the window into a 32 bit value (notice that SND_SCALE must be initialised to 0)
424
; unscale the window into a 32 bit value
422
 
425
 
423
	movzx	eax, [edx + TCP_segment.Window]
426
	movzx	eax, [edx + TCP_segment.Window]
-
 
427
	push	ecx
424
	push	ecx
428
	mov	cl, [ebx + TCP_SOCKET.SND_SCALE]
Line 425... Line -...
425
	mov	cl, [ebx + TCP_SOCKET.SND_SCALE]
-
 
426
	shl	eax, cl
-
 
427
	pop	ecx
429
	shl	eax, cl
428
 
430
	mov	dword [edx + TCP_segment.Window], eax	; word after window is checksum, we dont need checksum anymore
Line 429... Line 431...
429
	;;;; do something with eax
431
	pop	ecx
-
 
432
 
-
 
433
;-----------------------------------
-
 
434
; Is this socket a listening socket?
-
 
435
 
-
 
436
	test	[ebx + SOCKET.options], SO_ACCEPTCON
-
 
437
	jz	.no_listening_socket
-
 
438
 
-
 
439
	call	SOCKET_fork
-
 
440
	jz	.drop
-
 
441
 
-
 
442
	push	[edx + TCP_segment.DestinationPort]
430
 
443
	pop	[eax + TCP_SOCKET.LocalPort]
-
 
444
 
-
 
445
	push	[edx - IPv4_Packet.DataOrOptional + IPv4_Packet.DestinationAddress]	;;; FIXME
-
 
446
	pop	[eax + IP_SOCKET.LocalIP]
-
 
447
 
-
 
448
	push	[edx - IPv4_Packet.DataOrOptional + IPv4_Packet.SourceAddress]	   ;;; FIXME
-
 
449
	pop	[eax + IP_SOCKET.RemoteIP]
-
 
450
 
Line 431... Line 451...
431
;-----------------------------------
451
	mov	[eax + TCP_SOCKET.t_state], TCB_LISTEN
432
; Is this socket a listening socket?
452
 
Line 433... Line 453...
433
 
453
	jmp	.not_uni_xfer
Line 447... Line 467...
447
	je	.no_options
467
	je	.no_options
Line 448... Line 468...
448
 
468
 
Line 449... Line 469...
449
	DEBUGF	1,"Segment has options\n"
469
	DEBUGF	1,"Segment has options\n"
450
 
470
 
Line 451... Line 471...
451
	cmp	[ebx + TCP_SOCKET.t_state], TCB_LISTEN		; no options when in listen state
471
	cmp	[ebx + TCP_SOCKET.t_state], TCB_LISTEN		; no options when in listen state
452
	jz	.no_options
472
	jz	.not_uni_xfer					; also no header prediction
Line 453... Line 473...
453
 
473
 
Line 551... Line 571...
551
 
571
 
552
	mov	eax, [edx + TCP_segment.SequenceNumber]
572
	mov	eax, [edx + TCP_segment.SequenceNumber]
553
	cmp	eax, [ebx + TCP_SOCKET.RCV_NXT]
573
	cmp	eax, [ebx + TCP_SOCKET.RCV_NXT]
Line 554... Line 574...
554
	jne	.not_uni_xfer
574
	jne	.not_uni_xfer
555
 
575
 
556
	movzx	eax, [edx + TCP_segment.Window] ;;;;; (should use pre-calculated value instead: todo: figure out where to store it)
576
	mov	eax, dword [edx + TCP_segment.Window]
Line 557... Line 577...
557
	cmp	eax, [ebx + TCP_SOCKET.SND_WND]
577
	cmp	eax, [ebx + TCP_SOCKET.SND_WND]
558
	jne	.not_uni_xfer
578
	jne	.not_uni_xfer
Line 685... Line 705...
685
align 4
705
align 4
686
.LISTEN:
706
.LISTEN:
Line 687... Line 707...
687
 
707
 
Line 688... Line 708...
688
	DEBUGF	1,"TCP state: listen\n"
708
	DEBUGF	1,"TCP state: listen\n"
689
 
709
 
Line 690... Line 710...
690
	test	[edx + TCP_segment.Flags], TH_RST
710
	test	[edx + TCP_segment.Flags], TH_RST	;;; TODO: kill new socket on error
691
	jnz	.drop
711
	jnz	.drop
Line 692... Line 712...
692
 
712
 
693
	test	[edx + TCP_segment.Flags], TH_ACK
713
	test	[edx + TCP_segment.Flags], TH_ACK
Line 694... Line -...
694
	jnz	.drop_with_reset
-
 
695
 
-
 
Line 696... Line 714...
696
	test	[edx + TCP_segment.Flags], TH_SYN
714
	jnz	.drop_with_reset
Line 697... Line -...
697
	jz	.drop
-
 
698
 
-
 
699
	cmp	esi, 0xffffff		; destination ip = 255.255.255.255 ?
-
 
700
	jz	.drop
715
 
701
 
716
	test	[edx + TCP_segment.Flags], TH_SYN
Line 702... Line 717...
702
	; TODO: check if it's a broadcast or multicast, and drop if so
717
	jz	.drop
Line 716... Line 731...
716
	pop	[eax + TCP_SOCKET.IRS]
731
	pop	[eax + TCP_SOCKET.IRS]
Line 717... Line 732...
717
 
732
 
718
	push	[eax + TCP_SOCKET.ISS]
733
	push	[eax + TCP_SOCKET.ISS]
Line -... Line 734...
-
 
734
	pop	[eax + TCP_SOCKET.SND_NXT]
-
 
735
 
-
 
736
	TCP_sendseqinit eax
719
	pop	[eax + TCP_SOCKET.SND_NXT]
737
	TCP_rcvseqinit eax
720
 
738
 
721
	mov	[eax + TCP_SOCKET.t_state], TCB_SYN_RECEIVED
739
	mov	[eax + TCP_SOCKET.t_state], TCB_SYN_RECEIVED
-
 
740
	mov	[eax + TCP_SOCKET.t_flags], TF_ACKNOW
-
 
741
	mov	[eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval  ;;;; macro
-
 
742
 
Line -... Line 743...
-
 
743
	add	eax, STREAM_SOCKET.snd
-
 
744
	call	SOCKET_ring_create
-
 
745
 
-
 
746
	add	eax, STREAM_SOCKET.rcv - STREAM_SOCKET.snd
-
 
747
	call	SOCKET_ring_create
722
	mov	[eax + TCP_SOCKET.t_flags], TF_ACKNOW
748
 
-
 
749
	sub	eax, STREAM_SOCKET.rcv
723
	mov	[eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval
750
 
Line 724... Line 751...
724
 
751
	mov	[eax + SOCKET.lock], 0
725
	mov	ebx, eax
752
	mov	ebx, eax	; if there is data, it must arrive in this new socket!
Line 828... Line 855...
828
       @@:
855
       @@:
829
	;;;;;
856
	;;;;;
830
	jmp	.step6
857
	jmp	.step6
Line 831... Line -...
831
 
-
 
832
 
-
 
833
 
-
 
834
 
858
 
Line 835... Line 859...
835
 
859
 
836
  .trim_then_step6:
860
  .trim_then_step6:
Line 1081... Line 1105...
1081
	mov	[ebx + TCP_SOCKET.timer_retransmission], 0
1105
	mov	[ebx + TCP_SOCKET.timer_retransmission], 0
Line 1082... Line 1106...
1082
 
1106
 
1083
	mov	eax, [ebx + TCP_SOCKET.SND_MAX]
1107
	mov	eax, [ebx + TCP_SOCKET.SND_MAX]
1084
	cmp	eax, [edx + TCP_segment.AckNumber]
1108
	cmp	eax, [edx + TCP_segment.AckNumber]
1085
	je	.all_outstanding
1109
	je	.all_outstanding
1086
	mov	[ebx + TCP_SOCKET.timer_retransmission], 120 ;;;; TODO: correct this value
1110
	mov	[ebx + TCP_SOCKET.timer_retransmission], 120 ;;;; TODO: correct this value (use a macro for it)
Line 1087... Line 1111...
1087
  .all_outstanding:
1111
  .all_outstanding:
1088
 
1112
 
Line 1180... Line 1204...
1180
	cmp	eax, [edx + TCP_segment.AckNumber]
1204
	cmp	eax, [edx + TCP_segment.AckNumber]
1181
	jl	.update_window
1205
	jl	.update_window
1182
	jg	.no_window_update
1206
	jg	.no_window_update
1183
       @@:
1207
       @@:
Line 1184... Line 1208...
1184
 
1208
 
1185
	mov	eax, [ebx + TCP_SOCKET.SND_WL2] 	  ;;;;
1209
	mov	eax, [ebx + TCP_SOCKET.SND_WL2]
1186
	cmp	eax, [edx + TCP_segment.AckNumber]
1210
	cmp	eax, [edx + TCP_segment.AckNumber]
Line 1187... Line 1211...
1187
	jne	.no_window_update
1211
	jne	.no_window_update
1188
 
1212
 
Line 1210... Line 1234...
1210
;
1234
;
1211
;        ;;; update stats
1235
;        ;;; update stats
1212
;
1236
;
1213
;       @@:
1237
;       @@:
Line 1214... Line 1238...
1214
 
1238
 
1215
	movzx	eax, [edx + TCP_segment.Window] 	;;; FIXME: use pre-calculated value instead!
1239
	mov	eax, dword [edx + TCP_segment.Window]
1216
	cmp	eax, [ebx + TCP_SOCKET.max_sndwnd]
1240
	cmp	eax, [ebx + TCP_SOCKET.max_sndwnd]
1217
	jle	@f
1241
	jle	@f
1218
	mov	[ebx + TCP_SOCKET.max_sndwnd], eax
1242
	mov	[ebx + TCP_SOCKET.max_sndwnd], eax
1219
       @@:
1243
       @@:
Line 1286... Line 1310...
1286
	shr	al, 2
1310
	shr	al, 2
Line 1287... Line 1311...
1287
 
1311
 
Line 1288... Line 1312...
1288
	lea	esi, [edx + eax]
1312
	lea	esi, [edx + eax]
1289
 
1313
 
Line 1290... Line 1314...
1290
	or	[ebx + TCP_SOCKET.t_flags], TF_DELACK
1314
	or	[ebx + TCP_SOCKET.t_flags], TF_DELACK
1291
	add	[ebx + TCP_SOCKET.RCV_NXT], ecx 	 ;;; right ?
1315
	add	[ebx + TCP_SOCKET.RCV_NXT], ecx
Line 1292... Line 1316...
1292
 
1316
 
Line 1556... Line 1580...
1556
	inc	ecx
1580
	inc	ecx
1557
	jmp	.no_persist_timeout
1581
	jmp	.no_persist_timeout
Line 1558... Line 1582...
1558
 
1582
 
Line 1559... Line 1583...
1559
  .no_zero_window:
1583
  .no_zero_window:
1560
 
1584
 
Line 1561... Line 1585...
1561
	mov	[eax + TCP_SOCKET.timer_persist], 0	;;;;
1585
	mov	[eax + TCP_SOCKET.timer_persist], 0
Line 1562... Line 1586...
1562
	mov	[eax + TCP_SOCKET.t_rxtshift], 0
1586
	mov	[eax + TCP_SOCKET.t_rxtshift], 0
Line 1798... Line 1822...
1798
	or	dx, di	;        .Flags                  db ?
1822
	or	dx, di	;        .Flags                  db ?
1799
	pushw	dx
1823
	pushw	dx
1800
	shr	edi, 2	;        .DataOffset             db ? ;;;;
1824
	shr	edi, 2	;        .DataOffset             db ? ;;;;
Line 1801... Line 1825...
1801
 
1825
 
1802
	push	[eax + TCP_SOCKET.RCV_NXT]	;        .AckNumber              dd ?
1826
	push	[eax + TCP_SOCKET.RCV_NXT]	;        .AckNumber              dd ?
Line 1803... Line 1827...
1803
	ntohld	[esp]
1827
	ntohd	[esp]
1804
 
1828
 
Line 1805... Line 1829...
1805
	push	[eax + TCP_SOCKET.SND_NXT]	;        .SequenceNumber         dd ?
1829
	push	[eax + TCP_SOCKET.SND_NXT]	;        .SequenceNumber         dd ?
1806
	ntohld	[esp]
1830
	ntohd	[esp]
Line 1807... Line 1831...
1807
 
1831
 
1808
	push	[eax + TCP_SOCKET.RemotePort]	;        .DestinationPort        dw ?
1832
	push	[eax + TCP_SOCKET.RemotePort]	;        .DestinationPort        dw ?
Line 1809... Line 1833...
1809
	ntohlw	[esp]
1833
	ntohw	[esp]
Line 1810... Line 1834...
1810
 
1834
 
1811
	push	[eax + TCP_SOCKET.LocalPort]	;        .SourcePort             dw ?
1835
	push	[eax + TCP_SOCKET.LocalPort]	;        .SourcePort             dw ?