[dpdk-dev] [PATCH v9 10/20] unci: init netlink

Ferruh Yigit ferruh.yigit at intel.com
Fri Jun 30 18:51:30 CEST 2017


Initialize netlink socket.

Userspace application will connect to the socket for data transfer.

Signed-off-by: Ferruh Yigit <ferruh.yigit at intel.com>
---
 .../eal/include/exec-env/rte_unci_common.h         | 14 ++++++
 lib/librte_eal/linuxapp/unci/Makefile              |  1 +
 lib/librte_eal/linuxapp/unci/unci_dev.h            |  3 ++
 lib/librte_eal/linuxapp/unci/unci_net.c            |  2 +
 lib/librte_eal/linuxapp/unci/unci_nl.c             | 55 ++++++++++++++++++++++
 5 files changed, 75 insertions(+)
 create mode 100644 lib/librte_eal/linuxapp/unci/unci_nl.c

diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_unci_common.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_unci_common.h
index d90423a07..a14c463a0 100644
--- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_unci_common.h
+++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_unci_common.h
@@ -60,6 +60,20 @@
 
 #define UNCI_DEVICE "unci"
 
+#define UNCI_NL_GRP 31
+
+#define UNCI_NL_MSG_LEN 500
+struct unci_nl_msg {
+	uint32_t cmd_id;
+	uint8_t port_id;
+	uint32_t flag;
+	uint8_t input_buffer[UNCI_NL_MSG_LEN];
+	uint8_t output_buffer[UNCI_NL_MSG_LEN];
+	size_t input_buffer_len;
+	size_t output_buffer_len;
+	int err;
+};
+
 enum {
 	IFLA_UNCI_UNSPEC,
 	IFLA_UNCI_PORTID,
diff --git a/lib/librte_eal/linuxapp/unci/Makefile b/lib/librte_eal/linuxapp/unci/Makefile
index 02e354814..c2a81be7d 100644
--- a/lib/librte_eal/linuxapp/unci/Makefile
+++ b/lib/librte_eal/linuxapp/unci/Makefile
@@ -48,5 +48,6 @@ MODULE_CFLAGS += -Wall -Werror
 # all source are stored in SRCS-y
 #
 SRCS-$(CONFIG_RTE_UNCI_KMOD) := unci_net.c
+SRCS-$(CONFIG_RTE_UNCI_KMOD) += unci_nl.c
 
 include $(RTE_SDK)/mk/rte.module.mk
diff --git a/lib/librte_eal/linuxapp/unci/unci_dev.h b/lib/librte_eal/linuxapp/unci/unci_dev.h
index b0a215f1b..668574167 100644
--- a/lib/librte_eal/linuxapp/unci/unci_dev.h
+++ b/lib/librte_eal/linuxapp/unci/unci_dev.h
@@ -38,4 +38,7 @@ struct unci_dev {
 	u32 pid;
 };
 
+void unci_nl_init(void);
+void unci_nl_release(void);
+
 #endif /* _UNCI_DEV_H_ */
diff --git a/lib/librte_eal/linuxapp/unci/unci_net.c b/lib/librte_eal/linuxapp/unci/unci_net.c
index ee23b0e4d..131769c37 100644
--- a/lib/librte_eal/linuxapp/unci/unci_net.c
+++ b/lib/librte_eal/linuxapp/unci/unci_net.c
@@ -63,6 +63,7 @@ static struct rtnl_link_ops unci_link_ops __read_mostly = {
 
 static int __init unci_init(void)
 {
+	unci_nl_init();
 	return rtnl_link_register(&unci_link_ops);
 }
 module_init(unci_init);
@@ -70,6 +71,7 @@ module_init(unci_init);
 static void __exit unci_exit(void)
 {
 	rtnl_link_unregister(&unci_link_ops);
+	unci_nl_release();
 }
 module_exit(unci_exit);
 
diff --git a/lib/librte_eal/linuxapp/unci/unci_nl.c b/lib/librte_eal/linuxapp/unci/unci_nl.c
new file mode 100644
index 000000000..9d07e9822
--- /dev/null
+++ b/lib/librte_eal/linuxapp/unci/unci_nl.c
@@ -0,0 +1,55 @@
+/*-
+ * GPL LICENSE SUMMARY
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of version 2 of the GNU General Public License as
+ *   published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful, but
+ *   WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *   General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program;
+ *   The full GNU General Public License is included in this distribution
+ *   in the file called LICENSE.GPL.
+ *
+ *   Contact Information:
+ *   Intel Corporation
+ */
+
+#include <net/sock.h>
+
+#include "unci_dev.h"
+
+static struct sock *nl_sock;
+static struct mutex sync_lock;
+
+static void nl_recv(struct sk_buff *skb)
+{
+	struct nlmsghdr *nlh;
+	struct unci_nl_msg nl_msg;
+
+	nlh = (struct nlmsghdr *)skb->data;
+
+	memcpy(&nl_msg, NLMSG_DATA(nlh), sizeof(struct unci_nl_msg));
+	pr_debug("CMD: %u\n", nl_msg.cmd_id);
+}
+
+static struct netlink_kernel_cfg cfg = {
+	.input = nl_recv,
+};
+
+void unci_nl_init(void)
+{
+	nl_sock = netlink_kernel_create(&init_net, UNCI_NL_GRP, &cfg);
+	mutex_init(&sync_lock);
+}
+
+void unci_nl_release(void)
+{
+	netlink_kernel_release(nl_sock);
+}
-- 
2.13.0



More information about the dev mailing list