[dpdk-dev] [PATCH v10 09/20] unci: add rtnl newlink

Ferruh Yigit ferruh.yigit at intel.com
Tue Jul 4 18:13:26 CEST 2017


Use rtnl to create a new interface. Interface is not setup yet.

Pid and port_id should be provided by userspace application that does
the call for interface creation.

Signed-off-by: Ferruh Yigit <ferruh.yigit at intel.com>
---
 lib/librte_eal/linuxapp/eal/Makefile               |  1 +
 .../linuxapp/eal/include/exec-env/unci.h           | 73 ++++++++++++++++++++++
 lib/librte_eal/linuxapp/unci/unci_dev.h            |  8 +++
 lib/librte_eal/linuxapp/unci/unci_net.c            | 50 ++++++++++++++-
 4 files changed, 131 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_eal/linuxapp/eal/include/exec-env/unci.h

diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 8651e2783..139e56033 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -130,6 +130,7 @@ CFLAGS_eal_thread.o += -Wno-return-type
 endif
 
 INC := rte_interrupts.h rte_kni_common.h rte_dom0_common.h
+INC += unci.h
 
 SYMLINK-$(CONFIG_RTE_EXEC_ENV_LINUXAPP)-include/exec-env := \
 	$(addprefix include/exec-env/,$(INC))
diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h b/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h
new file mode 100644
index 000000000..8d4a95777
--- /dev/null
+++ b/lib/librte_eal/linuxapp/eal/include/exec-env/unci.h
@@ -0,0 +1,73 @@
+/*-
+ *   This file is provided under a dual BSD/LGPLv2 license.  When using or
+ *   redistributing this file, you may do so under either license.
+ *
+ *   GNU LESSER GENERAL PUBLIC LICENSE
+ *
+ *   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.1 of the GNU Lesser 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
+ *   Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this program;
+ *
+ *   Contact Information:
+ *   Intel Corporation
+ *
+ *
+ *   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 _UAPI_LINUX_UNCI_H_
+#define _UAPI_LINUX_UNCI_H_
+
+#define UNCI_DEVICE "unci"
+
+/* can go into include/uapi/linux/if_link.h */
+enum {
+	IFLA_UNCI_UNSPEC,
+	IFLA_UNCI_PORTID,
+	IFLA_UNCI_PID,
+	__IFLA_UNCI_MAX,
+};
+
+#define IFLA_UNCI_MAX (__IFLA_UNCI_MAX - 1)
+
+#endif /* _UAPI_LINUX_UNCI_H_ */
diff --git a/lib/librte_eal/linuxapp/unci/unci_dev.h b/lib/librte_eal/linuxapp/unci/unci_dev.h
index 102409020..92b9b8383 100644
--- a/lib/librte_eal/linuxapp/unci/unci_dev.h
+++ b/lib/librte_eal/linuxapp/unci/unci_dev.h
@@ -25,10 +25,18 @@
 #ifndef _UNCI_DEV_H_
 #define _UNCI_DEV_H_
 
+#include <linux/netdevice.h>
+
+#include <exec-env/unci.h>
+
 #ifdef pr_fmt
 #undef pr_fmt
 #endif
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+struct unci_dev {
+	__u32 port_id;
+	__u32 pid;
+};
 
 #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 b8ef409d3..42fac3e63 100644
--- a/lib/librte_eal/linuxapp/unci/unci_net.c
+++ b/lib/librte_eal/linuxapp/unci/unci_net.c
@@ -23,20 +23,68 @@
  */
 
 #include <linux/module.h>
+#include <net/rtnetlink.h>
 
 #include "unci_dev.h"
 
-static int __init unci_init(void)
+static const struct net_device_ops unci_net_netdev_ops = { 0 };
+
+static void unci_net_setup(struct net_device *dev)
+{
+	ether_setup(dev);
+	dev->netdev_ops = &unci_net_netdev_ops;
+}
+
+static int unci_net_newlink(struct net *net, struct net_device *dev,
+		struct nlattr *tb[], struct nlattr *data[])
+{
+	struct unci_dev *unci = netdev_priv(dev);
+
+	unci->port_id = nla_get_u32(data[IFLA_UNCI_PORTID]);
+	unci->pid = nla_get_u32(data[IFLA_UNCI_PID]);
+
+	return register_netdevice(dev);
+}
+
+static const struct nla_policy unci_policy[IFLA_UNCI_MAX + 1] = {
+	[IFLA_UNCI_PORTID] = { .type = NLA_U32 },
+	[IFLA_UNCI_PID]    = { .type = NLA_U32 },
+};
+
+static int unci_validate(struct nlattr *tb[], struct nlattr *data[])
 {
+	if (!data)
+		return -EINVAL;
+
+	if (!data[IFLA_UNCI_PID] || !data[IFLA_UNCI_PORTID])
+		return -EINVAL;
+
 	return 0;
 }
+
+static struct rtnl_link_ops unci_link_ops __read_mostly = {
+	.kind = UNCI_DEVICE,
+	.priv_size = sizeof(struct unci_dev),
+	.maxtype = IFLA_UNCI_MAX,
+	.setup = unci_net_setup,
+	.newlink = unci_net_newlink,
+	.policy = unci_policy,
+	.validate = unci_validate,
+};
+
+static int __init unci_init(void)
+{
+	return rtnl_link_register(&unci_link_ops);
+}
 module_init(unci_init);
 
 static void __exit unci_exit(void)
 {
+	rtnl_link_unregister(&unci_link_ops);
 }
 module_exit(unci_exit);
 
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_AUTHOR("Intel Corporation");
 MODULE_DESCRIPTION("Kernel Module for managing unci devices");
+MODULE_ALIAS_RTNL_LINK(UNCI_DEVICE);
-- 
2.13.0



More information about the dev mailing list