亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 35253 | 回復(fù): 80
打印 上一主題 下一主題

[網(wǎng)絡(luò)管理] 發(fā)布一個速度匹配的內(nèi)核模塊(hashspeed) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2008-01-02 12:04 |只看該作者 |倒序瀏覽
本模塊是在hashlimit基礎(chǔ)上修改的,除了可以進行包的匹配以外,還可以進行字節(jié)的匹配,可以達到針對IP來進行限速和限制包的發(fā)送速度。

hashspeed-0.1.tar.gz (11.47 KB, 下載次數(shù): 641)

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內(nèi)核上編譯通過的,iptables-1.3.8, gcc-4,1

如果是更舊的內(nèi)核,可能會沒有l(wèi)inux/mutex.h

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

如果沒有mutex.h,就得自己想辦法了。(主要是用到mutex_lock這個函數(shù))
在一些老的內(nèi)核版本中,有 fs/xfs/linux-2.6/mutex.h這個頭文件,有能力的兄弟可以自己參考參考,做一些修改


因為對linux編程不是很熟悉,這個只是在hashlimit模塊的基礎(chǔ)上,按照需要進行了適當?shù)男薷模ǘ鴋ashlimit模塊是在比較新的內(nèi)核中才出現(xiàn)的),因此,對于那些遇到編譯問題的,本人無法做出一一解答。

不過,我會針對大家提供的一些編譯錯誤,在源代碼上做一些修改,并投放在我的網(wǎng)站上,因此,直接從我的網(wǎng)站上下載的源碼包可能與這兒的附件有些微差別。

如果哪位兄弟在自己的實際環(huán)境中,成功編譯并運行(通過修改源代碼),請張貼您的修改和編譯環(huán)境。


linux不同版本的內(nèi)核,結(jié)構(gòu)定義不一樣,這個真是煩人,要想讓它能夠在不同版本的內(nèi)核下都能夠編譯成功,真不是一件容易的事,只能一點點完善了。

我會不斷地更新我的網(wǎng)站上的文件,也許,你下載到最新的源代碼,就有可能解決以前不能成功編譯的問題了。

[ 本帖最后由 springwind426 于 2008-10-12 10:14 編輯 ]

論壇徽章:
0
2 [報告]
發(fā)表于 2008-01-02 14:18 |只看該作者
wow~~~~~~~~~~測試下,精確嗎?同時支持 -m mac --mac-source嗎?

論壇徽章:
0
3 [報告]
發(fā)表于 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連接的內(nèi)網(wǎng)的所有主機的TCP上傳速度限制在256K/S


iptables -A FORWARD -o eth1 -p tcp -m hashspeed \! --hashspeed-bytes 256K --hashspeed-mode dstip --hashspeed-name dlimit -j DROP
可以將eth1連接的內(nèi)網(wǎng)的所有主機的TCP下載速度限制在256K/S

論壇徽章:
0
4 [報告]
發(fā)表于 2008-01-02 17:20 |只看該作者
iptables 1.3.5 內(nèi)核2.6.19.7 編譯不過去

論壇徽章:
0
5 [報告]
發(fā)表于 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

論壇徽章:
0
6 [報告]
發(fā)表于 2008-01-02 17:21 |只看該作者
原帖由 springwind426 于 2008-1-2 14:34 發(fā)表
這只是一個匹配模塊,因此,是可以與其他模塊一起使用的

我自己測試的精確度還行

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



請問限速是 per ip的 還是per net的?

論壇徽章:
0
7 [報告]
發(fā)表于 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

是不是路徑的問題?  要在源碼路徑下編譯嗎?

論壇徽章:
0
8 [報告]
發(fā)表于 2008-01-02 18:40 |只看該作者
原帖由 5iwww 于 2008-1-2 17:21 發(fā)表



請問限速是 per ip的 還是per net的?



是per ip

論壇徽章:
0
9 [報告]
發(fā)表于 2008-01-02 19:08 |只看該作者
需要編繹內(nèi)核不?我是MAKE成功了,但再現(xiàn)iptables: Unknown error 4294967295

論壇徽章:
0
10 [報告]
發(fā)表于 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?
這應(yīng)該是正常安裝上去了呀!
下面是安裝記錄
[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 編輯 ]
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP