diff --git a/kernel/branches/net/network/ARP.inc b/kernel/branches/net/network/ARP.inc index 285693c9b9..70ef8d2f42 100644 --- a/kernel/branches/net/network/ARP.inc +++ b/kernel/branches/net/network/ARP.inc @@ -161,7 +161,7 @@ align 4 ARP_input: DEBUGF 1,"ARP_Handler - start\n" - cmp ecx, 28 + cmp ecx, ARP_Packet.size jb .exit ;--------------------- diff --git a/kernel/branches/net/network/IPv4.inc b/kernel/branches/net/network/IPv4.inc index 1609209d93..8c789ebd70 100644 --- a/kernel/branches/net/network/IPv4.inc +++ b/kernel/branches/net/network/IPv4.inc @@ -240,9 +240,9 @@ IPv4_input: ; TODO: implement handler for IP options ; check for broadcast - mov eax, dword[SUBNET_LIST+edi] + mov eax, [SUBNET_LIST+edi] not eax - or eax, dword[IP_LIST+edi] + or eax, [IP_LIST+edi] cmp [edx + IPv4_Packet.DestinationAddress], eax 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 - cmp ecx, 1480 ;;;;; + cmp ecx, 1480 ;;;;; FIXME ja .too_large sub esp, 8 @@ -778,10 +778,10 @@ IPv4_fragment: push eax - push esi ; ptr to ip header - sub ecx, 20 ; substract header size - push ecx ; max data size - push dword 0 ; offset + push esi ; ptr to ip header + sub ecx, IPv4_Packet.DataOrOptional ; substract header size + push ecx ; max data size + push dword 0 ; offset .new_fragment: DEBUGF 1,"Ipv4_fragment - new_fragmentn" @@ -802,7 +802,7 @@ IPv4_fragment: ; copy data mov esi, [esp + 2*4] - add esi, 20 + add esi, IPv4_Packet.DataOrOptional add esi, [esp] ; offset mov ecx, [esp + 1*4] @@ -811,7 +811,7 @@ IPv4_fragment: ; now, correct header mov ecx, [esp + 1*4] - add ecx, 20 + add ecx, IPv4_Packet.DataOrOptional xchg cl, ch mov [edi + IPv4_Packet.TotalLength], cx diff --git a/kernel/branches/net/network/ethernet.inc b/kernel/branches/net/network/ethernet.inc index ce5481f393..c2a5f3eba3 100644 --- a/kernel/branches/net/network/ethernet.inc +++ b/kernel/branches/net/network/ethernet.inc @@ -23,6 +23,8 @@ struct ETH_FRAME .Data: ; data (46-1500 bytes for a normal packet) ends +ETH_FRAME_MINIMUM equ 60 + virtual at NET_DEVICE.end ETH_DEVICE: @@ -63,7 +65,7 @@ ETH_input: mov ecx, [esp+4] DEBUGF 1,"ETH_input - size: %u\n", ecx - cmp ecx, 60 ; check packet length + cmp ecx, ETH_FRAME_MINIMUM jb .dump sub ecx, ETH_FRAME.Data @@ -140,13 +142,13 @@ ETH_output: pop ecx ; >> 1 - cmp edx, 60 ; minimum ethernet packet size + cmp edx, ETH_FRAME_MINIMUM jb .adjust_size DEBUGF 1,"ETH_output: done: %x total size: %u\n", eax, edx ret .adjust_size: - mov edx, 60 + mov edx, ETH_FRAME_MINIMUM test edx, edx ; clear zero flag ret diff --git a/kernel/branches/net/network/socket.inc b/kernel/branches/net/network/socket.inc index 29e99431a4..232a5eb1f0 100644 --- a/kernel/branches/net/network/socket.inc +++ b/kernel/branches/net/network/socket.inc @@ -237,9 +237,25 @@ macro SOCKET_init { ; 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 sys_socket: - cmp ebx, 9 ; highest possible number + cmp ebx, SOCKET_SYSFUNCS-1 ja @f jmp dword [sock_sysfn_table + 4*ebx] @@: @@ -252,18 +268,7 @@ s_error: 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 jb s_error - push word [edx + 2] - pop word [eax + UDP_SOCKET.LocalPort] + pushw [edx + 2] + pop [eax + UDP_SOCKET.LocalPort] - push dword [edx + 4] + pushd [edx + 4] pop [eax + IP_SOCKET.LocalIP] DEBUGF 1,"local ip: %u.%u.%u.%u\n",\ @@ -463,10 +468,10 @@ align 4 lea ebx, [eax + SOCKET.lock] call wait_mutex - push word [edx + 2] + pushw [edx + 2] pop [eax + UDP_SOCKET.RemotePort] - push dword [edx + 4] + pushd [edx + 4] pop [eax + IP_SOCKET.RemoteIP] cmp [eax + UDP_SOCKET.LocalPort], 0 @@ -489,10 +494,10 @@ align 4 lea ebx, [eax + SOCKET.lock] call wait_mutex - push word [edx + 2] + pushw [edx + 2] pop [eax + TCP_SOCKET.RemotePort] - push dword [edx + 4] + pushd [edx + 4] pop [eax + IP_SOCKET.RemoteIP] cmp [eax + TCP_SOCKET.LocalPort], 0 @@ -532,8 +537,8 @@ align 4 lea ebx, [eax + SOCKET.lock] call wait_mutex - push dword [edx + 4] - pop dword [eax + IP_SOCKET.RemoteIP] + pushd [edx + 4] + pop [eax + IP_SOCKET.RemoteIP] push eax init_queue (eax + SOCKET_QUEUE_LOCATION) ; Set up data receiving queue diff --git a/kernel/branches/net/network/tcp.inc b/kernel/branches/net/network/tcp.inc index 52a2adb7d1..9868036cf1 100644 --- a/kernel/branches/net/network/tcp.inc +++ b/kernel/branches/net/network/tcp.inc @@ -17,17 +17,17 @@ $Revision$ ; Socket states -TCPS_CLOSED equ 0 -TCPS_LISTEN equ 1 -TCPS_SYN_SENT equ 2 -TCPS_SYN_RECEIVED equ 3 -TCPS_ESTABLISHED equ 4 -TCPS_CLOSE_WAIT equ 5 -TCPS_FIN_WAIT_1 equ 6 -TCPS_CLOSING equ 7 -TCPS_LAST_ACK equ 8 -TCPS_FIN_WAIT_2 equ 9 -TCPS_TIMED_WAIT equ 10 +TCPS_CLOSED equ 0 +TCPS_LISTEN equ 1 +TCPS_SYN_SENT equ 2 +TCPS_SYN_RECEIVED equ 3 +TCPS_ESTABLISHED equ 4 +TCPS_CLOSE_WAIT equ 5 +TCPS_FIN_WAIT_1 equ 6 +TCPS_CLOSING equ 7 +TCPS_LAST_ACK equ 8 +TCPS_FIN_WAIT_2 equ 9 +TCPS_TIMED_WAIT equ 10 ; Socket Flags TF_ACKNOW equ 1 shl 0 ; ack peer immediately diff --git a/kernel/branches/net/network/tcp_input.inc b/kernel/branches/net/network/tcp_input.inc index 9bc89886e4..a9cfac6477 100644 --- a/kernel/branches/net/network/tcp_input.inc +++ b/kernel/branches/net/network/tcp_input.inc @@ -45,7 +45,7 @@ TCP_input: DEBUGF 1,"headersize=%u\n", eax - cmp eax, 20 + cmp eax, TCP_segment.DataOffset 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) - cmp esi, 20 + 12 ; Timestamp option is 12 bytes + cmp esi, TCP_segment.DataOffset + 12 ; Timestamp option is 12 bytes jb .no_timestamp je .is_ok @@ -213,13 +213,13 @@ TCP_input: ;-------------------- ; Process TCP options - cmp esi, 20 ; esi is headersize + cmp esi, TCP_segment.DataOffset ; esi is headersize je .no_options DEBUGF 1,"Segment has options\n" - cmp [ebx + TCP_SOCKET.t_state], TCPS_LISTEN ; no options when in listen state - jz .not_uni_xfer ; also no header prediction + cmp [ebx + TCP_SOCKET.t_state], TCPS_LISTEN ; no options when in listen state + jz .not_uni_xfer ; also no header prediction lea edi, [edx + TCP_segment.Data] lea eax, [edx + esi] diff --git a/kernel/branches/net/network/tcp_output.inc b/kernel/branches/net/network/tcp_output.inc index 318c989d81..d8f64f556e 100644 --- a/kernel/branches/net/network/tcp_output.inc +++ b/kernel/branches/net/network/tcp_output.inc @@ -277,7 +277,7 @@ TCP_output: test [eax + TCP_SOCKET.t_flags], TF_NOOPT jnz .options_done - mov ecx, 1460 + mov ecx, 1460 ;;;; FIXME or ecx, TCP_OPT_MAXSEG shl 24 + 4 shl 16 bswap ecx push ecx @@ -454,7 +454,7 @@ TCP_output: ; 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 cmp edx, [eax + TCP_SOCKET.SND_UNA] ; edx = [eax + TCP_SOCKET.SND_NXT] diff --git a/kernel/branches/net/network/tcp_subr.inc b/kernel/branches/net/network/tcp_subr.inc index e3ac88740e..3ae0f3723b 100644 --- a/kernel/branches/net/network/tcp_subr.inc +++ b/kernel/branches/net/network/tcp_subr.inc @@ -268,7 +268,7 @@ TCP_respond_socket: mov eax, [esi + TCP_SOCKET.RCV_NXT] bswap eax stosd - mov al, 0x50 ; Dataoffset: 20 bytes + mov al, 0x50 ; Dataoffset: 20 bytes (TCP_segment.DataOffset) stosb mov al, cl stosb @@ -323,8 +323,8 @@ TCP_respond_segment: ; Create the IP packet push cx edx - mov ebx, [edx - 20 + IPv4_Packet.SourceAddress] ;;;; and what if ip packet had options?! - mov eax, [edx - 20 + IPv4_Packet.DestinationAddress] ;;; + mov ebx, [edx - IPv4_Packet.DataOrOptional + IPv4_Packet.SourceAddress] ;;;; FIXME: and what if ip packet had options?! + mov eax, [edx - IPv4_Packet.DataOrOptional + IPv4_Packet.DestinationAddress] ;;; mov ecx, TCP_segment.Data mov di , IP_PROTO_TCP shl 8 + 128 call IPv4_output @@ -347,7 +347,7 @@ TCP_respond_segment: stosd xor eax, eax stosd - mov al, 0x50 ; Dataoffset: 20 bytes + mov al, 0x50 ; Dataoffset: 20 bytes (TCP_segment.Data) stosb mov al, cl stosb @@ -363,7 +363,8 @@ TCP_respond_segment: .checksum: lea esi, [edi - 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 ;--------------------