Implement dpif netlink register sFlow upcall callback API.

Signed-off-by: Chris Mi <c...@nvidia.com>
Reviewed-by: Eli Britstein <el...@nvidia.com>
---
 lib/dpif-netlink.c   | 28 +++++++++++++++++++++++++++-
 lib/netdev-offload.c | 18 ++++++++++++++++++
 lib/netdev-offload.h |  1 +
 3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 2a47d483c..fd8db8332 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -237,6 +237,8 @@ static unsigned int ovs_vport_mcgroup;
  * to using the compat interface. */
 static bool ovs_tunnels_out_of_tree = true;
 
+static sflow_upcall_callback *sflow_upcall_cb;
+
 static int dpif_netlink_init(void);
 static int open_dpif(const struct dpif_netlink_dp *, struct dpif **);
 static uint32_t dpif_netlink_port_get_pid(const struct dpif *,
@@ -2829,6 +2831,30 @@ dpif_netlink_recv_purge(struct dpif *dpif_)
     fat_rwlock_unlock(&dpif->upcall_lock);
 }
 
+static int
+dpif_netlink_sflow_upcall_cb(struct dpif_upcall_sflow *dupcall)
+{
+    return sflow_upcall_cb(dupcall);
+}
+
+static void
+dpif_netlink_register_sflow_upcall_cb(struct dpif *dpif,
+                                      sflow_upcall_callback *cb)
+{
+    const char *dpif_type_str = dpif_normalize_type(dpif_type(dpif));
+    struct netdev *dev;
+
+    sflow_upcall_cb = cb;
+    dev = netdev_get(dpif_type_str);
+    if (!dev) {
+        VLOG_ERR("%s: Can't find any netdev for dpif type: %s", __func__,
+                 dpif_type_str);
+        return;
+    }
+    netdev_regsiter_nl_sflow_upcall_cb(dev, dpif_netlink_sflow_upcall_cb);
+    netdev_close(dev);
+}
+
 static char *
 dpif_netlink_get_datapath_version(void)
 {
@@ -3987,7 +4013,7 @@ const struct dpif_class dpif_netlink_class = {
     NULL,                       /* register_upcall_cb */
     NULL,                       /* enable_upcall */
     NULL,                       /* disable_upcall */
-    NULL,                       /* register_sflow_upcall_cb */
+    dpif_netlink_register_sflow_upcall_cb,
     dpif_netlink_get_datapath_version, /* get_datapath_version */
     dpif_netlink_ct_dump_start,
     dpif_netlink_ct_dump_next,
diff --git a/lib/netdev-offload.c b/lib/netdev-offload.c
index f8d397d08..17f1592b5 100644
--- a/lib/netdev-offload.c
+++ b/lib/netdev-offload.c
@@ -581,6 +581,24 @@ netdev_ports_get(odp_port_t port_no, const char *dpif_type)
     return ret;
 }
 
+struct netdev *
+netdev_get(const char *dpif_type)
+{
+    struct port_to_netdev_data *data;
+    struct netdev *dev = NULL;
+
+    ovs_rwlock_rdlock(&netdev_hmap_rwlock);
+    HMAP_FOR_EACH (data, portno_node, &port_to_netdev) {
+        if (netdev_get_dpif_type(data->netdev) == dpif_type) {
+            dev = netdev_ref(data->netdev);
+            break;
+        }
+    }
+    ovs_rwlock_unlock(&netdev_hmap_rwlock);
+
+    return dev;
+}
+
 int
 netdev_ports_remove(odp_port_t port_no, const char *dpif_type)
 {
diff --git a/lib/netdev-offload.h b/lib/netdev-offload.h
index 84d267178..5a5dd6867 100644
--- a/lib/netdev-offload.h
+++ b/lib/netdev-offload.h
@@ -109,6 +109,7 @@ struct dpif_port;
 int netdev_ports_insert(struct netdev *, const char *dpif_type,
                         struct dpif_port *);
 struct netdev *netdev_ports_get(odp_port_t port, const char *dpif_type);
+struct netdev *netdev_get(const char *dpif_type);
 int netdev_ports_remove(odp_port_t port, const char *dpif_type);
 odp_port_t netdev_ifindex_to_odp_port(int ifindex);
 
-- 
2.26.2

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to