Chinaunix

标题: 发布一个速度匹配的内核模块(hashspeed) [打印本页]

作者: springwind426    时间: 2008-01-02 12:04
标题: 发布一个速度匹配的内核模块(hashspeed)
本模块是在hashlimit基础上修改的,除了可以进行包的匹配以外,还可以进行字节的匹配,可以达到针对IP来进行限速和限制包的发送速度。

hashspeed-0.1.tar.gz (11.47 KB, 下载次数: 640)

2008.10.12 更新源代码,添加了对高版本kernel和iptables的支持,目前能够在linux-2.6.25 linux-2.6.26和iptables-1.4.1正常编译(gcc-4.1和gcc-4.3)

更多信息可以查看压缩包中的README.zh_CN-utf8(中文UTF-8编码)

我是在2.6.22 和 2.6.23内核上编译通过的,iptables-1.3.8, gcc-4,1

如果是更旧的内核,可能会没有linux/mutex.h

如果没有x_table.h,那么可以把ipt_hashspeed.c中的
#include <linux/netfilter/x_tables.h>
去掉,不会有任何影响

如果没有mutex.h,就得自己想办法了。(主要是用到mutex_lock这个函数)
在一些老的内核版本中,有 fs/xfs/linux-2.6/mutex.h这个头文件,有能力的兄弟可以自己参考参考,做一些修改


因为对linux编程不是很熟悉,这个只是在hashlimit模块的基础上,按照需要进行了适当的修改(而hashlimit模块是在比较新的内核中才出现的),因此,对于那些遇到编译问题的,本人无法做出一一解答。

不过,我会针对大家提供的一些编译错误,在源代码上做一些修改,并投放在我的网站上,因此,直接从我的网站上下载的源码包可能与这儿的附件有些微差别。

如果哪位兄弟在自己的实际环境中,成功编译并运行(通过修改源代码),请张贴您的修改和编译环境。


linux不同版本的内核,结构定义不一样,这个真是烦人,要想让它能够在不同版本的内核下都能够编译成功,真不是一件容易的事,只能一点点完善了。

我会不断地更新我的网站上的文件,也许,你下载到最新的源代码,就有可能解决以前不能成功编译的问题了。

[ 本帖最后由 springwind426 于 2008-10-12 10:14 编辑 ]
作者: 5iwww    时间: 2008-01-02 14:18
wow~~~~~~~~~~测试下,精确吗?同时支持 -m mac --mac-source吗?
作者: springwind426    时间: 2008-01-02 14:34
这只是一个匹配模块,因此,是可以与其他模块一起使用的

我自己测试的精确度还行

比如:
iptables -A FORWARD -i eth1 -p tcp -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode srcip --hashspeed-name slimit -j DROP

可以将eth1连接的内网的所有主机的TCP上传速度限制在256K/S


iptables -A FORWARD -o eth1 -p tcp -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP
可以将eth1连接的内网的所有主机的TCP下载速度限制在256K/S
作者: seacon    时间: 2008-01-02 17:20
iptables 1.3.5 内核2.6.19.7 编译不过去
作者: seacon    时间: 2008-01-02 17:21
[root@proxy hashspeed-0.1]# make
make -C /lib/modules/2.6.9-Custom/build M=/root/hashspeed-0.1 modules
make[1]: Entering directory `/usr/src/linux-2.6.9'
  CC [M]  /root/hashspeed-0.1/ipt_hashspeed.o
/root/hashspeed-0.1/ipt_hashspeed.c:27:38: linux/netfilter/x_tables.h: No such file or directory
/root/hashspeed-0.1/ipt_hashspeed.c:107: error: syntax error before "__read_mostly"
/root/hashspeed-0.1/ipt_hashspeed.c:107: warning: type defaults to `int' in declaration of `__read_mostly'
/root/hashspeed-0.1/ipt_hashspeed.c:107: warning: data definition has no type or storage class
/root/hashspeed-0.1/ipt_hashspeed.c: In function `dsthash_alloc_init':
/root/hashspeed-0.1/ipt_hashspeed.c:158: error: `hashspeed_cachep' undeclared (first use in this function)
/root/hashspeed-0.1/ipt_hashspeed.c:158: error: (Each undeclared identifier is reported only once
/root/hashspeed-0.1/ipt_hashspeed.c:158: error: for each function it appears in.)
/root/hashspeed-0.1/ipt_hashspeed.c: In function `dsthash_free':
/root/hashspeed-0.1/ipt_hashspeed.c:176: error: `hashspeed_cachep' undeclared (first use in this function)
/root/hashspeed-0.1/ipt_hashspeed.c: In function `htable_create':
/root/hashspeed-0.1/ipt_hashspeed.c:243: warning: assignment discards qualifiers from pointer target type
/root/hashspeed-0.1/ipt_hashspeed.c:259: warning: implicit declaration of function `setup_timer'
/root/hashspeed-0.1/ipt_hashspeed.c: In function `hashspeed_checkentry':
/root/hashspeed-0.1/ipt_hashspeed.c:542: error: `match' undeclared (first use in this function)
/root/hashspeed-0.1/ipt_hashspeed.c: At top level:
/root/hashspeed-0.1/ipt_hashspeed.c:555: warning: "struct xt_match" declared inside parameter list
/root/hashspeed-0.1/ipt_hashspeed.c:555: warning: its scope is only this definition or declaration, which is probably not what you want
/root/hashspeed-0.1/ipt_hashspeed.c:606: warning: initialization from incompatible pointer type
/root/hashspeed-0.1/ipt_hashspeed.c: In function `ipt_hashspeed_init':
/root/hashspeed-0.1/ipt_hashspeed.c:728: warning: implicit declaration of function `ipt_register_matches'
/root/hashspeed-0.1/ipt_hashspeed.c:734: error: `hashspeed_cachep' undeclared (first use in this function)
/root/hashspeed-0.1/ipt_hashspeed.c:754: warning: implicit declaration of function `xt_unregister_matches'
/root/hashspeed-0.1/ipt_hashspeed.c: In function `ipt_hashspeed_fini':
/root/hashspeed-0.1/ipt_hashspeed.c:763: error: `hashspeed_cachep' undeclared (first use in this function)
/root/hashspeed-0.1/ipt_hashspeed.c:767: warning: implicit declaration of function `ipt_unregister_matches'
make[2]: *** [/root/hashspeed-0.1/ipt_hashspeed.o] Error 1
make[1]: *** [_module_/root/hashspeed-0.1] Error 2
make[1]: Leaving directory `/usr/src/linux-2.6.9'
make: *** [ipt_hashspeed.ko] Error 2
作者: 5iwww    时间: 2008-01-02 17:21
原帖由 springwind426 于 2008-1-2 14:34 发表
这只是一个匹配模块,因此,是可以与其他模块一起使用的

我自己测试的精确度还行

比如:
iptables -A FORWARD -i eth1 -p tcp -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode srcip --hashsp ...



请问限速是 per ip的 还是per net的?
作者: 5iwww    时间: 2008-01-02 17:50
我也是这个错误

[root@wj hashspeed-0.1]# make
Makefile:23: You need to install iptables sources and maybe set IPTABLES_SRC
make -C /lib/modules/2.6.9-5.EL/build M=/tmp/hashspeed-0.1 modules
make[1]: Entering directory `/usr/src/kernels/2.6.9-5.EL-i686'
  CC [M]  /tmp/hashspeed-0.1/ipt_hashspeed.o
/tmp/hashspeed-0.1/ipt_hashspeed.c:27:38: linux/netfilter/x_tables.h: No such file or directory
/tmp/hashspeed-0.1/ipt_hashspeed.c:29:25: linux/mutex.h: No such file or directory

是不是路径的问题?  要在源码路径下编译吗?
作者: springwind426    时间: 2008-01-02 18:40
原帖由 5iwww 于 2008-1-2 17:21 发表



请问限速是 per ip的 还是per net的?



是per ip
作者: 5639863    时间: 2008-01-02 19:08
需要编绎内核不?我是MAKE成功了,但再现iptables: Unknown error 4294967295
作者: mack2050    时间: 2008-01-02 19:46
不知道可不可以和IPRANGE一起匹配使用,我试试先!

iptables -I FORWARD 18 -m iprange --src-range 192.168.1.12-192.168.80 -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP

我的编译成功了,但是运行上面这一句提示:iptables: No chain/target/match by that name
可是用iptables -m hashspeed --help 显示
hashspeed v1.3.8 options:
required parameter: <hashspeed-name>  <hashspeed-mode>  <hashspeed-bytes|hashspeed-packets>
only one revert parameter is accepted, meaning ! hashspeed-bytes or ! hashspeed-packets or ! <hashspeed-bytes || hashspeed-packets>
[--hashspeed-bytes <avg>]       Bytes per second unless followed by K M postfixes
[--hashspeed-bytes-burst <num>] max bytes a burst, default avg*0.1
[--hashspeed-packets <num>]             [Packets per second]
[--hashspeed-packets-burst <num>]       max packets a burst, default 5
--hashspeed-mode <mode>         mode is a comma-separated list of
                                        dstip,srcip
--hashspeed-name <name>         name for /proc/net/ipt_hashspeed/
[--hashspeed-htable-size <num>] number of hashtable buckets
[--hashspeed-htable-max <num>]  number of hashtable entries
[--hashspeed-htable-gcinterval] interval between garbage collection runs
[--hashspeed-htable-expire]     after which time are idle entries expired?
这应该是正常安装上去了呀!
下面是安装记录
[root@mack2050 hashspeed-0.1]# make
make -C /lib/modules/2.6.22.8/build M=/root/hashspeed-0.1 modules
make[1]: Entering directory `/usr/src/linux-2.6.22.8'
  CC [M]  /root/hashspeed-0.1/ipt_hashspeed.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /root/hashspeed-0.1/ipt_hashspeed.mod.o
  LD [M]  /root/hashspeed-0.1/ipt_hashspeed.ko
