From patchwork Tue Dec 28 06:38:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Mi X-Patchwork-Id: 1573610 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=pGWBw9NV; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JNPyz3gnGz9sR4 for ; Tue, 28 Dec 2021 17:39:39 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 5227660BA2; Tue, 28 Dec 2021 06:39:37 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rQd3NrqBDe4H; Tue, 28 Dec 2021 06:39:35 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id CB67B60B5D; Tue, 28 Dec 2021 06:39:34 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A5CB3C001E; Tue, 28 Dec 2021 06:39:34 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0AF5BC001E for ; Tue, 28 Dec 2021 06:39:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 7EFFD81D70 for ; Tue, 28 Dec 2021 06:39:14 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5j8J4xS5-bhk for ; Tue, 28 Dec 2021 06:39:13 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20607.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eae::607]) by smtp1.osuosl.org (Postfix) with ESMTPS id 4267981D16 for ; Tue, 28 Dec 2021 06:39:13 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EWRj18gZ7P1TJHIo9m7n5DmloST/qmo9MApXCyuYxxOiZdgUlssxWdm2sKWQQs2NqLJBkf9vio1lTv3xZoGLv49znwbB0PVOqQpJOv7ULQ33z13j4isEl8ZVZ26vxg/UQoEA6cJgl+/mYVEQN69290y/9MquQ5gMb3Egp8LQO6xafjHFP5KqVZwuixhmXkfDz6sXxR4UzlCK8FbuTh1V/KVrCr7s5E8ePBk/g7FzL/a8+ccBteJlzBSAuDKhJZJ6XY5bnJ0pON0TH2Z425L+FfAyv7Q/OSWFaqMcoTZxFAGhIKrioh8JfX+HBXsZP3HBwMbp1kNAhZ0BbJmJQ638XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uin5px717gL6FhvmZAmSNTP2hld0KraEyJDq8FLP+V0=; b=TUxRiMn+uvOfFGaIfKPGK89wbWj03oemVPhZiOa4WpE2ubtz8OX7L/eZoHNxPiACAVGh+NjZ+Y1OX+IllAbGvJlbm5aRTDozbOEtG7KhjJyIyp4ULVyjYrB1NRMo8Ugt+m+XQZGa2lHh4/IddGC9wbNIiXSpabe59WvMGJLO1F5Dio5kA1M4C418wL3C69ForhDLYzz8h/ON3fopOtFZ7UYCyWH0MP8bTgaRr9gxfU5B3I2C7SvRtNd+ip22XP4c3G6MjR2rrBLgV8UYzLbzAwGEg6VrWcaFDK/ZcaecaLBqBzCAaaBdyKQBwJ5eGNESvCiwhfoSQ4H1yGLCkNuxvA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=netronome.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uin5px717gL6FhvmZAmSNTP2hld0KraEyJDq8FLP+V0=; b=pGWBw9NVAiozPcOR6AvXLAIDo4HFy2TOF/AEfdC+gVti75Qx+QMkaLc4hUa7rLe1T8m+ts1ETtl1yD6Z5UiE24POffxIrfU+pWiHoY8ujrYi4ZulwZ7Tz9yPelErwlwke68bRzik+XJ1GhWpnggl1CgqsQANX9IFlzqAWwmKEBzU+yxEKy5Q+y2Hi8IglWlRJMLAIGE0WP4mnd6pXPHtKA26i9cC8qy9GFmUxg/P11mfHAlqELr+pYfeX2qBPeSuE6eBzWMuBv6JEGTD/I0QvtlT00yPIP6nF6hCK1O9CHcKN0K4oKsxDcIDYlqirm3pGTUzAAbL0xD1IALOylW50Q== Received: from MWHPR1601CA0002.namprd16.prod.outlook.com (2603:10b6:300:da::12) by BN6PR12MB1588.namprd12.prod.outlook.com (2603:10b6:405:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4823.19; Tue, 28 Dec 2021 06:39:10 +0000 Received: from CO1NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:300:da:cafe::e8) by MWHPR1601CA0002.outlook.office365.com (2603:10b6:300:da::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4823.18 via Frontend Transport; Tue, 28 Dec 2021 06:39:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT048.mail.protection.outlook.com (10.13.175.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4823.18 via Frontend Transport; Tue, 28 Dec 2021 06:39:10 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 28 Dec 2021 06:38:59 +0000 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 28 Dec 2021 06:38:59 +0000 Received: from dev-r630-03.lab.mtl.com (172.20.187.5) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Tue, 28 Dec 2021 06:38:57 +0000 To: Date: Tue, 28 Dec 2021 14:38:40 +0800 Message-ID: <20211228063844.195233-5-cmi@nvidia.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211228063844.195233-1-cmi@nvidia.com> References: <20211228063844.195233-1-cmi@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c481a6e6-18a9-4c48-92f5-08d9c9ccc184 X-MS-TrafficTypeDiagnostic: BN6PR12MB1588:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IXU3UwyjrJNjzUYzFsfFzKKe+F3KcvqLdlsvvNzgTJfd8ZZRA9Rur0No4DX2UZdIAD9dQH4pfEDrM8j44Rxs9gTSGFUry5M1RqdLYga4dZQ5Bsg4QF47A48YHf2bosfNhVVzILU2R7E/ZnIjJPZVMGC+DNIQnUJHEDNdXHwi4nKnGJf3WWJzTvBjBleKSZmNqB5f1LF3U350U4+xb965xQB+MtzQZJ0SPA87gs9vd4E8K66id1bG1jufSfU4NuIjOFUMB6m5AZg7zNs2djTtPWwIxJUMYABrw5xQOARntZgFWubpi3xYi6VpEb8i1FTOM04Rz5RRrn2Mx3FO5saF3EkbyRhFoFgMYmQ7fzNZ9AGFVLT+X6VEDHXOECW0vWTvS7gb2kyGWPgyU/Xh/lYoFP7vjKe8Y6dK7hO7jgNHfzZlvfgY1WNbEhOegMZZ9JmairzqCdMBI+LE/3oTyRc32+4dV+WYY5rWLuu0Fl0LFhyj52Hfhafvb81TpERPG1+3ruHgODxtrEWzKbJUb7/p0iquWe3hYqcvguQmCpB9OiBYiozFFze7jHMtw1EMiuGJXeQ3wxCcCZeSEtJLvvRCJn/Gt0aeMOg6XE10kDnI4AN/W/zbcp3wK2TflOybjStlumW98vtqGZNvaefrDB7Tb/OlkbknLj8pmyEbMEyu2fX5ZMmOtArXtUr4s+g49TSiMa39ccYylzljh0sGJ0uWl1588d3WKIuCVlBf6aYsUhkxJQ7nrwebLo1vV3osNINX1TPGPO5sErcoqW919jG8BRrAnA53m9mBSS36V0qUmTE= X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(4636009)(46966006)(40470700002)(36840700001)(83380400001)(4326008)(2906002)(426003)(82310400004)(47076005)(26005)(70206006)(70586007)(81166007)(356005)(36756003)(316002)(54906003)(86362001)(30864003)(5660300002)(336012)(8676002)(6916009)(8936002)(1076003)(186003)(2616005)(508600001)(6666004)(107886003)(40460700001)(36860700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Dec 2021 06:39:10.5744 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c481a6e6-18a9-4c48-92f5-08d9c9ccc184 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1588 Cc: elibr@nvidia.com, simon.horman@netronome.com, roniba@nvidia.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH v19 4/8] netdev-offload-tc: Introduce group ID management API 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: , X-Patchwork-Original-From: Chris Mi via dev From: Chris Mi Reply-To: Chris Mi Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When offloading sample action to TC, userspace creates a unique ID to map sFlow action and tunnel info and passes this ID to kernel instead of the sFlow info. psample 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. Signed-off-by: Chris Mi Reviewed-by: Eli Britstein Acked-by: Eelco Chaudron --- lib/dpif-offload-provider.h | 17 +++ lib/netdev-offload-tc.c | 246 +++++++++++++++++++++++++++++++++++- lib/netdev-offload.h | 2 + lib/tc.h | 1 + 4 files changed, 260 insertions(+), 6 deletions(-) diff --git a/lib/dpif-offload-provider.h b/lib/dpif-offload-provider.h index 3b94740df..af49eedb9 100644 --- a/lib/dpif-offload-provider.h +++ b/lib/dpif-offload-provider.h @@ -17,9 +17,26 @@ #ifndef DPIF_OFFLOAD_PROVIDER_H #define DPIF_OFFLOAD_PROVIDER_H +#include "netlink-protocol.h" +#include "openvswitch/packets.h" +#include "openvswitch/types.h" + struct dpif; struct dpif_offload_sflow; +/* 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 *action; /* SFlow action. */ + const struct nlattr *userdata; /* Struct user_action_cookie. */ + struct flow_tnl *tunnel; /* Tunnel info. */ + ovs_u128 ufid; /* Flow ufid. */ +}; + /* Datapath interface offload structure, to be defined by each implementation * of a datapath interface. */ diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 9845e8d3f..204d1c833 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -40,6 +40,7 @@ #include "unaligned.h" #include "util.h" #include "dpif-provider.h" +#include "cmap.h" VLOG_DEFINE_THIS_MODULE(netdev_offload_tc); @@ -62,6 +63,233 @@ struct chain_node { uint32_t chain; }; +/* This maps a psample group ID to struct dpif_sflow_attr for sFlow */ +struct sgid_node { + struct ovs_list exp_node OVS_GUARDED; + struct cmap_node metadata_node; + struct cmap_node id_node; + struct ovs_refcount refcount; + uint32_t hash; + uint32_t id; + const struct dpif_sflow_attr sflow; +}; + +static struct ovs_rwlock sgid_rwlock = OVS_RWLOCK_INITIALIZER; +static struct cmap sgid_map = CMAP_INITIALIZER; +static struct cmap sgid_metadata_map = CMAP_INITIALIZER; +static struct ovs_list sgid_expiring OVS_GUARDED_BY(sgid_rwlock) + = OVS_LIST_INITIALIZER(&sgid_expiring); +static uint32_t next_sample_group_id OVS_GUARDED_BY(sgid_rwlock) = 1; + +static void +sgid_node_free(struct sgid_node *node) +{ + free(node->sflow.tunnel); + free(CONST_CAST(void *, node->sflow.action)); + free(CONST_CAST(void *, node->sflow.userdata)); + free(node); +} + +/* Lockless RCU protected lookup. If node is needed accross RCU quiescent + * state, caller should copy the contents. */ +static const struct sgid_node * +sgid_find(uint32_t id) +{ + const struct cmap_node *node = cmap_find(&sgid_map, id); + + return node ? CONTAINER_OF(node, const struct sgid_node, id_node) : NULL; +} + +const struct dpif_sflow_attr * +dpif_offload_sflow_attr_find(uint32_t id) +{ + const struct sgid_node *node; + + node = sgid_find(id); + if (!node) { + return NULL; + } + + return &node->sflow; +} + +static uint32_t +dpif_sflow_attr_hash(const struct dpif_sflow_attr *sflow) +{ + return hash_bytes(&sflow->ufid, sizeof sflow->ufid, 0); +} + +static bool +dpif_sflow_attr_equal(const struct dpif_sflow_attr *a, + const struct dpif_sflow_attr *b) +{ + if (!ovs_u128_equals(a->ufid, b->ufid)) { + return false; + } + if (!a->action || !b->action) { + return false; + } + if (a->action->nla_len != b->action->nla_len + || memcmp(a->action, b->action, a->action->nla_len)) { + return false; + } + if (!a->tunnel && !b->tunnel) { + return true; + } + if (!a->tunnel || !b->tunnel) { + return false; + } + + return !memcmp(a->tunnel, b->tunnel, sizeof *a->tunnel); +} + +/* Lockless RCU protected lookup. If node is needed accross RCU quiescent + * state, caller should take a reference. */ +static struct sgid_node * +sgid_find_equal(const struct dpif_sflow_attr *target, uint32_t hash) +{ + struct sgid_node *node; + + CMAP_FOR_EACH_WITH_HASH (node, metadata_node, hash, &sgid_metadata_map) { + if (dpif_sflow_attr_equal(&node->sflow, target)) { + return node; + } + } + return NULL; +} + +static struct sgid_node * +sgid_ref_equal(const struct dpif_sflow_attr *target, uint32_t hash) +{ + struct sgid_node *node; + + do { + node = sgid_find_equal(target, hash); + /* Try again if the node was released before we get the reference. */ + } while (node && !ovs_refcount_try_ref_rcu(&node->refcount)); + + return node; +} + +static void +dpif_sflow_attr_clone(struct dpif_sflow_attr *new, + const struct dpif_sflow_attr *old) +{ + new->action = xmemdup(old->action, old->action->nla_len); + new->userdata = xmemdup(old->userdata, old->userdata->nla_len); + new->tunnel = old->tunnel + ? xmemdup(old->tunnel, sizeof *old->tunnel) + : NULL; + new->ufid = old->ufid; +} + +/* We use the id as the hash value, which works due to cmap internal rehashing. + * We also only insert nodes with unique IDs, so all possible hash collisions + * remain internal to the cmap. */ +static struct sgid_node * +sgid_find__(uint32_t id) + OVS_REQUIRES(sgid_rwlock) +{ + struct cmap_node *node = cmap_find_protected(&sgid_map, id); + + return node ? CONTAINER_OF(node, struct sgid_node, id_node) : NULL; +} + +/* Allocate a unique group id for the given set of flow metadata. The id + * space is 2^^32, but if looping too many times, we still can't find a + * free one, that means something is wrong, return NULL. + */ +#define SGID_ALLOC_RETRY_MAX 8192 +static struct sgid_node * +sgid_alloc__(const struct dpif_sflow_attr *sflow, uint32_t hash) +{ + struct sgid_node *node = xzalloc(sizeof *node); + int i = 0; + + node->hash = hash; + ovs_refcount_init(&node->refcount); + dpif_sflow_attr_clone(CONST_CAST(struct dpif_sflow_attr *, + &node->sflow), sflow); + + ovs_rwlock_wrlock(&sgid_rwlock); + for (;;) { + node->id = next_sample_group_id++; + if (OVS_UNLIKELY(!node->id)) { + next_sample_group_id = 1; + node->id = next_sample_group_id++; + } + /* Find if the id is free. */ + if (OVS_LIKELY(!sgid_find__(node->id))) { + break; + } + if (++i == SGID_ALLOC_RETRY_MAX) { + VLOG_ERR("Can't find a free group ID after %d retries", i); + ovs_rwlock_unlock(&sgid_rwlock); + sgid_node_free(node); + return NULL; + } + } + cmap_insert(&sgid_map, &node->id_node, node->id); + cmap_insert(&sgid_metadata_map, &node->metadata_node, node->hash); + ovs_rwlock_unlock(&sgid_rwlock); + return node; +} + +/* Allocate a unique group id for the given set of flow metadata and + optional actions. */ +static uint32_t +sgid_alloc_ctx(const struct dpif_sflow_attr *sflow) +{ + uint32_t hash = dpif_sflow_attr_hash(sflow); + struct sgid_node *node = sgid_ref_equal(sflow, hash); + + if (!node) { + node = sgid_alloc__(sflow, hash); + } + + return node ? node->id : 0; +} + +static void +sgid_node_unref(const struct sgid_node *node_) + OVS_EXCLUDED(sgid_rwlock) +{ + struct sgid_node *node = CONST_CAST(struct sgid_node *, node_); + + ovs_rwlock_wrlock(&sgid_rwlock); + if (node && ovs_refcount_unref(&node->refcount) == 1) { + cmap_remove(&sgid_metadata_map, &node->metadata_node, node->hash); + cmap_remove(&sgid_map, &node->id_node, node->id); + ovsrcu_postpone(sgid_node_free, node); + } + ovs_rwlock_unlock(&sgid_rwlock); +} + +static void +sgid_free(uint32_t id) +{ + const struct sgid_node *node; + + if (!id) { + return; + } + + node = sgid_find(id); + if (node) { + sgid_node_unref(node); + } else { + VLOG_ERR("Freeing nonexistent group ID: %"PRIu32, id); + } +} + +static int +del_filter_and_sgid(struct tcf_id *id) +{ + sgid_free(id->sample_group_id); + id->sample_group_id = 0; + return tc_del_filter(id); +} + static bool is_internal_port(const char *type) { @@ -198,13 +426,13 @@ del_ufid_tc_mapping(const ovs_u128 *ufid) ovs_mutex_unlock(&ufid_lock); } -/* Wrapper function to delete filter and ufid tc mapping */ +/* Wrapper function to delete filter, sgid and ufid tc mapping */ static int -del_filter_and_ufid_mapping(struct tcf_id *id, const ovs_u128 *ufid) +del_filter_sgid_ufid_mapping(struct tcf_id *id, const ovs_u128 *ufid) { int err; - err = tc_del_filter(id); + err = del_filter_and_sgid(id); if (!err) { del_ufid_tc_mapping(ufid); } @@ -426,7 +654,7 @@ netdev_tc_flow_flush(struct netdev *netdev) continue; } - err = tc_del_filter(&data->id); + err = del_filter_and_sgid(&data->id); if (!err) { del_ufid_tc_mapping_unlocked(&data->ufid); } @@ -1917,6 +2145,11 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, action->type = TC_ACT_GOTO; action->chain = 0; /* 0 is reserved and not used by recirc. */ flower.action_count++; + } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_SAMPLE) { + struct dpif_sflow_attr sflow_attr; + + memset(&sflow_attr, 0, sizeof sflow_attr); + sgid_alloc_ctx(&sflow_attr); } else { VLOG_DBG_RL(&rl, "unsupported put action type: %d", nl_attr_type(nla)); @@ -1932,7 +2165,8 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, if (get_ufid_tc_mapping(ufid, &id) == 0) { VLOG_DBG_RL(&rl, "updating old handle: %d prio: %d", id.handle, id.prio); - info->tc_modify_flow_deleted = !del_filter_and_ufid_mapping(&id, ufid); + info->tc_modify_flow_deleted = !del_filter_sgid_ufid_mapping(&id, + ufid); } prio = get_prio_for_tc_flower(&flower); @@ -2021,7 +2255,7 @@ netdev_tc_flow_del(struct netdev *netdev OVS_UNUSED, } } - error = del_filter_and_ufid_mapping(&id, ufid); + error = del_filter_sgid_ufid_mapping(&id, ufid); return error; } diff --git a/lib/netdev-offload.h b/lib/netdev-offload.h index 43a98d499..409551c94 100644 --- a/lib/netdev-offload.h +++ b/lib/netdev-offload.h @@ -137,6 +137,8 @@ int netdev_ports_flow_get(const char *dpif_type, struct match *match, int netdev_ports_get_n_flows(const char *dpif_type, odp_port_t port_no, uint64_t *n_flows); +const struct dpif_sflow_attr *dpif_offload_sflow_attr_find(uint32_t id); + #ifdef __cplusplus } #endif diff --git a/lib/tc.h b/lib/tc.h index a147ca461..2e4084f48 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -276,6 +276,7 @@ struct tcf_id { uint32_t chain; uint16_t prio; uint32_t handle; + uint32_t sample_group_id; }; static inline struct tcf_id