【OVS2.5.0源码分析】datapath之netlink
来源:互联网 发布:stm32串口接收数据 编辑:程序博客网 时间:2024/05/01 14:04
ovs datapath是通过netlink与用户态进行通信的,实现dp、端口、流表、packet的操作。 netlink的注册是在datapath模块的初始化函数中实现的。
1、dp_init函数
static int __init dp_init(void){int err;BUILD_BUG_ON(sizeof(struct ovs_skb_cb) > FIELD_SIZEOF(struct sk_buff, cb));pr_info("Open vSwitch switching datapath %s\n", VERSION);err = compat_init();if (err)goto error;err = action_fifos_init();if (err)goto error_compat_exit;err = ovs_internal_dev_rtnl_link_register();if (err)goto error_action_fifos_exit;err = ovs_flow_init();if (err)goto error_unreg_rtnl_link;err = ovs_vport_init();if (err)goto error_flow_exit;err = register_pernet_device(&ovs_net_ops);if (err)goto error_vport_exit;err = register_netdevice_notifier(&ovs_dp_device_notifier);if (err)goto error_netns_exit;err = ovs_netdev_init();if (err)goto error_unreg_notifier;err = dp_register_genl();//注册netlink处理函数if (err < 0)goto error_unreg_netdev;return 0;error_unreg_netdev:ovs_netdev_exit();error_unreg_notifier:unregister_netdevice_notifier(&ovs_dp_device_notifier);error_netns_exit:unregister_pernet_device(&ovs_net_ops);error_vport_exit:ovs_vport_exit();error_flow_exit:ovs_flow_exit();error_unreg_rtnl_link:ovs_internal_dev_rtnl_link_unregister();error_action_fifos_exit:action_fifos_exit();error_compat_exit:compat_exit();error:return err;}
2、genl_register_family函数
#define genl_register_family rpl_genl_register_familystatic inline int rpl_genl_register_family(struct genl_family *family){family->module = THIS_MODULE;return rpl___genl_register_family(family); //注册netlink}3、rpl___genl_register_family函数
int rpl___genl_register_family(struct rpl_genl_family *f){int err;f->compat_family.id = f->id;f->compat_family.hdrsize = f->hdrsize;strncpy(f->compat_family.name, f->name, GENL_NAMSIZ);f->compat_family.version = f->version;f->compat_family.maxattr = f->maxattr;f->compat_family.netnsok = f->netnsok;#ifdef HAVE_PARALLEL_OPSf->compat_family.parallel_ops = f->parallel_ops;#endiferr = genl_register_family_with_ops(&f->compat_family,//调用系统接口,可以不用关注消息处理,可以把ops作为netlink的处理入口函数 (struct genl_ops *) f->ops, f->n_ops);if (err)goto error;if (f->mcgrps) {/* Need to Fix GROUP_ID() for more than one group. */BUG_ON(f->n_mcgrps > 1);err = genl_register_mc_group(&f->compat_family,//调用系统接口,暂时只看到dp中用ovs_notify中在使用,没想明白,估计要深入netlink实现才能搞清楚 (struct genl_multicast_group *) f->mcgrps);if (err)goto error;}error:return err;}netlink的操作是由dp_genl_families定义的,一共有4类。
static struct genl_family *dp_genl_families[] = {&dp_datapath_genl_family,&dp_vport_genl_family,&dp_flow_genl_family,&dp_packet_genl_family,};datapath netlink定义:
static struct genl_family dp_datapath_genl_family = {.id = GENL_ID_GENERATE,.hdrsize = sizeof(struct ovs_header),.name = OVS_DATAPATH_FAMILY,.version = OVS_DATAPATH_VERSION,.maxattr = OVS_DP_ATTR_MAX,.netnsok = true,.parallel_ops = true,.ops = dp_datapath_genl_ops,.n_ops = ARRAY_SIZE(dp_datapath_genl_ops),.mcgrps = &ovs_dp_datapath_multicast_group,.n_mcgrps = 1,};static struct genl_ops dp_datapath_genl_ops[] = {{ .cmd = OVS_DP_CMD_NEW, .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ .policy = datapath_policy, .doit = ovs_dp_cmd_new //创建datapath},{ .cmd = OVS_DP_CMD_DEL, .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ .policy = datapath_policy, .doit = ovs_dp_cmd_del //删除datapath},{ .cmd = OVS_DP_CMD_GET, .flags = 0, /* OK for unprivileged users. */ .policy = datapath_policy, .doit = ovs_dp_cmd_get, .dumpit = ovs_dp_cmd_dump //导出datapath},{ .cmd = OVS_DP_CMD_SET, .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ .policy = datapath_policy, .doit = ovs_dp_cmd_set, //修改datapath},};vport netlink定义:
struct genl_family dp_vport_genl_family = {.id = GENL_ID_GENERATE,.hdrsize = sizeof(struct ovs_header),.name = OVS_VPORT_FAMILY,.version = OVS_VPORT_VERSION,.maxattr = OVS_VPORT_ATTR_MAX,.netnsok = true,.parallel_ops = true,.ops = dp_vport_genl_ops,.n_ops = ARRAY_SIZE(dp_vport_genl_ops),.mcgrps = &ovs_dp_vport_multicast_group,.n_mcgrps = 1,};static struct genl_ops dp_vport_genl_ops[] = {{ .cmd = OVS_VPORT_CMD_NEW, .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ .policy = vport_policy, .doit = ovs_vport_cmd_new//创建vport},{ .cmd = OVS_VPORT_CMD_DEL, .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ .policy = vport_policy, .doit = ovs_vport_cmd_del//删除vport},{ .cmd = OVS_VPORT_CMD_GET, .flags = 0, /* OK for unprivileged users. */ .policy = vport_policy, .doit = ovs_vport_cmd_get, .dumpit = ovs_vport_cmd_dump//导出vport},{ .cmd = OVS_VPORT_CMD_SET, .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ .policy = vport_policy, .doit = ovs_vport_cmd_set,//修改vport},};精确流表 netlink定义:
static struct genl_family dp_flow_genl_family = {.id = GENL_ID_GENERATE,.hdrsize = sizeof(struct ovs_header),.name = OVS_FLOW_FAMILY,.version = OVS_FLOW_VERSION,.maxattr = OVS_FLOW_ATTR_MAX,.netnsok = true,.parallel_ops = true,.ops = dp_flow_genl_ops,.n_ops = ARRAY_SIZE(dp_flow_genl_ops),.mcgrps = &ovs_dp_flow_multicast_group,.n_mcgrps = 1,};static struct genl_ops dp_flow_genl_ops[] = {{ .cmd = OVS_FLOW_CMD_NEW, .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ .policy = flow_policy, .doit = ovs_flow_cmd_new//添加精确流表},{ .cmd = OVS_FLOW_CMD_DEL, .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ .policy = flow_policy, .doit = ovs_flow_cmd_del//删除精确流表},{ .cmd = OVS_FLOW_CMD_GET, .flags = 0, /* OK for unprivileged users. */ .policy = flow_policy, .doit = ovs_flow_cmd_get, .dumpit = ovs_flow_cmd_dump//导出精确流表},{ .cmd = OVS_FLOW_CMD_SET, .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ .policy = flow_policy, .doit = ovs_flow_cmd_set,//修改精确流表},};packet netlink定义:
static struct genl_family dp_packet_genl_family = {.id = GENL_ID_GENERATE,.hdrsize = sizeof(struct ovs_header),.name = OVS_PACKET_FAMILY,.version = OVS_PACKET_VERSION,.maxattr = OVS_PACKET_ATTR_MAX,.netnsok = true,.parallel_ops = true,.ops = dp_packet_genl_ops,.n_ops = ARRAY_SIZE(dp_packet_genl_ops),};static struct genl_ops dp_packet_genl_ops[] = {{ .cmd = OVS_PACKET_CMD_EXECUTE, .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ .policy = packet_policy, .doit = ovs_packet_cmd_execute//执行报文action操作}};
0 0
- 【OVS2.5.0源码分析】datapath之netlink
- 【OVS2.5.0源码分析】datapath之主流程分析
- 【OVS2.5.0源码分析】datapath之action分析(1)
- 【OVS2.5.0源码分析】datapath之action分析(2)
- 【OVS2.5.0源码分析】datapath之action分析(3)
- 【OVS2.5.0源码分析】datapath之action分析(4)
- 【OVS2.5.0源码分析】datapath之action分析(5)
- 【OVS2.5.0源码分析】datapath之action分析(6)
- 【OVS2.5.0源码分析】datapath之action分析(7)
- 【OVS2.5.0源码分析】datapath之action分析(8)
- 【OVS2.5.0源码分析】datapath之流表查询
- 【OVS2.5.0源码分析】datapath之流表创建过程
- 【OVS2.5源码解读】datapath的netlink机制
- 【OVS2.5源码解读】datapath主流程分析
- 【OVS2.5.0源码分析】dpif向dp发送netlink消息分析
- 【OVS2.5.0源码分析】ofpbuf数据结构分析
- 【OVS2.5.0源码分析】nlattr数据结构分析
- 【OVS2.5.0源码分析】bridge&bundle&port分析(1)
- 指定viewcontroller的entrypoint
- 最长公共子序列问题 Longest Common Subsequence problem
- 高德地图 react-native(一)
- Increasing Triplet Subsequence
- 几种segue的使用场景
- 【OVS2.5.0源码分析】datapath之netlink
- 兄弟会第六天上课笔记
- 七款代码味道识别工具【简介】
- 软件设计度量工具inFusion(一):inFusion的基本概念
- 软件设计度量工具inFusion(二):看懂inFusion度量结果
- nodejs中exports与module.exports的区别详细介绍
- 2016.9.13
- 【OVS2.5.0源码分析】sFlow实现分析(2)
- spring框架开发笔记 lesson3 AOP