make[1]: Leaving directory `/usr/src/linux-2.6.22.8'
cc -O2 -Wall -DIPTABLES_VERSION=\"1.3.8\" -I/usr/src/iptables-1.3.8/include -fPIC -c libipt_hashspeed.c
cc -shared -o libipt_hashspeed.so libipt_hashspeed.o
[root@mack2050 hashspeed-0.1]# make install
cp ipt_hashspeed.ko /lib/modules/2.6.22.8/kernel/net/ipv4/netfilter/
cp libipt_hashspeed.so /lib/iptables/

请大家指点,谢谢!

[ 本帖最后由 mack2050 于 2008-1-2 20:01 编辑 ]
作者: wysilly    时间: 2008-01-02 19:56
太棒了.

希望这种帖子越来越多.
作者: springwind426    时间: 2008-01-02 20:02
原帖由 mack2050 于 2008-1-2 19:46 发表
不知道可不可以和IPRANGE一起匹配使用,我试试先!

iptables -I FORWARD 18 -m iprange --src-range 192.168.1.12-192.168.80 -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode dstip --hashspeed-na ...



你需要运行
depmod -a
否则,不会自动加载相应的内核模块
作者: mack2050    时间: 2008-01-02 20:04
谢谢,楼主,我马上试试!
作者: mack2050    时间: 2008-01-02 20:07
确实可以了,不过因为我是远程做的,所以现在还不能测试是否能达到效果,有了结果我会马上回贴的!
对了,请楼主解释一下depmod -a的意义所在?还有如果象我这样针对一段IP来做的话,如果这一段的IP当中有某一个人的流量很大的话,虽然限制了是不是还是会影响到他人,这个模块是否会有象TC一样轮询的机制,来保证其它人不受影响?
作者: springwind426    时间: 2008-01-02 20:19
原帖由 mack2050 于 2008-1-2 20:07 发表
确实可以了,不过因为我是远程做的,所以现在还不能测试是否能达到效果,有了结果我会马上回贴的!
对了,请楼主解释一下depmod -a的意义所在?还有如果象我这样针对一段IP来做的话,如果这一段的IP当中有某一个人的流 ...



就是修正各个内核模块之间的依赖关系,并生成相应的信息文件,这样,用modprobe进行加载的时候,就可以自动加载指定的模块,同时加载它依赖的所有模块。

这个只是匹配模块,没有更多的处理,更没有轮询的机制(在readme中说明得很清楚)

如果你的带宽不大,但是给每个IP设置的带宽很大(IP数*每IP带宽>总带宽)的话,就有可能出现抢占现象。


我自己监测到的也有这种情况,当网络空闲的时候,会有一些IP达到设定的带宽,而被阻止,但是当网络繁忙的时候,大部分IP都达不到设定的带宽(但是,鲜有IP会超过设定的带宽)

根据匹配原理,带宽限制不是绝对精确的,有一个浮动范围,我监测到的基本上保持在10%的范围以内。
作者: springwind426    时间: 2008-01-02 20:28
http://springwind.bhu.edu.cn:60000/hashspeed/showspeed.cgi

是一个perl写的cgi程序,可以通过它在浏览器中查看当前各个IP的数据带宽和数据包的速率(取样间隔0.5秒)

这个需要web服务器支持cgi

至于如何让这个程序正常运行,需要根据具体的web服务器来进行设定
作者: mack2050    时间: 2008-01-02 21:02
您说的这个意思是指对每一个IP限制的带宽,而不是一批IP共享这个带宽是吗?按这样理解的话,就是前面我的那个语句指的是从12-80的这些IP,每个的最高上限为200K,任一个超过了就会阻止是吗?

还有您最后这个程序具体是怎么使用的呀?
作者: springwind426    时间: 2008-01-02 22:28
原帖由 mack2050 于 2008-1-2 21:02 发表
您说的这个意思是指对每一个IP限制的带宽,而不是一批IP共享这个带宽是吗?按这样理解的话,就是前面我的那个语句指的是从12-80的这些IP,每个的最高上限为200K,任一个超过了就会阻止是吗?

还有您最后这个程序具 ...



本来就是针对每个IP的
作者: mack2050    时间: 2008-01-02 22:33
iptables -I FORWARD 18 -m iprange --src-range 192.168.1.12-192.168.80 -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP


我这句是想限制下载速度的,那么IPRANGE 应该是用--dst-range才对吧?
作者: springwind426    时间: 2008-01-02 22:41
如果想限制下载速度,你需要控制的是内网接口上的发包,mode为dstip

iptables -I FORWARD 18 -o eth1 -m iprange --dst-range 192.168.1.12-192.168.80 -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP

至于iprange的具体用法,我不太清楚

如果想控制上传速度,需要控制在内网接口上的受包,同时,需要把mode修改为srcip
作者: platinum    时间: 2008-01-03 01:47
这样的限速仅仅是通过丢包实现的,如果能结合 tc 实现针对 per IP 进行流量整形就好了
我也在考虑这个问题,但目前还没有什么好的想法
初步想法是修改 tc 的内核代码,通过 hash 实现对 per IP 的控制
作者: mack2050    时间: 2008-01-03 09:16
标题: 测试没有成功
我用了这句-A FORWARD -o eth1 -m iprange --dst-range 192.168.1.12-192.168.80.0 -m hashspeed  ! --hashspeed-bytes 60K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP
可是在长沙电信上测试下载还是有800K的流量呀?另ETH1是连接外网的接口,这个没错吧?后来把ETH1改成ETH0内网的接口,结果整个内网都上不了网了,删了这句还是不行,REBOOT一次才正常!!!
下面是我的配置
# Generated by iptables-save v1.3.8 on Thu Jan  3 09:13:32 2008
*filter
:INPUT DROP [55960:3875019]
:FORWARD DROP [68908:3919599]
:OUTPUT ACCEPT [21416:10431208]
-A INPUT -i eth0 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 22,23,6160 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m multiport --dports 20,21 -j ACCEPT
-A FORWARD -p tcp -m multiport --dports 135,137,138,139,445 -j DROP
-A FORWARD -p udp -m multiport --dports 135,137,138,139,445 -j DROP
-A FORWARD -m iprange --src-range 192.168.1.81-192.168.1.90 -j ACCEPT
-A FORWARD -m iprange --dst-range 192.168.1.81-192.168.1.90 -j ACCEPT
-A FORWARD -m iprange --src-range 192.168.1.15-192.168.1.16 -j ACCEPT
-A FORWARD -m iprange --dst-range 192.168.1.15-192.168.1.16 -j ACCEPT
-A FORWARD -s 192.168.1.109 -p tcp -m tcp --dport 7001 -j ACCEPT
-A FORWARD -s 192.168.1.109 -p tcp -m tcp --dport 98 -j ACCEPT
-A FORWARD -m mac --mac-source 00:E0:4C:39:04:4E -m time --timestart 02:01 --timestop 19:58 -j DROP
-A FORWARD -m mac --mac-source 00:E0:4C:39:04:4E -m time --timestart 19:59 --timestop 02:00 -j ACCEPT
-A FORWARD -m mac --mac-source 00:C0:26:AC:CD:A6 -m time --timestart 19:59 --timestop 02:00 -j ACCEPT
-A FORWARD -m mac --mac-source 00:E0:4C:4A:80:F1 -m time --timestart 19:59 --timestop 02:00 -j ACCEPT
-A FORWARD -s 192.168.1.0/255.255.255.0 -m time --timestart 20:00 --timestop 08:20 -j DROP
-A FORWARD -p icmp -m icmp --icmp-type any -j ACCEPT
-A FORWARD -m ipp2p --ipp2p -j DROP
-A FORWARD -m ipp2p --xunlei -j DROP
-A FORWARD -p udp -m udp --dport 15000 -j DROP
-A FORWARD -o eth1 -m iprange --dst-range 192.168.1.12-192.168.80.0 -m hashspeed  ! --hashspeed-bytes 60K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP
-A FORWARD -p tcp -m multiport --dports 53,21,80,443,444,194,119,110,25,161,22,23,91,6911,3004 -j ACCEPT
-A FORWARD -p udp -m multiport --dports 53,123,8000 -j ACCEPT
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -p tcp -m multiport --sports 23,443,444 -j ACCEPT
COMMIT
# Completed on Thu Jan  3 09:13:32 2008
# Generated by iptables-save v1.3.8 on Thu Jan  3 09:13:32 2008
*nat
REROUTING ACCEPT [412791:24627481]
OSTROUTING ACCEPT [148:7462]
:OUTPUT ACCEPT [1211:59074]
-A PREROUTING -i ppp0 -p udp -m udp --dport 7324 -j DNAT --to-destination 192.168.1.86:7324
-A PREROUTING -i ppp0 -p tcp -m tcp --dport 7324 -j DNAT --to-destination 192.168.1.86:7324
-A PREROUTING -i ppp0 -p udp -m udp --dport 14672 -j DNAT --to-destination 192.168.1.86:14672
-A PREROUTING -i ppp0 -p tcp -m tcp --dport 14662 -j DNAT --to-destination 192.168.1.86:14662
-A PREROUTING -i ppp0 -p tcp -m tcp --dport 8015 -j DNAT --to-destination 192.168.1.15:80
-A PREROUTING -i ppp0 -p tcp -m tcp --dport 3000 -j DNAT --to-destination 192.168.1.15:3000
-A PREROUTING -i ppp0 -p tcp -m tcp --dport 3001 -j DNAT --to-destination 192.168.1.15:3001
-A PREROUTING -i ppp0 -p tcp -m tcp --dport 8016 -j DNAT --to-destination 192.168.1.16:80
-A PREROUTING -i ppp0 -p tcp -m tcp --dport 3003 -j DNAT --to-destination 192.168.1.16:3003
-A PREROUTING -i ppp0 -p tcp -m tcp --dport 3002 -j DNAT --to-destination 192.168.1.16:3002
-A PREROUTING -i ppp0 -p tcp -m tcp --dport 8888 -j DNAT --to-destination 192.168.1.86:3389
-A POSTROUTING -o ppp0 -j MASQUERADE
COMMIT
# Completed on Thu Jan  3 09:13:32 2008
我测试的IP是22,我侍会儿再试试不带IPRANGE 匹配看能不能成功!

[ 本帖最后由 mack2050 于 2008-1-3 09:33 编辑 ]
作者: fuleru    时间: 2008-01-03 09:38
看样子不错,留名有时间再测试,哈哈!
作者: springwind426    时间: 2008-01-03 10:43
-A FORWARD -o eth1 -m iprange --dst-range 192.168.1.12-192.168.80.0 -m hashspeed  ! --hashspeed-bytes 60K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP

这句明显有问题

看你的样子,似乎是用的adsl(我看到ppp0),而你的内网接口是eth0

因此,只有-o eth0 的时候,-m iprange --dst-range 192.168.1.12-192.168.80.0 才能匹配到
不知道你的shell是什么,在我的shell下执行的时候,需要用 \!  而不是 !

注:
需要严格控制好 网络接口 和 srcip  dstip  的对应关系

你想要控制内网,因此必须在内网接口上做控制
-o 内网接口  的时候,内网地址都是数据包中的  目的地址  ,因此应该是dst
-i 内网接口 的时候,内网地址都是数据包中的  源地址, 因此都应该是src
作者: springwind426    时间: 2008-01-03 10:49
原帖由 platinum 于 2008-1-3 01:47 发表
这样的限速仅仅是通过丢包实现的,如果能结合 tc 实现针对 per IP 进行流量整形就好了
我也在考虑这个问题,但目前还没有什么好的想法
初步想法是修改 tc 的内核代码,通过 hash 实现对 per IP 的控制


是的,就是通过丢弃不匹配的包来实现的

TC的控制方法很多,这个模块的作用原理是TBF(应该是一种最简单的控制方式),如果TC能够很容易做到Per IP的话,也许早就写出来了。

通过我自己的测试,感觉基本上能够达到我的控制目的,就是限制包发送的速度和带宽占用

基本上能够控制在10%以内。
作者: platinum    时间: 2008-01-03 11:14
springwind426 兄这个模块是你自己改的吧?是根据哪个内核版本的 hashlimit 改的?
我对比了一下 2.6.21 的,发现不是 ipt_hashlimit 而是 xt_hashlimit,里面也有很多结构都不一样了
我相对比一下改之前和之后的情况,看看究竟动了哪里
作者: springwind426    时间: 2008-01-03 11:42
对,就是用hashlimit修改的
作者: mack2050    时间: 2008-01-03 12:36
标题: 回复 #24 springwind426 的帖子
我的线路是电信的以太网接入,不用ADSL设备,但是要进行虚拟拨号才可以,所以确实用到了PPP0

-A FORWARD -o eth0 -m iprange --dst-range 192.168.1.12-192.168.80.0 -m hashspeed  /! --hashspeed-bytes 60K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP

我现在是想控制内网的下载速度,限制每个IP的最高速率为60K,但是一运行这条命令之后,所有内网的机器都不能打开网页了,QQ也上不了,不过能PING通外网,去掉这一句情况还是一样,后来重启才好的,现在都不能再做测试,等下班了才好再继续测试!另我的SHELL查了一下,应该是/bin/bash,是否应该不要/   ?

[ 本帖最后由 mack2050 于 2008-1-3 12:37 编辑 ]
作者: platinum    时间: 2008-01-03 12:43
原帖由 springwind426 于 2008-1-3 11:42 发表
对,就是用hashlimit修改的

是根据哪个内核版本的 hashlimit 改的?
作者: springwind426    时间: 2008-01-03 13:07
原帖由 platinum 于 2008-1-3 12:43 发表

是根据哪个内核版本的 hashlimit 改的?



根据2.6.23的修改的,我做了不少改动,去掉了IPV6的支持,修改了初始值的设置(我用hashlimit测试过,它的初始值和峰值的设置不合理,也就是说,它的令牌桶太小了,尽管我设置的值很大,可是匹配的值却很小,相差多。)
对一些结构的定义我也做了修改,主要是方便我的统计用的(就是添加了一些计数器。)
还有,我把  带宽的控制和数据包速率的控制整合到一起了,这样就可以完全脱离hashlimit(它只有数据包速率的控制),而且,我对控制做了简化,只接收 秒 这个单位,即每秒多少数据流或者每秒多少数据包这样的限制,因此,可以说从控制粒度上没有它细(因为我认为,我没有必要限制到 /分钟  /小时 /天 这样的粒度)
原来,hashlimit并不接收 “逻辑非” 这样的条件,而我恰恰认为这个条件比较重要(即超过部分才匹配),这样,想丢弃某些包的时候,只要一条规则就可以了。


我改进了一下,令牌桶的大小设置成  平均值+burst值了(burst值我初始设定为10%的平均值),我经过测试,令牌桶的容量(峰值)小于平均值的时候,相差越多,误差越大。

其实,对于持续的数据传输,令牌桶的容量再大一点儿也无所谓。(不过,对于持续传输,令牌桶设置大了,对结果也没有任何影响)。

还有,x_tables.h这个在新内核中有,对于旧内核,是没有的,同样的,以xt_打头的函数,对于旧版本也没有的
我原来是想修改成可以在旧版本下也可以编译,可是,用到mutex_lock和mutex_unlock这些函数,只有在新内核中才有,就是mutex.h这个头文件
主要作用是用来在修改hash表的内容的时候对hash表进行锁定用的。

因此,我的这个想法并没有能够实现,可是我也不知道如何修改它。
作者: springwind426    时间: 2008-01-03 13:15
原帖由 mack2050 于 2008-1-3 12:36 发表
我的线路是电信的以太网接入,不用ADSL设备,但是要进行虚拟拨号才可以,所以确实用到了PPP0

-A FORWARD -o eth0 -m iprange --dst-range 192.168.1.12-192.168.80.0 -m hashspeed  /! --hashspeed-bytes 60K - ...



如果是bash的话,应该用 \!  来转义 !   而不是/!

不过,用 iptables-save 或者 iptables -L 来显示设定的情况的时候,会只显示!,而没有\
作者: 5639863    时间: 2008-01-03 14:29
dmesg看到如下信息:
ipt_hashspeed: Unknown symbol xt_unregister_matches
ipt_hashspeed: Unknown symbol ipt_unregister_matches
ipt_hashspeed: Unknown symbol ipt_register_matches
这是什么意思?
作者: mack2050    时间: 2008-01-03 15:54
我想那是我的笔误了,我是按这个输的-A FORWARD -o eth1 -m iprange --dst-range 192.168.1.12-192.168.80.0 -m hashspeed  \! --hashspeed-bytes 60K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP 可能是笔误,我下班再试一次!
作者: mack2050    时间: 2008-01-03 18:29
呵呵,发布最新测试反馈!
一切顺利,能把我想要的IP段限速在我指定的范围内,不过我的网关(192.168.1.11)和广播地址(192.168.1.255)也在其中,暂时似乎没有什么影响,大家看看觉得会不会有什么问题!

-A FORWARD -o eth0 -m iprange ! --dst-range 192.168.1.81-192.168.1.90 -m hashspeed  ! --hashspeed-bytes 60K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP
作者: springwind426    时间: 2008-01-03 18:30
原帖由 5639863 于 2008-1-3 14:29 发表
dmesg看到如下信息:
ipt_hashspeed: Unknown symbol xt_unregister_matches
ipt_hashspeed: Unknown symbol ipt_unregister_matches
ipt_hashspeed: Unknown symbol ipt_register_matches
这是什么意思?



有可能是没有加载相依赖的内核模块,比如 x_tables 和 ip_tables

是不是手动加载内核模块了?(比如  insmod ./ipt_hashspeed.ko)
作者: springwind426    时间: 2008-01-03 18:33
原帖由 mack2050 于 2008-1-3 18:29 发表
呵呵,发布最新测试反馈!
一切顺利,能把我想要的IP段限速在我指定的范围内,不过我的网关(192.168.1.11)和广播地址(192.168.1.255)也在其中,暂时似乎没有什么影响,大家看看觉得会不会有什么问题!

-A FORWARD  ...



正常情况下,网关的IP不会出现在路过的数据包中,只有网关的MAC会出现在数据包中

正常访问的情况下,广播数据包是很少的
作者: 5639863    时间: 2008-01-03 19:16
原帖由 springwind426 于 2008-1-3 18:30 发表



有可能是没有加载相依赖的内核模块,比如 x_tables 和 ip_tables

是不是手动加载内核模块了?(比如  insmod ./ipt_hashspeed.ko)


应该是手动加载了一下,但没有成功,所以出现上面的提示。我depmod -a 然后在insmod,但还是不行。只好重新编译,但出现下面的问题:
make -C /lib/modules/2.6.18.8/build M=/root/hashspeed-0.1 modules
make[1]: Entering directory `/usr/src/linux-2.6.18.8'
  CC [M]  /root/hashspeed-0.1/ipt_hashspeed.o
