/kernel/trunk/network/ARP.inc |
---|
293,13 → 293,10 |
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 |
347,7 → 344,7 |
movsd ; |
popd [edi] ; DestIP |
push edx eax |
push 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,8 → 323,7 |
.dump: |
DEBUGF DEBUG_NETWORK_VERBOSE, "IPv4_input: dumping\n" |
inc [IPv4_packets_dumped] ; FIXME: use correct interface |
call NET_packet_free |
add esp, 4 ; pop (balance stack) |
call NET_BUFF_free |
ret |
371,7 → 370,6 |
mov [eax + IPv4_FRAGMENT_entry.PrevPtr], edi |
mov [eax + IPv4_FRAGMENT_entry.Owner], ebx |
add esp, 4 |
ret |
405,7 → 403,6 |
mov [eax + IPv4_FRAGMENT_entry.PrevPtr], -1 |
mov [eax + IPv4_FRAGMENT_entry.Owner], ebx |
add esp, 4 ; balance stack and exit |
ret |
506,7 → 503,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_packet_free ; free the previous fragment buffer (this uses the value from stack) |
call NET_BUFF_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 |
654,7 → 651,7 |
ret |
.loopback: |
mov dword [esp + 2], eax ; change source IP to dest IP |
mov dword [esp], eax ; set source IP to dest IP |
mov ecx, [esp + 10] |
add ecx, sizeof.IPv4_header |
mov edi, AF_INET4 |
749,7 → 746,6 |
; |
; |
; 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 |
; |
857,9 → 853,7 |
add esp, 12 + 4 + 6 |
.err2: |
DEBUGF DEBUG_NETWORK_VERBOSE, "Ipv4_fragment: dumping\n" |
call NET_packet_free |
add esp, 4 |
call NET_BUFF_free |
ret |
/kernel/trunk/network/IPv6.inc |
---|
147,9 → 147,7 |
.dump: |
DEBUGF DEBUG_NETWORK_VERBOSE, "IPv6_input - dumping\n" |
call kernel_free |
add esp, 4 |
call NET_BUFF_free |
ret |
.dump_options: |
/kernel/trunk/network/PPPoE.inc |
---|
106,8 → 106,7 |
popa |
DEBUGF DEBUG_NETWORK_VERBOSE, 'PPPoE_discovery_input: dumping\n' |
call NET_packet_free |
add esp, 4 |
call NET_BUFF_free |
ret |
232,13 → 231,11 |
.dump: |
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_input: dumping\n" |
call NET_packet_free |
add esp, 4 |
call NET_BUFF_free |
ret |
;----------------------------------------------------------------- |
; |
; PPPoE_output |
/kernel/trunk/network/ethernet.inc |
---|
33,30 → 33,25 |
ends |
struct ETH_queue_entry |
iglobal |
align 4 |
device dd ? |
packet dd ? |
size dd ? |
ETH_BROADCAST dp 0xffffffffffff |
ends |
ETH_frame_queued dd 0 ; Number of queued frames |
iglobal |
align 4 |
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 |
ETH_BROADCAST dp 0xffffffffffff |
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 |
72,11 → 67,10 |
; ETH_input |
; |
; This function is called by ethernet drivers, |
; It pushes the received ethernet packets onto the eth_in_queue |
; It pushes the received ethernet packets onto the ethernet input queue |
; |
; IN: [esp] = Pointer to buffer |
; [esp+4] = size of buffer |
; ebx = pointer to eth_device |
; |
; OUT: / |
; |
;----------------------------------------------------------------- |
83,12 → 77,26 |
align 4 |
ETH_input: |
push ebx |
mov esi, esp |
pop eax |
pushf |
cli |
add_to_queue ETH_queue, ETH_QUEUE_SIZE, sizeof.ETH_queue_entry, .fail |
add esp, sizeof.ETH_queue_entry |
cmp [ETH_frame_queued], ETH_QUEUE_SIZE |
jae .full |
inc [ETH_frame_queued] |
; 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] |
97,13 → 105,11 |
ret |
.fail: |
.full: |
DEBUGF DEBUG_NETWORK_ERROR, "ETH incoming queue is full, discarding packet!\n" |
pop ebx |
call NET_packet_free |
add esp, 4 |
popf |
push eax |
call NET_BUFF_free |
ret |
116,29 → 122,46 |
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: |
get_from_queue ETH_queue, ETH_QUEUE_SIZE, sizeof.ETH_queue_entry, .wait |
pushf |
cli |
cmp [ETH_frame_queued], 0 |
je .wait |
mov eax, [esi + ETH_queue_entry.packet] |
mov ecx, [esi + ETH_queue_entry.size] |
mov ebx, [esi + ETH_queue_entry.device] |
dec [ETH_frame_queued] |
pushd .loop ; return address |
push ecx eax |
mov esi, [ETH_frame_head] |
mov ebx, [esi + NET_BUFF.NextPtr] |
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 |
158,8 → 181,7 |
.dump: |
DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_input: dumping\n" |
call NET_packet_free |
add esp, 4 |
call NET_BUFF_free |
ret |
;----------------------------------------------------------------- |
171,11 → 193,10 |
; ecx = payload size |
; edx = pointer to destination mac |
; |
; OUT: eax = start of ethernet frame / 0 on error |
; OUT: eax = start of net frame / 0 on error |
; ebx = device ptr |
; ecx = payload size |
; edx = ethernet frame size |
; edi = start of ethernet payload |
; edi = start of payload |
; |
;----------------------------------------------------------------- |
align 4 |
189,11 → 210,14 |
push ecx |
push ax edx |
add ecx, sizeof.ETH_header |
stdcall kernel_alloc, ecx |
add ecx, sizeof.ETH_header + NET_BUFF.data |
stdcall NET_BUFF_alloc, ecx |
test eax, eax |
jz .out_of_ram |
mov edi, eax |
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] |
pop esi |
movsd |
204,13 → 228,14 |
pop ax |
stosw |
lea eax, [edi - sizeof.ETH_header] ; Set eax to buffer start |
lea eax, [edi - sizeof.ETH_header - NET_BUFF.data] ; Set eax to buffer start |
pop ecx |
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 |
272,7 → 297,7 |
.read_mac: |
movzx ebx, word [eax + ETH_DEVICE.mac] |
mov eax, dword [eax + ETH_DEVICE.mac + 2] |
mov [esp+20+4], ebx ; TODO: fix this ugly code |
mov [esp+20+4], ebx ; FIXME |
ret |
/kernel/trunk/network/icmp.inc |
---|
131,7 → 131,6 |
; 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 |
143,10 → 142,9 |
align 4 |
ICMP_input: |
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP_input:\n" |
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP_input\n" |
; First, check the checksum (altough some implementations ignore it) |
; Check the checksum |
push esi ecx |
push [esi + ICMP_header.Checksum] |
mov [esi + ICMP_header.Checksum], 0 |
155,100 → 153,34 |
call checksum_2 |
pop si |
cmp dx, si |
pop ecx edx |
pop ecx esi |
jne .checksum_mismatch |
; Check packet type |
DEBUGF DEBUG_NETWORK_VERBOSE, "ICMP_input: Checksum OK\n" |
cmp [edx + ICMP_header.Type], ICMP_ECHO ; Is this an echo request? |
jne .check_sockets |
; Update stats (and validate device ptr) |
; Ualidate device ptr |
mov eax, edi |
call NET_ptr_to_num4 |
cmp edi, -1 |
je .dump |
; Update stats |
inc [ICMP_PACKETS_RX + edi] |
; We well re-use the packet so we can create the response as fast as possible |
; Notice: this only works on pure ethernet |
; Is this an echo request? |
cmp [esi + ICMP_header.Type], ICMP_ECHO |
je .echo_request |
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 esi, [edi] ; ipv4 source address |
mov edx, [eax] ; ipv4 source address |
mov eax, net_sockets |
.try_more: |
; mov , [edx + ICMP_header.Identifier] |
; mov , [esi + ICMP_header.Identifier] |
.next_socket: |
mov eax, [eax + SOCKET.NextPtr] |
or eax, eax |
260,18 → 192,12 |
cmp [eax + SOCKET.Protocol], IP_PROTO_ICMP |
jne .next_socket |
cmp [eax + IP_SOCKET.RemoteIP], esi |
cmp [eax + IP_SOCKET.RemoteIP], edx |
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 |
284,11 → 210,82 |
call mutex_lock |
popa |
mov esi, edx |
jmp SOCKET_input |
.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 |
297,16 → 294,12 |
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_packet_free |
add esp, 4 ; pop (balance stack) |
call NET_BUFF_free |
ret |
400,7 → 393,6 |
jz .exit |
pop esi |
push edx |
push eax |
push edi ecx |
426,7 → 418,6 |
ret |
.exit: |
DEBUGF DEBUG_NETWORK_ERROR, "Creating ICMP Packet failed\n" |
add esp, 4 |
ret |
/kernel/trunk/network/loopback.inc |
---|
66,7 → 66,6 |
; LOOP_input |
; |
; IN: [esp+4] = Pointer to buffer |
; [esp+8] = size of buffer |
; |
; OUT: / |
; |
73,47 → 72,50 |
;----------------------------------------------------------------- |
align 4 |
LOOP_input: |
pop ebx |
pop eax |
pop ecx |
push ebx |
push ecx |
push eax |
mov eax, [esp+4] |
; 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: size=%u\n", ecx |
lea edx, [eax + 4] |
mov eax, dword[eax] |
mov ebx, LOOPBACK_DEVICE |
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: ptr=%x size=%u\n", eax, ecx |
; 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", ax |
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", eax |
.dump: |
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n" |
call NET_packet_free |
add esp, 4 |
call NET_BUFF_free |
ret |
;----------------------------------------------------------------- |
; |
; LOOP_output |
; |
; IN: |
; ecx = packet size |
; IN: ecx = packet size |
; edi = address family |
; |
; OUT: edi = 0 on error, pointer to buffer otherwise |
; eax = buffer start |
; OUT: eax = start of net frame / 0 on error |
; ebx = to device structure |
; ecx = unchanged (packet size of embedded data) |
; edx = size of complete buffer |
; edi = start of payload |
; |
;----------------------------------------------------------------- |
align 4 |
121,35 → 123,38 |
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output\n" |
push ecx |
push edi |
cmp ecx, [LOOPBACK_DEVICE.mtu] |
ja .too_large |
add ecx, 4 |
cmp ecx, [LOOPBACK_DEVICE.mtu] |
ja .out_of_ram |
stdcall kernel_alloc, ecx |
push ecx edi |
stdcall NET_BUFF_alloc, ecx |
test eax, eax |
jz .out_of_ram |
mov edi, eax |
pop eax |
stosd |
lea eax, [edi - 4] ; Set eax to buffer start |
pop edi |
mov [eax + NET_BUFF.type], edi |
mov ebx, LOOPBACK_DEVICE |
mov [eax + NET_BUFF.device], ebx |
pop ecx |
lea edx, [ecx + 4] ; Set edx to complete buffer size |
mov ebx, LOOPBACK_DEVICE |
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, edx |
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, ecx |
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 edi, edi |
xor eax, eax |
ret |
/kernel/trunk/network/socket.inc |
---|
179,8 → 179,8 |
struct socket_queue_entry |
data_ptr dd ? |
data_size dd ? |
buf_ptr dd ? |
data_size dd ? |
ends |
822,7 → 822,7 |
rep movsd |
.nd: |
call NET_packet_free |
call NET_BUFF_free |
pop ecx eax ; return number of bytes copied to application |
xor ebx, ebx |
ret |
1441,7 → 1441,6 |
; ecx = data size |
; esi = ptr to data |
; [esp] = ptr to buf |
; [esp + 4] = buf size |
; |
; OUT: / |
; |
1451,7 → 1450,7 |
DEBUGF DEBUG_NETWORK_VERBOSE, "SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx |
mov [esp+4], ecx |
push ecx |
push esi |
mov esi, esp |
1475,16 → 1474,13 |
call mutex_unlock |
popa |
call NET_packet_free |
add esp, 8 |
call NET_BUFF_free |
ret |
;-------------------------- |
; |
; IN: eax = ptr to ring struct (just a buffer of the right size) |
; OUT: eax = unchanged / 0 on error |
; eax = ptr to ring struct (just a buffer of the right size) |
; |
align 4 |
SOCKET_ring_create: |
/kernel/trunk/network/stack.inc |
---|
155,6 → 155,10 |
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 |
175,7 → 179,19 |
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] |
327,7 → 343,13 |
align 4 |
NET_packet_free: |
NET_BUFF_alloc: |
add dword[esp+4], NET_BUFF.data |
jmp kernel_alloc |
align 4 |
NET_BUFF_free: |
and dword[esp+4], not 0xfff |
jmp kernel_free |
482,8 → 504,10 |
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 |
mov ecx, NET_DEVICES_MAX |
mov edi, NET_DRV_LIST |
.loop: |
493,8 → 517,9 |
dec ecx |
jnz .loop |
pop ecx |
.fail: |
or edi, -1 |
pop ecx |
ret |
.found: |
/kernel/trunk/network/tcp.inc |
---|
124,9 → 124,8 |
segment_ptr dd ? |
segment_size dd ? |
device_ptr dd ? |
timestamp dd ? |
buffer_ptr dd ? |
timestamp dd ? |
ends |
/kernel/trunk/network/tcp_input.inc |
---|
23,7 → 23,6 |
; 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 |
37,10 → 36,8 |
TCP_input: |
; record the current time |
mov eax, [timer_ticks] ; in 1/100 seconds |
mov [esp + 4], eax |
push ebx ecx esi edi ; mind the order |
push [timer_ticks] ; in 1/100 seconds |
push ebx ecx esi edi ; mind the order (see TCP_queue_entry struct) |
mov esi, esp |
add_to_queue TCP_queue, TCP_QUEUE_SIZE, sizeof.TCP_queue_entry, .fail |
64,14 → 61,11 |
inc [TCP_segments_missed + edi] |
add esp, sizeof.TCP_queue_entry - 8 |
call NET_packet_free |
add esp, 4 |
call NET_BUFF_free |
ret |
align 4 |
proc TCP_process_input |
1595,7 → 1589,7 |
.done: |
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: dumping\n" |
call NET_packet_free |
call NET_BUFF_free |
jmp .loop |
1714,7 → 1708,7 |
.drop_no_socket: |
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_input: Drop (no socket)\n" |
call NET_packet_free |
call NET_BUFF_free |
jmp .loop |
endp |
/kernel/trunk/network/tcp_output.inc |
---|
522,7 → 522,6 |
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 |
537,7 → 536,7 |
; ecx = buffer size |
; edi = ptr to buffer |
mov eax, [esp + 16] ; get socket ptr |
mov eax, [esp + 12] ; get socket ptr |
push edx |
push [eax + TCP_SOCKET.SND_NXT] ; we'll need this for timing the transmission |
552,7 → 551,7 |
pop edi |
pop esi ; begin of data |
pop ecx ; full packet size |
mov eax, [esp + 12] ; socket ptr |
mov eax, [esp + 8] ; socket ptr |
;---------------------------------- |
; initialize retransmit timer (400) |
/kernel/trunk/network/tcp_subr.inc |
---|
292,7 → 292,7 |
call IPv4_output |
jz .error |
pop esi cx |
push edx eax |
push eax |
;----------------------------------------------- |
; Fill in the TCP header by using the socket ptr |
376,7 → 376,7 |
jz .error |
pop esi cx |
push edx eax |
push 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 .dump_ |
jz .unlock_dump |
cmp [eax + SOCKET.Domain], AF_INET4 |
jne .next_socket |
213,8 → 213,7 |
mov [eax + UDP_SOCKET.RemotePort], cx |
jmp .updatesock |
.dump_: |
.unlock_dump: |
pusha |
mov ecx, socket_mutex |
call mutex_unlock |
221,7 → 220,6 |
popa |
DEBUGF DEBUG_NETWORK_VERBOSE, "UDP_input: no socket found\n" |
jmp .dump |
.checksum_mismatch: |
228,15 → 226,12 |
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 |
260,7 → 255,7 |
mov dx, [eax + UDP_SOCKET.LocalPort] |
DEBUGF DEBUG_NETWORK_VERBOSE, "local port=%x\n", dx |
sub esp, 8 ; Data ptr and data size will be placed here |
sub esp, 4 ; Data ptr will be placed here |
push edx esi |
mov edx, [eax + IP_SOCKET.LocalIP] |
mov eax, [eax + IP_SOCKET.RemoteIP] |
269,7 → 264,6 |
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 |