Changed some debug output messages (and their levels) in new stack.

Implemented a queue for incoming TCP segments.

git-svn-id: svn://kolibrios.org@3251 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2013-02-17 17:58:53 +00:00
parent 8fc51dbddb
commit 72f758c218
8 changed files with 145 additions and 84 deletions

View File

@ -111,7 +111,7 @@ local .loop, .next
jmp .done jmp .done
.died: .died:
DEBUGF 1,"Fragment slot timed-out!\n" DEBUGF 2,"IPv4 Fragment slot timed-out!\n"
;;; TODO: clear all entry's of timed-out slot ;;; TODO: clear all entry's of timed-out slot
jmp .next jmp .next
@ -204,10 +204,10 @@ macro IPv4_checksum ptr {
align 4 align 4
IPv4_input: ; TODO: add IPv4 raw sockets support IPv4_input: ; TODO: add IPv4 raw sockets support
DEBUGF 1,"IPv4_input, packet from: %u.%u.%u.%u ",\ DEBUGF 2,"IPv4_input, packet from: %u.%u.%u.%u ",\
[edx + IPv4_header.SourceAddress + 0]:1,[edx + IPv4_header.SourceAddress + 1]:1,\ [edx + IPv4_header.SourceAddress + 0]:1,[edx + IPv4_header.SourceAddress + 1]:1,\
[edx + IPv4_header.SourceAddress + 2]:1,[edx + IPv4_header.SourceAddress + 3]:1 [edx + IPv4_header.SourceAddress + 2]:1,[edx + IPv4_header.SourceAddress + 3]:1
DEBUGF 1,"to: %u.%u.%u.%u\n",\ DEBUGF 2,"to: %u.%u.%u.%u\n",\
[edx + IPv4_header.DestinationAddress + 0]:1,[edx + IPv4_header.DestinationAddress + 1]:1,\ [edx + IPv4_header.DestinationAddress + 0]:1,[edx + IPv4_header.DestinationAddress + 1]:1,\
[edx + IPv4_header.DestinationAddress + 2]:1,[edx + IPv4_header.DestinationAddress + 3]:1 [edx + IPv4_header.DestinationAddress + 2]:1,[edx + IPv4_header.DestinationAddress + 3]:1
@ -302,7 +302,7 @@ IPv4_input: ; TODO: add IPv4
DEBUGF 2,"IPv4_input: unknown protocol %u\n", al DEBUGF 2,"IPv4_input: unknown protocol %u\n", al
.dump: .dump:
DEBUGF 2,"IPv4_input: dumping\n" DEBUGF 1,"IPv4_input: dumping\n"
; inc [dumped_rx_count] ;;; TODO ; inc [dumped_rx_count] ;;; TODO
call kernel_free call kernel_free
add esp, 4 ; pop (balance stack) add esp, 4 ; pop (balance stack)
@ -613,23 +613,23 @@ IPv4_output:
IPv4_checksum edi IPv4_checksum edi
add edi, sizeof.IPv4_header add edi, sizeof.IPv4_header
DEBUGF 1,"IPv4_output: success!\n" DEBUGF 2,"IPv4_output: success!\n"
ret ret
.eth_error: .eth_error:
DEBUGF 1,"IPv4_output: ethernet error\n" DEBUGF 2,"IPv4_output: ethernet error\n"
add esp, 3*4+2+6 add esp, 3*4+2+6
xor edi, edi xor edi, edi
ret ret
.arp_error: .arp_error:
DEBUGF 1,"IPv4_output: ARP error=%x\n", eax DEBUGF 2,"IPv4_output: ARP error=%x\n", eax
add esp, 3*4+2 add esp, 3*4+2
xor edi, edi xor edi, edi
ret ret
.too_large: .too_large:
DEBUGF 1,"IPv4_output: Packet too large!\n" DEBUGF 2,"IPv4_output: Packet too large!\n"
xor edi, edi xor edi, edi
ret ret
@ -712,7 +712,7 @@ IPv4_output_raw:
IPv4_checksum edi ;;;; todo: checksum for IP packet with options! IPv4_checksum edi ;;;; todo: checksum for IP packet with options!
add edi, sizeof.IPv4_header add edi, sizeof.IPv4_header
DEBUGF 1,"IPv4_output_raw: device=%x\n", ebx DEBUGF 2,"IPv4_output_raw: device=%x\n", ebx
call [ebx + NET_DEVICE.transmit] call [ebx + NET_DEVICE.transmit]
ret ret
@ -721,7 +721,7 @@ IPv4_output_raw:
.arp_error: .arp_error:
add esp, 8+4+4 add esp, 8+4+4
.too_large: .too_large:
DEBUGF 1,"IPv4_output_raw: Failed\n" DEBUGF 2,"IPv4_output_raw: Failed\n"
sub edi, edi sub edi, edi
ret ret

View File

@ -83,7 +83,7 @@ macro IPv6_init {
align 4 align 4
IPv6_input: IPv6_input:
DEBUGF 1,"IPv6_input from: %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x\n",\ DEBUGF 2,"IPv6_input from: %x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x\n",\
[edx + IPv6_header.SourceAddress + 0]:2,[edx + IPv6_header.SourceAddress + 1]:2,\ [edx + IPv6_header.SourceAddress + 0]:2,[edx + IPv6_header.SourceAddress + 1]:2,\
[edx + IPv6_header.SourceAddress + 2]:2,[edx + IPv6_header.SourceAddress + 3]:2,\ [edx + IPv6_header.SourceAddress + 2]:2,[edx + IPv6_header.SourceAddress + 3]:2,\
[edx + IPv6_header.SourceAddress + 4]:2,[edx + IPv6_header.SourceAddress + 5]:2,\ [edx + IPv6_header.SourceAddress + 4]:2,[edx + IPv6_header.SourceAddress + 5]:2,\
@ -146,7 +146,7 @@ IPv6_input:
DEBUGF 2,"IPv6_input - unknown protocol: %u\n", al DEBUGF 2,"IPv6_input - unknown protocol: %u\n", al
.dump: .dump:
DEBUGF 2,"IPv6_input - dumping\n" DEBUGF 1,"IPv6_input - dumping\n"
call kernel_free call kernel_free
add esp, 4 add esp, 4
@ -166,7 +166,7 @@ IPv6_input:
; Hop-by-Hop ; Hop-by-Hop
.hop_by_hop: .hop_by_hop:
DEBUGF 2,"IPv6_input - hop by hop\n" DEBUGF 1,"IPv6_input - hop by hop\n"
pushw [esi] ; 8 bit identifier for option type pushw [esi] ; 8 bit identifier for option type
movzx eax, byte[esi + 1] ; Hdr Ext Len movzx eax, byte[esi + 1] ; Hdr Ext Len
inc eax ; first 8 octets not counted inc eax ; first 8 octets not counted
@ -195,7 +195,7 @@ IPv6_input:
.pad_n: .pad_n:
movzx eax, byte[esi + 1] movzx eax, byte[esi + 1]
DEBUGF 2,"IPv6_input - pad %u\n", eax DEBUGF 1,"IPv6_input - pad %u\n", eax
inc esi inc esi
inc esi inc esi
add esi, eax add esi, eax
@ -203,7 +203,7 @@ IPv6_input:
jmp .hop_by_hop jmp .hop_by_hop
.pad_1: .pad_1:
DEBUGF 2,"IPv6_input - pad 1\n" DEBUGF 1,"IPv6_input - pad 1\n"
inc esi inc esi
dec ecx dec ecx
jmp .hop_by_hop jmp .hop_by_hop
@ -211,11 +211,11 @@ IPv6_input:
.dest_opts: .dest_opts:
DEBUGF 2,"IPv6_input - dest opts\n" DEBUGF 1,"IPv6_input - dest opts\n"
jmp .nextheader jmp .nextheader
.routing: .routing:
DEBUGF 2,"IPv6_input - routing\n" DEBUGF 1,"IPv6_input - routing\n"
pushw [esi] ; 8 bit identifier for option type pushw [esi] ; 8 bit identifier for option type
movzx eax, byte[esi + 1] ; Hdr Ext Len movzx eax, byte[esi + 1] ; Hdr Ext Len
inc eax ; first 8 octets not counted inc eax ; first 8 octets not counted
@ -238,7 +238,7 @@ IPv6_input:
jmp .nextheader jmp .nextheader
.fragment: .fragment:
DEBUGF 2,"IPv6_input - fragment\n" DEBUGF 1,"IPv6_input - fragment\n"
jmp .nextheader jmp .nextheader

View File

@ -93,7 +93,7 @@ LOOP_input:
align 4 align 4
LOOP_output: LOOP_output:
DEBUGF 1,"LOOP_output: " DEBUGF 1,"LOOP_output\n"
push ecx push ecx
push di push di
@ -114,11 +114,11 @@ LOOP_output:
mov ebx, LOOPBACK_DEVICE mov ebx, LOOPBACK_DEVICE
.done: .done:
DEBUGF 1,"ptr=%x size=%u\n", eax, edx DEBUGF 2,"LOOP_output: ptr=%x size=%u\n", eax, edx
ret ret
.out_of_ram: .out_of_ram:
DEBUGF 2,"error\n" DEBUGF 2,"LOOP_output: failed\n"
add esp, 2+4 add esp, 2+4
sub edi, edi sub edi, edi
ret ret

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2013. 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 ;;
@ -27,15 +27,15 @@ struct SOCKET
mutex MUTEX mutex MUTEX
PID dd ? ; application process id PID dd ? ; application process id
Domain dd ? ; INET/UNIX/.. Domain dd ? ; INET/LOCAL/..
Type dd ? ; RAW/STREAM/DGRAP Type dd ? ; RAW/STREAM/DGRAP
Protocol dd ? ; ICMP/IPv4/ARP/TCP/UDP Protocol dd ? ; ICMP/IPv4/ARP/TCP/UDP
errorcode dd ? errorcode dd ?
device dd ? ; driver pointer, socket pointer if it's an UNIX socket device dd ? ; driver pointer, socket pointer if it's an LOCAL socket
options dd ? options dd ?
state dd ? state dd ?
backlog dw ? ; how many incomming connections that can be queued backlog dw ? ; how many incoming connections that can be queued
snd_proc dd ? snd_proc dd ?
rcv_proc dd ? rcv_proc dd ?
@ -183,7 +183,7 @@ ends
SOCKETBUFFSIZE = 4096 ; in bytes SOCKETBUFFSIZE = 4096 ; in bytes
SOCKET_QUEUE_SIZE = 10 ; maximum number ofincoming packets queued for 1 socket SOCKET_QUEUE_SIZE = 10 ; maximum number of incoming packets queued for 1 socket
; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start ; the incoming packet queue for sockets is placed in the socket struct itself, at this location from start
SOCKET_QUEUE_LOCATION = (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue) SOCKET_QUEUE_LOCATION = (SOCKETBUFFSIZE - SOCKET_QUEUE_SIZE*sizeof.socket_queue_entry - sizeof.queue)
@ -279,7 +279,7 @@ sys_socket:
.number = ($ - .table) / 4 - 1 .number = ($ - .table) / 4 - 1
s_error: s_error:
DEBUGF 1,"socket error\n" DEBUGF 2,"SOCKET: error\n"
mov dword [esp+32], -1 mov dword [esp+32], -1
ret ret
@ -297,7 +297,7 @@ s_error:
align 4 align 4
SOCKET_open: SOCKET_open:
DEBUGF 1,"SOCKET_open: domain=%u type=%u protocol=%x\n", ecx, edx, esi DEBUGF 2,"SOCKET_open: domain=%u type=%u protocol=%x ", ecx, edx, esi
push ecx edx esi push ecx edx esi
call SOCKET_alloc call SOCKET_alloc
@ -305,6 +305,7 @@ SOCKET_open:
jz s_error jz s_error
mov [esp+32], edi ; return socketnumber mov [esp+32], edi ; return socketnumber
DEBUGF 2,"socknum=%u\n", edi
mov [eax + SOCKET.Domain], ecx mov [eax + SOCKET.Domain], ecx
mov [eax + SOCKET.Type], edx mov [eax + SOCKET.Type], edx
@ -330,6 +331,7 @@ SOCKET_open:
je .pppoe je .pppoe
.no_ppp: .no_ppp:
DEBUGF 2,"Unknown socket family/protocol\n"
ret ret
align 4 align 4
@ -402,7 +404,7 @@ align 4
align 4 align 4
SOCKET_bind: SOCKET_bind:
DEBUGF 1,"SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi DEBUGF 2,"SOCKET_bind: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -413,12 +415,12 @@ SOCKET_bind:
cmp word [edx], AF_INET4 cmp word [edx], AF_INET4
je .af_inet4 je .af_inet4
cmp word [edx], AF_UNIX cmp word [edx], AF_LOCAL
je .af_unix je .af_local
jmp s_error jmp s_error
.af_unix: .af_local:
; TODO: write code here ; TODO: write code here
mov dword [esp+32], 0 mov dword [esp+32], 0
@ -475,7 +477,7 @@ SOCKET_bind:
align 4 align 4
SOCKET_connect: SOCKET_connect:
DEBUGF 1,"SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi DEBUGF 2,"SOCKET_connect: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -624,7 +626,7 @@ align 4
align 4 align 4
SOCKET_listen: SOCKET_listen:
DEBUGF 1,"SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx DEBUGF 2,"SOCKET_listen: socknum=%u backlog=%u\n", ecx, edx
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -676,7 +678,7 @@ SOCKET_listen:
align 4 align 4
SOCKET_accept: SOCKET_accept:
DEBUGF 1,"SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi DEBUGF 2,"SOCKET_accept: socknum=%u sockaddr=%x length=%u\n", ecx, edx, esi
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -722,7 +724,7 @@ SOCKET_accept:
align 4 align 4
SOCKET_close: SOCKET_close:
DEBUGF 1,"SOCKET_close: %u\n", ecx DEBUGF 2,"SOCKET_close: socknum=%u\n", ecx
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -777,7 +779,7 @@ SOCKET_close:
align 4 align 4
SOCKET_receive: SOCKET_receive:
DEBUGF 1,"SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi DEBUGF 2,"SOCKET_receive: socknum=%u bufaddr=%x buflength=%u flags=%x\n", ecx, edx, esi, edi
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -826,7 +828,7 @@ SOCKET_receive_dgram:
.too_small: .too_small:
DEBUGF 1,"SOCKET_receive: Buffer too small\n" DEBUGF 2,"SOCKET_receive: Buffer too small\n"
jmp s_error jmp s_error
.block: .block:
@ -870,7 +872,7 @@ SOCKET_receive_stream:
align 4 align 4
SOCKET_send: SOCKET_send:
DEBUGF 1,"SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi DEBUGF 2,"SOCKET_send: socknum=%u data ptr=%x length=%u flags=%x\n", ecx, edx, esi, edi
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -949,9 +951,9 @@ SOCKET_send_pppoe:
align 4 align 4
SOCKET_send_unix: SOCKET_send_local:
DEBUGF 1,"SOCKET_send: UNIX\n" DEBUGF 1,"SOCKET_send: LOCAL\n"
; does this socket have a PID yet? ; does this socket have a PID yet?
cmp [eax + SOCKET.PID], 0 cmp [eax + SOCKET.PID], 0
@ -1000,7 +1002,7 @@ SOCKET_send_unix:
align 4 align 4
SOCKET_get_opt: SOCKET_get_opt:
DEBUGF 1,"SOCKET_get_opt\n" DEBUGF 2,"SOCKET_get_opt\n"
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -1050,7 +1052,7 @@ SOCKET_get_opt:
align 4 align 4
SOCKET_set_opt: SOCKET_set_opt:
DEBUGF 1,"SOCKET_set_opt\n" DEBUGF 2,"SOCKET_set_opt\n"
call SOCKET_num_to_ptr call SOCKET_num_to_ptr
jz s_error jz s_error
@ -1111,7 +1113,7 @@ SOCKET_set_opt:
; ;
; SOCKET_pair ; SOCKET_pair
; ;
; Allocates a pair of linked UNIX domain sockets ; Allocates a pair of linked LOCAL domain sockets
; ;
; IN: / ; IN: /
; OUT: eax is socket1 num, -1 on error ; OUT: eax is socket1 num, -1 on error
@ -1121,16 +1123,16 @@ SOCKET_set_opt:
align 4 align 4
SOCKET_pair: SOCKET_pair:
DEBUGF 1,"SOCKET_pair\n" DEBUGF 2,"SOCKET_pair\n"
call SOCKET_alloc call SOCKET_alloc
jz s_error jz s_error
mov [esp+32], edi ; application's eax mov [esp+32], edi ; application's eax
mov [eax + SOCKET.Domain], AF_UNIX mov [eax + SOCKET.Domain], AF_LOCAL
mov [eax + SOCKET.Type], SOCK_STREAM mov [eax + SOCKET.Type], SOCK_STREAM
mov [eax + SOCKET.Protocol], 0 ;;; CHECKME mov [eax + SOCKET.Protocol], 0 ;;; CHECKME
mov [eax + SOCKET.snd_proc], SOCKET_send_unix mov [eax + SOCKET.snd_proc], SOCKET_send_local
mov [eax + SOCKET.rcv_proc], SOCKET_receive_stream mov [eax + SOCKET.rcv_proc], SOCKET_receive_stream
mov ebx, eax mov ebx, eax
@ -1138,10 +1140,10 @@ SOCKET_pair:
jz .error jz .error
mov [esp+24], edi ; application's ebx mov [esp+24], edi ; application's ebx
mov [eax + SOCKET.Domain], AF_UNIX mov [eax + SOCKET.Domain], AF_LOCAL
mov [eax + SOCKET.Type], SOCK_STREAM mov [eax + SOCKET.Type], SOCK_STREAM
mov [eax + SOCKET.Protocol], 0 ;;; CHECKME mov [eax + SOCKET.Protocol], 0 ;;; CHECKME
mov [eax + SOCKET.snd_proc], SOCKET_send_unix mov [eax + SOCKET.snd_proc], SOCKET_send_local
mov [eax + SOCKET.rcv_proc], SOCKET_receive_stream mov [eax + SOCKET.rcv_proc], SOCKET_receive_stream
; Link the two sockets to eachother ; Link the two sockets to eachother
@ -1155,8 +1157,6 @@ SOCKET_pair:
call SOCKET_ring_create call SOCKET_ring_create
pop eax pop eax
ret ret
.error: .error:
@ -1180,7 +1180,7 @@ SOCKET_pair:
align 4 align 4
SOCKET_debug: SOCKET_debug:
; DEBUGF 1,"SOCKET_debug\n" DEBUGF 1,"SOCKET_debug\n"
mov edi, edx mov edi, edx
@ -1229,7 +1229,7 @@ SOCKET_debug:
align 4 align 4
SOCKET_find_port: SOCKET_find_port:
DEBUGF 1,"SOCKET_find_port\n" DEBUGF 2,"SOCKET_find_port\n"
push ebx esi ecx push ebx esi ecx
@ -1290,7 +1290,7 @@ SOCKET_find_port:
align 4 align 4
SOCKET_check_port: SOCKET_check_port:
DEBUGF 1,"SOCKET_check_port: " DEBUGF 2,"SOCKET_check_port: "
mov ecx, [eax + SOCKET.Protocol] mov ecx, [eax + SOCKET.Protocol]
mov edx, [eax + IP_SOCKET.LocalIP] mov edx, [eax + IP_SOCKET.LocalIP]
@ -1310,11 +1310,11 @@ SOCKET_check_port:
cmp [esi + UDP_SOCKET.LocalPort], bx cmp [esi + UDP_SOCKET.LocalPort], bx
jne .next_socket jne .next_socket
DEBUGF 1,"local port %x already in use\n", bx ; FIXME: find a way to print big endian values with debugf DEBUGF 2,"local port %x already in use\n", bx ; FIXME: find a way to print big endian values with debugf
ret ret
.port_ok: .port_ok:
DEBUGF 1,"local port %x is free\n", bx ; FIXME: find a way to print big endian values with debugf DEBUGF 2,"local port %x is free\n", bx ; FIXME: find a way to print big endian values with debugf
mov [eax + UDP_SOCKET.LocalPort], bx mov [eax + UDP_SOCKET.LocalPort], bx
or bx, bx ; clear the zero-flag or bx, bx ; clear the zero-flag
ret ret
@ -1341,7 +1341,7 @@ SOCKET_check_port:
align 4 align 4
SOCKET_input: SOCKET_input:
DEBUGF 1,"SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx DEBUGF 2,"SOCKET_input: socket=%x, data=%x size=%u\n", eax, esi, ecx
mov [esp+4], ecx mov [esp+4], ecx
push esi push esi
@ -1349,7 +1349,7 @@ SOCKET_input:
add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, SOCKET_input.full add_to_queue (eax + SOCKET_QUEUE_LOCATION), SOCKET_QUEUE_SIZE, sizeof.socket_queue_entry, SOCKET_input.full
DEBUGF 1,"SOCKET_input: queued packet successfully\n" DEBUGF 1,"SOCKET_input: success\n"
add esp, sizeof.socket_queue_entry add esp, sizeof.socket_queue_entry
pusha pusha

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
;; Distributed under terms of the GNU General Public License ;; ;; Distributed under terms of the GNU General Public License ;;
;; ;; ;; ;;
;; STACK.INC ;; ;; STACK.INC ;;
@ -48,7 +48,7 @@ PPP_IPV6 = 0x5780
;Protocol family ;Protocol family
AF_UNSPEC = 0 AF_UNSPEC = 0
AF_UNIX = 1 AF_LOCAL = 1
AF_INET4 = 2 AF_INET4 = 2
AF_INET6 = 10 AF_INET6 = 10
AF_PPP = 777 AF_PPP = 777
@ -259,6 +259,8 @@ stack_handler:
cmp [NET_RUNNING], 0 cmp [NET_RUNNING], 0
je .exit je .exit
call TCP_process_input ; de-queue TCP ragments and process them
; Test for 10ms tick ; Test for 10ms tick
mov eax, [timer_ticks] mov eax, [timer_ticks]
cmp eax, [net_10ms] cmp eax, [net_10ms]

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2013. 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 ;;
@ -99,6 +99,8 @@ TCP_BIT_SENDALOT = 1 shl 0
TCP_PAWS_IDLE = 24*24*60*60*100 ; 24 days, in 1/100 seconds TCP_PAWS_IDLE = 24*24*60*60*100 ; 24 days, in 1/100 seconds
TCP_QUEUE_SIZE = 50
struct TCP_header struct TCP_header
SourcePort dw ? SourcePort dw ?
@ -113,6 +115,18 @@ struct TCP_header
ends ends
struct TCP_queue_entry
ip_ptr dd ?
segment_ptr dd ?
segment_size dd ?
device_ptr dd ?
buffer_ptr dd ?
buffer_size dd ?
ends
align 4 align 4
uglobal uglobal
TCP_segments_tx rd MAX_NET_DEVICES TCP_segments_tx rd MAX_NET_DEVICES
@ -120,6 +134,7 @@ uglobal
TCP_bytes_rx rq MAX_NET_DEVICES TCP_bytes_rx rq MAX_NET_DEVICES
TCP_bytes_tx rq MAX_NET_DEVICES TCP_bytes_tx rq MAX_NET_DEVICES
TCP_sequence_num dd ? TCP_sequence_num dd ?
TCP_queue rd TCP_QUEUE_SIZE*sizeof.TCP_queue_entry/4
endg endg
@ -140,6 +155,8 @@ macro TCP_init {
pseudo_random eax pseudo_random eax
mov [TCP_sequence_num], eax mov [TCP_sequence_num], eax
init_queue TCP_queue
} }

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2013. 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 ;;
@ -20,6 +20,8 @@ $Revision$
; ;
; TCP_input: ; TCP_input:
; ;
; Add a segment to the incoming TCP queue
;
; IN: [esp] = ptr to buffer ; IN: [esp] = ptr to buffer
; [esp+4] = buffer size ; [esp+4] = buffer size
; ebx = ptr to device struct ; ebx = ptr to device struct
@ -34,14 +36,63 @@ $Revision$
align 4 align 4
TCP_input: TCP_input:
pushfd push ebx ecx esi edi ; mind the order
mov esi, esp
pushf
cli cli
add_to_queue TCP_queue, TCP_QUEUE_SIZE, sizeof.TCP_queue_entry, .fail
popf
add esp, sizeof.TCP_queue_entry
ret
.fail:
DEBUGF 2, "TCP incoming queue is full, discarding packet!\n"
add esp, sizeof.TCP_queue_entry - 8
call kernel_free
add esp, 4
.done:
ret
align 4
TCP_process_input:
.loop:
get_from_queue TCP_queue, TCP_QUEUE_SIZE, sizeof.TCP_queue_entry, TCP_input.done
push .loop
push [esi + TCP_queue_entry.buffer_size]
push [esi + TCP_queue_entry.buffer_ptr]
mov ebx, [esi + TCP_queue_entry.device_ptr]
mov ecx, [esi + TCP_queue_entry.segment_size]
mov edi, [esi + TCP_queue_entry.ip_ptr]
mov esi, [esi + TCP_queue_entry.segment_ptr] ; change esi last
;-----------------------------------------------------------------
;
; IN: [esp] = ptr to buffer
; [esp+4] = buffer size - actually, we dont care
; ebx = ptr to device struct
; ecx = segment size
; esi = ptr to TCP segment
; edi = ptr to ipv4 source address, followed by ipv4 dest address
;
; OUT: /
;
;-----------------------------------------------------------------
DEBUGF 1,"TCP_input: size=%u time=%d\n", ecx, [timer_ticks] DEBUGF 1,"TCP_input: size=%u time=%d\n", ecx, [timer_ticks]
; First, record the current time ; First, record the current time
mov eax, [timer_ticks] ; in 1/100 seconds mov eax, [timer_ticks] ; in 1/100 seconds
mov [esp+8], eax mov [esp + 4], eax ; from now on, we'll call this TCP_now
; then, re-calculate the checksum (if not already done by hw) ; then, re-calculate the checksum (if not already done by hw)
; test [ebx + NET_DEVICE.hwacc], HWACC_TCP_IPv4_IN ; test [ebx + NET_DEVICE.hwacc], HWACC_TCP_IPv4_IN
@ -313,7 +364,7 @@ TCP_input:
DEBUGF 1,"TCP_input: PAWS: detected an old segment\n" DEBUGF 1,"TCP_input: PAWS: detected an old segment\n"
mov eax, [esp+4+4+4] ; tcp_now mov eax, [esp+4+4] ; tcp_now
sub eax, [ebx + TCP_SOCKET.ts_recent_age] sub eax, [ebx + TCP_SOCKET.ts_recent_age]
cmp eax, TCP_PAWS_IDLE cmp eax, TCP_PAWS_IDLE
jle .drop_after_ack ; TODO: update stats jle .drop_after_ack ; TODO: update stats
@ -402,7 +453,7 @@ TCP_input:
test [ebx + TCP_SOCKET.temp_bits], TCP_BIT_TIMESTAMP test [ebx + TCP_SOCKET.temp_bits], TCP_BIT_TIMESTAMP
jz .no_timestamp_rtt jz .no_timestamp_rtt
mov eax, [esp + 4+4] ; timestamp when this segment was received mov eax, [esp + 4] ; timestamp when this segment was received
sub eax, [ebx + TCP_SOCKET.ts_ecr] sub eax, [ebx + TCP_SOCKET.ts_ecr]
inc eax inc eax
call TCP_xmit_timer call TCP_xmit_timer
@ -669,7 +720,7 @@ TCP_input:
DEBUGF 1,"Recording timestamp\n" DEBUGF 1,"Recording timestamp\n"
mov eax, [esp + 4+4] ; tcp_now mov eax, [esp + 4] ; tcp_now
mov [ebx + TCP_SOCKET.ts_recent_age], eax mov [ebx + TCP_SOCKET.ts_recent_age], eax
mov eax, [ebx + TCP_SOCKET.ts_val] mov eax, [ebx + TCP_SOCKET.ts_val]
mov [ebx + TCP_SOCKET.ts_recent], eax mov [ebx + TCP_SOCKET.ts_recent], eax
@ -918,7 +969,7 @@ TCP_input:
test [ebx + TCP_SOCKET.temp_bits], TCP_BIT_TIMESTAMP test [ebx + TCP_SOCKET.temp_bits], TCP_BIT_TIMESTAMP
jz .timestamp_not_present jz .timestamp_not_present
mov eax, [esp+4+4] mov eax, [esp+4]
sub eax, [ebx + TCP_SOCKET.ts_ecr] sub eax, [ebx + TCP_SOCKET.ts_ecr]
inc eax inc eax
call TCP_xmit_timer call TCP_xmit_timer
@ -1025,7 +1076,7 @@ TCP_input:
.wakeup: .wakeup:
pushf pushf ; Why?
mov eax, ebx mov eax, ebx
call SOCKET_notify_owner call SOCKET_notify_owner
@ -1491,7 +1542,6 @@ align 4
.dumpit: .dumpit:
DEBUGF 1,"TCP_input: dumping\n" DEBUGF 1,"TCP_input: dumping\n"
popf
call kernel_free call kernel_free
add esp, 4 add esp, 4
@ -1538,7 +1588,6 @@ align 4
.drop_no_socket: .drop_no_socket:
DEBUGF 1,"TCP_input: Drop (no socket)\n" DEBUGF 1,"TCP_input: Drop (no socket)\n"
popf
call kernel_free call kernel_free
add esp, 4 add esp, 4

View File

@ -1,6 +1,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; ;; ;;
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; ;; Copyright (C) KolibriOS team 2004-2013. 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 ;;
@ -28,9 +28,6 @@ $Revision$
align 4 align 4
TCP_output: TCP_output:
pushf
cli
DEBUGF 1,"TCP_output: socket=%x\n", eax DEBUGF 1,"TCP_output: socket=%x\n", eax
pusha pusha
@ -292,7 +289,6 @@ TCP_output:
call mutex_unlock call mutex_unlock
popa popa
popf
ret ret
@ -586,7 +582,6 @@ TCP_send:
DEBUGF 1,"TCP_send: success!\n" DEBUGF 1,"TCP_send: success!\n"
xor eax, eax xor eax, eax
popf
ret ret
@ -605,7 +600,6 @@ TCP_send:
DEBUGF 1,"TCP_send: IP error\n" DEBUGF 1,"TCP_send: IP error\n"
or eax, -1 or eax, -1
popf
ret ret
.send_error: .send_error:
@ -614,7 +608,6 @@ TCP_send:
DEBUGF 1,"TCP_send: sending failed\n" DEBUGF 1,"TCP_send: sending failed\n"
or eax, -2 or eax, -2
popf
ret ret