|
加载的模块代码:
#include <linux/kernel.h>
#include <linux/module.h>
//#include <linux/config.h>
#include <linux/init.h>
#include <linux/netdevice.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/netfilter_ipv4.h>
MODULE_LICENSE("GPL") ;
static unsigned int idrop(unsigned int hooknum,struct sk_buff**skb,const struct net_device*in,const struct net_device*out,int(*okfn)(struct sk_buff*)){
return NF_QUEUE;
}
static struct nf_hook_ops ishnet=
{{NULL,NULL},
idrop,
NULL,
PF_INET,
NF_IP_LOCAL_IN,
NF_IP_PRI_FIRST
};
static int init_net(void){
return nf_register_hook(&ishnet);
}
static void cleanup_net(void){
nf_unregister_hook(&ishnet);
}
module_init(init_net);
module_exit(cleanup_net);
用户空间的数据包回注内核代码:
#include <linux/netfilter.h>
#include <libipq.h>
#include <stdio.h>
#define BUFSIZE 2048
static void die(struct ipq_handle *h)
{
ipq_perror("passer");
ipq_destroy_handle(h);
exit(1);
}
int main(int argc, char **argv)
{
int status;
unsigned char buf[BUFSIZE];
struct ipq_handle *h;
h = ipq_create_handle(0, PF_INET);
if (!h)
die(h);
status = ipq_set_mode(h, IPQ_COPY_PACKET, BUFSIZE);
if (status < 0)
die(h);
do{
status = ipq_read(h, buf, BUFSIZE, 0);
if (status < 0)
die(h);
ipq_packet_msg_t *m = ipq_get_packet(buf);
status = ipq_set_verdict(h, m->packet_id,
NF_ACCEPT, 0, NULL);
} while (1);
ipq_destroy_handle(h);
return 0;
}
加载模块后网页上不了,说明数据包确实被放到用户空间队列去了。
运行用户空间队列程序把数据包回注后仍然上不了网页,不知道这是
什么原因,哪位了解的请指导一下,谢谢! |
|