get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 26129,
    "url": "https://patches.dpdk.org/api/patches/26129/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20170630165140.59594-18-ferruh.yigit@intel.com/",
    "project": {
        "id": 1,
        "url": "https://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": "<20170630165140.59594-18-ferruh.yigit@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20170630165140.59594-18-ferruh.yigit@intel.com",
    "date": "2017-06-30T16:51:37",
    "name": "[dpdk-dev,v9,17/20] ctrl_if: process control messages",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "89a4532fa56f460f4ddc2bae582e87bbdf3ac996",
    "submitter": {
        "id": 324,
        "url": "https://patches.dpdk.org/api/people/324/?format=api",
        "name": "Ferruh Yigit",
        "email": "ferruh.yigit@intel.com"
    },
    "delegate": null,
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20170630165140.59594-18-ferruh.yigit@intel.com/mbox/",
    "series": [],
    "comments": "https://patches.dpdk.org/api/patches/26129/comments/",
    "check": "fail",
    "checks": "https://patches.dpdk.org/api/patches/26129/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 [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 305DC7CEC;\n\tFri, 30 Jun 2017 18:52:46 +0200 (CEST)",
            "from mga02.intel.com (mga02.intel.com [134.134.136.20])\n\tby dpdk.org (Postfix) with ESMTP id 42B1C235\n\tfor <dev@dpdk.org>; Fri, 30 Jun 2017 18:52:10 +0200 (CEST)",
            "from orsmga004.jf.intel.com ([10.7.209.38])\n\tby orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t30 Jun 2017 09:52:09 -0700",
            "from silpixa00372839.ir.intel.com (HELO\n\tsilpixa00372839.ger.corp.intel.com) ([10.237.222.154])\n\tby orsmga004.jf.intel.com with ESMTP; 30 Jun 2017 09:52:08 -0700"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.40,287,1496127600\"; d=\"scan'208\";a=\"103233362\"",
        "From": "Ferruh Yigit <ferruh.yigit@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "Ferruh Yigit <ferruh.yigit@intel.com>,\n\tStephen Hemminger <stephen@networkplumber.org>,\n\tBruce Richardson <bruce.richardson@intel.com>,\n\tAnatoly Burakov <anatoly.burakov@intel.com>",
        "Date": "Fri, 30 Jun 2017 17:51:37 +0100",
        "Message-Id": "<20170630165140.59594-18-ferruh.yigit@intel.com>",
        "X-Mailer": "git-send-email 2.13.0",
        "In-Reply-To": "<20170630165140.59594-1-ferruh.yigit@intel.com>",
        "References": "<20170621110651.75299-1-ferruh.yigit@intel.com>\n\t<20170630165140.59594-1-ferruh.yigit@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v9 17/20] ctrl_if: process control messages",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Receive the requests from virtual interface and process control\nmessages.\n\nSigned-off-by: Ferruh Yigit <ferruh.yigit@intel.com>\n---\n lib/librte_ctrl_if/Makefile           |   1 +\n lib/librte_ctrl_if/rte_ctrl_process.c | 167 ++++++++++++++++++++++++++++++++++\n lib/librte_ctrl_if/rte_ctrl_process.h |  50 ++++++++++\n lib/librte_ctrl_if/rte_nl.c           | 130 ++++++++++++++++++++++++++\n 4 files changed, 348 insertions(+)\n create mode 100644 lib/librte_ctrl_if/rte_ctrl_process.c\n create mode 100644 lib/librte_ctrl_if/rte_ctrl_process.h",
    "diff": "diff --git a/lib/librte_ctrl_if/Makefile b/lib/librte_ctrl_if/Makefile\nindex 0da04f7d0..67b9967b4 100644\n--- a/lib/librte_ctrl_if/Makefile\n+++ b/lib/librte_ctrl_if/Makefile\n@@ -46,6 +46,7 @@ LIBABIVER := 1\n \n SRCS-$(CONFIG_RTE_LIBRTE_CTRL_IF) := rte_ctrl_if.c\n SRCS-$(CONFIG_RTE_LIBRTE_CTRL_IF) += rte_nl.c\n+SRCS-$(CONFIG_RTE_LIBRTE_CTRL_IF) += rte_ctrl_process.c\n \n #\n # Export include files\ndiff --git a/lib/librte_ctrl_if/rte_ctrl_process.c b/lib/librte_ctrl_if/rte_ctrl_process.c\nnew file mode 100644\nindex 000000000..cfb243f64\n--- /dev/null\n+++ b/lib/librte_ctrl_if/rte_ctrl_process.c\n@@ -0,0 +1,167 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <stdio.h>\n+#include <error.h>\n+\n+#include <linux/if_link.h>\n+\n+#include <rte_version.h>\n+#include <rte_ethdev.h>\n+#include \"rte_ctrl_process.h\"\n+\n+static int\n+set_mtu(uint8_t port_id, void *in_data)\n+{\n+\tint *mtu = in_data;\n+\n+\treturn rte_eth_dev_set_mtu(port_id, *mtu);\n+}\n+\n+static int\n+get_stats(uint8_t port_id, void *data, size_t *data_len)\n+{\n+\tstruct rte_eth_stats stats;\n+\tstruct rtnl_link_stats64 *if_stats = data;\n+\tint ret;\n+\n+\tret = rte_eth_stats_get(port_id, &stats);\n+\tif (ret < 0)\n+\t\treturn -EOPNOTSUPP;\n+\n+\tif_stats->rx_packets = stats.ipackets;\n+\tif_stats->tx_packets = stats.opackets;\n+\tif_stats->rx_bytes = stats.ibytes;\n+\tif_stats->tx_bytes = stats.obytes;\n+\tif_stats->rx_errors = stats.ierrors;\n+\tif_stats->tx_errors = stats.oerrors;\n+\tif_stats->rx_dropped = stats.imissed;\n+\n+\t*data_len = sizeof(struct rtnl_link_stats64);\n+\n+\treturn 0;\n+}\n+\n+static int\n+get_mac(uint8_t port_id, void *data, size_t *data_len)\n+{\n+\tstruct ether_addr addr;\n+\n+\trte_eth_macaddr_get(port_id, &addr);\n+\tmemcpy(data, &addr, sizeof(struct ether_addr));\n+\n+\t*data_len = sizeof(struct ether_addr);\n+\n+\treturn 0;\n+}\n+\n+static int\n+set_mac(uint8_t port_id, void *in_data)\n+{\n+\tstruct ether_addr addr;\n+\n+\tmemcpy(&addr, in_data, ETHER_ADDR_LEN);\n+\n+\treturn rte_eth_dev_default_mac_addr_set(port_id, &addr);\n+}\n+\n+static int\n+start_port(uint8_t port_id)\n+{\n+\trte_eth_dev_stop(port_id);\n+\treturn rte_eth_dev_start(port_id);\n+}\n+\n+static int\n+stop_port(uint8_t port_id)\n+{\n+\trte_eth_dev_stop(port_id);\n+\treturn 0;\n+}\n+\n+static int\n+set_promisc(uint8_t port_id, void *in_data)\n+{\n+\tint *promisc = in_data;\n+\n+\tif (*promisc)\n+\t\trte_eth_promiscuous_enable(port_id);\n+\telse\n+\t\trte_eth_promiscuous_disable(port_id);\n+\n+\treturn 0;\n+}\n+\n+static int\n+set_allmulti(uint8_t port_id, void *in_data)\n+{\n+\tint *allmulti = in_data;\n+\n+\tif (*allmulti)\n+\t\trte_eth_allmulticast_enable(port_id);\n+\telse\n+\t\trte_eth_allmulticast_disable(port_id);\n+\n+\treturn 0;\n+}\n+\n+int\n+rte_eth_dev_control_process(uint32_t cmd_id, uint8_t port_id, void *in_data,\n+\t\tvoid *out_data, size_t *out_data_len)\n+{\n+\tif (!rte_eth_dev_is_valid_port(port_id))\n+\t\treturn -ENODEV;\n+\n+\tswitch (cmd_id) {\n+\tcase UNCI_REQ_CHANGE_MTU:\n+\t\treturn set_mtu(port_id, in_data);\n+\tcase UNCI_REQ_GET_STATS:\n+\t\treturn get_stats(port_id, out_data, out_data_len);\n+\tcase UNCI_REQ_GET_MAC:\n+\t\treturn get_mac(port_id, out_data, out_data_len);\n+\tcase UNCI_REQ_SET_MAC:\n+\t\treturn set_mac(port_id, in_data);\n+\tcase UNCI_REQ_START_PORT:\n+\t\treturn start_port(port_id);\n+\tcase UNCI_REQ_STOP_PORT:\n+\t\treturn stop_port(port_id);\n+\tcase UNCI_REQ_SET_PROMISC:\n+\t\treturn set_promisc(port_id, in_data);\n+\tcase UNCI_REQ_SET_ALLMULTI:\n+\t\treturn set_allmulti(port_id, in_data);\n+\tdefault:\n+\t\treturn -EOPNOTSUPP;\n+\t}\n+\n+\treturn 0;\n+}\ndiff --git a/lib/librte_ctrl_if/rte_ctrl_process.h b/lib/librte_ctrl_if/rte_ctrl_process.h\nnew file mode 100644\nindex 000000000..f67c60107\n--- /dev/null\n+++ b/lib/librte_ctrl_if/rte_ctrl_process.h\n@@ -0,0 +1,50 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2016 Intel Corporation. All rights reserved.\n+ *   All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#ifndef _RTE_CTRL_ETHTOOL_H_\n+#define _RTE_CTRL_ETHTOOL_H_\n+\n+#ifdef __cplusplus\n+extern \"C\" {\n+#endif\n+\n+#include <exec-env/rte_unci_common.h>\n+\n+int rte_eth_dev_control_process(uint32_t cmd_id, uint8_t port_id, void *in_data,\n+\t\tvoid *out_data, size_t *out_data_len);\n+\n+#ifdef __cplusplus\n+}\n+#endif\n+\n+#endif /* _RTE_CTRL_ETHTOOL_H_ */\ndiff --git a/lib/librte_ctrl_if/rte_nl.c b/lib/librte_ctrl_if/rte_nl.c\nindex e88b3fc91..920d123a9 100644\n--- a/lib/librte_ctrl_if/rte_nl.c\n+++ b/lib/librte_ctrl_if/rte_nl.c\n@@ -39,6 +39,7 @@\n \n #include <rte_spinlock.h>\n #include <rte_log.h>\n+#include \"rte_ctrl_process.h\"\n #include \"rte_nl.h\"\n #include \"rte_ctrl_if.h\"\n \n@@ -54,12 +55,139 @@ struct ctrl_if_nl {\n \tstruct sockaddr_nl dest_addr;\n };\n \n+struct ctrl_if_msg_sync {\n+\tstruct unci_nl_msg msg_storage;\n+\tpthread_mutex_t msg_lock;\n+\tuint32_t pending_process;\n+};\n+\n+\n+/**\n+ * Flags values for rte_eth_control_interface_process_msg() API\n+ */\n+enum control_interface_process_flag {\n+\t/**< Process if msg available. */\n+\tRTE_ETHTOOL_CTRL_IF_PROCESS_MSG,\n+\n+\t/**< Discard msg if available, respond with a error value. */\n+\tRTE_ETHTOOL_CTRL_IF_DISCARD_MSG,\n+};\n+\n static int sock_fd = -1;\n static pthread_t thread_id;\n \n static struct ctrl_if_nl nl_s;\n static struct ctrl_if_nl nl_r;\n \n+static struct ctrl_if_msg_sync ctrl_if_sync = {\n+\t.msg_lock = PTHREAD_MUTEX_INITIALIZER,\n+};\n+\n+static int\n+nl_send(void *buf, size_t len)\n+{\n+\tint ret;\n+\n+\tif (nl_s.nlh.nlmsg_len < len) {\n+\t\tRTE_LOG(ERR, CTRL_IF, \"Message is too big, len:%zu\\n\", len);\n+\t\treturn -1;\n+\t}\n+\n+\tif (!NLMSG_OK(&nl_s.nlh, NLMSG_SPACE(MAX_PAYLOAD))) {\n+\t\tRTE_LOG(ERR, CTRL_IF, \"Message is not OK\\n\");\n+\t\treturn -1;\n+\t}\n+\n+\t/* Fill in the netlink message payload */\n+\tmemcpy(NLMSG_DATA(nl_s.nlmsg), buf, len);\n+\n+\tret = sendmsg(sock_fd, &nl_s.msg, 0);\n+\n+\tif (ret < 0)\n+\t\tRTE_LOG(ERR, CTRL_IF, \"Failed nl msg send. ret:%d, err:%d\\n\",\n+\t\t\t\tret, errno);\n+\treturn ret;\n+}\n+\n+/* each request sent expects a reply */\n+static int\n+nl_reply(struct unci_nl_msg *msg)\n+{\n+\treturn nl_send((void *)msg, sizeof(struct unci_nl_msg));\n+}\n+\n+static void\n+process_msg(struct unci_nl_msg *msg)\n+{\n+\tif (msg->cmd_id > UNCI_REQ_UNKNOWN) {\n+\t\tmsg->err = rte_eth_dev_control_process(msg->cmd_id,\n+\t\t\t\tmsg->port_id, msg->input_buffer,\n+\t\t\t\tmsg->output_buffer, &msg->output_buffer_len);\n+\t}\n+\n+\tif (msg->err)\n+\t\tmemset(msg->output_buffer, 0, msg->output_buffer_len);\n+\n+\tnl_reply(msg);\n+}\n+\n+static int\n+control_interface_msg_process(uint32_t flag)\n+{\n+\tstruct unci_nl_msg msg_storage;\n+\tint ret = 0;\n+\n+\tpthread_mutex_lock(&ctrl_if_sync.msg_lock);\n+\tif (ctrl_if_sync.pending_process == 0) {\n+\t\tpthread_mutex_unlock(&ctrl_if_sync.msg_lock);\n+\t\treturn 0;\n+\t}\n+\n+\tmemcpy(&msg_storage, &ctrl_if_sync.msg_storage,\n+\t\t\tsizeof(struct unci_nl_msg));\n+\tctrl_if_sync.pending_process = 0;\n+\tpthread_mutex_unlock(&ctrl_if_sync.msg_lock);\n+\n+\tswitch (flag) {\n+\tcase RTE_ETHTOOL_CTRL_IF_PROCESS_MSG:\n+\t\tprocess_msg(&msg_storage);\n+\t\tbreak;\n+\n+\tcase RTE_ETHTOOL_CTRL_IF_DISCARD_MSG:\n+\t\tmsg_storage.err = -1;\n+\t\tnl_reply(&msg_storage);\n+\t\tbreak;\n+\n+\tdefault:\n+\t\tret = -1;\n+\t\tbreak;\n+\t}\n+\n+\treturn ret;\n+}\n+\n+static int\n+msg_add_and_process(struct nlmsghdr *nlh)\n+{\n+\tpthread_mutex_lock(&ctrl_if_sync.msg_lock);\n+\n+\tif (ctrl_if_sync.pending_process) {\n+\t\tpthread_mutex_unlock(&ctrl_if_sync.msg_lock);\n+\t\treturn -1;\n+\t}\n+\n+\tmemcpy(&ctrl_if_sync.msg_storage, NLMSG_DATA(nlh),\n+\t\t\tsizeof(struct unci_nl_msg));\n+\tctrl_if_sync.msg_storage.flag = UNCI_MSG_FLAG_RESPONSE;\n+\tctrl_if_sync.pending_process = 1;\n+\n+\tpthread_mutex_unlock(&ctrl_if_sync.msg_lock);\n+\n+\tcontrol_interface_msg_process(RTE_ETHTOOL_CTRL_IF_PROCESS_MSG);\n+\n+\treturn 0;\n+}\n+\n static void *\n nl_recv(void *arg)\n {\n@@ -76,6 +204,8 @@ nl_recv(void *arg)\n \t\t\t\t\tret, sizeof(struct unci_nl_msg));\n \t\t\tcontinue;\n \t\t}\n+\n+\t\tmsg_add_and_process(&nl_r.nlh);\n \t}\n \n \treturn arg;\n",
    "prefixes": [
        "dpdk-dev",
        "v9",
        "17/20"
    ]
}