Added simple socket debugging tool.
Moved some TCP code to tcp_usreq.inc. git-svn-id: svn://kolibrios.org@3146 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
9e043be92f
commit
2033224063
164
kernel/branches/net/applications/socketdbg/socket.inc
Normal file
164
kernel/branches/net/applications/socketdbg/socket.inc
Normal file
@ -0,0 +1,164 @@
|
||||
struct LHEAD
|
||||
next dd ? ;next object in list
|
||||
prev dd ? ;prev object in list
|
||||
ends
|
||||
|
||||
struct MUTEX
|
||||
lhead LHEAD
|
||||
count dd ?
|
||||
ends
|
||||
|
||||
|
||||
struct SOCKET
|
||||
|
||||
NextPtr dd ? ; pointer to next socket in list
|
||||
PrevPtr dd ? ; pointer to previous socket in list
|
||||
Number dd ? ; socket number
|
||||
|
||||
mutex MUTEX
|
||||
|
||||
PID dd ? ; application process id
|
||||
Domain dd ? ; INET/UNIX/..
|
||||
Type dd ? ; RAW/STREAM/DGRAP
|
||||
Protocol dd ? ; ICMP/IPv4/ARP/TCP/UDP
|
||||
errorcode dd ?
|
||||
device dd ?
|
||||
|
||||
options dd ?
|
||||
state dd ?
|
||||
backlog dw ? ; how many incomming connections that can be queued
|
||||
|
||||
snd_proc dd ?
|
||||
rcv_proc dd ?
|
||||
|
||||
ends
|
||||
|
||||
struct IP_SOCKET SOCKET
|
||||
|
||||
LocalIP rd 4 ; network byte order
|
||||
RemoteIP rd 4 ; network byte order
|
||||
|
||||
ends
|
||||
|
||||
struct TCP_SOCKET IP_SOCKET
|
||||
|
||||
LocalPort dw ? ; network byte order
|
||||
RemotePort dw ? ; network byte order
|
||||
|
||||
t_state dd ? ; TCB state
|
||||
t_rxtshift db ?
|
||||
rb 3 ; align
|
||||
t_rxtcur dd ?
|
||||
t_dupacks dd ?
|
||||
t_maxseg dd ?
|
||||
t_force dd ?
|
||||
t_flags dd ?
|
||||
|
||||
;---------------
|
||||
; RFC783 page 21
|
||||
|
||||
; send sequence
|
||||
SND_UNA dd ? ; sequence number of unack'ed sent Packets
|
||||
SND_NXT dd ? ; next send sequence number to use
|
||||
SND_UP dd ? ; urgent pointer
|
||||
SND_WL1 dd ? ; window minus one
|
||||
SND_WL2 dd ? ;
|
||||
ISS dd ? ; initial send sequence number
|
||||
SND_WND dd ? ; send window
|
||||
|
||||
; receive sequence
|
||||
RCV_WND dd ? ; receive window
|
||||
RCV_NXT dd ? ; next receive sequence number to use
|
||||
RCV_UP dd ? ; urgent pointer
|
||||
IRS dd ? ; initial receive sequence number
|
||||
|
||||
;---------------------
|
||||
; Additional variables
|
||||
|
||||
; receive variables
|
||||
RCV_ADV dd ?
|
||||
|
||||
; retransmit variables
|
||||
SND_MAX dd ?
|
||||
|
||||
; congestion control
|
||||
SND_CWND dd ?
|
||||
SND_SSTHRESH dd ?
|
||||
|
||||
;----------------------
|
||||
; Transmit timing stuff
|
||||
t_idle dd ?
|
||||
t_rtt dd ?
|
||||
t_rtseq dd ?
|
||||
t_srtt dd ?
|
||||
t_rttvar dd ?
|
||||
t_rttmin dd ?
|
||||
max_sndwnd dd ?
|
||||
|
||||
;-----------------
|
||||
; Out-of-band data
|
||||
t_oobflags dd ?
|
||||
t_iobc dd ?
|
||||
t_softerror dd ?
|
||||
|
||||
|
||||
;---------
|
||||
; RFC 1323 ; the order of next 4 elements may not change
|
||||
|
||||
SND_SCALE db ?
|
||||
RCV_SCALE db ?
|
||||
requested_s_scale db ?
|
||||
request_r_scale db ?
|
||||
|
||||
ts_recent dd ? ; a copy of the most-recent valid timestamp from the other end
|
||||
ts_recent_age dd ?
|
||||
last_ack_sent dd ?
|
||||
|
||||
|
||||
;-------
|
||||
; Timers
|
||||
timer_retransmission dd ? ; rexmt
|
||||
timer_persist dd ?
|
||||
timer_keepalive dd ? ; keepalive/syn timeout
|
||||
timer_timed_wait dd ? ; also used as 2msl timer
|
||||
|
||||
; extra
|
||||
|
||||
ts_ecr dd ? ; timestamp echo reply
|
||||
ts_val dd ?
|
||||
temp_bits db ?
|
||||
|
||||
ends
|
||||
|
||||
struct UDP_SOCKET IP_SOCKET
|
||||
|
||||
LocalPort dw ? ; network byte order
|
||||
RemotePort dw ? ; network byte order
|
||||
firstpacket db ?
|
||||
|
||||
ends
|
||||
|
||||
|
||||
struct ICMP_SOCKET IP_SOCKET
|
||||
|
||||
Identifier dw ?
|
||||
|
||||
ends
|
||||
|
||||
|
||||
struct RING_BUFFER
|
||||
|
||||
start_ptr dd ? ; Pointer to start of buffer
|
||||
end_ptr dd ? ; pointer to end of buffer
|
||||
read_ptr dd ? ; Read pointer
|
||||
write_ptr dd ? ; Write pointer
|
||||
size dd ? ; Number of bytes buffered
|
||||
|
||||
ends
|
||||
|
||||
struct STREAM_SOCKET TCP_SOCKET
|
||||
|
||||
rcv RING_BUFFER
|
||||
snd RING_BUFFER
|
||||
|
||||
ends
|
100
kernel/branches/net/applications/socketdbg/socketdbg.asm
Normal file
100
kernel/branches/net/applications/socketdbg/socketdbg.asm
Normal file
@ -0,0 +1,100 @@
|
||||
format binary as ""
|
||||
|
||||
use32
|
||||
; standard header
|
||||
db 'MENUET01' ; signature
|
||||
dd 1 ; header version
|
||||
dd start ; entry point
|
||||
dd i_end ; initialized size
|
||||
dd mem ; required memory
|
||||
dd mem ; stack pointer
|
||||
dd 0 ; parameters
|
||||
dd 0 ; path
|
||||
|
||||
; useful includes
|
||||
include '../macros.inc'
|
||||
purge mov,add,sub
|
||||
include '../proc32.inc'
|
||||
include '../dll.inc'
|
||||
|
||||
include '../struct.inc'
|
||||
|
||||
include 'socket.inc'
|
||||
|
||||
; entry point
|
||||
start:
|
||||
mcall 40, 0 ; we dont want any events
|
||||
; load libraries
|
||||
stdcall dll.Load, @IMPORT
|
||||
test eax, eax
|
||||
jnz exit
|
||||
; initialize console
|
||||
push 1
|
||||
call [con_start]
|
||||
push title
|
||||
push -1
|
||||
push -1
|
||||
push -1
|
||||
push -1
|
||||
call [con_init]
|
||||
; main loop
|
||||
main:
|
||||
mcall 75, 255, 0, socket_list ; get current socket list
|
||||
|
||||
call [con_cls]
|
||||
|
||||
mov esi, socket_list
|
||||
.loop:
|
||||
lodsd
|
||||
test eax, eax
|
||||
jz .done
|
||||
|
||||
mov ecx, eax
|
||||
mcall 75, 255, , socket_buf
|
||||
|
||||
pushd [socket_buf + SOCKET.state]
|
||||
pushd [socket_buf + SOCKET.PID]
|
||||
pushd [socket_buf + SOCKET.Number]
|
||||
push str_sock
|
||||
call [con_printf]
|
||||
add esp, 4
|
||||
|
||||
jmp .loop
|
||||
|
||||
.done:
|
||||
|
||||
mcall 23, 50
|
||||
|
||||
jmp main
|
||||
|
||||
|
||||
push 0
|
||||
call [con_exit]
|
||||
exit:
|
||||
mcall -1
|
||||
|
||||
; data
|
||||
title db 'Socket debugger', 0
|
||||
|
||||
str_sock db 'Socket=%d PID=%d state=%d', 10, 0
|
||||
|
||||
; import
|
||||
align 4
|
||||
@IMPORT:
|
||||
|
||||
library console, 'console.obj'
|
||||
|
||||
import console, \
|
||||
con_start, 'START', \
|
||||
con_init, 'con_init', \
|
||||
con_cls, 'con_cls', \
|
||||
con_exit, 'con_exit', \
|
||||
con_printf, 'con_printf'
|
||||
i_end:
|
||||
|
||||
socket_list rd 4096
|
||||
socket_buf rd 4096
|
||||
|
||||
align 4
|
||||
rb 4096 ; stack
|
||||
mem:
|
@ -1092,17 +1092,37 @@ SOCKET_debug:
|
||||
|
||||
DEBUGF 1,"SOCKET_debug\n"
|
||||
|
||||
mov edi, edx
|
||||
|
||||
test ecx, ecx
|
||||
jz .returnall
|
||||
|
||||
call SOCKET_num_to_ptr
|
||||
jz s_error
|
||||
|
||||
mov esi, eax
|
||||
mov edi, edx
|
||||
mov ecx, SOCKETBUFFSIZE/4
|
||||
rep movsd
|
||||
|
||||
mov dword [esp+32], 0
|
||||
ret
|
||||
|
||||
.returnall:
|
||||
mov ebx, net_sockets
|
||||
.next_socket:
|
||||
mov ebx, [ebx + SOCKET.NextPtr]
|
||||
test ebx, ebx
|
||||
jz .done
|
||||
mov eax, [ebx + SOCKET.Number]
|
||||
stosd
|
||||
jmp .next_socket
|
||||
.done:
|
||||
xor eax, eax
|
||||
stosd
|
||||
|
||||
mov dword [esp+32], 0
|
||||
ret
|
||||
|
||||
|
||||
;-----------------------------------------------------------------
|
||||
;
|
||||
|
@ -595,7 +595,7 @@ checksum_2:
|
||||
|
||||
;----------------------------------------------------------------
|
||||
;
|
||||
; System function to work with network devices (76)
|
||||
; System function to work with network devices (75)
|
||||
;
|
||||
;----------------------------------------------------------------
|
||||
align 4
|
||||
|
@ -145,6 +145,7 @@ macro TCP_init {
|
||||
|
||||
include 'tcp_timer.inc'
|
||||
include 'tcp_subr.inc'
|
||||
include 'tcp_usreq.inc'
|
||||
include 'tcp_input.inc'
|
||||
include 'tcp_output.inc'
|
||||
|
||||
|
@ -81,6 +81,8 @@ TCP_output:
|
||||
cmp [eax + TCP_SOCKET.t_force], 0
|
||||
je .no_force
|
||||
|
||||
DEBUGF 1,"TCP_output: forcing data out\n"
|
||||
|
||||
test ecx, ecx
|
||||
jnz .no_zero_window
|
||||
|
||||
|
@ -195,87 +195,6 @@ TCP_close:
|
||||
|
||||
|
||||
|
||||
;-------------------------
|
||||
;
|
||||
; TCP_disconnect
|
||||
;
|
||||
; IN: eax = socket ptr
|
||||
; OUT: eax = socket ptr
|
||||
;
|
||||
;-------------------------
|
||||
align 4
|
||||
TCP_disconnect:
|
||||
|
||||
DEBUGF 1,"TCP_disconnect: %x\n", eax
|
||||
|
||||
cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED
|
||||
jb TCP_close
|
||||
|
||||
|
||||
; TODO: implement LINGER ?
|
||||
|
||||
call SOCKET_is_disconnecting
|
||||
call TCP_usrclosed
|
||||
call TCP_output
|
||||
|
||||
ret
|
||||
|
||||
|
||||
|
||||
;-------------------------
|
||||
;
|
||||
; TCP_usrclose
|
||||
;
|
||||
; IN: eax = socket ptr
|
||||
;
|
||||
;-------------------------
|
||||
align 4
|
||||
TCP_usrclosed:
|
||||
|
||||
DEBUGF 1,"TCP_usrclosed: %x\n", eax
|
||||
|
||||
push ebx
|
||||
mov ebx, [eax + TCP_SOCKET.t_state]
|
||||
mov ebx, dword [.switch + ebx*4]
|
||||
jmp ebx
|
||||
|
||||
.switch:
|
||||
|
||||
dd .close ; TCPS_CLOSED
|
||||
dd .close ; TCPS_LISTEN
|
||||
dd .close ; TCPS_SYN_SENT
|
||||
dd .wait1 ; TCPS_SYN_RECEIVED
|
||||
dd .wait1 ; TCPS_ESTABLISHED
|
||||
dd .last_ack ; TCPS_CLOSE_WAIT
|
||||
dd .ret ; TCPS_FIN_WAIT_1
|
||||
dd .ret ; TCPS_CLOSING
|
||||
dd .ret ; TCPS_LAST_ACK
|
||||
dd .disc ; TCPS_FIN_WAIT_2
|
||||
dd .disc ; TCPS_TIMED_WAIT
|
||||
|
||||
|
||||
.close:
|
||||
pop ebx
|
||||
mov [eax + TCP_SOCKET.t_state], TCPS_CLOSED
|
||||
call TCP_close
|
||||
ret
|
||||
|
||||
.wait1:
|
||||
pop ebx
|
||||
mov [eax + TCP_SOCKET.t_state], TCPS_FIN_WAIT_1
|
||||
ret
|
||||
|
||||
.last_ack:
|
||||
pop ebx
|
||||
mov [eax + TCP_SOCKET.t_state], TCPS_LAST_ACK
|
||||
ret
|
||||
|
||||
.disc:
|
||||
call SOCKET_is_disconnected
|
||||
.ret:
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
|
||||
;-------------------------
|
||||
;
|
||||
|
100
kernel/branches/net/network/tcp_usreq.inc
Normal file
100
kernel/branches/net/network/tcp_usreq.inc
Normal file
@ -0,0 +1,100 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; ;;
|
||||
;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;;
|
||||
;; Distributed under terms of the GNU General Public License ;;
|
||||
;; ;;
|
||||
;; Part of the TCP/IP network stack for KolibriOS ;;
|
||||
;; ;;
|
||||
;; Written by hidnplayr@kolibrios.org ;;
|
||||
;; ;;
|
||||
;; Based on the code of 4.4BSD ;;
|
||||
;; ;;
|
||||
;; GNU GENERAL PUBLIC LICENSE ;;
|
||||
;; Version 2, June 1991 ;;
|
||||
;; ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
|
||||
;-------------------------
|
||||
;
|
||||
; TCP_usrclose
|
||||
;
|
||||
; Move connection to next state, based on process close.
|
||||
;
|
||||
; IN: eax = socket ptr
|
||||
;
|
||||
;-------------------------
|
||||
align 4
|
||||
TCP_usrclosed:
|
||||
|
||||
DEBUGF 1,"TCP_usrclosed: %x\n", eax
|
||||
|
||||
push ebx
|
||||
mov ebx, [eax + TCP_SOCKET.t_state]
|
||||
mov ebx, dword [.switch + ebx*4]
|
||||
jmp ebx
|
||||
|
||||
.switch:
|
||||
|
||||
dd .close ; TCPS_CLOSED
|
||||
dd .close ; TCPS_LISTEN
|
||||
dd .close ; TCPS_SYN_SENT
|
||||
dd .wait1 ; TCPS_SYN_RECEIVED
|
||||
dd .wait1 ; TCPS_ESTABLISHED
|
||||
dd .last_ack ; TCPS_CLOSE_WAIT
|
||||
dd .ret ; TCPS_FIN_WAIT_1
|
||||
dd .ret ; TCPS_CLOSING
|
||||
dd .ret ; TCPS_LAST_ACK
|
||||
dd .disc ; TCPS_FIN_WAIT_2
|
||||
dd .disc ; TCPS_TIMED_WAIT
|
||||
|
||||
|
||||
.close:
|
||||
mov [eax + TCP_SOCKET.t_state], TCPS_CLOSED
|
||||
call TCP_close
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
.wait1:
|
||||
mov [eax + TCP_SOCKET.t_state], TCPS_FIN_WAIT_1
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
.last_ack:
|
||||
mov [eax + TCP_SOCKET.t_state], TCPS_LAST_ACK
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
.disc:
|
||||
call SOCKET_is_disconnected
|
||||
.ret:
|
||||
pop ebx
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
;-------------------------
|
||||
;
|
||||
; TCP_disconnect
|
||||
;
|
||||
; IN: eax = socket ptr
|
||||
; OUT: eax = socket ptr
|
||||
;
|
||||
;-------------------------
|
||||
align 4
|
||||
TCP_disconnect:
|
||||
|
||||
DEBUGF 1,"TCP_disconnect: %x\n", eax
|
||||
|
||||
cmp [eax + TCP_SOCKET.t_state], TCPS_ESTABLISHED
|
||||
jb TCP_close
|
||||
|
||||
|
||||
; TODO: implement LINGER ?
|
||||
|
||||
call SOCKET_is_disconnecting
|
||||
call TCP_usrclosed
|
||||
call TCP_output
|
||||
|
||||
ret
|
Loading…
Reference in New Issue
Block a user