Replaced some of the 'magic numbers' in net branch with constants.

git-svn-id: svn://kolibrios.org@2301 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2011-11-07 21:03:20 +00:00
parent b7875fe3bf
commit 8aee69dafb
8 changed files with 66 additions and 58 deletions

View File

@ -161,7 +161,7 @@ align 4
ARP_input: ARP_input:
DEBUGF 1,"ARP_Handler - start\n" DEBUGF 1,"ARP_Handler - start\n"
cmp ecx, 28 cmp ecx, ARP_Packet.size
jb .exit jb .exit
;--------------------- ;---------------------

View File

@ -240,9 +240,9 @@ IPv4_input: ; TODO: implement handler for IP options
; check for broadcast ; check for broadcast
mov eax, dword[SUBNET_LIST+edi] mov eax, [SUBNET_LIST+edi]
not eax not eax
or eax, dword[IP_LIST+edi] or eax, [IP_LIST+edi]
cmp [edx + IPv4_Packet.DestinationAddress], eax cmp [edx + IPv4_Packet.DestinationAddress], eax
je .ip_ok je .ip_ok
@ -672,7 +672,7 @@ IPv4_output_raw:
DEBUGF 1,"IPv4_output_raw: size=%u ptr=%x socket=%x\n", ecx, esi, eax DEBUGF 1,"IPv4_output_raw: size=%u ptr=%x socket=%x\n", ecx, esi, eax
cmp ecx, 1480 ;;;;; cmp ecx, 1480 ;;;;; FIXME
ja .too_large ja .too_large
sub esp, 8 sub esp, 8
@ -778,10 +778,10 @@ IPv4_fragment:
push eax push eax
push esi ; ptr to ip header push esi ; ptr to ip header
sub ecx, 20 ; substract header size sub ecx, IPv4_Packet.DataOrOptional ; substract header size
push ecx ; max data size push ecx ; max data size
push dword 0 ; offset push dword 0 ; offset
.new_fragment: .new_fragment:
DEBUGF 1,"Ipv4_fragment - new_fragmentn" DEBUGF 1,"Ipv4_fragment - new_fragmentn"
@ -802,7 +802,7 @@ IPv4_fragment:
; copy data ; copy data
mov esi, [esp + 2*4] mov esi, [esp + 2*4]
add esi, 20 add esi, IPv4_Packet.DataOrOptional
add esi, [esp] ; offset add esi, [esp] ; offset
mov ecx, [esp + 1*4] mov ecx, [esp + 1*4]
@ -811,7 +811,7 @@ IPv4_fragment:
; now, correct header ; now, correct header
mov ecx, [esp + 1*4] mov ecx, [esp + 1*4]
add ecx, 20 add ecx, IPv4_Packet.DataOrOptional
xchg cl, ch xchg cl, ch
mov [edi + IPv4_Packet.TotalLength], cx mov [edi + IPv4_Packet.TotalLength], cx

View File

@ -23,6 +23,8 @@ struct ETH_FRAME
.Data: ; data (46-1500 bytes for a normal packet) .Data: ; data (46-1500 bytes for a normal packet)
ends ends
ETH_FRAME_MINIMUM equ 60
virtual at NET_DEVICE.end virtual at NET_DEVICE.end
ETH_DEVICE: ETH_DEVICE:
@ -63,7 +65,7 @@ ETH_input:
mov ecx, [esp+4] mov ecx, [esp+4]
DEBUGF 1,"ETH_input - size: %u\n", ecx DEBUGF 1,"ETH_input - size: %u\n", ecx
cmp ecx, 60 ; check packet length cmp ecx, ETH_FRAME_MINIMUM
jb .dump jb .dump
sub ecx, ETH_FRAME.Data sub ecx, ETH_FRAME.Data
@ -140,13 +142,13 @@ ETH_output:
pop ecx ; >> 1 pop ecx ; >> 1
cmp edx, 60 ; minimum ethernet packet size cmp edx, ETH_FRAME_MINIMUM
jb .adjust_size jb .adjust_size
DEBUGF 1,"ETH_output: done: %x total size: %u\n", eax, edx DEBUGF 1,"ETH_output: done: %x total size: %u\n", eax, edx
ret ret
.adjust_size: .adjust_size:
mov edx, 60 mov edx, ETH_FRAME_MINIMUM
test edx, edx ; clear zero flag test edx, edx ; clear zero flag
ret ret

View File

