Reputation: 2859
I want to push skb to prerouting
point of Linux network stack. Is there any way to do this?
I used dev_queue_xmit()
and netif_rx()
functions, but I don't think they can push skb in prerouting
point of Linux network stack.
Upvotes: 9
Views: 1980
Reputation: 529
I think the function you are looking for is ip_queue_xmit()
, which is where IPV4 implementation starts checking tables, filters, etc.
Upvotes: 0
Reputation: 25129
I'm not entirely clear where this skb originates from. In userland, there are two ways to do this. One is to use a tun
device (and simply write the packet in). The other is to use libpcap
(which has the little known feature of sending raw packets hidden amongst all the receive stuff).
You say you want to do this by registering an ioctl
(presumably meaning adding your own ioctl
) then calling the ioctl
from user space. It isn't immediately obvious why you would want to do that when you can already achieve this without modifying the kernel. However, if you did want to do this, what I'd do is follow the path the tun
driver uses, and do the equivalent of write()
-ing to the tun
device in your new ioctl
. That might mean having a tun
-like interface hanging around to act as the source for the packets. I suspect packets in the system need a source interface of sorts.
Upvotes: 2
Reputation: 2338
I suspect you want libpcap or libnetfilter_queue hereafter collectively referred to as userland queuing. Userland queuing will route all packets matching some rule (you define) to your userland application. The dev_queue_* and netif_* functions apply to kernel level routing and are not relevant to userland applications.
Userland queuing has performance implications and depending on the library you use you will have to use a specific method of re-injecting your packet back into the netfilter queues.
Upvotes: 1