Dummynet简单部署

Tianyiyun · · 320 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

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

部署流程

^准备内核版本

^参看系统内核版本

uname -r

我们需要将ipfw编译成内核模块,请确保ipfw用到的内核源码版本同你linux系统运行内核版本一致。

^编译dummynet

https://github.com/FS1360472174/dummynet.git 下载包

^上传解压

^进入操作目录

cd dummynet-master

^编译

make KERNELPATH=/usr/src/kernels/3.10.0-957.el7.x86_64/

 

^加载ipfw 模块

cd kipfw-mod

insmod ipfw_mod.ko

cd ../ipfw

cp ipfw /sbin

chmod 700 /sbin/ipfw

^验证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

);

320 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传