Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push skb in specific point of Linux network stack?

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.

enter image description here

like image 729
Milad Khajavi Avatar asked Jan 13 '14 08:01

Milad Khajavi


1 Answers

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.

like image 60
abligh Avatar answered Sep 23 '22 01:09

abligh