lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] [lwip] ip reassembly fixes


From: Jani Monoses
Subject: [lwip-users] [lwip] ip reassembly fixes
Date: Thu, 09 Jan 2003 00:03:21 -0000


The exprimental IP reassembly code has a couple of bugs
1)it only copies the right data to the reass buffer if it fits in one 
pbuf.If it's a chain it does not work
2)does not set the total length of the reconstructed IP packet
3)the pbuf should be IP not LINK type

with the patch below it seems to work.
copy_from_buf should reside in pbuf.c I think there are a couple of places where
it could be used...
 
--- /home/jani/sources/lwip-cvs-20020920/src/core/ipv4/ip.c     Fri Sep 20 
17:00:05 2002
+++ ip.c        Mon Sep 23 11:40:56 2002
@@ -207,6 +207,24 @@
   netif->output(netif, p, (struct ip_addr *)&(iphdr->dest));
 }
 #endif /* IP_FORWARD */
+
+
+/* Copy len bytes from offset in pbuf to buffer */
+static void copy_from_pbuf(struct pbuf *p, int offset, char * buffer, int len)
+{
+       int l;
+       
+       (char*)p->payload += offset;
+       p->len -= offset;
+       while (len) {
+               l = len < p->len ? len : p->len;
+               bcopy(p->payload, buffer, l);
+               buffer += l;
+               len -= l;
+               p = p->next;
+       }
+}
+
 
/*-----------------------------------------------------------------------------------*/
 /* ip_reass:
  *
@@ -227,6 +245,7 @@
 #define IP_REASS_FLAG_LASTFRAG 0x01
 static u8_t ip_reasstmr;
 
+
 static struct pbuf *
 ip_reass(struct pbuf *p)
 {
@@ -249,7 +268,6 @@
     /* Clear the bitmap. */
     bzero(ip_reassbitmap, sizeof(ip_reassbitmap));
   }
-
   /* Check if the incoming fragment matches the one currently present
      in the reasembly buffer. If so, we proceed with copying the
      fragment into the buffer. */
@@ -276,9 +294,7 @@
        offset. */
     DEBUGF(IP_REASS_DEBUG, ("ip_reass: copying with offset %d into %d:%d\n",
                            offset, IP_HLEN + offset, IP_HLEN + offset + len));
-    bcopy((u8_t *)fraghdr + IPH_HL(fraghdr) * 4,
-         &ip_reassbuf[IP_HLEN + offset], len);
-
+       copy_from_pbuf(p, IPH_HL(fraghdr) * 4, &ip_reassbuf[IP_HLEN + offset], 
len);
     /* Update the bitmap. */
     if(offset / (8 * 8) == (offset + len) / (8 * 8)) {
       DEBUGF(IP_REASS_DEBUG, ("ip_reass: updating single byte in bitmap.\n"));
@@ -336,6 +352,9 @@
 
       /* Pretend to be a "normal" (i.e., not fragmented) IP packet
         from now on. */
+      ip_reasslen += IP_HLEN;
+
+      IPH_LEN_SET(iphdr, htons(ip_reasslen));
       IPH_OFFSET_SET(iphdr, 0);
       IPH_CHKSUM_SET(iphdr, 0);
       IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN));
@@ -345,7 +364,7 @@
         also reset the timer. */
       ip_reasstmr = 0;
       pbuf_free(p);
-      p = pbuf_alloc(PBUF_LINK, ip_reasslen, PBUF_POOL);
+      p = pbuf_alloc(PBUF_IP, ip_reasslen, PBUF_POOL);
       if(p != NULL) {
        i = 0;
        for(q = p; q != NULL; q = q->next) {
@@ -388,7 +407,6 @@
   static u8_t hl;
 
   
-  
 #ifdef IP_STATS
   ++stats.ip.recv;
 #endif /* IP_STATS */
[This message was sent through the lwip discussion list.]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]