get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 1528342,
    "url": "http://patchwork.ozlabs.org/api/patches/1528342/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/openvswitch/patch/20210915124319.1683219-8-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": "<20210915124319.1683219-8-cmi@nvidia.com>",
    "list_archive_url": null,
    "date": "2021-09-15T12:43:19",
    "name": "[ovs-dev,v15,7/7] netdev-offload-tc: Add offload support for sFlow",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "29a6403548f3a9dc4635fce03d8f3540b7169055",
    "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/20210915124319.1683219-8-cmi@nvidia.com/mbox/",
    "series": [
        {
            "id": 262447,
            "url": "http://patchwork.ozlabs.org/api/series/262447/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/openvswitch/list/?series=262447",
            "date": "2021-09-15T12:43:12",
            "name": "Add offload support for sFlow",
            "version": 15,
            "mbox": "http://patchwork.ozlabs.org/series/262447/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/1528342/comments/",
    "check": "success",
    "checks": "http://patchwork.ozlabs.org/api/patches/1528342/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@ozlabs.org",
            "ovs-dev@lists.linuxfoundation.org"
        ],
        "Authentication-Results": "ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org\n (client-ip=140.211.166.136; helo=smtp3.osuosl.org;\n envelope-from=ovs-dev-bounces@openvswitch.org; receiver=<UNKNOWN>)",
        "Received": [
            "from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136])\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 ozlabs.org (Postfix) with ESMTPS id 4H8fz41MMyz9sSs\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Sep 2021 22:43:44 +1000 (AEST)",
            "from localhost (localhost [127.0.0.1])\n\tby smtp3.osuosl.org (Postfix) with ESMTP id E44F660C02;\n\tWed, 15 Sep 2021 12:43:39 +0000 (UTC)",
            "from smtp3.osuosl.org ([127.0.0.1])\n\tby localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id Bkj8X6z9c5zo; Wed, 15 Sep 2021 12:43:37 +0000 (UTC)",
            "from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56])\n\tby smtp3.osuosl.org (Postfix) with ESMTPS id E2B0360BBB;\n\tWed, 15 Sep 2021 12:43:36 +0000 (UTC)",
            "from lf-lists.osuosl.org (localhost [127.0.0.1])\n\tby lists.linuxfoundation.org (Postfix) with ESMTP id 72658C002C;\n\tWed, 15 Sep 2021 12:43:34 +0000 (UTC)",
            "from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138])\n by lists.linuxfoundation.org (Postfix) with ESMTP id 93770C0022\n for <dev@openvswitch.org>; Wed, 15 Sep 2021 12:43:30 +0000 (UTC)",
            "from localhost (localhost [127.0.0.1])\n by smtp1.osuosl.org (Postfix) with ESMTP id 42555827A0\n for <dev@openvswitch.org>; Wed, 15 Sep 2021 12:43:30 +0000 (UTC)",
            "from smtp1.osuosl.org ([127.0.0.1])\n by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n with ESMTP id 3qAzCrajfqmL for <dev@openvswitch.org>;\n Wed, 15 Sep 2021 12:43:29 +0000 (UTC)",
            "from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129])\n by smtp1.osuosl.org (Postfix) with ESMTP id 4903C82702\n for <dev@openvswitch.org>; Wed, 15 Sep 2021 12:43:28 +0000 (UTC)",
            "from Internal Mail-Server by MTLPINE1 (envelope-from cmi@nvidia.com)\n with SMTP; 15 Sep 2021 15:43:21 +0300",
            "from c-141-46-1-010.mtl.labs.mlnx (c-141-46-1-010.mtl.labs.mlnx\n [10.141.46.10])\n by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 18FChLbb010242;\n Wed, 15 Sep 2021 15:43:21 +0300"
        ],
        "X-Virus-Scanned": [
            "amavisd-new at osuosl.org",
            "amavisd-new at osuosl.org"
        ],
        "X-Greylist": "domain auto-whitelisted by SQLgrey-1.8.0",
        "To": "dev@openvswitch.org",
        "Date": "Wed, 15 Sep 2021 15:43:19 +0300",
        "Message-Id": "<20210915124319.1683219-8-cmi@nvidia.com>",
        "X-Mailer": "git-send-email 2.27.0",
        "In-Reply-To": "<20210915124319.1683219-1-cmi@nvidia.com>",
        "References": "<20210915124319.1683219-1-cmi@nvidia.com>",
        "MIME-Version": "1.0",
        "Cc": "elibr@nvidia.com, simon.horman@netronome.com, roniba@nvidia.com,\n i.maximets@ovn.org",
        "Subject": "[ovs-dev] [PATCH v15 7/7] netdev-offload-tc: Add offload support\n\tfor sFlow",
        "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": "Create a unique group ID to map the sFlow info when offloading sFlow\naction to TC. When showing the offloaded datapath flows, translate the\ngroup ID from TC sample action to sFlow info using the mapping.\n\nSigned-off-by: Chris Mi <cmi@nvidia.com>\nReviewed-by: Eli Britstein <elibr@nvidia.com>\n---\n NEWS                    |   1 +\n lib/netdev-offload-tc.c | 220 ++++++++++++++++++++++++++++++++++++----\n lib/tc.c                |  61 ++++++++++-\n lib/tc.h                |  15 ++-\n 4 files changed, 275 insertions(+), 22 deletions(-)",
    "diff": "diff --git a/NEWS b/NEWS\nindex 1f2adf718..974a3e8e0 100644\n--- a/NEWS\n+++ b/NEWS\n@@ -8,6 +8,7 @@ Post-v2.16.0\n        by default.  'other_config:dpdk-socket-limit' can be set equal to\n        the 'other_config:dpdk-socket-mem' to preserve the legacy memory\n        limiting behavior.\n+   - Add sFlow offload support for kernel (netlink) datapath.\n \n \n v2.16.0 - 16 Aug 2021\ndiff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c\nindex 5d817b6cf..4f603566c 100644\n--- a/lib/netdev-offload-tc.c\n+++ b/lib/netdev-offload-tc.c\n@@ -20,6 +20,7 @@\n #include <linux/if_ether.h>\n \n #include \"dpif.h\"\n+#include \"dpif-offload-provider.h\"\n #include \"hash.h\"\n #include \"openvswitch/hmap.h\"\n #include \"openvswitch/match.h\"\n@@ -1053,6 +1054,19 @@ parse_tc_flower_to_match(struct tc_flower *flower,\n         action = flower->actions;\n         for (i = 0; i < flower->action_count; i++, action++) {\n             switch (action->type) {\n+            case TC_ACT_SAMPLE: {\n+                const struct sgid_node *node;\n+\n+                node = sgid_find(action->sample.group_id);\n+                if (!node) {\n+                    VLOG_WARN(\"%s: sgid node is NULL, sgid: %d\",\n+                              __func__, action->sample.group_id);\n+                    return ENOENT;\n+                }\n+                nl_msg_put(buf, node->sflow.action,\n+                           node->sflow.action->nla_len);\n+            }\n+            break;\n             case TC_ACT_VLAN_POP: {\n                 nl_msg_put_flag(buf, OVS_ACTION_ATTR_POP_VLAN);\n             }\n@@ -1791,6 +1805,155 @@ parse_match_ct_state_to_flower(struct tc_flower *flower, struct match *match)\n     }\n }\n \n+static int\n+parse_userspace_attributes(const struct nlattr *actions,\n+                           struct dpif_sflow_attr *sflow_attr)\n+{\n+    static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);\n+    const struct nlattr *nla;\n+    unsigned int left;\n+\n+    NL_NESTED_FOR_EACH_UNSAFE (nla, left, actions) {\n+        if (nl_attr_type(nla) == OVS_USERSPACE_ATTR_USERDATA) {\n+            struct user_action_cookie *cookie;\n+\n+            cookie = CONST_CAST(struct user_action_cookie *, nl_attr_get(nla));\n+            if (cookie->type == USER_ACTION_COOKIE_SFLOW) {\n+                sflow_attr->userdata = nla;\n+                return 0;\n+            }\n+        }\n+    }\n+\n+    VLOG_DBG_RL(&rl, \"%s: cannot offload userspace action other than sFlow\",\n+                __func__);\n+    return EOPNOTSUPP;\n+}\n+\n+static int\n+parse_sample_actions_attribute(const struct nlattr *actions,\n+                               struct dpif_sflow_attr *sflow_attr)\n+{\n+    static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);\n+    const struct nlattr *nla;\n+    unsigned int left;\n+    int err = EINVAL;\n+\n+    NL_NESTED_FOR_EACH_UNSAFE (nla, left, actions) {\n+        if (nl_attr_type(nla) == OVS_ACTION_ATTR_USERSPACE) {\n+            err = parse_userspace_attributes(nla, sflow_attr);\n+        } else {\n+            /* We can't offload other nested actions */\n+            VLOG_DBG_RL(&rl, \"%s: can only offload \"\n+                        \"OVS_ACTION_ATTR_USERSPACE attribute\", __func__);\n+            return EINVAL;\n+        }\n+    }\n+\n+    if (err) {\n+        VLOG_ERR_RL(&error_rl, \"%s: no OVS_ACTION_ATTR_USERSPACE attribute\",\n+                    __func__);\n+    }\n+    return err;\n+}\n+\n+static int\n+parse_sample_action(struct tc_flower *flower, struct tc_action *tc_action,\n+                    const struct nlattr *sample_action,\n+                    const struct flow_tnl *tnl, uint32_t *group_id,\n+                    const ovs_u128 *ufid)\n+{\n+    static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);\n+    struct dpif_sflow_attr sflow_attr;\n+    const struct nlattr *nla;\n+    unsigned int left;\n+    int ret = EINVAL;\n+\n+    if (*group_id) {\n+        VLOG_ERR_RL(&error_rl, \"%s: Only a single TC_SAMPLE action \"\n+                    \"per flow is supported\", __func__);\n+        return EOPNOTSUPP;\n+    }\n+\n+    memset(&sflow_attr, 0, sizeof sflow_attr);\n+    sflow_attr.ufid = *ufid;\n+    sflow_attr.action = sample_action;\n+\n+    if (flower->tunnel) {\n+        sflow_attr.tunnel = CONST_CAST(struct flow_tnl *, tnl);\n+    }\n+\n+    NL_NESTED_FOR_EACH_UNSAFE (nla, left, sample_action) {\n+        if (nl_attr_type(nla) == OVS_SAMPLE_ATTR_ACTIONS) {\n+            ret = parse_sample_actions_attribute(nla, &sflow_attr);\n+        } else if (nl_attr_type(nla) == OVS_SAMPLE_ATTR_PROBABILITY) {\n+            tc_action->type = TC_ACT_SAMPLE;\n+            tc_action->sample.rate = UINT32_MAX / nl_attr_get_u32(nla);\n+        } else {\n+            return EINVAL;\n+        }\n+    }\n+\n+    if (!tc_action->sample.rate || ret) {\n+        return EINVAL;\n+    }\n+\n+    *group_id = sgid_alloc_ctx(&sflow_attr);\n+    if (!*group_id) {\n+        VLOG_DBG_RL(&rl, \"%s: Failed allocating group id for sample action\",\n+                    __func__);\n+        return ENOENT;\n+    }\n+    tc_action->sample.group_id = *group_id;\n+    flower->action_count++;\n+\n+    return 0;\n+}\n+\n+static int\n+parse_userspace_action(struct tc_flower *flower, struct tc_action *tc_action,\n+                       const struct nlattr *userspace_action,\n+                       const struct flow_tnl *tnl, uint32_t *group_id,\n+                       const ovs_u128 *ufid)\n+{\n+    static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);\n+    struct dpif_sflow_attr sflow_attr;\n+    int err;\n+\n+    if (*group_id) {\n+        VLOG_ERR_RL(&error_rl, \"%s: Only a single TC_SAMPLE action \"\n+                    \"per flow is supported\", __func__);\n+        return EOPNOTSUPP;\n+    }\n+\n+    /* If sampling rate is 1, there is only a sFlow cookie inside of a\n+     * userspace action, but no sample attribute. That means we can\n+     * only offload userspace actions for sFlow.\n+     */\n+    memset(&sflow_attr, 0, sizeof sflow_attr);\n+    sflow_attr.ufid = *ufid;\n+    if (flower->tunnel) {\n+        sflow_attr.tunnel = CONST_CAST(struct flow_tnl *, tnl);\n+    }\n+    err = parse_userspace_attributes(userspace_action, &sflow_attr);\n+    if (err) {\n+        return err;\n+    }\n+    sflow_attr.action = userspace_action;\n+    *group_id = sgid_alloc_ctx(&sflow_attr);\n+    if (!*group_id) {\n+        VLOG_DBG_RL(&rl, \"%s: Failed allocating group id for sample action\",\n+                    __func__);\n+        return ENOENT;\n+    }\n+    tc_action->type = TC_ACT_SAMPLE;\n+    tc_action->sample.group_id = *group_id;\n+    tc_action->sample.rate = 1;\n+    flower->action_count++;\n+\n+    return 0;\n+}\n+\n static int\n netdev_tc_flow_put(struct netdev *netdev, struct match *match,\n                    struct nlattr *actions, size_t actions_len,\n@@ -1806,6 +1969,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,\n     const struct flow_tnl *tnl_mask = &mask->tunnel;\n     struct tc_action *action;\n     bool recirc_act = false;\n+    uint32_t sample_gid = 0;\n     uint32_t block_id = 0;\n     struct nlattr *nla;\n     struct tcf_id id;\n@@ -2058,7 +2222,8 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,\n     NL_ATTR_FOR_EACH(nla, left, actions, actions_len) {\n         if (flower.action_count >= TCA_ACT_MAX_NUM) {\n             VLOG_DBG_RL(&rl, \"Can only support %d actions\", TCA_ACT_MAX_NUM);\n-            return EOPNOTSUPP;\n+            err = EOPNOTSUPP;\n+            goto out;\n         }\n         action = &flower.actions[flower.action_count];\n         if (nl_attr_type(nla) == OVS_ACTION_ATTR_OUTPUT) {\n@@ -2068,7 +2233,8 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,\n \n             if (!outdev) {\n                 VLOG_DBG_RL(&rl, \"Can't find netdev for output port %d\", port);\n-                return ENODEV;\n+                err = ENODEV;\n+                goto out;\n             }\n             action->out.ifindex_out = netdev_get_ifindex(outdev);\n             action->out.ingress = is_internal_port(netdev_get_type(outdev));\n@@ -2106,7 +2272,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,\n \n             err = parse_put_flow_set_action(&flower, action, set, set_len);\n             if (err) {\n-                return err;\n+                goto out;\n             }\n             if (action->type == TC_ACT_ENCAP) {\n                 action->encap.tp_dst = info->tp_dst_port;\n@@ -2119,7 +2285,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,\n             err = parse_put_flow_set_masked_action(&flower, action, set,\n                                                    set_len, true);\n             if (err) {\n-                return err;\n+                goto out;\n             }\n         } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_CT) {\n             const struct nlattr *ct = nl_attr_get(nla);\n@@ -2131,7 +2297,7 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,\n \n             err = parse_put_flow_ct_action(&flower, action, ct, ct_len);\n             if (err) {\n-                return err;\n+                goto out;\n             }\n         } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_CT_CLEAR) {\n             action->type = TC_ACT_CT;\n@@ -2147,20 +2313,29 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,\n             action->chain = 0;  /* 0 is reserved and not used by recirc. */\n             flower.action_count++;\n         } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_SAMPLE) {\n-            struct dpif_sflow_attr sflow_attr;\n-\n-            memset(&sflow_attr, 0, sizeof sflow_attr);\n-            sgid_alloc_ctx(&sflow_attr);\n+            err = parse_sample_action(&flower, action, nla, tnl, &sample_gid,\n+                                      ufid);\n+            if (err) {\n+                goto out;\n+            }\n+        } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_USERSPACE) {\n+            err = parse_userspace_action(&flower, action, nla, tnl,\n+                                         &sample_gid, ufid);\n+            if (err) {\n+                goto out;\n+            }\n         } else {\n             VLOG_DBG_RL(&rl, \"unsupported put action type: %d\",\n                         nl_attr_type(nla));\n-            return EOPNOTSUPP;\n+            err = EOPNOTSUPP;\n+            goto out;\n         }\n     }\n \n     if ((chain || recirc_act) && !info->recirc_id_shared_with_tc) {\n         VLOG_ERR_RL(&error_rl, \"flow_put: recirc_id sharing not supported\");\n-        return EOPNOTSUPP;\n+        err = EOPNOTSUPP;\n+        goto out;\n     }\n \n     if (get_ufid_tc_mapping(ufid, &id) == 0) {\n@@ -2173,20 +2348,29 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match,\n     prio = get_prio_for_tc_flower(&flower);\n     if (prio == 0) {\n         VLOG_ERR_RL(&rl, \"couldn't get tc prio: %s\", ovs_strerror(ENOSPC));\n-        return ENOSPC;\n+        err = ENOSPC;\n+        goto out;\n     }\n \n     flower.act_cookie.data = ufid;\n     flower.act_cookie.len = sizeof *ufid;\n \n     block_id = get_block_id_from_netdev(netdev);\n-    id = tc_make_tcf_id_chain(ifindex, block_id, chain, prio, hook);\n+    id = tc_make_tcf_id_all(ifindex, block_id, chain, prio, hook, sample_gid);\n     err = tc_replace_flower(&id, &flower);\n-    if (!err) {\n-        if (stats) {\n-            memset(stats, 0, sizeof *stats);\n-        }\n-        add_ufid_tc_mapping(netdev, ufid, &id);\n+    if (err) {\n+        goto out;\n+    }\n+\n+    if (stats) {\n+        memset(stats, 0, sizeof *stats);\n+    }\n+    add_ufid_tc_mapping(netdev, ufid, &id);\n+    return 0;\n+\n+out:\n+    if (sample_gid) {\n+        sgid_free(sample_gid);\n     }\n \n     return err;\ndiff --git a/lib/tc.c b/lib/tc.c\nindex 38a1dfc0e..dc8db6b22 100644\n--- a/lib/tc.c\n+++ b/lib/tc.c\n@@ -23,14 +23,15 @@\n #include <linux/if_packet.h>\n #include <linux/rtnetlink.h>\n #include <linux/tc_act/tc_csum.h>\n+#include <linux/tc_act/tc_ct.h>\n #include <linux/tc_act/tc_gact.h>\n #include <linux/tc_act/tc_mirred.h>\n #include <linux/tc_act/tc_mpls.h>\n #include <linux/tc_act/tc_pedit.h>\n+#include <linux/tc_act/tc_sample.h>\n #include <linux/tc_act/tc_skbedit.h>\n #include <linux/tc_act/tc_tunnel_key.h>\n #include <linux/tc_act/tc_vlan.h>\n-#include <linux/tc_act/tc_ct.h>\n #include <linux/gen_stats.h>\n #include <net/if.h>\n #include <unistd.h>\n@@ -1341,6 +1342,38 @@ nl_parse_act_gact(struct nlattr *options, struct tc_flower *flower)\n     return 0;\n }\n \n+static const struct nl_policy sample_policy[] = {\n+    [TCA_SAMPLE_PARMS] = { .type = NL_A_UNSPEC,\n+                           .min_len = sizeof(struct tc_sample),\n+                           .optional = false, },\n+    [TCA_SAMPLE_PSAMPLE_GROUP] = { .type = NL_A_U32,\n+                                   .optional = false, },\n+    [TCA_SAMPLE_RATE] = { .type = NL_A_U32,\n+                          .optional = false, },\n+};\n+\n+static int\n+nl_parse_act_sample(struct nlattr *options, struct tc_flower *flower)\n+{\n+    struct nlattr *sample_attrs[ARRAY_SIZE(sample_policy)];\n+    struct tc_action *action;\n+\n+    if (!nl_parse_nested(options, sample_policy, sample_attrs,\n+                         ARRAY_SIZE(sample_policy))) {\n+        VLOG_ERR_RL(&error_rl, \"failed to parse sample action options\");\n+        return EPROTO;\n+    }\n+\n+    action = &flower->actions[flower->action_count++];\n+    action->type = TC_ACT_SAMPLE;\n+    action->sample.group_id =\n+        nl_attr_get_u32(sample_attrs[TCA_SAMPLE_PSAMPLE_GROUP]);\n+    action->sample.rate =\n+        nl_attr_get_u32(sample_attrs[TCA_SAMPLE_RATE]);\n+\n+    return 0;\n+}\n+\n static const struct nl_policy mirred_policy[] = {\n     [TCA_MIRRED_PARMS] = { .type = NL_A_UNSPEC,\n                            .min_len = sizeof(struct tc_mirred),\n@@ -1749,6 +1782,8 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower,\n         /* Added for TC rule only (not in OvS rule) so ignore. */\n     } else if (!strcmp(act_kind, \"ct\")) {\n         nl_parse_act_ct(act_options, flower);\n+    } else if (!strcmp(act_kind, \"sample\")) {\n+        nl_parse_act_sample(act_options, flower);\n     } else {\n         VLOG_ERR_RL(&error_rl, \"unknown tc action kind: %s\", act_kind);\n         err = EINVAL;\n@@ -2375,6 +2410,23 @@ nl_msg_put_act_mirred(struct ofpbuf *request, int ifindex, int action,\n     nl_msg_end_nested(request, offset);\n }\n \n+static void\n+nl_msg_put_act_sample(struct ofpbuf *request, uint32_t rate, uint32_t group_id)\n+{\n+    size_t offset;\n+\n+    nl_msg_put_string(request, TCA_ACT_KIND, \"sample\");\n+    offset = nl_msg_start_nested(request, TCA_ACT_OPTIONS | NLA_F_NESTED);\n+    {\n+        struct tc_sample parm = { .action = TC_ACT_PIPE };\n+\n+        nl_msg_put_unspec(request, TCA_SAMPLE_PARMS, &parm, sizeof parm);\n+        nl_msg_put_u32(request, TCA_SAMPLE_RATE, rate);\n+        nl_msg_put_u32(request, TCA_SAMPLE_PSAMPLE_GROUP, group_id);\n+    }\n+    nl_msg_end_nested(request, offset);\n+}\n+\n static inline void\n nl_msg_put_act_cookie(struct ofpbuf *request, struct tc_cookie *ck) {\n     if (ck->len) {\n@@ -2634,6 +2686,13 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower)\n                 nl_msg_end_nested(request, act_offset);\n             }\n             break;\n+            case TC_ACT_SAMPLE: {\n+                act_offset = nl_msg_start_nested(request, act_index++);\n+                nl_msg_put_act_sample(request, action->sample.rate,\n+                                      action->sample.group_id);\n+                nl_msg_end_nested(request, act_offset);\n+            }\n+            break;\n             case TC_ACT_OUTPUT: {\n                 if (!released && flower->tunnel) {\n                     act_offset = nl_msg_start_nested(request, act_index++);\ndiff --git a/lib/tc.h b/lib/tc.h\nindex 2e4084f48..f764d7d1e 100644\n--- a/lib/tc.h\n+++ b/lib/tc.h\n@@ -174,6 +174,7 @@ enum tc_action_type {\n     TC_ACT_MPLS_SET,\n     TC_ACT_GOTO,\n     TC_ACT_CT,\n+    TC_ACT_SAMPLE,\n };\n \n enum nat_type {\n@@ -256,6 +257,11 @@ struct tc_action {\n             bool force;\n             bool commit;\n         } ct;\n+\n+        struct {\n+            uint32_t rate;\n+            uint32_t group_id;\n+        } sample;\n      };\n \n      enum tc_action_type type;\n@@ -294,12 +300,14 @@ tc_make_tcf_id(int ifindex, uint32_t block_id, uint16_t prio,\n }\n \n static inline struct tcf_id\n-tc_make_tcf_id_chain(int ifindex, uint32_t block_id, uint32_t chain,\n-                     uint16_t prio, enum tc_qdisc_hook hook)\n+tc_make_tcf_id_all(int ifindex, uint32_t block_id, uint32_t chain,\n+                     uint16_t prio, enum tc_qdisc_hook hook,\n+                     uint32_t sample_group_id)\n {\n     struct tcf_id id = tc_make_tcf_id(ifindex, block_id, prio, hook);\n \n     id.chain = chain;\n+    id.sample_group_id = sample_group_id;\n \n     return id;\n }\n@@ -313,7 +321,8 @@ is_tcf_id_eq(struct tcf_id *id1, struct tcf_id *id2)\n            && id1->hook == id2->hook\n            && id1->block_id == id2->block_id\n            && id1->ifindex == id2->ifindex\n-           && id1->chain == id2->chain;\n+           && id1->chain == id2->chain\n+           && id1->sample_group_id == id2->sample_group_id;\n }\n \n enum tc_offload_policy {\n",
    "prefixes": [
        "ovs-dev",
        "v15",
        "7/7"
    ]
}