From 3ce07b4be0eff2101a869bef5fd49328cd0638d2 Mon Sep 17 00:00:00 2001 From: hidnplayr Date: Sat, 12 Nov 2011 20:05:07 +0000 Subject: [PATCH] more small updates and fixes in net branch git-svn-id: svn://kolibrios.org@2310 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/branches/net/network/IPv4.inc | 2 +- kernel/branches/net/network/icmp.inc | 5 +- kernel/branches/net/network/socket.inc | 1475 +++++++++++---------- kernel/branches/net/network/tcp_input.inc | 24 +- kernel/branches/net/network/udp.inc | 85 +- 5 files changed, 796 insertions(+), 795 deletions(-) diff --git a/kernel/branches/net/network/IPv4.inc b/kernel/branches/net/network/IPv4.inc index 08314bae79..f5ca25dbb1 100644 --- a/kernel/branches/net/network/IPv4.inc +++ b/kernel/branches/net/network/IPv4.inc @@ -301,7 +301,7 @@ IPv4_input: ; TODO: implement handler for IP options lea edi, [edx + IPv4_header.SourceAddress] ; make edi ptr to source and dest IPv4 address mov al , [edx + IPv4_header.Protocol] - add edx, esi ; make edi ptr to data + add esi, edx ; make esi ptr to data cmp al , IP_PROTO_TCP je TCP_input diff --git a/kernel/branches/net/network/icmp.inc b/kernel/branches/net/network/icmp.inc index dedd02c5ee..003d01c531 100644 --- a/kernel/branches/net/network/icmp.inc +++ b/kernel/branches/net/network/icmp.inc @@ -133,7 +133,7 @@ macro ICMP_init { ; size of buffer in [esp+4] ; ebx = pointer to device struct ; ecx = ICMP Packet size -; edx = ptr to ICMP Packet data +; esi = ptr to ICMP Packet data ; edi = ptr to ipv4 source and dest address ; ; OUT: / @@ -146,10 +146,9 @@ ICMP_input: ; First, check the checksum (altough some implementations ignore it) - push edx ecx + push esi ecx push [edx + ICMP_header.Checksum] mov [edx + ICMP_header.Checksum], 0 - mov esi, edx xor edx, edx call checksum_1 call checksum_2 diff --git a/kernel/branches/net/network/socket.inc b/kernel/branches/net/network/socket.inc index 248334018a..1d85927035 100644 --- a/kernel/branches/net/network/socket.inc +++ b/kernel/branches/net/network/socket.inc @@ -16,169 +16,170 @@ $Revision$ -struct SOCKET +struct SOCKET - NextPtr dd ? ; pointer to next socket in list - PrevPtr dd ? ; pointer to previous socket in list - Number dd ? ; socket number + NextPtr dd ? ; pointer to next socket in list + PrevPtr dd ? ; pointer to previous socket in list + Number dd ? ; socket number - lock dd ? ; lock mutex + lock dd ? ; lock mutex - PID dd ? ; application process id - Domain dd ? ; INET/UNIX/.. - Type dd ? ; RAW/STREAM/DGRAP - Protocol dd ? ; ICMP/IPv4/ARP/TCP/UDP - errorcode dd ? + PID dd ? ; application process id + Domain dd ? ; INET/UNIX/.. + Type dd ? ; RAW/STREAM/DGRAP + Protocol dd ? ; ICMP/IPv4/ARP/TCP/UDP + errorcode dd ? - options dd ? - state dd ? - backlog dw ? ; how many incomming connections that can be queued + options dd ? + state dd ? + backlog dw ? ; how many incomming connections that can be queued - snd_proc dd ? - rcv_proc dd ? + snd_proc dd ? + rcv_proc dd ? ends -struct IP_SOCKET SOCKET +struct IP_SOCKET SOCKET - LocalIP rd 4 - RemoteIP rd 4 + LocalIP rd 4 + RemoteIP rd 4 ends -struct TCP_SOCKET IP_SOCKET +struct TCP_SOCKET IP_SOCKET - LocalPort dw ? - RemotePort dw ? + LocalPort dw ? + RemotePort dw ? - t_state dd ? ; TCB state - t_rxtshift dd ? - t_rxtcur dd ? - t_dupacks dd ? - t_maxseg dd ? - t_force dd ? - t_flags dd ? + t_state dd ? ; TCB state + t_rxtshift dd ? + t_rxtcur dd ? + t_dupacks dd ? + t_maxseg dd ? + t_force dd ? + t_flags dd ? ;--------------- ; RFC783 page 21 ; send sequence - SND_UNA dd ? ; sequence number of unack'ed sent Packets - SND_NXT dd ? ; next send sequence number to use - SND_UP dd ? - SND_WL1 dd ? ; window minus one - SND_WL2 dd ? ; - ISS dd ? ; initial send sequence number - SND_WND dd ? ; send window + SND_UNA dd ? ; sequence number of unack'ed sent Packets + SND_NXT dd ? ; next send sequence number to use + SND_UP dd ? + SND_WL1 dd ? ; window minus one + SND_WL2 dd ? ; + ISS dd ? ; initial send sequence number + SND_WND dd ? ; send window ; receive sequence - RCV_WND dw ? ; receive window - RCV_NXT dd ? ; next receive sequence number to use - RCV_UP dd ? - IRS dd ? ; initial receive sequence number + RCV_WND dw ? ; receive window + RCV_NXT dd ? ; next receive sequence number to use + RCV_UP dd ? + IRS dd ? ; initial receive sequence number ;--------------------- ; Additional variables ; receive variables - RCV_ADV dd ? + RCV_ADV dd ? ; retransmit variables - SND_MAX dd ? + SND_MAX dd ? ; congestion control - SND_CWND dd ? - SND_SSTHRESH dd ? + SND_CWND dd ? + SND_SSTHRESH dd ? ;---------------------- ; Transmit timing stuff - t_idle dd ? - t_rtt dd ? - t_rtseq dd ? - t_srtt dd ? - t_rttvar dd ? - t_rttmin dd ? - max_sndwnd dd ? + t_idle dd ? + t_rtt dd ? + t_rtseq dd ? + t_srtt dd ? + t_rttvar dd ? + t_rttmin dd ? + max_sndwnd dd ? ;----------------- ; Out-of-band data - t_oobflags dd ? - t_iobc dd ? - t_softerror dd ? + t_oobflags dd ? + t_iobc dd ? + t_softerror dd ? ;--------- -; RFC 1323 - SND_SCALE db ? ; Scale factor - RCV_SCALE db ? - request_r_scale db ? - requested_s_scale dd ? +; RFC 1323 ; the order of next 4 elements may not change - ts_recent dd ? - ts_recent_age dd ? - last_ack_sent dd ? + SND_SCALE db ? + RCV_SCALE db ? + requested_s_scale db ? + request_r_scale db ? + + ts_recent dd ? + ts_recent_age dd ? + last_ack_sent dd ? ;------- ; Timers - timer_retransmission dw ? ; rexmt - timer_persist dw ? - timer_keepalive dw ? ; keepalive/syn timeout - timer_timed_wait dw ? ; also used as 2msl timer + timer_retransmission dw ? ; rexmt + timer_persist dw ? + timer_keepalive dw ? ; keepalive/syn timeout + timer_timed_wait dw ? ; also used as 2msl timer ends -struct UDP_SOCKET IP_SOCKET +struct UDP_SOCKET IP_SOCKET - LocalPort dw ? - RemotePort dw ? - firstpacket db ? + LocalPort dw ? + RemotePort dw ? + firstpacket db ? ends -struct ICMP_SOCKET +struct ICMP_SOCKET - Identifier dw ? + Identifier dw ? ends -struct RING_BUFFER - start_ptr dd ? ; Pointer to start of buffer - end_ptr dd ? ; pointer to end of buffer - read_ptr dd ? ; Read pointer - write_ptr dd ? ; Write pointer - size dd ? ; Number of bytes buffered +struct RING_BUFFER + start_ptr dd ? ; Pointer to start of buffer + end_ptr dd ? ; pointer to end of buffer + read_ptr dd ? ; Read pointer + write_ptr dd ? ; Write pointer + size dd ? ; Number of bytes buffered ends -struct STREAM_SOCKET TCP_SOCKET +struct STREAM_SOCKET TCP_SOCKET - rcv rd sizeof.RING_BUFFER/4 - snd rd sizeof.RING_BUFFER/4 + rcv rd sizeof.RING_BUFFER/4 + snd rd sizeof.RING_BUFFER/4 ends -struct socket_queue_entry +struct socket_queue_entry - data_ptr dd ? - buf_ptr dd ? - data_size dd ? + data_ptr dd ? + buf_ptr dd ? + data_size dd ? ends -SOCKETBUFFSIZE equ 4096 ; in bytes +SOCKETBUFFSIZE equ 4096 ; in bytes -SOCKET_QUEUE_SIZE equ 10 ; maximum number ofincoming packets queued for 1 socket +SOCKET_QUEUE_SIZE equ 10 ; maximum number ofincoming packets queued for 1 socket ; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start -SOCKET_QUEUE_LOCATION equ (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue) +SOCKET_QUEUE_LOCATION equ (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue) uglobal - net_sockets rd 4 - last_socket_num dd ? - last_UDP_port dw ? ; These values give the number of the last used ephemeral port - last_TCP_port dw ? ; + net_sockets rd 4 + last_socket_num dd ? + last_UDP_port dw ? ; These values give the number of the last used ephemeral port + last_TCP_port dw ? ; endg @@ -187,28 +188,28 @@ endg ; SOCKET_init ; ;----------------------------------------------------------------- -macro SOCKET_init { +macro SOCKET_init { - xor eax, eax - mov edi, net_sockets - mov ecx, 5 - rep stosd + xor eax, eax + mov edi, net_sockets + mov ecx, 5 + rep stosd @@: - pseudo_random eax - cmp ax, MIN_EPHEMERAL_PORT - jb @r - cmp ax, MAX_EPHEMERAL_PORT - ja @r - mov [last_UDP_port], ax + pseudo_random eax + cmp ax, MIN_EPHEMERAL_PORT + jb @r + cmp ax, MAX_EPHEMERAL_PORT + ja @r + mov [last_UDP_port], ax @@: - pseudo_random eax - cmp ax, MIN_EPHEMERAL_PORT - jb @r - cmp ax, MAX_EPHEMERAL_PORT - ja @r - mov [last_TCP_port], ax + pseudo_random eax + cmp ax, MIN_EPHEMERAL_PORT + jb @r + cmp ax, MAX_EPHEMERAL_PORT + ja @r + mov [last_TCP_port], ax } @@ -220,34 +221,34 @@ macro SOCKET_init { ;----------------------------------------------------------------- align 16 sock_sysfn_table: - dd SOCKET_open ; 0 - dd SOCKET_close ; 1 - dd SOCKET_bind ; 2 - dd SOCKET_listen ; 3 - dd SOCKET_connect ; 4 - dd SOCKET_accept ; 5 - dd SOCKET_send ; 6 - dd SOCKET_receive ; 7 - dd SOCKET_set_opt ; 8 - dd SOCKET_get_opt ; 9 + dd SOCKET_open ; 0 + dd SOCKET_close ; 1 + dd SOCKET_bind ; 2 + dd SOCKET_listen ; 3 + dd SOCKET_connect ; 4 + dd SOCKET_accept ; 5 + dd SOCKET_send ; 6 + dd SOCKET_receive ; 7 + dd SOCKET_set_opt ; 8 + dd SOCKET_get_opt ; 9 SOCKET_SYSFUNCS = ($ - sock_sysfn_table)/4 align 4 sys_socket: - cmp ebx, SOCKET_SYSFUNCS-1 - ja @f - jmp dword [sock_sysfn_table + 4*ebx] + cmp ebx, SOCKET_SYSFUNCS-1 + ja @f + jmp dword [sock_sysfn_table + 4*ebx] @@: - cmp ebx, 255 - jz SOCKET_debug + cmp ebx, 255 + jz SOCKET_debug s_error: - DEBUGF 1,"socket error\n" - mov dword [esp+32], -1 + DEBUGF 1,"socket error\n" + mov dword [esp+32], -1 - ret + ret @@ -264,78 +265,78 @@ s_error: align 4 SOCKET_open: - DEBUGF 1,"SOCKET_open: domain: %u, type: %u protocol: %x\n", ecx, edx, esi + DEBUGF 1,"SOCKET_open: domain: %u, type: %u protocol: %x\n", ecx, edx, esi - call SOCKET_alloc - jz s_error + call SOCKET_alloc + jz s_error - mov [esp+32], edi ; return socketnumber + mov [esp+32], edi ; return socketnumber - mov [eax + SOCKET.Domain], ecx - mov [eax + SOCKET.Type], edx - mov [eax + SOCKET.Protocol], esi + mov [eax + SOCKET.Domain], ecx + mov [eax + SOCKET.Type], edx + mov [eax + SOCKET.Protocol], esi - cmp ecx, AF_INET4 - jne .no_inet4 + cmp ecx, AF_INET4 + jne .no_inet4 - cmp edx, SOCK_DGRAM - je .udp + cmp edx, SOCK_DGRAM + je .udp - cmp edx, SOCK_STREAM - je .tcp + cmp edx, SOCK_STREAM + je .tcp - cmp edx, SOCK_RAW - je .raw + cmp edx, SOCK_RAW + je .raw .no_inet4: - ret + ret align 4 .raw: - test esi, esi ; IP_PROTO_IP - jz .ip + test esi, esi ; IP_PROTO_IP + jz .ip - cmp esi, IP_PROTO_ICMP - je .icmp + cmp esi, IP_PROTO_ICMP + je .icmp - cmp esi, IP_PROTO_UDP - je .udp + cmp esi, IP_PROTO_UDP + je .udp - cmp esi, IP_PROTO_TCP - je .tcp + cmp esi, IP_PROTO_TCP + je .tcp - ret + ret align 4 .udp: - mov [eax + SOCKET.Protocol], IP_PROTO_UDP - mov [eax + SOCKET.snd_proc], SOCKET_send_udp - mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram - ret + mov [eax + SOCKET.Protocol], IP_PROTO_UDP + mov [eax + SOCKET.snd_proc], SOCKET_send_udp + mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram + ret align 4 .tcp: - mov [eax + SOCKET.Protocol], IP_PROTO_TCP - mov [eax + SOCKET.snd_proc], SOCKET_send_tcp - mov [eax + SOCKET.rcv_proc], SOCKET_receive_tcp + mov [eax + SOCKET.Protocol], IP_PROTO_TCP + mov [eax + SOCKET.snd_proc], SOCKET_send_tcp + mov [eax + SOCKET.rcv_proc], SOCKET_receive_tcp - mov [eax + TCP_SOCKET.t_maxseg], 1480 ;;;;; FIXME - ret + mov [eax + TCP_SOCKET.t_maxseg], 1480 ;;;;; FIXME + ret align 4 .ip: - mov [eax + SOCKET.snd_proc], SOCKET_send_ip - mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram - ret + mov [eax + SOCKET.snd_proc], SOCKET_send_ip + mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram + ret align 4 .icmp: - mov [eax + SOCKET.snd_proc], SOCKET_send_icmp - mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram - ret + mov [eax + SOCKET.snd_proc], SOCKET_send_icmp + mov [eax + SOCKET.rcv_proc], SOCKET_receive_dgram + ret @@ -352,47 +353,47 @@ align 4 align 4 SOCKET_bind: - DEBUGF 1,"socket_bind: socknum: %u sockaddr: %x, length: %u\n", ecx, edx, esi + DEBUGF 1,"socket_bind: socknum: %u sockaddr: %x, length: %u\n", ecx, edx, esi - call SOCKET_num_to_ptr - jz s_error + call SOCKET_num_to_ptr + jz s_error - cmp esi, 2 - jb s_error + cmp esi, 2 + jb s_error - cmp word [edx], AF_INET4 - je .af_inet4 + cmp word [edx], AF_INET4 + je .af_inet4 - cmp word [edx], AF_UNIX - je .af_unix + cmp word [edx], AF_UNIX + je .af_unix - jmp s_error + jmp s_error .af_unix: - ; TODO: write code here + ; TODO: write code here - mov dword [esp+32], 0 - ret + mov dword [esp+32], 0 + ret .af_inet4: - DEBUGF 1,"af_inet4\n" + DEBUGF 1,"af_inet4\n" - cmp esi, 6 - jb s_error + cmp esi, 6 + jb s_error - pushw [edx + 2] - pop [eax + UDP_SOCKET.LocalPort] + pushw [edx + 2] + pop [eax + UDP_SOCKET.LocalPort] - pushd [edx + 4] - pop [eax + IP_SOCKET.LocalIP] + pushd [edx + 4] + pop [eax + IP_SOCKET.LocalIP] - DEBUGF 1,"local ip: %u.%u.%u.%u\n",\ - [eax + IP_SOCKET.LocalIP + 0]:1,[eax + IP_SOCKET.LocalIP + 1]:1,\ - [eax + IP_SOCKET.LocalIP + 2]:1,[eax + IP_SOCKET.LocalIP + 3]:1 + DEBUGF 1,"local ip: %u.%u.%u.%u\n",\ + [eax + IP_SOCKET.LocalIP + 0]:1,[eax + IP_SOCKET.LocalIP + 1]:1,\ + [eax + IP_SOCKET.LocalIP + 2]:1,[eax + IP_SOCKET.LocalIP + 3]:1 - mov dword [esp+32], 0 - ret + mov dword [esp+32], 0 + ret @@ -410,124 +411,124 @@ SOCKET_bind: align 4 SOCKET_connect: - DEBUGF 1,"SOCKET_connect: socknum: %u sockaddr: %x, length: %u\n", ecx, edx, esi + DEBUGF 1,"SOCKET_connect: socknum: %u sockaddr: %x, length: %u\n", ecx, edx, esi - call SOCKET_num_to_ptr - jz s_error + call SOCKET_num_to_ptr + jz s_error - cmp esi, 8 - jb s_error + cmp esi, 8 + jb s_error - cmp word [edx], AF_INET4 - je .af_inet4 + cmp word [edx], AF_INET4 + je .af_inet4 - jmp s_error + jmp s_error .af_inet4: - cmp [eax + IP_SOCKET.LocalIP], 0 - jne @f - push [IP_LIST] - pop [eax + IP_SOCKET.LocalIP] + cmp [eax + IP_SOCKET.LocalIP], 0 + jne @f + push [IP_LIST] + pop [eax + IP_SOCKET.LocalIP] @@: - cmp [eax + SOCKET.Protocol], IP_PROTO_UDP - je .udp + cmp [eax + SOCKET.Protocol], IP_PROTO_UDP + je .udp - cmp [eax + SOCKET.Protocol], IP_PROTO_TCP - je .tcp + cmp [eax + SOCKET.Protocol], IP_PROTO_TCP + je .tcp - cmp [eax + SOCKET.Protocol], IP_PROTO_IP - je .ip + cmp [eax + SOCKET.Protocol], IP_PROTO_IP + je .ip - cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP - je .ip + cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP + je .ip - jmp s_error + jmp s_error align 4 .udp: - lea ebx, [eax + SOCKET.lock] - call wait_mutex + lea ebx, [eax + SOCKET.lock] + call wait_mutex - pushw [edx + 2] - pop [eax + UDP_SOCKET.RemotePort] + pushw [edx + 2] + pop [eax + UDP_SOCKET.RemotePort] - pushd [edx + 4] - pop [eax + IP_SOCKET.RemoteIP] + pushd [edx + 4] + pop [eax + IP_SOCKET.RemoteIP] - cmp [eax + UDP_SOCKET.LocalPort], 0 - jne @f - call SOCKET_find_port + cmp [eax + UDP_SOCKET.LocalPort], 0 + jne @f + call SOCKET_find_port @@: - mov [eax + UDP_SOCKET.firstpacket], 0 + mov [eax + UDP_SOCKET.firstpacket], 0 - push eax - init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue - pop eax + push eax + init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue + pop eax - mov [eax + SOCKET.lock], 0 - mov dword [esp+32], 0 - ret + mov [eax + SOCKET.lock], 0 + mov dword [esp+32], 0 + ret align 4 .tcp: - lea ebx, [eax + SOCKET.lock] - call wait_mutex + lea ebx, [eax + SOCKET.lock] + call wait_mutex - pushw [edx + 2] - pop [eax + TCP_SOCKET.RemotePort] + pushw [edx + 2] + pop [eax + TCP_SOCKET.RemotePort] - pushd [edx + 4] - pop [eax + IP_SOCKET.RemoteIP] + pushd [edx + 4] + pop [eax + IP_SOCKET.RemoteIP] - cmp [eax + TCP_SOCKET.LocalPort], 0 - jne @f - call SOCKET_find_port + cmp [eax + TCP_SOCKET.LocalPort], 0 + jne @f + call SOCKET_find_port @@: - mov [eax + TCP_SOCKET.timer_persist], 0 - mov [eax + TCP_SOCKET.t_state], TCPS_SYN_SENT - push [TCP_sequence_num] - add [TCP_sequence_num], 6400 - pop [eax + TCP_SOCKET.ISS] - mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init + mov [eax + TCP_SOCKET.timer_persist], 0 + mov [eax + TCP_SOCKET.t_state], TCPS_SYN_SENT + push [TCP_sequence_num] + add [TCP_sequence_num], 6400 + pop [eax + TCP_SOCKET.ISS] + mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init - TCP_sendseqinit eax + TCP_sendseqinit eax ; mov [ebx + TCP_SOCKET.timer_retransmission], ;; todo: create macro to set retransmission timer - mov ebx, eax + mov ebx, eax - lea eax, [ebx + STREAM_SOCKET.snd] - call SOCKET_ring_create + lea eax, [ebx + STREAM_SOCKET.snd] + call SOCKET_ring_create - lea eax, [ebx + STREAM_SOCKET.rcv] - call SOCKET_ring_create + lea eax, [ebx + STREAM_SOCKET.rcv] + call SOCKET_ring_create - mov [ebx + SOCKET.lock], 0 + mov [ebx + SOCKET.lock], 0 - mov eax, ebx - call TCP_output + mov eax, ebx + call TCP_output - mov dword [esp+32], 0 - ret + mov dword [esp+32], 0 + ret align 4 .ip: - lea ebx, [eax + SOCKET.lock] - call wait_mutex + lea ebx, [eax + SOCKET.lock] + call wait_mutex - pushd [edx + 4] - pop [eax + IP_SOCKET.RemoteIP] + pushd [edx + 4] + pop [eax + IP_SOCKET.RemoteIP] - push eax - init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue - pop eax + push eax + init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue + pop eax - mov [eax + SOCKET.lock], 0 - mov dword [esp+32], 0 - ret + mov [eax + SOCKET.lock], 0 + mov dword [esp+32], 0 + ret ;----------------------------------------------------------------- @@ -542,42 +543,42 @@ align 4 align 4 SOCKET_listen: - DEBUGF 1,"SOCKET_listen: socknum: %u backlog: %u\n", ecx, edx + DEBUGF 1,"SOCKET_listen: socknum: %u backlog: %u\n", ecx, edx - call SOCKET_num_to_ptr - jz s_error + call SOCKET_num_to_ptr + jz s_error - cmp [eax + SOCKET.Domain], AF_INET4 - jne s_error + cmp [eax + SOCKET.Domain], AF_INET4 + jne s_error - cmp [eax + SOCKET.Protocol], IP_PROTO_TCP - jne s_error + cmp [eax + SOCKET.Protocol], IP_PROTO_TCP + jne s_error - cmp [eax + TCP_SOCKET.LocalPort], 0 - je s_error + cmp [eax + TCP_SOCKET.LocalPort], 0 + je s_error - cmp [eax + IP_SOCKET.LocalIP], 0 - jne @f - push [IP_LIST] - pop [eax + IP_SOCKET.LocalIP] + cmp [eax + IP_SOCKET.LocalIP], 0 + jne @f + push [IP_LIST] + pop [eax + IP_SOCKET.LocalIP] @@: - cmp edx, MAX_backlog - jbe @f - mov edx, MAX_backlog + cmp edx, MAX_backlog + jbe @f + mov edx, MAX_backlog @@: - mov [eax + SOCKET.backlog], dx - or [eax + SOCKET.options], SO_ACCEPTCON - mov [eax + TCP_SOCKET.t_state], TCPS_LISTEN + mov [eax + SOCKET.backlog], dx + or [eax + SOCKET.options], SO_ACCEPTCON + mov [eax + TCP_SOCKET.t_state], TCPS_LISTEN - push eax - init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up sockets queue - pop eax + push eax + init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up sockets queue + pop eax - mov dword [esp+32], 0 + mov dword [esp+32], 0 - ret + ret ;----------------------------------------------------------------- @@ -593,27 +594,27 @@ SOCKET_listen: align 4 SOCKET_accept: - DEBUGF 1,"SOCKET_accept: socknum: %u sockaddr: %x, length: %u\n", ecx, edx, esi + DEBUGF 1,"SOCKET_accept: socknum: %u sockaddr: %x, length: %u\n", ecx, edx, esi - call SOCKET_num_to_ptr - jz s_error + call SOCKET_num_to_ptr + jz s_error - test [eax + SOCKET.options], SO_ACCEPTCON - jz s_error + test [eax + SOCKET.options], SO_ACCEPTCON + jz s_error - cmp [eax + SOCKET.Domain], AF_INET4 - jne s_error + cmp [eax + SOCKET.Domain], AF_INET4 + jne s_error - cmp [eax + SOCKET.Protocol], IP_PROTO_TCP - jne s_error + cmp [eax + SOCKET.Protocol], IP_PROTO_TCP + jne s_error - get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, s_error + get_from_queue (eax + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, s_error - mov eax, [esi] - call SOCKET_ptr_to_num - jz s_error - mov [esp+32], eax - ret + mov eax, [esi] + call SOCKET_ptr_to_num + jz s_error + mov [esp+32], eax + ret ;----------------------------------------------------------------- @@ -627,42 +628,42 @@ SOCKET_accept: align 4 SOCKET_close: - DEBUGF 1,"SOCKET_close: socknum: %u\n", ecx + DEBUGF 1,"SOCKET_close: socknum: %u\n", ecx - call SOCKET_num_to_ptr - jz s_error + call SOCKET_num_to_ptr + jz s_error - cmp [eax + SOCKET.Domain], AF_INET4 - jne s_error + cmp [eax + SOCKET.Domain], AF_INET4 + jne s_error - cmp [eax + SOCKET.Protocol], IP_PROTO_UDP - je .free + cmp [eax + SOCKET.Protocol], IP_PROTO_UDP + je .free - cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP - je .free + cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP + je .free - cmp [eax + SOCKET.Protocol], IP_PROTO_IP - je .free + cmp [eax + SOCKET.Protocol], IP_PROTO_IP + je .free - cmp [eax + SOCKET.Protocol], IP_PROTO_TCP - je .tcp + cmp [eax + SOCKET.Protocol], IP_PROTO_TCP + je .tcp - jmp s_error + jmp s_error .tcp: - cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED ; state must be LISTEN, SYN_SENT or CLOSED - jb .free + cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_RECEIVED ; state must be LISTEN, SYN_SENT or CLOSED + jb .free - call TCP_output - mov dword [esp+32], 0 + call TCP_output + mov dword [esp+32], 0 - ret + ret .free: - call SOCKET_free - mov dword [esp+32], 0 + call SOCKET_free + mov dword [esp+32], 0 - ret + ret ;----------------------------------------------------------------- @@ -679,71 +680,71 @@ SOCKET_close: align 4 SOCKET_receive: - DEBUGF 1,"SOCKET_receive: socknum: %u bufaddr: %x, buflength: %u, flags: %x, ", ecx, edx, esi, edi + DEBUGF 1,"SOCKET_receive: socknum: %u bufaddr: %x, buflength: %u, flags: %x, ", ecx, edx, esi, edi - call SOCKET_num_to_ptr - jz s_error + call SOCKET_num_to_ptr + jz s_error - jmp [eax + SOCKET.rcv_proc] + jmp [eax + SOCKET.rcv_proc] align 4 SOCKET_receive_dgram: - DEBUGF 1,"SOCKET_receive: DGRAM\n" + DEBUGF 1,"SOCKET_receive: DGRAM\n" - mov ebx, esi - mov edi, edx ; addr to buffer + mov ebx, esi + mov edi, edx ; addr to buffer - get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, s_error ; destroys esi and ecx + get_from_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, s_error ; destroys esi and ecx - mov ecx, [esi + socket_queue_entry.data_size] - DEBUGF 1,"Got %u bytes of data\n", ecx + mov ecx, [esi + socket_queue_entry.data_size] + DEBUGF 1,"Got %u bytes of data\n", ecx - cmp ecx, ebx - ja .too_small + cmp ecx, ebx + ja .too_small - push [esi + socket_queue_entry.buf_ptr] ; save the buffer addr so we can clear it later - mov esi, [esi + socket_queue_entry.data_ptr] - DEBUGF 1,"Source buffer: %x, real addr: %x\n", [esp], esi - mov [esp+32+4], ecx ; return number of bytes copied + push [esi + socket_queue_entry.buf_ptr] ; save the buffer addr so we can clear it later + mov esi, [esi + socket_queue_entry.data_ptr] + DEBUGF 1,"Source buffer: %x, real addr: %x\n", [esp], esi + mov [esp+32+4], ecx ; return number of bytes copied ; copy the data - shr ecx, 1 - jnc .nb - movsb + shr ecx, 1 + jnc .nb + movsb .nb: - shr ecx, 1 - jnc .nw - movsw + shr ecx, 1 + jnc .nw + movsw .nw: - test ecx, ecx - jz .nd - rep movsd + test ecx, ecx + jz .nd + rep movsd .nd: - call kernel_free ; remove the packet - ret + call kernel_free ; remove the packet + ret .too_small: - DEBUGF 1,"Buffer too small...\n" - jmp s_error + DEBUGF 1,"Buffer too small...\n" + jmp s_error align 4 SOCKET_receive_tcp: - DEBUGF 1,"SOCKET_receive: TCP\n" + DEBUGF 1,"SOCKET_receive: TCP\n" - mov ecx, esi - mov edi, edx - add eax, STREAM_SOCKET.rcv - call SOCKET_ring_read - call SOCKET_ring_free + mov ecx, esi + mov edi, edx + add eax, STREAM_SOCKET.rcv + call SOCKET_ring_read + call SOCKET_ring_free - mov [esp+32], ecx ; return number of bytes copied + mov [esp+32], ecx ; return number of bytes copied - ret + ret ;----------------------------------------------------------------- @@ -761,63 +762,63 @@ SOCKET_receive_tcp: align 4 SOCKET_send: - DEBUGF 1,"SOCKET_send: socknum: %u data ptr: %x, length: %u, flags: %x, ", ecx, edx, esi, edi + DEBUGF 1,"SOCKET_send: socknum: %u data ptr: %x, length: %u, flags: %x, ", ecx, edx, esi, edi - call SOCKET_num_to_ptr - jz s_error + call SOCKET_num_to_ptr + jz s_error - mov ecx, esi - mov esi, edx + mov ecx, esi + mov esi, edx - jmp [eax + SOCKET.snd_proc] + jmp [eax + SOCKET.snd_proc] align 4 SOCKET_send_udp: - DEBUGF 1,"SOCKET_send: UDP\n" + DEBUGF 1,"SOCKET_send: UDP\n" - call UDP_output + call UDP_output - mov [esp+32], eax - ret + mov [esp+32], eax + ret align 4 SOCKET_send_tcp: - DEBUGF 1,"SOCKET_send: TCP\n" + DEBUGF 1,"SOCKET_send: TCP\n" - push eax - add eax, STREAM_SOCKET.snd - call SOCKET_ring_write - pop eax + push eax + add eax, STREAM_SOCKET.snd + call SOCKET_ring_write + pop eax - call TCP_output + call TCP_output - mov [esp+32], eax - ret + mov [esp+32], eax + ret align 4 SOCKET_send_ip: - DEBUGF 1,"type: IP\n" + DEBUGF 1,"type: IP\n" - call IPv4_output_raw + call IPv4_output_raw - mov [esp+32], eax - ret + mov [esp+32], eax + ret align 4 SOCKET_send_icmp: - DEBUGF 1,"SOCKET_send: ICMP\n" + DEBUGF 1,"SOCKET_send: ICMP\n" - call ICMP_output_raw + call ICMP_output_raw - mov [esp+32], eax - ret + mov [esp+32], eax + ret @@ -839,17 +840,17 @@ SOCKET_send_icmp: align 4 SOCKET_get_opt: - DEBUGF 1,"SOCKET_get_opt\n" + DEBUGF 1,"SOCKET_get_opt\n" - call SOCKET_num_to_ptr - jz s_error + call SOCKET_num_to_ptr + jz s_error - cmp dword [edx], IP_PROTO_TCP - jne s_error - cmp dword [edx+4], -2 - je @f - cmp dword [edx+4], -3 - jne s_error + cmp dword [edx], IP_PROTO_TCP + jne s_error + cmp dword [edx+4], -2 + je @f + cmp dword [edx+4], -3 + jne s_error @@: ; mov eax, [edx+12] ; test eax, eax @@ -866,13 +867,13 @@ SOCKET_get_opt: ; jz @f ; mov ecx, [eax + TCP_SOCKET.state] @@: - mov eax, [edx+8] - test eax, eax - jz @f - mov [eax], ecx + mov eax, [edx+8] + test eax, eax + jz @f + mov [eax], ecx @@: - mov dword [esp+32], 0 - ret + mov dword [esp+32], 0 + ret @@ -880,7 +881,7 @@ SOCKET_get_opt: align 4 SOCKET_set_opt: - ret + ret @@ -898,18 +899,18 @@ SOCKET_set_opt: align 4 SOCKET_debug: - DEBUGF 1,"socket_debug\n" + DEBUGF 1,"socket_debug\n" - call SOCKET_num_to_ptr - jz s_error + call SOCKET_num_to_ptr + jz s_error - mov esi, eax - mov edi, edx - mov ecx, SOCKETBUFFSIZE/4 - rep movsd + mov esi, eax + mov edi, edx + mov ecx, SOCKETBUFFSIZE/4 + rep movsd - mov dword [esp+32], 0 - ret + mov dword [esp+32], 0 + ret ;----------------------------------------------------------------- @@ -927,49 +928,49 @@ SOCKET_debug: align 4 SOCKET_find_port: - DEBUGF 1,"SOCKET_find_port\n" + DEBUGF 1,"SOCKET_find_port\n" - push ebx esi ecx + push ebx esi ecx - cmp [eax + SOCKET.Protocol], IP_PROTO_UDP - je .udp + cmp [eax + SOCKET.Protocol], IP_PROTO_UDP + je .udp - cmp [eax + SOCKET.Protocol], IP_PROTO_TCP - je .tcp + cmp [eax + SOCKET.Protocol], IP_PROTO_TCP + je .tcp - jmp .error + jmp .error .done: - mov [eax + UDP_SOCKET.LocalPort], bx + mov [eax + UDP_SOCKET.LocalPort], bx .error: - pop ecx esi ebx - ret + pop ecx esi ebx + ret .udp: - mov bx, [last_UDP_port] - call .findit - mov [last_UDP_port], bx - jmp .done + mov bx, [last_UDP_port] + call .findit + mov [last_UDP_port], bx + jmp .done .tcp: - mov bx, [last_TCP_port] - call .findit - mov [last_TCP_port], bx - jmp .done + mov bx, [last_TCP_port] + call .findit + mov [last_TCP_port], bx + jmp .done .restart: - mov bx, MIN_EPHEMERAL_PORT + mov bx, MIN_EPHEMERAL_PORT .findit: - inc bx + inc bx - cmp bx, MAX_EPHEMERAL_PORT - jz .restart + cmp bx, MAX_EPHEMERAL_PORT + jz .restart - call SOCKET_check_port - jz .findit + call SOCKET_check_port + jz .findit - ret + ret @@ -989,30 +990,30 @@ SOCKET_find_port: align 4 SOCKET_check_port: - DEBUGF 1,"SOCKET_check_port\n" + DEBUGF 1,"SOCKET_check_port\n" - mov ecx, [eax + SOCKET.Protocol] - mov esi, net_sockets + mov ecx, [eax + SOCKET.Protocol] + mov esi, net_sockets .next_socket: - mov esi, [esi + SOCKET.NextPtr] - or esi, esi - jz .port_ok + mov esi, [esi + SOCKET.NextPtr] + or esi, esi + jz .port_ok - cmp [esi + SOCKET.Protocol], ecx - jne .next_socket + cmp [esi + SOCKET.Protocol], ecx + jne .next_socket - cmp [esi + UDP_SOCKET.LocalPort], bx - jne .next_socket + cmp [esi + UDP_SOCKET.LocalPort], bx + jne .next_socket - DEBUGF 1,"local port %u already in use\n", bx - ret + DEBUGF 1,"local port %u already in use\n", bx + ret .port_ok: - mov [eax + UDP_SOCKET.LocalPort], bx - or bx, bx ; set the zero-flag + mov [eax + UDP_SOCKET.LocalPort], bx + or bx, bx ; set the zero-flag - ret + ret @@ -1037,26 +1038,26 @@ SOCKET_check_port: align 4 SOCKET_input: - DEBUGF 1,"SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx + DEBUGF 1,"SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx - mov [esp+4], ecx - push esi - mov esi, esp + mov [esp+4], ecx + push esi + mov esi, esp - add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, SOCKET_input.full + add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, SOCKET_input.full - DEBUGF 1,"SOCKET_input: queued packet successfully\n" - add esp, sizeof.socket_queue_entry - mov [eax + SOCKET.lock], 0 - jmp SOCKET_notify_owner + DEBUGF 1,"SOCKET_input: queued packet successfully\n" + add esp, sizeof.socket_queue_entry + mov [eax + SOCKET.lock], 0 + jmp SOCKET_notify_owner .full: - DEBUGF 2,"SOCKET_input: socket %x is full!\n", eax - mov [eax + SOCKET.lock], 0 - call kernel_free - add esp, 8 + DEBUGF 2,"SOCKET_input: socket %x is full!\n", eax + mov [eax + SOCKET.lock], 0 + call kernel_free + add esp, 8 - ret + ret ;-------------------------- @@ -1066,24 +1067,24 @@ SOCKET_input: align 4 SOCKET_ring_create: - push esi - mov esi, eax + push esi + mov esi, eax - push edx - stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SW - pop edx + push edx + stdcall create_ring_buffer, SOCKET_MAXDATA, PG_SW + pop edx - DEBUGF 1,"SOCKET_ring_created: %x\n", eax - mov [esi + RING_BUFFER.start_ptr], eax - mov [esi + RING_BUFFER.write_ptr], eax - mov [esi + RING_BUFFER.read_ptr], eax - mov [esi + RING_BUFFER.size], 0 - add eax, SOCKET_MAXDATA - mov [esi + RING_BUFFER.end_ptr], eax - mov eax, esi - pop esi + DEBUGF 1,"SOCKET_ring_created: %x\n", eax + mov [esi + RING_BUFFER.start_ptr], eax + mov [esi + RING_BUFFER.write_ptr], eax + mov [esi + RING_BUFFER.read_ptr], eax + mov [esi + RING_BUFFER.size], 0 + add eax, SOCKET_MAXDATA + mov [esi + RING_BUFFER.end_ptr], eax + mov eax, esi + pop esi - ret + ret ;----------------------------------------------------------------- ; @@ -1101,55 +1102,55 @@ SOCKET_ring_create: align 4 SOCKET_ring_write: - DEBUGF 1,"SOCKET_ring_write: ringbuff=%x ptr=%x size=%u\n", eax, esi, ecx + DEBUGF 1,"SOCKET_ring_write: ringbuff=%x ptr=%x size=%u\n", eax, esi, ecx - add [eax + RING_BUFFER.size], ecx - cmp [eax + RING_BUFFER.size], SOCKET_MAXDATA - ja .too_large + add [eax + RING_BUFFER.size], ecx + cmp [eax + RING_BUFFER.size], SOCKET_MAXDATA + ja .too_large .copy: - mov edi, [eax + RING_BUFFER.write_ptr] - DEBUGF 2,"SOCKET_ring_write: %u bytes from %x to %x\n", ecx, esi, edi + mov edi, [eax + RING_BUFFER.write_ptr] + DEBUGF 2,"SOCKET_ring_write: %u bytes from %x to %x\n", ecx, esi, edi - push ecx - shr ecx, 1 - jnc .nb - movsb + push ecx + shr ecx, 1 + jnc .nb + movsb .nb: - shr ecx, 1 - jnc .nw - movsw + shr ecx, 1 + jnc .nw + movsw .nw: - test ecx, ecx - jz .nd - rep movsd + test ecx, ecx + jz .nd + rep movsd .nd: - pop ecx + pop ecx - cmp edi, [eax + RING_BUFFER.end_ptr] - jae .wrap - mov [eax + RING_BUFFER.write_ptr], edi + cmp edi, [eax + RING_BUFFER.end_ptr] + jae .wrap + mov [eax + RING_BUFFER.write_ptr], edi - ret + ret .wrap: - sub edi, SOCKET_MAXDATA - mov [eax + RING_BUFFER.write_ptr], edi + sub edi, SOCKET_MAXDATA + mov [eax + RING_BUFFER.write_ptr], edi - ret + ret .too_large: - mov ecx, SOCKET_MAXDATA ; calculate number of bytes available in buffer - sub ecx, [eax + RING_BUFFER.size] - jae .full + mov ecx, SOCKET_MAXDATA ; calculate number of bytes available in buffer + sub ecx, [eax + RING_BUFFER.size] + jae .full - mov [eax + RING_BUFFER.size], SOCKET_MAXDATA ; update size, we will fill buffer completely - jmp .copy + mov [eax + RING_BUFFER.size], SOCKET_MAXDATA ; update size, we will fill buffer completely + jmp .copy .full: - DEBUGF 2,"SOCKET_ring_write: ring buffer is full!\n" - xor ecx, ecx - ret + DEBUGF 2,"SOCKET_ring_write: ring buffer is full!\n" + xor ecx, ecx + ret ;----------------------------------------------------------------- @@ -1168,38 +1169,38 @@ SOCKET_ring_write: align 4 SOCKET_ring_read: - DEBUGF 1,"SOCKET_ring_read: ringbuff=%x ptr=%x size=%u\n", eax, edi, ecx + DEBUGF 1,"SOCKET_ring_read: ringbuff=%x ptr=%x size=%u\n", eax, edi, ecx - cmp ecx, [eax + RING_BUFFER.size] - ja .less_data + cmp ecx, [eax + RING_BUFFER.size] + ja .less_data .copy: - mov esi, [eax + RING_BUFFER.read_ptr] + mov esi, [eax + RING_BUFFER.read_ptr] - DEBUGF 2,"SOCKET_ring_read: %u bytes from %x to %x\n", ecx, esi, edi - push ecx - shr ecx, 1 - jnc .nb - movsb + DEBUGF 2,"SOCKET_ring_read: %u bytes from %x to %x\n", ecx, esi, edi + push ecx + shr ecx, 1 + jnc .nb + movsb .nb: - shr ecx, 1 - jnc .nw - movsw + shr ecx, 1 + jnc .nw + movsw .nw: - test ecx, ecx - jz .nd - rep movsd + test ecx, ecx + jz .nd + rep movsd .nd: - pop ecx + pop ecx .no_data_at_all: - ret + ret .less_data: - mov ecx, [eax + RING_BUFFER.size] + mov ecx, [eax + RING_BUFFER.size] ; test ecx, ecx ; jz .no_data_at_all - jmp .copy + jmp .copy ;----------------------------------------------------------------- @@ -1217,23 +1218,23 @@ SOCKET_ring_read: align 4 SOCKET_ring_free: - DEBUGF 1,"SOCKET_ring_free: %u bytes from ring %x\n", ecx, eax + DEBUGF 1,"SOCKET_ring_free: %u bytes from ring %x\n", ecx, eax - sub [eax + RING_BUFFER.size], ecx - jb .sumthinwong - add [eax + RING_BUFFER.read_ptr], ecx + sub [eax + RING_BUFFER.size], ecx + jb .sumthinwong + add [eax + RING_BUFFER.read_ptr], ecx - mov edx, [eax + RING_BUFFER.end_ptr] - cmp [eax + RING_BUFFER.read_ptr], edx - jb @f - sub [eax + RING_BUFFER.read_ptr], SOCKET_MAXDATA + mov edx, [eax + RING_BUFFER.end_ptr] + cmp [eax + RING_BUFFER.read_ptr], edx + jb @f + sub [eax + RING_BUFFER.read_ptr], SOCKET_MAXDATA @@: - ret + ret - .sumthinwong: ; we could free all available bytes, but that would be stupid, i guess.. - add [eax + RING_BUFFER.size], ecx - xor ecx, ecx - ret + .sumthinwong: ; we could free all available bytes, but that would be stupid, i guess.. + add [eax + RING_BUFFER.size], ecx + xor ecx, ecx + ret ;----------------------------------------------------------------- @@ -1249,44 +1250,44 @@ SOCKET_ring_free: align 4 SOCKET_notify_owner: - DEBUGF 1,"SOCKET_notify_owner: %x\n", eax + DEBUGF 1,"SOCKET_notify_owner: %x\n", eax - call SOCKET_check - jz .error + call SOCKET_check + jz .error - push eax ecx esi + push eax ecx esi ; socket exists, now try to flag an event to the application - mov eax, [eax + SOCKET.PID] - mov ecx, 1 - mov esi, TASK_DATA + TASKDATA.pid + mov eax, [eax + SOCKET.PID] + mov ecx, 1 + mov esi, TASK_DATA + TASKDATA.pid .next_pid: - cmp [esi], eax - je .found_pid - inc ecx - add esi, 0x20 - cmp ecx, [TASK_COUNT] - jbe .next_pid + cmp [esi], eax + je .found_pid + inc ecx + add esi, 0x20 + cmp ecx, [TASK_COUNT] + jbe .next_pid ; PID not found, TODO: close socket! - jmp .error2 + jmp .error2 .found_pid: - shl ecx, 8 - or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK - mov [check_idle_semaphore], 200 + shl ecx, 8 + or [ecx + SLOT_BASE + APPDATA.event_mask], EVENT_NETWORK + mov [check_idle_semaphore], 200 - DEBUGF 1,"SOCKET_notify_owner: succes!\n" + DEBUGF 1,"SOCKET_notify_owner: succes!\n" .error2: - pop esi ecx eax + pop esi ecx eax .error: - ret + ret ;-------------------------------------------------------------------- @@ -1306,74 +1307,74 @@ SOCKET_notify_owner: align 4 SOCKET_alloc: - push ecx ebx + push ecx ebx - stdcall kernel_alloc, SOCKETBUFFSIZE - DEBUGF 1, "SOCKET_alloc: ptr=%x\n", eax - or eax, eax - jz .exit + stdcall kernel_alloc, SOCKETBUFFSIZE + DEBUGF 1, "SOCKET_alloc: ptr=%x\n", eax + or eax, eax + jz .exit ; zero-initialize allocated memory - push eax edi - mov edi, eax - mov ecx, SOCKETBUFFSIZE / 4 - xor eax, eax - rep stosd - pop edi eax + push eax edi + mov edi, eax + mov ecx, SOCKETBUFFSIZE / 4 + xor eax, eax + rep stosd + pop edi eax ; set send-and receive procedures to return -1 - mov [eax + SOCKET.snd_proc], s_error - mov [eax + SOCKET.rcv_proc], s_error + mov [eax + SOCKET.snd_proc], s_error + mov [eax + SOCKET.rcv_proc], s_error ; find first free socket number and use it - mov ecx, [last_socket_num] + mov ecx, [last_socket_num] .next_socket_number: - inc ecx - jz .next_socket_number ; avoid socket nr 0 - cmp ecx, -1 - je .next_socket_number ; avoid socket nr -1 - mov ebx, net_sockets + inc ecx + jz .next_socket_number ; avoid socket nr 0 + cmp ecx, -1 + je .next_socket_number ; avoid socket nr -1 + mov ebx, net_sockets .next_socket: - mov ebx, [ebx + SOCKET.NextPtr] - test ebx, ebx - jz .last_socket + mov ebx, [ebx + SOCKET.NextPtr] + test ebx, ebx + jz .last_socket - cmp [ebx + SOCKET.Number], ecx - jne .next_socket - jmp .next_socket_number + cmp [ebx + SOCKET.Number], ecx + jne .next_socket + jmp .next_socket_number .last_socket: - mov [last_socket_num], ecx - mov [eax + SOCKET.Number], ecx - DEBUGF 1, "SOCKET_alloc: number=%u\n", ecx - mov edi, ecx + mov [last_socket_num], ecx + mov [eax + SOCKET.Number], ecx + DEBUGF 1, "SOCKET_alloc: number=%u\n", ecx + mov edi, ecx ; Fill in PID - mov ebx, [TASK_BASE] - mov ebx, [ebx + TASKDATA.pid] - mov [eax + SOCKET.PID], ebx + mov ebx, [TASK_BASE] + mov ebx, [ebx + TASKDATA.pid] + mov [eax + SOCKET.PID], ebx ; add socket to the list by re-arranging some pointers - mov ebx, [net_sockets + SOCKET.NextPtr] + mov ebx, [net_sockets + SOCKET.NextPtr] - mov [eax + SOCKET.PrevPtr], net_sockets - mov [eax + SOCKET.NextPtr], ebx + mov [eax + SOCKET.PrevPtr], net_sockets + mov [eax + SOCKET.NextPtr], ebx - test ebx, ebx - jz @f - add ebx, SOCKET.lock ; lock the next socket - call wait_mutex - sub ebx, SOCKET.lock - mov [ebx + SOCKET.PrevPtr], eax - mov [ebx + SOCKET.lock], 0 ; and unlock it again + test ebx, ebx + jz @f + add ebx, SOCKET.lock ; lock the next socket + call wait_mutex + sub ebx, SOCKET.lock + mov [ebx + SOCKET.PrevPtr], eax + mov [ebx + SOCKET.lock], 0 ; and unlock it again @@: - mov [net_sockets + SOCKET.NextPtr], eax - or eax, eax ; used to clear zero flag + mov [net_sockets + SOCKET.NextPtr], eax + or eax, eax ; used to clear zero flag .exit: - pop ebx ecx + pop ebx ecx - ret + ret ;---------------------------------------------------- @@ -1389,52 +1390,52 @@ SOCKET_alloc: align 4 SOCKET_free: - DEBUGF 1, "SOCKET_free: %x\n", eax + DEBUGF 1, "SOCKET_free: %x\n", eax - call SOCKET_check - jz .error + call SOCKET_check + jz .error - push ebx - lea ebx, [eax + SOCKET.lock] - call wait_mutex + push ebx + lea ebx, [eax + SOCKET.lock] + call wait_mutex - DEBUGF 1, "SOCKET_free: freeing socket..\n" + DEBUGF 1, "SOCKET_free: freeing socket..\n" - cmp [eax + SOCKET.Domain], AF_INET4 - jnz .no_tcp + cmp [eax + SOCKET.Domain], AF_INET4 + jnz .no_tcp - cmp [eax + SOCKET.Protocol], IP_PROTO_TCP - jnz .no_tcp + cmp [eax + SOCKET.Protocol], IP_PROTO_TCP + jnz .no_tcp - mov ebx, eax - stdcall kernel_free, [ebx + STREAM_SOCKET.rcv + RING_BUFFER.start_ptr] - stdcall kernel_free, [ebx + STREAM_SOCKET.snd + RING_BUFFER.start_ptr] - mov eax, ebx + mov ebx, eax + stdcall kernel_free, [ebx + STREAM_SOCKET.rcv + RING_BUFFER.start_ptr] + stdcall kernel_free, [ebx + STREAM_SOCKET.snd + RING_BUFFER.start_ptr] + mov eax, ebx .no_tcp: - push eax ; this will be passed to kernel_free - mov ebx, [eax + SOCKET.NextPtr] - mov eax, [eax + SOCKET.PrevPtr] + push eax ; this will be passed to kernel_free + mov ebx, [eax + SOCKET.NextPtr] + mov eax, [eax + SOCKET.PrevPtr] - DEBUGF 1, "SOCKET_free: linking socket %x to socket %x\n", eax, ebx + DEBUGF 1, "SOCKET_free: linking socket %x to socket %x\n", eax, ebx - test eax, eax - jz @f - mov [eax + SOCKET.NextPtr], ebx + test eax, eax + jz @f + mov [eax + SOCKET.NextPtr], ebx @@: - test ebx, ebx - jz @f - mov [ebx + SOCKET.PrevPtr], eax + test ebx, ebx + jz @f + mov [ebx + SOCKET.PrevPtr], eax @@: - call kernel_free - pop ebx + call kernel_free + pop ebx - DEBUGF 1, "SOCKET_free: success!\n" + DEBUGF 1, "SOCKET_free: success!\n" .error: - ret + ret ;------------------------------------ ; @@ -1449,41 +1450,41 @@ SOCKET_free: align 4 SOCKET_fork: - DEBUGF 1,"SOCKET_fork: %x\n", ebx + DEBUGF 1,"SOCKET_fork: %x\n", ebx ; Exit if backlog queue is full - mov eax, [ebx + SOCKET_QUEUE_LOCATION + queue.size] - cmp ax, [ebx + SOCKET.backlog] - jae .fail + mov eax, [ebx + SOCKET_QUEUE_LOCATION + queue.size] + cmp ax, [ebx + SOCKET.backlog] + jae .fail ; Allocate new socket - call SOCKET_alloc - jz .fail + call SOCKET_alloc + jz .fail - push esi ecx edi - push eax - mov esi, esp - add_to_queue (ebx + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .fail2 - pop eax + push esi ecx edi + push eax + mov esi, esp + add_to_queue (ebx + SOCKET_QUEUE_LOCATION), MAX_backlog, 4, .fail2 + pop eax ; Copy structure from current socket to new ; We start at PID to preserve the socket num, and the 2 pointers at beginning of socket - lea esi, [ebx + SOCKET.PID] - lea edi, [eax + SOCKET.PID] - mov ecx, (SOCKET_QUEUE_LOCATION - SOCKET.PID + 3)/4 - rep movsd + lea esi, [ebx + SOCKET.PID] + lea edi, [eax + SOCKET.PID] + mov ecx, (SOCKET_QUEUE_LOCATION - SOCKET.PID + 3)/4 + rep movsd - and [eax + SOCKET.options], not SO_ACCEPTCON - pop edi ecx esi + and [eax + SOCKET.options], not SO_ACCEPTCON + pop edi ecx esi - ret + ret .fail2: - add esp, 4+4+4 + add esp, 4+4+4 .fail: - DEBUGF 1,"SOCKET_fork: failed\n" - xor eax, eax - ret + DEBUGF 1,"SOCKET_fork: failed\n" + xor eax, eax + ret ;--------------------------------------------------- @@ -1500,22 +1501,22 @@ SOCKET_fork: align 4 SOCKET_num_to_ptr: - DEBUGF 1,"SOCKET_num_to_ptr: %u ", ecx + DEBUGF 1,"SOCKET_num_to_ptr: %u ", ecx - mov eax, net_sockets + mov eax, net_sockets .next_socket: - mov eax, [eax + SOCKET.NextPtr] - or eax, eax - jz .error - cmp [eax + SOCKET.Number], ecx - jne .next_socket + mov eax, [eax + SOCKET.NextPtr] + or eax, eax + jz .error + cmp [eax + SOCKET.Number], ecx + jne .next_socket - test eax, eax + test eax, eax - DEBUGF 1,"(%x)\n", eax + DEBUGF 1,"(%x)\n", eax .error: - ret + ret ;--------------------------------------------------- @@ -1532,17 +1533,17 @@ SOCKET_num_to_ptr: align 4 SOCKET_ptr_to_num: - DEBUGF 1,"SOCKET_ptr_to_num: %x ", eax + DEBUGF 1,"SOCKET_ptr_to_num: %x ", eax - call SOCKET_check - jz .error + call SOCKET_check + jz .error - mov eax, [eax + SOCKET.Number] + mov eax, [eax + SOCKET.Number] - DEBUGF 1,"(%u)\n", eax + DEBUGF 1,"(%u)\n", eax .error: - ret + ret ;--------------------------------------------------- @@ -1559,24 +1560,24 @@ SOCKET_ptr_to_num: align 4 SOCKET_check: - DEBUGF 1,"SOCKET_check: %x\n", eax + DEBUGF 1,"SOCKET_check: %x\n", eax - push ebx - mov ebx, net_sockets + push ebx + mov ebx, net_sockets .next_socket: - mov ebx, [ebx + SOCKET.NextPtr] - or ebx, ebx - jz .done - cmp ebx, eax - jnz .next_socket + mov ebx, [ebx + SOCKET.NextPtr] + or ebx, ebx + jz .done + cmp ebx, eax + jnz .next_socket .done: - mov eax, ebx - test eax, eax - pop ebx + mov eax, ebx + test eax, eax + pop ebx - ret + ret @@ -1593,15 +1594,15 @@ SOCKET_check: align 4 SOCKET_check_owner: - DEBUGF 1,"SOCKET_check_owner: %x\n", eax + DEBUGF 1,"SOCKET_check_owner: %x\n", eax - push ebx - mov ebx, [TASK_BASE] - mov ebx, [ecx + TASKDATA.pid] - cmp [eax + SOCKET.PID], ebx - pop ebx + push ebx + mov ebx, [TASK_BASE] + mov ebx, [ecx + TASKDATA.pid] + cmp [eax + SOCKET.PID], ebx + pop ebx - ret + ret @@ -1621,49 +1622,49 @@ SOCKET_check_owner: align 4 SOCKET_process_end: - DEBUGF 1,"SOCKET_process_end: %x\n", eax + DEBUGF 1,"SOCKET_process_end: %x\n", eax - push ebx - mov ebx, net_sockets + push ebx + mov ebx, net_sockets .next_socket: - mov ebx, [ebx + SOCKET.NextPtr] + mov ebx, [ebx + SOCKET.NextPtr] .test_socket: - test ebx, ebx - jz .done + test ebx, ebx + jz .done - cmp [ebx + SOCKET.PID], eax - jne .next_socket + cmp [ebx + SOCKET.PID], eax + jne .next_socket - DEBUGF 1,"closing socket %x", eax, ebx + DEBUGF 1,"closing socket %x", eax, ebx - mov [ebx + SOCKET.PID], 0 + mov [ebx + SOCKET.PID], 0 - cmp [ebx + SOCKET.Protocol], IP_PROTO_UDP - je .udp + cmp [ebx + SOCKET.Protocol], IP_PROTO_UDP + je .udp - cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP - je .tcp + cmp [ebx + SOCKET.Protocol], IP_PROTO_TCP + je .tcp - jmp .next_socket ; kill all sockets for given PID + jmp .next_socket ; kill all sockets for given PID .udp: - mov eax, ebx - mov ebx, [ebx + SOCKET.NextPtr] - call SOCKET_free - jmp .test_socket + mov eax, ebx + mov ebx, [ebx + SOCKET.NextPtr] + call SOCKET_free + jmp .test_socket .tcp: - ;;; TODO + ;;; TODO - jmp .next_socket + jmp .next_socket .done: - pop ebx + pop ebx - ret + ret @@ -1681,10 +1682,10 @@ align 4 SOCKET_is_connecting: - and [eax + SOCKET.options], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING) - or [eax + SOCKET.options], SS_ISCONNECTING + and [eax + SOCKET.options], not (SS_ISCONNECTED + SS_ISDISCONNECTING + SS_ISCONFIRMING) + or [eax + SOCKET.options], SS_ISCONNECTING - jmp SOCKET_notify_owner + jmp SOCKET_notify_owner @@ -1701,10 +1702,10 @@ align 4 SOCKET_is_connected: - and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING) - or [eax + SOCKET.options], SS_ISCONNECTED + and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISDISCONNECTING + SS_ISCONFIRMING) + or [eax + SOCKET.options], SS_ISCONNECTED - jmp SOCKET_notify_owner + jmp SOCKET_notify_owner @@ -1721,10 +1722,10 @@ SOCKET_is_connected: align 4 SOCKET_is_disconnecting: - and [eax + SOCKET.options], not (SS_ISCONNECTING) - or [eax + SOCKET.options], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE + and [eax + SOCKET.options], not (SS_ISCONNECTING) + or [eax + SOCKET.options], SS_ISDISCONNECTING + SS_CANTRCVMORE + SS_CANTSENDMORE - jmp SOCKET_notify_owner + jmp SOCKET_notify_owner @@ -1740,10 +1741,10 @@ SOCKET_is_disconnecting: align 4 SOCKET_is_disconnected: - and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING) - or [eax + SOCKET.options], SS_CANTRCVMORE + SS_CANTSENDMORE + and [eax + SOCKET.options], not (SS_ISCONNECTING + SS_ISCONNECTED + SS_ISDISCONNECTING) + or [eax + SOCKET.options], SS_CANTRCVMORE + SS_CANTSENDMORE - jmp SOCKET_notify_owner + jmp SOCKET_notify_owner ;----------------------------------------------------------------- @@ -1758,9 +1759,9 @@ SOCKET_is_disconnected: align 4 SOCKET_cant_recv_more: - or [eax + SOCKET.options], SS_CANTRCVMORE + or [eax + SOCKET.options], SS_CANTRCVMORE - ret + ret @@ -1776,6 +1777,6 @@ SOCKET_cant_recv_more: align 4 SOCKET_cant_send_more: - or [eax + SOCKET.options], SS_CANTSENDMORE + or [eax + SOCKET.options], SS_CANTSENDMORE - ret \ No newline at end of file + ret \ No newline at end of file diff --git a/kernel/branches/net/network/tcp_input.inc b/kernel/branches/net/network/tcp_input.inc index b72dfdf372..f0e9338834 100644 --- a/kernel/branches/net/network/tcp_input.inc +++ b/kernel/branches/net/network/tcp_input.inc @@ -24,7 +24,7 @@ $Revision$ ; [esp+4] = buffer size ; ebx = ptr to device struct ; ecx = segment size -; edx = ptr to TCP segment +; esi = ptr to TCP segment ; edi = ptr to ipv4 source address, followed by ipv4 dest address ; ; OUT: / @@ -36,18 +36,17 @@ TCP_input: DEBUGF 1,"TCP_input size=%u\n", ecx - 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 + and [esi + TCP_header.DataOffset], 0xf0 ; Calculate TCP segment header size (throwing away unused reserved bits in TCP header) + shr [esi + TCP_header.DataOffset], 2 + cmp [esi + 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 ;------------------------------- ; Now, re-calculate the checksum - push ecx edx - pushw [edx + TCP_header.Checksum] - mov [edx + TCP_header.Checksum], 0 - mov esi, edx + push ecx esi + pushw [esi + TCP_header.Checksum] + mov [esi + TCP_header.Checksum], 0 TCP_checksum (edi), (edi+4) pop cx ; previous checksum cmp cx, dx @@ -56,14 +55,15 @@ TCP_input: DEBUGF 1,"Checksum ok\n" - sub ecx, [edx + TCP_header.DataOffset] ; substract TCP header size from total segment size + 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 DEBUGF 1,"we got %u bytes of data\n", ecx ;----------------------------------------------------------------------------------------- ; Check if this packet has a timestamp option (We do it here so we can process it quickly) - cmp [edx + TCP_header.DataOffset], sizeof.TCP_header + 12 ; Timestamp option is 12 bytes + cmp eax, sizeof.TCP_header + 12 ; Timestamp option is 12 bytes jb .no_timestamp je .is_ok @@ -202,8 +202,8 @@ TCP_input: ;-------------------- ; Process TCP options - mov eax, [edx + TCP_header.DataOffset] - cmp eax, TCP_header.DataOffset ; Does header contain any options? + movzx eax, [edx + TCP_header.DataOffset] + cmp eax, sizeof.TCP_header ; Does header contain any options? je .no_options DEBUGF 1,"Segment has options\n" diff --git a/kernel/branches/net/network/udp.inc b/kernel/branches/net/network/udp.inc index d9c38f0dda..d9d3478f3a 100644 --- a/kernel/branches/net/network/udp.inc +++ b/kernel/branches/net/network/udp.inc @@ -17,7 +17,7 @@ $Revision$ -struct UDP_Packet +struct UDP_header SourcePort dw ? DestinationPort dw ? @@ -65,33 +65,33 @@ macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size adc dl, [IP2+3] adc dh, [IP2+2] - adc dl, cl ; byte[esi+UDP_Packet.Length+1] - adc dh, ch ; byte[esi+UDP_Packet.Length+0] + adc dl, cl ; byte[esi+UDP_header.Length+1] + adc dh, ch ; byte[esi+UDP_header.Length+0] ; Done with pseudoheader, now do real header - adc dl, byte[esi+UDP_Packet.SourcePort+1] - adc dh, byte[esi+UDP_Packet.SourcePort+0] + adc dl, byte[esi+UDP_header.SourcePort+1] + adc dh, byte[esi+UDP_header.SourcePort+0] - adc dl, byte[esi+UDP_Packet.DestinationPort+1] - adc dh, byte[esi+UDP_Packet.DestinationPort+0] + adc dl, byte[esi+UDP_header.DestinationPort+1] + adc dh, byte[esi+UDP_header.DestinationPort+0] - adc dl, byte[esi+UDP_Packet.Length+1] - adc dh, byte[esi+UDP_Packet.Length+0] + adc dl, byte[esi+UDP_header.Length+1] + adc dh, byte[esi+UDP_header.Length+0] adc edx, 0 ; Done with header, now do data push esi - movzx ecx, [esi+UDP_Packet.Length] + movzx ecx, [esi+UDP_header.Length] rol cx , 8 - sub cx , sizeof.UDP_Packet - add esi, sizeof.UDP_Packet + sub cx , sizeof.UDP_header + add esi, sizeof.UDP_header call checksum_1 call checksum_2 pop esi - add [esi+UDP_Packet.Checksum], dx ; this final instruction will set or clear ZF :) + add [esi+UDP_header.Checksum], dx ; this final instruction will set or clear ZF :) } @@ -107,7 +107,7 @@ macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size ; [esp+4] = size of buffer ; ebx = ptr to device struct ; ecx = UDP Packet size -; edx = ptr to UDP header +; esi = ptr to UDP header ; edi = ptr to ipv4 source and dest address ; ; OUT: / @@ -118,40 +118,46 @@ UDP_input: DEBUGF 1,"UDP_input, size:%u\n", ecx -; First validate, checksum: - neg [edx+UDP_Packet.Checksum] ; substract chechksum from 0 +; First validate, checksum + + neg [esi + UDP_header.Checksum] ; substract checksum from 0 jz .no_checksum ; if checksum is zero, it is considered valid and we continue processing ; otherwise, we will re-calculate the checksum and add it to this value, thus creating 0 when it is correct - push edx - push edi push esi - mov esi, edx UDP_checksum (edi), (edi+4) - pop edi - pop esi ; we dont need it, but it is smaller then add esp, 4 pop edx jnz .checksum_mismatch .no_checksum: DEBUGF 1,"UDP Checksum is correct\n" + ; Convert port numbers to intel format + + rol [edx + UDP_header.DestinationPort], 8 + rol [edx + UDP_header.SourcePort], 8 + rol [edx + UDP_header.Length], 8 + ; Look for a socket where ; IP Packet UDP Destination Port = local Port ; IP Packet SA = Remote IP + mov si, [edx + UDP_header.DestinationPort] + mov cx, [edx + UDP_header.SourcePort] + mov edi, [edi + 4] ; ipv4 source address mov eax, net_sockets - .try_more: - mov si , [edx + UDP_Packet.DestinationPort] ; get the local port from the IP Packet's UDP header - rol si , 8 + .next_socket: mov eax, [eax + SOCKET.NextPtr] or eax, eax jz .dump + cmp [eax + SOCKET.Domain], AF_INET4 jne .next_socket + cmp [eax + SOCKET.Protocol], IP_PROTO_UDP jne .next_socket + cmp [eax + UDP_SOCKET.LocalPort], si jne .next_socket @@ -161,17 +167,14 @@ UDP_input: cmp [eax + IP_SOCKET.RemoteIP], 0xffffffff je @f - mov edi, [edi + 4] ; ipv4 source address cmp [eax + IP_SOCKET.RemoteIP], edi - jne .try_more + jne .next_socket @@: cmp [eax + UDP_SOCKET.firstpacket], 0 jz .updateport - mov si, [edx + UDP_Packet.SourcePort] - rol si, 8 - cmp [eax + UDP_SOCKET.RemotePort], si + cmp [eax + UDP_SOCKET.RemotePort], cx jne .dump push ebx @@ -182,10 +185,9 @@ UDP_input: .updatesock: inc [UDP_PACKETS_RX] DEBUGF 1,"Found valid UDP packet for socket %x\n", eax - lea esi, [edx + sizeof.UDP_Packet] - movzx ecx, [edx + UDP_Packet.Length] - rol cx , 8 - sub cx , sizeof.UDP_Packet + lea esi, [edx + sizeof.UDP_header] + movzx ecx, [edx + UDP_header.Length] + sub ecx, sizeof.UDP_header jmp SOCKET_input @@ -195,8 +197,7 @@ UDP_input: call wait_mutex pop ebx - mov si, [edx + UDP_Packet.SourcePort] - rol si, 8 + mov si, [edx + UDP_header.SourcePort] DEBUGF 1,"Changing remote port to: %u\n", si mov [eax + UDP_SOCKET.RemotePort], si inc [eax + UDP_SOCKET.firstpacket] @@ -246,7 +247,7 @@ UDP_output: mov di, IP_PROTO_UDP shl 8 + 128 sub esp, 8 ; Data ptr and data size will be placed here - add ecx, sizeof.UDP_Packet + add ecx, sizeof.UDP_header ;;; TODO: fragment id push edx esi @@ -256,13 +257,13 @@ UDP_output: mov [esp + 8], eax ; pointer to buffer start mov [esp + 8 + 4], edx ; buffer size - mov [edi + UDP_Packet.Length], cx - rol [edi + UDP_Packet.Length], 8 + mov [edi + UDP_header.Length], cx + rol [edi + UDP_header.Length], 8 pop esi push edi ecx - sub ecx, sizeof.UDP_Packet - add edi, sizeof.UDP_Packet + sub ecx, sizeof.UDP_header + add edi, sizeof.UDP_header shr ecx, 2 rep movsd mov ecx, [esp] @@ -270,11 +271,11 @@ UDP_output: rep movsb pop ecx edi - pop dword [edi + UDP_Packet.SourcePort] + pop dword [edi + UDP_header.SourcePort] ; Checksum mov esi, edi - mov [edi + UDP_Packet.Checksum], 0 + mov [edi + UDP_header.Checksum], 0 UDP_checksum (edi-4), (edi-8) ; TODO: fix this, IPv4 packet could have options.. inc [UDP_PACKETS_TX]