我想在ovs收发包的时候加printk打印
int ovs_vport_receive(struct vport *vport, struct sk_buff *skb,
const struct ip_tunnel_info *tun_info)
{
struct sw_flow_key key;
int error;
OVS_CB(skb)->input_vport = vport;
OVS_CB(skb)->mru = 0;
OVS_CB(skb)->cutlen = 0;
if (unlikely(dev_net(skb->dev) != ovs_dp_get_net(vport->dp))) {
u32 mark;
mark = skb->mark;
skb_scrub_packet(skb, true);
skb->mark = mark;
tun_info = NULL;
}
printk(KERN_ERR "\r\n[%s]%d!!!print1 !!!\r\n",__FUNCTION__,__LINE__);//调试打印
ovs_skb_init_inner_protocol(skb);
skb_clear_ovs_gso_cb(skb);
/* Extract flow from 'skb' into 'key'. */
error = ovs_flow_key_extract(tun_info, skb, &key);
if (unlikely(error)) {
kfree_skb(skb);
return error;
}
ovs_dp_process_packet(skb, &key);
return 0;
}
修改代码后要在ovs安装目录重新编译
./configure --prefix=/usr --with-linux=/lib/modules/`uname -r`/build //可不必执行
make //必须执行
make install //可不必执行
先停止原来的ovs进程,ps -e就搜不到了
root@nettraffic-vm:~/openvswitch/openvswitch-2.15.0# ovs-ctl stop
* Exiting ovs-vswitchd (79127)
* Exiting ovsdb-server (79124)
卸载mod
rmmod openvswitch
安装新编译的mod
insmod datapath/linux/openvswitch.ko
若出现报错
[20210829_14:01:59]insmod: ERROR: could not insert module datapath/linux/openvswitch.ko: Unknown symbol in module
dmeg查看信息
[20210829_14:20:01][16226.692278] openvswitch: Unknown symbol nf_nat_alloc_null_binding (err 0)
[20210829_14:20:01][16226.692315] openvswitch: Unknown symbol xfrm6_tunnel_register (err 0)
[20210829_14:20:01][16226.692419] openvswitch: Unknown symbol nf_nat_packet (err 0)
[20210829_14:20:01][16226.692515] openvswitch: Unknown symbol nf_nat_setup_info (err 0)
[20210829_14:20:01][16226.692596] openvswitch: Unknown symbol nf_nat_icmp_reply_translation (err 0)
[20210829_14:20:01][16226.692623] openvswitch: Unknown symbol nf_nat_icmpv6_reply_translation (err 0)
[20210829_14:20:01][16226.692768] openvswitch: Unknown symbol nf_ct_nat_ext_add (err 0)
[20210829_14:20:01][16226.692809] openvswitch: Unknown symbol xfrm6_tunnel_deregister (err 0)
说明openvswitch.ko的依赖包没有,查找依赖项
[20210829_14:07:40]root@nettraffic-vm:~/openvswitch/openvswitch-2.15.0# modinfo ./datapath/linux/openvswitch.ko |grep depends
[20210829_14:07:40]depends: nf_conntrack,tunnel6,nf_nat,nf_defrag_ipv6,libcrc32c,nf_nat_ipv6,nf_nat_ipv4
要用modprobe将这些都加入
[20210829_14:08:03]root@nettraffic-vm:~/openvswitch/openvswitch-2.15.0# modprobe nf_conntrack
[20210829_14:08:13]root@nettraffic-vm:~/openvswitch/openvswitch-2.15.0# modprobe tunnel6
[20210829_14:08:19]root@nettraffic-vm:~/openvswitch/openvswitch-2.15.0# modprobe nf_nat
[20210829_14:08:25]root@nettraffic-vm:~/openvswitch/openvswitch-2.15.0# modprobe nf_defrag_ipv6
[20210829_14:08:30]root@nettraffic-vm:~/openvswitch/openvswitch-2.15.0# modprobe libcrc32c
[20210829_14:08:36]root@nettraffic-vm:~/openvswitch/openvswitch-2.15.0# modprobe nf_nat_ipv6
[20210829_14:08:42]root@nettraffic-vm:~/openvswitch/openvswitch-2.15.0# modprobe nf_nat_ipv4
然后insmod openvswitch.ko就可以成功了。
下面继续重启安装
make modules_install
modprobe openvswitch
重启ovs
/etc/init.d/openvswitch-switch start
ovsdb-tool create /usr/local/etc/openvswitch/conf.db /usr/local/share/openvswitch/vswitch.ovsschema
ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \--remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile --detach --log-file
ovs-vsctl --no-wait init
ovs-vswitchd --pidfile --detach
启动mininet后,h1 ping h2。打开一个终端输入dmesg,在最下方可以看到加打印的信息。
[20210829_14:20:01][16916.135075]
[20210829_14:20:01] [ovs_vport_receive]546!!!print1 !!!
[20210829_14:20:01][16916.135111]
[20210829_14:20:01] [ovs_vport_receive]546!!!print1 !!!
[20210829_14:20:01][16917.139510]
[20210829_14:20:01] [ovs_vport_receive]546!!!print1 !!!
[20210829_14:20:01][16917.139553]
[20210829_14:20:01] [ovs_vport_receive]546!!!print1 !!!
参考文档: