本文分享自天翼云开发者社区《Dummynet简单部署
作者:凸凹

部署流程
^准备内核版本 
^参看系统内核版本
uname -r 
我们需要将ipfw编译成内核模块,请确保ipfw用到的内核源码版本同你linux系统运行内核版本一致。
^编译dummynet
https://github.com/FS1360472174/dummynet.git  下载包
^上传解压
image.png
^进入操作目录
cd dummynet-master 
image.png
^编译
make KERNELPATH=/usr/src/kernels/3.10.0-957.el7.x86_64/
image.png
^加载ipfw 模块
cd kipfw-modinsmod
ipfw_mod.ko
image.png
cd ../ipfw
cp ipfw /sbin
chmod 700 /sbin/ipfw
image.png

^验证ipfw
ipfw add pipe 2 in proto tcp 
可选择地,将ipfw 设置为boot启动
cp /root/dummynet-master/kipfw-mod/ipfw_mod.ko /lib/modules/3.10.0-957.el7.x86_64/kernel/net/netfilter
depmod
sh -c 'echo modprobe ipfw_mod >> /etc/rc.modules'
chmod +x /etc/rc.modules

^附录
问题分析
1.insmod: ERROR: could not insert module ipfw_mod.ko: Invalid module format
解决:
modinfo ipfw_mod.ko 看下vermagic版本是不是uname -r的版本。
然后重新编译ipfw 模块
make KERNELPATH=/usr/src/kernels/3.10.0-957.el7.x86_64

2.ipfw: getsockopt(IP_FW_ADD): Protocol not available 
解决:
ipfw 模块未加载到内核
可以lsmod |grep ipfw看下
需要重述上述步骤,将ipfw编译进内核模块

3.编译模块时报错
类似于ipfw2_mod.c line 848 nf_hook_ops.hk struct have errors. 
解决:
Hook structure 在各个版本的linux中定义不一样,所以如果是从dummynet 站点中下载的老的dummynet 包可能就有错误。
查看下当前所用系统的hook 结构 
/usr/src/kernels/linux-3.10.0-957.el7/include/linux/netfilter.h
定义了nf_hook_ops,nf_hookfn的结构
struct nf_hook_ops {
struct list_head list;
     / User fills in from here down. /   
nf_hookfn       *hook;   
struct module   *owner;   
void            *priv;   
u_int8_t        pf;   
unsigned int    hooknum;   
/ Hooks are ordered in ascending priority. /   
int             priority;    
/ Reserved for use in the future RHEL versions. Set to zero.
unsigned long   __rht_reserved1;   
unsigned long   __rht_reserved2;   
unsigned long   __rht_reserved3;   
unsigned long   __rht_reserved4;   
unsigned long   __rht_reserved5;
}; 
typedef unsigned int nf_hookfn(const struct nf_hook_ops *ops,

struct sk_buff *skb,  
const struct net_device *in,  
const struct net_device *out,

ifndef __GENKSYMS__  

const struct nf_hook_state *state

else  

int (okfn)(struct sk_buff )

endif  

);


天翼云开发者社区
91 声望2 粉丝

天翼云是中国电信倾力打造的云服务品牌,致力于成为领先的云计算服务提供商。提供云主机、CDN、云电脑、大数据及AI等全线产品和场景化解决方案。


引用和评论

0 条评论