centos openssl devel7 无法安装 libnetfilter_queue-devel

新手园地& & & 硬件问题Linux系统管理Linux网络问题Linux环境编程Linux桌面系统国产LinuxBSD& & & BSD文档中心AIX& & & 新手入门& & & AIX文档中心& & & 资源下载& & & Power高级应用& & & IBM存储AS400Solaris& & & Solaris文档中心HP-UX& & & HP文档中心SCO UNIX& & & SCO文档中心互操作专区IRIXTru64 UNIXMac OS X门户网站运维集群和高可用服务器应用监控和防护虚拟化技术架构设计行业应用和管理服务器及硬件技术& & & 服务器资源下载云计算& & & 云计算文档中心& & & 云计算业界& & & 云计算资源下载存储备份& & & 存储文档中心& & & 存储业界& & & 存储资源下载& & & Symantec技术交流区安全技术网络技术& & & 网络技术文档中心C/C++& & & GUI编程& & & Functional编程内核源码& & & 内核问题移动开发& & & 移动开发技术资料ShellPerlJava& & & Java文档中心PHP& & & php文档中心Python& & & Python文档中心RubyCPU与编译器嵌入式开发驱动开发Web开发VoIP开发技术MySQL& & & MySQL文档中心SybaseOraclePostgreSQLDB2Informix数据仓库与数据挖掘NoSQL技术IT业界新闻与评论IT职业生涯& & & 猎头招聘IT图书与评论& & & CU技术图书大系& & & Linux书友会二手交易下载共享Linux文档专区IT培训与认证& & & 培训交流& & & 认证培训清茶斋投资理财运动地带快乐数码摄影& & & 摄影器材& & & 摄影比赛专区IT爱车族旅游天下站务交流版主会议室博客SNS站务交流区CU活动专区& & & Power活动专区& & & 拍卖交流区频道交流区
UID空间积分0 积分16阅读权限10帖子精华可用积分16 信誉积分24 专家积分0 在线时间20 小时注册时间最后登录
白手起家, 积分 16, 距离下一级还需 184 积分
帖子主题精华可用积分16 信誉积分24 专家积分0 在线时间20 小时注册时间最后登录
论坛徽章:0
各位大神,我想完成一个HTTP访问控制的功能。所以想利用netfilter拦截HTTP数据包并且返回NF_QUEUE,上层应用利用libnetfilter_queue子系统进行接收处理并返回接受或丢弃。
目前测试的功能如下:
1)netfilter内核模块挂载到POST_ROUTING,检测到目的端口是80或8080后 return NF_QUEUE,否则 return NF_ACCEPT;
2) libnetfilter_queue上层应用接收到拷贝上来的数据包后,对包进行一个计数,并cout&&& This is a HTTP PACKET&&&而后return nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL);
现在的情况是,程序运行起来貌似没问题,打开百度首页都能正常计数输出。但是我打开像新浪这种大的门户网站后因为包的数量特别多,我刷新几次之后电脑就会打印oops之后崩溃。这个问题困扰了好久,还望各位请教。
以下是源码:
(1)netfilter内核模块
#include &linux/kernel.h&
#include &linux/init.h&
#include &linux/module.h&
#include &linux/version.h&
#include &linux/string.h&
#include &linux/kmod.h&
#include &linux/vmalloc.h&
#include &linux/workqueue.h&
#include &linux/spinlock.h&
#include &linux/socket.h&
#include &linux/net.h&
#include &linux/in.h&
#include &linux/skbuff.h&
#include &linux/ip.h&
#include &linux/tcp.h&
#include &linux/netfilter.h&
#include &linux/netfilter_ipv4.h&
#include &net/sock.h&
#include &asm/uaccess.h&
#include &asm/unistd.h&
#include &linux/if_arp.h&
//定义钩子函数结构体
struct nf_hook_ops&&post_& &
//实例化钩子函数
static unsigned int watch_out(unsigned int hooknum,
& && && && && && &struct sk_buff *skb,
& && && && && && &const struct net_device *in,
& && && && && && &const struct net_device *out,
& && && && && && &int (*okfn)(struct sk_buff *))
& &//复制skbuff结构体,将指针指向ip头和tcp头
& &struct sk_buff *
& &struct iphdr *
& &struct tcphdr *
& &sk = skb_copy(skb, 1);
& &iph = ip_hdr(sk);
& &tcph = (void *) iph + iph-&ihl * 4;
& &//判断协议是否为TCP,是则继续判断,否则放行返回NF_ACCEPT
& &if ( iph-&protocol == IPPROTO_TCP)
//判断数据包是否是HTTP数据包,是则将数据包排队NF_QUEUE等待上层空间发回响应策略
& && &&&if(tcph-&dest == htons(8080) || tcph-&dest == htons(80)) //利用端口号区分服务,将FTP,HTTP 数据包上传。
& && && && & return NF_QUEUE;&&
& && &&&else
& && && && & return NF_ACCEPT;
& &}& && && &
& && & return NF_ACCEPT;
int init_module()
& &printk(&------Client_Lite_Kernel Start------\n&);
& &//将钩子函数注册到POST_RPOTING挂载点上,设置优先级最高。
& &post_hook.hook& &&&= watch_
& &post_hook.pf& && & = PF_INET;
& &post_hook.priority = NF_IP_PRI_FIRST;
& &post_hook.hooknum&&= NF_INET_POST_ROUTING;
& &nf_register_hook(&post_hook);
& &return 0;
void cleanup_module()
& &printk(&------Client_Lite_Kernel finish------\n&);
& &//注销钩子函数
& &nf_unregister_hook(&post_hook);
MODULE_INIT(init_module);
MODULE_EXIT(cleanup_module);
MODULE_LICENSE(&GPL&);
MODULE_AUTHOR(&zhaoyun&);
(2)libnetfilter_queue上层用户应用
#include &stdio.h&
#include &stdlib.h&
#include &unistd.h&
#include &netinet/in.h&
#include &linux/netfilter.h&
#include &netinet/ip.h&
#include &netinet/tcp.h&
#include &arpa/inet.h&
#include &libnetfilter_queue/libnetfilter_queue.h&
#include &iostream&
#include &string.h&
#define LENGTH 4096
static int count=0;
static int cb(struct nfq_q_handle *qh, struct nfgenmsg *nfmsg, struct nfq_data *nfa, void *data)
& & int id = 0, pload_
& & unsigned char *
& & struct nfqnl_msg_packet_hdr *
& & //get unique ID of packet in queue
& & ph = nfq_get_msg_packet_hdr(nfa);
& & if(ph)
& && &&&id = ntohl(ph-&packet_id);
& & //get payload
& & pload_len = nfq_get_payload(nfa, &pload);
& & if(pload_len == -1)
& && &&&pload_len = 0;
& & struct iphdr *iph = (struct iphdr *)
& & struct tcphdr *tcph =(struct tcphdr*)((u_int8_t*)iph + (iph-&ihl&&2));
& & if(tcph-&dest == htons(80) || tcph-&dest == htons(8080))
& & & & & & count++;
& && &&&cout&&count&&& This is a HTTP PACKET&&&
& && &&&return nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL);
& && &&&return nfq_set_verdict(qh, id, NF_ACCEPT, 0, NULL);
int main(int argc, const char *argv[])
& & int len,
& & char buf[LENGTH];
& & struct nfq_handle *h;
& & struct nfq_q_handle *
& & //call nfq_open() to open a NFQUEUE handler
& & h = nfq_open();
& & if(!h)
& && &&&fprintf(stderr, &error during nfq_open()\n&);
& && &&&exit(1);
& & //unbinging existing nf_queue handler for PE_INET(if any)
& & if(nfq_unbind_pf(h, PF_INET) & 0)
& && &&&fprintf(stderr, &error during nfq_unbind_pf()\n&);
& && &&&exit(1);
& & //binding nfnetlink_queue as nf_queue handler for PF_INET
& & if(nfq_bind_pf(h, PF_INET) & 0)
& && &&&fprintf(stderr, &error during nfq_bind_pf()\n&);
& && &&&exit(1);
& & //binding this socket to queue '0'
& & qh = nfq_create_queue(h, 0, &cb, NULL);
& & if(!qh)
& && &&&fprintf(stderr,&error during nfq_create_queue()\n&);
& && &&&exit(1);
& & //setting copy_packet mode
& & if(nfq_set_mode(qh, NFQNL_COPY_PACKET, 0xffff) & 0)
& && &&&fprintf(stderr, &can't set packet_copy_mode\n&);
& && &&&exit(1);
& & //get the file descriptor associated with the nfqueue handler
& & fd = nfq_fd(h);
& & //handle a packet received from the nfqueue subsystem
& & while ((len = recv(fd, buf, sizeof(buf), 0)) && len &= 0)
& && &&&nfq_handle_packet(h, buf, len);
& & nfq_destroy_queue(qh);
& & nfq_close(h);
& & return 0;
(3)oops信息
10:15 上传
PS:我在Ubuntu12.04LST(内核3.8.0-39-generic),Ubuntu10.04LTS(内核2.6.32-38-generic),中标麒麟V3(内核2.6.32-220.2.1.2.ky3.2.i686),中标麒麟V5(2.6.27.41-170.2.117_ND5_1.i686)上都测试过此代码,虽然崩溃的时间不相同,但是都会出现崩溃。其中中标麒麟打印的OOPS信息如上,Ubuntu直接卡死没有任何输出。
&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp&&nbsp|&&nbsp
UID空间积分0 积分16阅读权限10帖子精华可用积分16 信誉积分24 专家积分0 在线时间20 小时注册时间最后登录
白手起家, 积分 16, 距离下一级还需 184 积分
帖子主题精华可用积分16 信誉积分24 专家积分0 在线时间20 小时注册时间最后登录
论坛徽章:0
没有人接触过libnetfilter_queue么。
UID空间积分0 积分1152阅读权限30帖子精华可用积分1152 信誉积分758 专家积分0 在线时间414 小时注册时间最后登录
家境小康, 积分 1152, 距离下一级还需 848 积分
帖子主题精华可用积分1152 信誉积分758 专家积分0 在线时间414 小时注册时间最后登录
论坛徽章:0
) 你在代码里边,不加规则试试程序能不能崩溃
然后一点一点加注释,确定崩的地方
UID空间积分0 积分16阅读权限10帖子精华可用积分16 信誉积分24 专家积分0 在线时间20 小时注册时间最后登录
白手起家, 积分 16, 距离下一级还需 184 积分
帖子主题精华可用积分16 信誉积分24 专家积分0 在线时间20 小时注册时间最后登录
论坛徽章:0
kkddkkdd11
通过看oops信息和objdump反编译ko文件,发现是内核模块的问题,错误出在skb_copy上,他有可能拷贝不成功造成sk指针为空,然后就崩溃了。我还是不明百为什么开始能拷贝成功,刷着刷着就不行了。谢谢你的回复,新手小白第一次发帖,十分感动!
To be 千里马!
UID空间积分3 积分2822阅读权限100帖子精华可用积分2822 信誉积分2764 专家积分79 在线时间7864 小时注册时间最后登录
帖子主题精华可用积分2822 信誉积分2764 专家积分79 在线时间7864 小时注册时间最后登录
认证徽章论坛徽章:4
zhaoyun0819
感觉你写 QUEUE 的那个 kernel module 有点多余啊,直接通过 iptables 下一条 NFQUEUE 的规则即可。
用户态调用 libnetfilter_queue 获取报文即可。
如果你要确定 skb_copy 调用是否正确,可以看一下kernel 中对于 NFQUEUE 这个 target 的实现代码就行了。
----------
欢迎光临Godbach的博客:
明犯我强汉天威者,穷搜天下,万里追杀,覆其巢,断其苗裔,戮其身,追其魂,屠其魄,虽远必诛!
To be 千里马!
UID空间积分3 积分2822阅读权限100帖子精华可用积分2822 信誉积分2764 专家积分79 在线时间7864 小时注册时间最后登录
帖子主题精华可用积分2822 信誉积分2764 专家积分79 在线时间7864 小时注册时间最后登录
认证徽章论坛徽章:4
zhaoyun0819
你看的 kernel module 基本上可以通过类似下面一条&&iptables 规则搞定
iptables -t mangle -A POSTROUTING -p tcp -m multiport --dport&&80,8080&&-j NFQUEUE --queue-num 10
然后专注用户态程序即可。
----------
欢迎光临Godbach的博客:
明犯我强汉天威者,穷搜天下,万里追杀,覆其巢,断其苗裔,戮其身,追其魂,屠其魄,虽远必诛!
UID空间积分0 积分22803阅读权限90帖子精华可用积分22803 信誉积分994 专家积分0 在线时间1085 小时注册时间最后登录
巨富豪门, 积分 22803, 距离下一级还需 17197 积分
帖子主题精华可用积分22803 信誉积分994 专家积分0 在线时间1085 小时注册时间最后登录
认证徽章论坛徽章:15
从最后的oops信息看,是在atomic上下文中发生了调度,从哪儿看出是skb指针为空导致的问题呢?
UID空间积分0 积分16阅读权限10帖子精华可用积分16 信誉积分24 专家积分0 在线时间20 小时注册时间最后登录
白手起家, 积分 16, 距离下一级还需 184 积分
帖子主题精华可用积分16 信誉积分24 专家积分0 在线时间20 小时注册时间最后登录
论坛徽章:0
嗯,好像是的,这个内核模块确实可以通过iptables规则来实现。是因为我之后在内核模块还有别的代码实现功能,所以简单测试一下。我把拷贝改成sk = skb_copy(skb, GFP_ATOMIC );之后就没有问题了目前,虽然我也具体不太清楚其中的原理。十分感谢!!
UID空间积分0 积分16阅读权限10帖子精华可用积分16 信誉积分24 专家积分0 在线时间20 小时注册时间最后登录
白手起家, 积分 16, 距离下一级还需 184 积分
帖子主题精华可用积分16 信誉积分24 专家积分0 在线时间20 小时注册时间最后登录
论坛徽章:0
humjb_1983
& & 确实是上下文,我oops没贴全,另外一次实验的时候还有oops信息提示 EIP is at watch_out+0xf/0x88
& & 我用objdump反汇编找到了是在& &iph = ip_hdr(sk);处,所以加了容错,if(sk==NULL){printk(&&0&&&sk pointer is NULL \n&);return NF_ACCEPT;},结果就打印了错误信息,所以发现是sk为空,skb_copy()拷贝没成功。
To be 千里马!
UID空间积分3 积分2822阅读权限100帖子精华可用积分2822 信誉积分2764 专家积分79 在线时间7864 小时注册时间最后登录
帖子主题精华可用积分2822 信誉积分2764 专家积分79 在线时间7864 小时注册时间最后登录
认证徽章论坛徽章:4
zhaoyun0819
你源代码中 skb_copy() 中第二个参数是 1,GFP_ATOMIC 的值也应该就是 1 啊。
在中断上下文,申请内存的话,是应该用 GFP_ATOMIC。
----------
欢迎光临Godbach的博客:
明犯我强汉天威者,穷搜天下,万里追杀,覆其巢,断其苗裔,戮其身,追其魂,屠其魄,虽远必诛!
北京皓辰网域网络信息技术有限公司. 版权所有 京ICP证:060528号 北京市公安局海淀分局网监中心备案编号:
广播电视节目制作经营许可证(京) 字第1234号
中国互联网协会会员&&联系我们:
感谢所有关心和支持过ChinaUnix的朋友们
转载本站内容请注明原作者名及出处1660人阅读
偶尔在网上看到了这篇文章,
并结合中的例子,
然后修改了一下tcp计算checksum部分,在linux2.6.24上用netfilter_queue在用户态实现NAT
程序功能: 将输出端目的地为 220.181.37.55 的包,都改为目的地为 202.118.236.130,输入段反之,达到DNAT的一小半功能,完整的NAT要做状态记录的.
直接上代码:
nf_queue_test.c
&* =====================================================================================
&* Filename: nf_queue_test.c
&* Description: 用netfilter_queue 在用户态修改网络数据包的例子程序
&* Version: 1.0
&* Created: 04/02/:48 AM
&* Revision: none
&* Compiler: gcc
&* Author: LeiuX (xulei), xulei@pact518.
&* Company: HIT
&* =====================================================================================
#include&&stdio.h&
#include&&stdlib.h&
#include&&unistd.h&
#include&&netdb.h&
#include&&string.h&
#include&&netinet/in.h&
#include&&arpa/inet.h&
#include&&asm/byteorder.h&
#include&&linux/netfilter.h&
#include&&libnetfilter_queue/libnetfilter_queue.h&
#include&&linux/ip.h&
#include&&linux/tcp.h&
#ifdef&__LITTLE_ENDIAN
#define&IPQUAD(addr)&\
((unsigned&char&*)&addr)[0],&\
((unsigned&char&*)&addr)[1],&\
((unsigned&char&*)&addr)[2],&\
((unsigned&char&*)&addr)[3]
#define&IPQUAD(addr)&\
((unsigned&char&*)&addr)[3],&\
((unsigned&char&*)&addr)[2],&\
((unsigned&char&*)&addr)[1],&\
((unsigned&char&*)&addr)[0]
struct&tcp_pseudo&/*the tcp pseudo header*/
&&__u32 src_addr;
&&__u32 dst_addr;
&&__u8 zero;
&&__u8 proto;
&&__u16 length;
}&pseudohead;
long&checksum(unsigned&short&*addr,&unsigned&int&count)&{
&&/* Compute Internet Checksum for &count& bytes
&&&* beginning at location &addr&.
&&register&long&sum&=&0;
&&while(&count&&&1&)&{
&&&&/* This is the inner loop */
&&&&sum&+=&*&addr++;
&&&&count&-=&2;
&&/* Add left-over byte, if any */
&&if(&count&&&0&)
&&&&sum&+=&*&(unsigned&char&*)&addr;
&&/* Fold 32-bit sum to 16 bits */
&&while&(sum&&16)
&&&&sum&=&(sum&&&0xffff)&+&(sum&&&&16);
&&return&~sum;
/*************************tcp checksum**********************/
long&get_tcp_checksum(struct&iphdr&*&myip,&struct&tcphdr&*&mytcp)&{
&&__u16 total_len&=&ntohs(myip-&tot_len);
&&int&tcpopt_len&=&mytcp-&doff*4&-&20;
&&int&tcpdatalen&=&total_len&-&(mytcp-&doff*4)&-&(myip-&ihl*4);
&&pseudohead.src_addr=myip-&saddr;
&&pseudohead.dst_addr=myip-&daddr;
&&pseudohead.zero=0;
&&pseudohead.proto=IPPROTO_TCP;
&&pseudohead.length=htons(sizeof(struct&tcphdr)&+&tcpopt_len&+&tcpdatalen);
&&int&totaltcp_len&=&sizeof(struct&tcp_pseudo)&+&sizeof(struct&tcphdr)&+&tcpopt_len&+tcpdatalen;
&&//unsigned short * tcp = new unsigned short[totaltcp_len];
&&unsigned&short&*&tcp&=&malloc(totaltcp_len);
&&memcpy((unsigned&char&*)tcp,&pseudohead,sizeof(struct&tcp_pseudo));
&&memcpy((unsigned&char&*)tcp+sizeof(struct&tcp_pseudo),(unsigned&char*)mytcp,sizeof(struct&tcphdr));
&&memcpy((unsigned&char&*)tcp+sizeof(struct&tcp_pseudo)+sizeof(struct&tcphdr),(unsigned&char&*)myip+(myip-&ihl*4)+(sizeof(struct&tcphdr)),&tcpopt_len);
&&memcpy((unsigned&char&*)tcp+sizeof(struct&tcp_pseudo)+sizeof(structtcphdr)+tcpopt_len,&(unsigned&char&*)mytcp+(mytcp-&doff*4),&tcpdatalen);
&&/* printf(&pseud length: %d\n&,pseudohead.length);
&&&&&&&&&&printf(&tcp hdr length: %d\n&,mytcp-&doff*4);
&&&&&&&&&&printf(&tcp hdr struct length: %d\n&,sizeof(struct tcphdr));
&&&&&&&&&&printf(&tcp opt length: %d\n&,tcpopt_len);
&&&&&&&&&&printf(&tcp total+psuedo length: %d\n&,totaltcp_len);
&&&&&&&&&&fflush(stdout);
&&&&&&&&&&printf(&tcp data len: %d, data start %u\n&, tcpdatalen,mytcp + (mytcp-&doff*4));
&&return&checksum(tcp,totaltcp_len);
static&u_int16_t tcp_checksum(struct&iphdr*&iphdrp){
&&struct&tcphdr&*tcphdrp&=
&&&&(struct&tcphdr*)((u_int8_t*)iphdrp&+&(iphdrp-&ihl&&2));
&&return&get_tcp_checksum(iphdrp,&tcphdrp);
static&void&set_tcp_checksum(struct&iphdr*&iphdrp){
&&struct&tcphdr&*tcphdrp&=
&&&&(struct&tcphdr*)((u_int8_t*)iphdrp&+&(iphdrp-&ihl&&2));
&&tcphdrp-&check&=&0;
&&tcphdrp-&check&=&get_tcp_checksum(iphdrp,&tcphdrp);
/****************************tcp checksum end****************************/
/********************************Ip checksum*****************************/
static&u_int16_t ip_checksum(struct&iphdr*&iphdrp){
&&return&checksum((unsigned&short*)iphdrp,&iphdrp-&ihl&&2);
static&void&set_ip_checksum(struct&iphdr*&iphdrp){
&&iphdrp-&check&=&0;
&&iphdrp-&check&=&checksum((unsigned&short*)iphdrp,&iphdrp-&ihl&&2);
/****************************Ip checksum end******************************/
static&int&cb(struct&nfq_q_handle&*qh,&struct&nfgenmsg&*nfmsg,
&&&&struct&nfq_data&*nfa,&void&*data){
&&(void)nfmsg;
&&(void)data;
&&u_int32_t id&=&0;
&&struct&nfqnl_msg_packet_hdr&*ph;
&&unsigned&char&*pdata&=&NULL;
&&int&pdata_len;
&&ph&=&nfq_get_msg_packet_hdr(nfa);
&&if&(ph){
&&&&id&=&ntohl(ph-&packet_id);
&&pdata_len&=&nfq_get_payload(nfa,&(char**)&pdata);
&&if(pdata_len&==&-1){
&&&&pdata_len&=&0;
&&struct&iphdr&*iphdrp&=&(struct&iphdr&*)pdata;
&&printf(&len %d iphdr %d
%u.%u.%u.%u -&&,
&&&&&&pdata_len,
&&&&&&iphdrp-&ihl&&2,
&&&&&&IPQUAD(iphdrp-&saddr));
&&printf(& %u.%u.%u.%u %s&,
&&&&&&IPQUAD(iphdrp-&daddr),
&&&&&&getprotobynumber(iphdrp-&protocol)-&p_name);
&&printf(& ipsum %hu&,&ip_checksum(iphdrp));
&&if(iphdrp-&protocol&==&IPPROTO_TCP){
&&&&printf(& tcpsum %hu&,&tcp_checksum(iphdrp));
#define&TO&&220.181.37.55&
#define&DNAT_TO&&202.118.236.130&
&&if(iphdrp-&daddr&==&inet_addr(TO)){
&&&&printf(& !hacked!&);
&&&&iphdrp-&daddr&=&inet_addr(DNAT_TO);
&&&&set_ip_checksum(iphdrp);
&&&&if(iphdrp-&protocol&==&IPPROTO_TCP){
&&&&&&set_tcp_checksum(iphdrp);
&&&&&&printf(& ipsum+ %hu
tcpsum+ %hu&,
&&&&&&&&&&ip_checksum(iphdrp),&tcp_checksum(iphdrp));
&&if(iphdrp-&saddr&==&inet_addr(DNAT_TO)){
&&&&iphdrp-&saddr&=&inet_addr(TO);
&&&&printf(& !hacked!&);
&&&&set_ip_checksum(iphdrp);
&&&&if(iphdrp-&protocol&==&IPPROTO_TCP){
&&&&&&set_tcp_checksum(iphdrp);
&&&&&&printf(& ipsum+ %hu
tcpsum+ %hu&,
&&&&&&&&&&ip_checksum(iphdrp),&tcp_checksum(iphdrp));
&&printf(&\n&);
&&return&nfq_set_verdict_mark(qh,&id,&NF_REPEAT,&1,
&&&&&&(u_int32_t)pdata_len,&pdata);
int&main(int&argc,&char&**argv)
&&struct&nfq_handle&*h;
&&struct&nfq_q_handle&*qh;
&&struct&nfnl_handle&*nh;
&&char&buf[4096];
&&h&=&nfq_open();
&&if&(!h)&{
&&&&exit(1);
&&nfq_unbind_pf(h,&AF_INET);
&&/*2.6.24 的内核有BUG, nfq_unbind_pf 返回值不正确,
&&&&见:http://article.gmane.org/gmane.c ... ilter.general/33573*/
&&&&&if (nfq_unbind_pf(h, AF_INET) & 0){
&&&&&exit(1);
&&if&(nfq_bind_pf(h,&AF_INET)&&&0)&{
&&&&exit(1);
&&int&qid&=&0;
&&if(argc&==&2){
&&&&qid&=&atoi(argv[1]);
&&printf(&binding this socket
to queue %d\n&,&qid);
&&qh&=&nfq_create_queue(h,&qid,&&cb,&NULL);
&&if&(!qh)&{
&&&&exit(1);
&&if&(nfq_set_mode(qh,&NFQNL_COPY_PACKET,&0xffff)&&&0)&{
&&&&exit(1);
&&nh&=&nfq_nfnlh(h);
&&fd&=&nfnl_fd(nh);
&&while&((rv&=&recv(fd,&buf,&sizeof(buf),&0))&&&&rv&&=&0)&{
&&&&nfq_handle_packet(h,&buf,&rv);
&&/* never reached */
&&nfq_destroy_queue(qh);
&&nfq_close(h);
&&exit(0);
CFLAGS=-g&-Wall
nf_queue_test&:&nf_queue_test.c
&&&&gcc $(CFLAGS)&-lnetfilter_queue
&&&&rm&-f nf_queue_test
#!/bin/bash
#===============================================================================
#&FILE:&load.sh
#&USAGE:&./load.sh&
#&DESCRIPTION:&
#&OPTIONS:&---
#&REQUIREMENTS:&---
#&BUGS:&---
#&NOTES:&---
#&AUTHOR:&LeiuX&(),&marksman.xu@gmail.com
#&COMPANY:&HIT
#&VERSION:&1.0
#&CREATED:&04/02/2010
09:51:36 AM CST
#&REVISION:&---
#===============================================================================
TABLE=mangle
function remove_chain(){
echo&-n removing chain...
&&sudo&/sbin/iptables&-t
${TABLE}&-D PREROUTING&-j
NF_QUEUE_CHAIN
&&sudo&/sbin/iptables&-t
${TABLE}&-D OUTPUT&-j
NF_QUEUE_CHAIN
&&sudo&/sbin/iptables&-t
${TABLE}&-F NF_QUEUE_CHAIN
&&sudo&/sbin/iptables&-t
${TABLE}&-X NF_QUEUE_CHAIN
}&&&/dev/null
function create_chain(){
echo&-n creating chain...
sudo&/sbin/iptables&-t
${TABLE}&-N NF_QUEUE_CHAIN
sudo&/sbin/iptables&-t
${TABLE}&-A NF_QUEUE_CHAIN&-m
mark&--mark 0&-j NFQUEUE--queue-num
sudo&/sbin/iptables&-t
${TABLE}&-A NF_QUEUE_CHAIN&-j
MARK&--set-mark
sudo&/sbin/iptables&-t
${TABLE}&-I OUTPUT&-j
NF_QUEUE_CHAIN
sudo&/sbin/iptables&-t
${TABLE}&-I PREROUTING&-j
NF_QUEUE_CHAIN
function on_iqh(){
remove_chain
trap on_iqh&INT&QUIT HUP
remove_chain
create_chain
sudo&./nf_queue_test 8010
remove_chain
运行loader.sh就好了,如果你没有sudo,那就改改脚本自己用root运行吧
要看效果,就ping 220.181.37.55,然后连 220.181.37.55 的80端口试试,并且注意程序的输出.
PS: 220.181.37.55 是 baidu 的一个服务器的IP, 另外一个IP是 pact lab 的.
reference:
&&tcp/ip详解卷一:协议&&
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:265289次
积分:4524
积分:4524
排名:第3054名
原创:168篇
转载:85篇
评论:60条
(4)(1)(1)(1)(1)(1)(2)(2)(3)(1)(1)(8)(11)(4)(5)(1)(6)(5)(3)(5)(29)(4)(7)(1)(5)(12)(14)(1)(13)(9)(3)(1)(5)(1)(1)(2)(3)(4)(2)(3)(7)(14)(21)(10)(4)(4)(7)

我要回帖

更多关于 centos kernel devel 的文章

 

随机推荐