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

Message ID 20170630165140.59594-11-ferruh.yigit@intel.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Ferruh Yigit June 30, 2017, 4:51 p.m. UTC
  Initialize netlink socket.

Userspace application will connect to the socket for data transfer.

Signed-off-by: Ferruh Yigit <ferruh.yigit@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
  

Comments

Stephen Hemminger June 30, 2017, 5:28 p.m. UTC | #1
On Fri, 30 Jun 2017 17:51:30 +0100
Ferruh Yigit <ferruh.yigit@intel.com> wrote:

>  #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,

Kernel code should not use uint32_t or uint8_t.
Stick to __u32 and __u8
  
Stephen Hemminger June 30, 2017, 5:29 p.m. UTC | #2
On Fri, 30 Jun 2017 17:51:30 +0100
Ferruh Yigit <ferruh.yigit@intel.com> wrote:

> +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);
> +}

What if netlink socket create fails?

Also, don't need to call mutex_init if you use simpler initailizer.

static DEFINE_MUTEX(sync_lock);
  

Patch

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);
+}