diff mbox series

[ovs-dev,v5,03/12] dpif: Introduce register sFlow upcall callback API

Message ID 20201029112340.14167-4-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
When offloading sample action to TC, psample sends the sampled packets
to userspace by a netlink message. The thread polling psample socket
will translate the psample netlink message to an sFlow format and call
the sFlow upcall callback to send the sFlow packet to right monitoring
host.

Introduce register sFlow upcall callback API.

Signed-off-by: Chris Mi <cmi@nvidia.com>
Reviewed-by: Eli Britstein <elibr@nvidia.com>
---
 lib/dpif-netdev.c   |  1 +
 lib/dpif-netlink.c  |  1 +
 lib/dpif-provider.h | 10 ++++++++++
 lib/dpif.c          |  8 ++++++++
 lib/dpif.h          | 26 ++++++++++++++++++++++++++
 5 files changed, 46 insertions(+)
diff mbox series

Patch

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 300861ca5..f47a3fdab 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -8426,6 +8426,7 @@  const struct dpif_class dpif_netdev_class = {
     dpif_netdev_register_upcall_cb,
     dpif_netdev_enable_upcall,
     dpif_netdev_disable_upcall,
+    NULL,                       /* register_sflow_upcall_cb */
     dpif_netdev_get_datapath_version,
     dpif_netdev_ct_dump_start,
     dpif_netdev_ct_dump_next,
diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 2f881e4fa..3fb992def 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -3978,6 +3978,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_get_datapath_version, /* get_datapath_version */
     dpif_netlink_ct_dump_start,
     dpif_netlink_ct_dump_next,
diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h
index b817fceac..589f11be4 100644
--- a/lib/dpif-provider.h
+++ b/lib/dpif-provider.h
@@ -427,6 +427,16 @@  struct dpif_class {
     /* Disables upcalls if 'dpif' directly executes upcall functions. */
     void (*disable_upcall)(struct dpif *);
 
+    /* When offloading sample action, psample sends the sampled packets to
+     * userspace by a netlink message. The thread polling psample socket
+     * will translate the psample netlink message to an sFlow format and call
+     * the sFlow upcall callback to send the sFlow packet to right monitoring
+     * host.
+     *
+     * Registers an upcall callback to process sFlow packet.
+     */
+    void (*register_sflow_upcall_cb)(struct dpif *, sflow_upcall_callback *);
+
     /* Get datapath version. Caller is responsible for freeing the string
      * returned.  */
     char *(*get_datapath_version)(void);
diff --git a/lib/dpif.c b/lib/dpif.c
index ac2860764..6e72b2087 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -1520,6 +1520,14 @@  dpif_disable_upcall(struct dpif *dpif)
     }
 }
 
+void
+dpif_register_sflow_upcall_cb(struct dpif *dpif, sflow_upcall_callback *cb)
+{
+    if (dpif->dpif_class->register_sflow_upcall_cb) {
+        dpif->dpif_class->register_sflow_upcall_cb(dpif, cb);
+    }
+}
+
 void
 dpif_print_packet(struct dpif *dpif, struct dpif_upcall *upcall)
 {
diff --git a/lib/dpif.h b/lib/dpif.h
index cb047dbe2..ed4257210 100644
--- a/lib/dpif.h
+++ b/lib/dpif.h
@@ -869,6 +869,32 @@  typedef int upcall_callback(const struct dp_packet *packet,
 
 void dpif_register_upcall_cb(struct dpif *, upcall_callback *, void *aux);
 
+/* When offloading sample action, userspace creates a unique ID to map
+ * sFlow action and tunnel info and passes this ID to datapath instead
+ * of the sFlow info. Datapath will send this ID and sampled packet to
+ * userspace. Using the ID, userspace can recover the sFlow info and send
+ * sampled packet to the right sFlow monitoring host.
+ */
+struct dpif_sflow_attr {
+    const struct nlattr *sflow; /* sFlow action */
+    size_t sflow_len;           /* Length of 'sflow' in bytes. */
+
+    void *userdata;             /* struct user_action_cookie */
+    size_t userdata_len;        /* struct user_action_cookie length */
+
+    struct flow_tnl *tunnel;    /* Tunnel info */
+};
+
+/* A sampled packet passed up from datapath to userspace. */
+struct dpif_upcall_sflow {
+    struct dp_packet packet;    /* packet data */
+    uint32_t iifindex;          /* input ifindex */
+    const struct dpif_sflow_attr *sflow_attr;
+};
+
+typedef int sflow_upcall_callback(struct dpif_upcall_sflow *dupcall);
+void dpif_register_sflow_upcall_cb(struct dpif *, sflow_upcall_callback *);
+
 int dpif_recv_set(struct dpif *, bool enable);
 int dpif_handlers_set(struct dpif *, uint32_t n_handlers);
 int dpif_set_config(struct dpif *, const struct smap *cfg);