From: Ferruh Yigit <ferruh.yigit@intel.com>
To: dev@dpdk.org
Cc: Ferruh Yigit <ferruh.yigit@intel.com>,
Stephen Hemminger <stephen@networkplumber.org>,
Bruce Richardson <bruce.richardson@intel.com>,
Anatoly Burakov <anatoly.burakov@intel.com>
Subject: [dpdk-dev] [PATCH v9 16/20] ctrl_if: initialize netlink interface
Date: Fri, 30 Jun 2017 17:51:36 +0100 [thread overview]
Message-ID: <20170630165140.59594-17-ferruh.yigit@intel.com> (raw)
In-Reply-To: <20170630165140.59594-1-ferruh.yigit@intel.com>
Initialize netlink sockets to exchange data between kernelspace.
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
lib/librte_ctrl_if/Makefile | 2 +
lib/librte_ctrl_if/rte_ctrl_if.c | 9 +++
lib/librte_ctrl_if/rte_nl.c | 158 +++++++++++++++++++++++++++++++++++++++
lib/librte_ctrl_if/rte_nl.h | 48 ++++++++++++
4 files changed, 217 insertions(+)
create mode 100644 lib/librte_ctrl_if/rte_nl.c
create mode 100644 lib/librte_ctrl_if/rte_nl.h
diff --git a/lib/librte_ctrl_if/Makefile b/lib/librte_ctrl_if/Makefile
index c682af4c4..0da04f7d0 100644
--- a/lib/librte_ctrl_if/Makefile
+++ b/lib/librte_ctrl_if/Makefile
@@ -38,12 +38,14 @@ LIB = librte_ctrl_if.a
CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lpthread
EXPORT_MAP := rte_ctrl_if_version.map
LIBABIVER := 1
SRCS-$(CONFIG_RTE_LIBRTE_CTRL_IF) := rte_ctrl_if.c
+SRCS-$(CONFIG_RTE_LIBRTE_CTRL_IF) += rte_nl.c
#
# Export include files
diff --git a/lib/librte_ctrl_if/rte_ctrl_if.c b/lib/librte_ctrl_if/rte_ctrl_if.c
index 8b0718969..a26699be7 100644
--- a/lib/librte_ctrl_if/rte_ctrl_if.c
+++ b/lib/librte_ctrl_if/rte_ctrl_if.c
@@ -44,6 +44,7 @@
#include <rte_log.h>
#include "rte_ctrl_if.h"
+#include "rte_nl.h"
#define NAMESZ 32
#define IFNAME "dpdk"
@@ -95,6 +96,13 @@ control_interface_init(void)
return -1;
}
+ ret = control_interface_nl_init();
+ if (ret < 0) {
+ RTE_LOG(ERR, CTRL_IF, "Failed to initialize netlink\n");
+ close(unci_rtnl_fd);
+ unci_rtnl_fd = -1;
+ }
+
return ret;
}
@@ -119,6 +127,7 @@ static void
control_interface_release(void)
{
close(unci_rtnl_fd);
+ control_interface_nl_release();
}
static int
diff --git a/lib/librte_ctrl_if/rte_nl.c b/lib/librte_ctrl_if/rte_nl.c
new file mode 100644
index 000000000..e88b3fc91
--- /dev/null
+++ b/lib/librte_ctrl_if/rte_nl.c
@@ -0,0 +1,158 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2017 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <string.h>
+#include <unistd.h>
+
+#include <sys/socket.h>
+#include <linux/netlink.h>
+
+#include <rte_spinlock.h>
+#include <rte_log.h>
+#include "rte_nl.h"
+#include "rte_ctrl_if.h"
+
+#define MAX_PAYLOAD sizeof(struct unci_nl_msg)
+
+struct ctrl_if_nl {
+ union {
+ struct nlmsghdr nlh;
+ uint8_t nlmsg[NLMSG_SPACE(MAX_PAYLOAD)];
+ };
+ struct msghdr msg;
+ struct iovec iov;
+ struct sockaddr_nl dest_addr;
+};
+
+static int sock_fd = -1;
+static pthread_t thread_id;
+
+static struct ctrl_if_nl nl_s;
+static struct ctrl_if_nl nl_r;
+
+static void *
+nl_recv(void *arg)
+{
+ int ret;
+
+ for (;;) {
+ ret = recvmsg(sock_fd, &nl_r.msg, 0);
+ if (ret < 0)
+ continue;
+
+ if ((unsigned int)ret < sizeof(struct unci_nl_msg)) {
+ RTE_LOG(WARNING, CTRL_IF,
+ "Received %d bytes, payload %zu\n",
+ ret, sizeof(struct unci_nl_msg));
+ continue;
+ }
+ }
+
+ return arg;
+}
+
+static void
+nl_setup_header(struct ctrl_if_nl *nl)
+{
+ nl->dest_addr.nl_family = AF_NETLINK;
+ nl->dest_addr.nl_pid = 0; /* For Linux Kernel */
+ nl->dest_addr.nl_groups = 0;
+
+ memset(nl->nlmsg, 0, NLMSG_SPACE(MAX_PAYLOAD));
+
+ /* Fill the netlink message header */
+ nl->nlh.nlmsg_len = NLMSG_LENGTH(MAX_PAYLOAD);
+ nl->nlh.nlmsg_pid = getpid(); /* self pid */
+ nl->nlh.nlmsg_flags = 0;
+
+ nl->iov.iov_base = (void *)nl->nlmsg;
+ nl->iov.iov_len = nl->nlh.nlmsg_len;
+ memset(&nl->msg, 0, sizeof(struct msghdr));
+ nl->msg.msg_name = (void *)&nl->dest_addr;
+ nl->msg.msg_namelen = sizeof(struct sockaddr_nl);
+ nl->msg.msg_iov = &nl->iov;
+ nl->msg.msg_iovlen = 1;
+}
+
+static int
+nl_socket_init(void)
+{
+ struct sockaddr_nl src_addr;
+ int fd;
+ int ret;
+
+ fd = socket(PF_NETLINK, SOCK_RAW, UNCI_NL_GRP);
+ if (fd < 0)
+ return -1;
+
+ src_addr.nl_family = AF_NETLINK;
+ src_addr.nl_pid = getpid();
+ ret = bind(fd, (struct sockaddr *)&src_addr, sizeof(src_addr));
+ if (ret) {
+ close(fd);
+ return -1;
+ }
+
+ nl_setup_header(&nl_s);
+ nl_setup_header(&nl_r);
+
+ return fd;
+}
+
+int
+control_interface_nl_init(void)
+{
+ int ret;
+
+ sock_fd = nl_socket_init();
+ if (sock_fd < 0) {
+ RTE_LOG(ERR, CTRL_IF, "Failed to initialize netlink socket\n");
+ return -1;
+ }
+
+ ret = pthread_create(&thread_id, NULL, nl_recv, NULL);
+ if (ret != 0) {
+ RTE_LOG(ERR, CTRL_IF, "Failed to create receive thread\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+void
+control_interface_nl_release(void)
+{
+ pthread_cancel(thread_id);
+ pthread_join(thread_id, NULL);
+ close(sock_fd);
+}
diff --git a/lib/librte_ctrl_if/rte_nl.h b/lib/librte_ctrl_if/rte_nl.h
new file mode 100644
index 000000000..05a61e193
--- /dev/null
+++ b/lib/librte_ctrl_if/rte_nl.h
@@ -0,0 +1,48 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2017 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_NL_H_
+#define _RTE_NL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int control_interface_nl_init(void);
+void control_interface_nl_release(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_NL_H_ */
--
2.13.0
next prev parent reply other threads:[~2017-06-30 16:52 UTC|newest]
Thread overview: 91+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-26 16:52 [dpdk-dev] [RFC] Kernel Control Path (KCP) Ferruh Yigit
2017-05-28 16:55 ` Wiles, Keith
2017-05-29 9:26 ` Bruce Richardson
2017-05-29 17:29 ` Wiles, Keith
2017-06-16 15:54 ` Ferruh Yigit
2017-06-20 12:33 ` Ferruh Yigit
2017-05-30 10:55 ` Thomas Monjalon
2017-06-13 17:21 ` Ferruh Yigit
2017-06-13 18:00 ` Jay Rolette
2017-06-13 18:04 ` Dumitrescu, Cristian
2017-06-13 18:18 ` Wiles, Keith
2017-06-15 12:07 ` Alex Rosenbaum
2017-06-16 15:27 ` Ferruh Yigit
2017-06-16 16:48 ` Stephen Hemminger
2017-06-13 18:17 ` Wiles, Keith
2017-06-21 11:06 ` [dpdk-dev] [PATCH v8 0/4] Userspace Network Control Interface (UNCI) Ferruh Yigit
2017-06-21 11:06 ` [dpdk-dev] [PATCH v8 1/4] ethtool: move from sample folder to lib folder Ferruh Yigit
2017-06-26 11:02 ` Bruce Richardson
2017-06-21 11:06 ` [dpdk-dev] [PATCH v8 2/4] unci: add kernel control path kernel module Ferruh Yigit
2017-06-21 15:23 ` Stephen Hemminger
2017-06-30 17:02 ` Ferruh Yigit
2017-06-21 11:06 ` [dpdk-dev] [PATCH v8 3/4] rte_ctrl_if: add control interface library Ferruh Yigit
2017-06-26 11:09 ` Bruce Richardson
2017-06-26 11:30 ` Bruce Richardson
2017-06-21 11:06 ` [dpdk-dev] [PATCH v8 4/4] ethdev: add control interface support Ferruh Yigit
2017-06-21 15:24 ` Stephen Hemminger
2017-06-30 17:06 ` Ferruh Yigit
2017-06-26 11:39 ` [dpdk-dev] [PATCH v8 0/4] Userspace Network Control Interface (UNCI) Bruce Richardson
2017-06-29 16:13 ` Ferruh Yigit
2017-06-30 16:56 ` Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 00/20] " Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 01/20] ethtool: add library skeleton Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 02/20] ethtool: move from sample folder into lib folder Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 03/20] ethtool: remove PMD specific API call Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 04/20] ethtool: update header doxygen syntax Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 05/20] ethtool: enable library Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 06/20] doc: add ethtool library documentation Ferruh Yigit
2017-07-02 20:18 ` Mcnamara, John
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 07/20] doc: update ethtool sample app doc Ferruh Yigit
2017-07-02 20:17 ` Mcnamara, John
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 08/20] unci: add module skeleton Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 09/20] unci: add rtnl newlink Ferruh Yigit
2017-06-30 17:27 ` Stephen Hemminger
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 10/20] unci: init netlink Ferruh Yigit
2017-06-30 17:28 ` Stephen Hemminger
2017-06-30 17:29 ` Stephen Hemminger
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 11/20] unci: add netlink exec Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 12/20] unci: add netdevice ops Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 13/20] unci: add ethtool support Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 14/20] ctrl_if: add library skeleton Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 15/20] ctrl_if: add create destroy interface APIs Ferruh Yigit
2017-06-30 16:51 ` Ferruh Yigit [this message]
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 17/20] ctrl_if: process control messages Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 18/20] ctrl_if: process ethtool messages Ferruh Yigit
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 19/20] doc: add control interface library documentation Ferruh Yigit
2017-07-02 20:16 ` Mcnamara, John
2017-06-30 16:51 ` [dpdk-dev] [PATCH v9 20/20] ethdev: add control interface support Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 00/20] Userspace Network Control Interface (UNCI) Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 01/20] ethtool: add library skeleton Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 02/20] ethtool: move from sample folder into lib folder Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 03/20] ethtool: remove PMD specific API call Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 04/20] ethtool: update header doxygen syntax Ferruh Yigit
2017-07-06 9:18 ` Burakov, Anatoly
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 05/20] ethtool: enable library Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 06/20] doc: add ethtool library documentation Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 07/20] doc: update ethtool sample app doc Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 08/20] unci: add module skeleton Ferruh Yigit
2017-07-06 9:25 ` Burakov, Anatoly
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 09/20] unci: add rtnl newlink Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 10/20] unci: init netlink Ferruh Yigit
2017-07-06 9:32 ` Burakov, Anatoly
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 11/20] unci: add netlink exec Ferruh Yigit
2017-07-05 19:07 ` Stephen Hemminger
2017-07-06 10:45 ` Ferruh Yigit
2017-07-07 0:25 ` Stephen Hemminger
2017-07-05 19:15 ` Stephen Hemminger
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 12/20] unci: add netdevice ops Ferruh Yigit
2017-07-05 19:12 ` Stephen Hemminger
2017-07-05 19:12 ` Stephen Hemminger
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 13/20] unci: add ethtool support Ferruh Yigit
2017-07-05 19:07 ` Stephen Hemminger
2017-07-05 19:08 ` Stephen Hemminger
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 14/20] ctrl_if: add library skeleton Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 15/20] ctrl_if: add create destroy interface APIs Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 16/20] ctrl_if: initialize generic netlink interface Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 17/20] ctrl_if: process control messages Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 18/20] ctrl_if: process ethtool messages Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 19/20] doc: add control interface library documentation Ferruh Yigit
2017-07-04 16:13 ` [dpdk-dev] [PATCH v10 20/20] ethdev: add control interface support Ferruh Yigit
2017-07-08 6:28 ` Yuanhan Liu
2017-07-20 14:55 ` Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170630165140.59594-17-ferruh.yigit@intel.com \
--to=ferruh.yigit@intel.com \
--cc=anatoly.burakov@intel.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).