get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/1555101/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1555101,
    "url": "http://patchwork.ozlabs.org/api/patches/1555101/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/openvswitch/patch/20211115025312.786953-6-cmi@nvidia.com/",
    "project": {
        "id": 47,
        "url": "http://patchwork.ozlabs.org/api/projects/47/?format=api",
        "name": "Open vSwitch",
        "link_name": "openvswitch",
        "list_id": "ovs-dev.openvswitch.org",
        "list_email": "ovs-dev@openvswitch.org",
        "web_url": "http://openvswitch.org/",
        "scm_url": "git@github.com:openvswitch/ovs.git",
        "webscm_url": "https://github.com/openvswitch/ovs",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20211115025312.786953-6-cmi@nvidia.com>",
    "list_archive_url": null,
    "date": "2021-11-15T02:53:09",
    "name": "[ovs-dev,v18,5/8] dpif-offload-netlink: Implement dpif-offload-provider API",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "a888bf049393e7fce2a135c81b394b0b13f99de0",
    "submitter": {
        "id": 80086,
        "url": "http://patchwork.ozlabs.org/api/people/80086/?format=api",
        "name": "Chris Mi",
        "email": "cmi@nvidia.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/openvswitch/patch/20211115025312.786953-6-cmi@nvidia.com/mbox/",
    "series": [
        {
            "id": 271987,
            "url": "http://patchwork.ozlabs.org/api/series/271987/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/openvswitch/list/?series=271987",
            "date": "2021-11-15T02:53:04",
            "name": "Add offload support for sFlow",
            "version": 18,
            "mbox": "http://patchwork.ozlabs.org/series/271987/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/1555101/comments/",
    "check": "success",
    "checks": "http://patchwork.ozlabs.org/api/patches/1555101/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<ovs-dev-bounces@openvswitch.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "dev@openvswitch.org"
        ],
        "Delivered-To": [
            "patchwork-incoming@bilbo.ozlabs.org",
            "ovs-dev@lists.linuxfoundation.org"
        ],
        "Authentication-Results": [
            "bilbo.ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256\n header.s=selector2 header.b=rqEdN65k;\n\tdkim-atps=neutral",
            "ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org\n (client-ip=140.211.166.138; helo=smtp1.osuosl.org;\n envelope-from=ovs-dev-bounces@openvswitch.org; receiver=<UNKNOWN>)",
            "smtp2.osuosl.org (amavisd-new);\n dkim=pass (2048-bit key) header.d=nvidia.com"
        ],
        "Received": [
            "from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest\n SHA256)\n\t(No client certificate requested)\n\tby bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hsv0N0SVtz9s5P\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 15 Nov 2021 13:53:55 +1100 (AEDT)",
            "from localhost (localhost [127.0.0.1])\n\tby smtp1.osuosl.org (Postfix) with ESMTP id 0F07780DE9;\n\tMon, 15 Nov 2021 02:53:54 +0000 (UTC)",
            "from smtp1.osuosl.org ([127.0.0.1])\n\tby localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id cHQOFcJoMOrD; Mon, 15 Nov 2021 02:53:52 +0000 (UTC)",
            "from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56])\n\tby smtp1.osuosl.org (Postfix) with ESMTPS id 991AF80DB1;\n\tMon, 15 Nov 2021 02:53:51 +0000 (UTC)",
            "from lf-lists.osuosl.org (localhost [127.0.0.1])\n\tby lists.linuxfoundation.org (Postfix) with ESMTP id 716A7C002E;\n\tMon, 15 Nov 2021 02:53:51 +0000 (UTC)",
            "from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133])\n by lists.linuxfoundation.org (Postfix) with ESMTP id 2F3C8C002E\n for <dev@openvswitch.org>; Mon, 15 Nov 2021 02:53:50 +0000 (UTC)",
            "from localhost (localhost [127.0.0.1])\n by smtp2.osuosl.org (Postfix) with ESMTP id 14C1A402DB\n for <dev@openvswitch.org>; Mon, 15 Nov 2021 02:53:38 +0000 (UTC)",
            "from smtp2.osuosl.org ([127.0.0.1])\n by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n with ESMTP id uMPmXYQmqlmH for <dev@openvswitch.org>;\n Mon, 15 Nov 2021 02:53:34 +0000 (UTC)",
            "from NAM12-DM6-obe.outbound.protection.outlook.com\n (mail-dm6nam12on2059.outbound.protection.outlook.com [40.107.243.59])\n by smtp2.osuosl.org (Postfix) with ESMTPS id 71B64402BF\n for <dev@openvswitch.org>; Mon, 15 Nov 2021 02:53:34 +0000 (UTC)",
            "from BN9PR03CA0285.namprd03.prod.outlook.com (2603:10b6:408:f5::20)\n by BY5PR12MB3682.namprd12.prod.outlook.com (2603:10b6:a03:195::12)\n with Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.17; Mon, 15 Nov\n 2021 02:53:32 +0000",
            "from BN8NAM11FT058.eop-nam11.prod.protection.outlook.com\n (2603:10b6:408:f5:cafe::ec) by BN9PR03CA0285.outlook.office365.com\n (2603:10b6:408:f5::20) with Microsoft SMTP Server (version=TLS1_2,\n cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.27 via Frontend\n Transport; Mon, 15 Nov 2021 02:53:31 +0000",
            "from mail.nvidia.com (216.228.112.32) by\n BN8NAM11FT058.mail.protection.outlook.com (10.13.177.58) with Microsoft SMTP\n Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id\n 15.20.4690.15 via Frontend Transport; Mon, 15 Nov 2021 02:53:30 +0000",
            "from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL109.nvidia.com\n (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Sun, 14 Nov\n 2021 18:53:26 -0800",
            "from dev-r630-03.lab.mtl.com (172.20.187.5) by mail.nvidia.com\n (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.18 via Frontend\n Transport; Mon, 15 Nov 2021 02:53:25 +0000"
        ],
        "X-Virus-Scanned": [
            "amavisd-new at osuosl.org",
            "amavisd-new at osuosl.org"
        ],
        "X-Greylist": "whitelisted by SQLgrey-1.8.0",
        "ARC-Seal": "i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;\n b=hsWInwFSsXGd7JDqq5JaLCDZTLIoz8G3xwYxGXoV9VB24l+a/HtT2lS1k/dI2+x6e6vvwatXm8xvUBuX42d4NXNnD9ElJFN3OiSCNoXciN7eEzVa+3DGIAp7MwZrdlVuALGTO0Zj59chMQEqKAPjDwIO6SN0iolkd8PgDN/S4j+KYmTUTUk3U0X2zTg77xiSGqYfuJ5QkN8JFMFwiyS6TG6KvmeeBFhqOqtB3aOUdrD2Mv3YONLGijWLhU3pSOlkjcqAO3Q5kvbqkvg3/DK8MO1r7umeNbAGITA4neek79cPTvLE4ryhKDyPJVCHDUz8K7RGGj+dZEni6CZGP7LO0w==",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;\n s=arcselector9901;\n 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;\n bh=35qfmgm6mEZVHe4h0uvW6jMRaO0P2ILygo6DUwWplWM=;\n b=MlBDDBTl9us5tjhswrXS7+FCs8Vu7b579PJ1juXZoMqwORpTATnqju2ylIHJ6CydMDD0b6Ohx4KOrGXpL2wP430Mux/cL9yMfAWgr7KYKlDYiL2Jed8PbtCxjI6iitaWHfzIYJAy5vpuYcEFnTIUXgdg2H3YtjIEttG4bZHYBEPJXNDX+jX7TY1CMHmVnQ8ZiA6R17uWzZzKiD1rzGIdjLHApurxgvXb4X1NishhSFB+ZGY90YlC1ii7r/0NaG+GMIfXfRYGmpTN3HSx1q5FhrHJYDIYMYLUvnbhTnjtNLa6fdnttkwBkEvkbQwawWPhCAAFZGnMHC4iEr+VLYrwLw==",
        "ARC-Authentication-Results": "i=1; mx.microsoft.com 1; spf=pass (sender ip is\n 216.228.112.32) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com;\n dmarc=pass (p=quarantine sp=quarantine pct=100) action=none\n header.from=nvidia.com; dkim=none (message not signed); arc=none",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com;\n s=selector2;\n h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;\n bh=35qfmgm6mEZVHe4h0uvW6jMRaO0P2ILygo6DUwWplWM=;\n b=rqEdN65kSUXk0EuQeTolL9stseJ8ECFkDYzW8GcRpHm2I2YN8vu93MJa8N1KLx+9mpGAwjxTo7OXegmaFshQOVO8FccQbcV440KoK1gtsvHXBmgxuNonoqChzCsoGpggS22Rpis/9hjaEbIzK55Rjt/MIRsDn+8SDBWKKIrLiLiwDFL9kNVZCgfH9bowcr3egyVl6lRrkQa1WFVJfIjL48EzGbOoz+bhuINWTfSjD76GAUebdQg+ORpuQMT2VikChA28L84d8u/7Ci0k+2ERR73YDfCuabkSL0SFgAVYhsxnaOdw3YJUF7K21HDFDpgajhpS9uxfaelHbv5SaxkxMw==",
        "X-MS-Exchange-Authentication-Results": "spf=pass (sender IP is 216.228.112.32)\n smtp.mailfrom=nvidia.com; dkim=none (message not signed)\n header.d=none;dmarc=pass action=none header.from=nvidia.com;",
        "Received-SPF": "Pass (protection.outlook.com: domain of nvidia.com designates\n 216.228.112.32 as permitted sender) receiver=protection.outlook.com;\n client-ip=216.228.112.32; helo=mail.nvidia.com;",
        "To": "<dev@openvswitch.org>",
        "Date": "Mon, 15 Nov 2021 10:53:09 +0800",
        "Message-ID": "<20211115025312.786953-6-cmi@nvidia.com>",
        "X-Mailer": "git-send-email 2.30.2",
        "In-Reply-To": "<20211115025312.786953-1-cmi@nvidia.com>",
        "References": "<20211115025312.786953-1-cmi@nvidia.com>",
        "MIME-Version": "1.0",
        "X-EOPAttributedMessage": "0",
        "X-MS-PublicTrafficType": "Email",
        "X-MS-Office365-Filtering-Correlation-Id": "32f9ac26-22db-49c7-99eb-08d9a7e31bcb",
        "X-MS-TrafficTypeDiagnostic": "BY5PR12MB3682:",
        "X-Microsoft-Antispam-PRVS": "\n <BY5PR12MB3682C6D497E17450E44B2F0FCF989@BY5PR12MB3682.namprd12.prod.outlook.com>",
        "X-MS-Oob-TLC-OOBClassifiers": "OLM:935;",
        "X-MS-Exchange-SenderADCheck": "1",
        "X-MS-Exchange-AntiSpam-Relay": "0",
        "X-Microsoft-Antispam": "BCL:0;",
        "X-Microsoft-Antispam-Message-Info": "\n fHgt3PyFFSmbE7CakMOJQgtXH4bFQ1sQLb4G+14Y9JxV/9dqvdY9DqbLYVCKbWxrgXu0rT/ELg5QGuaAlZJVnqS77RQlu/6XzYoMG5pmWNoz9Wx38He2iXKswuQZFAOvAa3sn844J1WK40aC4A/FAojbcQQHIT18euHX6CLnVmKcXmOBeAp6TLzwHQr2AjE5z724HyhpnW5aBq2xGFFBWSKA5wAfk1YmAKncgSLaB7pnV98ixFNjwEYeflGVcj8dBHxAGQOKmfIioWSa6pe9Tp2+nBJKjeH+6CkvQ9NGmelniQfyaD556xZx6YH4F5PUv98ZRape/YYf3YH53T1HLclzOqwhMgSwQhAcjfx44S1jWWqf25O4jYGz5Kh2Bh5ZiwpyoGUiCXkn/wT4vcqC3e0lJd+WerqHB4Zv8Oc52kzI/V/OjpSm+KvbTjNX7QH55rRsJVuTdp0EtYNWSiK4feWpwt/k95WbuY/nRq7HJZgqPWkC0eTXqdHVzmnwWwGFd7mRhw467WRv6Wxi8qAjcwWS9oPadI70UW/YuIAx6TEvS2E1gIZqfSL5jEctBdAaFYghyHFRoYJlyQDGDBbxXOwE0q1kFroAa1IbiInAZrtbKPK/j7cryFvUnVkowWohNVT61C6Oe9HDWU0NXAyRDnj3t8/7mX7HAuKzIZwDlpBS6nLYvSu1UlQrnk+ektPGaSGqaI1Qt5tTBhvHRVZ5eQg/t7+LRqBrz3cKZcXiGjovGsAu/v8gGc9/9CQ5MIZtdGCeHOZHMPA7g4t0OATZh/1i6MZChkhybTt0VjQaILY=",
        "X-Forefront-Antispam-Report": "CIP:216.228.112.32; CTRY:US; LANG:en; SCL:1;\n SRV:;\n IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid01.nvidia.com; CAT:NONE;\n SFS:(4636009)(36840700001)(46966006)(83380400001)(82310400003)(316002)(1076003)(107886003)(4326008)(54906003)(8676002)(36860700001)(2906002)(8936002)(86362001)(966005)(6666004)(356005)(508600001)(26005)(336012)(36756003)(30864003)(5660300002)(426003)(6916009)(7636003)(2616005)(70586007)(186003)(70206006)(47076005);\n DIR:OUT; SFP:1101;",
        "X-OriginatorOrg": "Nvidia.com",
        "X-MS-Exchange-CrossTenant-OriginalArrivalTime": "15 Nov 2021 02:53:30.9652 (UTC)",
        "X-MS-Exchange-CrossTenant-Network-Message-Id": "\n 32f9ac26-22db-49c7-99eb-08d9a7e31bcb",
        "X-MS-Exchange-CrossTenant-Id": "43083d15-7273-40c1-b7db-39efd9ccc17a",
        "X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp": "\n TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.32];\n Helo=[mail.nvidia.com]",
        "X-MS-Exchange-CrossTenant-AuthSource": "\n BN8NAM11FT058.eop-nam11.prod.protection.outlook.com",
        "X-MS-Exchange-CrossTenant-AuthAs": "Anonymous",
        "X-MS-Exchange-CrossTenant-FromEntityHeader": "HybridOnPrem",
        "X-MS-Exchange-Transport-CrossTenantHeadersStamped": "BY5PR12MB3682",
        "Cc": "elibr@nvidia.com, simon.horman@netronome.com, roniba@nvidia.com,\n i.maximets@ovn.org",
        "Subject": "[ovs-dev] [PATCH v18 5/8] dpif-offload-netlink: Implement\n\tdpif-offload-provider API",
        "X-BeenThere": "ovs-dev@openvswitch.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "<ovs-dev.openvswitch.org>",
        "List-Unsubscribe": "<https://mail.openvswitch.org/mailman/options/ovs-dev>,\n <mailto:ovs-dev-request@openvswitch.org?subject=unsubscribe>",
        "List-Archive": "<http://mail.openvswitch.org/pipermail/ovs-dev/>",
        "List-Post": "<mailto:ovs-dev@openvswitch.org>",
        "List-Help": "<mailto:ovs-dev-request@openvswitch.org?subject=help>",
        "List-Subscribe": "<https://mail.openvswitch.org/mailman/listinfo/ovs-dev>,\n <mailto:ovs-dev-request@openvswitch.org?subject=subscribe>",
        "From": "Chris Mi via dev <ovs-dev@openvswitch.org>",
        "Reply-To": "Chris Mi <cmi@nvidia.com>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "ovs-dev-bounces@openvswitch.org",
        "Sender": "\"dev\" <ovs-dev-bounces@openvswitch.org>"
    },
    "content": "Implement dpif-offload API for netlink datapath. And implement a\ndummy dpif-offload API for netdev datapath to make tests pass.\n\nSigned-off-by: Chris Mi <cmi@nvidia.com>\nReviewed-by: Eli Britstein <elibr@nvidia.com>\n---\n lib/automake.mk             |   2 +\n lib/dpif-netdev.c           |   8 +-\n lib/dpif-netlink.c          |   4 +-\n lib/dpif-offload-netdev.c   |  43 +++++++\n lib/dpif-offload-netlink.c  | 222 ++++++++++++++++++++++++++++++++++++\n lib/dpif-offload-provider.h |  25 +++-\n lib/dpif-offload.c          | 163 ++++++++++++++++++++++++++\n lib/dpif-provider.h         |   6 +-\n lib/dpif.c                  |  20 +++-\n 9 files changed, 486 insertions(+), 7 deletions(-)\n create mode 100644 lib/dpif-offload-netdev.c\n create mode 100644 lib/dpif-offload-netlink.c",
    "diff": "diff --git a/lib/automake.mk b/lib/automake.mk\nindex 9259f57de..ce9f1c98a 100644\n--- a/lib/automake.mk\n+++ b/lib/automake.mk\n@@ -128,6 +128,7 @@ lib_libopenvswitch_la_SOURCES = \\\n \tlib/dpif-netdev-perf.c \\\n \tlib/dpif-netdev-perf.h \\\n \tlib/dpif-offload.c \\\n+\tlib/dpif-offload-netdev.c \\\n \tlib/dpif-offload-provider.h \\\n \tlib/dpif-provider.h \\\n \tlib/dpif.c \\\n@@ -446,6 +447,7 @@ lib_libopenvswitch_la_SOURCES += \\\n \tlib/dpif-netlink.h \\\n \tlib/dpif-netlink-rtnl.c \\\n \tlib/dpif-netlink-rtnl.h \\\n+\tlib/dpif-offload-netlink.c \\\n \tlib/if-notifier.c \\\n \tlib/netdev-linux.c \\\n \tlib/netdev-linux.h \\\ndiff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c\nindex 98453a206..b40a1071c 100644\n--- a/lib/dpif-netdev.c\n+++ b/lib/dpif-netdev.c\n@@ -1593,7 +1593,8 @@ create_dpif_netdev(struct dp_netdev *dp)\n     ovs_refcount_ref(&dp->ref_cnt);\n \n     dpif = xmalloc(sizeof *dpif);\n-    dpif_init(&dpif->dpif, dp->class, dp->name, netflow_id >> 8, netflow_id);\n+    dpif_init(&dpif->dpif, dp->class, NULL, dp->name, netflow_id >> 8,\n+              netflow_id);\n     dpif->dp = dp;\n     dpif->last_port_seq = seq_read(dp->port_seq);\n \n@@ -8893,6 +8894,10 @@ dpif_dummy_override(const char *type)\n     if (error == 0 || error == EAFNOSUPPORT) {\n         dpif_dummy_register__(type);\n     }\n+    error = dp_offload_unregister_provider(type);\n+    if (error == 0 || error == EAFNOSUPPORT) {\n+        dpif_offload_dummy_register(type);\n+    }\n }\n \n void\n@@ -8913,6 +8918,7 @@ dpif_dummy_register(enum dummy_level level)\n     }\n \n     dpif_dummy_register__(\"dummy\");\n+    dpif_offload_dummy_register(\"dummy\");\n \n     unixctl_command_register(\"dpif-dummy/change-port-number\",\n                              \"dp port new-number\",\ndiff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c\nindex 18cdfe6e5..b253dc668 100644\n--- a/lib/dpif-netlink.c\n+++ b/lib/dpif-netlink.c\n@@ -461,8 +461,8 @@ open_dpif(const struct dpif_netlink_dp *dp, struct dpif **dpifp)\n     dpif->port_notifier = NULL;\n     fat_rwlock_init(&dpif->upcall_lock);\n \n-    dpif_init(&dpif->dpif, &dpif_netlink_class, dp->name,\n-              dp->dp_ifindex, dp->dp_ifindex);\n+    dpif_init(&dpif->dpif, &dpif_netlink_class, &dpif_offload_netlink_class,\n+              dp->name, dp->dp_ifindex, dp->dp_ifindex);\n \n     dpif->dp_ifindex = dp->dp_ifindex;\n     dpif->user_features = dp->user_features;\ndiff --git a/lib/dpif-offload-netdev.c b/lib/dpif-offload-netdev.c\nnew file mode 100644\nindex 000000000..35dac2cc3\n--- /dev/null\n+++ b/lib/dpif-offload-netdev.c\n@@ -0,0 +1,43 @@\n+/*\n+ * Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at:\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+#include <config.h>\n+\n+#include \"dpif.h\"\n+#include \"dpif-offload-provider.h\"\n+#include \"openvswitch/vlog.h\"\n+\n+VLOG_DEFINE_THIS_MODULE(dpif_offload_netdev);\n+\n+/* Currently, it is used only for dummy netdev to make tests pass. */\n+const struct dpif_offload_class dpif_offload_netdev_class = {\n+    .type = \"netdev\",\n+    .init = NULL,\n+    .destroy = NULL,\n+    .sflow_recv_wait = NULL,\n+    .sflow_recv = NULL,\n+};\n+\n+void\n+dpif_offload_dummy_register(const char *type)\n+{\n+    struct dpif_offload_class *class;\n+\n+    class = xmalloc(sizeof *class);\n+    *class = dpif_offload_netdev_class;\n+    class->type = xstrdup(type);\n+    dp_offload_register_provider(class);\n+}\ndiff --git a/lib/dpif-offload-netlink.c b/lib/dpif-offload-netlink.c\nnew file mode 100644\nindex 000000000..320363bbc\n--- /dev/null\n+++ b/lib/dpif-offload-netlink.c\n@@ -0,0 +1,222 @@\n+/*\n+ * Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at:\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+#include <config.h>\n+#include <errno.h>\n+#include <linux/psample.h>\n+#include <sys/poll.h>\n+\n+#include \"dpif-offload-provider.h\"\n+#include \"netdev-offload.h\"\n+#include \"netlink-protocol.h\"\n+#include \"netlink-socket.h\"\n+#include \"openvswitch/vlog.h\"\n+\n+VLOG_DEFINE_THIS_MODULE(dpif_offload_netlink);\n+\n+static struct nl_sock *psample_sock;\n+static int psample_family;\n+\n+/* Receive psample netlink message and save the attributes. */\n+struct offload_psample {\n+    struct nlattr *packet;      /* Packet data. */\n+    int dp_group_id;            /* Mapping id for sFlow offload. */\n+    int iifindex;               /* Input ifindex. */\n+};\n+\n+/* In order to keep compatibility with kernels without psample module,\n+ * return success even if psample is not initialized successfully. */\n+static void\n+psample_init(void)\n+{\n+    unsigned int psample_mcgroup;\n+    int err;\n+\n+    if (!netdev_is_flow_api_enabled()) {\n+        VLOG_DBG(\"Flow API is not enabled.\");\n+        return;\n+    }\n+\n+    if (psample_sock) {\n+        VLOG_DBG(\"Psample socket is already initialized.\");\n+        return;\n+    }\n+\n+    err = nl_lookup_genl_family(PSAMPLE_GENL_NAME,\n+                                &psample_family);\n+    if (err) {\n+        VLOG_WARN(\"Generic Netlink family '%s' does not exist: %s\\n\"\n+                  \"Please make sure the kernel module psample is loaded.\",\n+                  PSAMPLE_GENL_NAME, ovs_strerror(err));\n+        return;\n+    }\n+\n+    err = nl_lookup_genl_mcgroup(PSAMPLE_GENL_NAME,\n+                                 PSAMPLE_NL_MCGRP_SAMPLE_NAME,\n+                                 &psample_mcgroup);\n+    if (err) {\n+        VLOG_WARN(\"Failed to join Netlink multicast group '%s': %s\",\n+                  PSAMPLE_NL_MCGRP_SAMPLE_NAME, ovs_strerror(err));\n+        return;\n+    }\n+\n+    err = nl_sock_create(NETLINK_GENERIC, &psample_sock);\n+    if (err) {\n+        VLOG_WARN(\"Failed to create psample socket: %s\", ovs_strerror(err));\n+        return;\n+    }\n+\n+    err = nl_sock_join_mcgroup(psample_sock, psample_mcgroup);\n+    if (err) {\n+        VLOG_WARN(\"Failed to join psample mcgroup: %s\", ovs_strerror(err));\n+        nl_sock_destroy(psample_sock);\n+        psample_sock = NULL;\n+        return;\n+    }\n+}\n+\n+static int\n+dpif_offload_netlink_init(void)\n+{\n+    psample_init();\n+\n+    return 0;\n+}\n+\n+static void\n+psample_destroy(void)\n+{\n+    if (!psample_sock) {\n+        return;\n+    }\n+\n+    nl_sock_destroy(psample_sock);\n+    psample_sock = NULL;\n+}\n+\n+static void\n+dpif_offload_netlink_destroy(void)\n+{\n+    psample_destroy();\n+}\n+\n+static void\n+dpif_offload_netlink_sflow_recv_wait(void)\n+{\n+    if (psample_sock) {\n+        nl_sock_wait(psample_sock, POLLIN);\n+    }\n+}\n+\n+static int\n+psample_from_ofpbuf(struct offload_psample *psample,\n+                    const struct ofpbuf *buf)\n+{\n+    static const struct nl_policy ovs_psample_policy[] = {\n+        [PSAMPLE_ATTR_IIFINDEX] = { .type = NL_A_U16 },\n+        [PSAMPLE_ATTR_SAMPLE_GROUP] = { .type = NL_A_U32 },\n+        [PSAMPLE_ATTR_GROUP_SEQ] = { .type = NL_A_U32 },\n+        [PSAMPLE_ATTR_DATA] = { .type = NL_A_UNSPEC },\n+    };\n+    struct nlattr *a[ARRAY_SIZE(ovs_psample_policy)];\n+    struct genlmsghdr *genl;\n+    struct nlmsghdr *nlmsg;\n+    struct ofpbuf b;\n+\n+    b = ofpbuf_const_initializer(buf->data, buf->size);\n+    nlmsg = ofpbuf_try_pull(&b, sizeof *nlmsg);\n+    genl = ofpbuf_try_pull(&b, sizeof *genl);\n+    if (!nlmsg || !genl || nlmsg->nlmsg_type != psample_family\n+        || !nl_policy_parse(&b, 0, ovs_psample_policy, a,\n+                            ARRAY_SIZE(ovs_psample_policy))) {\n+        return EINVAL;\n+    }\n+\n+    psample->iifindex = nl_attr_get_u16(a[PSAMPLE_ATTR_IIFINDEX]);\n+    psample->dp_group_id = nl_attr_get_u32(a[PSAMPLE_ATTR_SAMPLE_GROUP]);\n+    psample->packet = a[PSAMPLE_ATTR_DATA];\n+\n+    return 0;\n+}\n+\n+static int\n+psample_parse_packet(struct offload_psample *psample,\n+                     struct dpif_offload_sflow *sflow)\n+{\n+    dp_packet_use_stub(&sflow->packet,\n+                       CONST_CAST(struct nlattr *,\n+                                  nl_attr_get(psample->packet)) - 1,\n+                       nl_attr_get_size(psample->packet) +\n+                       sizeof(struct nlattr));\n+    dp_packet_set_data(&sflow->packet,\n+                       (char *) dp_packet_data(&sflow->packet) +\n+                       sizeof(struct nlattr));\n+    dp_packet_set_size(&sflow->packet, nl_attr_get_size(psample->packet));\n+\n+    sflow->attr = dpif_offload_sflow_attr_find(psample->dp_group_id);\n+    if (!sflow->attr) {\n+        return ENOENT;\n+    }\n+    sflow->iifindex = psample->iifindex;\n+\n+    return 0;\n+}\n+\n+static int\n+dpif_offload_netlink_sflow_recv(struct dpif_offload_sflow *sflow)\n+{\n+    if (!psample_sock) {\n+        return ENOENT;\n+    }\n+\n+    for (;;) {\n+        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);\n+        struct offload_psample psample;\n+        uint64_t buf_stub[4096 / 8];\n+        struct ofpbuf buf;\n+        int error;\n+\n+        ofpbuf_use_stub(&buf, buf_stub, sizeof buf_stub);\n+        error = nl_sock_recv(psample_sock, &buf, NULL, false);\n+\n+        if (!error) {\n+            error = psample_from_ofpbuf(&psample, &buf);\n+            if (!error) {\n+                    ofpbuf_uninit(&buf);\n+                    error = psample_parse_packet(&psample, sflow);\n+                    return error;\n+            }\n+        } else if (error != EAGAIN) {\n+            VLOG_WARN_RL(&rl, \"Error reading or parsing netlink (%s).\",\n+                         ovs_strerror(error));\n+            nl_sock_drain(psample_sock);\n+            error = ENOBUFS;\n+        }\n+\n+        ofpbuf_uninit(&buf);\n+        if (error) {\n+            return error;\n+        }\n+    }\n+}\n+\n+const struct dpif_offload_class dpif_offload_netlink_class = {\n+    .type = \"system\",\n+    .init = dpif_offload_netlink_init,\n+    .destroy = dpif_offload_netlink_destroy,\n+    .sflow_recv_wait = dpif_offload_netlink_sflow_recv_wait,\n+    .sflow_recv = dpif_offload_netlink_sflow_recv,\n+};\ndiff --git a/lib/dpif-offload-provider.h b/lib/dpif-offload-provider.h\nindex af49eedb9..4ef50266d 100644\n--- a/lib/dpif-offload-provider.h\n+++ b/lib/dpif-offload-provider.h\n@@ -17,12 +17,18 @@\n #ifndef DPIF_OFFLOAD_PROVIDER_H\n #define DPIF_OFFLOAD_PROVIDER_H\n \n+#include \"dp-packet.h\"\n #include \"netlink-protocol.h\"\n #include \"openvswitch/packets.h\"\n #include \"openvswitch/types.h\"\n \n struct dpif;\n-struct dpif_offload_sflow;\n+struct registered_dpif_offload_class;\n+\n+#ifdef __linux__\n+extern const struct dpif_offload_class dpif_offload_netlink_class;\n+#endif\n+extern const struct dpif_offload_class dpif_offload_netdev_class;\n \n /* When offloading sample action, userspace creates a unique ID to map\n  * sFlow action and tunnel info and passes this ID to datapath instead\n@@ -37,6 +43,13 @@ struct dpif_sflow_attr {\n     ovs_u128 ufid;                  /* Flow ufid. */\n };\n \n+/* Parse the specific dpif message to sFlow. So OVS can process it. */\n+struct dpif_offload_sflow {\n+    struct dp_packet packet;            /* Packet data. */\n+    uint32_t iifindex;                  /* Input ifindex. */\n+    const struct dpif_sflow_attr *attr; /* SFlow attribute. */\n+};\n+\n /* Datapath interface offload structure, to be defined by each implementation\n  * of a datapath interface.\n  */\n@@ -62,6 +75,16 @@ struct dpif_offload_class {\n     int (*sflow_recv)(struct dpif_offload_sflow *sflow);\n };\n \n+void dp_offload_initialize(void);\n+void dpif_offload_close(struct dpif *);\n+void dpif_offload_delete(struct dpif *);\n+\n+int dp_offload_register_provider(const struct dpif_offload_class *);\n+int dp_offload_unregister_provider(const char *type);\n+void dpif_offload_dummy_register(const char *type);\n+void dp_offload_class_unref(struct registered_dpif_offload_class *rc);\n+struct registered_dpif_offload_class *dp_offload_class_lookup(const char *);\n+\n void dpif_offload_sflow_recv_wait(const struct dpif *dpif);\n int dpif_offload_sflow_recv(const struct dpif *dpif,\n                             struct dpif_offload_sflow *sflow);\ndiff --git a/lib/dpif-offload.c b/lib/dpif-offload.c\nindex f2bf3e634..10d0bff53 100644\n--- a/lib/dpif-offload.c\n+++ b/lib/dpif-offload.c\n@@ -18,6 +18,169 @@\n #include <errno.h>\n \n #include \"dpif-provider.h\"\n+#include \"openvswitch/shash.h\"\n+#include \"openvswitch/vlog.h\"\n+\n+VLOG_DEFINE_THIS_MODULE(dpif_offload);\n+\n+static const struct dpif_offload_class *base_dpif_offload_classes[] = {\n+#if defined(__linux__)\n+    &dpif_offload_netlink_class,\n+#endif\n+    &dpif_offload_netdev_class,\n+};\n+\n+struct registered_dpif_offload_class {\n+    const struct dpif_offload_class *offload_class;\n+    int refcount;\n+};\n+static struct shash dpif_offload_classes =\n+    SHASH_INITIALIZER(&dpif_offload_classes);\n+\n+/* Protects 'dpif_offload_classes', including the refcount. */\n+static struct ovs_mutex dpif_offload_mutex = OVS_MUTEX_INITIALIZER;\n+\n+void\n+dp_offload_initialize(void)\n+{\n+    static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;\n+\n+    if (ovsthread_once_start(&once)) {\n+        int i;\n+\n+        for (i = 0; i < ARRAY_SIZE(base_dpif_offload_classes); i++) {\n+            dp_offload_register_provider(base_dpif_offload_classes[i]);\n+        }\n+        ovsthread_once_done(&once);\n+    }\n+}\n+\n+static int\n+dp_offload_register_provider__(const struct dpif_offload_class *new_class)\n+{\n+    struct registered_dpif_offload_class *registered_class;\n+    int error;\n+\n+    if (shash_find(&dpif_offload_classes, new_class->type)) {\n+        VLOG_WARN(\"attempted to register duplicate datapath offload \"\n+                  \"provider: %s\", new_class->type);\n+        return EEXIST;\n+    }\n+\n+    error = new_class->init ? new_class->init() : 0;\n+    if (error) {\n+        VLOG_WARN(\"failed to initialize %s datapath offload class: %s\",\n+                  new_class->type, ovs_strerror(error));\n+        return error;\n+    }\n+\n+    registered_class = xmalloc(sizeof *registered_class);\n+    registered_class->offload_class = new_class;\n+    registered_class->refcount = 0;\n+\n+    shash_add(&dpif_offload_classes, new_class->type, registered_class);\n+\n+    return 0;\n+}\n+\n+void dpif_offload_close(struct dpif *dpif)\n+{\n+    if (dpif->offload_class) {\n+        struct registered_dpif_offload_class *rc;\n+\n+        rc = shash_find_data(&dpif_offload_classes, dpif->offload_class->type);\n+        dp_offload_class_unref(rc);\n+    }\n+}\n+\n+void dpif_offload_delete(struct dpif *dpif)\n+{\n+    const struct dpif_offload_class *offload_class = dpif->offload_class;\n+\n+    if (offload_class && offload_class->destroy) {\n+        offload_class->destroy();\n+    }\n+}\n+\n+int\n+dp_offload_register_provider(const struct dpif_offload_class *new_class)\n+{\n+    int error;\n+\n+    ovs_mutex_lock(&dpif_offload_mutex);\n+    error = dp_offload_register_provider__(new_class);\n+    ovs_mutex_unlock(&dpif_offload_mutex);\n+\n+    return error;\n+}\n+\n+/* Unregisters an offload datapath provider.  'type' must have been previously\n+ * registered and not currently be in use by any dpifs.  After unregistration\n+ * new offload datapaths of that type cannot be opened using dpif_open(). */\n+static int\n+dp_offload_unregister_provider__(const char *type)\n+{\n+    struct shash_node *node;\n+    struct registered_dpif_offload_class *registered_class;\n+\n+    node = shash_find(&dpif_offload_classes, type);\n+    if (!node) {\n+        return EAFNOSUPPORT;\n+    }\n+\n+    registered_class = node->data;\n+    if (registered_class->refcount) {\n+        VLOG_WARN(\"attempted to unregister in use offload datapath provider: \"\n+                  \"%s\", type);\n+        return EBUSY;\n+    }\n+\n+    shash_delete(&dpif_offload_classes, node);\n+    free(registered_class);\n+\n+    return 0;\n+}\n+\n+/* Unregisters an offload datapath provider.  'type' must have been previously\n+ * registered and not currently be in use by any dpifs.  After unregistration\n+ * new offload datapaths of that type cannot be opened using dpif_open(). */\n+int\n+dp_offload_unregister_provider(const char *type)\n+{\n+    int error;\n+\n+    dp_offload_initialize();\n+\n+    ovs_mutex_lock(&dpif_offload_mutex);\n+    error = dp_offload_unregister_provider__(type);\n+    ovs_mutex_unlock(&dpif_offload_mutex);\n+\n+    return error;\n+}\n+\n+void\n+dp_offload_class_unref(struct registered_dpif_offload_class *rc)\n+{\n+    ovs_mutex_lock(&dpif_offload_mutex);\n+    ovs_assert(rc->refcount);\n+    rc->refcount--;\n+    ovs_mutex_unlock(&dpif_offload_mutex);\n+}\n+\n+struct registered_dpif_offload_class *\n+dp_offload_class_lookup(const char *type)\n+{\n+    struct registered_dpif_offload_class *rc;\n+\n+    ovs_mutex_lock(&dpif_offload_mutex);\n+    rc = shash_find_data(&dpif_offload_classes, type);\n+    if (rc) {\n+        rc->refcount++;\n+    }\n+    ovs_mutex_unlock(&dpif_offload_mutex);\n+\n+    return rc;\n+}\n \n void\n dpif_offload_sflow_recv_wait(const struct dpif *dpif)\ndiff --git a/lib/dpif-provider.h b/lib/dpif-provider.h\nindex 37b3d3618..3b9607afc 100644\n--- a/lib/dpif-provider.h\n+++ b/lib/dpif-provider.h\n@@ -47,8 +47,10 @@ struct dpif {\n struct dpif_ipf_status;\n struct ipf_dump_ctx;\n \n-void dpif_init(struct dpif *, const struct dpif_class *, const char *name,\n-               uint8_t netflow_engine_type, uint8_t netflow_engine_id);\n+void dpif_init(struct dpif *, const struct dpif_class *,\n+               const struct dpif_offload_class *offload_class,\n+               const char *name, uint8_t netflow_engine_type,\n+               uint8_t netflow_engine_id);\n void dpif_uninit(struct dpif *dpif, bool close);\n \n static inline void dpif_assert_class(const struct dpif *dpif,\ndiff --git a/lib/dpif.c b/lib/dpif.c\nindex 38bcb47cb..a550bf5dd 100644\n--- a/lib/dpif.c\n+++ b/lib/dpif.c\n@@ -332,6 +332,7 @@ do_open(const char *name, const char *type, bool create, struct dpif **dpifp)\n     struct dpif *dpif = NULL;\n     int error;\n     struct registered_dpif_class *registered_class;\n+    struct registered_dpif_offload_class *registered_offload_class;\n \n     dp_initialize();\n \n@@ -344,6 +345,17 @@ do_open(const char *name, const char *type, bool create, struct dpif **dpifp)\n         goto exit;\n     }\n \n+    dp_offload_initialize();\n+\n+    registered_offload_class = dp_offload_class_lookup(type);\n+    if (!registered_offload_class) {\n+        VLOG_WARN(\"could not create offload datapath %s of unknown type %s\",\n+                  name, type);\n+        error = EAFNOSUPPORT;\n+        dp_class_unref(registered_class);\n+        goto exit;\n+    }\n+\n     error = registered_class->dpif_class->open(registered_class->dpif_class,\n                                                name, create, &dpif);\n     if (!error) {\n@@ -372,6 +384,7 @@ do_open(const char *name, const char *type, bool create, struct dpif **dpifp)\n             }\n         }\n     } else {\n+        dp_offload_class_unref(registered_offload_class);\n         dp_class_unref(registered_class);\n     }\n \n@@ -447,6 +460,7 @@ dpif_close(struct dpif *dpif)\n     if (dpif) {\n         struct registered_dpif_class *rc;\n \n+        dpif_offload_close(dpif);\n         rc = shash_find_data(&dpif_classes, dpif->dpif_class->type);\n \n         if (rc->refcount == 1) {\n@@ -527,6 +541,9 @@ dpif_delete(struct dpif *dpif)\n \n     COVERAGE_INC(dpif_destroy);\n \n+    dpif_offload_delete(dpif);\n+    log_operation(dpif, \"offload delete\", 0);\n+\n     error = dpif->dpif_class->destroy(dpif);\n     log_operation(dpif, \"delete\", error);\n     return error;\n@@ -1680,10 +1697,11 @@ dpif_queue_to_priority(const struct dpif *dpif, uint32_t queue_id,\n \f\n void\n dpif_init(struct dpif *dpif, const struct dpif_class *dpif_class,\n-          const char *name,\n+          const struct dpif_offload_class *offload_class, const char *name,\n           uint8_t netflow_engine_type, uint8_t netflow_engine_id)\n {\n     dpif->dpif_class = dpif_class;\n+    dpif->offload_class = offload_class;\n     dpif->base_name = xstrdup(name);\n     dpif->full_name = xasprintf(\"%s@%s\", dpif_class->type, name);\n     dpif->netflow_engine_type = netflow_engine_type;\n",
    "prefixes": [
        "ovs-dev",
        "v18",
        "5/8"
    ]
}