Subversion Repositories Kolibri OS

Rev

Rev 1830 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1830 Rev 1831
Line 12... Line 12...
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
12
;;          GNU GENERAL PUBLIC LICENSE                             ;;
13
;;             Version 2, June 1991                                ;;
13
;;             Version 2, June 1991                                ;;
14
;;                                                                 ;;
14
;;                                                                 ;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 16... Line 16...
16
 
16
 
Line 17... Line 17...
17
$Revision: 1830 $
17
$Revision: 1831 $
18
 
18
 
19
;-----------------------------------------------------------------
19
;-----------------------------------------------------------------
20
;
20
;
Line 103... Line 103...
103
	ntohw	[edx + TCP_segment.UrgentPointer]
103
	ntohw	[edx + TCP_segment.UrgentPointer]
104
	ntohw	[edx + TCP_segment.SourcePort]
104
	ntohw	[edx + TCP_segment.SourcePort]
105
	ntohw	[edx + TCP_segment.DestinationPort]
105
	ntohw	[edx + TCP_segment.DestinationPort]
Line 106... Line 106...
106
 
106
 
107
;------------------------------------------------------------
107
;------------------------------------------------------------
Line 108... Line 108...
108
; Next thing to do is find the TCB (thus, the socket pointer)
108
; Next thing to do is find the TCPS (thus, the socket pointer)
109
 
109
 
110
; IP Packet TCP Destination Port = local Port
110
; IP Packet TCP Destination Port = local Port
Line 146... Line 146...
146
; ebx now contains the pointer to the socket
146
; ebx now contains the pointer to the socket
Line 147... Line 147...
147
 
147
 
148
;----------------------------
148
;----------------------------
Line 149... Line 149...
149
; Check if socket isnt closed
149
; Check if socket isnt closed
150
 
150
 
Line 151... Line 151...
151
	cmp	[ebx + TCP_SOCKET.t_state], TCB_CLOSED
151
	cmp	[ebx + TCP_SOCKET.t_state], TCPS_CLOSED
152
	je	.drop_not_locked
152
	je	.drop_not_locked
Line 191... Line 191...
191
	pop	[eax + IP_SOCKET.LocalIP]
191
	pop	[eax + IP_SOCKET.LocalIP]
Line 192... Line 192...
192
 
192
 
193
	push	[edx - IPv4_Packet.DataOrOptional + IPv4_Packet.SourceAddress]	   ;;; FIXME
193
	push	[edx - IPv4_Packet.DataOrOptional + IPv4_Packet.SourceAddress]	   ;;; FIXME
Line 194... Line 194...
194
	pop	[eax + IP_SOCKET.RemoteIP]
194
	pop	[eax + IP_SOCKET.RemoteIP]
Line 195... Line 195...
195
 
195
 
Line 196... Line 196...
196
	mov	[eax + TCP_SOCKET.t_state], TCB_LISTEN
196
	mov	[eax + TCP_SOCKET.t_state], TCPS_LISTEN
Line 211... Line 211...
211
	cmp	esi, 20 			; esi is headersize
211
	cmp	esi, 20 			; esi is headersize
212
	je	.no_options
212
	je	.no_options
Line 213... Line 213...
213
 
213
 
Line 214... Line 214...
214
	DEBUGF	1,"Segment has options\n"
214
	DEBUGF	1,"Segment has options\n"
215
 
215
 
Line 216... Line 216...
216
	cmp	[ebx + TCP_SOCKET.t_state], TCB_LISTEN		; no options when in listen state
216
	cmp	[ebx + TCP_SOCKET.t_state], TCPS_LISTEN 	 ; no options when in listen state
217
	jz	.not_uni_xfer					; also no header prediction
217
	jz	.not_uni_xfer					; also no header prediction