@ -237,9 +237,25 @@ macro SOCKET_init {
; Socket API (function 74) ; Socket API (function 74)
; ;
;----------------------------------------------------------------- ;-----------------------------------------------------------------
align 16
sock_sysfn_table:
dd SOCKET_open ; 0
dd SOCKET_close ; 1
dd SOCKET_bind ; 2
dd SOCKET_listen ; 3
dd SOCKET_connect ; 4
dd SOCKET_accept ; 5
dd SOCKET_send ; 6
dd SOCKET_receive ; 7
dd SOCKET_set_opt ; 8
dd SOCKET_get_opt ; 9
SOCKET_SYSFUNCS = ($ - sock_sysfn_table)/4
align 4 align 4
sys_socket: sys_socket:
cmp ebx, 9 ; highest possible number cmp ebx, SOCKET_SYSFUNCS-1
ja @f ja @f
jmp dword [sock_sysfn_table + 4*ebx] jmp dword [sock_sysfn_table + 4*ebx]
@@: @@:
@ -252,18 +268,7 @@ s_error:
ret ret
align 4
sock_sysfn_table:
dd SOCKET_open ; 0
dd SOCKET_close ; 1
dd SOCKET_bind ; 2
dd SOCKET_listen ; 3
dd SOCKET_connect ; 4
dd SOCKET_accept ; 5
dd SOCKET_send ; 6
dd SOCKET_receive ; 7
dd SOCKET_set_opt ; 8
dd SOCKET_get_opt ; 9
;----------------------------------------------------------------- ;-----------------------------------------------------------------
; ;
@ -395,10 +400,10 @@ SOCKET_bind:
cmp esi, 6 cmp esi, 6
jb s_error jb s_error
push word [edx + 2] pushw [edx + 2]
pop word [eax + UDP_SOCKET.LocalPort] pop [eax + UDP_SOCKET.LocalPort]
push dword [edx + 4] pushd [edx + 4]
pop [eax + IP_SOCKET.LocalIP] pop [eax + IP_SOCKET.LocalIP]
DEBUGF 1,"local ip: %u.%u.%u.%u\n",\ DEBUGF 1,"local ip: %u.%u.%u.%u\n",\
@ -463,10 +468,10 @@ align 4
lea ebx, [eax + SOCKET.lock] lea ebx, [eax + SOCKET.lock]
call wait_mutex call wait_mutex
push word [edx + 2] pushw [edx + 2]
pop [eax + UDP_SOCKET.RemotePort] pop [eax + UDP_SOCKET.RemotePort]
push dword [edx + 4] pushd [edx + 4]
pop [eax + IP_SOCKET.RemoteIP] pop [eax + IP_SOCKET.RemoteIP]
cmp [eax + UDP_SOCKET.LocalPort], 0 cmp [eax + UDP_SOCKET.LocalPort], 0
@ -489,10 +494,10 @@ align 4
lea ebx, [eax + SOCKET.lock] lea ebx, [eax + SOCKET.lock]
call wait_mutex call wait_mutex
push word [edx + 2] pushw [edx + 2]
pop [eax + TCP_SOCKET.RemotePort] pop [eax + TCP_SOCKET.RemotePort]
push dword [edx + 4] pushd [edx + 4]
pop [eax + IP_SOCKET.RemoteIP] pop [eax + IP_SOCKET.RemoteIP]
cmp [eax + TCP_SOCKET.LocalPort], 0 cmp [eax + TCP_SOCKET.LocalPort], 0
@ -532,8 +537,8 @@ align 4
lea ebx, [eax + SOCKET.lock] lea ebx, [eax + SOCKET.lock]
call wait_mutex call wait_mutex
push dword [edx + 4] pushd [edx + 4]
pop dword [eax + IP_SOCKET.RemoteIP] pop [eax + IP_SOCKET.RemoteIP]
push eax push eax
init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue

View File

@ -17,17 +17,17 @@
$Revision$ $Revision$
; Socket states ; Socket states
TCPS_CLOSED equ 0 TCPS_CLOSED equ 0
TCPS_LISTEN equ 1 TCPS_LISTEN equ 1
TCPS_SYN_SENT equ 2 TCPS_SYN_SENT equ 2
TCPS_SYN_RECEIVED equ 3 TCPS_SYN_RECEIVED equ 3
TCPS_ESTABLISHED equ 4 TCPS_ESTABLISHED equ 4
TCPS_CLOSE_WAIT equ 5 TCPS_CLOSE_WAIT equ 5
TCPS_FIN_WAIT_1 equ 6 TCPS_FIN_WAIT_1 equ 6
TCPS_CLOSING equ 7 TCPS_CLOSING equ 7
TCPS_LAST_ACK equ 8 TCPS_LAST_ACK equ 8
TCPS_FIN_WAIT_2 equ 9 TCPS_FIN_WAIT_2 equ 9
TCPS_TIMED_WAIT equ 10 TCPS_TIMED_WAIT equ 10
; Socket Flags ; Socket Flags
TF_ACKNOW equ 1 shl 0 ; ack peer immediately TF_ACKNOW equ 1 shl 0 ; ack peer immediately

View File

@ -45,7 +45,7 @@ TCP_input:
DEBUGF 1,"headersize=%u\n", eax DEBUGF 1,"headersize=%u\n", eax
cmp eax, 20 cmp eax, TCP_segment.DataOffset
jb .drop_not_locked jb .drop_not_locked
;------------------------------- ;-------------------------------
@ -72,7 +72,7 @@ TCP_input:
;----------------------------------------------------------------------------------------- ;-----------------------------------------------------------------------------------------
; Check if this packet has a timestamp option (We do it here so we can process it quickly) ; Check if this packet has a timestamp option (We do it here so we can process it quickly)
cmp esi, 20 + 12 ; Timestamp option is 12 bytes cmp esi, TCP_segment.DataOffset + 12 ; Timestamp option is 12 bytes
jb .no_timestamp jb .no_timestamp
je .is_ok je .is_ok
@ -213,13 +213,13 @@ TCP_input:
;-------------------- ;--------------------
; Process TCP options ; Process TCP options
cmp esi, 20 ; esi is headersize cmp esi, TCP_segment.DataOffset ; esi is headersize
je .no_options je .no_options
DEBUGF 1,"Segment has options\n" DEBUGF 1,"Segment has options\n"
cmp [ebx + TCP_SOCKET.t_state], TCPS_LISTEN ; no options when in listen state cmp [ebx + TCP_SOCKET.t_state], TCPS_LISTEN ; no options when in listen state
jz .not_uni_xfer ; also no header prediction jz .not_uni_xfer ; also no header prediction
lea edi, [edx + TCP_segment.Data] lea edi, [edx + TCP_segment.Data]
lea eax, [edx + esi] lea eax, [edx + esi]

View File

@ -277,7 +277,7 @@ TCP_output:
test [eax + TCP_SOCKET.t_flags], TF_NOOPT test [eax + TCP_SOCKET.t_flags], TF_NOOPT
jnz .options_done jnz .options_done
mov ecx, 1460 mov ecx, 1460 ;;;; FIXME
or ecx, TCP_OPT_MAXSEG shl 24 + 4 shl 16 or ecx, TCP_OPT_MAXSEG shl 24 + 4 shl 16
bswap ecx bswap ecx
push ecx push ecx
@ -454,7 +454,7 @@ TCP_output:
; set retransmission timer if not already set, and not doing an ACK or keepalive probe ; set retransmission timer if not already set, and not doing an ACK or keepalive probe
cmp [eax + TCP_SOCKET.timer_retransmission], 1000 ;;;; cmp [eax + TCP_SOCKET.timer_retransmission], 1000 ;;;; FIXME
jb .retransmit_set jb .retransmit_set
cmp edx, [eax + TCP_SOCKET.SND_UNA] ; edx = [eax + TCP_SOCKET.SND_NXT] cmp edx, [eax + TCP_SOCKET.SND_UNA] ; edx = [eax + TCP_SOCKET.SND_NXT]

View File

@ -268,7 +268,7 @@ TCP_respond_socket:
mov eax, [esi + TCP_SOCKET.RCV_NXT] mov eax, [esi + TCP_SOCKET.RCV_NXT]
bswap eax bswap eax
stosd stosd
mov al, 0x50 ; Dataoffset: 20 bytes mov al, 0x50 ; Dataoffset: 20 bytes (TCP_segment.DataOffset)
stosb stosb
mov al, cl mov al, cl
stosb stosb
@ -323,8 +323,8 @@ TCP_respond_segment:
; Create the IP packet ; Create the IP packet
push cx edx push cx edx
mov ebx, [edx - 20 + IPv4_Packet.SourceAddress] ;;;; and what if ip packet had options?! mov ebx, [edx - IPv4_Packet.DataOrOptional + IPv4_Packet.SourceAddress] ;;;; FIXME: and what if ip packet had options?!
mov eax, [edx - 20 + IPv4_Packet.DestinationAddress] ;;; mov eax, [edx - IPv4_Packet.DataOrOptional + IPv4_Packet.DestinationAddress] ;;;
mov ecx, TCP_segment.Data mov ecx, TCP_segment.Data
mov di , IP_PROTO_TCP shl 8 + 128 mov di , IP_PROTO_TCP shl 8 + 128
call IPv4_output call IPv4_output
@ -347,7 +347,7 @@ TCP_respond_segment:
stosd stosd
xor eax, eax xor eax, eax
stosd stosd
mov al, 0x50 ; Dataoffset: 20 bytes mov al, 0x50 ; Dataoffset: 20 bytes (TCP_segment.Data)
stosb stosb
mov al, cl mov al, cl
stosb stosb
@ -363,7 +363,8 @@ TCP_respond_segment:
.checksum: .checksum:
lea esi, [edi - TCP_segment.Data] lea esi, [edi - TCP_segment.Data]
mov ecx, TCP_segment.Data mov ecx, TCP_segment.Data
TCP_checksum (esi - 20 + IPv4_Packet.DestinationAddress), (esi - 20 + IPv4_Packet.DestinationAddress) TCP_checksum (esi - IPv4_Packet.DataOrOptional + IPv4_Packet.DestinationAddress),\ ; FIXME
(esi - IPv4_Packet.DataOrOptional + IPv4_Packet.SourceAddress)
mov [esi+TCP_segment.Checksum], dx mov [esi+TCP_segment.Checksum], dx
;-------------------- ;--------------------