/root/hashspeed-0.1/ipt_hashspeed.c:606: 警告:从不兼容的指针类型初始化
/root/hashspeed-0.1/ipt_hashspeed.c: 在函数 ‘ipt_hashspeed_init’ 中:
/root/hashspeed-0.1/ipt_hashspeed.c:728: 警告:隐式声明函数 ‘ipt_register_matches’
/root/hashspeed-0.1/ipt_hashspeed.c:754: 警告:隐式声明函数 ‘xt_unregister_matches’
/root/hashspeed-0.1/ipt_hashspeed.c: 在函数 ‘ipt_hashspeed_fini’ 中:
/root/hashspeed-0.1/ipt_hashspeed.c:767: 警告:隐式声明函数 ‘ipt_unregister_matches’
  Building modules, stage 2.
  MODPOST
WARNING: "xt_unregister_matches" [/root/hashspeed-0.1/ipt_hashspeed.ko] undefined!
WARNING: "ipt_register_matches" [/root/hashspeed-0.1/ipt_hashspeed.ko] undefined!
WARNING: "ipt_unregister_matches" [/root/hashspeed-0.1/ipt_hashspeed.ko] undefined!
  CC      /root/hashspeed-0.1/ipt_hashspeed.mod.o
  LD [M]  /root/hashspeed-0.1/ipt_hashspeed.ko
