Added crude loopback device.

git-svn-id: svn://kolibrios.org@2914 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2012-08-08 13:14:32 +00:00
parent a9f1828898
commit cfa8509ec1
5 changed files with 149 additions and 7 deletions

View File

@ -578,6 +578,9 @@ IPv4_output:
push ecx eax edx di push ecx eax edx di
cmp eax, 1 shl 24 + 127
je .loopback
call IPv4_dest_to_dev ; outputs device number in edi, dest ip in eax call IPv4_dest_to_dev ; outputs device number in edi, dest ip in eax
call ARP_IP_to_MAC call ARP_IP_to_MAC
test eax, 0xffff0000 ; error bits test eax, 0xffff0000 ; error bits
@ -597,6 +600,7 @@ IPv4_output:
jz .eth_error jz .eth_error
add esp, 6 ; pop the mac out of the stack add esp, 6 ; pop the mac out of the stack
.continue:
xchg cl, ch ; internet byte order xchg cl, ch ; internet byte order
mov [edi + IPv4_header.VersionAndIHL], 0x45 ; IPv4, normal length (no Optional header) mov [edi + IPv4_header.VersionAndIHL], 0x45 ; IPv4, normal length (no Optional header)
mov [edi + IPv4_header.TypeOfService], 0 ; nothing special, just plain ip packet mov [edi + IPv4_header.TypeOfService], 0 ; nothing special, just plain ip packet
@ -633,6 +637,12 @@ IPv4_output:
xor edi, edi xor edi, edi
ret ret
.loopback:
mov dword [esp + 2], eax
add ecx, sizeof.IPv4_header
mov di, ETHER_IPv4
call LOOP_output
jmp .continue

View File

@ -166,6 +166,11 @@ ICMP_input:
DEBUGF 1,"got echo request\n" DEBUGF 1,"got echo request\n"
mov [edx + ICMP_header.Type], ICMP_ECHOREPLY ; Change Packet type to reply mov [edx + ICMP_header.Type], ICMP_ECHOREPLY ; Change Packet type to reply
mov esi, [esp] ; Start of buffer
cmp dword[edi + 4], 1 shl 24 + 127
je .loopback
; Update stats (and validate device ptr) ; Update stats (and validate device ptr)
call NET_ptr_to_num call NET_ptr_to_num
cmp edi,-1 cmp edi,-1
@ -175,7 +180,6 @@ ICMP_input:
; exchange dest and source address in IP header ; exchange dest and source address in IP header
; exchange dest and source MAC in ETH header ; exchange dest and source MAC in ETH header
mov esi, [esp] ; Start of buffer
push dword [esi + ETH_header.DstMAC] push dword [esi + ETH_header.DstMAC]
push dword [esi + ETH_header.SrcMAC] push dword [esi + ETH_header.SrcMAC]
pop dword [esi + ETH_header.DstMAC] pop dword [esi + ETH_header.DstMAC]
@ -184,8 +188,10 @@ ICMP_input:
push word [esi + ETH_header.SrcMAC + 4] push word [esi + ETH_header.SrcMAC + 4]
pop word [esi + ETH_header.DstMAC + 4] pop word [esi + ETH_header.DstMAC + 4]
pop word [esi + ETH_header.SrcMAC + 4] pop word [esi + ETH_header.SrcMAC + 4]
add esi, sizeof.ETH_header-2
add esi, sizeof.ETH_header .loopback:
add esi, 2
push [esi + IPv4_header.SourceAddress] push [esi + IPv4_header.SourceAddress]
push [esi + IPv4_header.DestinationAddress] push [esi + IPv4_header.DestinationAddress]
pop [esi + IPv4_header.SourceAddress] pop [esi + IPv4_header.SourceAddress]

View File

@ -0,0 +1,126 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;;
;; 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 ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Revision: 2891 $
iglobal
LOOPBACK_DEVICE:
.type dd NET_TYPE_LOOPBACK
.mtu dd 4096
.name dd .namestr
.unload dd .dummy_fn
.reset dd .dummy_fn
.transmit dd LOOP_input
.bytes_tx dq 0
.bytes_rx dq 0
.packets_tx dd 0
.packets_rx dd 0
.namestr db 'loopback', 0
.dummy_fn:
ret
endg
;-----------------------------------------------------------------
;
; LOOP_input
;
; IN: [esp+4] = Pointer to buffer
; [esp+8] = size of buffer
;
; OUT: /
;
;-----------------------------------------------------------------
align 4
LOOP_input:
pop ebx
pop eax
pop ecx
push ebx
push ecx
push eax
DEBUGF 1,"LOOP_input: size=%u\n", ecx
lea edx, [eax + 2]
mov ax, word[eax]
mov ebx, LOOPBACK_DEVICE
cmp ax, ETHER_IPv4
je IPv4_input
DEBUGF 2,"LOOP_input: Unknown packet type=%x\n", ax
.dump:
DEBUGF 2,"LOOP_input: dumping\n"
call kernel_free
add esp, 4
ret
;-----------------------------------------------------------------
;
; LOOP_output
;
; IN:
; ecx = packet size
; di = protocol
;
; 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
;
;-----------------------------------------------------------------
align 4
LOOP_output:
DEBUGF 1,"LOOP_output: "
push ecx
push di
add ecx, 2
cmp ecx, [LOOPBACK_DEVICE.mtu]
ja .out_of_ram
stdcall kernel_alloc, ecx
test eax, eax
jz .out_of_ram
mov edi, eax
pop ax
stosw
lea eax, [edi - 2] ; Set eax to buffer start
pop ecx
lea edx, [ecx + 2] ; Set edx to complete buffer size
mov ebx, LOOPBACK_DEVICE
.done:
DEBUGF 1,"ptr=%x size=%u\n", eax, edx
ret
.out_of_ram:
DEBUGF 2,"error\n"
add esp, 2+4
sub edi, edi
ret

View File

@ -96,6 +96,7 @@ SS_MORETOCOME = 0x400
SOCKET_MAXDATA = 4096*32 ; must be 4096*(power of 2) where 'power of 2' is at least 8 SOCKET_MAXDATA = 4096*32 ; must be 4096*(power of 2) where 'power of 2' is at least 8
; Network driver types ; Network driver types
NET_TYPE_LOOPBACK = 0
NET_TYPE_ETH = 1 NET_TYPE_ETH = 1
NET_TYPE_SLIP = 2 NET_TYPE_SLIP = 2
@ -165,6 +166,7 @@ macro ntohw reg {
include "queue.inc" include "queue.inc"
include "loopback.inc"
include "ethernet.inc" include "ethernet.inc"
;include "PPPoE.inc" ;include "PPPoE.inc"

View File

@ -489,12 +489,10 @@ align 4
push [edx + TCP_header.SequenceNumber] push [edx + TCP_header.SequenceNumber]
pop [ebx + TCP_SOCKET.IRS] pop [ebx + TCP_SOCKET.IRS]
push [TCP_sequence_num] ;;;;; mov eax, [TCP_sequence_num]
add [TCP_sequence_num], 64000 / 2 add [TCP_sequence_num], 64000 / 2
pop [ebx + TCP_SOCKET.ISS] mov [ebx + TCP_SOCKET.ISS], eax
mov [ebx + TCP_SOCKET.SND_NXT], eax
push [ebx + TCP_SOCKET.ISS]
pop [ebx + TCP_SOCKET.SND_NXT]
TCP_sendseqinit ebx TCP_sendseqinit ebx
TCP_rcvseqinit ebx TCP_rcvseqinit ebx