forked from KolibriOS/kolibrios
Implemented global socket mutex.
git-svn-id: svn://kolibrios.org@3647 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
97a976fc9a
commit
3e584a778f
@ -63,6 +63,11 @@ PPPoE_discovery_input:
|
|||||||
|
|
||||||
; First, find open PPPoE socket
|
; First, find open PPPoE socket
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_lock
|
||||||
|
popa
|
||||||
|
|
||||||
mov eax, net_sockets
|
mov eax, net_sockets
|
||||||
|
|
||||||
.next_socket:
|
.next_socket:
|
||||||
@ -76,6 +81,11 @@ PPPoE_discovery_input:
|
|||||||
cmp [eax + SOCKET.Protocol], PPP_PROTO_ETHERNET
|
cmp [eax + SOCKET.Protocol], PPP_PROTO_ETHERNET
|
||||||
jne .next_socket
|
jne .next_socket
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
; Now, send it to the this socket
|
; Now, send it to the this socket
|
||||||
|
|
||||||
mov ecx, [esp + 4]
|
mov ecx, [esp + 4]
|
||||||
@ -84,6 +94,11 @@ PPPoE_discovery_input:
|
|||||||
jmp SOCKET_input
|
jmp SOCKET_input
|
||||||
|
|
||||||
.dump:
|
.dump:
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, 'PPPoE_discovery_input: dumping\n'
|
DEBUGF DEBUG_NETWORK_VERBOSE, 'PPPoE_discovery_input: dumping\n'
|
||||||
call kernel_free
|
call kernel_free
|
||||||
add esp, 4
|
add esp, 4
|
||||||
|
@ -238,6 +238,11 @@ ICMP_input:
|
|||||||
.check_sockets:
|
.check_sockets:
|
||||||
; Look for an open ICMP socket
|
; Look for an open ICMP socket
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_lock
|
||||||
|
popa
|
||||||
|
|
||||||
mov esi, [edi] ; ipv4 source address
|
mov esi, [edi] ; ipv4 source address
|
||||||
mov eax, net_sockets
|
mov eax, net_sockets
|
||||||
.try_more:
|
.try_more:
|
||||||
@ -245,7 +250,7 @@ ICMP_input:
|
|||||||
.next_socket:
|
.next_socket:
|
||||||
mov eax, [eax + SOCKET.NextPtr]
|
mov eax, [eax + SOCKET.NextPtr]
|
||||||
or eax, eax
|
or eax, eax
|
||||||
jz .dump
|
jz .dump_
|
||||||
|
|
||||||
cmp [eax + SOCKET.Domain], AF_INET4
|
cmp [eax + SOCKET.Domain], AF_INET4
|
||||||
jne .next_socket
|
jne .next_socket
|
||||||
@ -262,9 +267,14 @@ ICMP_input:
|
|||||||
; Update stats (and validate device ptr)
|
; Update stats (and validate device ptr)
|
||||||
call NET_ptr_to_num4
|
call NET_ptr_to_num4
|
||||||
cmp edi, -1
|
cmp edi, -1
|
||||||
je .dump
|
je .dump_
|
||||||
inc [ICMP_PACKETS_RX + edi]
|
inc [ICMP_PACKETS_RX + edi]
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "socket=%x\n", eax
|
DEBUGF DEBUG_NETWORK_VERBOSE, "socket=%x\n", eax
|
||||||
|
|
||||||
pusha
|
pusha
|
||||||
@ -275,6 +285,16 @@ ICMP_input:
|
|||||||
mov esi, edx
|
mov esi, edx
|
||||||
jmp SOCKET_input
|
jmp SOCKET_input
|
||||||
|
|
||||||
|
.dump_:
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
|
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP_input: no socket found\n"
|
||||||
|
jmp .dump
|
||||||
|
|
||||||
|
|
||||||
.checksum_mismatch:
|
.checksum_mismatch:
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "checksum mismatch\n"
|
DEBUGF DEBUG_NETWORK_VERBOSE, "checksum mismatch\n"
|
||||||
|
@ -199,6 +199,7 @@ uglobal
|
|||||||
last_socket_num dd ?
|
last_socket_num dd ?
|
||||||
last_UDP_port dw ? ; These values give the number of the last used ephemeral port
|
last_UDP_port dw ? ; These values give the number of the last used ephemeral port
|
||||||
last_TCP_port dw ? ;
|
last_TCP_port dw ? ;
|
||||||
|
socket_mutex MUTEX
|
||||||
endg
|
endg
|
||||||
|
|
||||||
|
|
||||||
@ -232,6 +233,9 @@ macro SOCKET_init {
|
|||||||
xchg al, ah
|
xchg al, ah
|
||||||
mov [last_TCP_port], ax
|
mov [last_TCP_port], ax
|
||||||
|
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_init
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
;-----------------------------------------------------------------
|
;-----------------------------------------------------------------
|
||||||
@ -1343,6 +1347,11 @@ SOCKET_check_port:
|
|||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_check_port: "
|
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_check_port: "
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_lock
|
||||||
|
popa
|
||||||
|
|
||||||
mov ecx, [eax + SOCKET.Protocol]
|
mov ecx, [eax + SOCKET.Protocol]
|
||||||
mov edx, [eax + IP_SOCKET.LocalIP]
|
mov edx, [eax + IP_SOCKET.LocalIP]
|
||||||
mov esi, net_sockets
|
mov esi, net_sockets
|
||||||
@ -1361,10 +1370,20 @@ SOCKET_check_port:
|
|||||||
cmp [esi + UDP_SOCKET.LocalPort], bx
|
cmp [esi + UDP_SOCKET.LocalPort], bx
|
||||||
jne .next_socket
|
jne .next_socket
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "local port %x already in use\n", bx ; FIXME: find a way to print big endian values with debugf
|
DEBUGF DEBUG_NETWORK_VERBOSE, "local port %x already in use\n", bx ; FIXME: find a way to print big endian values with debugf
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.port_ok:
|
.port_ok:
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "local port %x is free\n", bx ; FIXME: find a way to print big endian values with debugf
|
DEBUGF DEBUG_NETWORK_VERBOSE, "local port %x is free\n", bx ; FIXME: find a way to print big endian values with debugf
|
||||||
mov [eax + UDP_SOCKET.LocalPort], bx
|
mov [eax + UDP_SOCKET.LocalPort], bx
|
||||||
or bx, bx ; clear the zero-flag
|
or bx, bx ; clear the zero-flag
|
||||||
@ -1815,6 +1834,11 @@ SOCKET_alloc:
|
|||||||
mov [eax + SOCKET.snd_proc], s_error
|
mov [eax + SOCKET.snd_proc], s_error
|
||||||
mov [eax + SOCKET.rcv_proc], s_error
|
mov [eax + SOCKET.rcv_proc], s_error
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_lock
|
||||||
|
popa
|
||||||
|
|
||||||
; find first free socket number and use it
|
; find first free socket number and use it
|
||||||
mov edi, [last_socket_num]
|
mov edi, [last_socket_num]
|
||||||
.next_socket_number:
|
.next_socket_number:
|
||||||
@ -1873,6 +1897,12 @@ SOCKET_alloc:
|
|||||||
|
|
||||||
mov [net_sockets + SOCKET.NextPtr], eax
|
mov [net_sockets + SOCKET.NextPtr], eax
|
||||||
or eax, eax ; used to clear zero flag
|
or eax, eax ; used to clear zero flag
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
pop ebx
|
pop ebx
|
||||||
|
|
||||||
@ -1899,6 +1929,11 @@ SOCKET_free:
|
|||||||
|
|
||||||
push ebx
|
push ebx
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_lock
|
||||||
|
popa
|
||||||
|
|
||||||
pusha
|
pusha
|
||||||
lea ecx, [eax + SOCKET.mutex]
|
lea ecx, [eax + SOCKET.mutex]
|
||||||
call mutex_lock
|
call mutex_lock
|
||||||
@ -1935,6 +1970,11 @@ SOCKET_free:
|
|||||||
call kernel_free
|
call kernel_free
|
||||||
pop ebx
|
pop ebx
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_free: success!\n"
|
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_free: success!\n"
|
||||||
|
|
||||||
.error:
|
.error:
|
||||||
@ -2006,6 +2046,11 @@ SOCKET_num_to_ptr:
|
|||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_num_to_ptr: num=%u ", ecx
|
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_num_to_ptr: num=%u ", ecx
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_lock
|
||||||
|
popa
|
||||||
|
|
||||||
mov eax, net_sockets
|
mov eax, net_sockets
|
||||||
|
|
||||||
.next_socket:
|
.next_socket:
|
||||||
@ -2017,10 +2062,20 @@ SOCKET_num_to_ptr:
|
|||||||
|
|
||||||
test eax, eax
|
test eax, eax
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "ptr=%x\n", eax
|
DEBUGF DEBUG_NETWORK_VERBOSE, "ptr=%x\n", eax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.error:
|
.error:
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: not found\n", eax
|
DEBUGF DEBUG_NETWORK_ERROR, "SOCKET_num_to_ptr: not found\n", eax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -2070,6 +2125,11 @@ SOCKET_check:
|
|||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_check: %x\n", eax
|
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_check: %x\n", eax
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_lock
|
||||||
|
popa
|
||||||
|
|
||||||
push ebx
|
push ebx
|
||||||
mov ebx, net_sockets
|
mov ebx, net_sockets
|
||||||
|
|
||||||
@ -2085,6 +2145,11 @@ SOCKET_check:
|
|||||||
test eax, eax
|
test eax, eax
|
||||||
pop ebx
|
pop ebx
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
@ -2132,6 +2197,11 @@ SOCKET_process_end:
|
|||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_process_end: %x\n", edx
|
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_process_end: %x\n", edx
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_lock
|
||||||
|
popa
|
||||||
|
|
||||||
push ebx
|
push ebx
|
||||||
mov ebx, net_sockets
|
mov ebx, net_sockets
|
||||||
|
|
||||||
@ -2157,6 +2227,11 @@ SOCKET_process_end:
|
|||||||
.done:
|
.done:
|
||||||
pop ebx
|
pop ebx
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,13 +150,18 @@ TCP_process_input:
|
|||||||
; (IP Packet TCP Source Port = remote Port) OR (remote Port = 0)
|
; (IP Packet TCP Source Port = remote Port) OR (remote Port = 0)
|
||||||
|
|
||||||
.findpcb:
|
.findpcb:
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_lock
|
||||||
|
popa
|
||||||
|
|
||||||
mov ebx, net_sockets
|
mov ebx, net_sockets
|
||||||
mov si, [edx + TCP_header.DestinationPort]
|
mov si, [edx + TCP_header.DestinationPort]
|
||||||
|
|
||||||
.socket_loop:
|
.socket_loop:
|
||||||
mov ebx, [ebx + SOCKET.NextPtr]
|
mov ebx, [ebx + SOCKET.NextPtr]
|
||||||
or ebx, ebx
|
or ebx, ebx
|
||||||
jz .respond_seg_reset
|
jz .no_socket ;respond_seg_reset
|
||||||
|
|
||||||
cmp [ebx + SOCKET.Domain], AF_INET4
|
cmp [ebx + SOCKET.Domain], AF_INET4
|
||||||
jne .socket_loop
|
jne .socket_loop
|
||||||
@ -180,6 +185,11 @@ TCP_process_input:
|
|||||||
test ax, ax
|
test ax, ax
|
||||||
jnz .socket_loop
|
jnz .socket_loop
|
||||||
.found_socket: ; ebx now contains the socketpointer
|
.found_socket: ; ebx now contains the socketpointer
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: socket ptr=%x state=%u flags=%x\n", ebx, [ebx + TCP_SOCKET.t_state], [edx + TCP_header.Flags]:2
|
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: socket ptr=%x state=%u flags=%x\n", ebx, [ebx + TCP_SOCKET.t_state], [edx + TCP_header.Flags]:2
|
||||||
|
|
||||||
;----------------------------
|
;----------------------------
|
||||||
@ -1619,6 +1629,13 @@ align 4
|
|||||||
pop ebx
|
pop ebx
|
||||||
jmp .destroy_new_socket
|
jmp .destroy_new_socket
|
||||||
|
|
||||||
|
.no_socket:
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
.respond_seg_reset:
|
.respond_seg_reset:
|
||||||
test [edx + TCP_header.Flags], TH_RST
|
test [edx + TCP_header.Flags], TH_RST
|
||||||
jnz .drop_no_socket
|
jnz .drop_no_socket
|
||||||
|
@ -139,6 +139,11 @@ UDP_input:
|
|||||||
; IP Packet UDP Destination Port = local Port
|
; IP Packet UDP Destination Port = local Port
|
||||||
; IP Packet SA = Remote IP
|
; IP Packet SA = Remote IP
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_lock
|
||||||
|
popa
|
||||||
|
|
||||||
mov cx, [esi + UDP_header.SourcePort]
|
mov cx, [esi + UDP_header.SourcePort]
|
||||||
mov dx, [esi + UDP_header.DestinationPort]
|
mov dx, [esi + UDP_header.DestinationPort]
|
||||||
mov edi, [edi + 4] ; ipv4 source address
|
mov edi, [edi + 4] ; ipv4 source address
|
||||||
@ -147,7 +152,7 @@ UDP_input:
|
|||||||
.next_socket:
|
.next_socket:
|
||||||
mov eax, [eax + SOCKET.NextPtr]
|
mov eax, [eax + SOCKET.NextPtr]
|
||||||
or eax, eax
|
or eax, eax
|
||||||
jz .dump
|
jz .dump_
|
||||||
|
|
||||||
cmp [eax + SOCKET.Domain], AF_INET4
|
cmp [eax + SOCKET.Domain], AF_INET4
|
||||||
jne .next_socket
|
jne .next_socket
|
||||||
@ -160,6 +165,11 @@ UDP_input:
|
|||||||
|
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "UDP_input: socket=%x\n", eax
|
DEBUGF DEBUG_NETWORK_VERBOSE, "UDP_input: socket=%x\n", eax
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
;;; TODO: when packet is processed, check more sockets!
|
;;; TODO: when packet is processed, check more sockets!
|
||||||
|
|
||||||
; cmp [eax + IP_SOCKET.RemoteIP], 0xffffffff
|
; cmp [eax + IP_SOCKET.RemoteIP], 0xffffffff
|
||||||
@ -203,6 +213,16 @@ UDP_input:
|
|||||||
|
|
||||||
jmp .updatesock
|
jmp .updatesock
|
||||||
|
|
||||||
|
.dump_:
|
||||||
|
|
||||||
|
pusha
|
||||||
|
mov ecx, socket_mutex
|
||||||
|
call mutex_unlock
|
||||||
|
popa
|
||||||
|
|
||||||
|
DEBUGF DEBUG_NETWORK_VERBOSE, "UDP_input: no socket found\n"
|
||||||
|
|
||||||
|
jmp .dump
|
||||||
|
|
||||||
.checksum_mismatch:
|
.checksum_mismatch:
|
||||||
DEBUGF DEBUG_NETWORK_VERBOSE, "UDP_input: checksum mismatch\n"
|
DEBUGF DEBUG_NETWORK_VERBOSE, "UDP_input: checksum mismatch\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user