Reputation: 11
static unsigned int main_hook(unsigned int hooknum , struct sk_buff *skb , const struct net_device *in , const struct net_device *out, int (*okfn)(struct sk_buff*))
{
int i=0;
struct iphdr *iph = ip_hdr(skb);
unsigned long saddr = 0 , daddr = 0;
unsigned long snet = 0; //dnet =0;
int dst_cnt=0 , src_cnt=0;
//printk("netfilter called\n");
//down(&sema);
Netfilter_Execute++;
saddr = iph->saddr;
daddr = iph->daddr;
when I execute this module program, the linux shut down and reboot.
When I test the program, iph
is null so saddr = iph->saddr and daddr = iph->daddr
was wrong.
I don't know why iph = ip_hdr(skb)
returns NULL
.
Upvotes: 0
Views: 560
Reputation: 201
try:
instead of struct iphdr *iph = ip_hdr(skb);
, type struct iphdr *iph = (struct iphdr *)skb_network_header(skb);
Upvotes: 1
Reputation: 49
The problem may be depend on which hook you use, you have to mind where your hook place related to the kernel routing module.
Let me show you these 2 examples
If you use
NF_IP_LOCAL_OUT
The packet that you receive in your hook doesn't go throw the Routing module in the kernel so it will not have a header
If you use
NF_IP_LOCAL_IN
The packet will go throw the Routing module but the Routing module will remove the header of the packet and route it to an internal process
Upvotes: 1