Skip to contentSkip to conversation

lib: move Netlink wrapper to lib

PATCH In review Nelio Laranjeiro 4 participants 11 messages Mar 13, 2018 – Mar 15, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover lib: move Netlink wrapper to lib

TAP PMD uses a wrapper to communicate with Netlink through a socket. This wrapper can be useful for other PMD which may need to communicate also with the Linux kernel via Netlink.

This series moves this wrapper to the lib level to let any PMD implement use it when necessary.

Nelio Laranjeiro (2):
lib: move Netlink code into a common library
lib: add request Netlink messages

 MAINTAINERS                                        |   3 +
 config/common_base                                 |   6 ++
 config/common_linuxapp                             |   1 +
 drivers/net/tap/Makefile                           |   3 +-
 drivers/net/tap/rte_eth_tap.c                      |  16 +--
 drivers/net/tap/tap_flow.c                         | 118 ++++++++++-----------
 drivers/net/tap/tap_netlink.h                      |  42 --------
 drivers/net/tap/tap_tcmsgs.c                       |  28 ++---
 drivers/net/tap/tap_tcmsgs.h                       |   2 +-
 lib/Makefile                                       |   2 +
 lib/librte_netlink/Makefile                        |  26 +++++
 lib/librte_netlink/meson.build                     |  13 +++
 .../librte_netlink/rte_netlink.c                   |  87 +++++++++++----
 lib/librte_netlink/rte_netlink.h                   |  43 ++++++++
 lib/librte_netlink/rte_netlink_version.map         |  18 ++++
 lib/meson.build                                    |   2 +-
 mk/rte.app.mk                                      |   1 +
 17 files changed, 263 insertions(+), 148 deletions(-)
 delete mode 100644 drivers/net/tap/tap_netlink.h
 create mode 100644 lib/librte_netlink/Makefile
 create mode 100644 lib/librte_netlink/meson.build
 rename drivers/net/tap/tap_netlink.c => lib/librte_netlink/rte_netlink.c (77%)
 create mode 100644 lib/librte_netlink/rte_netlink.h
 create mode 100644 lib/librte_netlink/rte_netlink_version.map
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/2 lib: move Netlink code into a common library

Moves TAP PMD generic Netlink library into lib directory to let other PMD use Netlink to communicate with kernel.

As this library uses a socket to communicate with Netlink it does not bring any dependency on the libnl.

Cc Pascal Mazon <[email protected]>
---
 MAINTAINERS                                        |   3 +
 config/common_base                                 |   6 ++
 config/common_linuxapp                             |   1 +
 drivers/net/tap/Makefile                           |   3 +-
 drivers/net/tap/rte_eth_tap.c                      |  16 +--
 drivers/net/tap/tap_flow.c                         | 118 ++++++++++-----------
 drivers/net/tap/tap_netlink.h                      |  42 --------
 drivers/net/tap/tap_tcmsgs.c                       |  28 ++---
 drivers/net/tap/tap_tcmsgs.h                       |   2 +-
 lib/Makefile                                       |   2 +
 lib/librte_netlink/Makefile                        |  26 +++++
 lib/librte_netlink/meson.build                     |  13 +++
 .../librte_netlink/rte_netlink.c                   |  42 ++++----
 lib/librte_netlink/rte_netlink.h                   |  42 ++++++++
 lib/librte_netlink/rte_netlink_version.map         |  17 +++
 lib/meson.build                                    |   2 +-
 mk/rte.app.mk                                      |   1 +
 17 files changed, 216 insertions(+), 148 deletions(-)
 delete mode 100644 drivers/net/tap/tap_netlink.h
 create mode 100644 lib/librte_netlink/Makefile
 create mode 100644 lib/librte_netlink/meson.build
 rename drivers/net/tap/tap_netlink.c => lib/librte_netlink/rte_netlink.c (88%)
 create mode 100644 lib/librte_netlink/rte_netlink.h
 create mode 100644 lib/librte_netlink/rte_netlink_version.map
MAINTAINERS +3 -0
index a646ca3e1..f836f4c5d 100644
@@ -325,6 +325,9 @@ F: drivers/raw/skeleton_rawdev/
 F: test/test/test_rawdev.c
 F: doc/guides/prog_guide/rawdev.rst
 
+Netlink Library
+M: Pascal Mazon <[email protected]>
+F: lib/librte_netlink/
 
 Bus Drivers
 -----------
config/common_base +6 -0
index ad03cf433..6ee715b21 100644
@@ -823,3 +823,9 @@ CONFIG_RTE_APP_CRYPTO_PERF=y
 # Compile the eventdev application
 #
 CONFIG_RTE_APP_EVENTDEV=y
+
+#
+# Compile netlink library
+# It is enabled by default for Linux only.
+#
+CONFIG_RTE_LIBRTE_NETLINK=n
config/common_linuxapp +1 -0
index ff98f2355..97e9d6dfe 100644
@@ -23,3 +23,4 @@ CONFIG_RTE_LIBRTE_NFP_PMD=y
 CONFIG_RTE_LIBRTE_POWER=y
 CONFIG_RTE_VIRTIO_USER=y
 CONFIG_RTE_PROC_INFO=y
