可编译易用的模块化nf-HiPAC移植成功

由于早在上周三对这个周末就有了别的安排,要折腾空气压缩机,突然接到通知又要陪老婆去考试,幸亏周四靠晚上的时间完成了nf-HiPAC的移植工作。
       模块化nf-HiPAC的工作只能排在晚上完成,周四晚上折腾到12点终于算是完成了。效果也还不错,最初的tar包放到了下载频道“模块化的nf- HiPAC”,也会有另外的人放在github上,下载频道的主要是为了使用,而github上的主要是为了更新,这主要鉴于nf-hipac在还有很多 TODO的情况下就停止了更新,这些TODO在其网页http://www.hipac.org/status/todo.html是可以查到的。

       主要的TODO列表如下(主要是怕以上这个网页也不在了...):


Planned Features:

    implement better algorithmic core: The new core will dramatically reduce memory usage while at the same time improving the running time of insert and delete operations. The lookup performance will be improved radically too, especially for bigger rulesets. The concepts and the design are already developed, but the implementation is still in its very early stages
    add support for transactions
    add support for ipv6
    add support for MAC matches
    add functionality similar to iptables-restore
    add native support for set of ranges (e.g. ippools). Each native match is not a single range but instead a set of ranges, which makes a single rule more expressive
    consider making HiPAC available for NAT and mangle tables
    consider removing "rule prefix mismatch" limitation
    the next big step in the far future will be to extend the HiPAC algorithm to do classification with several stages. The HiPAC algorithm will then be capable of combining several classification problems in one data structure, e.g. it will be possible to solve routing, firewalling and traffic control with one HiPAC lookup. The idea is to shorten the packet forwarding path by combining e.g. fib_lookup and iptables filter lookup into one HiPAC query

Outstanding Bugfixes:

    fix handling of jump rules containing iptables matches (currently only some known iptables matches are allowed in jump rules)
    in the current version the number of rule updates per second is limited by the number of synchronize_rcu() calls per second. This slows down rule updates dramatically. Future releases will work around this problem and will offer full rule update speed again

Other Stuff:

    man page for userspace tool
    add more documentation
    more in-depth performance tests

模 块化后的nf-hipac可以直接编译出一个ko文件以及一个用户态的工具nf-hipac程序。值得注意的是,我在移植过程中,去掉了和 iptables模块的联动机制,这有两方面的原因,第一是因为这方面的移植比较复杂,iptables的内核API在内核版本之间变化太大了;另一方面 就是还真的不怎么会用到iptables的match/target模块,如果使用了大量的iptables match/target模块,还不如直接就用iptables呢,再者说,iptables模块只是延展了nf-hipac的功能,对其性能是一个打折 的过程。
       以下是模块化移植工作遇到的一些问题:

1.iptables模块的问题

需要将match/target操作进行移植,内核API变化太大,砍去。

2.netlink接口问题

这 部分比较容易。2.6.13版本的netlink的input回调函数参数是一个socket,创建者需要自己创建内核线程来从该socket的 queue中持续获取skb并且维护queue本身,这部分工作在高版本内核中得到了简化,因为input回调函数的参数就是skb本身,队列的维护由 netlink系统完成。

3.内存问题

在原始的nf-hipac中,为了节省内存,用了两套内存管理方案,即mini alloc/free以及big alloc/free,在调试这部分的时候遇到了不少问题,加之现在内存没必要那么节省,我就统一采用了big alloc/free,也就是说统一在vmalloc区域进行分配。

4.net namespace问题

说实话,2.6.32内核对net namespace的支持也只是个半吊子,但无论如何接口已经适配了,这就是说我必须按照net namespace的要求来处理proc_net。

5.其它

我只是测试了2.6.32内核和3.9.6内核,对于其它版本的内核并没有测试,这种风格也是拜ipset-6.23所赐,要知道,我也是一个很较真儿的人,有时候也会有点书生气。
...

即便是不下载tgz压缩包,也可以通过打patch的方式构建编译目录。
新建一个nf-hipac空目录并cd到它,然后执行:
patch -p1 < $path/nfhipac-1.0.0.patch

就 会将所有的文件和目录置于该目录下,然后make;make install即可。注意,编译的时候需要准备好你的当前内核版本头文件,链接到/lib/modules/`uname -r`/build。 最后给出一个比较长的patch,即nfhipac-1.0.0.patch文件:51CTO下载中心。



 本文转自 dog250 51CTO博客,原文链接:http://blog.51cto.com/dog250/1581361


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nf-HiPAC能十分高效的在linux 2.4的netfilter构架下执行包过滤。它一个用户空间工具,称作“nf-HiPAC”,它被设计为完美兼容'iptables -t filter'。 'nf- hipac'和使用相同的钩子钩在linux 2.4核心的网络栈中,'iptables -t filter'也一样做。用户空间的工具能定义每一个规则在一个数组成的分类器中,能随意对某一连接产生作用。最大的优势在于能够兼容iptables, 用户能够充分按iptables的语法进行设置。 你或许会问:“为什么要使用另外一个包过滤器?” 最短最好的回答是:“性能!” iptables,象更多的包过滤,使用一个简单的包分类算法,对线性的穿过一个链中的每一个包在进行匹配(非)一个规则。明显的,这个方法缺乏效率。 nf-HiPAC ,提供一个新颖包分类的架构。当查找每一个包的时候使用一个高级算法来减少内存占用。在一个有特别多的规则和高带宽的网络中nf-HiPAC表现十分完美。 功能: 充分优化以实现适度内存占用和高性能的包分类 完全动态: 当插入或者删除规则时数据结构没有重建,高速更新成为可能。 在规则更新时,只很短暂时间的锁定,包匹配没有锁定。 支持64位体系。 优化核心用户空间协议(netlink),改良列表速度。 libnfhipac: netlink library for kernel-user communication 原始匹配支持: 源/目的 ip in/out 网络界面 协议 (udp, tcp, icmp) 包分段 源/目的 端口 (udp, tcp) icmp 类型 tcp 标记 ttl 连接状态匹配 match negation ("!") iptables 兼容: 语法和语义同iptables十分相似。 nf-HiPAC和iptables二者可以同时使用 安装需要环境: linux 2.6.26.5 内核源代码 iptables 1.4.4 源代码

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值