make[1]: Leaving directory `/usr/src/linux-2.6.18.8'
cc -O2 -Wall -DIPTABLES_VERSION=\"1.3.5\" -I/usr/src/iptables-1.3.5/include -fPIC -c libipt_hashspeed.c
cc -shared -o libipt_hashspeed.so libipt_hashspeed.o
libipt_hashspeed.o: In function `_init':
libipt_hashspeed.c.text+0x50): multiple definition of `_init'
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crti.o.init+0x0): first defined here
collect2: ld 返回 1
make: *** [libipt_hashspeed.so] 错误 1

停止了。
作者: springwind426    时间: 2008-01-03 20:07
原帖由 5639863 于 2008-1-3 19:16 发表


应该是手动加载了一下,但没有成功,所以出现上面的提示。我depmod -a 然后在insmod,但还是不行。只好重新编译,但出现下面的问题:
make -C /lib/modules/2.6.18.8/build M=/root/hashspeed-0.1 modules ...



我检查了一下,发现旧版本的内核是 ipt_register_match,而且参数也只有一个

我针对这个做了修改,你到我的主页上下载最新的,然后再编译看看,或者,自己修改后,再编译看看

ipt_unregister_match(ipt_hashspeed);
ipt_register_match(ipt_hashspeed);

有几处

原来是
ipt_unregister_matches(ipt_hashspeed, ARRAY_SIZE(ipt_hashspeed));
ipt_register_matches(ipt_hashspeed, ARRAY_SIZE(ipt_hashspeed));
作者: 5639863    时间: 2008-01-03 20:56
make -C /lib/modules/2.6.18.8/build M=/root/hashspeed-0.1 modules
make[1]: Entering directory `/usr/src/linux-2.6.18.8'
  CC [M]  /root/hashspeed-0.1/ipt_hashspeed.o
/root/hashspeed-0.1/ipt_hashspeed.c:607: 警告:从不兼容的指针类型初始化
  Building modules, stage 2.
  MODPOST
  CC      /root/hashspeed-0.1/ipt_hashspeed.mod.o
  LD [M]  /root/hashspeed-0.1/ipt_hashspeed.ko
make[1]: Leaving directory `/usr/src/linux-2.6.18.8'
cc -O2 -Wall -DIPTABLES_VERSION=\"1.3.5\" -I/usr/src/iptables-1.3.5/include -fPIC -c libipt_hashspeed.c
cc -shared -o libipt_hashspeed.so libipt_hashspeed.o
libipt_hashspeed.o: In function `_init':
libipt_hashspeed.c.text+0x50): multiple definition of `_init'
/usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crti.o.init+0x0): first defined here
collect2: ld 返回 1
make: *** [libipt_hashspeed.so] 错误 1

我已经下载你的最新的了,但还是出现如上错误。请问更改的是哪个文件。对于不懂编程的我可以更改吗?谢谢
作者: springwind426    时间: 2008-01-03 21:36
原帖由 5639863 于 2008-1-3 20:56 发表
make -C /lib/modules/2.6.18.8/build M=/root/hashspeed-0.1 modules
make[1]: Entering directory `/usr/src/linux-2.6.18.8'
  CC [M]  /root/hashspeed-0.1/ipt_hashspeed.o
/root/hashspeed-0.1/ipt_ha ...



网上似乎看到例子,这个是编译iptables模块的时候的错误

cc -shared -o libipt_hashspeed.so libipt_hashspeed.o
好象有大侠说把 Makefile中的
$(CC) -shared  修改成  ld -shared 就可以编译过去。

还有,我查看了一下2.6.18的定义

static void
hashspeed_destroy(const struct ipt_match *match, void *matchinfo
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
        ,unsigned int matchsize
#endif
)

把hashspeed_destroy部分的定义修改一下(如上),编译看看,是不是编译内核模块的时候就没有警告信息了

[ 本帖最后由 springwind426 于 2008-1-3 21:50 编辑 ]
作者: dzb_01    时间: 2008-01-03 22:35
springwind426兄,能否解决一下hashspeed在iptables-1.4.0下的编译,谢谢先
内核2.6.23,iptables-1.4.0,内核模块编译通过,iptables模块编译错误如下

[root@qq hashspeed-0.1]# make
make -C /usr/src/linux-2.6.23 M=/usr/src/pom/hashspeed-0.1 modules
make[1]: Entering directory `/usr/src/linux-2.6.23'
  CC [M]  /usr/src/pom/hashspeed-0.1/ipt_hashspeed.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /usr/src/pom/hashspeed-0.1/ipt_hashspeed.mod.o
  LD [M]  /usr/src/pom/hashspeed-0.1/ipt_hashspeed.ko
make[1]: Leaving directory `/usr/src/linux-2.6.23'
cc -O2 -Wall -DIPTABLES_VERSION=\"1.4.0\" -I/usr/src/iptables-1.4.0/include -fPIC -c libipt_hashspeed.c
在包含自 /usr/src/iptables-1.4.0/include/libiptc/libiptc.h:7 的文件中,
                 从 /usr/src/iptables-1.4.0/include/iptables.h:5,
                 从 libipt_hashspeed.c:13:
/usr/src/iptables-1.4.0/include/linux/netfilter_ipv4/ip_tables.h:18:28: 错误:linux/compiler.h:没有那个文件或目录
In file included from /usr/src/iptables-1.4.0/include/libiptc/libiptc.h:7,
                 from /usr/src/iptables-1.4.0/include/iptables.h:5,
                 from libipt_hashspeed.c:13:
/usr/src/iptables-1.4.0/include/linux/netfilter_ipv4/ip_tables.h:190: 错误:expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘*’ token
make: *** [libipt_hashspeed.so] 错误 1
作者: springwind426    时间: 2008-01-04 10:43
原帖由 dzb_01 于 2008-1-3 22:35 发表
springwind426兄,能否解决一下hashspeed在iptables-1.4.0下的编译,谢谢先
内核2.6.23,iptables-1.4.0,内核模块编译通过,iptables模块编译错误如下

[root@qq hashspeed-0.1]# make
make -C /usr/src/l ...



你到我的主页上下载最新的吧,我看了一下iptables-1.4.0的头文件,需要把linux的include也包含到-I中才行

还有,我修改了一下Makefile,修正了可能检测错误iptables版本的情况
(比如,我当前的系统安装的iptables版本是1.3.8,可是我想编译供1.4.0的iptables运行的模块,虽然指定了iptables的源代码所在路径,可是,版本检测却是当前的版本。)
作者: 5639863    时间: 2008-01-04 10:50
原帖由 springwind426 于 2008-1-4 10:43 发表



你到我的主页上下载最新的吧,我看了一下iptables-1.4.0的头文件,需要把linux的include也包含到-I中才行