+CONFIG_RTE_LIBRTE_NETLINK=y
drivers/net/tap/Makefile +1 -2
index ccc5c5fc0..05fd392ef 100644
@@ -24,7 +24,7 @@ CFLAGS += -I.
 CFLAGS += $(WERROR_FLAGS)
 LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring
 LDLIBS += -lrte_ethdev -lrte_net -lrte_kvargs -lrte_hash
-LDLIBS += -lrte_bus_vdev
+LDLIBS += -lrte_bus_vdev -lrte_netlink
 
 CFLAGS += -DTAP_MAX_QUEUES=$(TAP_MAX_QUEUES)
 
@@ -33,7 +33,6 @@ CFLAGS += -DTAP_MAX_QUEUES=$(TAP_MAX_QUEUES)
 #
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += rte_eth_tap.c
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += tap_flow.c
-SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += tap_netlink.c
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += tap_tcmsgs.c
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += tap_bpf_api.c
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_TAP) += tap_intr.c
drivers/net/tap/rte_eth_tap.c +8 -8
index f09db0ea9..05a6beabb 100644
@@ -15,6 +15,7 @@
 #include <rte_net.h>
 #include <rte_debug.h>
 #include <rte_ip.h>
+#include <rte_netlink.h>
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -36,7 +37,6 @@
 
 #include <rte_eth_tap.h>
 #include <tap_flow.h>
-#include <tap_netlink.h>
 #include <tap_tcmsgs.h>
 
 /* Linux based path to the TUN device */
@@ -1197,7 +1197,7 @@ tap_set_mc_addr_list(struct rte_eth_dev *dev __rte_unused,
 }
 
 static int
-tap_nl_msg_handler(struct nlmsghdr *nh, void *arg)
+rte_nl_msg_handler(struct nlmsghdr *nh, void *arg)
 {
 	struct rte_eth_dev *dev = arg;
 	struct pmd_internals *pmd = dev->data->dev_private;
@@ -1216,7 +1216,7 @@ tap_dev_intr_handler(void *cb_arg)
 	struct rte_eth_dev *dev = cb_arg;
 	struct pmd_internals *pmd = dev->data->dev_private;
 
-	tap_nl_recv(pmd->intr_handle.fd, tap_nl_msg_handler, dev);
+	rte_nl_recv(pmd->intr_handle.fd, rte_nl_msg_handler, dev);
 }
 
 static int
@@ -1227,20 +1227,20 @@ tap_lsc_intr_handle_set(struct rte_eth_dev *dev, int set)
 	/* In any case, disable interrupt if the conf is no longer there. */
 	if (!dev->data->dev_conf.intr_conf.lsc) {
 		if (pmd->intr_handle.fd != -1) {
-			tap_nl_final(pmd->intr_handle.fd);
+			rte_nl_final(pmd->intr_handle.fd);
 			rte_intr_callback_unregister(&pmd->intr_handle,
 				tap_dev_intr_handler, dev);
 		}
 		return 0;
 	}
 	if (set) {
-		pmd->intr_handle.fd = tap_nl_init(RTMGRP_LINK);
+		pmd->intr_handle.fd = rte_nl_init(RTMGRP_LINK);
 		if (unlikely(pmd->intr_handle.fd == -1))
 			return -EBADF;
 		return rte_intr_callback_register(
 			&pmd->intr_handle, tap_dev_intr_handler, dev);
 	}
-	tap_nl_final(pmd->intr_handle.fd);
+	rte_nl_final(pmd->intr_handle.fd);
 	return rte_intr_callback_unregister(&pmd->intr_handle,
 					    tap_dev_intr_handler, dev);
 }
@@ -1436,7 +1436,7 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name,
 	 * - rte_flow actual/implicit lists
 	 * - implicit rules
 	 */
