- 论坛徽章:
- 0
|
帮你修改了一下代码,我测试了一下checksum可以通过了; 我的服务器出了点问题,剩下的十一以后再调试吧
#define _KERNEL_
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/config.h>
#include <linux/ip.h>
#include <linux/inet.h>
#include <linux/in.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#define ALERT(fmt,args...) printk("Test: " fmt,##args)
#define REALIP "192.168.9.163" /* port that appears on the wire */
#define FAKEIP "192.168.9.6" /* port that appears on the wire */
static struct nf_hook_ops nfho_in;
static struct nf_hook_ops nfho_out;
//static unsigned char *drop_ip ="\x2a\xd7\xf1\x1";
__u32 in_aton(const char *);
unsigned long int magic_ip;
char *ip;
//MODULE_PARM(ip, "s" ;
static unsigned int my_call_out(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 *sk = *skb;
unsigned int tcphoff=sk->nh.iph->ihl*4;
struct iphdr *iph = (*skb)->nh.iph;
struct tcphdr *th = (struct tcphdr*)((void *)sk->nh.iph + tcphoff);
unsigned short size;
int csum = 0;
if ( iph->daddr == in_aton(REALIP) && iph->protocol == IPPROTO_TCP ) {
printk("test IP packet with packet to %d.%d.%d.%d \n",NIPQUAD(iph->daddr));
iph->daddr = in_aton(FAKEIP);
iph->check = 0;
iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
sk->csum = 0;
th->check = 0;
csum = skb_checksum( sk, tcphoff ,sk->len-tcphoff , 0 );
sk->csum = csum;
th->check = csum_tcpudp_magic(
iph->saddr,
iph->daddr,
sk->len-tcphoff,
iph->protocol,
csum
);
}
sk->ip_summed = CHECKSUM_UNNECESSARY;
return NF_ACCEPT;
}
static unsigned int my_call_in(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 *sk = *skb;
unsigned int tcphoff=sk->nh.iph->ihl*4;
struct iphdr *iph = (*skb)->nh.iph;
struct tcphdr *th = (struct tcphdr*)((void *)sk->nh.iph + tcphoff);
unsigned short size;
int csum = 0;
if ( iph->saddr == in_aton(REALIP) && iph->protocol == IPPROTO_TCP ) {
printk("test IP packet with packet from %d.%d.%d.%d \n",NIPQUAD(iph->saddr));
iph->saddr = in_aton(FAKEIP);
iph->check = 0;
iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
sk->csum = 0;
th->check = 0;
csum = skb_checksum( sk, tcphoff ,sk->len-tcphoff , 0 );
sk->csum = csum;
th->check = csum_tcpudp_magic(
iph->saddr,
iph->daddr,
sk->len-tcphoff,
iph->protocol,
csum
);
}
sk->ip_summed = CHECKSUM_UNNECESSARY;
return NF_ACCEPT;
} |
[ 本帖最后由 lsddx110 于 2007-9-29 19:41 编辑 ] |
|