4

I am trying to handle simple packet inspection with netfilter hooks.

Declaration seems fairly straightforward:

unsigned int hook_func(unsigned int hooknum, struct sk_buff *skb, 
            const struct net_device *in,
            const struct net_device *out, int (*okfn)(struct sk_buff *))
{

     struct iphdr *iph = (struct iphdr *)skb_network_header(skb);

}

And I can access the protocol portion of the network header

iph->protocol == IPPROTO_TCP

However

iph->saddr

Fails. Any suggestions? I feel as this is a fairly simple error on my part, but all the examples follow either this method or they simply use

struct iphdr *iph = ip_hdr(skb);

I get the same behavior with both methods. I have looked through skbuff.h for any clues but havn't had any luck.

EDIT:

Could this have to do with they way I am accessing it? Right now for debugging I am merely trying to print the value out using:

printk(KERN_DEBUG "%pI4", iph->saddr);

Timothy Jones
  • 21,495
  • 6
  • 60
  • 90
kevgliss
  • 105
  • 1
  • 8

1 Answers1

3

%pI4 takes an address, so you are reading possibly invalid memory. Use &iph->saddr instead.

fnl
  • 2,209
  • 19
  • 17