-	pmd->nlsk_fd = tap_nl_init(0);
+	pmd->nlsk_fd = rte_nl_init(0);
 	if (pmd->nlsk_fd == -1) {
 		RTE_LOG(WARNING, PMD, "%s: failed to create netlink socket.\n",
 			pmd->name);
@@ -1673,7 +1673,7 @@ rte_pmd_tap_remove(struct rte_vdev_device *dev)
 	if (internals->nlsk_fd) {
 		tap_flow_flush(eth_dev, NULL);
 		tap_flow_implicit_flush(internals, NULL);
-		tap_nl_final(internals->nlsk_fd);
+		rte_nl_final(internals->nlsk_fd);
 	}
 	for (i = 0; i < RTE_PMD_TAP_MAX_QUEUES; i++) {
 		if (internals->rxq[i].fd != -1) {
drivers/net/tap/tap_flow.c +59 -59

326 lines not on this page · raw message

drivers/net/tap/tap_netlink.h deleted +0 -42

42 lines not on this page · raw message

drivers/net/tap/tap_tcmsgs.c +14 -14
index 954f13ebb..69638dfc7 100644
@@ -79,7 +79,7 @@ qdisc_del(int nlsk_fd, uint16_t ifindex, struct qdisc *qinfo)
 	msg.t.tcm_parent = qinfo->parent;
 	/* if no netlink socket is provided, create one */
 	if (!nlsk_fd) {
-		fd = tap_nl_init(0);
+		fd = rte_nl_init(0);
 		if (fd < 0) {
 			RTE_LOG(ERR, PMD,
 				"Could not delete QDISC: null netlink socket\n");
@@ -88,16 +88,16 @@ qdisc_del(int nlsk_fd, uint16_t ifindex, struct qdisc *qinfo)
 	} else {
 		fd = nlsk_fd;
 	}
-	if (tap_nl_send(fd, &msg.nh) < 0)
+	if (rte_nl_send(fd, &msg.nh) < 0)
 		goto error;
-	if (tap_nl_recv_ack(fd) < 0)
+	if (rte_nl_recv_ack(fd) < 0)
 		goto error;
 	if (!nlsk_fd)
-		return tap_nl_final(fd);
+		return rte_nl_final(fd);
 	return 0;
 error:
 	if (!nlsk_fd)
-		tap_nl_final(fd);
+		rte_nl_final(fd);
 	return -1;
 }
 
@@ -122,11 +122,11 @@ qdisc_add_multiq(int nlsk_fd, uint16_t ifindex)
 		    NLM_F_REQUEST | NLM_F_ACK | NLM_F_EXCL | NLM_F_CREATE);
 	msg.t.tcm_handle = TC_H_MAKE(MULTIQ_MAJOR_HANDLE, 0);
 	msg.t.tcm_parent = TC_H_ROOT;
-	tap_nlattr_add(&msg.nh, TCA_KIND, sizeof("multiq"), "multiq");
-	tap_nlattr_add(&msg.nh, TCA_OPTIONS, sizeof(opt), &opt);
-	if (tap_nl_send(nlsk_fd, &msg.nh) < 0)
+	rte_nlattr_add(&msg.nh, TCA_KIND, sizeof("multiq"), "multiq");
+	rte_nlattr_add(&msg.nh, TCA_OPTIONS, sizeof(opt), &opt);
+	if (rte_nl_send(nlsk_fd, &msg.nh) < 0)
 		return -1;
-	if (tap_nl_recv_ack(nlsk_fd) < 0)
+	if (rte_nl_recv_ack(nlsk_fd) < 0)
 		return -1;
 	return 0;
 }
@@ -151,10 +151,10 @@ qdisc_add_ingress(int nlsk_fd, uint16_t ifindex)
 		    NLM_F_REQUEST | NLM_F_ACK | NLM_F_EXCL | NLM_F_CREATE);
 	msg.t.tcm_handle = TC_H_MAKE(TC_H_INGRESS, 0);
 	msg.t.tcm_parent = TC_H_INGRESS;
-	tap_nlattr_add(&msg.nh, TCA_KIND, sizeof("ingress"), "ingress");
-	if (tap_nl_send(nlsk_fd, &msg.nh) < 0)
+	rte_nlattr_add(&msg.nh, TCA_KIND, sizeof("ingress"), "ingress");
+	if (rte_nl_send(nlsk_fd, &msg.nh) < 0)
 		return -1;
-	if (tap_nl_recv_ack(nlsk_fd) < 0)
+	if (rte_nl_recv_ack(nlsk_fd) < 0)
 		return -1;
 	return 0;
 }
@@ -218,9 +218,9 @@ qdisc_iterate(int nlsk_fd, uint16_t ifindex,
 	};
 
 	tc_init_msg(&msg, ifindex, RTM_GETQDISC, NLM_F_REQUEST | NLM_F_DUMP);
-	if (tap_nl_send(nlsk_fd, &msg.nh) < 0)
+	if (rte_nl_send(nlsk_fd, &msg.nh) < 0)
 		return -1;
-	if (tap_nl_recv(nlsk_fd, callback, &args) < 0)
+	if (rte_nl_recv(nlsk_fd, callback, &args) < 0)
 		return -1;
 	return 0;
 }
drivers/net/tap/tap_tcmsgs.h +1 -1
index f72f8c5c2..73f74502a 100644
@@ -20,7 +20,7 @@
 #include <inttypes.h>
 
 #include <rte_ether.h>
-#include <tap_netlink.h>
+#include <rte_netlink.h>
 
 #define MULTIQ_MAJOR_HANDLE (1 << 16)
 
lib/Makefile +2 -0
index ec965a606..699f962d9 100644
@@ -103,5 +103,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
 endif
 DEPDIRS-librte_kni := librte_eal librte_mempool librte_mbuf librte_ether
 DEPDIRS-librte_kni += librte_pci
+DIRS-$(CONFIG_RTE_LIBRTE_NETLINK) += librte_netlink
+DEPDIRS-librte_netlink := librte_eal
 
 include $(RTE_SDK)/mk/rte.subdir.mk
lib/librte_netlink/Makefile new file +26 -0
new file mode 100644
index 000000000..89300284f
@@ -0,0 +1,26 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2010-2017 Intel Corporation
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+#
+# library name
+#
+LIB = librte_netlink.a
+
+CFLAGS += -O3
+CFLAGS += $(WERROR_FLAGS)
+LDLIBS += -lrte_eal
+
+EXPORT_MAP := rte_netlink_version.map
+
+LIBABIVER := 1
+
+SRCS-y += rte_netlink.c
+
+#
+# Export include files
+#
+SYMLINK-y-include += rte_netlink.h
+
+include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_netlink/meson.build new file +13 -0
new file mode 100644
index 000000000..77592c7d4
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2018 6WIND S.A.
+# Copyright 2018 Mellanox Technologies, Ltd.
+
+
+name = 'netlink'
+version = 1
+allow_experimental_apis = true
+sources = files('rte_netlink.c',)
+
+headers = files('rte_netlink.h')
+
+deps += ['net']
lib/librte_netlink/rte_netlink.c renamed from drivers/net/tap/tap_netlink.c +21 -21

