I am writing a dissector for a UDP protocol with the following (rather unfortunate) features:
In practice, this means that some assembly must be done before it is even possible to determine how much assembly will be needed to complete a PDU. I have approached this by using the various tools in reassemble.h. However, I am getting stuck in a few places, and am looking for suggestions. My dissector essentially looks like this (pseudocode):
|
2 Answers:
From the looks of it your protocol is screwed up. UDP is an unreliable datagram protocol, hence does not guarantee delivery, nor sequence. Once an inconsistency occurs your dissector (and any receiver for that matter) will get out of sync. Maybe the RTP dissector can be of help, it also runs over UDP, and contains reassembly code. Although I think it has the benefit of sequence numbers. answered 12 Aug '11, 01:38 Jaap ♦ |
OK, so let's look at the protocol's (mis-)features:
That means you need to have some way of knowing when the PDU ends, i.e. when you're done with reassembly.
That means you need to have some way of knowing when the header ends.
Again, you need to know when the PDU ends, even if the entire PDU is within one UDP datagram.
OK, that presumably means the length tells you when the PDU ends. If the delimiter is variable-length, there has to be some way of knowing when the delimiter ends; what is that?
Which, as Jaap noted, means that the receiver has to assume that the packets are delivered in order, and, if they're not, it won't work correctly, so, if Wireshark doesn't reassemble the packets "correctly" in that case, it's actually correct in the sense that it'll show you what a receiver that got the UDP packets in the same order will think it got, even if that's not what the sender intended it to see.
That's similar to many protocols running atop TCP, so that's not inherently insoluble. You might have to implement something similar to answered 16 Aug '11, 03:03 Guy Harris ♦♦ edited 17 Aug '11, 16:10 Whether or not the dissector will show PDU reassembly problems experienced by the receiver also depends on where the capture is made. At the sender side all may seem nice and dandy, while at the receiver things may not be... (16 Aug '11, 05:02) Jaap ♦ For the moment, I'm ignoring packet loss and sequence problems. (17 Aug '11, 15:54) sweetpea The delimiter looks like MSG:xxxxx[newline], where xxxxx is 1-5 characters. Following is a 2-byte PDU type, and 2 byte PDU length, then the data, then a 2-byte checksum. Packets often come in a pattern like this:
... (17 Aug '11, 15:57) sweetpea |
The protocol is screwed up. Sadly, that doesn't eliminate the need to dissect and troubleshoot it. The main consolation is that PDUs are generally fairly small, so any dropped or out-of-sequence packets will only affect a small part of the stream.
The RTP dissector seems to depend on conversations and sequence numbers, but it does offer some hints. Setting the partial reassembly flag is one step I was missing. I'm still stumped on multiple PDUs, though.
On the first pass through the capture, you'll see the packets in the sequence they're in inside the capture file, which is the closest approximation you'll get to the time order. Reassemble them assuming they're in the right order; if they're not, what you reassemble will be what any receiver who got them in the same order would see - if that's bogus, then what the receiver reassembles will be bogus to, so Wireshark will show you that bogosity. (I.e., given the brokenness of the protocol, the brokenness of reassembly will show you the results of the brokenness of the protocol.)
Yes. I know I can't do better than the sequence coming into wireshark. Originally, I implemented all of the reassembly myself, which worked on the first pass, but not on random access when looking at actual frames in wireshark. I can understand how to parse and display PDUs based on that first pass; what's tricky is finding the correct way to store the information so that it works in random access.