Cleanup/small refactor of some internal network functions.

git-svn-id: svn://kolibrios.org@5015 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2014-08-02 12:48:32 +00:00
parent 3f20695fd0
commit e7360b0f51
7 changed files with 57 additions and 64 deletions

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; ARP.INC ;; ;; ARP.INC ;;
@ -318,10 +318,9 @@ ARP_output_request:
DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_output_request: ip=%u.%u.%u.%u device=0x%x\n",\ DEBUGF DEBUG_NETWORK_VERBOSE, "ARP_output_request: ip=%u.%u.%u.%u device=0x%x\n",\
[esp]:1, [esp + 1]:1, [esp + 2]:1, [esp + 3]:1, ebx [esp]:1, [esp + 1]:1, [esp + 2]:1, [esp + 3]:1, ebx
lea eax, [ebx + ETH_DEVICE.mac] ; local device mac mov ax, ETHER_PROTO_ARP
mov edx, ETH_BROADCAST ; broadcast mac
mov ecx, sizeof.ARP_header mov ecx, sizeof.ARP_header
mov di, ETHER_PROTO_ARP mov edx, ETH_BROADCAST ; broadcast mac
call ETH_output call ETH_output
jz .exit jz .exit

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; IPv4.INC ;; ;; IPv4.INC ;;
@ -574,13 +574,13 @@ IPv4_find_fragment_slot:
; IN: eax = Destination IP ; IN: eax = Destination IP
; ecx = data length ; ecx = data length
; edx = Source IP ; edx = Source IP
; di = TTL shl 8 + protocol ; di = TTL shl 8 + protocol
; ;
; OUT: eax = pointer to buffer start ; OUT: eax = pointer to buffer start / 0 on error
; ebx = pointer to device struct (needed for sending procedure) ; ebx = device ptr (send packet through this device)
; ecx = unchanged (packet size of embedded data) ; ecx = data length
; edx = size of complete buffer ; edx = size of complete frame
; edi = pointer to start of data (0 on error) ; edi = start of IPv4 payload
; ;
;------------------------------------------------------------------ ;------------------------------------------------------------------
align 4 align 4
@ -594,7 +594,6 @@ IPv4_output:
push ecx di eax push ecx di eax
call IPv4_route ; outputs device number in edi, dest ip in eax, source IP in edx call IPv4_route ; outputs device number in edi, dest ip in eax, source IP in edx
push edx push edx
test edi, edi test edi, edi
jz .loopback jz .loopback
@ -606,12 +605,11 @@ IPv4_output:
inc [IPv4_packets_tx + edi] ; update stats inc [IPv4_packets_tx + edi] ; update stats
mov ax, ETHER_PROTO_IPv4
mov ebx, [NET_DRV_LIST + edi] mov ebx, [NET_DRV_LIST + edi]
lea eax, [ebx + ETH_DEVICE.mac]
mov edx, esp
mov ecx, [esp + 6 + 8 + 2] mov ecx, [esp + 6 + 8 + 2]
add ecx, sizeof.IPv4_header add ecx, sizeof.IPv4_header
mov di, ETHER_PROTO_IPv4 mov edx, esp
call ETH_output call ETH_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
@ -641,18 +639,18 @@ IPv4_output:
.eth_error: .eth_error:
DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: ethernet error\n" DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: ethernet error\n"
add esp, 3*4+2+6 add esp, 3*4+2+6
xor edi, edi xor eax, eax
ret ret
.arp_error: .arp_error:
DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: ARP error=%x\n", eax DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: ARP error=%x\n", eax
add esp, 3*4+2 add esp, 3*4+2
xor edi, edi xor eax, eax
ret ret
.too_large: .too_large:
DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: Packet too large!\n" DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output: Packet too large!\n"
xor edi, edi xor eax, eax
ret ret
.loopback: .loopback:
@ -674,7 +672,7 @@ IPv4_output:
; ecx = data length ; ecx = data length
; esi = data ptr ; esi = data ptr
; ;
; OUT: / ; OUT: eax = -1 on error
; ;
;------------------------------------------------------------------ ;------------------------------------------------------------------
align 4 align 4
@ -698,15 +696,13 @@ IPv4_output_raw:
push ax push ax
inc [IPv4_packets_tx + 4*edi] inc [IPv4_packets_tx + 4*edi]
mov ax, ETHER_PROTO_IPv4
mov ebx, [NET_DRV_LIST + 4*edi] mov ebx, [NET_DRV_LIST + 4*edi]
lea eax, [ebx + ETH_DEVICE.mac]
mov edx, esp
mov ecx, [esp + 6 + 4] mov ecx, [esp + 6 + 4]
add ecx, sizeof.IPv4_header add ecx, sizeof.IPv4_header
mov di, ETHER_PROTO_IPv4 mov edx, esp
call ETH_output call ETH_output
jz .error jz .error
add esp, 6 ; pop the mac add esp, 6 ; pop the mac
mov dword[esp+4+4], edx mov dword[esp+4+4], edx
@ -745,7 +741,7 @@ IPv4_output_raw:
add esp, 8+4+4 add esp, 8+4+4
.too_large: .too_large:
DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output_raw: Failed\n" DEBUGF DEBUG_NETWORK_ERROR, "IPv4_output_raw: Failed\n"
sub edi, edi or eax, -1
ret ret
@ -794,13 +790,9 @@ IPv4_fragment:
.new_fragment: .new_fragment:
DEBUGF DEBUG_NETWORK_VERBOSE, "Ipv4_fragment: new fragment" DEBUGF DEBUG_NETWORK_VERBOSE, "Ipv4_fragment: new fragment"
mov ax, ETHER_PROTO_IPv4
mov eax, [esp + 3*4]
lea ebx, [esp + 4*4] lea ebx, [esp + 4*4]
mov di , ETHER_PROTO_IPv4
call ETH_output call ETH_output
cmp edi, -1
jz .err jz .err
; copy header ; copy header

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2012-2013. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2012-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; PPPoE.INC ;; ;; PPPoE.INC ;;
@ -243,17 +243,15 @@ PPPoE_session_input:
; ;
; PPPoE_output ; PPPoE_output
; ;
; IN: ; IN: ax = protocol
; ebx = device ptr ; ebx = device ptr
; ecx = packet size ; ecx = packet size
; ;
; di = protocol ; OUT: eax = buffer start / 0 on error
; ; ebx = device ptr
; OUT: edi = 0 on error, pointer to buffer otherwise ; ecx = packet size
; eax = buffer start
; ebx = to device structure
; ecx = unchanged (packet size of embedded data)
; edx = size of complete buffer ; edx = size of complete buffer
; edi = start of PPP payload
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
@ -261,13 +259,12 @@ PPPoE_output:
DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_output: size=%u device=%x\n", ecx, ebx DEBUGF DEBUG_NETWORK_VERBOSE, "PPPoE_output: size=%u device=%x\n", ecx, ebx
pushw di pushw ax
pushw [PPPoE_SID] pushw [PPPoE_SID]
lea eax, [ebx + ETH_DEVICE.mac] mov ax, ETHER_PROTO_PPP_SESSION
lea edx, [PPPoE_MAC]
add ecx, PPPoE_frame.Payload + 2 add ecx, PPPoE_frame.Payload + 2
mov di, ETHER_PROTO_PPP_SESSION lea edx, [PPPoE_MAC]
call ETH_output call ETH_output
jz .eth_error jz .eth_error
@ -290,8 +287,7 @@ PPPoE_output:
.eth_error: .eth_error:
add esp, 4 add esp, 4
xor edi, edi xor eax, eax
ret ret

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; ETHERNET.INC ;; ;; ETHERNET.INC ;;
@ -166,17 +166,16 @@ ETH_process_input:
; ;
; ETH_output ; ETH_output
; ;
; IN: eax = pointer to source mac ; IN: ax = protocol
; ebx = device ptr ; ebx = device ptr
; ecx = packet size ; ecx = payload size
; edx = pointer to destination mac ; edx = pointer to destination mac
; di = protocol
; ;
; OUT: edi = 0 on error, pointer to buffer otherwise ; OUT: eax = start of ethernet frame / 0 on error
; eax = buffer start ; ebx = device ptr
; ebx = to device structure ; ecx = payload size
; ecx = unchanged (packet size of embedded data) ; edx = ethernet frame size
; edx = size of complete buffer ; edi = start of ethernet payload
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4
@ -184,11 +183,11 @@ ETH_output:
DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_output: size=%u device=%x\n", ecx, ebx DEBUGF DEBUG_NETWORK_VERBOSE, "ETH_output: size=%u device=%x\n", ecx, ebx
cmp ecx, [ebx + NET_DEVICE.mtu] cmp ecx, [ebx + ETH_DEVICE.mtu]
ja .exit ja .exit
push ecx push ecx
push di eax edx push ax edx
add ecx, sizeof.ETH_header add ecx, sizeof.ETH_header
stdcall kernel_alloc, ecx stdcall kernel_alloc, ecx
@ -199,7 +198,7 @@ ETH_output:
pop esi pop esi
movsd movsd
movsw movsw
pop esi lea esi, [ebx + ETH_DEVICE.mac]
movsd movsd
movsw movsw
pop ax pop ax
@ -217,18 +216,18 @@ ETH_output:
.adjust_size: .adjust_size:
mov edx, ETH_FRAME_MINIMUM mov edx, ETH_FRAME_MINIMUM
test edx, edx ; clear zero flag test edx, edx ; clear zero flag
jmp .done jmp .done
.out_of_ram: .out_of_ram:
DEBUGF DEBUG_NETWORK_ERROR, "ETH_output: Out of ram!\n" DEBUGF DEBUG_NETWORK_ERROR, "ETH_output: Out of ram!\n"
add esp, 4+4+2+4 add esp, 4+2+4
sub edi, edi xor eax, eax
ret ret
.exit: .exit:
DEBUGF DEBUG_NETWORK_ERROR, "ETH_output: Packet too large!\n" DEBUGF DEBUG_NETWORK_ERROR, "ETH_output: Packet too large!\n"
sub edi, edi xor eax, eax
ret ret

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; Part of the TCP/IP network stack for KolibriOS ;; ;; Part of the TCP/IP network stack for KolibriOS ;;
@ -273,6 +273,8 @@ TCP_api:
jz .packets_missed ; 2 jz .packets_missed ; 2
dec bl dec bl
jz .packets_dumped ; 3 jz .packets_dumped ; 3
dec bl
jz .packets_queued ; 4
.error: .error:
mov eax, -1 mov eax, -1
@ -293,3 +295,7 @@ TCP_api:
.packets_dumped: .packets_dumped:
mov eax, [TCP_segments_dumped + eax] mov eax, [TCP_segments_dumped + eax]
ret ret
.packets_queued:
mov eax, [TCP_queue + queue.size]
ret

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; Part of the TCP/IP network stack for KolibriOS ;; ;; Part of the TCP/IP network stack for KolibriOS ;;
@ -143,7 +143,7 @@ TCP_pull_out_of_band:
; ;
;------------------------- ;-------------------------
align 4 align 4
TCP_drop: TCP_drop: ; FIXME CHECKME TODO
DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_drop: %x\n", eax DEBUGF DEBUG_NETWORK_VERBOSE, "TCP_drop: %x\n", eax
@ -290,7 +290,6 @@ TCP_respond:
mov ecx, sizeof.TCP_header mov ecx, sizeof.TCP_header
mov di, IP_PROTO_TCP shl 8 + 128 mov di, IP_PROTO_TCP shl 8 + 128
call IPv4_output call IPv4_output
test edi, edi
jz .error jz .error
pop esi cx pop esi cx
push edx eax push edx eax

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; UDP.INC ;; ;; UDP.INC ;;
@ -245,6 +245,8 @@ UDP_input:
; ecx = number of bytes to send ; ecx = number of bytes to send
; esi = pointer to data ; esi = pointer to data
; ;
; OUT: eax = -1 on error
;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 4 align 4