专栏
天翼云开发者社区

Dummynet简单部署

2023-05-17 17:05:22 57阅读

部署流程

^准备内核版本

 

^参看系统内核版本

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

   );

  • 0
  • 0
  • 0
0 评论
0/1000
评论(0) 发表评论
凸凹

凸凹

2 篇文章 0 粉丝
关注

Dummynet简单部署

2023-05-17 17:05:22 57阅读

部署流程

^准备内核版本

 

^参看系统内核版本

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

   );

文章来自专栏

产品测试-tools

2 篇文章 1 订阅
0 评论
0/1000
评论(0) 发表评论
  • 0
    点赞
  • 0
    收藏
  • 0
    评论