Re: Dropping packets, general kernel hacking (newbie questions)

Rogier Wolff (R.E.Wolff@BitWizard.nl)
Sat, 23 Aug 1997 08:50:03 +0200 (MET DST)


Alan Cox wrote:
>
> > IP forwarding code for a linux router occasionally drop packets
> > and/or delay them some number of milliseconds. My first attempt
>
> I use a 3c501 ethernet card for this. Hardware crap network support.
>
> > will be to add the code somewhere at the end of ip_forward.c,
> > before the packets get put on the interface queue.
>
> Delaying packets is extremely tricky. Tossing them is quite easy. To
> toss the packet just add code to dev_queue_xmit and free the buffer
> (following the path as if the driver failed the transmit). To delay
> it needs some driver level tweaks - sometimes after a tx complete
> leave dev->tbusy set and reset it on a timer.

Ehhhm. Alan, I once implemented delaying packets (I problably
misplaced the patch), and it wasn't that hard:

delay = ipfw (GET_DELAY)
if (delay) {
pktdesc = kmalloc (...);
pktdesc.timer.func = continue_sending;
pktdesc.timer.time = jiffies + delay;
pktdesc.timer.data = (long) pktdesc;
pktdesc.packet = skb;
add_timer (pktdesc.timer);
return;
}
output_packet (skb);

[...]

continue_sending (pktdesc)
{
output_packet (pktdesc.skb);
kfree (pktdesc);
}

Note that the timer support functions are written to allow me to kfree
the memory in the timer function itself....

Roger.