I am trying to modify the source IP of all packets outcoming from the machine to something I specify in this Kernel Module, but everytime I try to access nh.iph->saddr I get an error in compile time that says Struct sk_buff has no member named nh
What am I doing wrong here? Have I missed some header or something??
我试图将从机器输出的所有数据包的源IP修改为我在内核模块中指定的内容,但每次尝试访问nh时。iph->saddr我在编译时得到一个错误,说Struct sk_buff没有成员nh,我在这里做错了什么?我是不是漏掉了一些标题?
#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;
}
Note that I am running Ubuntu 10.04 LTS 64 bits
Kernel 2.6.32-33
注意,我正在运行Ubuntu 10.04 LTS 64位内核2.6.32-33
2 个解决方案
#1
13
In your kernel version the struct sk_buff
has changed. It no longer has those members. To access the ip header you should try:
在您的内核版本中,结构sk_buff发生了更改。它不再拥有这些成员。要访问ip头,请尝试:
#include <linux/ip.h>
struct iphdr* iph = ip_hdr(skb);
Then just use the iph
variable to change the addresses, something like:
然后使用iph变量来改变地址,比如:
iph->saddr = ....
iph->daddr = ....
Also, don't forget that you might need to recalculate ip
and possible transport packets checksums.
另外,不要忘记您可能需要重新计算ip和可能的传输数据包校验和。
#2
-1
You can find the definition of struck sk_buff in 'include/linux/skbuff.h'.
您可以在“include/linux/skbuff.h”中找到hit sk_buff的定义。
It does not have an nh field, which explains the compilation errors you're seeing. It does have a 'network_header' field, which is probably what you're looking for.
它没有nh字段,这解释了您所看到的编译错误。它确实有一个'network_header'字段,这可能是您正在寻找的。
#1
13
In your kernel version the struct sk_buff
has changed. It no longer has those members. To access the ip header you should try:
在您的内核版本中,结构sk_buff发生了更改。它不再拥有这些成员。要访问ip头,请尝试:
#include <linux/ip.h>
struct iphdr* iph = ip_hdr(skb);
Then just use the iph
variable to change the addresses, something like:
然后使用iph变量来改变地址,比如:
iph->saddr = ....
iph->daddr = ....
Also, don't forget that you might need to recalculate ip
and possible transport packets checksums.
另外,不要忘记您可能需要重新计算ip和可能的传输数据包校验和。
#2
-1
You can find the definition of struck sk_buff in 'include/linux/skbuff.h'.
您可以在“include/linux/skbuff.h”中找到hit sk_buff的定义。
It does not have an nh field, which explains the compilation errors you're seeing. It does have a 'network_header' field, which is probably what you're looking for.
它没有nh字段,这解释了您所看到的编译错误。它确实有一个'network_header'字段,这可能是您正在寻找的。