[dpdk-dev,v9,10/20] unci: init netlink
Checks
Commit Message
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
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
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);
@@ -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,
@@ -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
@@ -38,4 +38,7 @@ struct unci_dev {
u32 pid;
};
+void unci_nl_init(void);
+void unci_nl_release(void);
+
#endif /* _UNCI_DEV_H_ */
@@ -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);
new file mode 100644
@@ -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);
+}