2013-05-28 19:34:26 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2019-08-25 20:21:44 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2019. 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
|
2015-12-27 16:37:31 +01:00
|
|
|
.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
|
|
|
|
2015-12-27 16:37:31 +01:00
|
|
|
macro loop_init {
|
2013-06-05 02:21:20 +02:00
|
|
|
local .fail
|
|
|
|
|
|
|
|
mov ebx, LOOPBACK_DEVICE
|
2015-12-27 16:37:31 +01:00
|
|
|
call net_add_device
|
2013-06-05 02:21:20 +02:00
|
|
|
|
|
|
|
cmp eax, -1
|
|
|
|
je .fail
|
|
|
|
|
2019-08-25 20:21:44 +02:00
|
|
|
mov [IPv4_address], 127 + 1 shl 24
|
|
|
|
mov [IPv4_subnet], 255
|
|
|
|
mov [IPv4_broadcast], 0xffffff00 + 127
|
2013-06-05 02:21:20 +02:00
|
|
|
|
|
|
|
.fail:
|
|
|
|
}
|
|
|
|
|
2015-12-16 22:20:53 +01:00
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
; ;
|
2015-12-27 16:37:31 +01:00
|
|
|
; loop_input ;
|
2015-12-16 22:20:53 +01:00
|
|
|
; ;
|
|
|
|
; IN: [esp+4] = Pointer to buffer ;
|
|
|
|
; ;
|
2019-08-25 20:21:44 +02:00
|
|
|
; OUT: eax = 0 on success, errorcode otherwise ;
|
2015-12-16 22:20:53 +01:00
|
|
|
; ;
|
|
|
|
;-----------------------------------------------------------------;
|
2013-05-28 19:34:26 +02:00
|
|
|
align 4
|
2015-12-27 16:37:31 +01:00
|
|
|
loop_input:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
mov eax, [esp+4]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
; Update stats
|
2019-08-25 20:21:44 +02:00
|
|
|
inc [LOOPBACK_DEVICE.packets_tx]
|
2013-06-06 08:08:45 +02:00
|
|
|
inc [LOOPBACK_DEVICE.packets_rx]
|
2015-03-17 22:50:29 +01:00
|
|
|
|
|
|
|
mov ecx, [eax + NET_BUFF.length]
|
2013-06-06 08:08:45 +02:00
|
|
|
add dword[LOOPBACK_DEVICE.bytes_rx], ecx
|
|
|
|
adc dword[LOOPBACK_DEVICE.bytes_rx + 4], 0
|
2019-08-25 20:21:44 +02:00
|
|
|
add dword[LOOPBACK_DEVICE.bytes_tx], ecx
|
|
|
|
adc dword[LOOPBACK_DEVICE.bytes_tx + 4], 0
|
2013-06-06 08:08:45 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: ptr=%x size=%u\n", eax, ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
; Reverse buffptr and returnaddr on stack
|
|
|
|
pop edx edi
|
2019-08-25 20:21:44 +02:00
|
|
|
push edx .done edi
|
2015-03-17 22:50:29 +01:00
|
|
|
|
|
|
|
; 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
|
2013-06-04 16:12:37 +02:00
|
|
|
cmp eax, AF_INET4
|
2015-12-27 16:37:31 +01:00
|
|
|
je ipv4_input
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_input: Unknown packet type=%x\n", eax
|
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"
|
2015-12-27 16:37:31 +01:00
|
|
|
call net_buff_free
|
2019-08-25 20:21:44 +02:00
|
|
|
|
|
|
|
or eax, -1
|
|
|
|
ret
|
|
|
|
|
|
|
|
.done:
|
|
|
|
xor eax, eax
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
|
2015-12-16 22:20:53 +01:00
|
|
|
;-----------------------------------------------------------------;
|
|
|
|
; ;
|
2015-12-27 16:37:31 +01:00
|
|
|
; loop_output ;
|
2015-12-16 22:20:53 +01:00
|
|
|
; ;
|
|
|
|
; IN: ecx = packet size ;
|
|
|
|
; edi = address family ;
|
|
|
|
; ;
|
|
|
|
; OUT: eax = start of net frame / 0 on error ;
|
|
|
|
; ebx = to device structure ;
|
|
|
|
; ecx = unchanged (packet size of embedded data) ;
|
|
|
|
; edi = start of payload ;
|
|
|
|
; ;
|
|
|
|
;-----------------------------------------------------------------;
|
2013-05-28 19:34:26 +02:00
|
|
|
align 4
|
2015-12-27 16:37:31 +01:00
|
|
|
loop_output:
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2013-05-28 21:19:23 +02:00
|
|
|
DEBUGF DEBUG_NETWORK_VERBOSE, "LOOP_output\n"
|
2013-05-28 19:34:26 +02:00
|
|
|
|
|
|
|
cmp ecx, [LOOPBACK_DEVICE.mtu]
|
2015-03-17 22:50:29 +01:00
|
|
|
ja .too_large
|
|
|
|
|
|
|
|
push ecx edi
|
2015-03-17 23:01:39 +01:00
|
|
|
add ecx, NET_BUFF.data
|
2015-12-27 16:37:31 +01:00
|
|
|
stdcall net_buff_alloc, ecx
|
2013-05-28 19:34:26 +02:00
|
|
|
test eax, eax
|
|
|
|
jz .out_of_ram
|
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
pop edi
|
|
|
|
mov [eax + NET_BUFF.type], edi
|
2013-05-28 19:34:26 +02:00
|
|
|
mov ebx, LOOPBACK_DEVICE
|
2015-03-17 22:50:29 +01:00
|
|
|
mov [eax + NET_BUFF.device], ebx
|
|
|
|
pop ecx
|
|
|
|
mov [eax + NET_BUFF.length], ecx
|
|
|
|
lea edi, [eax + NET_BUFF.data]
|
2013-05-28 19:34:26 +02:00
|
|
|
|
2015-03-17 22:50:29 +01:00
|
|
|
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
|
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
|
2015-03-17 22:50:29 +01:00
|
|
|
xor eax, eax
|
2013-05-28 19:34:26 +02:00
|
|
|
ret
|
|
|
|
|
|
|
|
|