From 7c8d55d5bbdafa3e25b71ef850b8306eff140646 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Mon, 12 Oct 2009 18:14:14 +0000 Subject: [PATCH] More fixes in UDP, IPv4 and socket code. Fixes in network library, nslookup works now. git-svn-id: svn://kolibrios.org@1208 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../net/applications/network_lib/network.asm | 29 ++++--------------- kernel/branches/net/network/IPv4.inc | 10 +++++++ kernel/branches/net/network/socket.inc | 6 ++-- kernel/branches/net/network/udp.inc | 10 +++++-- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/kernel/branches/net/applications/network_lib/network.asm b/kernel/branches/net/applications/network_lib/network.asm index b1070db39b..1b9b5a8301 100644 --- a/kernel/branches/net/applications/network_lib/network.asm +++ b/kernel/branches/net/applications/network_lib/network.asm @@ -675,40 +675,23 @@ lock xadd [DNSrequestID], eax ; atomically increment ID, get old value mov eax, 0x01000100 stosd ; 7. Get DNS server address. -; Get number of running cards. - mcall 73, -1 - xchg eax, edx -; Loop for all initialized network cards, scanning for initialized DNS address. - mov ebx, 0x00000004 ; protocol IP=0, device number=0, function=get DNS address -.get_dns_loop: - mcall 75 + mcall 75, 0x00000004 ; protocol IP=0, device number=0, function=get DNS address cmp eax, -1 - jz .get_dns_next - test ecx, ecx - jnz .got_dns - dec edx - jz .get_dns_done -.get_dns_next: - inc bh - jnz .get_dns_loop -; all possible devices were checked, none found - return error -.get_dns_done: - jmp .ret.dnserr -.got_dns: - mov esi, ecx ; put server address to esi + je .ret.dnserr + mov esi, eax ; put server address to esi ; 8. Open UDP socket to DNS server, port 53. ; 8a. Create new socket. mcall 74, 0, AF_INET, IPPROTO_UDP cmp eax, -1 ; error? jz .ret.dnserr - xchg ecx, eax ; put socket handle to ecx + mov ecx, eax ; put socket handle to ecx ; 8b. Create sockaddr structure on the stack. push 0 push 0 ; sin_zero push esi ; sin_addr push AF_INET + (53 shl 24) ; sin_family and sin_port in network byte order -; 8c. Call the system. +; 8c. Connect. mcall 74, 4, , esp, sizeof.sockaddr_in ; 8d. Restore the stack, undo 8b. add esp, esi @@ -778,7 +761,7 @@ end virtual ; 2. Read UDP datagram. mov ecx, [edi+__gai_reqdata.socket] push edi - mcall 74, 6, , , 512, 0 + mcall 74, 7, , , 512, 0 pop edi ; 3. Ignore events for other sockets (return if no data read) test eax, eax diff --git a/kernel/branches/net/network/IPv4.inc b/kernel/branches/net/network/IPv4.inc index 107cefb28a..2f11a7a4a8 100644 --- a/kernel/branches/net/network/IPv4.inc +++ b/kernel/branches/net/network/IPv4.inc @@ -512,6 +512,16 @@ IPv4_create_packet: cmp ecx, 1480 jg .exit_ + cmp ebx, ebx ; if dest ip = 0 + jnz .ip_ok ; and local ip is valid + ; use local ip instead + cmp [IP_LIST],0xffffffff ; + je .ip_ok ; TODO: find solution to send broadcast + ; on device other then device 0 + mov ebx, [IP_LIST] ; + ; + .ip_ok: ; + push ecx eax ebx dx di cmp eax, -1 diff --git a/kernel/branches/net/network/socket.inc b/kernel/branches/net/network/socket.inc index 36be87d0f4..05b50e5dd4 100644 --- a/kernel/branches/net/network/socket.inc +++ b/kernel/branches/net/network/socket.inc @@ -722,9 +722,11 @@ socket_send: cmp [eax + SOCKET.LocalPort],0 jne .port_ok + push esi mov ecx, [eax + SOCKET.Type] call socket_find_port test bx, bx + pop esi je s_error mov [eax + SOCKET.LocalPort], bx @@ -733,7 +735,7 @@ socket_send: mov ecx, esi mov esi, edx mov edx, dword [eax + SOCKET.LocalPort] ; load local port and remote port at once - DEBUGF 1,"local port: %x, remote port: %x\n",[eax + SOCKET.LocalPort]:2, [eax + SOCKET.RemotePort]:2 + DEBUGF 1,"local port: %x, remote port: %x\n",[eax + SOCKET.LocalPort]:4, [eax + SOCKET.RemotePort]:4 mov ebx, [eax + SOCKET.LocalIP] mov eax, [eax + SOCKET.RemoteIP] @@ -787,7 +789,7 @@ socket_send: align 4 socket_find_port: - DEBUGF 1,"Socket_find_free_port, type: %u ",eax + DEBUGF 1,"Socket_find_free_port\n" cmp ecx, IP_PROTO_UDP je .udp diff --git a/kernel/branches/net/network/udp.inc b/kernel/branches/net/network/udp.inc index 2949b56f31..f3c5f494f1 100644 --- a/kernel/branches/net/network/udp.inc +++ b/kernel/branches/net/network/udp.inc @@ -95,6 +95,8 @@ UDP_handler: cmp [eax + SOCKET.LocalPort], bx jne .next_socket + DEBUGF 1,"found socket with matching domain, type and localport\n" + ; For dhcp, we must allow any remote server to respond. ; I will accept the first incoming response to be the one ; I bind to, if the socket is opened with a destination IP address of @@ -103,15 +105,17 @@ UDP_handler: je .ok1 mov ebx, [esp] - mov ebx, [ebx + ETH_FRAME.Data + IPv4_Packet.SourceAddress] ; get the Source address from the IP Packet - cmp [eax + SOCKET.RemoteIP], eax + mov ebx, [ebx + ETH_FRAME.Data + IPv4_Packet.SourceAddress] ; get the Source address from the IP Packet FIXME + cmp [eax + SOCKET.RemoteIP], ebx jne .try_more ; Quit if the source IP is not valid, check for more sockets with this IP/PORT combination + + DEBUGF 1,"Remote Ip matches\n" .ok1: mov bx, [edx + UDP_Packet.SourcePort] ; Remote port must be 0, or equal to sourceport of packet - cmp [eax + SOCKET.RemotePort],0 + cmp [eax + SOCKET.RemotePort], 0 je .ok2 cmp [eax + SOCKET.RemotePort], bx