Line 308... Line 308...
308
;      In this case we'll free the ACK'ed data and notify higher levels that we have free space in buffer
308
;      In this case we'll free the ACK'ed data and notify higher levels that we have free space in buffer
309
;
309
;
310
;  -  If the length is not 0 and the ACK didn't move, we're the receiver side of the transfer.
310
;  -  If the length is not 0 and the ACK didn't move, we're the receiver side of the transfer.
311
;      If the packets are in order (data queue is empty), add the data to the socket buffer and request a delayed ACK
311
;      If the packets are in order (data queue is empty), add the data to the socket buffer and request a delayed ACK
Line 312... Line 312...
312
 
312
 
313
	cmp	[ebx + TCP_SOCKET.t_state], TCB_ESTABLISHED
313
	cmp	[ebx + TCP_SOCKET.t_state], TCPS_ESTABLISHED
Line 314... Line 314...
314
	jnz	.not_uni_xfer
314
	jnz	.not_uni_xfer
315
 
315
 
Line 436... Line 436...
436
 
436
 
Line 437... Line 437...
437
; Calculate receive window size
437
; Calculate receive window size
Line 438... Line 438...
438
 
438
 
439
;;;; TODO: 444
439
;;;; TODO: 444
Line 440... Line 440...
440
 
440
 
441
	cmp	[ebx + TCP_SOCKET.t_state], TCB_LISTEN
441
	cmp	[ebx + TCP_SOCKET.t_state], TCPS_LISTEN
Line 442... Line 442...
442
	je	.LISTEN
442
	je	.LISTEN
Line 479... Line 479...
479
	pop	[eax + TCP_SOCKET.SND_NXT]
479
	pop	[eax + TCP_SOCKET.SND_NXT]
Line 480... Line 480...
480
 
480
 
481
	TCP_sendseqinit eax
481
	TCP_sendseqinit eax
Line 482... Line 482...
482
	TCP_rcvseqinit eax
482
	TCP_rcvseqinit eax
483
 
483
 
484
	mov	[eax + TCP_SOCKET.t_state], TCB_SYN_RECEIVED
