[ovs-dev] [PATCH 2/2 v2] netlink-socket.c: add support for nl_lookup_genl_mcgroup()

Nithin Raju nithin at vmware.com
Mon Aug 25 16:45:08 UTC 2014


While we work out whether nl_sock_join_mcgroup() will be the mechanism
to support VPORT events, it is easy to add support for
nl_lookup_genl_mcgroup() and make progress on the other commands.

In this patch, we implement support for nl_lookup_genl_mcgroup() only
for the VPORT family though, which is all what dpif-linux.c needs.

Validation:
- A ported dpif-linux.c with epoll code commented out went so far as
to call dp_enumerate! DP Dump commands can be implemented next.
---
 lib/netlink-socket.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c
index 98baf58..2a90197 100644
--- a/lib/netlink-socket.c
+++ b/lib/netlink-socket.c
@@ -1172,16 +1172,20 @@ do_lookup_genl_family(const char *name, struct nlattr **attrs,
                       struct ofpbuf **replyp)
 {
     struct nl_sock *sock;
+    struct nlmsghdr *nlmsg;
     struct ofpbuf *reply;
     int error;
     uint16_t family_id;
     const char *family_name;
     uint32_t family_version;
     uint32_t family_attrmax;
+    uint32_t mcgrp_id = OVS_WIN_NL_INVALID_MCGRP_ID;
+    const char *mcgrp_name = NULL;
 
     *replyp = NULL;
     reply = ofpbuf_new(1024);
 
+    /* CTRL_ATTR_MCAST_GROUPS is supported only for VPORT family. */
     if (!strcmp(name, OVS_WIN_CONTROL_FAMILY)) {
         family_id = OVS_WIN_NL_CTRL_FAMILY_ID;
         family_name = OVS_WIN_CONTROL_FAMILY;
@@ -1202,6 +1206,8 @@ do_lookup_genl_family(const char *name, struct nlattr **attrs,
         family_name = OVS_VPORT_FAMILY;
         family_version = OVS_VPORT_VERSION;
         family_attrmax = OVS_VPORT_ATTR_MAX;
+        mcgrp_id = OVS_WIN_NL_VPORT_MCGRP_ID;
+        mcgrp_name = OVS_VPORT_MCGROUP;
     } else if (!strcmp(name, OVS_FLOW_FAMILY)) {
         family_id = OVS_WIN_NL_FLOW_FAMILY_ID;
         family_name = OVS_FLOW_FAMILY;
@@ -1221,6 +1227,21 @@ do_lookup_genl_family(const char *name, struct nlattr **attrs,
     nl_msg_put_u32(reply, CTRL_ATTR_VERSION, family_version);
     nl_msg_put_u32(reply, CTRL_ATTR_MAXATTR, family_attrmax);
 
+    if (mcgrp_id != OVS_WIN_NL_INVALID_MCGRP_ID) {
+        size_t mcgrp_ofs1 = nl_msg_start_nested(reply, CTRL_ATTR_MCAST_GROUPS);
+        size_t mcgrp_ofs2= nl_msg_start_nested(reply,
+            OVS_WIN_NL_VPORT_MCGRP_ID - OVS_WIN_NL_MCGRP_START_ID);
+        nl_msg_put_u32(reply, CTRL_ATTR_MCAST_GRP_ID, mcgrp_id);
+        ovs_assert(mcgrp_name != NULL);
+        nl_msg_put_string(reply, CTRL_ATTR_MCAST_GRP_NAME, mcgrp_name);
+        nl_msg_end_nested(reply, mcgrp_ofs2);
+        nl_msg_end_nested(reply, mcgrp_ofs1);
+    }
+
+    /* Set the total length of the netlink message. */
+    nlmsg = nl_msg_nlmsghdr(reply);
+    nlmsg->nlmsg_len = ofpbuf_size(reply);
+
     if (!nl_policy_parse(reply, NLMSG_HDRLEN + GENL_HDRLEN,
                          family_policy, attrs, ARRAY_SIZE(family_policy))
         || nl_attr_get_u16(attrs[CTRL_ATTR_FAMILY_ID]) == 0) {
-- 
1.7.4.1




More information about the dev mailing list