diff options
author | Pravin B Shelar <pshelar@nicira.com> | 2014-05-06 19:44:50 -0400 |
---|---|---|
committer | Pravin B Shelar <pshelar@nicira.com> | 2014-05-22 19:27:37 -0400 |
commit | 0c200ef94c9492205e18a18c25650cf27939889c (patch) | |
tree | a43c54ba306e05f04c3e6911047bd4a4dded2ad7 /net/openvswitch | |
parent | 893f139b9a6c00c097b9082a90f3041cfb3a0d20 (diff) |
openvswitch: Simplify genetlink code.
Following patch get rid of struct genl_family_and_ops which is
redundant due to changes to struct genl_family.
Signed-off-by: Kyle Mestery <mestery@noironetworks.com>
Acked-by: Kyle Mestery <mestery@noironetworks.com>
Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Diffstat (limited to 'net/openvswitch')
-rw-r--r-- | net/openvswitch/datapath.c | 185 |
1 files changed, 90 insertions, 95 deletions
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index 6bc9d94c8df2..0d407bca81e3 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c | |||
@@ -44,11 +44,11 @@ | |||
44 | #include <linux/netfilter_ipv4.h> | 44 | #include <linux/netfilter_ipv4.h> |
45 | #include <linux/inetdevice.h> | 45 | #include <linux/inetdevice.h> |
46 | #include <linux/list.h> | 46 | #include <linux/list.h> |
47 | #include <linux/lockdep.h> | ||
48 | #include <linux/openvswitch.h> | 47 | #include <linux/openvswitch.h> |
49 | #include <linux/rculist.h> | 48 | #include <linux/rculist.h> |
50 | #include <linux/dmi.h> | 49 | #include <linux/dmi.h> |
51 | #include <linux/workqueue.h> | 50 | #include <linux/genetlink.h> |
51 | #include <net/genetlink.h> | ||
52 | #include <net/genetlink.h> | 52 | #include <net/genetlink.h> |
53 | #include <net/net_namespace.h> | 53 | #include <net/net_namespace.h> |
54 | #include <net/netns/generic.h> | 54 | #include <net/netns/generic.h> |
@@ -62,6 +62,22 @@ | |||
62 | 62 | ||
63 | int ovs_net_id __read_mostly; | 63 | int ovs_net_id __read_mostly; |
64 | 64 | ||
65 | static struct genl_family dp_packet_genl_family; | ||
66 | static struct genl_family dp_flow_genl_family; | ||
67 | static struct genl_family dp_datapath_genl_family; | ||
68 | |||
69 | static struct genl_multicast_group ovs_dp_flow_multicast_group = { | ||
70 | .name = OVS_FLOW_MCGROUP | ||
71 | }; | ||
72 | |||
73 | static struct genl_multicast_group ovs_dp_datapath_multicast_group = { | ||
74 | .name = OVS_DATAPATH_MCGROUP | ||
75 | }; | ||
76 | |||
77 | struct genl_multicast_group ovs_dp_vport_multicast_group = { | ||
78 | .name = OVS_VPORT_MCGROUP | ||
79 | }; | ||
80 | |||
65 | /* Check if need to build a reply message. | 81 | /* Check if need to build a reply message. |
66 | * OVS userspace sets the NLM_F_ECHO flag if it needs the reply. */ | 82 | * OVS userspace sets the NLM_F_ECHO flag if it needs the reply. */ |
67 | static bool ovs_must_notify(struct genl_info *info, | 83 | static bool ovs_must_notify(struct genl_info *info, |
@@ -272,16 +288,6 @@ out: | |||
272 | u64_stats_update_end(&stats->syncp); | 288 | u64_stats_update_end(&stats->syncp); |
273 | } | 289 | } |
274 | 290 | ||
275 | static struct genl_family dp_packet_genl_family = { | ||
276 | .id = GENL_ID_GENERATE, | ||
277 | .hdrsize = sizeof(struct ovs_header), | ||
278 | .name = OVS_PACKET_FAMILY, | ||
279 | .version = OVS_PACKET_VERSION, | ||
280 | .maxattr = OVS_PACKET_ATTR_MAX, | ||
281 | .netnsok = true, | ||
282 | .parallel_ops = true, | ||
283 | }; | ||
284 | |||
285 | int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb, | 291 | int ovs_dp_upcall(struct datapath *dp, struct sk_buff *skb, |
286 | const struct dp_upcall_info *upcall_info) | 292 | const struct dp_upcall_info *upcall_info) |
287 | { | 293 | { |
@@ -600,6 +606,18 @@ static const struct genl_ops dp_packet_genl_ops[] = { | |||
600 | } | 606 | } |
601 | }; | 607 | }; |
602 | 608 | ||
609 | static struct genl_family dp_packet_genl_family = { | ||
610 | .id = GENL_ID_GENERATE, | ||
611 | .hdrsize = sizeof(struct ovs_header), | ||
612 | .name = OVS_PACKET_FAMILY, | ||
613 | .version = OVS_PACKET_VERSION, | ||
614 | .maxattr = OVS_PACKET_ATTR_MAX, | ||
615 | .netnsok = true, | ||
616 | .parallel_ops = true, | ||
617 | .ops = dp_packet_genl_ops, | ||
618 | .n_ops = ARRAY_SIZE(dp_packet_genl_ops), | ||
619 | }; | ||
620 | |||
603 | static void get_dp_stats(struct datapath *dp, struct ovs_dp_stats *stats, | 621 | static void get_dp_stats(struct datapath *dp, struct ovs_dp_stats *stats, |
604 | struct ovs_dp_megaflow_stats *mega_stats) | 622 | struct ovs_dp_megaflow_stats *mega_stats) |
605 | { | 623 | { |
@@ -631,26 +649,6 @@ static void get_dp_stats(struct datapath *dp, struct ovs_dp_stats *stats, | |||
631 | } | 649 | } |
632 | } | 650 | } |
633 | 651 | ||
634 | static const struct nla_policy flow_policy[OVS_FLOW_ATTR_MAX + 1] = { | ||
635 | [OVS_FLOW_ATTR_KEY] = { .type = NLA_NESTED }, | ||
636 | [OVS_FLOW_ATTR_ACTIONS] = { .type = NLA_NESTED }, | ||
637 | [OVS_FLOW_ATTR_CLEAR] = { .type = NLA_FLAG }, | ||
638 | }; | ||
639 | |||
640 | static struct genl_family dp_flow_genl_family = { | ||
641 | .id = GENL_ID_GENERATE, | ||
642 | .hdrsize = sizeof(struct ovs_header), | ||
643 | .name = OVS_FLOW_FAMILY, | ||
644 | .version = OVS_FLOW_VERSION, | ||
645 | .maxattr = OVS_FLOW_ATTR_MAX, | ||
646 | .netnsok = true, | ||
647 | .parallel_ops = true, | ||
648 | }; | ||
649 | |||
650 | static struct genl_multicast_group ovs_dp_flow_multicast_group = { | ||
651 | .name = OVS_FLOW_MCGROUP | ||
652 | }; | ||
653 | |||
654 | static size_t ovs_flow_cmd_msg_size(const struct sw_flow_actions *acts) | 652 | static size_t ovs_flow_cmd_msg_size(const struct sw_flow_actions *acts) |
655 | { | 653 | { |
656 | return NLMSG_ALIGN(sizeof(struct ovs_header)) | 654 | return NLMSG_ALIGN(sizeof(struct ovs_header)) |
@@ -1186,7 +1184,13 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
1186 | return skb->len; | 1184 | return skb->len; |
1187 | } | 1185 | } |
1188 | 1186 | ||
1189 | static const struct genl_ops dp_flow_genl_ops[] = { | 1187 | static const struct nla_policy flow_policy[OVS_FLOW_ATTR_MAX + 1] = { |
1188 | [OVS_FLOW_ATTR_KEY] = { .type = NLA_NESTED }, | ||
1189 | [OVS_FLOW_ATTR_ACTIONS] = { .type = NLA_NESTED }, | ||
1190 | [OVS_FLOW_ATTR_CLEAR] = { .type = NLA_FLAG }, | ||
1191 | }; | ||
1192 | |||
1193 | static struct genl_ops dp_flow_genl_ops[] = { | ||
1190 | { .cmd = OVS_FLOW_CMD_NEW, | 1194 | { .cmd = OVS_FLOW_CMD_NEW, |
1191 | .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ | 1195 | .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
1192 | .policy = flow_policy, | 1196 | .policy = flow_policy, |
@@ -1210,24 +1214,18 @@ static const struct genl_ops dp_flow_genl_ops[] = { | |||
1210 | }, | 1214 | }, |
1211 | }; | 1215 | }; |
1212 | 1216 | ||
1213 | static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = { | 1217 | static struct genl_family dp_flow_genl_family = { |
1214 | [OVS_DP_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 }, | ||
1215 | [OVS_DP_ATTR_UPCALL_PID] = { .type = NLA_U32 }, | ||
1216 | [OVS_DP_ATTR_USER_FEATURES] = { .type = NLA_U32 }, | ||
1217 | }; | ||
1218 | |||
1219 | static struct genl_family dp_datapath_genl_family = { | ||
1220 | .id = GENL_ID_GENERATE, | 1218 | .id = GENL_ID_GENERATE, |
1221 | .hdrsize = sizeof(struct ovs_header), | 1219 | .hdrsize = sizeof(struct ovs_header), |
1222 | .name = OVS_DATAPATH_FAMILY, | 1220 | .name = OVS_FLOW_FAMILY, |
1223 | .version = OVS_DATAPATH_VERSION, | 1221 | .version = OVS_FLOW_VERSION, |
1224 | .maxattr = OVS_DP_ATTR_MAX, | 1222 | .maxattr = OVS_FLOW_ATTR_MAX, |
1225 | .netnsok = true, | 1223 | .netnsok = true, |
1226 | .parallel_ops = true, | 1224 | .parallel_ops = true, |
1227 | }; | 1225 | .ops = dp_flow_genl_ops, |
1228 | 1226 | .n_ops = ARRAY_SIZE(dp_flow_genl_ops), | |
1229 | static struct genl_multicast_group ovs_dp_datapath_multicast_group = { | 1227 | .mcgrps = &ovs_dp_flow_multicast_group, |
1230 | .name = OVS_DATAPATH_MCGROUP | 1228 | .n_mcgrps = 1, |
1231 | }; | 1229 | }; |
1232 | 1230 | ||
1233 | static size_t ovs_dp_cmd_msg_size(void) | 1231 | static size_t ovs_dp_cmd_msg_size(void) |
@@ -1574,7 +1572,13 @@ static int ovs_dp_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb) | |||
1574 | return skb->len; | 1572 | return skb->len; |
1575 | } | 1573 | } |
1576 | 1574 | ||
1577 | static const struct genl_ops dp_datapath_genl_ops[] = { | 1575 | static const struct nla_policy datapath_policy[OVS_DP_ATTR_MAX + 1] = { |
1576 | [OVS_DP_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 }, | ||
1577 | [OVS_DP_ATTR_UPCALL_PID] = { .type = NLA_U32 }, | ||
1578 | [OVS_DP_ATTR_USER_FEATURES] = { .type = NLA_U32 }, | ||
1579 | }; | ||
1580 | |||
1581 | static struct genl_ops dp_datapath_genl_ops[] = { | ||
1578 | { .cmd = OVS_DP_CMD_NEW, | 1582 | { .cmd = OVS_DP_CMD_NEW, |
1579 | .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ | 1583 | .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
1580 | .policy = datapath_policy, | 1584 | .policy = datapath_policy, |
@@ -1598,27 +1602,18 @@ static const struct genl_ops dp_datapath_genl_ops[] = { | |||
1598 | }, | 1602 | }, |
1599 | }; | 1603 | }; |
1600 | 1604 | ||
1601 | static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = { | 1605 | static struct genl_family dp_datapath_genl_family = { |
1602 | [OVS_VPORT_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 }, | ||
1603 | [OVS_VPORT_ATTR_STATS] = { .len = sizeof(struct ovs_vport_stats) }, | ||
1604 | [OVS_VPORT_ATTR_PORT_NO] = { .type = NLA_U32 }, | ||
1605 | [OVS_VPORT_ATTR_TYPE] = { .type = NLA_U32 }, | ||
1606 | [OVS_VPORT_ATTR_UPCALL_PID] = { .type = NLA_U32 }, | ||
1607 | [OVS_VPORT_ATTR_OPTIONS] = { .type = NLA_NESTED }, | ||
1608 | }; | ||
1609 | |||
1610 | struct genl_family dp_vport_genl_family = { | ||
1611 | .id = GENL_ID_GENERATE, | 1606 | .id = GENL_ID_GENERATE, |
1612 | .hdrsize = sizeof(struct ovs_header), | 1607 | .hdrsize = sizeof(struct ovs_header), |
1613 | .name = OVS_VPORT_FAMILY, | 1608 | .name = OVS_DATAPATH_FAMILY, |
1614 | .version = OVS_VPORT_VERSION, | 1609 | .version = OVS_DATAPATH_VERSION, |
1615 | .maxattr = OVS_VPORT_ATTR_MAX, | 1610 | .maxattr = OVS_DP_ATTR_MAX, |
1616 | .netnsok = true, | 1611 | .netnsok = true, |
1617 | .parallel_ops = true, | 1612 | .parallel_ops = true, |
1618 | }; | 1613 | .ops = dp_datapath_genl_ops, |
1619 | 1614 | .n_ops = ARRAY_SIZE(dp_datapath_genl_ops), | |
1620 | static struct genl_multicast_group ovs_dp_vport_multicast_group = { | 1615 | .mcgrps = &ovs_dp_datapath_multicast_group, |
1621 | .name = OVS_VPORT_MCGROUP | 1616 | .n_mcgrps = 1, |
1622 | }; | 1617 | }; |
1623 | 1618 | ||
1624 | /* Called with ovs_mutex or RCU read lock. */ | 1619 | /* Called with ovs_mutex or RCU read lock. */ |
@@ -1941,7 +1936,16 @@ out: | |||
1941 | return skb->len; | 1936 | return skb->len; |
1942 | } | 1937 | } |
1943 | 1938 | ||
1944 | static const struct genl_ops dp_vport_genl_ops[] = { | 1939 | static const struct nla_policy vport_policy[OVS_VPORT_ATTR_MAX + 1] = { |
1940 | [OVS_VPORT_ATTR_NAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ - 1 }, | ||
1941 | [OVS_VPORT_ATTR_STATS] = { .len = sizeof(struct ovs_vport_stats) }, | ||
1942 | [OVS_VPORT_ATTR_PORT_NO] = { .type = NLA_U32 }, | ||
1943 | [OVS_VPORT_ATTR_TYPE] = { .type = NLA_U32 }, | ||
1944 | [OVS_VPORT_ATTR_UPCALL_PID] = { .type = NLA_U32 }, | ||
1945 | [OVS_VPORT_ATTR_OPTIONS] = { .type = NLA_NESTED }, | ||
1946 | }; | ||
1947 | |||
1948 | static struct genl_ops dp_vport_genl_ops[] = { | ||
1945 | { .cmd = OVS_VPORT_CMD_NEW, | 1949 | { .cmd = OVS_VPORT_CMD_NEW, |
1946 | .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ | 1950 | .flags = GENL_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */ |
1947 | .policy = vport_policy, | 1951 | .policy = vport_policy, |
@@ -1965,26 +1969,25 @@ static const struct genl_ops dp_vport_genl_ops[] = { | |||
1965 | }, | 1969 | }, |
1966 | }; | 1970 | }; |
1967 | 1971 | ||
1968 | struct genl_family_and_ops { | 1972 | struct genl_family dp_vport_genl_family = { |
1969 | struct genl_family *family; | 1973 | .id = GENL_ID_GENERATE, |
1970 | const struct genl_ops *ops; | 1974 | .hdrsize = sizeof(struct ovs_header), |
1971 | int n_ops; | 1975 | .name = OVS_VPORT_FAMILY, |
1972 | const struct genl_multicast_group *group; | 1976 | .version = OVS_VPORT_VERSION, |
1977 | .maxattr = OVS_VPORT_ATTR_MAX, | ||
1978 | .netnsok = true, | ||
1979 | .parallel_ops = true, | ||
1980 | .ops = dp_vport_genl_ops, | ||
1981 | .n_ops = ARRAY_SIZE(dp_vport_genl_ops), | ||
1982 | .mcgrps = &ovs_dp_vport_multicast_group, | ||
1983 | .n_mcgrps = 1, | ||
1973 | }; | 1984 | }; |
1974 | 1985 | ||
1975 | static const struct genl_family_and_ops dp_genl_families[] = { | 1986 | static struct genl_family * const dp_genl_families[] = { |
1976 | { &dp_datapath_genl_family, | 1987 | &dp_datapath_genl_family, |
1977 | dp_datapath_genl_ops, ARRAY_SIZE(dp_datapath_genl_ops), | 1988 | &dp_vport_genl_family, |
1978 | &ovs_dp_datapath_multicast_group }, | 1989 | &dp_flow_genl_family, |
1979 | { &dp_vport_genl_family, | 1990 | &dp_packet_genl_family, |
1980 | dp_vport_genl_ops, ARRAY_SIZE(dp_vport_genl_ops), | ||
1981 | &ovs_dp_vport_multicast_group }, | ||
1982 | { &dp_flow_genl_family, | ||
1983 | dp_flow_genl_ops, ARRAY_SIZE(dp_flow_genl_ops), | ||
1984 | &ovs_dp_flow_multicast_group }, | ||
1985 | { &dp_packet_genl_family, | ||
1986 | dp_packet_genl_ops, ARRAY_SIZE(dp_packet_genl_ops), | ||
1987 | NULL }, | ||
1988 | }; | 1991 | }; |
1989 | 1992 | ||
1990 | static void dp_unregister_genl(int n_families) | 1993 | static void dp_unregister_genl(int n_families) |
@@ -1992,33 +1995,25 @@ static void dp_unregister_genl(int n_families) | |||
1992 | int i; | 1995 | int i; |
1993 | 1996 | ||
1994 | for (i = 0; i < n_families; i++) | 1997 | for (i = 0; i < n_families; i++) |
1995 | genl_unregister_family(dp_genl_families[i].family); | 1998 | genl_unregister_family(dp_genl_families[i]); |
1996 | } | 1999 | } |
1997 | 2000 | ||
1998 | static int dp_register_genl(void) | 2001 | static int dp_register_genl(void) |
1999 | { | 2002 | { |
2000 | int n_registered; | ||
2001 | int err; | 2003 | int err; |
2002 | int i; | 2004 | int i; |
2003 | 2005 | ||
2004 | n_registered = 0; | ||
2005 | for (i = 0; i < ARRAY_SIZE(dp_genl_families); i++) { | 2006 | for (i = 0; i < ARRAY_SIZE(dp_genl_families); i++) { |
2006 | const struct genl_family_and_ops *f = &dp_genl_families[i]; | ||
2007 | 2007 | ||
2008 | f->family->ops = f->ops; | 2008 | err = genl_register_family(dp_genl_families[i]); |
2009 | f->family->n_ops = f->n_ops; | ||
2010 | f->family->mcgrps = f->group; | ||
2011 | f->family->n_mcgrps = f->group ? 1 : 0; | ||
2012 | err = genl_register_family(f->family); | ||
2013 | if (err) | 2009 | if (err) |
2014 | goto error; | 2010 | goto error; |
2015 | n_registered++; | ||
2016 | } | 2011 | } |
2017 | 2012 | ||
2018 | return 0; | 2013 | return 0; |
2019 | 2014 | ||
2020 | error: | 2015 | error: |
2021 | dp_unregister_genl(n_registered); | 2016 | dp_unregister_genl(i); |
2022 | return err; | 2017 | return err; |
2023 | } | 2018 | } |
2024 | 2019 | ||