Skip to contentSkip to conversation

Need help combining packets in netfilter driver...

DISCUSSION Tom Dickerson 2 participants 3 messages Nov 14, 2005 – Dec 16, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

Hi Everyone,

I have a situation where we must send a large number of small packets over a relatively slow wireless link. I have a quick custom compression algortihm which can save alot of bandwidth for only a few machine cycles, but the sheer number of packets will swamp the wireless link. Due to handshaking on the wireless link, I must aggregate N small packets into 1 large packet, where N is determined by the number of compressed packets I can fit into a single 1500 byte packet. All traffic I am concerned with is UDP, and originates from a set of well known ports and machines, destined to a set of well known ports and machines.

I am trying to design something for in house use that is quick, dirty and most importantly fast. I need something that will do 300k+ pps. That is a challenge enough in itself, even without the compression filter. The compression algorithm will only add a few hundred machine cycles per packet...negligible in comparison to the netfilter infrastructure.

This will be my first attempt at writing anything with netfilter. Can someone suggest the quickest and most reliable way to aggregate a number of individual UDP packets into a single 1500 byte packet? The data is also a real time stream and latency is very important. I need to guarantee a minimum of 5000 pps over the wireless link. Thus, if I don't have a full 1500 bytes after 200 microseconds, I need to force the aggregate packet to be sent anyway.

My first plan was to hook in at POSTROUTING after all routing had been performed. In that hook I would simply compress and buffer the data in private storage, returning DROP for all the packets until I got a complete buffer. If the buffer was complete, I'd replace the skb with my own skb consisting of the aggregate packets I had stored and return ACCEPT.

This seemed simple, but it is not clear how to get the 200 microsecond timer behavior that I need in this case. Can I force my POSTROUTING hook to be called every 200 microseconds even if there is no traffic?

Also, on the receiving side, I need to reconstruct the original packet stream. I was thinking that in the PREROUTING hook I could simply decompress the packet back into the original packet stream. But this means I have to inject N-1 new packets directly into the netfilter stream. Can this be done from the PREROUTING hook?

Note that the Linux box is simply acting as a router for these packets. The packets are generated on remote servers and are destined for remote servers. There are no userspace programs involved in the packet transactions.

Can someone who is experienced suggest the correct way to implement a compression filter like this? Is there a way to make this very quick? Since this is such a specialized case I could even accept bypassing the routing tables and filtering altogether. The traffic will simply be coming in one gigabit ethernet card and heading out the other.

Any and all advice is appreciated,

Thank you in advance,

Tom Dickerson
[email protected]

#1 lore raw
Quoted 5 lines · Tom Dickerson

My first plan was to hook in at POSTROUTING after all routing had been performed. In that hook I would simply compress and buffer the data in private storage, returning DROP for all the packets until I got a complete buffer. If the buffer was complete, I'd replace the skb with my own skb consisting of the aggregate packets I had stored and return ACCEPT.

You may want to implement a custom queueing discipline to get this done. Qdiscs already are intimate with timers in the manner that you need and it would be simple to aggregate the packets as they arrive, simply updating header information as each new packet arrived. They could then be fired out when the qdisc calls for packets when the timer expires.

For information on qdisc programming, first read http://lartc.org to get an idea of how they are used. Then check out the source of net/sched/sch_tbf.c and net/sched/sch_sfq.c in you Linux kernel sources. If you need the qdisc to be classful (you'll know what that entails after reading LARTC above), you should look at net/sched/sch_htb.c.

Quoted 5 lines

Also, on the receiving side, I need to reconstruct the original packet stream. I was thinking that in the PREROUTING hook I could simply decompress the packet back into the original packet stream. But this means I have to inject N-1 new packets directly into the netfilter stream. Can this be done from the PREROUTING hook?

This could be done with an ingress qdisc. Exploding packets in iptables has been, how shall we say... problematic, for me at least. You should have less of an issue with this by creating a custom ingress qdisc. Check out the code in net/sched/sch_ingress.c for an idea of how to implement an ingress qdisc. (currently in Linux, there is only one)

Quoted 4 lines

Note that the Linux box is simply acting as a router for these packets. The packets are generated on remote servers and are destined for remote servers. There are no userspace programs involved in the packet transactions.

Yeah, this really indicates a custom qdisc to me. That would seem to me to be the most workable and elegant solution to your problem. Alternatively, you could attempt to hack the wireless driver and aggregate+compress the packets at that point, but the qdisc is more elegant IMO.

As far as resources on the Linux qdisc API, there aren't many. I couldn't find the one that I was thinking of, but here are some that have good information:

http://qos.ittc.ku.edu/howto.pdf
http://www.cs.odu.edu/%7Egmanepal/documents/qos.pdf

The paper is quite old, but mostly still correct.

As I was googling around to find that, however, I found this, which may be of some use to you, as well, as it speaks more directly to your problem area:

http://www.cs.umu.se/education/examina/Rapporter/JohanCimen.pdf

Good luck!

--
Toby DiPasquale
0x636f6465736c696e67657240676d61696c2e636f6d

#2 lore raw
Quoted 7 lines · Toby DiPasquale

As far as resources on the Linux qdisc API, there aren't many. I couldn't find the one that I was thinking of, but here are some that have good information:

http://qos.ittc.ku.edu/howto.pdf
http://www.cs.odu.edu/%7Egmanepal/documents/qos.pdf

Quoted 7 lines

The paper is quite old, but mostly still correct.

As I was googling around to find that, however, I found this, which may be of some use to you, as well, as it speaks more directly to your problem area:

http://www.cs.umu.se/education/examina/Rapporter/JohanCimen.pdf

This is the paper I found the most useful. It took me a while to find again because I didn't remember the name or author and only had a paper copy, which was buried until today.

http://citeseer.ist.psu.edu/almesberger99linux.html

--
Toby DiPasquale
0x636f6465736c696e67657240676d61696c2e636f6d