还有,我修改了一下Makefile,修正了可能检测错误iptables版本的情况
(比如,我当前的系统安 ...



哈哈,太感谢了啊,我刚刚下载你最新的修改版本,并把里面的$(cc) -share 改成ld -share编译成功。
作者: springwind426    时间: 2008-01-04 10:52
原帖由 5639863 于 2008-1-4 10:50 发表



哈哈,太感谢了啊,我刚刚下载你最新的修改版本,并把里面的$(cc) -share 改成ld -share编译成功。



我没有修改成ld也是编译成功的,而且也能够正常运行

我的环境:
linux 2.6.22
iptables-1.4.0
gcc 4.1.3 20071209
作者: 5639863    时间: 2008-01-04 11:12
springwind426 兄,我没有想通在有代理的情况下,应该怎么做限制,因为有代理的时候走的是INPUT链,将如何控制呢?

我根据前面的例子写了一个针对我自己机器的规则:

iptables -I INPUT   -s 192.168.0.88  -p tcp -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP

但没有看到任何变化。

[ 本帖最后由 5639863 于 2008-1-4 11:27 编辑 ]
作者: dzb_01    时间: 2008-01-04 11:17
标题: 回复 #42 springwind426 的帖子
严重感谢springwind426兄,下载新版之后成功编译,无错误和警告
过程如下

[root@qq hashspeed-0.1]# make
make -C /usr/src/linux-2.6.23 M=/usr/src/pom/hashspeed-0.1 modules
make[1]: Entering directory `/usr/src/linux-2.6.23'
  CC [M]  /usr/src/pom/hashspeed-0.1/ipt_hashspeed.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /usr/src/pom/hashspeed-0.1/ipt_hashspeed.mod.o
  LD [M]  /usr/src/pom/hashspeed-0.1/ipt_hashspeed.ko
make[1]: Leaving directory `/usr/src/linux-2.6.23'
cc -O2 -Wall -DIPTABLES_VERSION=\"1.4.0\" -I/usr/src/iptables-1.4.0/include -I/usr/src/linux-2.6.23/include -fPIC -c libipt_hashspeed.c
cc -shared -o libipt_hashspeed.so libipt_hashspeed.o
作者: 5639863    时间: 2008-01-04 11:18
原帖由 springwind426 于 2008-1-4 10:52 发表



我没有修改成ld也是编译成功的,而且也能够正常运行

我的环境:
linux 2.6.22
iptables-1.4.0
gcc 4.1.3 20071209


我又重新编译了一下,如果不更改$(cc) -share 为 ld -share 的话就无法完成。
我的环境是:
linux 2.6.18
iptables-1.3.5
gcc 版本 4.1.1 20070105
作者: springwind426    时间: 2008-01-04 12:03
原帖由 5639863 于 2008-1-4 11:12 发表
springwind426 兄,我没有想通在有代理的情况下,应该怎么做限制,因为有代理的时候走的是INPUT链,将如何控制呢?

我根据前面的例子写了一个针对我自己机器的规则:

iptables -I INPUT   -s 192.168.0.8 ...


你可以试试:

iptables -t nat -I POSTROUTING 1 -o 内网网卡 -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP

就是在NAT链上做控制,在内网卡的发包上做控制,能够控制内网的下载速度

iptables -t nat -I PREROUTING 1 -i 内网网卡 -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode srcip --hashspeed-name slimit -j DROP

这个是在内网网卡的收包上做控制,能够控制内网的上传速度

因为数据包进入的时候,是先进入nat表的PREROUTING链,然后经过filter表,而出去的时候,是先经过filter,然后再经过nat表的POSTROUTING链

只是有人说,在nat表中做访问控制,可能会影响效率,我没有试过。
作者: 5639863    时间: 2008-01-04 12:34
iptables -t nat -I POSTROUTING 1 -o 内网网卡 -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP

我用这个规则试了一下,还是没有任何效果。
我用的是SQUID
作者: springwind426    时间: 2008-01-04 13:40
原帖由 5639863 于 2008-1-4 12:34 发表
iptables -t nat -I POSTROUTING 1 -o 内网网卡 -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP

我用这个规则试了一下,还是没有任何效果。
我用的是SQUID


我用这个:
iptables -t mangle -A POSTROUTING -o 内网网卡 -m hashspeed --hashspeed-name squid --hashspeed-mode dstip \! --hashspeed-bytes 64K -j DROP

能够把通过代理访问的内网主机的下载速度限制在64K/S

你试试,只是不知道这样做以后,效率上有多大影响,通常情况下,都不在mangle表中做控制
作者: 5639863    时间: 2008-01-07 09:20
原帖由 springwind426 于 2008-1-4 13:40 发表


我用这个:
iptables -t mangle -A POSTROUTING -o 内网网卡 -m hashspeed --hashspeed-name squid --hashspeed-mode dstip \! --hashspeed-bytes 64K -j DROP

能够把通过代理访问的内网主机的下载速度 ...


在mangle上做规则确实可以了。
但如果将下载限制到100K的话,那对浏览网页有没有影响呢,这个咋测试,用感观还是其他什么软件?
作者: springwind426    时间: 2008-01-07 13:48
至于有没有影响,你需要自己去测试

如果客户端开了下载上传的软件,可能会对自己有一些影响。
作者: laixi781211    时间: 2008-01-11 13:22
执行iptables -m hashspeed --help 可以看到hashspeed,
但是执行iptables -A FORWARD -o eth0 -m iprange ! --dst-range 192.168.1.81-192.168.1.90 -m hashspeed  ! --hashspeed-bytes 60K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP
提示iptables: No chain/target/match by that name
作者: wheel    时间: 2008-01-14 10:04
不错,限制成下载64K,好用
作者: skylove    时间: 2008-03-05 20:51
老大,你的主页我这里打不开啊。。。

对了,可以的话,能传输份最新的上来么?反正文件不大的~~~ 不是不支持您主页,确实是访问不能啊。。。
作者: springwind426    时间: 2008-03-06 19:01
真是抱歉,前两天重启了电脑,忘记开web服务了

现在已经更新了第一个帖子上的附件
作者: skylove    时间: 2008-03-06 19:32
原帖由 springwind426 于 2008-3-6 19:01 发表
真是抱歉,前两天重启了电脑,忘记开web服务了

现在已经更新了第一个帖子上的附件


呵呵,下载了,但是结果好像大概是由于我用的 iptables 1.4.0 和 gcc 4.1.2 所有有些不尽如人意


  1. make
  2. make -C /lib/modules/2.6.24.3skylove/build M=/data/hashspeed-0.1 modules
  3. make[1]: Entering directory `/data/linux-2.6.24.3'
  4.   CC [M]  /data/hashspeed-0.1/ipt_hashspeed.o
  5. /data/hashspeed-0.1/ipt_hashspeed.c: 在函数 ‘ipt_hashspeed_init’ 中:
  6. /data/hashspeed-0.1/ipt_hashspeed.c:751: 错误:‘proc_net’ 未声明 (在此函数内第一次使用)
  7. /data/hashspeed-0.1/ipt_hashspeed.c:751: 错误:(即使在一个函数内多次出现,每个未声明的标识符在其
  8. /data/hashspeed-0.1/ipt_hashspeed.c:751: 错误:所在的函数内只报告一次。)
  9. /data/hashspeed-0.1/ipt_hashspeed.c: 在函数 ‘ipt_hashspeed_fini’ 中:
  10. /data/hashspeed-0.1/ipt_hashspeed.c:773: 错误:‘proc_net’ 未声明 (在此函数内第一次使用)
  11. make[2]: *** [/data/hashspeed-0.1/ipt_hashspeed.o] 错误 1
  12. make[1]: *** [_module_/data/hashspeed-0.1] 错误 2
  13. make[1]: Leaving directory `/data/linux-2.6.24.3'
  14. make: *** [ipt_hashspeed.ko] 错误 2
复制代码


我尝试着处理,但是没辙。。。盼助
作者: springwind426    时间: 2008-03-07 13:45
你查看查看

proc_net 是在 include/linux/proc_fs.h中定义的

我没有用过2.6.24,是不是定义有变化?
在include/linux/proc_fs.h中有proc_mkdir的定义
作者: skylove    时间: 2008-03-07 17:44
原帖由 springwind426 于 2008-3-7 13:45 发表
你查看查看

proc_net 是在 include/linux/proc_fs.h中定义的

我没有用过2.6.24,是不是定义有变化?
在include/linux/proc_fs.h中有proc_mkdir的定义


我现在在外面,今天单位女同志过节,我搭着吃饭。。。 回去了试一下,感谢哦
作者: skylove    时间: 2008-03-08 08:30
原帖由 springwind426 于 2008-3-7 13:45 发表
你查看查看

proc_net 是在 include/linux/proc_fs.h中定义的

我没有用过2.6.24,是不是定义有变化?
在include/linux/proc_fs.h中有proc_mkdir的定义


我将这个版本的 proc_fs.h 贴出,麻烦您参考看看,给点意见?


  1. cat proc_fs.h   
  2. #ifndef _LINUX_PROC_FS_H
  3. #define _LINUX_PROC_FS_H

  4. #include <linux/slab.h>
  5. #include <linux/fs.h>
  6. #include <linux/spinlock.h>
  7. #include <linux/magic.h>
  8. #include <asm/atomic.h>

  9. struct net;
  10. struct completion;

  11. /*
  12. * The proc filesystem constants/structures
  13. */

  14. /*
  15. * Offset of the first process in the /proc root directory..
  16. */
  17. #define FIRST_PROCESS_ENTRY 256


  18. /*
  19. * We always define these enumerators
  20. */

  21. enum {
  22.         PROC_ROOT_INO = 1,
  23. };

  24. /*
  25. * This is not completely implemented yet. The idea is to
  26. * create an in-memory tree (like the actual /proc filesystem
  27. * tree) of these proc_dir_entries, so that we can dynamically
  28. * add new files to /proc.
  29. *
  30. * The "next" pointer creates a linked list of one /proc directory,
  31. * while parent/subdir create the directory structure (every
  32. * /proc file has a parent, but "subdir" is NULL for all
  33. * non-directory entries).
  34. *
  35. * "get_info" is called at "read", while "owner" is used to protect module
  36. * from unloading while proc_dir_entry is in use
  37. */

  38. typedef int (read_proc_t)(char *page, char **start, off_t off,
  39.                           int count, int *eof, void *data);
  40. typedef int (write_proc_t)(struct file *file, const char __user *buffer,
  41.                            unsigned long count, void *data);
  42. typedef int (get_info_t)(char *, char **, off_t, int);
  43. typedef struct proc_dir_entry *(shadow_proc_t)(struct task_struct *task,
  44.                                                 struct proc_dir_entry *pde);

  45. struct proc_dir_entry {
  46.         unsigned int low_ino;
  47.         unsigned short namelen;
  48.         const char *name;
  49.         mode_t mode;
  50.         nlink_t nlink;
  51.         uid_t uid;
  52.         gid_t gid;
  53.         loff_t size;
  54.         const struct inode_operations *proc_iops;
  55.         /*
  56.          * NULL ->proc_fops means "PDE is going away RSN" or
  57.          * "PDE is just created". In either case, e.g. ->read_proc won't be
  58.          * called because it's too late or too early, respectively.
  59.          *
  60.          * If you're allocating ->proc_fops dynamically, save a pointer
  61.          * somewhere.
  62.          */
  63.         const struct file_operations *proc_fops;
  64.         get_info_t *get_info;
  65.         struct module *owner;
  66.         struct proc_dir_entry *next, *parent, *subdir;
  67.         void *data;
  68.         read_proc_t *read_proc;
  69.         write_proc_t *write_proc;
  70.         atomic_t count;         /* use count */
  71.         int pde_users;  /* number of callers into module in progress */
  72.         spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
  73.         struct completion *pde_unload_completion;
  74.         shadow_proc_t *shadow_proc;
  75. };

  76. struct kcore_list {
  77.         struct kcore_list *next;
  78.         unsigned long addr;
  79.         size_t size;
  80. };

  81. struct vmcore {
  82.         struct list_head list;
  83.         unsigned long long paddr;
  84.         unsigned long long size;
  85.         loff_t offset;
  86. };

  87. #ifdef CONFIG_PROC_FS

  88. extern struct proc_dir_entry proc_root;
  89. extern struct proc_dir_entry *proc_root_fs;
  90. extern struct proc_dir_entry *proc_bus;
  91. extern struct proc_dir_entry *proc_root_driver;
  92. extern struct proc_dir_entry *proc_root_kcore;

  93. extern spinlock_t proc_subdir_lock;

  94. extern void proc_root_init(void);
  95. extern void proc_misc_init(void);

  96. struct mm_struct;

  97. void proc_flush_task(struct task_struct *task);
  98. struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct nameidata *);
  99. int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
  100. unsigned long task_vsize(struct mm_struct *);
  101. int task_statm(struct mm_struct *, int *, int *, int *, int *);
  102. char *task_mem(struct mm_struct *, char *);
  103. void clear_refs_smap(struct mm_struct *mm);

  104. struct proc_dir_entry *de_get(struct proc_dir_entry *de);
  105. void de_put(struct proc_dir_entry *de);

  106. extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  107.                                                 struct proc_dir_entry *parent);
  108. extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);

  109. extern struct vfsmount *proc_mnt;
  110. struct pid_namespace;
  111. extern int proc_fill_super(struct super_block *);
  112. extern struct inode *proc_get_inode(struct super_block *, unsigned int, struct proc_dir_entry *);

  113. /*
  114. * These are generic /proc routines that use the internal
  115. * "struct proc_dir_entry" tree to traverse the filesystem.
  116. *
  117. * The /proc root directory has extended versions to take care
  118. * of the /proc/<pid> subdirectories.
  119. */
  120. extern int proc_readdir(struct file *, void *, filldir_t);
  121. extern struct dentry *proc_lookup(struct inode *, struct dentry *, struct nameidata *);

  122. extern const struct file_operations proc_kcore_operations;
  123. extern const struct file_operations proc_kmsg_operations;
  124. extern const struct file_operations ppc_htab_operations;

  125. extern int pid_ns_prepare_proc(struct pid_namespace *ns);
  126. extern void pid_ns_release_proc(struct pid_namespace *ns);

  127. /*
  128. * proc_tty.c
  129. */
  130. struct tty_driver;
  131. extern void proc_tty_init(void);
  132. extern void proc_tty_register_driver(struct tty_driver *driver);
  133. extern void proc_tty_unregister_driver(struct tty_driver *driver);

  134. /*
  135. * proc_devtree.c
  136. */
  137. #ifdef CONFIG_PROC_DEVICETREE
  138. struct device_node;
  139. struct property;
  140. extern void proc_device_tree_init(void);
  141. extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
  142. extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
  143. extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
  144.                                          struct property *prop);
  145. extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
  146.                                          struct property *newprop,
  147.                                          struct property *oldprop);
  148. #endif /* CONFIG_PROC_DEVICETREE */

  149. extern struct proc_dir_entry *proc_symlink(const char *,
  150.                 struct proc_dir_entry *, const char *);
  151. extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
  152. extern struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
  153.                         struct proc_dir_entry *parent);

  154. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  155.         mode_t mode, struct proc_dir_entry *base,
  156.         read_proc_t *read_proc, void * data)
  157. {
  158.         struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  159.         if (res) {
  160.                 res->read_proc=read_proc;
  161.                 res->data=data;
  162.         }
  163.         return res;
  164. }

  165. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  166.         mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  167. {
  168.         struct proc_dir_entry *res=create_proc_entry(name,mode,base);
  169.         if (res) res->get_info=get_info;
  170.         return res;
  171. }

  172. extern struct proc_dir_entry *proc_net_fops_create(struct net *net,
  173.         const char *name, mode_t mode, const struct file_operations *fops);
  174. extern void proc_net_remove(struct net *net, const char *name);

  175. #else

  176. #define proc_root_driver NULL
  177. #define proc_bus NULL

  178. #define proc_net_fops_create(net, name, mode, fops)  ({ (void)(mode), NULL; })
  179. static inline void proc_net_remove(struct net *net, const char *name) {}

  180. static inline void proc_flush_task(struct task_struct *task)
  181. {
  182. }

  183. static inline struct proc_dir_entry *create_proc_entry(const char *name,
  184.         mode_t mode, struct proc_dir_entry *parent) { return NULL; }

  185. #define remove_proc_entry(name, parent) do {} while (0)

  186. static inline struct proc_dir_entry *proc_symlink(const char *name,
  187.                 struct proc_dir_entry *parent,const char *dest) {return NULL;}
  188. static inline struct proc_dir_entry *proc_mkdir(const char *name,
  189.         struct proc_dir_entry *parent) {return NULL;}

  190. static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
  191.         mode_t mode, struct proc_dir_entry *base,
  192.         read_proc_t *read_proc, void * data) { return NULL; }
  193. static inline struct proc_dir_entry *create_proc_info_entry(const char *name,
  194.         mode_t mode, struct proc_dir_entry *base, get_info_t *get_info)
  195.         { return NULL; }

  196. struct tty_driver;
  197. static inline void proc_tty_register_driver(struct tty_driver *driver) {};
  198. static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};

  199. extern struct proc_dir_entry proc_root;

  200. static inline int pid_ns_prepare_proc(struct pid_namespace *ns)
  201. {
  202.         return 0;
  203. }

  204. static inline void pid_ns_release_proc(struct pid_namespace *ns)
  205. {
  206. }

  207. #endif /* CONFIG_PROC_FS */

  208. #if !defined(CONFIG_PROC_KCORE)
  209. static inline void kclist_add(struct kcore_list *new, void *addr, size_t size)
  210. {
  211. }
  212. #else
  213. extern void kclist_add(struct kcore_list *, void *, size_t);
  214. #endif

  215. union proc_op {
  216.         int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
  217.         int (*proc_read)(struct task_struct *task, char *page);
  218. };

  219. struct proc_inode {
  220.         struct pid *pid;
  221.         int fd;
  222.         union proc_op op;
  223.         struct proc_dir_entry *pde;
  224.         struct inode vfs_inode;
  225. };

  226. static inline struct proc_inode *PROC_I(const struct inode *inode)
  227. {
  228.         return container_of(inode, struct proc_inode, vfs_inode);
  229. }

  230. static inline struct proc_dir_entry *PDE(const struct inode *inode)
  231. {
  232.         return PROC_I(inode)->pde;
  233. }

  234. static inline struct net *PDE_NET(struct proc_dir_entry *pde)
  235. {
  236.         return pde->parent->data;
  237. }

  238. struct net *get_proc_net(const struct inode *inode);

  239. struct proc_maps_private {
  240.         struct pid *pid;
  241.         struct task_struct *task;
  242. #ifdef CONFIG_MMU
  243.         struct vm_area_struct *tail_vma;
  244. #endif
  245. };

  246. #endif /* _LINUX_PROC_FS_H */
