Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 5522 → Rev 5521

/kernel/trunk/network/socket.inc
179,8 → 179,8
struct socket_queue_entry
 
data_ptr dd ?
buf_ptr dd ?
data_size dd ?
buf_ptr dd ?
 
ends
 
822,7 → 822,7
rep movsd
.nd:
 
call NET_BUFF_free
call NET_packet_free
pop ecx eax ; return number of bytes copied to application
xor ebx, ebx
ret
1441,6 → 1441,7
; ecx = data size
; esi = ptr to data
; [esp] = ptr to buf
; [esp + 4] = buf size
;
; OUT: /
;
1450,7 → 1451,7
 
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx
 
push ecx
mov [esp+4], ecx
push esi
mov esi, esp
 
1474,13 → 1475,16
call mutex_unlock
popa
 
call NET_BUFF_free
call NET_packet_free
add esp, 8
 
ret
 
 
;--------------------------
;
; eax = ptr to ring struct (just a buffer of the right size)
; IN: eax = ptr to ring struct (just a buffer of the right size)
; OUT: eax = unchanged / 0 on error
;
align 4
SOCKET_ring_create:
/kernel/trunk/network/tcp_input.inc
23,6 → 23,7
; Add a segment to the incoming TCP queue
;
; IN: [esp] = ptr to buffer
; [esp+4] = buffer size (dont care)
; ebx = ptr to device struct
; ecx = segment size
; esi = ptr to TCP segment
36,8 → 37,10
TCP_input:
 
; record the current time
push [timer_ticks] ; in 1/100 seconds
push ebx ecx esi edi ; mind the order (see TCP_queue_entry struct)
mov eax, [timer_ticks] ; in 1/100 seconds
mov [esp + 4], eax
 
push ebx ecx esi edi ; mind the order
mov esi, esp
 
add_to_queue TCP_queue, TCP_QUEUE_SIZE, sizeof.TCP_queue_entry, .fail
61,11 → 64,14
inc [TCP_segments_missed + edi]
 
add esp, sizeof.TCP_queue_entry - 8
call NET_BUFF_free
call NET_packet_free
add esp, 4
 
ret
 
 
 
 
align 4
proc TCP_process_input
 
1589,7 → 1595,7
.done:
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: dumping\n"
 
call NET_BUFF_free
call NET_packet_free
jmp .loop
 
 
1708,7 → 1714,7
.drop_no_socket:
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: Drop (no socket)\n"
 
call NET_BUFF_free
call NET_packet_free
jmp .loop
 
endp
/kernel/trunk/network/tcp_output.inc
522,6 → 522,7
pop esi ; headersize
add esp, esi ; remove it from stack
 
push edx ; packet size for send proc
push eax ; packet ptr for send proc
 
mov edx, edi ; begin of data
536,7 → 537,7
; ecx = buffer size
; edi = ptr to buffer
 
mov eax, [esp + 12] ; get socket ptr
mov eax, [esp + 16] ; get socket ptr
 
push edx
push [eax + TCP_SOCKET.SND_NXT] ; we'll need this for timing the transmission
551,7 → 552,7
pop edi
pop esi ; begin of data
pop ecx ; full packet size
mov eax, [esp + 8] ; socket ptr
mov eax, [esp + 12] ; socket ptr
 
;----------------------------------
; initialize retransmit timer (400)
/kernel/trunk/network/ARP.inc
293,10 → 293,13
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_input: IP address conflict detected!\n"
 
.exit:
call NET_packet_free
add esp, 4 ; pop (balance stack)
 
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_input: exiting\n"
call NET_BUFF_free
ret
 
 
;---------------------------------------------------------------------------
;
; ARP_output_request
344,7 → 347,7
movsd ;
popd [edi] ; DestIP
 
push eax
push edx eax
call [ebx + NET_DEVICE.transmit]
ret
 
/kernel/trunk/network/IPv4.inc
225,10 → 225,10
align 4
IPv4_input: ; TODO: add IPv4 raw sockets support
 
DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: packet from %u.%u.%u.%u ",\
DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input, packet from: %u.%u.%u.%u ",\
[edx + IPv4_header.SourceAddress + 0]:1,[edx + IPv4_header.SourceAddress + 1]:1,\
[edx + IPv4_header.SourceAddress + 2]:1,[edx + IPv4_header.SourceAddress + 3]:1
DEBUGF DEBUG_NETWORK_VERBOSE, "to %u.%u.%u.%u\n",\
DEBUGF DEBUG_NETWORK_VERBOSE, "to: %u.%u.%u.%u\n",\
[edx + IPv4_header.DestinationAddress + 0]:1,[edx + IPv4_header.DestinationAddress + 1]:1,\
[edx + IPv4_header.DestinationAddress + 2]:1,[edx + IPv4_header.DestinationAddress + 3]:1
 
323,7 → 323,8
.dump:
DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: dumping\n"
inc [IPv4_packets_dumped] ; FIXME: use correct interface
call NET_BUFF_free
call NET_packet_free
add esp, 4 ; pop (balance stack)
ret
 
 
370,6 → 371,7
mov [eax + IPv4_FRAGMENT_entry.PrevPtr], edi
mov [eax + IPv4_FRAGMENT_entry.Owner], ebx
 
add esp, 4
ret
 
 
403,6 → 405,7
mov [eax + IPv4_FRAGMENT_entry.PrevPtr], -1
mov [eax + IPv4_FRAGMENT_entry.Owner], ebx
 
add esp, 4 ; balance stack and exit
ret
 
 
503,7 → 506,7
push [edx + IPv4_FRAGMENT_entry.NextPtr] ; Set edx to the next pointer
push edx ; Push pointer to fragment onto stack
DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: Next Fragment: 0x%x\n", edx
call NET_BUFF_free ; free the previous fragment buffer (this uses the value from stack)
call NET_packet_free ; free the previous fragment buffer (this uses the value from stack)
pop edx ebx eax
cmp edx, -1 ; Check if it is last fragment in chain
jne .rebuild_packet_loop
651,7 → 654,7
ret
 
.loopback:
mov dword [esp], eax ; set source IP to dest IP
mov dword [esp + 2], eax ; change source IP to dest IP
mov ecx, [esp + 10]
add ecx, sizeof.IPv4_header
mov edi, AF_INET4
746,6 → 749,7
;
;
; IN: dword [esp] = pointer to buffer containing ipv4 packet to be fragmented
; dword [esp+4] = buffer size
; esi = pointer to ip header in that buffer
; ecx = max size of fragments
;
853,7 → 857,9
add esp, 12 + 4 + 6
.err2:
DEBUGF DEBUG_NETWORK_VERBOSE, "Ipv4_fragment: dumping\n"
call NET_BUFF_free
call NET_packet_free
add esp, 4
 
ret
 
 
/kernel/trunk/network/IPv6.inc
147,7 → 147,9
 
.dump:
DEBUGF DEBUG_NETWORK_VERBOSE, "IPv6_input - dumping\n"
call NET_BUFF_free
call kernel_free
add esp, 4
 
ret
 
.dump_options:
/kernel/trunk/network/PPPoE.inc
106,7 → 106,8
popa
 
DEBUGF DEBUG_NETWORK_VERBOSE, 'PPPoE_discovery_input: dumping\n'
call NET_BUFF_free
call NET_packet_free
add esp, 4
ret
 
 
231,11 → 232,13
 
.dump:
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_input: dumping\n"
call NET_BUFF_free
call NET_packet_free
add esp, 4
ret
 
 
 
 
;-----------------------------------------------------------------
;
; PPPoE_output
/kernel/trunk/network/ethernet.inc
33,25 → 33,30
 
ends
 
struct ETH_queue_entry
 
device dd ?
packet dd ?
size dd ?
 
ends
 
iglobal
align 4
 
ETH_BROADCAST dp 0xffffffffffff
 
ETH_frame_queued dd 0 ; Number of queued frames
 
ETH_frame_head dd ETH_frame_head ; Pointer to next frame in the linked list
ETH_frame_tail dd ETH_frame_head ; Pointer to last frame in the linked list
 
endg
 
uglobal
align 4
ETH_input_event dd ?
ETH_queue rd (ETH_QUEUE_SIZE*sizeof.ETH_queue_entry + sizeof.queue)/4
endg
 