144 lines not on this page · raw message

lib/librte_netlink/rte_netlink.h new file +42 -0

42 lines not on this page · raw message

lib/librte_netlink/rte_netlink_version.map new file +17 -0
new file mode 100644
index 000000000..5aa9b6228
@@ -0,0 +1,17 @@
+DPDK_18.05 {
+	global:
+
+	rte_nl_init;
+	rte_nl_final;
+	rte_nl_send;
+	rte_nl_recv;
+	rte_nl_recv_ack;
+	rte_nlattr_add;
+	rte_nlattr_add8;
+	rte_nlattr_add16;
+	rte_nlattr_add32;
+	rte_nlattr_nested_start;
+	rte_nlattr_nested_finish;
+
+	local: *;
+};
lib/meson.build +1 -1
index ef6159170..873a39785 100644
@@ -23,7 +23,7 @@ libraries = [ 'compat', # just a header, used for versioning
 	# add pkt framework libs which use other libs from above
 	'port', 'table', 'pipeline',
 	# flow_classify lib depends on pkt framework table lib
-	'flow_classify']
+	'flow_classify', 'netlink']
 
 foreach l:libraries
 	build = true
mk/rte.app.mk +1 -0
index 3eb41d176..5cc8ed622 100644
@@ -106,6 +106,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL)            += -lrte_eal
 _LDLIBS-$(CONFIG_RTE_LIBRTE_CMDLINE)        += -lrte_cmdline
 _LDLIBS-$(CONFIG_RTE_LIBRTE_REORDER)        += -lrte_reorder
 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrte_sched
+_LDLIBS-$(CONFIG_RTE_LIBRTE_NETLINK)        += -lrte_netlink
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 _LDLIBS-$(CONFIG_RTE_LIBRTE_KNI)            += -lrte_kni
Signature · 1 line
2.11.0
#2 lore raw

Re: [PATCH 1/2] lib: move Netlink code into a common library

Quoted 35 lines · Nelio Laranjeiro

Moves TAP PMD generic Netlink library into lib directory to let other PMD use Netlink to communicate with kernel.

As this library uses a socket to communicate with Netlink it does not bring any dependency on the libnl.

Cc Pascal Mazon <[email protected]>
---
 MAINTAINERS                                        |   3 +
 config/common_base                                 |   6 ++
 config/common_linuxapp                             |   1 +
 drivers/net/tap/Makefile                           |   3 +-
 drivers/net/tap/rte_eth_tap.c                      |  16 +--
 drivers/net/tap/tap_flow.c                         | 118 ++++++++++-----------
 drivers/net/tap/tap_netlink.h                      |  42 --------
 drivers/net/tap/tap_tcmsgs.c                       |  28 ++---
 drivers/net/tap/tap_tcmsgs.h                       |   2 +-
 lib/Makefile                                       |   2 +
 lib/librte_netlink/Makefile                        |  26 +++++
 lib/librte_netlink/meson.build                     |  13 +++
 .../librte_netlink/rte_netlink.c                   |  42 ++++----
 lib/librte_netlink/rte_netlink.h                   |  42 ++++++++
 lib/librte_netlink/rte_netlink_version.map         |  17 +++
 lib/meson.build                                    |   2 +-
 mk/rte.app.mk                                      |   1 +
 17 files changed, 216 insertions(+), 148 deletions(-)
 delete mode 100644 drivers/net/tap/tap_netlink.h
 create mode 100644 lib/librte_netlink/Makefile
 create mode 100644 lib/librte_netlink/meson.build
 rename drivers/net/tap/tap_netlink.c => lib/librte_netlink/rte_netlink.c (88%)
 create mode 100644 lib/librte_netlink/rte_netlink.h
 create mode 100644 lib/librte_netlink/rte_netlink_version.map

<snip>

lib/librte_netlink/meson.build line 7

Quoted 13 lines
lib/librte_netlink/meson.build new file +7 -0
new file mode 100644
index 000000000..77592c7d4
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2018 6WIND S.A.
+# Copyright 2018 Mellanox Technologies, Ltd.
+
+
+name = 'netlink'
+version = 1

Not a big issue, but the above two lines are unnecessary, and can be omitted. I'd rather than the name of the lib *not* be explicitly called out, to prevent the temptation of giving the library a different name to the name of the directory it is in.

Quoted 6 lines
lib/librte_netlink/meson.build new file +6 -0
+allow_experimental_apis = true
+sources = files('rte_netlink.c',)
+
+headers = files('rte_netlink.h')
+
+deps += ['net']

<snip>

lib/meson.build libraries = [ 'compat', # just a header, used for versioning · line 26

Quoted 10 lines
lib/meson.build +1 -1
index ef6159170..873a39785 100644
@@ -23,7 +23,7 @@ libraries = [ 'compat', # just a header, used for versioning
 	# add pkt framework libs which use other libs from above
 	'port', 'table', 'pipeline',
 	# flow_classify lib depends on pkt framework table lib
-	'flow_classify']
+	'flow_classify', 'netlink']

