From cb6e8e3fb9086d0ab4000f3ea7810b7aaa3f2582 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Wed, 11 Apr 2012 13:07:45 +0000 Subject: [PATCH] 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 --- kernel/branches/net/network/tcp_input.inc | 58 ++++++++++++++++++----- kernel/branches/net/network/tcp_subr.inc | 7 ++- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/kernel/branches/net/network/tcp_input.inc b/kernel/branches/net/network/tcp_input.inc index be70c7c0db..83eeb327e2 100644 --- a/kernel/branches/net/network/tcp_input.inc +++ b/kernel/branches/net/network/tcp_input.inc @@ -45,18 +45,18 @@ TCP_input: pop cx ; previous checksum cmp cx, dx pop edx ecx - jne .drop_not_locked + jne .drop_no_socket DEBUGF 1,"Checksum ok\n" 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 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] 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 ;----------------------------------------------------------------------------------------- @@ -107,7 +107,7 @@ TCP_input: .socket_loop: mov ebx, [ebx + SOCKET.NextPtr] or ebx, ebx - jz .drop_with_reset_not_locked + jz .drop_with_reset_no_socket cmp [ebx + SOCKET.Domain], AF_INET4 jne .socket_loop @@ -1525,15 +1525,13 @@ align 4 align 4 .drop_with_reset: + DEBUGF 1,"Drop with reset\n" + pusha lea ecx, [ebx + SOCKET.mutex] call mutex_unlock popa -.drop_with_reset_not_locked: - - DEBUGF 1,"Drop with reset\n" - test [edx + TCP_header.Flags], TH_RST jnz .drop @@ -1555,7 +1553,6 @@ align 4 mov cl, TH_RST call TCP_respond_socket pop ebx - jmp .destroy_new_socket @@ -1565,15 +1562,12 @@ align 4 mov cl, TH_RST + TH_ACK call TCP_respond_socket pop ebx - jmp .destroy_new_socket - - ;----- ; Drop @@ -1597,4 +1591,42 @@ align 4 call kernel_free add esp, 4 - ret \ No newline at end of file + 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 \ No newline at end of file diff --git a/kernel/branches/net/network/tcp_subr.inc b/kernel/branches/net/network/tcp_subr.inc index e9272626b1..25988dd23b 100644 --- a/kernel/branches/net/network/tcp_subr.inc +++ b/kernel/branches/net/network/tcp_subr.inc @@ -313,8 +313,7 @@ TCP_respond_socket: ;------------------------- ; TCP_respond.segment: ; -; IN: ebx = ptr to driver -; edx = segment ptr (a previously received segment) +; IN: edx = segment ptr (a previously received segment) ; edi = ptr to dest and src IPv4 addresses ; cl = flags @@ -326,14 +325,14 @@ TCP_respond_segment: ;--------------------- ; Create the IP packet - push cx edx ebx + push cx edx mov ebx, [edi + 4] mov eax, [edi] mov ecx, sizeof.TCP_header mov di , IP_PROTO_TCP shl 8 + 128 call IPv4_output jz .error - pop ebx esi cx + pop esi cx push edx eax