Sending a packet through the kernel module

I am trying to create a kernel module that can send modified packets from those that it receives through a netfilter connection. I use the code skeleton provided here . I create a raw socket inside the kernel just using this code:

struct socket *sockptr; sock_create(PF_INET, SOCK_RAW, IPPROTO_TCP, &sockptr); 

The sendpacket function is called as follows:

 len = sendpacket(sockptr, dev, IPPROTO_TCP, duplicate, ntohs(dupiph->tot_len)); 

socketptr, which is the raw socket I created, dev, which is the net_device passed to me by the hooking function, and duplication is a modified copy of the source package.

A return from the dev_queue_xmit call indicates that the packet was successfully transmitted, but I do not see the packet on the wire. I have two questions: firstly, I would like to be able to better debug what is happening, so any advice regarding this is greatly appreciated. Also, I am wondering if I am handling the socket creation correctly or not, of any configuration that I am skipping. This is all very new to me, so it’s very good that I am missing out on something stupid.

+8
c linux networking kernel
source share
1 answer

It is unlikely that you need to change the kernel to complete your task. Have you considered using the tun or tap interface so that you can do all your work in user space? Here is the tutorial: http://backreference.org/2010/03/26/tuntap-interface-tutorial/

+1
source share

All Articles