how to hack linux driver to delay incoming packets

hello,
can anyone suggest how to delay the incoming packets ??
or how the packets are prossed inside the kernal and a way to make the packets wait a while??
it wud be vry helpful

regards
sameer

You can easily delay packets leaving the system using traffic control, but entering? That's a ton harder and much less stable: It has to store everything before it lets it enter, you get the potential for states where the kernel can't store as fast as it's receiving and has no way to tell the other end to slow down. In-kernel memory is also limited.

I'm not sure you need driver hacking to do it anyway. Doing it in userspace avoids most of the above problems. I'd try this:

  • Create a tun/tap interface (see Documentation/networking/tuntap.txt in the linux kernel)
  • Configure your ethernet device for 0.0.0.0, remove it from the routing table, and just read/write raw packets with a userspace program.
  • Write raw packets from the ethernet adaptor to the tun/tap device. Write raw packets from the tun/tap device to the ethernet adaptor. Your program can store them for how long you want inbetween.
  • Use your tun/tap device for normal traffic. Add it to the routing table, etc. so normal programs use it.
1 Like

is it possible by the above method
in case

  1. when the packets come from say system A and its destination is C.
    2.before forwarding it to C from the current system i need to introdude the delay
  2. and i want it run like a demon process delaying every packet...

That's actually much much easier, and possible without a daemon, because having a host in the middle lets you control traffic both ways just by delaying outgoing packets; it's easy to control what you send but difficult to control what you receive. Linux can throttle outgoing traffic natively, even on routed traffic. It's done in terms of priority and bandwidth, not fixed delays though. See "hierarchical token bucket" aka htb.

1 Like

may i kw how to convert unsigned long int to ip string format??

See man inet_ntoa.

hey my prob is
system A: i am sending long integer (after converting char string ip of some other system say C) to other sys say B.
system B: here i receive long integer but i want in char string format say for connecting to tht converted ip address from here..ie system C..

inet_ntoa directly converts 32-bit integers into character strings. See man inet_ntoa.

printf("%s\n", inet_ntoa(0x0100007f));