lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] Re: [lwip] IP reassembly


From: Adam Dunkels
Subject: [lwip-users] Re: [lwip] IP reassembly
Date: Wed, 08 Jan 2003 23:58:03 -0000

Hi!

On Wed, 2002-07-24 at 11:22, amol patel wrote:
>    Can anybody tell me how bitmap_bits (constant) is 
> related to  the ip_reassbitmap in the above function? 
> 
> static u8_t ip_reassbitmap[IP_REASS_BUFSIZE / (8 *
> 8)];
> static const u8_t bitmap_bits[8] = {0xff, 0x7f, 0x3f,
> 0x1f,0x0f, 0x07, 0x03, 0x01};
> 
> and how the size of the bitmap_bits array is fixed (8)

The ip_reassbitmap[] array is used to keep track of which fragments that
has been received so far. Each bit in the array marks that a 8-byte
chunk of the resulting packet is stored in the ip_reassbuf[].

The bitmap_bits[] table is a helping hand in the implementation of the
bit map operations. Basically, the table is used to look up the bit
offset for the byte that will be affected by the bit map update.

To get a feeling for it, try to work out some examples by hand! The
following code contains the "magic" ;-):

      /* If the two endpoints are in the same byte, we only update
         that byte. */
      ip_reassbitmap[offset / (8 * 8)] |=
        bitmap_bits[(offset / 8 ) & 7] &
        ~bitmap_bits[((offset + len) / 8 ) & 7];
and 

      /* If the two endpoints are in different bytes, we update the
         bytes in the endpoints and fill the stuff inbetween with
         0xff. */
      ip_reassbitmap[offset / (8 * 8)] |= bitmap_bits[(offset / 8 ) &
7];
      for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) {
        ip_reassbitmap[i] = 0xff;
      }      
      ip_reassbitmap[(offset + len) / (8 * 8)] |= ~bitmap_bits[((offset
+ len) / 8 ) & 7];

There is some quite nice boolean algebra tricks in there, similar to how
two bytes are swapped without a temporary location (try to figure it out
if you don't know it!).

/adam
-- 
Adam Dunkels <address@hidden>
http://www.dunkels.com/adam/

[This message was sent through the lwip discussion list.]




reply via email to

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