484
	mov	[eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
Line 485... Line 485...
485
	mov	[eax + TCP_SOCKET.t_flags], TF_ACKNOW
485
	mov	[eax + TCP_SOCKET.t_flags], TF_ACKNOW
486
	mov	[eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval  ;;;; macro
486
	mov	[eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_interval  ;;;; macro
Line 576... Line 576...
576
 
576
 
Line 577... Line 577...
577
; set socket state to connected
577
; set socket state to connected
Line 578... Line 578...
578
 
578
 
Line 579... Line 579...
579
	mov	[ebx + SOCKET.state],1	;;;; FIXME
579
	mov	[ebx + SOCKET.state],1	;;;; FIXME
580
 
580
 
Line 581... Line 581...
581
	mov	[ebx + TCP_SOCKET.t_state], TCB_ESTABLISHED
581
	mov	[ebx + TCP_SOCKET.t_state], TCPS_ESTABLISHED
Line 582... Line 582...
582
 
582
 
Line 583... Line 583...
583
;;; TODO: check if we should scale the connection (567-572)
583
;;; TODO: check if we should scale the connection (567-572)
584
;;; TODO: update RTT estimators
584
;;; TODO: update RTT estimators
585
 
585
 
Line 745... Line 745...
745
; Handle data that arrives after process terminates
745
; Handle data that arrives after process terminates
Line 746... Line 746...
746
 
746
 
747
	cmp	[ebx + SOCKET.PID], 0
747
	cmp	[ebx + SOCKET.PID], 0
Line 748... Line 748...
748
	jg	@f
748
	jg	@f
749
 
749
 
Line 750... Line 750...
750
	cmp	[ebx + TCP_SOCKET.t_state], TCB_CLOSE_WAIT
750
	cmp	[ebx + TCP_SOCKET.t_state], TCPS_CLOSE_WAIT
751
	jle	@f
751
	jle	@f
Line 809... Line 809...
809
	mov	eax, [ebx + TCP_SOCKET.t_state]
809
	mov	eax, [ebx + TCP_SOCKET.t_state]
810
	shl	eax, 2
810
	shl	eax, 2
811
	jmp	dword [eax + .rst_sw_list]
811
	jmp	dword [eax + .rst_sw_list]
Line 812... Line 812...
812
 
812
 
813
  .rst_sw_list:
813
  .rst_sw_list:
814
	dd	.rst_skip	;TCB_CLOSED
814
	dd	.rst_skip	;TCPS_CLOSED
815
	dd	.rst_skip	;TCB_LISTEN
815
	dd	.rst_skip	;TCPS_LISTEN
816
	dd	.rst_skip	;TCB_SYN_SENT
816
	dd	.rst_skip	;TCPS_SYN_SENT
817
	dd	.econnrefused	;TCB_SYN_RECEIVED
817
	dd	.econnrefused	;TCPS_SYN_RECEIVED
818
	dd	.econnreset	;TCB_ESTABLISHED
818
	dd	.econnreset	;TCPS_ESTABLISHED
819
	dd	.econnreset	;TCB_CLOSE_WAIT
819
	dd	.econnreset	;TCPS_CLOSE_WAIT
820
	dd	.econnreset	;TCB_FIN_WAIT_1
820
	dd	.econnreset	;TCPS_FIN_WAIT_1
821
	dd	.rst_close	;TCB_CLOSING
821
	dd	.rst_close	;TCPS_CLOSING
822
	dd	.rst_close	;TCB_LAST_ACK
822
	dd	.rst_close	;TCPS_LAST_ACK
823
	dd	.econnreset	;TCB_FIN_WAIT_2
823
	dd	.econnreset	;TCPS_FIN_WAIT_2
Line 824... Line 824...
824
	dd	.rst_close	;TCB_TIMED_WAIT
824
	dd	.rst_close	;TCPS_TIMED_WAIT
825
 
-
 
826
  .econnrefused:
825
 
Line 827... Line 826...
827
 
826
  .econnrefused:
828
	DEBUGF	1,"Connection refused"
-
 
829
 
827
	DEBUGF	1,"Connection refused"
Line 830... Line 828...
830
;;; TODO: debug info
828
 
831
 
-
 
832
	jmp	.close
829
	mov	[ebx + SOCKET.errorcode], ECONNREFUSED
Line 833... Line 830...
833
 
830
	jmp	.close
Line 834... Line 831...
834
  .econnreset:
831
 
835
 
-
 
836
	DEBUGF	1,"Connection reset"
832
  .econnreset:
Line -... Line 833...
-
 
833
	DEBUGF	1,"Connection reset"
837
 
834
 
-
 
835
	mov	[ebx + SOCKET.errorcode], ECONNRESET
-
 
836
 
-
 
837
    .close:
Line 838... Line 838...
838
;;; TODO: debug info
838
	DEBUGF	1,"Closing connection"
839
 
-
 
840
  .close:
839
 
Line -... Line 840...
-
 
840
	mov	[ebx + TCP_SOCKET.t_state], TCPS_CLOSED
841
 
841
	;;; TODO: update stats
842
	DEBUGF	1,"Closing connection"
-
 
843
 
842
	mov	eax, ebx
Line 864... Line 863...
864
; handle SYN-full and ACK-less segments
863
; handle SYN-full and ACK-less segments
Line 865... Line 864...
865
 
864
 
866
	test	[edx + TCP_segment.Flags], TH_SYN
865
	test	[edx + TCP_segment.Flags], TH_SYN
Line -... Line 866...
-
 
866
	jz	@f
867
	jz	@f
867
 
868
 
868
	mov	eax, ebx
869
	mov	ebx, ECONNRESET
-
 
870
	call	TCP_drop
869
	mov	ebx, ECONNRESET
Line 871... Line 870...
871
 
870
	call	TCP_drop
872
	jmp	.drop_with_reset
871
	jmp	.drop_with_reset
873
 
872
 
Line 882... Line 881...
882
 
881
 
883
 
882
 
Line 884... Line 883...
884
;---------------
883
;---------------
885
; ACK processing
884
; ACK processing
Line 886... Line 885...
886
 
885
 
Line -... Line 886...
-
 
886
	cmp	[ebx + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED
-
 
887
	jnz	.no_syn_rcv
-
 
888
 
-
 
889
	DEBUGF	1,"TCP state = syn received\n"
-
 
890
 
-
 
891
	mov	eax, [edx + TCP_segment.AckNumber]
-
 
892
	cmp	eax, [ebx + TCP_SOCKET.SND_UNA]
-
 
893
	jg	.drop_with_reset
-
 
894
 
-
 
895
	cmp	[ebx + TCP_SOCKET.SND_MAX], eax
-
 
896
	jg	.drop_with_reset
-
 
897
	;;; update stats
-
 
898
	mov	eax, ebx
-
 
899
	call	SOCKET_is_connected
-
 
900
	mov	[ebx + TCP_SOCKET.t_state], TCPS_ESTABLISHED
-
 
901
 
-
 
902
; Do window scaling?
-
 
903
 
887
	cmp	[ebx + TCP_SOCKET.t_state], TCB_SYN_RECEIVED
904
	test	[ebx + TCP_SOCKET.t_flags], TF_RCVD_SCALE
-
 
905
	jz	@f
-
 
906
	test	[ebx + TCP_SOCKET.t_flags], TF_REQ_SCALE
-
 
907
	jz	@f
-
 
908
 
-
 
909
	;;; 810-811
-
 
910
 
-
 
911
       @@:
-
 
912
 
-
 
913
	;;; 813 ?
Line 888... Line 914...
888
	jnz	.no_syn_rcv
914
 
Line 889... Line 915...
889
 
915
	mov	eax, [edx + TCP_segment.SequenceNumber]
Line 1093... Line 1119...
1093
; Wake up process waiting on send buffer
1119
; Wake up process waiting on send buffer
Line 1094... Line 1120...
1094
 
1120
 
1095
	mov	eax, ebx
1121
	mov	eax, ebx
Line 1096... Line 1122...
1096
	call	SOCKET_notify_owner
1122
	call	SOCKET_notify_owner
Line 1097... Line 1123...
1097
 
1123
 
1098
; Update TCB
1124
; Update TCPS
Line 1099... Line 1125...
1099
 
1125
 
Line 1116... Line 1142...
1116
 
1142
 
1117
	mov	eax, [ebx + TCP_SOCKET.t_state]
1143
	mov	eax, [ebx + TCP_SOCKET.t_state]
Line 1118... Line 1144...
1118
	jmp	dword [eax*4 + .ACK_sw_list]
1144
	jmp	dword [eax*4 + .ACK_sw_list]
1119
 
1145
 
1120
  .ACK_sw_list:
1146
  .ACK_sw_list:
1121
	dd	.ack_processed	;TCB_CLOSED
1147
	dd	.ack_processed	;TCPS_CLOSED
1122
	dd	.ack_processed	;TCB_LISTEN
1148
	dd	.ack_processed	;TCPS_LISTEN
1123
	dd	.ack_processed	;TCB_SYN_SENT
1149
	dd	.ack_processed	;TCPS_SYN_SENT
1124
	dd	.ack_processed	;TCB_SYN_RECEIVED
1150
	dd	.ack_processed	;TCPS_SYN_RECEIVED
1125
	dd	.ack_processed	;TCB_ESTABLISHED
1151
	dd	.ack_processed	;TCPS_ESTABLISHED
1126
	dd	.ack_processed	;TCB_CLOSE_WAIT
1152
	dd	.ack_processed	;TCPS_CLOSE_WAIT
1127
	dd	.ack_fw1	;TCB_FIN_WAIT_1
1153
	dd	.ack_fw1	;TCPS_FIN_WAIT_1
1128
	dd	.ack_c		;TCB_CLOSING
1154
	dd	.ack_c		;TCPS_CLOSING
1129
	dd	.ack_la 	;TCB_LAST_ACK
1155
	dd	.ack_la 	;TCPS_LAST_ACK
Line 1130... Line 1156...
1130
	dd	.ack_processed	;TCB_FIN_WAIT_2
1156
	dd	.ack_processed	;TCPS_FIN_WAIT_2
1131
	dd	.ack_tw 	;TCB_TIMED_WAIT
1157
	dd	.ack_tw 	;TCPS_TIMED_WAIT
Line 1139... Line 1165...
1139
	mov	eax, ebx
1165
	mov	eax, ebx
1140
	call	SOCKET_is_disconnected
1166
	call	SOCKET_is_disconnected
1141
;;;        mov     [ebx + TCP_SOCKET.timer_timed_wait], TCP_time_max_idle
1167
;;;        mov     [ebx + TCP_SOCKET.timer_timed_wait], TCP_time_max_idle
1142
       @@:
1168
       @@:
Line 1143... Line 1169...
1143
 
1169
 
1144
	mov	[ebx + TCP_SOCKET.t_state], TCB_FIN_WAIT_2
1170
	mov	[ebx + TCP_SOCKET.t_state], TCPS_FIN_WAIT_2
Line 1145... Line 1171...
1145
	jmp	.ack_processed
1171
	jmp	.ack_processed
1146
 
1172
 
Line 1147... Line 1173...
1147
 
1173
 
1148
  .ack_c:
1174
  .ack_c:
1149
	jz	.ack_processed
1175
	jz	.ack_processed
1150
 
1176
 
1151
	mov	[ebx + TCP_SOCKET.t_state], TCB_TIMED_WAIT
1177
	mov	[ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT
1152
	mov	eax, ebx
1178
	mov	eax, ebx
Line 1260... Line 1286...
1260
	jz	.not_urgent
1286
	jz	.not_urgent
Line 1261... Line 1287...
1261
 
1287
 
1262
	cmp	[edx + TCP_segment.UrgentPointer], 0
1288
	cmp	[edx + TCP_segment.UrgentPointer], 0
Line 1263... Line 1289...
1263
	jz	.not_urgent
1289
	jz	.not_urgent
1264
 
1290
 
Line 1265... Line 1291...
1265
	cmp	[ebx + TCP_SOCKET.t_state], TCB_TIMED_WAIT
1291
	cmp	[ebx + TCP_SOCKET.t_state], TCPS_TIMED_WAIT
Line 1266... Line 1292...
1266
	je	.not_urgent
1292
	je	.not_urgent
Line 1299... Line 1325...
1299
	DEBUGF	1,"TCP: do data (%u)\n", ecx
1325
	DEBUGF	1,"TCP: do data (%u)\n", ecx
Line 1300... Line 1326...
1300
 
1326
 
1301
	test	[edx + TCP_segment.Flags], TH_FIN
1327
	test	[edx + TCP_segment.Flags], TH_FIN
Line 1302... Line 1328...
1302
	jnz	.process_fin
1328
	jnz	.process_fin
1303
 
1329
 
Line 1304... Line 1330...
1304
	cmp	[ebx + TCP_SOCKET.t_state], TCB_FIN_WAIT_1
1330
	cmp	[ebx + TCP_SOCKET.t_state], TCPS_FIN_WAIT_1
1305
	jge	.dont_do_data
1331
	jge	.dont_do_data
Line 1342... Line 1368...
1342
 
1368
 
Line 1343... Line 1369...
1343
  .process_fin:
1369
  .process_fin:
Line 1344... Line 1370...
1344
 
1370
 
1345
	DEBUGF	1,"Processing FIN\n"
1371
	DEBUGF	1,"Processing FIN\n"
1346
 
1372
 
1347
	cmp	[ebx + TCP_SOCKET.t_state], TCB_CLOSE_WAIT
1373
	cmp	[ebx + TCP_SOCKET.t_state], TCPS_CLOSE_WAIT
1348
	je	.not_first_fin
1374
	je	.not_first_fin
1349
	cmp	[ebx + TCP_SOCKET.t_state], TCB_CLOSING
1375
	cmp	[ebx + TCP_SOCKET.t_state], TCPS_CLOSING
Line 1350... Line 1376...
1350
	je	.not_first_fin
1376
	je	.not_first_fin
Line 1351... Line 1377...
1351
	cmp	[ebx + TCP_SOCKET.t_state], TCB_FIN_WAIT_2
1377
	cmp	[ebx + TCP_SOCKET.t_state], TCPS_FIN_WAIT_2
Line 1363... Line 1389...
1363
	mov	eax, [ebx + TCP_SOCKET.t_state]
1389
	mov	eax, [ebx + TCP_SOCKET.t_state]
1364
	shl	eax, 2
1390
	shl	eax, 2
1365
	jmp	dword [eax + .FIN_sw_list]
1391
	jmp	dword [eax + .FIN_sw_list]
Line 1366... Line 1392...
1366
 
1392
 
1367
  .FIN_sw_list:
1393
  .FIN_sw_list:
1368
	dd	.no_fin 	;TCB_CLOSED
1394
	dd	.no_fin 	;TCPS_CLOSED
1369
	dd	.no_fin 	;TCB_LISTEN
1395
	dd	.no_fin 	;TCPS_LISTEN
1370
	dd	.no_fin 	;TCB_SYN_SENT
1396
	dd	.no_fin 	;TCPS_SYN_SENT
1371
	dd	.fin_syn_est	;TCB_SYN_RECEIVED
1397
	dd	.fin_syn_est	;TCPS_SYN_RECEIVED
1372
	dd	.fin_syn_est	;TCB_ESTABLISHED
1398
	dd	.fin_syn_est	;TCPS_ESTABLISHED
1373
	dd	.no_fin 	;TCB_CLOSE_WAIT
1399
	dd	.no_fin 	;TCPS_CLOSE_WAIT
1374
	dd	.fin_wait1	;TCB_FIN_WAIT_1
1400
	dd	.fin_wait1	;TCPS_FIN_WAIT_1
1375
	dd	.no_fin 	;TCB_CLOSING
1401
	dd	.no_fin 	;TCPS_CLOSING
1376
	dd	.no_fin 	;TCB_LAST_ACK
1402
	dd	.no_fin 	;TCPS_LAST_ACK
1377
	dd	.fin_wait2	;TCB_FIN_WAIT_2
1403
	dd	.fin_wait2	;TCPS_FIN_WAIT_2
Line 1378... Line 1404...
1378
	dd	.fin_timed	;TCB_TIMED_WAIT
1404
	dd	.fin_timed	;TCPS_TIMED_WAIT
Line 1379... Line 1405...
1379
 
1405
 
1380
  .fin_syn_est:
1406
  .fin_syn_est:
Line 1381... Line 1407...
1381
 
1407
 
Line 1382... Line 1408...
1382
	mov	[ebx + TCP_SOCKET.t_state], TCB_CLOSE_WAIT
1408
	mov	[ebx + TCP_SOCKET.t_state], TCPS_CLOSE_WAIT
1383
	jmp	.no_fin
1409
	jmp	.no_fin
Line 1384... Line 1410...
1384
 
1410
 
Line 1385... Line 1411...
1385
  .fin_wait1:
1411
  .fin_wait1:
1386
 
1412
 
1387
	mov	[ebx + TCP_SOCKET.t_state], TCB_CLOSING
1413
	mov	[ebx + TCP_SOCKET.t_state], TCPS_CLOSING
1388
	jmp	.no_fin
1414
	jmp	.no_fin
1389
 
1415
 
1390
  .fin_wait2:
1416
  .fin_wait2: