diff --git a/kernel/branches/net/network/socket.inc b/kernel/branches/net/network/socket.inc index 1fe20f350b..e3dc91b78d 100644 --- a/kernel/branches/net/network/socket.inc +++ b/kernel/branches/net/network/socket.inc @@ -324,7 +324,7 @@ align 4 mov [eax + SOCKET.snd_proc], SOCKET_send_tcp mov [eax + SOCKET.rcv_proc], SOCKET_receive_tcp - mov [eax + TCP_SOCKET.t_maxseg], 1480 ;;;;; FIXME + TCP_init_socket eax ret @@ -498,11 +498,13 @@ align 4 mov [eax + TCP_SOCKET.timer_persist], 0 mov [eax + TCP_SOCKET.t_state], TCPS_SYN_SENT + push [TCP_sequence_num] add [TCP_sequence_num], 6400 pop [eax + TCP_SOCKET.ISS] mov [eax + TCP_SOCKET.timer_keepalive], TCP_time_keep_init + TCP_sendseqinit eax ; mov [ebx + TCP_SOCKET.timer_retransmission], ;; todo: create macro to set retransmission timer diff --git a/kernel/branches/net/network/tcp.inc b/kernel/branches/net/network/tcp.inc index 50bee5c84b..7a1909f218 100644 --- a/kernel/branches/net/network/tcp.inc +++ b/kernel/branches/net/network/tcp.inc @@ -17,87 +17,90 @@ $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 -TF_DELACK equ 1 shl 1 ; ack, but try to delay it -TF_NODELAY equ 1 shl 2 ; don't delay packets to coalesce -TF_NOOPT equ 1 shl 3 ; don't use tcp options -TF_SENTFIN equ 1 shl 4 ; have sent FIN -TF_REQ_SCALE equ 1 shl 5 ; have/will request window scaling -TF_RCVD_SCALE equ 1 shl 6 ; other side has requested scaling -TF_REQ_TSTMP equ 1 shl 7 ; have/will request timestamps -TF_RCVD_TSTMP equ 1 shl 8 ; a timestamp was received in SYN -TF_SACK_PERMIT equ 1 shl 9 ; other side said I could SACK +TF_ACKNOW equ 1 shl 0 ; ack peer immediately +TF_DELACK equ 1 shl 1 ; ack, but try to delay it +TF_NODELAY equ 1 shl 2 ; don't delay packets to coalesce +TF_NOOPT equ 1 shl 3 ; don't use tcp options +TF_SENTFIN equ 1 shl 4 ; have sent FIN +TF_REQ_SCALE equ 1 shl 5 ; have/will request window scaling +TF_RCVD_SCALE equ 1 shl 6 ; other side has requested scaling +TF_REQ_TSTMP equ 1 shl 7 ; have/will request timestamps +TF_RCVD_TSTMP equ 1 shl 8 ; a timestamp was received in SYN +TF_SACK_PERMIT equ 1 shl 9 ; other side said I could SACK ; Segment flags -TH_FIN equ 1 shl 0 -TH_SYN equ 1 shl 1 -TH_RST equ 1 shl 2 -TH_PUSH equ 1 shl 3 -TH_ACK equ 1 shl 4 -TH_URG equ 1 shl 5 +TH_FIN equ 1 shl 0 +TH_SYN equ 1 shl 1 +TH_RST equ 1 shl 2 +TH_PUSH equ 1 shl 3 +TH_ACK equ 1 shl 4 +TH_URG equ 1 shl 5 ; Segment header options -TCP_OPT_EOL equ 0 ; End of option list. -TCP_OPT_NOP equ 1 ; No-Operation. -TCP_OPT_MAXSEG equ 2 ; Maximum Segment Size. -TCP_OPT_WINDOW equ 3 ; window scale -TCP_OPT_TIMESTAMP equ 8 +TCP_OPT_EOL equ 0 ; End of option list. +TCP_OPT_NOP equ 1 ; No-Operation. +TCP_OPT_MAXSEG equ 2 ; Maximum Segment Size. +TCP_OPT_WINDOW equ 3 ; window scale +TCP_OPT_TIMESTAMP equ 8 ; Fundamental timer values -TCP_time_MSL equ 47 ; max segment lifetime (30s) -TCP_time_re_min equ 2 ; min retransmission (1,28s) -TCP_time_re_max equ 100 ; max retransmission (64s) -TCP_time_pers_min equ 8 ; min persist (5,12s) -TCP_time_pers_max equ 94 ; max persist (60,16s) -TCP_time_keep_init equ 118 ; connectione stablishment (75,52s) -TCP_time_keep_idle equ 4608 ; idle time before 1st probe (2h) -TCP_time_keep_interval equ 118 ; between probes when no response (75,52s) -TCP_time_rtt_default equ 5 ; default Round Trip Time (3,2s) +TCP_time_MSL equ 47 ; max segment lifetime (30s) +TCP_time_re_min equ 2 ; min retransmission (1,28s) +TCP_time_re_max equ 100 ; max retransmission (64s) +TCP_time_pers_min equ 8 ; min persist (5,12s) +TCP_time_pers_max equ 94 ; max persist (60,16s) +TCP_time_keep_init equ 118 ; connectione stablishment (75,52s) +TCP_time_keep_idle equ 4608 ; idle time before 1st probe (2h) +TCP_time_keep_interval equ 118 ; between probes when no response (75,52s) +TCP_time_rtt_default equ 5 ; default Round Trip Time (3,2s) +TCP_time_srtt_default equ 0 ; ; timer constants -TCP_max_rxtshift equ 12 ; max retransmissions waiting for ACK -TCP_max_keepcnt equ 8 ; max keepalive probes +TCP_max_rxtshift equ 12 ; max retransmissions waiting for ACK +TCP_max_keepcnt equ 8 ; max keepalive probes ; -TCP_max_winshift equ 14 -TCP_max_win equ 65535 +TCP_max_winshift equ 14 +TCP_max_win equ 65535 -TCP_re_xmit_thresh equ 3 +TCP_re_xmit_thresh equ 3 -struct TCP_header +TCP_mss_default equ 1480 ; default max segment size - SourcePort dw ? - DestinationPort dw ? - SequenceNumber dd ? - AckNumber dd ? - DataOffset db ? ; DataOffset[0-3 bits] and Reserved[4-7] - Flags db ? ; Reserved[0-1 bits]|URG|ACK|PSH|RST|SYN|FIN - Window dw ? - Checksum dw ? - UrgentPointer dw ? +struct TCP_header + + SourcePort dw ? + DestinationPort dw ? + SequenceNumber dd ? + AckNumber dd ? + DataOffset db ? ; DataOffset[0-3 bits] and Reserved[4-7] + Flags db ? ; Reserved[0-1 bits]|URG|ACK|PSH|RST|SYN|FIN + Window dw ? + Checksum dw ? + UrgentPointer dw ? ends align 4 uglobal - TCP_headers_tx rd IP_MAX_INTERFACES - TCP_headers_rx rd IP_MAX_INTERFACES - TCP_bytes_rx rq IP_MAX_INTERFACES - TCP_bytes_tx rq IP_MAX_INTERFACES - TCP_sequence_num dd ? + TCP_headers_tx rd IP_MAX_INTERFACES + TCP_headers_rx rd IP_MAX_INTERFACES + TCP_bytes_rx rq IP_MAX_INTERFACES + TCP_bytes_tx rq IP_MAX_INTERFACES + TCP_sequence_num dd ? endg @@ -108,15 +111,15 @@ endg ; This function resets all TCP variables ; ;----------------------------------------------------------------- -macro TCP_init { +macro TCP_init { - xor eax, eax - mov edi, TCP_headers_tx - mov ecx, (6*IP_MAX_INTERFACES) - rep stosd + xor eax, eax + mov edi, TCP_headers_tx + mov ecx, (6*IP_MAX_INTERFACES) + rep stosd - pseudo_random eax - mov [TCP_sequence_num], eax + pseudo_random eax + mov [TCP_sequence_num], eax } @@ -143,24 +146,24 @@ include 'tcp_output.inc' align 4 TCP_API: - movzx eax, bh - shl eax, 2 + movzx eax, bh + shl eax, 2 - test bl, bl - jz .packets_tx ; 0 - dec bl - jz .packets_rx ; 1 + test bl, bl + jz .packets_tx ; 0 + dec bl + jz .packets_rx ; 1 .error: - mov eax, -1 - ret + mov eax, -1 + ret .packets_tx: - add eax, TCP_headers_tx - mov eax, [eax] - ret + add eax, TCP_headers_tx + mov eax, [eax] + ret .packets_rx: - add eax, TCP_headers_rx - mov eax, [eax] - ret + add eax, TCP_headers_rx + mov eax, [eax] + ret diff --git a/kernel/branches/net/network/tcp_input.inc b/kernel/branches/net/network/tcp_input.inc index 83eeb327e2..da85e696db 100644 --- a/kernel/branches/net/network/tcp_input.inc +++ b/kernel/branches/net/network/tcp_input.inc @@ -595,6 +595,8 @@ align 4 mov [ebx + TCP_SOCKET.t_state], TCPS_ESTABLISHED ;;; TODO: check if we should scale the connection (567-572) + mov [ebx + TCP_SOCKET.SND_SCALE], 0 + ;;; TODO: update RTT estimators jmp .trim_then_step6 @@ -1249,24 +1251,7 @@ align 4 .update_window: - DEBUGF 1,"Updating window\n" - -; Keep track of pure window updates - -; test ecx, ecx -; jz @f -; -; mov eax, [ebx + TCP_SOCKET.SND_WL2] -; cmp eax, [edx + TCP_header.AckNumber] -; jne @f -; -; ;; mov eax, tiwin -; cmp eax, [ebx + TCP_SOCKET.SND_WND] -; jbe @f -; -; ;;; update stats -; -; @@: +;;; TODO: Keep track of pure window updates mov eax, dword [edx + TCP_header.Window] cmp eax, [ebx + TCP_SOCKET.max_sndwnd] @@ -1275,6 +1260,8 @@ align 4 @@: mov [ebx + TCP_SOCKET.SND_WND], eax + DEBUGF 1,"Updating window to %d\n", eax + push [edx + TCP_header.SequenceNumber] pop [ebx + TCP_SOCKET.SND_WL1] diff --git a/kernel/branches/net/network/tcp_output.inc b/kernel/branches/net/network/tcp_output.inc index 71f8fb49e5..86df6bff67 100644 --- a/kernel/branches/net/network/tcp_output.inc +++ b/kernel/branches/net/network/tcp_output.inc @@ -100,13 +100,14 @@ TCP_output: @@: sub esi, ebx + ;------------------------ ; check for window shrink (107) ; If FIN has been set, but not ACKed, but we havent been called to retransmit, esi will be -1 ; Otherwise, window shrank after we sent into it. - jns .not_negative + jae .not_persist ; enter persist state xor esi, esi @@ -126,7 +127,7 @@ TCP_output: ; If window didn't close completely, just wait for an ACK - .not_negative: + .not_persist: ;--------------------------- ; Send one segment at a time (124) @@ -291,7 +292,7 @@ TCP_output: .send: - DEBUGF 1,"Preparing to send a segment\n" + DEBUGF 1,"Preparing to send a segment socket: %x length: %u flags: %x\n", eax, esi, dl mov edi, sizeof.TCP_header ; edi will contain headersize diff --git a/kernel/branches/net/network/tcp_subr.inc b/kernel/branches/net/network/tcp_subr.inc index 25988dd23b..a7ad3ee927 100644 --- a/kernel/branches/net/network/tcp_subr.inc +++ b/kernel/branches/net/network/tcp_subr.inc @@ -82,11 +82,21 @@ macro TCP_rcvseqinit ptr { +macro TCP_init_socket socket { + + mov [socket + TCP_SOCKET.t_maxseg], TCP_mss_default + mov [socket + TCP_SOCKET.t_flags], 0 ; we could also request scale and timestamp + + mov [socket + TCP_SOCKET.t_srtt], TCP_time_srtt_default + mov [socket + TCP_SOCKET.t_rttvar], TCP_time_rtt_default * 4 + mov [socket + TCP_SOCKET.t_rttmin], TCP_time_re_min +;;; TODO: TCP_time_rangeset + + mov [socket + TCP_SOCKET.SND_CWND], TCP_max_win shl TCP_max_winshift + mov [socket + TCP_SOCKET.SND_SSTHRESH], TCP_max_win shl TCP_max_winshift - - - +} ;--------------------------- @@ -402,4 +412,4 @@ macro TCP_set_persist socket { ;if (tp->t_rxtshift < TCP_MAXRXTSHIFT) ; tp->t_rxtshift++; -} \ No newline at end of file +}