From 3b4749a91b9c4b94c8e14e44037161108fb5c5b9 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Sun, 27 Dec 2009 21:05:25 +0000 Subject: [PATCH] UDP fixes for net branch git-svn-id: svn://kolibrios.org@1335 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/net/network/socket.inc | 2 ++ kernel/branches/net/network/udp.inc | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/kernel/branches/net/network/socket.inc b/kernel/branches/net/network/socket.inc index 2b1a4a32b8..decdb4e3d5 100644 --- a/kernel/branches/net/network/socket.inc +++ b/kernel/branches/net/network/socket.inc @@ -76,6 +76,7 @@ struct UDP_SOCKET .LocalPort dw ? ; In INET byte order .RemotePort dw ? ; In INET byte order + .firstpacket db ? .end: ends @@ -343,6 +344,7 @@ socket_connect: mov bx , word [edx + 2] mov word [eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.RemotePort], bx + mov [eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.firstpacket], 0 DEBUGF 1,"remote port: %x ",bx mov ebx, dword [edx + 4] diff --git a/kernel/branches/net/network/udp.inc b/kernel/branches/net/network/udp.inc index 93a03d20d9..6242f5437b 100644 --- a/kernel/branches/net/network/udp.inc +++ b/kernel/branches/net/network/udp.inc @@ -140,11 +140,13 @@ UDP_handler: DEBUGF 1,"Remote Ip matches\n" .ok1: - mov bx, [edx + UDP_Packet.SourcePort] ; Remote port must be 0, or equal to sourceport of packet + lea ebx, [eax + SOCKET_head.lock] + call wait_mutex - cmp [eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.RemotePort], 0 - je .ok2 + cmp [eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.firstpacket], 0 + jz .updateport + mov bx, [edx + UDP_Packet.SourcePort] cmp [eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.RemotePort], bx jne .dump @@ -155,13 +157,7 @@ UDP_handler: movzx ecx, [edx + UDP_Packet.Length] rol cx , 8 sub cx , UDP_Packet.Data - mov dx , bx - - lea ebx, [eax + SOCKET_head.lock] - call wait_mutex - mov [eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.RemotePort], dx ; update remote port number - mov [eax + SOCKET_head.end + IPv4_SOCKET.RemoteIP], edi inc [UDP_PACKETS_RX] pop edi @@ -172,6 +168,15 @@ UDP_handler: jmp socket_internal_receiver + .updateport: + + mov bx, [edx + UDP_Packet.SourcePort] + DEBUGF 1,"Changing remote port to: %x\n", bx + mov [eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.RemotePort], bx + inc [eax + SOCKET_head.end + IPv4_SOCKET.end + UDP_SOCKET.firstpacket] + + jmp .ok2 + .dump: DEBUGF 1,"Dumping UDP packet\n" call kernel_free @@ -247,7 +252,7 @@ UDP_socket_send: mov esi, edi call checksum_1 ; Checksum for pseudoheader - pushd [edi-4] ; destination address ; TODO: fix this, IPv4 packet could have options.. + pushd [edi-4] ; destination address ; TODO: fix this, IPv4 packet could have options.. pushd [edi-8] ; source address mov ecx, 12 mov esi, esp