免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: springwind426
打印 上一主题 下一主题

[网络管理] 发布一个速度匹配的内核模块(hashspeed) [复制链接]

论坛徽章:
0
31 [报告]
发表于 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 来显示设定的情况的时候,会只显示!,而没有\

论坛徽章:
0
32 [报告]
发表于 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
这是什么意思?

论坛徽章:
0
33 [报告]
发表于 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 可能是笔误,我下班再试一次!

论坛徽章:
0
34 [报告]
发表于 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

论坛徽章:
0
35 [报告]
发表于 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)

论坛徽章:
0
36 [报告]
发表于 2008-01-03 18:33 |只看该作者
原帖由 mack2050 于 2008-1-3 18:29 发表
呵呵,发布最新测试反馈!
一切顺利,能把我想要的IP段限速在我指定的范围内,不过我的网关(192.168.1.11)和广播地址(192.168.1.255)也在其中,暂时似乎没有什么影响,大家看看觉得会不会有什么问题!

-A FORWARD  ...



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

正常访问的情况下,广播数据包是很少的

论坛徽章:
0
37 [报告]
发表于 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

停止了。

论坛徽章:
0
38 [报告]
发表于 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));

论坛徽章:
0
39 [报告]
发表于 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

我已经下载你的最新的了,但还是出现如上错误。请问更改的是哪个文件。对于不懂编程的我可以更改吗?谢谢

论坛徽章:
0
40 [报告]
发表于 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 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP