Fixed bug in TCP.

Error occured when receiving a TCP segment wich has no local socket. (netbranch)

git-svn-id: svn://kolibrios.org@2600 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-04-11 13:07:45 +00:00
parent e047996abc
commit cb6e8e3fb9
2 changed files with 48 additions and 17 deletions

View File

@ -45,18 +45,18 @@ TCP_input:
pop cx ; previous checksum pop cx ; previous checksum
cmp cx, dx cmp cx, dx
pop edx ecx pop edx ecx
jne .drop_not_locked jne .drop_no_socket
DEBUGF 1,"Checksum ok\n" DEBUGF 1,"Checksum ok\n"
and [edx + TCP_header.DataOffset], 0xf0 ; Calculate TCP segment header size (throwing away unused reserved bits in TCP header) and [edx + TCP_header.DataOffset], 0xf0 ; Calculate TCP segment header size (throwing away unused reserved bits in TCP header)
shr [edx + TCP_header.DataOffset], 2 shr [edx + TCP_header.DataOffset], 2
cmp [edx + TCP_header.DataOffset], sizeof.TCP_header ; Now see if it's at least the size of a standard TCP header cmp [edx + TCP_header.DataOffset], sizeof.TCP_header ; Now see if it's at least the size of a standard TCP header
jb .drop_not_locked ; If not, drop the packet jb .drop_no_socket ; If not, drop the packet
movzx eax, [edx + TCP_header.DataOffset] movzx eax, [edx + TCP_header.DataOffset]
sub ecx, eax ; substract TCP header size from total segment size sub ecx, eax ; substract TCP header size from total segment size
jb .drop_not_locked ; If total segment size is less then the advertised header size, drop packet jb .drop_no_socket ; If total segment size is less then the advertised header size, drop packet
DEBUGF 1,"we got %u bytes of data\n", ecx DEBUGF 1,"we got %u bytes of data\n", ecx
;----------------------------------------------------------------------------------------- ;-----------------------------------------------------------------------------------------
@ -107,7 +107,7 @@ TCP_input:
.socket_loop: .socket_loop:
mov ebx, [ebx + SOCKET.NextPtr] mov ebx, [ebx + SOCKET.NextPtr]
or ebx, ebx or ebx, ebx
jz .drop_with_reset_not_locked jz .drop_with_reset_no_socket
cmp [ebx + SOCKET.Domain], AF_INET4 cmp [ebx + SOCKET.Domain], AF_INET4
jne .socket_loop jne .socket_loop
@ -1525,15 +1525,13 @@ align 4
align 4 align 4
.drop_with_reset: .drop_with_reset:
DEBUGF 1,"Drop with reset\n"
pusha pusha
lea ecx, [ebx + SOCKET.mutex] lea ecx, [ebx + SOCKET.mutex]
call mutex_unlock call mutex_unlock
popa popa
.drop_with_reset_not_locked:
DEBUGF 1,"Drop with reset\n"
test [edx + TCP_header.Flags], TH_RST test [edx + TCP_header.Flags], TH_RST
jnz .drop jnz .drop
@ -1555,7 +1553,6 @@ align 4
mov cl, TH_RST mov cl, TH_RST
call TCP_respond_socket call TCP_respond_socket
pop ebx pop ebx
jmp .destroy_new_socket jmp .destroy_new_socket
@ -1565,15 +1562,12 @@ align 4
mov cl, TH_RST + TH_ACK mov cl, TH_RST + TH_ACK
call TCP_respond_socket call TCP_respond_socket
pop ebx pop ebx
jmp .destroy_new_socket jmp .destroy_new_socket
;----- ;-----
; Drop ; Drop
@ -1597,4 +1591,42 @@ align 4
call kernel_free call kernel_free
add esp, 4 add esp, 4
ret ret
.drop_with_reset_no_socket:
DEBUGF 1,"Drop with reset (no socket)\n"
test [edx + TCP_header.Flags], TH_RST
jnz .drop_no_socket
;;; if its a multicast/broadcast, also drop
test [edx + TCP_header.Flags], TH_ACK
jnz .respond_seg_ack
test [edx + TCP_header.Flags], TH_SYN
jnz .respond_seg_syn
.drop_no_socket:
DEBUGF 1,"Drop (no socket)\n"
call kernel_free
add esp, 4
ret
.respond_seg_ack:
mov cl, TH_RST
call TCP_respond_segment
jmp .drop_no_socket
.respond_seg_syn:
mov cl, TH_RST + TH_ACK
call TCP_respond_segment
jmp .drop_no_socket

View File

@ -313,8 +313,7 @@ TCP_respond_socket:
;------------------------- ;-------------------------
; TCP_respond.segment: ; TCP_respond.segment:
; ;
; IN: ebx = ptr to driver ; IN: edx = segment ptr (a previously received segment)
; edx = segment ptr (a previously received segment)
; edi = ptr to dest and src IPv4 addresses ; edi = ptr to dest and src IPv4 addresses
; cl = flags ; cl = flags
@ -326,14 +325,14 @@ TCP_respond_segment:
;--------------------- ;---------------------
; Create the IP packet ; Create the IP packet
push cx edx ebx push cx edx
mov ebx, [edi + 4] mov ebx, [edi + 4]
mov eax, [edi] mov eax, [edi]
mov ecx, sizeof.TCP_header mov ecx, sizeof.TCP_header
mov di , IP_PROTO_TCP shl 8 + 128 mov di , IP_PROTO_TCP shl 8 + 128
call IPv4_output call IPv4_output
jz .error jz .error
pop ebx esi cx pop esi cx
push edx eax push edx eax