From patchwork Thu Sep 24 10:24:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1370584 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.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bxrkr6KHKz9sTQ for ; Thu, 24 Sep 2020 20:24:36 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 73CB086ADF; Thu, 24 Sep 2020 10:24:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Nov6oMyTEeB4; Thu, 24 Sep 2020 10:24:33 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 89E6B86A72; Thu, 24 Sep 2020 10:24:32 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5DC72C1AD8; Thu, 24 Sep 2020 10:24:32 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 137E7C0889 for ; Thu, 24 Sep 2020 10:24:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 00D1786B79 for ; Thu, 24 Sep 2020 10:24:30 +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 mpmaq75xiWzb for ; Thu, 24 Sep 2020 10:24:28 +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 whitealder.osuosl.org (Postfix) with ESMTP id 19CA986B78 for ; Thu, 24 Sep 2020 10:24:27 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from cmi@nvidia.com) with SMTP; 24 Sep 2020 13:24:25 +0300 Received: from dev-r630-04.mtbc.labs.mlnx (dev-r630-04.mtbc.labs.mlnx [10.75.205.14]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 08OAOJfZ016057; Thu, 24 Sep 2020 13:24:24 +0300 From: Chris Mi To: dev@openvswitch.org Date: Thu, 24 Sep 2020 18:24:09 +0800 Message-Id: <20200924102415.23528-4-cmi@nvidia.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200924102415.23528-1-cmi@nvidia.com> References: <20200924102415.23528-1-cmi@nvidia.com> MIME-Version: 1.0 Cc: elibr@nvidia.com, Chris Mi Subject: [ovs-dev] [PATCH v4 3/9] dpif-netlink: 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/dpif-netlink.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 7da4fb54d..79afef5f1 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -208,6 +209,9 @@ struct dpif_netlink { /* Change notification. */ struct nl_sock *port_notifier; /* vport multicast group subscriber. */ bool refresh_channels; + + /* receive sampled packets from psample */ + struct nl_sock *psample_sock; }; static void report_loss(struct dpif_netlink *, struct dpif_channel *, @@ -224,11 +228,13 @@ static int ovs_flow_family; static int ovs_packet_family; static int ovs_meter_family; static int ovs_ct_limit_family; +static int psample_family; /* Generic Netlink multicast groups for OVS. * * Initialized by dpif_netlink_init(). */ static unsigned int ovs_vport_mcgroup; +static unsigned int psample_mcgroup; /* If true, tunnel devices are created using OVS compat/genetlink. * If false, tunnel devices are created with rtnetlink and using light weight @@ -371,6 +377,34 @@ dpif_netlink_open(const struct dpif_class *class OVS_UNUSED, const char *name, return error; } +static int +open_dpif_psample(struct dpif_netlink *dpif) +{ + struct nl_sock *sock; + int error; + + dpif->psample_sock = NULL; + if (!netdev_is_flow_api_enabled() || !psample_mcgroup) { + return 0; + } + + error = nl_sock_create(NETLINK_GENERIC, &sock); + if (error) { + VLOG_WARN("%s: failed to create psample socket", __func__); + return error; + } + + error = nl_sock_join_mcgroup(sock, psample_mcgroup); + if (error) { + VLOG_WARN("%s: failed to join psample mcgroup", __func__); + nl_sock_destroy(sock); + return error; + } + dpif->psample_sock = sock; + + return 0; +} + static int open_dpif(const struct dpif_netlink_dp *dp, struct dpif **dpifp) { @@ -378,6 +412,7 @@ open_dpif(const struct dpif_netlink_dp *dp, struct dpif **dpifp) dpif = xzalloc(sizeof *dpif); dpif->port_notifier = NULL; + open_dpif_psample(dpif); fat_rwlock_init(&dpif->upcall_lock); dpif_init(&dpif->dpif, &dpif_netlink_class, dp->name, @@ -615,6 +650,7 @@ dpif_netlink_close(struct dpif *dpif_) struct dpif_netlink *dpif = dpif_netlink_cast(dpif_); nl_sock_destroy(dpif->port_notifier); + nl_sock_destroy(dpif->psample_sock); fat_rwlock_wrlock(&dpif->upcall_lock); destroy_all_channels(dpif); @@ -4098,6 +4134,18 @@ dpif_netlink_init(void) "Please update the Open vSwitch kernel module to enable " "the conntrack limit feature.", OVS_CT_LIMIT_FAMILY); } + if (nl_lookup_genl_family(PSAMPLE_GENL_NAME, &psample_family) < 0) { + VLOG_INFO("Generic Netlink family '%s' does not exist. " + "Please make sure the kernel module psample is loaded", + PSAMPLE_GENL_NAME); + } + if (nl_lookup_genl_mcgroup(PSAMPLE_GENL_NAME, + PSAMPLE_NL_MCGRP_SAMPLE_NAME, + &psample_mcgroup) < 0) { + VLOG_INFO("Failed to join multicast group '%s' for Generic " + "Netlink family '%s'", PSAMPLE_NL_MCGRP_SAMPLE_NAME, + PSAMPLE_GENL_NAME); + } ovs_tunnels_out_of_tree = dpif_netlink_rtnl_probe_oot_tunnels();