get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 49994,
    "url": "http://patches.dpdk.org/api/patches/49994/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1548158746-9885-1-git-send-email-viacheslavo@mellanox.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1548158746-9885-1-git-send-email-viacheslavo@mellanox.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1548158746-9885-1-git-send-email-viacheslavo@mellanox.com",
    "date": "2019-01-22T12:05:46",
    "name": "net/mlx5: fix tc rule handle assignment",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "8dd1c62f2c10203797a11386ecc8d2a46395b137",
    "submitter": {
        "id": 1102,
        "url": "http://patches.dpdk.org/api/people/1102/?format=api",
        "name": "Slava Ovsiienko",
        "email": "viacheslavo@mellanox.com"
    },
    "delegate": {
        "id": 6624,
        "url": "http://patches.dpdk.org/api/users/6624/?format=api",
        "username": "shahafs",
        "first_name": "Shahaf",
        "last_name": "Shuler",
        "email": "shahafs@mellanox.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1548158746-9885-1-git-send-email-viacheslavo@mellanox.com/mbox/",
    "series": [
        {
            "id": 3289,
            "url": "http://patches.dpdk.org/api/series/3289/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=3289",
            "date": "2019-01-22T12:05:46",
            "name": "net/mlx5: fix tc rule handle assignment",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/3289/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/49994/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/49994/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id A38F22D13;\n\tTue, 22 Jan 2019 13:06:01 +0100 (CET)",
            "from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129])\n\tby dpdk.org (Postfix) with ESMTP id A44142C36\n\tfor <dev@dpdk.org>; Tue, 22 Jan 2019 13:06:00 +0100 (CET)",
            "from Internal Mail-Server by MTLPINE1 (envelope-from\n\tviacheslavo@mellanox.com)\n\twith ESMTPS (AES256-SHA encrypted); 22 Jan 2019 14:05:56 +0200",
            "from pegasus12.mtr.labs.mlnx. (pegasus12.mtr.labs.mlnx\n\t[10.210.17.40])\n\tby labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x0MC5uCZ023522;\n\tTue, 22 Jan 2019 14:05:56 +0200"
        ],
        "From": "Viacheslav Ovsiienko <viacheslavo@mellanox.com>",
        "To": "dev@dpdk.org",
        "Cc": "shahafs@mellanox.com, stable@dpdk.org",
        "Date": "Tue, 22 Jan 2019 12:05:46 +0000",
        "Message-Id": "<1548158746-9885-1-git-send-email-viacheslavo@mellanox.com>",
        "X-Mailer": "git-send-email 1.8.3.1",
        "Subject": "[dpdk-dev] [PATCH] net/mlx5: fix tc rule handle assignment",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "When tc rule is created via Netlink message application\ncan provide the unique rule value which can be accepted\nby the kernel. Than rule is managed with this assigned\nhandle. It was found that kernel can reject the proposed\nhandle and assign its own handle value, the rule control\nis lost, because application uses its initially prorosed\nrule handle and knows nothing about handle been repleced.\n\nThe kernel can assign handle automatically, the application\ncan get the assigned handle value by specifying NLM_F_ECHO\nflag in Netlink message when rule is being created. The\nkernel sends back the full descriptor of rule and handle\ncan be retrieved from and stored by application for further\nrule management.\n\nFixes: 57123c00c1b8 (\"net/mlx5: add Linux TC flower driver for E-Switch flow\")\nCc: stable@dpdk.org\n\nSigned-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>\n---\n drivers/net/mlx5/mlx5_flow_tcf.c | 97 +++++++++++++++++++++++++---------------\n 1 file changed, 60 insertions(+), 37 deletions(-)",
    "diff": "diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c\nindex cf34742..859e99a 100644\n--- a/drivers/net/mlx5/mlx5_flow_tcf.c\n+++ b/drivers/net/mlx5/mlx5_flow_tcf.c\n@@ -2778,27 +2778,6 @@ struct pedit_parser {\n }\n \n /**\n- * Brand rtnetlink buffer with unique handle.\n- *\n- * This handle should be unique for a given network interface to avoid\n- * collisions.\n- *\n- * @param nlh\n- *   Pointer to Netlink message.\n- * @param handle\n- *   Unique 32-bit handle to use.\n- */\n-static void\n-flow_tcf_nl_brand(struct nlmsghdr *nlh, uint32_t handle)\n-{\n-\tstruct tcmsg *tcm = mnl_nlmsg_get_payload(nlh);\n-\n-\ttcm->tcm_handle = handle;\n-\tDRV_LOG(DEBUG, \"Netlink msg %p is branded with handle %x\",\n-\t\t(void *)nlh, handle);\n-}\n-\n-/**\n  * Prepare a flow object for Linux TC flower. It calculates the maximum size of\n  * memory required, allocates the memory, initializes Netlink message headers\n  * and set unique TC message handle.\n@@ -2888,20 +2867,6 @@ struct pedit_parser {\n \t\tdev_flow->tcf.tunnel->type = FLOW_TCF_TUNACT_VXLAN_DECAP;\n \telse if (action_flags & MLX5_FLOW_ACTION_VXLAN_ENCAP)\n \t\tdev_flow->tcf.tunnel->type = FLOW_TCF_TUNACT_VXLAN_ENCAP;\n-\t/*\n-\t * Generate a reasonably unique handle based on the address of the\n-\t * target buffer.\n-\t *\n-\t * This is straightforward on 32-bit systems where the flow pointer can\n-\t * be used directly. Otherwise, its least significant part is taken\n-\t * after shifting it by the previous power of two of the pointed buffer\n-\t * size.\n-\t */\n-\tif (sizeof(dev_flow) <= 4)\n-\t\tflow_tcf_nl_brand(nlh, (uintptr_t)dev_flow);\n-\telse\n-\t\tflow_tcf_nl_brand(nlh, (uintptr_t)dev_flow >>\n-\t\t\t\t       rte_log2_u32(rte_align32prevpow2(size)));\n \treturn dev_flow;\n }\n \n@@ -5593,6 +5558,7 @@ struct tcf_nlcb_query {\n \tstruct mlx5_flow_tcf_context *ctx = priv->tcf_context;\n \tstruct mlx5_flow *dev_flow;\n \tstruct nlmsghdr *nlh;\n+\tstruct tcmsg *tcm;\n \n \tif (!flow)\n \t\treturn;\n@@ -5613,11 +5579,54 @@ struct tcf_nlcb_query {\n \t\t\t\tdev_flow);\n \t\t\tdev_flow->tcf.tunnel->vtep = NULL;\n \t\t}\n+\t\t/* Cleanup the rule handle value. */\n+\t\ttcm = mnl_nlmsg_get_payload(nlh);\n+\t\ttcm->tcm_handle = 0;\n \t\tdev_flow->tcf.applied = 0;\n \t}\n }\n \n /**\n+ * Fetch the applied rule handle. This is callback routine called by\n+ * libmnl mnl_cb_run() in loop for every message in received packet.\n+ * When the NLM_F_ECHO flag i sspecified the kernel sends the created\n+ * rule descriptor back to the application and we can retrieve the\n+ * actual rule handle from updated descriptor.\n+ *\n+ * @param[in] nlh\n+ *   Pointer to reply header.\n+ * @param[in, out] arg\n+ *   Context pointer for this callback.\n+ *\n+ * @return\n+ *   A positive, nonzero value on success (required by libmnl\n+ *   to continue messages processing).\n+ */\n+static int\n+flow_tcf_collect_apply_cb(const struct nlmsghdr *nlh, void *arg)\n+{\n+\tstruct nlmsghdr *nlhrq = arg;\n+\tstruct tcmsg *tcmrq = mnl_nlmsg_get_payload(nlhrq);\n+\tstruct tcmsg *tcm = mnl_nlmsg_get_payload(nlh);\n+\tstruct nlattr *na;\n+\n+\tif (nlh->nlmsg_type != RTM_NEWTFILTER ||\n+\t    nlh->nlmsg_seq != nlhrq->nlmsg_seq)\n+\t\treturn 1;\n+\tmnl_attr_for_each(na, nlh, sizeof(*tcm)) {\n+\t\tswitch (mnl_attr_get_type(na)) {\n+\t\tcase TCA_KIND:\n+\t\t\tif (strcmp(mnl_attr_get_payload(na), \"flower\")) {\n+\t\t\t\t/* Not flower filter, drop entire message. */\n+\t\t\t\treturn 1;\n+\t\t\t}\n+\t\t\ttcmrq->tcm_handle = tcm->tcm_handle;\n+\t\t\treturn 1;\n+\t\t}\n+\t}\n+\treturn 1;\n+}\n+/**\n  * Apply flow to E-Switch by sending Netlink message.\n  *\n  * @param[in] dev\n@@ -5638,6 +5647,8 @@ struct tcf_nlcb_query {\n \tstruct mlx5_flow_tcf_context *ctx = priv->tcf_context;\n \tstruct mlx5_flow *dev_flow;\n \tstruct nlmsghdr *nlh;\n+\tstruct tcmsg *tcm;\n+\tint ret;\n \n \tdev_flow = LIST_FIRST(&flow->dev_flows);\n \t/* E-Switch flow can't be expanded. */\n@@ -5646,7 +5657,11 @@ struct tcf_nlcb_query {\n \t\treturn 0;\n \tnlh = dev_flow->tcf.nlh;\n \tnlh->nlmsg_type = RTM_NEWTFILTER;\n-\tnlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_EXCL;\n+\tnlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE |\n+\t\t\t   NLM_F_EXCL | NLM_F_ECHO;\n+\ttcm = mnl_nlmsg_get_payload(nlh);\n+\t/* Allow kernel to assign handle on its own. */\n+\ttcm->tcm_handle = 0;\n \tif (dev_flow->tcf.tunnel) {\n \t\t/*\n \t\t * Replace the interface index, target for\n@@ -5667,7 +5682,15 @@ struct tcf_nlcb_query {\n \t\t*dev_flow->tcf.tunnel->ifindex_ptr =\n \t\t\tdev_flow->tcf.tunnel->vtep->ifindex;\n \t}\n-\tif (!flow_tcf_nl_ack(ctx, nlh, NULL, NULL)) {\n+\tret = flow_tcf_nl_ack(ctx, nlh, flow_tcf_collect_apply_cb, nlh);\n+\tif (!ret) {\n+\t\tif (!tcm->tcm_handle) {\n+\t\t\tflow_tcf_remove(dev, flow);\n+\t\t\treturn rte_flow_error_set\n+\t\t\t\t(error, ENOENT,\n+\t\t\t\t RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,\n+\t\t\t\t \"netlink: rule zero handle returned\");\n+\t\t}\n \t\tdev_flow->tcf.applied = 1;\n \t\tif (*dev_flow->tcf.ptc_flags & TCA_CLS_FLAGS_SKIP_SW)\n \t\t\treturn 0;\n",
    "prefixes": []
}