summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-12-25 16:35:47 +0100
committerThomas Haller <thaller@redhat.com>2021-01-15 11:32:30 +0100
commit186f2da2fc82cdac81a5fd01a21912301d6c036c (patch)
tree5ee49667ea3db3e9c6c8239f36f5f70380f74ee7
parent05008faf6ef88a5ec75e220ff41216153bc02a2d (diff)
downloadNetworkManager-186f2da2fc82cdac81a5fd01a21912301d6c036c.tar.gz
shared,platform: add "shared/nm-platform" library
NetworkManager core is huge. We should try to split out parts that are independent. Platform code is already mostly independent. But due to having it under "src/", there is no strict separation/layering which determines the parts that can work independently. So, while the code is mostly independent (in practice), that is not obvious from looking at the source tree. It thus still contributes to cognitive load. Add a shared library "shared/nm-platform", which should have no dependencies on libnm-core or NetworkManager core. In a first step, move the netlink code there. More should follow.
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am59
-rw-r--r--shared/meson.build23
-rw-r--r--shared/nm-platform/nm-netlink.c (renamed from src/platform/nm-netlink.c)0
-rw-r--r--shared/nm-platform/nm-netlink.h (renamed from src/platform/nm-netlink.h)0
-rw-r--r--shared/nm-platform/tests/meson.build19
-rw-r--r--shared/nm-platform/tests/test-nm-platform.c95
-rw-r--r--src/meson.build6
-rw-r--r--src/platform/nm-linux-platform.c2
-rw-r--r--src/platform/wifi/nm-wifi-utils-nl80211.c2
-rw-r--r--src/platform/wifi/nm-wifi-utils-nl80211.h2
-rw-r--r--src/platform/wifi/nm-wifi-utils.h2
-rw-r--r--src/platform/wpan/nm-wpan-utils.c2
-rw-r--r--src/platform/wpan/nm-wpan-utils.h2
14 files changed, 204 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
index b21bbf5c09..e9c4ba3590 100644
--- a/.gitignore
+++ b/.gitignore
@@ -135,6 +135,7 @@ test-*.trs
/shared/nm-glib-aux/tests/test-json-aux
/shared/nm-glib-aux/tests/test-shared-general
+/shared/nm-platform/tests/test-nm-platform
/shared/nm-version-macros.h
/introspection/org.freedesktop.NetworkManager*.[ch]
diff --git a/Makefile.am b/Makefile.am
index 493081373c..269fec1e50 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -464,6 +464,59 @@ shared_nm_udev_aux_libnm_udev_aux_la_LIBADD = \
###############################################################################
+noinst_LTLIBRARIES += shared/nm-platform/libnm-platform.la
+
+shared_nm_platform_libnm_platform_la_CPPFLAGS = \
+ $(shared_nm_glib_aux_cppflags) \
+ $(NULL)
+
+shared_nm_platform_libnm_platform_la_SOURCES = \
+ shared/nm-platform/nm-netlink.c \
+ shared/nm-platform/nm-netlink.h \
+ $(NULL)
+
+shared_nm_platform_libnm_platform_la_LDFLAGS = \
+ $(CODE_COVERAGE_LDFLAGS) \
+ $(SANITIZER_LIB_LDFLAGS) \
+ $(NULL)
+
+shared_nm_platform_libnm_platform_la_LIBADD = \
+ $(GLIB_LIBS) \
+ $(NULL)
+
+###############################################################################
+
+check_programs += shared/nm-platform/tests/test-nm-platform
+
+shared_nm_platform_tests_test_nm_platform_CPPFLAGS = \
+ $(dflt_cppflags) \
+ -I$(srcdir)/shared \
+ -DNETWORKMANAGER_COMPILATION_TEST \
+ -DNETWORKMANAGER_COMPILATION='(NM_NETWORKMANAGER_COMPILATION_GLIB|NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG)' \
+ $(CODE_COVERAGE_CFLAGS) \
+ $(GLIB_CFLAGS) \
+ $(SANITIZER_LIB_CFLAGS) \
+ $(NULL)
+
+shared_nm_platform_tests_test_nm_platform_LDFLAGS = \
+ $(CODE_COVERAGE_LDFLAGS) \
+ $(SANITIZER_EXEC_LDFLAGS) \
+ $(NULL)
+
+shared_nm_platform_tests_test_nm_platform_LDADD = \
+ shared/nm-platform/libnm-platform.la \
+ shared/nm-glib-aux/libnm-glib-aux.la \
+ shared/nm-std-aux/libnm-std-aux.la \
+ shared/libcsiphash.la \
+ $(GLIB_LIBS) \
+ $(NULL)
+
+EXTRA_DIST += \
+ shared/nm-platform/tests/meson.build \
+ $(NULL)
+
+###############################################################################
+
noinst_LTLIBRARIES += libnm-core/nm-libnm-core-intern/libnm-libnm-core-intern.la
libnm_core_nm_libnm_core_intern_libnm_libnm_core_intern_la_CPPFLAGS = \
@@ -2121,9 +2174,6 @@ src_libNetworkManagerBase_la_SOURCES = \
src/NetworkManagerUtils.c \
src/NetworkManagerUtils.h \
\
- src/platform/nm-netlink.c \
- src/platform/nm-netlink.h \
- \
src/platform/nmp-netns.c \
src/platform/nmp-netns.h \
src/platform/nmp-object.c \
@@ -2392,6 +2442,7 @@ src_libNetworkManager_la_LIBADD = \
libnm-core/libnm-core.la \
$(libnm_crypto_lib) \
libnm-core/nm-libnm-core-intern/libnm-libnm-core-intern.la \
+ shared/nm-platform/libnm-platform.la \
shared/nm-udev-aux/libnm-udev-aux.la \
shared/nm-glib-aux/libnm-glib-aux.la \
shared/nm-std-aux/libnm-std-aux.la \
@@ -2503,6 +2554,7 @@ src_nm_iface_helper_LDADD = \
libnm-core/libnm-core.la \
$(libnm_crypto_lib) \
libnm-core/nm-libnm-core-intern/libnm-libnm-core-intern.la \
+ shared/nm-platform/libnm-platform.la \
shared/nm-udev-aux/libnm-udev-aux.la \
shared/nm-glib-aux/libnm-glib-aux.la \
shared/nm-std-aux/libnm-std-aux.la \
@@ -2555,6 +2607,7 @@ src_initrd_nm_initrd_generator_LDADD = \
libnm-core/libnm-core.la \
$(libnm_crypto_lib) \
libnm-core/nm-libnm-core-intern/libnm-libnm-core-intern.la \
+ shared/nm-platform/libnm-platform.la \
shared/nm-udev-aux/libnm-udev-aux.la \
shared/nm-glib-aux/libnm-glib-aux.la \
shared/nm-std-aux/libnm-std-aux.la \
diff --git a/shared/meson.build b/shared/meson.build
index 42fccae7da..eb96e4d305 100644
--- a/shared/meson.build
+++ b/shared/meson.build
@@ -182,6 +182,28 @@ libnm_udev_aux_dep = declare_dependency(
link_with: libnm_udev_aux,
)
+libnm_platform = static_library(
+ 'nm-platform',
+ sources: [
+ 'nm-platform/nm-netlink.c',
+ ],
+ dependencies: [
+ glib_nm_default_dep,
+ ],
+ c_args: [
+ '-DG_LOG_DOMAIN="NetworkManager"',
+ '-DNETWORKMANAGER_COMPILATION=(NM_NETWORKMANAGER_COMPILATION_GLIB|NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_LIB)',
+ ],
+)
+
+libnm_platform_dep = declare_dependency(
+ include_directories: shared_inc,
+ dependencies: [
+ libnm_utils_base_dep,
+ ],
+ link_with: libnm_platform,
+)
+
sources = files(
'systemd/nm-sd-utils-shared.c',
'systemd/src/basic/alloc-util.c',
@@ -257,4 +279,5 @@ libnm_systemd_logging_stub = static_library(
if enable_tests
subdir('nm-glib-aux/tests')
+ subdir('nm-platform/tests')
endif
diff --git a/src/platform/nm-netlink.c b/shared/nm-platform/nm-netlink.c
index f9ebd1b623..f9ebd1b623 100644
--- a/src/platform/nm-netlink.c
+++ b/shared/nm-platform/nm-netlink.c
diff --git a/src/platform/nm-netlink.h b/shared/nm-platform/nm-netlink.h
index 8de42531d3..8de42531d3 100644
--- a/src/platform/nm-netlink.h
+++ b/shared/nm-platform/nm-netlink.h
diff --git a/shared/nm-platform/tests/meson.build b/shared/nm-platform/tests/meson.build
new file mode 100644
index 0000000000..4c9d91d118
--- /dev/null
+++ b/shared/nm-platform/tests/meson.build
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: LGPL-2.1-or-later
+
+exe = executable(
+ 'test-nm-platform',
+ 'test-nm-platform.c',
+ c_args: [
+ '-DNETWORKMANAGER_COMPILATION_TEST',
+ '-DNETWORKMANAGER_COMPILATION=(NM_NETWORKMANAGER_COMPILATION_GLIB|NM_NETWORKMANAGER_COMPILATION_WITH_GLIB_I18N_PROG)',
+ ],
+ dependencies: libnm_platform_dep,
+ link_with: libnm_systemd_logging_stub,
+)
+
+test(
+ 'shared/nm-glib-aux/test-nm-platform',
+ test_script,
+ args: test_args + [exe.full_path()],
+ timeout: default_test_timeout,
+)
diff --git a/shared/nm-platform/tests/test-nm-platform.c b/shared/nm-platform/tests/test-nm-platform.c
new file mode 100644
index 0000000000..179a3b6bb9
--- /dev/null
+++ b/shared/nm-platform/tests/test-nm-platform.c
@@ -0,0 +1,95 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#define NM_TEST_UTILS_NO_LIBNM 1
+
+#include "nm-default.h"
+
+#include "nm-platform/nm-netlink.h"
+
+#include "nm-utils/nm-test-utils.h"
+
+/*****************************************************************************/
+
+static void
+test_use_symbols(void)
+{
+ static void (*const SYMBOLS[])(void) = {
+ (void (*)(void)) nl_nlmsghdr_to_str,
+ (void (*)(void)) nlmsg_hdr,
+ (void (*)(void)) nlmsg_reserve,
+ (void (*)(void)) nla_reserve,
+ (void (*)(void)) nlmsg_alloc_size,
+ (void (*)(void)) nlmsg_alloc,
+ (void (*)(void)) nlmsg_alloc_convert,
+ (void (*)(void)) nlmsg_alloc_simple,
+ (void (*)(void)) nlmsg_free,
+ (void (*)(void)) nlmsg_append,
+ (void (*)(void)) nlmsg_parse,
+ (void (*)(void)) nlmsg_put,
+ (void (*)(void)) nla_strlcpy,
+ (void (*)(void)) nla_memcpy,
+ (void (*)(void)) nla_put,
+ (void (*)(void)) nla_find,
+ (void (*)(void)) nla_nest_cancel,
+ (void (*)(void)) nla_nest_start,
+ (void (*)(void)) nla_nest_end,
+ (void (*)(void)) nla_parse,
+ (void (*)(void)) nlmsg_get_proto,
+ (void (*)(void)) nlmsg_set_proto,
+ (void (*)(void)) nlmsg_set_src,
+ (void (*)(void)) nlmsg_get_creds,
+ (void (*)(void)) nlmsg_set_creds,
+ (void (*)(void)) genlmsg_put,
+ (void (*)(void)) genlmsg_data,
+ (void (*)(void)) genlmsg_user_hdr,
+ (void (*)(void)) genlmsg_hdr,
+ (void (*)(void)) genlmsg_user_data,
+ (void (*)(void)) genlmsg_attrdata,
+ (void (*)(void)) genlmsg_len,
+ (void (*)(void)) genlmsg_attrlen,
+ (void (*)(void)) genlmsg_valid_hdr,
+ (void (*)(void)) genlmsg_parse,
+ (void (*)(void)) genl_ctrl_resolve,
+ (void (*)(void)) nl_socket_alloc,
+ (void (*)(void)) nl_socket_free,
+ (void (*)(void)) nl_socket_get_fd,
+ (void (*)(void)) nl_socket_get_local_port,
+ (void (*)(void)) nl_socket_get_msg_buf_size,
+ (void (*)(void)) nl_socket_set_passcred,
+ (void (*)(void)) nl_socket_set_msg_buf_size,
+ (void (*)(void)) nlmsg_get_dst,
+ (void (*)(void)) nl_socket_set_nonblocking,
+ (void (*)(void)) nl_socket_set_buffer_size,
+ (void (*)(void)) nl_socket_add_memberships,
+ (void (*)(void)) nl_socket_set_ext_ack,
+ (void (*)(void)) nl_socket_disable_msg_peek,
+ (void (*)(void)) nl_connect,
+ (void (*)(void)) nl_wait_for_ack,
+ (void (*)(void)) nl_recvmsgs,
+ (void (*)(void)) nl_sendmsg,
+ (void (*)(void)) nl_send_iovec,
+ (void (*)(void)) nl_complete_msg,
+ (void (*)(void)) nl_send,
+ (void (*)(void)) nl_send_auto,
+ (void (*)(void)) nl_recv,
+ NULL,
+ };
+
+ /* The only (not very exciting) purpose of this test is to see that
+ * we can use various symbols and don't get a linker error. */
+ assert(G_N_ELEMENTS(SYMBOLS) == NM_PTRARRAY_LEN(SYMBOLS) + 1);
+}
+
+/*****************************************************************************/
+
+NMTST_DEFINE();
+
+int
+main(int argc, char **argv)
+{
+ nmtst_init(&argc, &argv, TRUE);
+
+ g_test_add_func("/nm-platform/test_use_symbols", test_use_symbols);
+
+ return g_test_run();
+}
diff --git a/src/meson.build b/src/meson.build
index 1d5f7b443c..f21ce17c44 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -5,7 +5,10 @@ src_inc = include_directories('.')
daemon_nm_default_dep = declare_dependency(
sources: libnm_core_enum_sources[1],
include_directories: src_inc,
- dependencies: libnm_core_nm_default_dep,
+ dependencies: [
+ libnm_core_nm_default_dep,
+ libnm_platform_dep,
+ ],
)
install_data(
@@ -28,7 +31,6 @@ sources = files(
'dhcp/nm-dhcp-options.c',
'ndisc/nm-lndp-ndisc.c',
'ndisc/nm-ndisc.c',
- 'platform/nm-netlink.c',
'platform/wifi/nm-wifi-utils-nl80211.c',
'platform/wifi/nm-wifi-utils.c',
'platform/wpan/nm-wpan-utils.c',
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index 74b2d5a962..a04b0ccf37 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -40,7 +40,7 @@
#include "nm-glib-aux/nm-secret-utils.h"
#include "nm-glib-aux/nm-c-list.h"
-#include "nm-netlink.h"
+#include "nm-platform/nm-netlink.h"
#include "nm-core-utils.h"
#include "nmp-object.h"
#include "nmp-netns.h"
diff --git a/src/platform/wifi/nm-wifi-utils-nl80211.c b/src/platform/wifi/nm-wifi-utils-nl80211.c
index a1c8ba6c93..0bca7acc46 100644
--- a/src/platform/wifi/nm-wifi-utils-nl80211.c
+++ b/src/platform/wifi/nm-wifi-utils-nl80211.c
@@ -15,7 +15,7 @@
#include <linux/nl80211.h>
#include <linux/if.h>
-#include "platform/nm-netlink.h"
+#include "nm-platform/nm-netlink.h"
#include "nm-wifi-utils-private.h"
#include "platform/nm-platform.h"
#include "platform/nm-platform-utils.h"
diff --git a/src/platform/wifi/nm-wifi-utils-nl80211.h b/src/platform/wifi/nm-wifi-utils-nl80211.h
index 1633a9ce4b..37c32ed78e 100644
--- a/src/platform/wifi/nm-wifi-utils-nl80211.h
+++ b/src/platform/wifi/nm-wifi-utils-nl80211.h
@@ -8,7 +8,7 @@
#define __WIFI_UTILS_NL80211_H__
#include "nm-wifi-utils.h"
-#include "platform/nm-netlink.h"
+#include "nm-platform/nm-netlink.h"
#define NM_TYPE_WIFI_UTILS_NL80211 (nm_wifi_utils_nl80211_get_type())
#define NM_WIFI_UTILS_NL80211(obj) \
diff --git a/src/platform/wifi/nm-wifi-utils.h b/src/platform/wifi/nm-wifi-utils.h
index 09e07a21c3..a252e43e54 100644
--- a/src/platform/wifi/nm-wifi-utils.h
+++ b/src/platform/wifi/nm-wifi-utils.h
@@ -11,7 +11,7 @@
#include "nm-dbus-interface.h"
#include "nm-setting-wireless.h"
-#include "platform/nm-netlink.h"
+#include "nm-platform/nm-netlink.h"
typedef struct NMWifiUtils NMWifiUtils;
diff --git a/src/platform/wpan/nm-wpan-utils.c b/src/platform/wpan/nm-wpan-utils.c
index 79c72b92da..d7c93b19b6 100644
--- a/src/platform/wpan/nm-wpan-utils.c
+++ b/src/platform/wpan/nm-wpan-utils.c
@@ -9,8 +9,8 @@
#include <linux/if.h>
+#include "nm-platform/nm-netlink.h"
#include "platform/linux/nl802154.h"
-#include "platform/nm-netlink.h"
#include "platform/nm-platform-utils.h"
#define _NMLOG_PREFIX_NAME "wpan-nl802154"
diff --git a/src/platform/wpan/nm-wpan-utils.h b/src/platform/wpan/nm-wpan-utils.h
index 6d170dd9ea..940c2c9daa 100644
--- a/src/platform/wpan/nm-wpan-utils.h
+++ b/src/platform/wpan/nm-wpan-utils.h
@@ -9,7 +9,7 @@
#include <net/ethernet.h>
#include "nm-dbus-interface.h"
-#include "platform/nm-netlink.h"
+#include "nm-platform/nm-netlink.h"
typedef struct NMWpanUtils NMWpanUtils;