Dummynet简单部署

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

部署流程

  1. 准备内核版本
  2. 参看系统内核版本
  3. uname -r

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

  1. 编译dummynet
  2. https://github.com/FS1360472174/dummynet.git 下载包
  3. 上传解压
图片[1]-Dummynet简单部署-IT熊技术站
  • 进入操作目录
cd dummynet-master
图片[2]-Dummynet简单部署-IT熊技术站
  • 编译
make KERNELPATH=/usr/src/kernels/3.10.0-957.el7.x86_64/
图片[3]-Dummynet简单部署-IT熊技术站
  • 加载ipfw 模块
cd kipfw-mod
insmod ipfw_mod.ko
图片[4]-Dummynet简单部署-IT熊技术站
cd ../ipfw
cp ipfw /sbin
chmod 700 /sbin/ipfw
图片[5]-Dummynet简单部署-IT熊技术站
  • 验证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

);
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容