0

I am trying to currently deal with IP packet fragmentation. I need to somehow flag fragmented packets with some value (sort them to a bucket according to some information), but I receive them after they're fragmented. I can't assure the order of the arriving fragments, nor that I'll receive fragments for each in order. For example, for packets A, B and C I can receive fragments in the following order: A1, B1, B2, C1, A2, C2, B3, C4, C3, A4, A3... I can't assume anything.

Now I'm using the simplest method available, and saving these fragments in lists. My question is, when (And whether it's even possible) can I know that all of the fragments of a specific packet have been arrived and that I can discard this packet from my cache? I'm probably missing something in the IP header field...

Thank you for your help.

fashasha
  • 481
  • 2
  • 7
  • 19
  • You don't have to work hard, Check out **MF** (More fragment) flag in ip [Here] (https://en.wikipedia.org/wiki/IPv4) – drtf Nov 04 '13 at 14:42

1 Answers1

0

So, I thought about it a bit, and I have a possible calculation which might help.

I will save some form of meta-info for each packet, and do some Total Length - HDL calculation - Frag Offset.

If I receive a packet, I save it's ID (Each ID will have its own meta-info) and if it's not the last frag (According to the field) I store [add up] the (Total length - HDL). In case it's the last frag, I deduce the (Frag Offset) from that accumulating value. I can consider the meta-info as "complete" and discard it as soon as I see that the calculation of the (Total Length - HDL) that I've accumulated along with (- Frag Offset) from the last packet is 0.

What do you think?

fashasha
  • 481
  • 2
  • 7
  • 19
  • There is a perfectly good flag in the header that tells you if More Fragments (MF) are following. Don't try to over-complicate things :) – Sander Steffann Nov 04 '13 at 18:37
  • 1
    But I can't rely on the order of the fragments. For a packet A, I can get the fragments in any order, for example, A3, A4, A1, A2 (Four fragments). That flag will not help me much in this scenario. – fashasha Nov 05 '13 at 08:52
  • Ah, ok. In that case you also need yo take care of overlapping fragments and other bad stuff. Don't assume everyone plays nicely :) – Sander Steffann Nov 05 '13 at 09:06