diff mbox series

[ovs-dev,v5,07/12] dpif-netlink: Implement register sFlow upcall callback API

Message ID 20201029112340.14167-8-cmi@nvidia.com
State New
Headers show
Series Add offload support for sFlow | expand

Commit Message

Chris Mi Oct. 29, 2020, 11:23 a.m. UTC
Implement dpif netlink register sFlow upcall callback API.

Signed-off-by: Chris Mi <cmi@nvidia.com>
Reviewed-by: Eli Britstein <elibr@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 mbox series

Patch

diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 3fb992def..380c1b129 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -236,6 +236,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 *,
@@ -2820,6 +2822,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)
 {
@@ -3978,7 +4004,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 f74419dee..dd465dd05 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);