How do I contact the members of struct sk_buff?
I am trying to change the original IP of all packets leaving the machine to what I am specifying in this kernel module, but every time I try to access nh.iph-> saddr I get a compile-time error, in which says Struct sk_buff has no name nh
What am I doing wrong here? Am I missing some title or something similar?
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/skbuff.h>
#include <linux/ip.h> /* For IP header */
#include <linux/inet.h> /* For in_aton(); htonl(); and other related Network utility functions */
static struct nf_hook_ops nfho;
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 sk_buff *sb = *skb;
struct in_addr masterIP;
masterIP.s_addr = htonl (in_aton("192.168.1.10"));
sb->nh.iph->saddr = masterIP.s_addr;
return NF_ACCEPT;
}
Please note that I am running Ubuntu 10.04 LTS 64 bit
Kernel 2.6.32-33
source to share
The version struct sk_buff
has changed in the kernel version . It no longer has these members. To access the IP header you should try:
#include <linux/ip.h>
struct iphdr* iph = ip_hdr(skb);
Then just use a variable iph
to change the addresses, for example:
iph->saddr = .... iph->daddr = ....
Also, do not forget that you may need to recalculate the ip
possible checksums of the transport packets.
source to share