diff --git a/kernel/trunk/network/ARP.inc b/kernel/trunk/network/ARP.inc index 81d1b9cbb7..211134258d 100644 --- a/kernel/trunk/network/ARP.inc +++ b/kernel/trunk/network/ARP.inc @@ -55,9 +55,8 @@ struct ARP_header ends -align 4 uglobal - +align 4 ARP_table rb NET_DEVICES_MAX*(ARP_TABLE_SIZE * sizeof.ARP_entry) diff --git a/kernel/trunk/network/IPv4.inc b/kernel/trunk/network/IPv4.inc index 248161319e..f1f357d180 100644 --- a/kernel/trunk/network/IPv4.inc +++ b/kernel/trunk/network/IPv4.inc @@ -55,8 +55,8 @@ struct FRAGMENT_entry ; This structure will replace the ethern ends -align 4 uglobal +align 4 IP_LIST rd NET_DEVICES_MAX SUBNET_LIST rd NET_DEVICES_MAX @@ -69,6 +69,7 @@ uglobal IP_packets_dumped rd NET_DEVICES_MAX FRAGMENT_LIST rb MAX_FRAGMENTS * sizeof.FRAGMENT_slot + endg diff --git a/kernel/trunk/network/IPv6.inc b/kernel/trunk/network/IPv6.inc index 0766eea424..6eedd10a4f 100644 --- a/kernel/trunk/network/IPv6.inc +++ b/kernel/trunk/network/IPv6.inc @@ -30,8 +30,8 @@ struct IPv6_header ends -align 4 uglobal +align 4 IPv6: .addresses rd 4*NET_DEVICES_MAX diff --git a/kernel/trunk/network/PPPoE.inc b/kernel/trunk/network/PPPoE.inc index 119f85e0d9..4b00890936 100644 --- a/kernel/trunk/network/PPPoE.inc +++ b/kernel/trunk/network/PPPoE.inc @@ -23,8 +23,11 @@ struct PPPoE_frame ends uglobal +align 4 + PPPoE_SID dw ? PPPoE_MAC dp ? + endg ;----------------------------------------------------------------- diff --git a/kernel/trunk/network/ethernet.inc b/kernel/trunk/network/ethernet.inc index 6c12f55c3e..26dcb2d935 100644 --- a/kernel/trunk/network/ethernet.inc +++ b/kernel/trunk/network/ethernet.inc @@ -32,8 +32,8 @@ struct ETH_DEVICE NET_DEVICE ends -align 4 iglobal +align 4 ETH_BROADCAST dp 0xffffffffffff endg diff --git a/kernel/trunk/network/icmp.inc b/kernel/trunk/network/icmp.inc index f8666e848a..06eb5a75d1 100644 --- a/kernel/trunk/network/icmp.inc +++ b/kernel/trunk/network/icmp.inc @@ -97,10 +97,12 @@ struct ICMP_header ends -align 4 uglobal +align 4 + ICMP_PACKETS_TX rd NET_DEVICES_MAX ICMP_PACKETS_RX rd NET_DEVICES_MAX + endg diff --git a/kernel/trunk/network/loopback.inc b/kernel/trunk/network/loopback.inc index 24e2e7cdea..6c788ff972 100644 --- a/kernel/trunk/network/loopback.inc +++ b/kernel/trunk/network/loopback.inc @@ -17,6 +17,7 @@ $Revision: 2891 $ iglobal +align 4 LOOPBACK_DEVICE: diff --git a/kernel/trunk/network/queue.inc b/kernel/trunk/network/queue.inc index eae232df99..41ce1a3b23 100644 --- a/kernel/trunk/network/queue.inc +++ b/kernel/trunk/network/queue.inc @@ -23,11 +23,12 @@ $Revision: 2305 $ ; (you can see some examples below) -struct queue +struct queue - size dd ? ; number of queued packets in this queue - w_ptr dd ? ; current writing pointer in queue - r_ptr dd ? ; current reading pointer + size dd ? ; number of queued packets in this queue + w_ptr dd ? ; current writing pointer in queue + r_ptr dd ? ; current reading pointer + mutex MUTEX ends @@ -44,23 +45,41 @@ ends macro add_to_queue ptr, size, entry_size, failaddr { - cmp [ptr + queue.size], size ; Check if queue isnt full - jae failaddr +local .ok, .no_wrap - inc [ptr + queue.size] ; if not full, queue one more + pusha + lea ecx, [ptr + queue.mutex] + call mutex_lock + popa - mov edi, [ptr + queue.w_ptr] ; Current write pointer (FIFO!) - mov ecx, entry_size/4 ; Write the queue entry - rep movsd ; + cmp [ptr + queue.size], size ; Check if queue isnt full + jb .ok - lea ecx, [size*entry_size+ptr+sizeof.queue] - cmp edi, ecx ; entry size - jb .no_wrap + pusha + lea ecx, [ptr + queue.mutex] + call mutex_unlock + popa + jmp failaddr - sub edi, size*entry_size + .ok: + inc [ptr + queue.size] ; if not full, queue one more + mov edi, [ptr + queue.w_ptr] ; Current write pointer (FIFO!) + mov ecx, entry_size/4 ; Write the queue entry + rep movsd ; + + lea ecx, [size*entry_size+ptr+sizeof.queue] + cmp edi, ecx ; entry size + jb .no_wrap + + sub edi, size*entry_size .no_wrap: - mov [ptr + queue.w_ptr], edi + mov [ptr + queue.w_ptr], edi + + pusha + lea ecx, [ptr + queue.mutex] + call mutex_unlock + popa } @@ -68,33 +87,55 @@ macro add_to_queue ptr, size, entry_size, failaddr { macro get_from_queue ptr, size, entry_size, failaddr { - cmp [ptr + queue.size], 0 ; any packets queued? - je failaddr +local .ok, .no_wrap - dec [ptr + queue.size] ; if so, dequeue one + pusha + lea ecx, [ptr + queue.mutex] + call mutex_lock + popa - mov esi, [ptr + queue.r_ptr] - push esi + cmp [ptr + queue.size], 0 ; any packets queued? + ja .ok - add esi, entry_size + pusha + lea ecx, [ptr + queue.mutex] + call mutex_unlock + popa + jmp failaddr - lea ecx, [size*entry_size+ptr+sizeof.queue] - cmp esi, ecx ; entry size - jb .no_wrap + .ok: + dec [ptr + queue.size] ; if so, dequeue one - sub esi, size*entry_size + mov esi, [ptr + queue.r_ptr] + push esi + + add esi, entry_size + + lea ecx, [size*entry_size+ptr+sizeof.queue] + cmp esi, ecx ; entry size + jb .no_wrap + + sub esi, size*entry_size .no_wrap: - mov dword [ptr + queue.r_ptr], esi + mov dword [ptr + queue.r_ptr], esi - pop esi + pop esi + + pusha + lea ecx, [ptr + queue.mutex] + call mutex_unlock + popa } macro init_queue ptr { - mov [ptr + queue.size] , 0 - lea edi, [ptr + sizeof.queue] - mov [ptr + queue.w_ptr], edi - mov [ptr + queue.r_ptr], edi + mov [ptr + queue.size] , 0 + lea edi, [ptr + sizeof.queue] + mov [ptr + queue.w_ptr], edi + mov [ptr + queue.r_ptr], edi + + lea ecx, [ptr + queue.mutex] + call mutex_init } \ No newline at end of file diff --git a/kernel/trunk/network/socket.inc b/kernel/trunk/network/socket.inc index 34260c77ac..24af1fdb29 100644 --- a/kernel/trunk/network/socket.inc +++ b/kernel/trunk/network/socket.inc @@ -194,11 +194,14 @@ SOCKET_QUEUE_SIZE = 10 ; maximum number of incoming packets queued f SOCKET_QUEUE_LOCATION = (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue) uglobal +align 4 + 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 ? ; socket_mutex MUTEX + endg @@ -614,8 +617,9 @@ align 4 .loop: cmp [eax + TCP_SOCKET.t_state], TCPS_CLOSED je .fail - cmp [eax + TCP_SOCKET.t_state], TCPS_SYN_SENT - jne .syn_received + cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED + je .established + ja .fail call SOCKET_block jmp .loop @@ -626,7 +630,7 @@ align 4 mov dword[esp+32], -1 ret - .syn_received: + .established: mov dword[esp+32], 0 ret diff --git a/kernel/trunk/network/stack.inc b/kernel/trunk/network/stack.inc index 57a26da28e..87f90510a7 100644 --- a/kernel/trunk/network/stack.inc +++ b/kernel/trunk/network/stack.inc @@ -221,8 +221,8 @@ include "socket.inc" -align 4 uglobal +align 4 NET_RUNNING dd ? NET_DRV_LIST rd NET_DEVICES_MAX diff --git a/kernel/trunk/network/udp.inc b/kernel/trunk/network/udp.inc index 4bab3893c8..8f967f7cb6 100644 --- a/kernel/trunk/network/udp.inc +++ b/kernel/trunk/network/udp.inc @@ -27,10 +27,12 @@ struct UDP_header ends -align 4 uglobal +align 4 + UDP_PACKETS_TX rd NET_DEVICES_MAX UDP_PACKETS_RX rd NET_DEVICES_MAX + endg @@ -114,6 +116,7 @@ macro UDP_checksum IP1, IP2 { ; esi = ptr to udp packet, ecx = packet size ; ;----------------------------------------------------------------- align 4 +diff16 "UDP packetgfgfgfgfs", 0, $ UDP_input: DEBUGF DEBUG_NETWORK_VERBOSE, "UDP_input: size=%u\n", ecx