C - Unable to access saddr

I am trying to handle packet inspection using network filters.

The declaration seems pretty simple:

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 part of the network header protocol

iph->protocol == IPPROTO_TCP

but

iph->saddr

Fails. Any suggestions? I feel that this is a pretty simple mistake on my part, but all the examples follow either this method, or just use

struct iphdr *iph = ip_hdr(skb);

I get the same behavior with both methods. I looked through skbuff.h for any tips, but havn't been lucky.

EDIT:

Could this have anything to do with how I refer to him? Now for debugging, I'm just trying to print the value with:

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

+4
source share
1 answer

%pI4 accepts the address, so you are reading possibly invalid memory. Use &iph->saddr .

+2
source

Source: https://habr.com/ru/post/1396077/


All Articles