macro ETH_init {
 
init_queue ETH_queue
 
movi ebx, 1
mov ecx, ETH_process_input
call new_sys_threads
67,10 → 72,11
; ETH_input
;
; This function is called by ethernet drivers,
; It pushes the received ethernet packets onto the ethernet input queue
; It pushes the received ethernet packets onto the eth_in_queue
;
; IN: [esp] = Pointer to buffer
;
; [esp+4] = size of buffer
; ebx = pointer to eth_device
; OUT: /
;
;-----------------------------------------------------------------
77,26 → 83,12
align 4
ETH_input:
 
pop eax
pushf
cli
push ebx
mov esi, esp
 
cmp [ETH_frame_queued], ETH_QUEUE_SIZE
jae .full
inc [ETH_frame_queued]
add_to_queue ETH_queue, ETH_QUEUE_SIZE, sizeof.ETH_queue_entry, .fail
add esp, sizeof.ETH_queue_entry
 
; Add frame to the end of the linked list
mov [eax + NET_BUFF.NextPtr], ETH_frame_head
 
mov ebx, [ETH_frame_tail]
mov [eax + NET_BUFF.PrevPtr], ebx
 
mov [ETH_frame_tail], eax
mov [ebx + NET_BUFF.NextPtr], eax
 
popf
 
; Now queue an event to process it
xor edx, edx
mov eax, [ETH_input_event]
mov ebx, [eax + EVENT.id]
105,11 → 97,13
 
ret
 
.full:
.fail:
DEBUGF DEBUG_NETWORK_ERROR, "ETH incoming queue is full, discarding packet!\n"
popf
push eax
call NET_BUFF_free
 
pop ebx
call NET_packet_free
add esp, 4
 
ret
 
 
122,46 → 116,29
mov ecx, MANUAL_DESTROY
call create_event
mov [ETH_input_event], eax
pushf
 
.wait:
popf
mov eax, [ETH_input_event]
mov ebx, [eax + EVENT.id]
call wait_event
 
.loop:
pushf
cli
cmp [ETH_frame_queued], 0
je .wait
get_from_queue ETH_queue, ETH_QUEUE_SIZE, sizeof.ETH_queue_entry, .wait
 
dec [ETH_frame_queued]
mov eax, [esi + ETH_queue_entry.packet]
mov ecx, [esi + ETH_queue_entry.size]
mov ebx, [esi + ETH_queue_entry.device]
 
mov esi, [ETH_frame_head]
mov ebx, [esi + NET_BUFF.NextPtr]
pushd .loop ; return address
push ecx eax
 
mov [ETH_frame_head], ebx
mov [ebx + NET_BUFF.PrevPtr], ETH_frame_head
 
popf
 
mov eax, [esi + NET_BUFF.offset]
add eax, esi
mov ecx, [esi + NET_BUFF.length]
mov ebx, [esi + NET_BUFF.device]
 
pushd .loop ; return address for protocol handler
push esi ; keep pointer to NET_BUFF on stack
 
DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: size=%u\n", ecx
sub ecx, sizeof.ETH_header
jb .dump
 
; Set registers for protocol handlers
lea edx, [eax + sizeof.ETH_header]
mov ax, [eax + ETH_header.Type]
 
; Place protocol handlers here
cmp ax, ETHER_PROTO_IPv4
je IPv4_input
 
181,7 → 158,8
 
.dump:
DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: dumping\n"
call NET_BUFF_free
call NET_packet_free
add esp, 4
ret
 
;-----------------------------------------------------------------
193,10 → 171,11
; ecx = payload size
; edx = pointer to destination mac
;
; OUT: eax = start of net frame / 0 on error
; OUT: eax = start of ethernet frame / 0 on error
; ebx = device ptr
; ecx = payload size
; edi = start of payload
; edx = ethernet frame size
; edi = start of ethernet payload
;
;-----------------------------------------------------------------
align 4
210,14 → 189,11
push ecx
push ax edx
 
add ecx, sizeof.ETH_header + NET_BUFF.data
stdcall NET_BUFF_alloc, ecx
add ecx, sizeof.ETH_header
stdcall kernel_alloc, ecx
test eax, eax
jz .out_of_ram
mov [eax + NET_BUFF.type], NET_BUFF_ETH
mov [eax + NET_BUFF.device], ebx
mov [eax + NET_BUFF.offset], NET_BUFF.data
lea edi, [eax + NET_BUFF.data]
mov edi, eax
 
pop esi
movsd
228,14 → 204,13
pop ax
stosw
 
lea eax, [edi - sizeof.ETH_header - NET_BUFF.data] ; Set eax to buffer start
lea eax, [edi - sizeof.ETH_header] ; Set eax to buffer start
pop ecx
lea edx, [ecx + sizeof.ETH_header] ; Set edx to complete buffer size
 
lea edx, [ecx + sizeof.ETH_header] ; Set edx to complete buffer size
cmp edx, ETH_FRAME_MINIMUM
jbe .adjust_size
.done:
mov [eax + NET_BUFF.length], edx
DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_output: ptr=%x size=%u\n", eax, edx
ret
 
297,7 → 272,7
.read_mac:
movzx ebx, word [eax + ETH_DEVICE.mac]
mov eax, dword [eax + ETH_DEVICE.mac + 2]
mov [esp+20+4], ebx ; FIXME
mov [esp+20+4], ebx ; TODO: fix this ugly code
ret
 
 
/kernel/trunk/network/icmp.inc
131,6 → 131,7
; and insert packets into sockets when needed
;
; IN: Pointer to buffer in [esp]
; size of buffer in [esp+4]
; ebx = pointer to device struct
; ecx = ICMP Packet size
; esi = ptr to ICMP Packet data
142,9 → 143,10
align 4
ICMP_input:
 
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP_input\n"
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP_input:\n"
 
; Check the checksum
; First, check the checksum (altough some implementations ignore it)
 
push esi ecx
push [esi + ICMP_header.Checksum]
mov [esi + ICMP_header.Checksum], 0
153,34 → 155,100
call checksum_2
pop si
cmp dx, si
pop ecx esi
pop ecx edx
jne .checksum_mismatch
 
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP_input: Checksum OK\n"
; Check packet type
 
; Ualidate device ptr
mov eax, edi
cmp [edx + ICMP_header.Type], ICMP_ECHO ; Is this an echo request?
jne .check_sockets
 
; Update stats (and validate device ptr)
call NET_ptr_to_num4
cmp edi, -1
je .dump
 
; Update stats
inc [ICMP_PACKETS_RX + edi]
 
; Is this an echo request?
cmp [esi + ICMP_header.Type], ICMP_ECHO
je .echo_request
; We well re-use the packet so we can create the response as fast as possible
; Notice: this only works on pure ethernet
 
DEBUGF DEBUG_NETWORK_VERBOSE, "got echo request\n"
mov [edx + ICMP_header.Type], ICMP_ECHOREPLY ; Change Packet type to reply
 
mov esi, [esp] ; Start of buffer
cmp ebx, LOOPBACK_DEVICE
je .loopback
 
; FIXME: dont assume device is an ethernet device!
 
; exchange dest and source address in IP header
; exchange dest and source MAC in ETH header
push dword [esi + ETH_header.DstMAC]
push dword [esi + ETH_header.SrcMAC]
pop dword [esi + ETH_header.DstMAC]
pop dword [esi + ETH_header.SrcMAC]
push word [esi + ETH_header.DstMAC + 4]
push word [esi + ETH_header.SrcMAC + 4]
pop word [esi + ETH_header.DstMAC + 4]
pop word [esi + ETH_header.SrcMAC + 4]
add esi, sizeof.ETH_header-4
 
.loopback:
add esi, 4
push [esi + IPv4_header.SourceAddress]
push [esi + IPv4_header.DestinationAddress]
pop [esi + IPv4_header.SourceAddress]
pop [esi + IPv4_header.DestinationAddress]
 
; Recalculate ip header checksum
movzx ecx, [esi + IPv4_header.VersionAndIHL] ; Calculate IP Header length by using IHL field
and ecx, 0x0f
shl cx, 2
mov edi, ecx ; IP header length
mov eax, edx ; ICMP packet start addr
 
push esi ; Calculate the IP checksum
xor edx, edx ;
call checksum_1 ;
call checksum_2 ;
pop esi ;
mov [esi + IPv4_header.HeaderChecksum], dx ;
 
; Recalculate ICMP CheckSum
movzx ecx, [esi + IPv4_header.TotalLength] ; Find length of IP Packet
xchg ch, cl ;
sub ecx, edi ; IP packet length - IP header length = ICMP packet length
 
mov esi, eax ; Calculate ICMP checksum
xor edx, edx ;
call checksum_1 ;
call checksum_2 ;
mov [eax + ICMP_header.Checksum], dx ;
 
; Transmit the packet (notice that packet ptr and packet size have been on stack since start of the procedure!)
call [ebx + NET_DEVICE.transmit]
test eax, eax
jnz @f
call NET_ptr_to_num4
inc [ICMP_PACKETS_TX + edi]
@@:
ret
 
 
 
 
.check_sockets:
; Look for an open ICMP socket
 
pusha
mov ecx, socket_mutex
call mutex_lock
popa
 
mov edx, [eax] ; ipv4 source address
mov esi, [edi] ; ipv4 source address
mov eax, net_sockets
.try_more:
; mov , [esi + ICMP_header.Identifier]
; mov , [edx + ICMP_header.Identifier]
.next_socket:
mov eax, [eax + SOCKET.NextPtr]
or eax, eax
192,12 → 260,18
cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP
jne .next_socket
 
cmp [eax + IP_SOCKET.RemoteIP], edx
cmp [eax + IP_SOCKET.RemoteIP], esi
jne .next_socket
 
; cmp [eax + ICMP_SOCKET.Identifier],
; jne .next_socket
 
; Update stats (and validate device ptr)
call NET_ptr_to_num4
cmp edi, -1
je .dump_
inc [ICMP_PACKETS_RX + edi]
 
pusha
mov ecx, socket_mutex
call mutex_unlock
210,82 → 284,11
call mutex_lock
popa
 
mov esi, edx
jmp SOCKET_input
 
.dump_:
 
 
.echo_request:
 
; We'll reuse the packet so we can create the response as fast as possible
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP echo request\n"
 
; Change Packet type to reply
mov [esi + ICMP_header.Type], ICMP_ECHOREPLY
 
mov eax, [esp]
lea esi, [eax + NET_BUFF.data]
 
; Check frame type
cmp [eax + NET_BUFF.type], NET_BUFF_ETH
jne .not_ethernet
 
; exchange dest and source MAC in ETH header
push dword [esi + ETH_header.DstMAC]
push dword [esi + ETH_header.SrcMAC]
pop dword [esi + ETH_header.DstMAC]
pop dword [esi + ETH_header.SrcMAC]
push word [esi + ETH_header.DstMAC + 4]
push word [esi + ETH_header.SrcMAC + 4]
pop word [esi + ETH_header.DstMAC + 4]
pop word [esi + ETH_header.SrcMAC + 4]
add esi, sizeof.ETH_header
 
.not_ethernet:
; Exchange dest and source address in IP header
push [esi + IPv4_header.SourceAddress]
push [esi + IPv4_header.DestinationAddress]
pop [esi + IPv4_header.SourceAddress]
pop [esi + IPv4_header.DestinationAddress]
 
; Calculate IP header length
movzx ecx, [esi + IPv4_header.VersionAndIHL]
and ecx, 0x0f
shl cx, 2
mov edi, ecx ; put it in edi for later
 
; Calculate IP checksum
mov eax, esi
mov [eax + IPv4_header.HeaderChecksum], 0
xor edx, edx
call checksum_1
call checksum_2
mov [eax + IPv4_header.HeaderChecksum], dx
 
; Calculate ICMP packet length
movzx ecx, [eax + IPv4_header.TotalLength]
xchg ch, cl
sub ecx, edi ; IP packet length - IP header length = ICMP packet length
 
; Calculate ICMP checkSum
mov eax, esi
mov [esi + ICMP_header.Checksum], 0
xor edx, edx
call checksum_1
call checksum_2
mov [eax + ICMP_header.Checksum], dx
 
; Transmit the frame
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP transmitting reply\n"
call [ebx + NET_DEVICE.transmit]
test eax, eax
jnz @f
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP transmit failed\n"
call NET_ptr_to_num4
inc [ICMP_PACKETS_TX + edi]
@@:
ret
 
.dump_:
pusha
mov ecx, socket_mutex
call mutex_unlock
294,12 → 297,16
DEBUGF DEBUG_NETWORK_ERROR, "ICMP_input: no socket found\n"
jmp .dump
 
 
.checksum_mismatch:
DEBUGF DEBUG_NETWORK_ERROR, "ICMP_input: checksum mismatch\n"
 
.dump:
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP_input: dumping\n"
call NET_BUFF_free
 
call NET_packet_free
add esp, 4 ; pop (balance stack)
 
ret
 
 
393,6 → 400,7
jz .exit
 
pop esi
push edx
push eax
 
push edi ecx
418,6 → 426,7
ret
.exit:
DEBUGF DEBUG_NETWORK_ERROR, "Creating ICMP Packet failed\n"
add esp, 4
ret
 
 
/kernel/trunk/network/loopback.inc
66,6 → 66,7
; LOOP_input
;
; IN: [esp+4] = Pointer to buffer
; [esp+8] = size of buffer
;
; OUT: /
;
72,50 → 73,47
;-----------------------------------------------------------------
align 4
LOOP_input:
pop ebx
pop eax
pop ecx
 
mov eax, [esp+4]
push ebx
push ecx
push eax
 
; Update stats
inc [LOOPBACK_DEVICE.packets_rx]
 
mov ecx, [eax + NET_BUFF.length]
add dword[LOOPBACK_DEVICE.bytes_rx], ecx
adc dword[LOOPBACK_DEVICE.bytes_rx + 4], 0
 
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: ptr=%x size=%u\n", eax, ecx
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx
lea edx, [eax + 4]
mov eax, dword[eax]
mov ebx, LOOPBACK_DEVICE
 
; Reverse buffptr and returnaddr on stack
pop edx edi
push edx edi
 
; Set registers for protocol handlers
lea edx, [eax + NET_BUFF.data]
mov ebx, [eax + NET_BUFF.device]
mov eax, [eax + NET_BUFF.type]
 
; Place protocol handlers here
cmp eax, AF_INET4
je IPv4_input
 
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", eax
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", ax
 
.dump:
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n"
call NET_BUFF_free
call NET_packet_free
add esp, 4
ret
 
 
;-----------------------------------------------------------------
;
; LOOP_output
;
; IN: ecx = packet size
; IN:
; ecx = packet size
; edi = address family
;
; OUT: eax = start of net frame / 0 on error
; OUT: edi = 0 on error, pointer to buffer otherwise
; eax = buffer start
; ebx = to device structure
; ecx = unchanged (packet size of embedded data)
; edi = start of payload
; edx = size of complete buffer
;
;-----------------------------------------------------------------
align 4
123,38 → 121,35
 
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
 
push ecx
push edi
 
add ecx, 4
cmp ecx, [LOOPBACK_DEVICE.mtu]
ja .too_large
 
push ecx edi
stdcall NET_BUFF_alloc, ecx
ja .out_of_ram
stdcall kernel_alloc, ecx
test eax, eax
jz .out_of_ram
mov edi, eax
pop eax
stosd
 
pop edi
mov [eax + NET_BUFF.type], edi
lea eax, [edi - 4] ; Set eax to buffer start
pop ecx
lea edx, [ecx + 4] ; Set edx to complete buffer size
mov ebx, LOOPBACK_DEVICE
mov [eax + NET_BUFF.device], ebx
pop ecx
mov [eax + NET_BUFF.length], ecx
lea edi, [eax + NET_BUFF.data]
 
inc [LOOPBACK_DEVICE.packets_tx]
add dword[LOOPBACK_DEVICE.bytes_tx], ecx
adc dword[LOOPBACK_DEVICE.bytes_tx + 4], 0
 
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, ecx
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx
ret
 
.too_large:
DEBUGF DEBUG_NETWORK_ERROR, "LOOP_output: packet is too large\n"
xor eax, eax
ret
 
.out_of_ram:
DEBUGF DEBUG_NETWORK_ERROR, "LOOP_output: out of memory\n"
add esp, 4+4
xor eax, eax
xor edi, edi
ret
 
 
/kernel/trunk/network/stack.inc
155,10 → 155,6
NET_HWACC_TCP_IPv4_IN = 1 shl 0
NET_HWACC_TCP_IPv4_OUT = 1 shl 1
 
; Network frame types
NET_BUFF_LOOPBACK = 0
NET_BUFF_ETH = 1
 
struct NET_DEVICE
 
device_type dd ? ; Type field
179,19 → 175,7
 
ends
 
struct NET_BUFF
 
NextPtr dd ? ; pointer to next frame in list
PrevPtr dd ? ; pointer to previous frame in list
device dd ? ; ptr to NET_DEVICE structure
type dd ? ; encapsulation type: e.g. Ethernet
length dd ? ; size of encapsulated data
offset dd ? ; offset to actual data (24 bytes for default frame)
data rb 0
 
ends
 
 
; Exactly as it says..
macro pseudo_random reg {
add reg, [esp]
343,13 → 327,7
 
 
align 4
NET_BUFF_alloc:
add dword[esp+4], NET_BUFF.data
jmp kernel_alloc
 
 
align 4
NET_BUFF_free:
NET_packet_free:
and dword[esp+4], not 0xfff
jmp kernel_free
 
504,10 → 482,8
align 4
NET_ptr_to_num4: ; Todo, place number in device structure so we only need to verify?
 
test ebx, ebx
jz .fail
push ecx
 
push ecx
mov ecx, NET_DEVICES_MAX
mov edi, NET_DRV_LIST
.loop:
517,9 → 493,8
dec ecx
jnz .loop
 
or edi, -1
pop ecx
.fail:
or edi, -1
ret
 
.found:
/kernel/trunk/network/tcp.inc
124,8 → 124,9
segment_ptr dd ?
segment_size dd ?
device_ptr dd ?
 
buffer_ptr dd ?
timestamp dd ?
buffer_ptr dd ?
 
ends
 
/kernel/trunk/network/tcp_subr.inc
292,7 → 292,7
call IPv4_output
jz .error
pop esi cx
push eax
push edx eax
 
;-----------------------------------------------
; Fill in the TCP header by using the socket ptr
376,7 → 376,7
jz .error
pop esi cx
 
push eax
push edx eax
 
;---------------------------------------------------
; Fill in the TCP header by using a received segment
/kernel/trunk/network/udp.inc
154,7 → 154,7
.next_socket:
mov eax, [eax + SOCKET.NextPtr]
or eax, eax
jz .unlock_dump
jz .dump_
 
cmp [eax + SOCKET.Domain], AF_INET4
jne .next_socket
213,7 → 213,8
mov [eax + UDP_SOCKET.RemotePort], cx
jmp .updatesock
 
.unlock_dump:
.dump_:
 
pusha
mov ecx, socket_mutex
call mutex_unlock
220,6 → 221,7
popa
 
DEBUGF DEBUG_NETWORK_VERBOSE, "UDP_input: no socket found\n"
 
jmp .dump
 
.checksum_mismatch:
226,12 → 228,15
DEBUGF DEBUG_NETWORK_VERBOSE, "UDP_input: checksum mismatch\n"
 
.dump:
call NET_packet_free
add esp, 4 ; pop (balance stack)
DEBUGF DEBUG_NETWORK_VERBOSE, "UDP_input: dumping\n"
call NET_BUFF_free
 
ret
 
 
 
 
;-----------------------------------------------------------------
;
; UDP_output
255,7 → 260,7
mov dx, [eax + UDP_SOCKET.LocalPort]
DEBUGF DEBUG_NETWORK_VERBOSE, "local port=%x\n", dx
 
sub esp, 4 ; Data ptr will be placed here
sub esp, 8 ; Data ptr and data size will be placed here
push edx esi
mov edx, [eax + IP_SOCKET.LocalIP]
mov eax, [eax + IP_SOCKET.RemoteIP]
264,6 → 269,7
call IPv4_output
jz .fail
mov [esp + 8], eax ; pointer to buffer start
mov [esp + 8 + 4], edx ; buffer size
 
mov [edi + UDP_header.Length], cx
rol [edi + UDP_header.Length], 8
/kernel/trunk/core/exports.inc
122,9 → 122,7
NET_remove_device, 'NetUnRegDev', \
NET_ptr_to_num, 'NetPtrToNum', \
NET_link_changed, 'NetLinkChanged', \
ETH_input, 'EthInput', \
NET_BUFF_alloc, 'NetAlloc', \
NET_BUFF_free, 'NetFree', \
ETH_input, 'Eth_input', \
\
get_pcidev_list, 'GetPCIList', \
\