2013-05-28 19:34:26 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2015-01-08 21:10:22 +01:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
|
2013-05-28 19:34:26 +02:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; loopback.inc ;;
|
|
|
|
;; ;;
|
|
|
|
;; LoopBack device for KolibriOS ;;
|
|
|
|
;; ;;
|
|
|
|
;; Written by hidnplayr@kolibrios.org ;;
|
|
|
|
;; ;;
|
|
|
|
;; GNU GENERAL PUBLIC LICENSE ;;
|
|
|
|
;; Version 2, June 1991 ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-04-17 23:19:45 +02:00
|
|
|
$Revision$
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
iglobal
|
2013-06-24 13:39:05 +02:00
|
|
|
align 4
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
LOOPBACK_DEVICE:
|
2013-06-04 16:12:37 +02:00
|
|
|
|
2013-06-05 02:21:20 +02:00
|
|
|
.device_type dd NET_DEVICE_LOOPBACK
|
|
|
|
.mtu dd 4096
|
|
|
|
.name dd .namestr
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-05 02:21:20 +02:00
|
|
|
.unload dd .dummy_fn
|
|
|
|
.reset dd .dummy_fn
|
|
|
|
.transmit dd LOOP_input
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-05 02:21:20 +02:00
|
|
|
.bytes_tx dq 0
|
|
|
|
.bytes_rx dq 0
|
|
|
|
.packets_tx dd 0
|
|
|
|
.packets_rx dd 0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-05 02:21:20 +02:00
|
|
|
.link_state dd -1
|
2013-12-19 22:39:14 +01:00
|
|
|
.hwacc dd NET_HWACC_TCP_IPv4_IN + NET_HWACC_TCP_IPv4_OUT
|
2013-06-05 02:21:20 +02:00
|
|
|
|
|
|
|
.namestr db 'loopback', 0
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.dummy_fn:
|
2013-06-27 01:35:43 +02:00
|
|
|
ret
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
endg
|
|
|
|
|
2013-06-05 02:21:20 +02:00
|
|
|
|
|
|
|
macro LOOP_init {
|
|
|
|
local .fail
|
|
|
|
|
|
|
|
mov ebx, LOOPBACK_DEVICE
|
|
|
|
call NET_add_device
|
|
|
|
|
|
|
|
cmp eax, -1
|
|
|
|
je .fail
|
|
|
|
|
|
|
|
mov [IP_LIST], 127 + 1 shl 24
|
|
|
|
mov [SUBNET_LIST], 255
|
|
|
|
mov [BROADCAST_LIST], 0xffffff00 + 127
|
|
|
|
|
|
|
|
.fail:
|
|
|
|
}
|
|
|
|
|
2013-05-28 19:34:26 +02:00
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; LOOP_input
|
|
|
|
;
|
2013-06-04 16:12:37 +02:00
|
|
|
; IN: [esp+4] = Pointer to buffer
|
2013-05-28 19:34:26 +02:00
|
|
|
; [esp+8] = size of buffer
|
|
|
|
;
|
|
|
|
; OUT: /
|
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
LOOP_input:
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
pop ecx
|
|
|
|
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push eax
|
|
|
|
|
2013-06-06 08:08:45 +02:00
|
|
|
inc [LOOPBACK_DEVICE.packets_rx]
|
|
|
|
add dword[LOOPBACK_DEVICE.bytes_rx], ecx
|
|
|
|
adc dword[LOOPBACK_DEVICE.bytes_rx + 4], 0
|
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: size=%u\n", ecx
|
2013-06-04 16:12:37 +02:00
|
|
|
lea edx, [eax + 4]
|
|
|
|
mov eax, dword[eax]
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ebx, LOOPBACK_DEVICE
|
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
cmp eax, AF_INET4
|
2013-05-28 19:34:26 +02:00
|
|
|
je IPv4_input
|
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", ax
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
.dump:
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: dumping\n"
|
2013-08-07 15:13:29 +02:00
|
|
|
call NET_packet_free
|
2013-05-28 19:34:26 +02:00
|
|
|
add esp, 4
|
|
|
|
ret
|
|
|
|
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
;
|
|
|
|
; LOOP_output
|
|
|
|
;
|
|
|
|
; IN:
|
2013-06-06 08:08:45 +02:00
|
|
|
; ecx = packet size
|
|
|
|
; edi = address family
|
2013-05-28 19:34:26 +02:00
|
|
|
;
|
2013-06-06 08:08:45 +02:00
|
|
|
; OUT: edi = 0 on error, pointer to buffer otherwise
|
|
|
|
; eax = buffer start
|
|
|
|
; ebx = to device structure
|
|
|
|
; ecx = unchanged (packet size of embedded data)
|
|
|
|
; edx = size of complete buffer
|
2013-05-28 19:34:26 +02:00
|
|
|
;
|
|
|
|
;-----------------------------------------------------------------
|
|
|
|
align 4
|
|
|
|
LOOP_output:
|
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
push ecx
|
2013-06-04 16:12:37 +02:00
|
|
|
push edi
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
add ecx, 4
|
2013-05-28 19:34:26 +02:00
|
|
|
cmp ecx, [LOOPBACK_DEVICE.mtu]
|
|
|
|
ja .out_of_ram
|
|
|
|
stdcall kernel_alloc, ecx
|
|
|
|
test eax, eax
|
|
|
|
jz .out_of_ram
|
|
|
|
mov edi, eax
|
2013-06-04 16:12:37 +02:00
|
|
|
pop eax
|
|
|
|
stosd
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-06-04 16:12:37 +02:00
|
|
|
lea eax, [edi - 4] ; Set eax to buffer start
|
2013-05-28 19:34:26 +02:00
|
|
|
pop ecx
|
2013-06-04 16:12:37 +02:00
|
|
|
lea edx, [ecx + 4] ; Set edx to complete buffer size
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ebx, LOOPBACK_DEVICE
|
|
|
|
|
2013-06-06 08:08:45 +02:00
|
|
|
inc [LOOPBACK_DEVICE.packets_tx]
|
|
|
|
add dword[LOOPBACK_DEVICE.bytes_tx], ecx
|
|
|
|
adc dword[LOOPBACK_DEVICE.bytes_tx + 4], 0
|
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output: ptr=%x size=%u\n", eax, edx
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
.out_of_ram:
|
2013-06-06 08:08:45 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_ERROR, "LOOP_output: out of memory\n"
|
2013-06-04 16:12:37 +02:00
|
|
|
add esp, 4+4
|
|
|
|
xor edi, edi
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
|