<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>

<META content="MSHTML 6.00.2800.1226" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>Hi All (and Harald 
in particular),</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>I have found the 
following oddity in the TCP state machine:-</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>If I do an active 
open from Nut/OS and the destination machine's server software is not running 
the destination machine will correctly return a RST to 
Nut/OS.</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>At this point the 
TCP state machine is in TCPS_SYN_SENT state and the incomming RST correctly 
sets:-</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial 
size=2>sock-&gt;so_last_error = ECONNREFUSED;<BR>sock-&gt;so_state = 
TCPS_CLOSE_WAIT;</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>It does not however 
remove the original active open SYN packet from the send 
queue.</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>Soon enough the 
retransmit timer expires and Nut/OS re-sends the original SYN packet, which 
again attracts a RST.</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>This repeats until 
the socket times out and closes and generates a LOT of useless 
traffic.</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>This should not 
happen, RFC 793 goes into quite some detail about how RSTs should be handled but 
in summary:-</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>All socket send and 
receive queues should be flushed.</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>The TCB should be 
deleted.</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>The Application 
should be notified.</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>The socket should go 
directly to the CLOSED state.</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003></SPAN><SPAN class=293101707-26082003><FONT 
face=Arial size=2>Looking through tcpsm it seems Nut/OS does not handle RST's 
correctly regardless of the current state.</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>I've added the 
following function to tcpsm.c</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>/*!<BR>&nbsp;* 
\brief RST processing.<BR>&nbsp;*<BR>&nbsp;* \param sock Socket descriptor. This 
pointer must have been 
<BR>&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
retrieved by calling NutTcpCreateSocket().<BR>&nbsp;*<BR>&nbsp;*/<BR>static void 
NutTcpProcessRst(TCPSOCKET * sock)<BR>{<BR>&nbsp;NETBUF *nb;</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>&nbsp;// Immediatly 
set state to closed<BR>&nbsp;sock-&gt;so_state = 
TCPS_CLOSED;</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>&nbsp;// Delete 
anything in the buffer<BR>&nbsp;if (sock-&gt;so_rx_buf) 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
NutHeapFree(sock-&gt;so_rx_buf);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
sock-&gt;so_rx_cnt = 0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
sock-&gt;so_rx_buf = 0;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; while ((nb 
= sock-&gt;so_tx_nbq) != 0) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
sock-&gt;so_tx_nbq = 
nb-&gt;nb_next;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
NutNetBufFree(nb);<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; while ((nb = 
sock-&gt;so_rx_nbq) != 0) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
sock-&gt;so_rx_nbq = 
nb-&gt;nb_next;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
NutNetBufFree(nb);<BR>&nbsp;&nbsp;&nbsp; }</FONT></SPAN></DIV>
<DIV>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>&nbsp;// Notify 
changes<BR>&nbsp;&nbsp;&nbsp; 
NutEventBroadcast(&amp;sock-&gt;so_rx_tq);<BR>&nbsp;&nbsp;&nbsp; 
NutEventBroadcast(&amp;sock-&gt;so_tx_tq);<BR>&nbsp;&nbsp;&nbsp; 
NutEventBroadcast(&amp;sock-&gt;so_pc_tq);<BR>&nbsp;&nbsp;&nbsp; 
NutEventBroadcast(&amp;sock-&gt;so_ac_tq);<BR>}</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial size=2>And call it as 
appropriate when a RST is received, which seems to work for 
me.</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003><FONT face=Arial 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=293101707-26082003></SPAN><SPAN class=293101707-26082003><FONT 
face=Arial size=2>Regards,</FONT></SPAN></DIV>
<DIV><SPAN class=293101707-26082003></SPAN>&nbsp;</DIV>
<DIV align=left><FONT face=Arial 
size=2>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<BR>Mike 
Cornelius&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
Internet: <A 
href="mailto:mikec@call-direct.com.au">mikec@call-direct.com.au</A><BR>Call 
Direct Cellular Solutions&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Phone:&nbsp;&nbsp;&nbsp; 
+61 2 9209-4259<BR>Suite 
145&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
FAX:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +61 2 9209-4196<BR>National Innovation 
Centre&nbsp;&nbsp;&nbsp;&nbsp; URL:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <A 
href="http://www.call-direct.com.au/">http://www.call-direct.com.au</A><BR>Australian 
Technology Park<BR>Eveleigh NSW 
1430<BR>Australia&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<BR>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</FONT></DIV>
<DIV>&nbsp;</DIV></BODY></HTML>