This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RedBoot sequenecnumber generation


>>>>> Roland =?iso-8859-15?q?Ca=DFebohm?= writes:

> Hello,

> i have a problem with RedBoot connecting to other hosts.

> In RedBoot the initial sequencenumber for TCP is always the same. 
> If RedBoot try to connect to the same host and port multiple
> times, it couldn't connect while the port is in TIME_WAIT state
> on the host. I think this is because the thinks it gets old lost
> packets and just drops them.

> The attached patch solved the problem for me, but I think it is
> maybe not what is really right. At least the part in do_retrans().

Right. You don't want to mess with the sequence number in do_retrans.
It would be wrong to do so in the case where the retrans happens
because of a missed SYN response from the remote host.

Could you try the following patch to see if it works for you?

--Mark

Index: redboot/current/src/net/tcp.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/redboot/current/src/net/tcp.c,v
retrieving revision 1.11
diff -u -p -5 -r1.11 tcp.c
--- redboot/current/src/net/tcp.c	21 Dec 2003 13:17:52 -0000	1.11
+++ redboot/current/src/net/tcp.c	16 Mar 2004 14:05:26 -0000
@@ -58,10 +58,12 @@
 #include <cyg/hal/hal_if.h>
 
 #define MAX_TCP_SEGMENT (ETH_MAX_PKTLEN - (sizeof(eth_header_t) + sizeof(ip_header_t)))
 #define MAX_TCP_DATA    (MAX_TCP_SEGMENT - sizeof(tcp_header_t))
 
+/* setting this to 1 is technically wrong, but BSD does it too... */
+static int initial_seqnum = 1;
 
 /* sequence number comparison macros */
 #define SEQ_LT(a,b) ((int)((a)-(b)) < 0)
 #define SEQ_LE(a,b) ((int)((a)-(b)) <= 0)
 #define SEQ_GT(a,b) ((int)((a)-(b)) > 0)
@@ -479,10 +481,11 @@ __tcp_handler(pktbuf_t *pkt, ip_route_t 
                       return;
                   }
                   s->state = _ESTABLISHED;
                   s->ack = ntohl(tcp->seqnum) + 1;
                   s->seq = ntohl(tcp->acknum);
+                  initial_seqnum += 64000;
 		  __timer_cancel(&s->timer);
                   send_ack(s);
 		break;
 
 	      case _LISTEN:
@@ -523,10 +526,11 @@ __tcp_handler(pktbuf_t *pkt, ip_route_t 
 		} else if ((tcp->flags & TCP_FLAG_ACK) &&
 			   ntohl(tcp->acknum) == (s->seq + 1)) {
 		    /* we've established the connection */
 		    s->state = _ESTABLISHED;
 		    s->seq++;
+                    initial_seqnum += 64000;
 
 		    BSPLOG(bsp_log("ACK received - connection established\n"));
 		}
 		break;
 
@@ -643,10 +647,13 @@ void
 __tcp_poll(void)
 {
     __enet_poll();
     MS_TICKS_DELAY();
     __timer_poll();
+
+    /* rfc793 says this should be incremented approx. once per 4ms */
+    initial_seqnum += 1000 / 4;
 }
 
 
 int
 __tcp_listen(tcp_socket_t *s, word port)
@@ -890,11 +897,11 @@ __tcp_open(tcp_socket_t *s, struct socka
     s->his_port = host->sin_port;
     s->pkt.buf = (word *)s->pktbuf;
     s->pkt.bufsize = ETH_MAX_PKTLEN;
     s->pkt.ip_hdr  = (ip_header_t *)s->pkt.buf;
     s->pkt.tcp_hdr = (tcp_header_t *)(s->pkt.ip_hdr + 1);
-    s->seq = (port << 16) | 0xDE77;
+    s->seq = initial_seqnum;
     s->ack = 0;
     if (__arp_lookup((ip_addr_t *)&host->sin_addr, &s->his_addr) < 0) {
         diag_printf("%s: Can't find address of server\n", __FUNCTION__);
         return -1;
     }

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]