Given that this doesn't depend on anything apart from the core libs, I think it should be placed earlier in the list, where the majority of the libs are in alphabetical order. [Yes, I should have put a comment just before the "acl" lib entry calling out the fact that it was meant to be an alphabetical list - I forgot, sorry! :-)]

/Bruce

#3 lore raw

Re: [PATCH 1/2] lib: move Netlink code into a common library

Quoted 84 lines · Bruce Richardson
Quoted 35 lines · Nelio Laranjeiro

Moves TAP PMD generic Netlink library into lib directory to let other PMD use Netlink to communicate with kernel.

As this library uses a socket to communicate with Netlink it does not bring any dependency on the libnl.

Cc Pascal Mazon <[email protected]>
---
 MAINTAINERS                                        |   3 +
 config/common_base                                 |   6 ++
 config/common_linuxapp                             |   1 +
 drivers/net/tap/Makefile                           |   3 +-
 drivers/net/tap/rte_eth_tap.c                      |  16 +--
 drivers/net/tap/tap_flow.c                         | 118 ++++++++++-----------
 drivers/net/tap/tap_netlink.h                      |  42 --------
 drivers/net/tap/tap_tcmsgs.c                       |  28 ++---
 drivers/net/tap/tap_tcmsgs.h                       |   2 +-
 lib/Makefile                                       |   2 +
 lib/librte_netlink/Makefile                        |  26 +++++
 lib/librte_netlink/meson.build                     |  13 +++
 .../librte_netlink/rte_netlink.c                   |  42 ++++----
 lib/librte_netlink/rte_netlink.h                   |  42 ++++++++
 lib/librte_netlink/rte_netlink_version.map         |  17 +++
 lib/meson.build                                    |   2 +-
 mk/rte.app.mk                                      |   1 +
 17 files changed, 216 insertions(+), 148 deletions(-)
 delete mode 100644 drivers/net/tap/tap_netlink.h
 create mode 100644 lib/librte_netlink/Makefile
 create mode 100644 lib/librte_netlink/meson.build
 rename drivers/net/tap/tap_netlink.c => lib/librte_netlink/rte_netlink.c (88%)
 create mode 100644 lib/librte_netlink/rte_netlink.h
 create mode 100644 lib/librte_netlink/rte_netlink_version.map

<snip>

lib/librte_netlink/meson.build line 7

Quoted 13 lines
lib/librte_netlink/meson.build new file +7 -0
new file mode 100644
index 000000000..77592c7d4
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2018 6WIND S.A.
+# Copyright 2018 Mellanox Technologies, Ltd.
+
+
+name = 'netlink'
+version = 1

Not a big issue, but the above two lines are unnecessary, and can be omitted. I'd rather than the name of the lib *not* be explicitly called out, to prevent the temptation of giving the library a different name to the name of the directory it is in.

Quoted 6 lines
lib/librte_netlink/meson.build new file +6 -0
+allow_experimental_apis = true
+sources = files('rte_netlink.c',)
+
+headers = files('rte_netlink.h')
+
+deps += ['net']

<snip>

lib/meson.build libraries = [ 'compat', # just a header, used for versioning · line 26

Quoted 10 lines
lib/meson.build +1 -1
index ef6159170..873a39785 100644
@@ -23,7 +23,7 @@ libraries = [ 'compat', # just a header, used for versioning
 	# add pkt framework libs which use other libs from above
 	'port', 'table', 'pipeline',
 	# flow_classify lib depends on pkt framework table lib
-	'flow_classify']
+	'flow_classify', 'netlink']

Given that this doesn't depend on anything apart from the core libs, I think it should be placed earlier in the list, where the majority of the libs are in alphabetical order. [Yes, I should have put a comment just before the "acl" lib entry calling out the fact that it was meant to be an alphabetical list - I forgot, sorry! :-)]

Quoted 1 line

/Bruce

Hi Bruce,

I will modify it for the v2.

Thanks,

Signature · 2 lines
Nélio Laranjeiro
6WIND
#4 lore raw

PATCH 2/2 lib: add request Netlink messages

In reply to Nelio Laranjeiro

rte_nl_send() generate a message without request. In some situation, the drivers needs to retrieve information from the Kernel before requesting modifications.

Cc Pascal Mazon <[email protected]>
---
 lib/librte_netlink/rte_netlink.c           | 45 ++++++++++++++++++++++++++++++
 lib/librte_netlink/rte_netlink.h           |  1 +
 lib/librte_netlink/rte_netlink_version.map |  1 +
 3 files changed, 47 insertions(+)
