From patchwork Wed Jan 27 06:23:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1432041 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DQYVG0ZcMz9sSs for ; Wed, 27 Jan 2021 17:24:38 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 91A3B86840; Wed, 27 Jan 2021 06:24:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dKGPI8LiPH2j; Wed, 27 Jan 2021 06:24:29 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 27692868AF; Wed, 27 Jan 2021 06:24:18 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E63A6C1E70; Wed, 27 Jan 2021 06:24:17 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3964AC1E70 for ; Wed, 27 Jan 2021 06:24:16 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 00E388719C for ; Wed, 27 Jan 2021 06:24:16 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PRUcLTY1G0z1 for ; Wed, 27 Jan 2021 06:24:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by hemlock.osuosl.org (Postfix) with ESMTP id 2176F871AF for ; Wed, 27 Jan 2021 06:24:10 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from cmi@nvidia.com) with SMTP; 27 Jan 2021 08:24:07 +0200 Received: from dev-r630-03.mtbc.labs.mlnx (dev-r630-03.mtbc.labs.mlnx [10.75.205.13]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 10R6NkMP004930; Wed, 27 Jan 2021 08:24:05 +0200 From: Chris Mi To: dev@openvswitch.org Date: Wed, 27 Jan 2021 14:23:42 +0800 Message-Id: <20210127062344.194230-10-cmi@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210127062344.194230-1-cmi@nvidia.com> References: <20210127062344.194230-1-cmi@nvidia.com> MIME-Version: 1.0 Cc: elibr@nvidia.com, roniba@nvidia.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH v12 09/11] netdev-offload-tc: Create psample netlink socket X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Create psample netlink socket as a pre-step towards receiving sampled packets. Signed-off-by: Chris Mi Reviewed-by: Eli Britstein --- lib/netdev-offload-tc.c | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 969a64562..9209217de 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -18,6 +18,7 @@ #include #include +#include #include "dpif.h" #include "hash.h" @@ -51,6 +52,8 @@ 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 nl_sock *psample_sock; struct netlink_field { int offset; @@ -2281,6 +2284,46 @@ 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) { @@ -2315,6 +2358,7 @@ netdev_tc_init_flow_api(struct netdev *netdev) block_id = get_block_id_from_netdev(netdev); probe_multi_mask_per_prio(ifindex); + psample_sock = netdev_tc_psample_init(); ovsthread_once_done(&once); }