复制代码

作者: springwind426    时间: 2008-03-08 15:50
试试把 proc_net 都换成 init_net.proc_net 试试

我是参考xt_hashlimit来修改的,我看2.6.24里面的xt_hashlimit.c里面是用的 init_net.proc_net
而2.6.23的xt_hashlimit.c里面用的是 proc_net
作者: skylove    时间: 2008-03-09 00:23
原帖由 springwind426 于 2008-3-8 15:50 发表
试试把 proc_net 都换成 init_net.proc_net 试试

我是参考xt_hashlimit来修改的,我看2.6.24里面的xt_hashlimit.c里面是用的 init_net.proc_net
而2.6.23的xt_hashlimit.c里面用的是 proc_net


结果倒是编译出来了,不过不少警告。。。

make
make -C /lib/modules/2.6.24.3skylove/build M=/data/hashspeed-0.1 modules
make[1]: Entering directory `/data/linux-2.6.24.3'
make[1]: Warning: File `.vmlinux.o.cmd' has modification time 2.4e+04 s in the future
make[2]: Warning: File `include/config/auto.conf' has modification time 2.4e+04 s in the future
  CC [M]  /data/hashspeed-0.1/ipt_hashspeed.o
make[2]: 警告:检测到时钟错误。您的创建可能是不完整的。
  Building modules, stage 2.
make[2]: Warning: File `include/config/auto.conf' has modification time 2.4e+04 s in the future
  MODPOST 1 modules
  CC      /data/hashspeed-0.1/ipt_hashspeed.mod.o
  LD [M]  /data/hashspeed-0.1/ipt_hashspeed.ko
make[2]: 警告:检测到时钟错误。您的创建可能是不完整的。
make[1]: 警告:检测到时钟错误。您的创建可能是不完整的。
make[1]: Leaving directory `/data/linux-2.6.24.3'
cc -O2 -Wall -DIPTABLES_VERSION=\"1.4.0\" -I/usr/src/iptables/include -I/lib/modules/2.6.24.3skylove/build/include -fPIC -c libipt_hashspeed.c
libipt_hashspeed.c: 在函数 ‘parse’ 中:
libipt_hashspeed.c:198: 警告:传递参数 4 (属于 ‘string_to_number_ll’)时在不兼容的指针类型间转换
libipt_hashspeed.c: 在函数 ‘print’ 中:
libipt_hashspeed.c:321: 警告:格式 ‘%Lu’ 需要类型 ‘long long unsigned int’,但实参 2 的类型为 ‘u_int64_t’
libipt_hashspeed.c: 在函数 ‘save’ 中:
libipt_hashspeed.c:360: 警告:格式 ‘%Lu’ 需要类型 ‘long long unsigned int’,但实参 2 的类型为 ‘u_int64_t’
cc -shared -o libipt_hashspeed.so libipt_hashspeed.o
作者: skylove    时间: 2008-03-09 01:03
虽然有报告警告,不过好象可以用了呢。。。我测试了一下, 在  -t mangle -A POSTROUTING  这样的方式下才能限制,在 -t nat ,或者 FORWARD 指定的时候不行
作者: platinum    时间: 2008-03-09 01:50
原帖由 skylove 于 2008-3-9 00:23 发表


结果倒是编译出来了,不过不少警告。。。

make
make -C /lib/modules/2.6.24.3skylove/build M=/data/hashspeed-0.1 modules
make[1]: Entering directory `/data/linux-2.6.24.3'
make[1]: Warning: ...

