1
0

TCP: improved routing, connect.

git-svn-id: svn://kolibrios.org@6912 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2017-05-28 20:57:46 +00:00
parent e15ba926dd
commit e9dc6c5ab5

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2017. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; Part of the TCP/IP network stack for KolibriOS ;; ;; Part of the TCP/IP network stack for KolibriOS ;;
@ -89,42 +89,9 @@ tcp_connect:
test [eax + SOCKET.state], SS_ISCONNECTED test [eax + SOCKET.state], SS_ISCONNECTED
jnz .eisconn jnz .eisconn
inc [TCPS_connattempt] ; update stats
push eax edx push eax edx
lea ecx, [eax + SOCKET.mutex] lea ecx, [eax + SOCKET.mutex]
call mutex_lock call mutex_lock
pop edx eax
; Fill in local IP
cmp [eax + IP_SOCKET.LocalIP], 0
jne @f
push [IP_LIST + 4] ; FIXME: use correct local IP
pop [eax + IP_SOCKET.LocalIP]
; Fill in remote port and IP
pushw [edx + 2]
pop [eax + TCP_SOCKET.RemotePort]
pushd [edx + 4]
pop [eax + IP_SOCKET.RemoteIP]
; Find a local port, if user didnt define one
cmp [eax + TCP_SOCKET.LocalPort], 0
jne @f
call socket_find_port
@@:
; Start the TCP sequence
mov [eax + TCP_SOCKET.timer_persist], 0
mov [eax + TCP_SOCKET.t_state], TCPS_SYN_SENT
push [TCP_sequence_num]
add [TCP_sequence_num], 6400
pop [eax + TCP_SOCKET.ISS]
mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init
tcp_sendseqinit eax
mov ebx, eax mov ebx, eax
lea eax, [ebx + STREAM_SOCKET.snd] lea eax, [ebx + STREAM_SOCKET.snd]
@ -136,20 +103,75 @@ tcp_connect:
call socket_ring_create call socket_ring_create
test eax, eax test eax, eax
jz .nomem jz .nomem
pop edx eax
push ebx ; Fill in remote port and IP
lea ecx, [ebx + SOCKET.mutex] pushw [edx + 2]
call mutex_unlock pop [eax + TCP_SOCKET.RemotePort]
pushd [edx + 4]
pop [eax + TCP_SOCKET.RemoteIP]
; Find route to host
pusha
push eax
mov ebx, [eax + TCP_SOCKET.device]
mov edx, [eax + TCP_SOCKET.LocalIP]
mov eax, [eax + TCP_SOCKET.RemoteIP]
call ipv4_route
test eax, eax
jz .enoroute
pop eax pop eax
mov ebx, [NET_DRV_LIST + edi]
mov [eax + TCP_SOCKET.device], ebx
mov [eax + TCP_SOCKET.LocalIP], edx
popa
; Find a local port, if user didnt define one
cmp [eax + TCP_SOCKET.LocalPort], 0
jne @f
call socket_find_port
@@:
; Compute window scaling factor
push ecx
xor ecx, ecx
mov ebx, TCP_max_win
@@:
cmp ebx, SOCKET_BUFFER_SIZE
ja @f
shl ebx, 1
inc ecx
cmp ecx, TCP_max_winshift
jb @r
@@:
mov [eax + TCP_SOCKET.request_r_scale], cl
pop ecx
call socket_is_connecting call socket_is_connecting
inc [TCPS_connattempt]
mov [eax + TCP_SOCKET.timer_persist], 0
mov [eax + TCP_SOCKET.t_state], TCPS_SYN_SENT
mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init
push [TCP_sequence_num]
add [TCP_sequence_num], TCP_ISSINCR/2
pop [eax + TCP_SOCKET.ISS]
tcp_sendseqinit eax
push eax
lea ecx, [eax + SOCKET.mutex]
call mutex_unlock
pop eax
; Now send the SYN packet to remote end ; Now send the SYN packet to remote end
push eax push eax
call tcp_output call tcp_output
pop eax pop eax
.block:
test [eax + SOCKET.options], SO_NONBLOCK test [eax + SOCKET.options], SO_NONBLOCK
jz .waitforit jz .waitforit
@ -159,6 +181,7 @@ tcp_connect:
ret ret
.nomem: .nomem:
pop edx eax
xor eax, eax xor eax, eax
dec eax dec eax
mov ebx, ENOMEM mov ebx, ENOMEM
@ -170,6 +193,14 @@ tcp_connect:
mov ebx, EISCONN mov ebx, EISCONN
ret ret
.enoroute:
pop eax
popa
xor eax, eax
dec eax
mov ebx, EADDRNOTAVAIL
ret
.waitforit: .waitforit:
push eax push eax
stdcall timer_hs, TCP_time_connect, 0, .timeout, eax stdcall timer_hs, TCP_time_connect, 0, .timeout, eax
@ -202,6 +233,5 @@ tcp_connect:
.established: .established:
stdcall cancel_timer_hs, [eax + TCP_SOCKET.timer_connect] stdcall cancel_timer_hs, [eax + TCP_SOCKET.timer_connect]
xor eax, eax xor eax, eax
ret ret