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.
c linux networking kernel
bschulte3
source share