你的是 64 位机吗?
作者: skylove    时间: 2008-03-09 08:19
原帖由 platinum 于 2008-3-9 01:50 发表

你的是 64 位机吗?


恩,是的,就是 http://linux.chinaunix.net/bbs/thread-908047-1-1.html 这帖子里提到的机器到货了,这几天正在配置,顺便也想用它把以前的一些计划和实验完成
作者: wwlovezz    时间: 2008-03-10 11:34
想问下老大这个限速模块能否实现在一个网段机器中``抽出几台机器不限速的给自己用
该怎么做?
谢谢
作者: fjingxu    时间: 2008-03-10 14:18
能用在2.4内核下吗?
作者: springwind426    时间: 2008-03-10 14:47
原帖由 wwlovezz 于 2008-3-10 11:34 发表
想问下老大这个限速模块能否实现在一个网段机器中``抽出几台机器不限速的给自己用
该怎么做?
谢谢


完全可以的

只要把允许的规则放在限制速度的规则前面就可以了
比如:

iptables -t forward -o eth1 -s IP -j ACCEPT #不需要限制速度的IP
iptables -t forward -o eth1 ....   #限制速度


这个只是一个速度匹配的内核模块,因此,遵循netfilter的规则控制,只要前面有匹配的规则,那么就不匹配后面的规则。
作者: wwlovezz    时间: 2008-03-12 09:39
我用2.6.24 iptables1.4编译出错类。。。。。
Makefile:24: You need to install iptables sources and maybe set IPTABLES_SRC
make -C /lib/modules/2.6.24.3/build M=/usr/src/hashspeed-0.1 modules
make[1]: Entering directory `/usr/src/linux-2.6.24.3'
  CC [M]  /usr/src/hashspeed-0.1/ipt_hashspeed.o
/usr/src/hashspeed-0.1/ipt_hashspeed.c: &Ocirc;&Uacute;&ordm;&macr;&Ecirc;&yacute; &iexcl;&reg;ipt_hashspeed_init&iexcl;&macr; &Ouml;&ETH;&pound;&ordm;
/usr/src/hashspeed-0.1/ipt_hashspeed.c:751: &acute;í&Icirc;ó&pound;&ordm;&iexcl;&reg;proc_net&iexcl;&macr; &Icirc;&acute;&Eacute;ù&Atilde;÷ (&Ocirc;&Uacute;&acute;&Euml;&ordm;&macr;&Ecirc;&yacute;&Auml;                  &Uacute;&micro;&Uacute;&Ograve;&raquo;&acute;&Icirc;&Ecirc;&sup1;&Oacute;&Atilde
/usr/src/hashspeed-0.1/ipt_hashspeed.c:751: &acute;í&Icirc;ó&pound;&ordm;(&frac14;&acute;&Ecirc;&sup1;&Ocirc;&Uacute;&Ograve;&raquo;&cedil;&ouml;&ordm;&macr;&Ecirc;&yacute;&Auml;&Uacute;&para;à&acute;&Icirc;&sup3;&ouml;&Iuml;&Ouml;&pound;&not;&Atilde;&iquest;&cedil;                  &ouml;&Icirc;&acute;&Eacute;ù&Atilde;÷&micro;&Auml;±ê&Ecirc;&para;·&ucirc;&Ocirc;&Uacute;&AElig;&auml;
/usr/src/hashspeed-0.1/ipt_hashspeed.c:751: &acute;í&Icirc;ó&pound;&ordm;&Euml;ù&Ocirc;&Uacute;&micro;&Auml;&ordm;&macr;&Ecirc;&yacute;&Auml;&Uacute;&Ouml;&raquo;±¨&cedil;&aelig;&Ograve;&raquo;&acute;&Icirc;&iexcl;&pound
/usr/src/hashspeed-0.1/ipt_hashspeed.c: &Ocirc;&Uacute;&ordm;&macr;&Ecirc;&yacute; &iexcl;&reg;ipt_hashspeed_fini&iexcl;&macr; &Ouml;&ETH;&pound;&ordm;
/usr/src/hashspeed-0.1/ipt_hashspeed.c:773: &acute;í&Icirc;ó&pound;&ordm;&iexcl;&reg;proc_net&iexcl;&macr; &Icirc;&acute;&Eacute;ù&Atilde;÷ (&Ocirc;&Uacute;&acute;&Euml;&ordm;&macr;&Ecirc;&yacute;&Auml;                  &Uacute;&micro;&Uacute;&Ograve;&raquo;&acute;&Icirc;&Ecirc;&sup1;&Oacute;&Atilde
make[2]: *** [/usr/src/hashspeed-0.1/ipt_hashspeed.o] &acute;í&Icirc;ó 1
make[1]: *** [_module_/usr/src/hashspeed-0.1] &acute;í&Icirc;ó 2
make[1]: Leaving directory `/usr/src/linux-2.6.24.3'
make: *** [ipt_hashspeed.ko] &acute;í&Icirc;ó 2
[root@Ecofe2 hashspeed-0.1]# init 0
[root@Ecofe2 hashspeed-0.1]# ls
ipt_hashspeed.c  libipt_hashspeed.c  README.zh_CN-utf8
ipt_hashspeed.h  Makefile
[root@Ecofe2 hashspeed-0.1]# history -c
[root@Ecofe2 hashspeed-0.1]# make
Makefile:24: You need to install iptables sources and maybe set IPTABLES_SRC
make -C /lib/modules/2.6.24.3/build M=/usr/src/hashspeed-0.1 modules
make[1]: Entering directory `/usr/src/linux-2.6.24.3'
  CC [M]  /usr/src/hashspeed-0.1/ipt_hashspeed.o
/usr/src/hashspeed-0.1/ipt_hashspeed.c: &Ocirc;&Uacute;&ordm;&macr;&Ecirc;&yacute; &iexcl;&reg;ipt_hashspeed_init&iexcl;&macr; &Ouml;&ETH;&pound;&ordm;
/usr/src/hashspeed-0.1/ipt_hashspeed.c:751: &acute;í&Icirc;ó&pound;&ordm;&iexcl;&reg;proc_net&iexcl;&macr; &Icirc;&acute;&Eacute;ù&Atilde;÷ (&Ocirc;&Uacute;&acute;&Euml;&ordm;&macr;&Ecirc;&yacute;&Auml;&Uacute;&micro;&Uacute;&Ograve;&raquo;&acute;&Icirc;&Ecirc;&sup1;&Oacute;&Atilde
/usr/src/hashspeed-0.1/ipt_hashspeed.c:751: &acute;í&Icirc;ó&pound;&ordm;(&frac14;&acute;&Ecirc;&sup1;&Ocirc;&Uacute;&Ograve;&raquo;&cedil;&ouml;&ordm;&macr;&Ecirc;&yacute;&Auml;&Uacute;&para;à&acute;&Icirc;&sup3;&ouml;&Iuml;&Ouml;&pound;&not;&Atilde;&iquest;&cedil;&ouml;&Icirc;&acute;&Eacute;ù&Atilde;÷&micro;&Auml;±ê&Ecirc;&para;·&ucirc;&Ocirc;&Uacute;&AElig;&auml;
/usr/src/hashspeed-0.1/ipt_hashspeed.c:751: &acute;í&Icirc;ó&pound;&ordm;&Euml;ù&Ocirc;&Uacute;&micro;&Auml;&ordm;&macr;&Ecirc;&yacute;&Auml;&Uacute;&Ouml;&raquo;±¨&cedil;&aelig;&Ograve;&raquo;&acute;&Icirc;&iexcl;&pound
/usr/src/hashspeed-0.1/ipt_hashspeed.c: &Ocirc;&Uacute;&ordm;&macr;&Ecirc;&yacute; &iexcl;&reg;ipt_hashspeed_fini&iexcl;&macr; &Ouml;&ETH;&pound;&ordm;
/usr/src/hashspeed-0.1/ipt_hashspeed.c:773: &acute;í&Icirc;ó&pound;&ordm;&iexcl;&reg;proc_net&iexcl;&macr; &Icirc;&acute;&Eacute;ù&Atilde;÷ (&Ocirc;&Uacute;&acute;&Euml;&ordm;&macr;&Ecirc;&yacute;&Auml;&Uacute;&micro;&Uacute;&Ograve;&raquo;&acute;&Icirc;&Ecirc;&sup1;&Oacute;&Atilde
make[2]: *** [/usr/src/hashspeed-0.1/ipt_hashspeed.o] &acute;í&Icirc;ó 1
make[1]: *** [_module_/usr/src/hashspeed-0.1] &acute;í&Icirc;ó 2
make[1]: Leaving directory `/usr/src/linux-2.6.24.3'
make: *** [ipt_hashspeed.ko] &acute;í&Icirc;ó 2
作者: skylove    时间: 2008-03-12 16:30
原帖由 wwlovezz 于 2008-3-12 09:39 发表
我用2.6.24 iptables1.4编译出错类。。。。。
Makefile:24: You need to install iptables sources and maybe set IPTABLES_SRC
make -C /lib/modules/2.6.24.3/build M=/usr/src/hashspeed-0.1 modules
mak ...


