diff mbox series

[ovs-dev,v5,10/12] netdev-offload-tc: Create psample netlink socket

Message ID 20201029112340.14167-11-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
Create psample netlink socket as a pre-step towards receiving sampled
packets.

Signed-off-by: Chris Mi <cmi@nvidia.com>
Reviewed-by: Eli Britstein <elibr@nvidia.com>
---
 lib/netdev-offload-tc.c | 42 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

Comments

0-day Robot Oct. 29, 2020, 12:22 p.m. UTC | #1
Bleep bloop.  Greetings Chris Mi, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Line is 80 characters long (recommended limit is 79)
#57 FILE: lib/netdev-offload-tc.c:2277:
                  "Netlink family '%s'", __func__, PSAMPLE_NL_MCGRP_SAMPLE_NAME,

Lines checked: 91, Warnings: 1, Errors: 0


Please check this out.  If you feel there has been an error, please email aconole@redhat.com

Thanks,
0-day Robot
diff mbox series

Patch

diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c
index a81003a98..33485a0b5 100644
--- a/lib/netdev-offload-tc.c
+++ b/lib/netdev-offload-tc.c
@@ -18,6 +18,7 @@ 
 
 #include <errno.h>
 #include <linux/if_ether.h>
+#include <linux/psample.h>
 
 #include "dpif.h"
 #include "hash.h"
@@ -51,6 +52,7 @@  static bool multi_mask_per_prio = false;
 static bool block_support = false;
 
 static dpif_netlink_sflow_upcall_callback *upcall_cb;
+static int psample_family;
 
 struct netlink_field {
     int offset;
@@ -2254,6 +2256,45 @@  netdev_tc_register_sflow_upcall_cb(dpif_netlink_sflow_upcall_callback *cb)
     upcall_cb = cb;
 }
 
+static struct nl_sock *
+netdev_tc_psample_init(void)
+{
+    unsigned int psample_mcgroup;
+    struct nl_sock *sock;
+    int error;
+
+    if (nl_lookup_genl_family(PSAMPLE_GENL_NAME, &psample_family)) {
+        VLOG_INFO("%s: Generic Netlink family '%s' does not exist. "
+                  "Please make sure the kernel module psample is loaded",
+                  __func__, PSAMPLE_GENL_NAME);
+        return NULL;
+    }
+
+    if (nl_lookup_genl_mcgroup(PSAMPLE_GENL_NAME,
+                               PSAMPLE_NL_MCGRP_SAMPLE_NAME,
+                               &psample_mcgroup)) {
+        VLOG_INFO("%s: Failed to join multicast group '%s' for Generic "
+                  "Netlink family '%s'", __func__, PSAMPLE_NL_MCGRP_SAMPLE_NAME,
+                  PSAMPLE_GENL_NAME);
+        return NULL;
+    }
+
+    error = nl_sock_create(NETLINK_GENERIC, &sock);
+    if (error) {
+        VLOG_INFO("%s: Failed to create psample socket", __func__);
+        return NULL;
+    }
+
+    error = nl_sock_join_mcgroup(sock, psample_mcgroup);
+    if (error) {
+        VLOG_INFO("%s: Failed to join psample mcgroup", __func__);
+        nl_sock_destroy(sock);
+        return NULL;
+    }
+
+    return sock;
+}
+
 static int
 netdev_tc_init_flow_api(struct netdev *netdev)
 {
@@ -2288,6 +2329,7 @@  netdev_tc_init_flow_api(struct netdev *netdev)
         block_id = get_block_id_from_netdev(netdev);
 
         probe_multi_mask_per_prio(ifindex);
+        netdev_tc_psample_init();
         ovsthread_once_done(&once);
     }