lib/librte_netlink/rte_netlink.c +45 -0
index a4ed07d30..a2020f6f8 100644
@@ -125,6 +125,51 @@ rte_nl_send(int nlsk_fd, struct nlmsghdr *nh)
 }
 
 /**
+ * Send a request message to the kernel on the netlink socket.
+ *
+ * @param[in] nlsk_fd
+ *   The netlink socket file descriptor used for communication.
+ * @param[in] nh
+ *   The netlink message send to the kernel.
+ * @param[in] req
+ *   Pointer to the request structure.
+ * @param[in] len
+ *   Length of the request in bytes.
+ *
+ * @return
+ *   the number of sent bytes on success, -1 otherwise.
+ */
+int
+rte_nl_request(int nlsk_fd, struct nlmsghdr *nh, void *req, int len)
+{
+	/* man 7 netlink EXAMPLE */
+	struct sockaddr_nl sa = {
+		.nl_family = AF_NETLINK,
+	};
+	struct iovec iov[2] = {
+		{ .iov_base = nh, .iov_len = sizeof(*nh), },
+		{ .iov_base = req, .iov_len = len, },
+	};
+	struct msghdr msg = {
+		.msg_name = &sa,
+		.msg_namelen = sizeof(sa),
+		.msg_iov = iov,
+		.msg_iovlen = 2,
+	};
+	int send_bytes;
+
+	nh->nlmsg_pid = 0; /* communication with the kernel uses pid 0 */
+	nh->nlmsg_seq = (uint32_t)rte_rand();
+	send_bytes = sendmsg(nlsk_fd, &msg, 0);
+	if (send_bytes < 0) {
+		RTE_LOG(ERR, PMD, "Failed to send netlink message: %s (%d)\n",
+			strerror(errno), errno);
+		return -1;
+	}
+	return send_bytes;
+}
+
+/**
  * Check that the kernel sends an appropriate ACK in response
  * to an rte_nl_send().
  *
lib/librte_netlink/rte_netlink.h +1 -0
index 29f7d64c5..9af03e738 100644
@@ -28,6 +28,7 @@ struct nlmsg {
 int rte_nl_init(uint32_t nl_groups);
 int rte_nl_final(int nlsk_fd);
 int rte_nl_send(int nlsk_fd, struct nlmsghdr *nh);
+int rte_nl_request(int nlsk_fd, struct nlmsghdr *nh, void *req, int len);
 int rte_nl_recv(int nlsk_fd, int (*callback)(struct nlmsghdr *, void *),
 		void *arg);
 int rte_nl_recv_ack(int nlsk_fd);
lib/librte_netlink/rte_netlink_version.map +1 -0
index 5aa9b6228..a52254b36 100644
@@ -4,6 +4,7 @@ DPDK_18.05 {
 	rte_nl_init;
 	rte_nl_final;
 	rte_nl_send;
+	rte_nl_request;
 	rte_nl_recv;
 	rte_nl_recv_ack;
 	rte_nlattr_add;
Signature · 1 line
2.11.0
#5 lore raw
In reply to Nelio Laranjeiro
Quoted 27 lines · On Tue, 13 Mar 2018 13:28:25 +0100 Nelio Laranjeiro…

TAP PMD uses a wrapper to communicate with Netlink through a socket. This wrapper can be useful for other PMD which may need to communicate also with the Linux kernel via Netlink.

This series moves this wrapper to the lib level to let any PMD implement use it when necessary.

Nelio Laranjeiro (2):
lib: move Netlink code into a common library
lib: add request Netlink messages

 MAINTAINERS                                        |   3 +
 config/common_base                                 |   6 ++
 config/common_linuxapp                             |   1 +
 drivers/net/tap/Makefile                           |   3 +-
 drivers/net/tap/rte_eth_tap.c                      |  16 +--
 drivers/net/tap/tap_flow.c                         | 118 ++++++++++-----------
 drivers/net/tap/tap_netlink.h                      |  42 --------
 drivers/net/tap/tap_tcmsgs.c                       |  28 ++---
 drivers/net/tap/tap_tcmsgs.h                       |   2 +-
 lib/Makefile                                       |   2 +
 lib/librte_netlink/Makefile                        |  26 +++++
 lib/librte_netlink/meson.build                     |  13 +++
 .../librte_netlink/rte_netlink.c                   |  87 +++++++++++----
 lib/librte_netlink/rte_netlink.h                   |  43 ++++++++
 lib/librte_netlink/rte_netlink_version.map         |  18 ++++
 lib/meson.build                                    |   2 +-
Quoted 9 lines
 mk/rte.app.mk                                      |   1 +
 17 files changed, 263 insertions(+), 148 deletions(-)
 delete mode 100644 drivers/net/tap/tap_netlink.h
 create mode 100644 lib/librte_netlink/Makefile
 create mode 100644 lib/librte_netlink/meson.build
 rename drivers/net/tap/tap_netlink.c => lib/librte_netlink/rte_netlink.c (77%)
 create mode 100644 lib/librte_netlink/rte_netlink.h
 create mode 100644 lib/librte_netlink/rte_netlink_version.map

I might have raised this before; but having yet another netlink library is not a great advantage. It would be much better to use a common external library libmnl which is already available on every distribution.

#6 lore raw
Quoted 40 lines · Stephen Hemminger
Quoted 27 lines · On Tue, 13 Mar 2018 13:28:25 +0100 Nelio Laranjeiro…

TAP PMD uses a wrapper to communicate with Netlink through a socket. This wrapper can be useful for other PMD which may need to communicate also with the Linux kernel via Netlink.

This series moves this wrapper to the lib level to let any PMD implement use it when necessary.

Nelio Laranjeiro (2):
lib: move Netlink code into a common library
lib: add request Netlink messages

 MAINTAINERS                                        |   3 +
 config/common_base                                 |   6 ++
 config/common_linuxapp                             |   1 +
 drivers/net/tap/Makefile                           |   3 +-
 drivers/net/tap/rte_eth_tap.c                      |  16 +--
 drivers/net/tap/tap_flow.c                         | 118 ++++++++++-----------
 drivers/net/tap/tap_netlink.h                      |  42 --------
 drivers/net/tap/tap_tcmsgs.c                       |  28 ++---
 drivers/net/tap/tap_tcmsgs.h                       |   2 +-
 lib/Makefile                                       |   2 +
 lib/librte_netlink/Makefile                        |  26 +++++
 lib/librte_netlink/meson.build                     |  13 +++
 .../librte_netlink/rte_netlink.c                   |  87 +++++++++++----
 lib/librte_netlink/rte_netlink.h                   |  43 ++++++++
 lib/librte_netlink/rte_netlink_version.map         |  18 ++++
 lib/meson.build                                    |   2 +-
Quoted 9 lines
 mk/rte.app.mk                                      |   1 +
 17 files changed, 263 insertions(+), 148 deletions(-)
 delete mode 100644 drivers/net/tap/tap_netlink.h
 create mode 100644 lib/librte_netlink/Makefile
 create mode 100644 lib/librte_netlink/meson.build
 rename drivers/net/tap/tap_netlink.c => lib/librte_netlink/rte_netlink.c (77%)
 create mode 100644 lib/librte_netlink/rte_netlink.h
 create mode 100644 lib/librte_netlink/rte_netlink_version.map
Quoted 3 lines

I might have raised this before; but having yet another netlink library is not a great advantage. It would be much better to use a common external library libmnl which is already available on every distribution.

The question is more do we really want to have a dependency on a so small wrapper for a socket interface?

Signature · 2 lines
Nélio Laranjeiro
6WIND
#7 lore raw
Quoted 41 lines · On Wed, 14 Mar 2018 13:08:55 +0100 Nélio Laranjeiro…
Quoted 40 lines · Stephen Hemminger
Quoted 36 lines · On Tue, 13 Mar 2018 13:28:25 +0100 Nelio Laranjeiro…

TAP PMD uses a wrapper to communicate with Netlink through a socket. This wrapper can be useful for other PMD which may need to communicate also with the Linux kernel via Netlink.

This series moves this wrapper to the lib level to let any PMD implement use it when necessary.

Nelio Laranjeiro (2):
lib: move Netlink code into a common library
lib: add request Netlink messages

 MAINTAINERS                                        |   3 +
 config/common_base                                 |   6 ++
 config/common_linuxapp                             |   1 +
 drivers/net/tap/Makefile                           |   3 +-
 drivers/net/tap/rte_eth_tap.c                      |  16 +--
 drivers/net/tap/tap_flow.c                         | 118 ++++++++++-----------
 drivers/net/tap/tap_netlink.h                      |  42 --------
 drivers/net/tap/tap_tcmsgs.c                       |  28 ++---
 drivers/net/tap/tap_tcmsgs.h                       |   2 +-
 lib/Makefile                                       |   2 +
 lib/librte_netlink/Makefile                        |  26 +++++
 lib/librte_netlink/meson.build                     |  13 +++
 .../librte_netlink/rte_netlink.c                   |  87 +++++++++++----
 lib/librte_netlink/rte_netlink.h                   |  43 ++++++++
 lib/librte_netlink/rte_netlink_version.map         |  18 ++++
 lib/meson.build                                    |   2 +-
 mk/rte.app.mk                                      |   1 +
 17 files changed, 263 insertions(+), 148 deletions(-)
 delete mode 100644 drivers/net/tap/tap_netlink.h
 create mode 100644 lib/librte_netlink/Makefile
 create mode 100644 lib/librte_netlink/meson.build
 rename drivers/net/tap/tap_netlink.c => lib/librte_netlink/rte_netlink.c (77%)
 create mode 100644 lib/librte_netlink/rte_netlink.h
 create mode 100644 lib/librte_netlink/rte_netlink_version.map
Quoted 7 lines
Quoted 3 lines

I might have raised this before; but having yet another netlink library is not a great advantage. It would be much better to use a common external library libmnl which is already available on every distribution.

The question is more do we really want to have a dependency on a so small wrapper for a socket interface?

Lots of drivers already have dependencies. And I trust libmnl rather than a reinvented library.

#8 lore raw

14/03/2018 16:17, Stephen Hemminger:

Quoted 22 lines
Quoted 20 lines · On Wed, 14 Mar 2018 13:08:55 +0100 Nélio Laranjeiro…
Quoted 18 lines · Stephen Hemminger
Quoted 4 lines · On Tue, 13 Mar 2018 13:28:25 +0100 Nelio Laranjeiro…
 drivers/net/tap/Makefile                           |   3 +-
 drivers/net/tap/rte_eth_tap.c                      |  16 +--
 drivers/net/tap/tap_flow.c                         | 118 ++++++++++-----------
 drivers/net/tap/tap_netlink.h                      |  42 --------
Quoted 8 lines
 drivers/net/tap/tap_tcmsgs.c                       |  28 ++---
 drivers/net/tap/tap_tcmsgs.h                       |   2 +-
 lib/Makefile                                       |   2 +
 lib/librte_netlink/Makefile                        |  26 +++++
 lib/librte_netlink/meson.build                     |  13 +++
 .../librte_netlink/rte_netlink.c                   |  87 +++++++++++----
 lib/librte_netlink/rte_netlink.h                   |  43 ++++++++
 lib/librte_netlink/rte_netlink_version.map         |  18 ++++

I might have raised this before; but having yet another netlink library is not a great advantage. It would be much better to use a common external library libmnl which is already available on every distribution.

Quoted 5 lines
Quoted 2 lines

The question is more do we really want to have a dependency on a so small wrapper for a socket interface?

Lots of drivers already have dependencies. And I trust libmnl rather than a reinvented library.

Are we sure it is commonly installed in distributions?

This is needed only for TAP and mlx drivers.
Do we really want to add this dependency as mandatory for everybody to compile DPDK with default PMDs?

I see 4 options:
1/ keep duplicated few functions in PMDs
2/ use libmnl
3/ add the functions in a DPDK lib (this patch)
4/ add the functions in EAL

I would vote for the first option because mlx5 has very minimal requirement regarding netlink.
The first option can give us some time to think about the right way to use netlink in the next releases.

#9 lore raw
Quoted 41 lines · Thomas Monjalon

14/03/2018 16:17, Stephen Hemminger:

Quoted 22 lines
Quoted 20 lines · On Wed, 14 Mar 2018 13:08:55 +0100 Nélio Laranjeiro…
Quoted 18 lines · Stephen Hemminger
Quoted 4 lines · On Tue, 13 Mar 2018 13:28:25 +0100 Nelio Laranjeiro…
 drivers/net/tap/Makefile                           |   3 +-
 drivers/net/tap/rte_eth_tap.c                      |  16 +--
 drivers/net/tap/tap_flow.c                         | 118 ++++++++++-----------
 drivers/net/tap/tap_netlink.h                      |  42 --------
Quoted 8 lines
 drivers/net/tap/tap_tcmsgs.c                       |  28 ++---
 drivers/net/tap/tap_tcmsgs.h                       |   2 +-
 lib/Makefile                                       |   2 +
 lib/librte_netlink/Makefile                        |  26 +++++
 lib/librte_netlink/meson.build                     |  13 +++
 .../librte_netlink/rte_netlink.c                   |  87 +++++++++++----
 lib/librte_netlink/rte_netlink.h                   |  43 ++++++++
 lib/librte_netlink/rte_netlink_version.map         |  18 ++++

I might have raised this before; but having yet another netlink library is not a great advantage. It would be much better to use a common external library libmnl which is already available on every distribution.

Quoted 5 lines
Quoted 2 lines

The question is more do we really want to have a dependency on a so small wrapper for a socket interface?

Lots of drivers already have dependencies. And I trust libmnl rather than a reinvented library.

Are we sure it is commonly installed in distributions?

This is needed only for TAP and mlx drivers.
Do we really want to add this dependency as mandatory for everybody to compile DPDK with default PMDs?

I see 4 options:
1/ keep duplicated few functions in PMDs
2/ use libmnl
3/ add the functions in a DPDK lib (this patch)
4/ add the functions in EAL

Quoted 4 lines

I would vote for the first option because mlx5 has very minimal requirement regarding netlink.
The first option can give us some time to think about the right way to use netlink in the next releases.

I also vote for option 1 until those 4 and maybe more options are discussed.

Signature · 2 lines
Nélio Laranjeiro
6WIND
#10 lore raw
Quoted 24 lines · On Thu, 15 Mar 2018 17:19:05 +0100 Nélio Laranjeiro…
Quoted 23 lines · Thomas Monjalon

14/03/2018 16:17, Stephen Hemminger:

Quoted 22 lines
Quoted 20 lines · On Wed, 14 Mar 2018 13:08:55 +0100 Nélio Laranjeiro…
Quoted 18 lines · Stephen Hemminger
Quoted 4 lines · On Tue, 13 Mar 2018 13:28:25 +0100 Nelio Laranjeiro…
 drivers/net/tap/Makefile                           |   3 +-
 drivers/net/tap/rte_eth_tap.c                      |  16 +--
 drivers/net/tap/tap_flow.c                         | 118 ++++++++++-----------
 drivers/net/tap/tap_netlink.h                      |  42 --------
Quoted 8 lines
 drivers/net/tap/tap_tcmsgs.c                       |  28 ++---
 drivers/net/tap/tap_tcmsgs.h                       |   2 +-
 lib/Makefile                                       |   2 +
 lib/librte_netlink/Makefile                        |  26 +++++
 lib/librte_netlink/meson.build                     |  13 +++
 .../librte_netlink/rte_netlink.c                   |  87 +++++++++++----
 lib/librte_netlink/rte_netlink.h                   |  43 ++++++++
 lib/librte_netlink/rte_netlink_version.map         |  18 ++++  

I might have raised this before; but having yet another netlink library is not a great advantage. It would be much better to use a common external library libmnl which is already available on every distribution.

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

The question is more do we really want to have a dependency on a so small wrapper for a socket interface?

Lots of drivers already have dependencies. And I trust libmnl rather than a reinvented library.

Are we sure it is commonly installed in distributions?

iproute2 now mostly requires libmnl. It is used for several networking types and extended error reporting.