把 proc_net 都换成 init_net.proc_net 试试
作者: wwlovezz    时间: 2008-04-03 16:22
哪位大哥有在2.6.24.4 iptables1.4下编译通过....

楼主GG说把proc_net 都换成 init_net.proc_net 试
试了也不行的...

GG帮忙看看

作者: wwlovezz    时间: 2008-04-07 23:53
......编译好几个内核..
我还是在linux-2.6.23 iptables-1.4.0  gcc-4.1.2-14.el5下编译通过...

楼主说的2.6.24内核要把proc_net 全换成init.proc_net
这个是替换哪个文件的proc_net.
作者: wwlovezz    时间: 2008-04-08 00:34
楼主老大.linux2.6.23 iptables-1.4下可以译出来..
模块已加载成功后我用
[root@EEE ~]# iptables -m hashspeed -h
iptables v1.4.0: Couldn't load match `hashspeed'null)

Try `iptables -h' or 'iptables --help' for more information.
怎么会这样呢?????

*******************
然后我把iptables换成1.3.8模块加块正常..使用hashspeed也正常...

哪位在iptables1.4.0下译成功能正常使用的...帮帮哇.....
在此先谢各位大哥大姐了... :wink:
作者: springwind426    时间: 2008-04-08 10:18
原帖由 wwlovezz 于 2008-4-8 00:34 发表
楼主老大.linux2.6.23 iptables-1.4下可以译出来..
模块已加载成功后我用
[root@EEE ~]# iptables -m hashspeed -h
iptables v1.4.0: Couldn't load match `hashspeed'null)

Try `iptables -h' or 'ipt ...



在编译的时候,你是否成功编译了libipt_hashspeed.so,还有,有没有把libipt_hashspeed.so复制到iptables的lib目录下?
作者: wwlovezz    时间: 2008-04-08 13:15
谢谢
我现在在linux2.6.24.4 iptables.1.4下顺利译过``正常运行。
嘿嘿。。。在此谢谢楼主及其他GG
作者: kwest    时间: 2009-08-25 17:39
好文章,翻出来晒晒!
作者: hc_ttcm    时间: 2009-08-26 16:35
报错了

[root@firewall hashspeed-0.1]# export KERNEL_DIR=/usr/src/linux-2.6.18.i686
[root@firewall hashspeed-0.1]# export IPTABLES_DIR=/usr/src/iptables-1.3.8/
[root@firewall hashspeed-0.1]# export KERNEL_DIR=/usr/src/linux-2.6.18.i686/
[root@firewall hashspeed-0.1]# export KERNEL_SRC=/usr/src/linux-2.6.18.i686/
[root@firewall hashspeed-0.1]# export IPTABLES_SRC=/usr/src/iptables-1.3.8/
[root@firewall hashspeed-0.1]# make
make -C /usr/src/linux-2.6.18.i686/ M=/home/hashspeed-0.1 modules
make[1]: Entering directory `/usr/src/linux-2.6.18.i686'

  WARNING: Symbol version dump /usr/src/linux-2.6.18.i686/Module.symvers
           is missing; modules will have no dependencies and modversions.

  CC [M]  /home/hashspeed-0.1/ipt_hashspeed.o
/home/hashspeed-0.1/ipt_hashspeed.c: In function ‘hash_dst’:
/home/hashspeed-0.1/ipt_hashspeed.c:114: 警告:传递实参 1(属于 ‘jhash2’)丢弃了指针目标类型的限定
/home/hashspeed-0.1/ipt_hashspeed.c: In function ‘hashspeed_match’:
/home/hashspeed-0.1/ipt_hashspeed.c:403: 警告:初始化丢弃了指针目标类型的限定
  Building modules, stage 2.
  MODPOST
  CC      /home/hashspeed-0.1/ipt_hashspeed.mod.o
  LD [M]  /home/hashspeed-0.1/ipt_hashspeed.ko
make[1]: Leaving directory `/usr/src/linux-2.6.18.i686'
cc -O2 -Wall -DIPTABLES_VERSION=\"1.3.8\" -I/usr/src/iptables-1.3.8/include -I/usr/src/linux-2.6.18.i686//include -fPIC -c libipt_hashspeed.c
libipt_hashspeed.c:369: 错误:变量 ‘hashspeed’ 有初始值设定但类型不完全
libipt_hashspeed.c:370: 错误:初始值设定项里有未知的字段 ‘next’
libipt_hashspeed.c:370: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:370: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c:371: 错误:初始值设定项里有未知的字段 ‘name’
libipt_hashspeed.c:371: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:371: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c:372: 错误:初始值设定项里有未知的字段 ‘family’
libipt_hashspeed.c:372: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:372: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c:373: 错误:初始值设定项里有未知的字段 ‘version’
libipt_hashspeed.c:373: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:373: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c:374: 错误:初始值设定项里有未知的字段 ‘size’
libipt_hashspeed.c:374: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:374: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c:375: 错误:初始值设定项里有未知的字段 ‘userspacesize’
libipt_hashspeed.c:375: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:375: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c:376: 错误:初始值设定项里有未知的字段 ‘help’
libipt_hashspeed.c:376: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:376: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c:377: 错误:初始值设定项里有未知的字段 ‘init’
libipt_hashspeed.c:377: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:377: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c:378: 错误:初始值设定项里有未知的字段 ‘parse’
libipt_hashspeed.c:378: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:378: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c:379: 错误:初始值设定项里有未知的字段 ‘final_check’
libipt_hashspeed.c:379: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:379: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c:380: 错误:初始值设定项里有未知的字段 ‘print’
libipt_hashspeed.c:380: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:380: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c:381: 错误:初始值设定项里有未知的字段 ‘save’
libipt_hashspeed.c:381: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:381: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c:382: 错误:初始值设定项里有未知的字段 ‘extra_opts’
libipt_hashspeed.c:383: 警告:结构初始值设定项中有多余元素
libipt_hashspeed.c:383: 警告:(在 ‘hashspeed’ 的初始化附近)
libipt_hashspeed.c: In function ‘my_init’:
libipt_hashspeed.c:387: 警告:隐式声明函数 ‘xtables_register_match’
make: *** [libipt_hashspeed.so] 错误 1
作者: bfz814    时间: 2010-02-02 10:27
本帖最后由 bfz814 于 2010-02-02 10:28 编辑

请问一下 ,这个模块 我打上了 内核是2.6.28.4 iptables是1.4.2 ,但是在执行iptables语句上报出一个问题,请帮忙看一下,指点下!!
问题如下:
[root@localhost ~]# iptables -A FORWARD -i eth1 -p tcp -m hashspeed  --hashspeed-bytes 256K --hashspeed-mode srcip --hashspeed-name slimit -j DROP

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel: Oops: 0000 [#2]

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel: last sysfs file: /sys/class/vc/vcs7/dev

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel: Process iptables (pid: 3274, ti=c75a6000 task=c7538ec0 task.ti   =c75a6000)

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel: Stack:

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  d188d0ab 00000058 c751bd06 d188e2b1 02000004 c751bd06 0600bc9  4 c751bc94

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  c751bc94 d189dd32 00000000 00000000 c75a6c3c ffffffff c751beb c fffffffe

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel: Call Trace:

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<d188d0ab>] xt_check_match+0xab/0x170 [x_tables]

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<d188e2b1>] xt_find_match+0xd1/0xf0 [x_tables]

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<d189dd32>] translate_table+0x602/0x6e0 [ip_tables]

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<d189dfe5>] do_ipt_set_ctl+0x1d5/0x430 [ip_tables]

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c0356b80>] nf_sockopt+0x110/0x120

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c0356be1>] nf_setsockopt+0x21/0x30

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c0367b02>] ip_setsockopt+0x132/0xd40

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c0356aef>] nf_sockopt+0x7f/0x120

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c03309d3>] release_sock+0x13/0xa0

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c0356bb4>] nf_getsockopt+0x24/0x30

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c0368d1a>] ip_getsockopt+0x60a/0x700

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c01566ce>] get_page_from_freelist+0x39e/0x460

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c015796c>] __alloc_pages_internal+0xac/0x470

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c0167ed6>] anon_vma_prepare+0x26/0xd0

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c015a528>] lru_cache_add_active_or_unevictable+0x8/0x30

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c0162ac0>] handle_mm_fault+0x4d0/0x660

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c0330cf3>] sock_common_setsockopt+0x23/0x30

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c032e92e>] sys_setsockopt+0x6e/0xc0

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c03306f0>] sys_socketcall+0x240/0x2c0

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel:  [<c0103121>] sysenter_do_call+0x12/0x21

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel: Code: d8 5b e9 ad 35 8d ee 8d b6 00 00 00 00 8d bc 27 00 00 00 00 83 ec 20 89 6c 24 1c 8b 6c 24 24 89 5c 24 10 89 74 24 14 89 7c 24 18 <8b> 45  30 85 c0 74 22 a8 05 74 1e 8b 45 3c 85 c0 74 17 80 7d 1f

Message from syslogd@localhost at Mon Feb  1 00:08:59 2010 ...
localhost kernel: EIP: [<d1896447>] hashspeed_checkentry+0x17/0x320 [ipt_hashspeed] SS:ESP 0068:c75a6bb4
作者: Anzyfly    时间: 2011-03-21 21:14
好东东,就是在新版本中确实编不过啊。:wink:
作者: it最牛    时间: 2011-03-22 12:06
感谢楼主无私的奉献!
作者: icooci    时间: 2011-12-02 21:54
感谢有LZ这样的高手愿意为大家无私奉献




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2