mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-15 12:34:55 +00:00
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.
This commit is contained in:
parent
05008faf6e
commit
186f2da2fc
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -135,6 +135,7 @@ test-*.trs
|
||||||
|
|
||||||
/shared/nm-glib-aux/tests/test-json-aux
|
/shared/nm-glib-aux/tests/test-json-aux
|
||||||
/shared/nm-glib-aux/tests/test-shared-general
|
/shared/nm-glib-aux/tests/test-shared-general
|
||||||
|
/shared/nm-platform/tests/test-nm-platform
|
||||||
/shared/nm-version-macros.h
|
/shared/nm-version-macros.h
|
||||||
|
|
||||||
/introspection/org.freedesktop.NetworkManager*.[ch]
|
/introspection/org.freedesktop.NetworkManager*.[ch]
|
||||||
|
|
59
Makefile.am
59
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
|
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 = \
|
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.c \
|
||||||
src/NetworkManagerUtils.h \
|
src/NetworkManagerUtils.h \
|
||||||
\
|
\
|
||||||
src/platform/nm-netlink.c \
|
|
||||||
src/platform/nm-netlink.h \
|
|
||||||
\
|
|
||||||
src/platform/nmp-netns.c \
|
src/platform/nmp-netns.c \
|
||||||
src/platform/nmp-netns.h \
|
src/platform/nmp-netns.h \
|
||||||
src/platform/nmp-object.c \
|
src/platform/nmp-object.c \
|
||||||
|
@ -2392,6 +2442,7 @@ src_libNetworkManager_la_LIBADD = \
|
||||||
libnm-core/libnm-core.la \
|
libnm-core/libnm-core.la \
|
||||||
$(libnm_crypto_lib) \
|
$(libnm_crypto_lib) \
|
||||||
libnm-core/nm-libnm-core-intern/libnm-libnm-core-intern.la \
|
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-udev-aux/libnm-udev-aux.la \
|
||||||
shared/nm-glib-aux/libnm-glib-aux.la \
|
shared/nm-glib-aux/libnm-glib-aux.la \
|
||||||
shared/nm-std-aux/libnm-std-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-core/libnm-core.la \
|
||||||
$(libnm_crypto_lib) \
|
$(libnm_crypto_lib) \
|
||||||
libnm-core/nm-libnm-core-intern/libnm-libnm-core-intern.la \
|
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-udev-aux/libnm-udev-aux.la \
|
||||||
shared/nm-glib-aux/libnm-glib-aux.la \
|
shared/nm-glib-aux/libnm-glib-aux.la \
|
||||||
shared/nm-std-aux/libnm-std-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-core/libnm-core.la \
|
||||||
$(libnm_crypto_lib) \
|
$(libnm_crypto_lib) \
|
||||||
libnm-core/nm-libnm-core-intern/libnm-libnm-core-intern.la \
|
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-udev-aux/libnm-udev-aux.la \
|
||||||
shared/nm-glib-aux/libnm-glib-aux.la \
|
shared/nm-glib-aux/libnm-glib-aux.la \
|
||||||
shared/nm-std-aux/libnm-std-aux.la \
|
shared/nm-std-aux/libnm-std-aux.la \
|
||||||
|
|
|
@ -182,6 +182,28 @@ libnm_udev_aux_dep = declare_dependency(
|
||||||
link_with: libnm_udev_aux,
|
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(
|
sources = files(
|
||||||
'systemd/nm-sd-utils-shared.c',
|
'systemd/nm-sd-utils-shared.c',
|
||||||
'systemd/src/basic/alloc-util.c',
|
'systemd/src/basic/alloc-util.c',
|
||||||
|
@ -257,4 +279,5 @@ libnm_systemd_logging_stub = static_library(
|
||||||
|
|
||||||
if enable_tests
|
if enable_tests
|
||||||
subdir('nm-glib-aux/tests')
|
subdir('nm-glib-aux/tests')
|
||||||
|
subdir('nm-platform/tests')
|
||||||
endif
|
endif
|
||||||
|
|
19
shared/nm-platform/tests/meson.build
Normal file
19
shared/nm-platform/tests/meson.build
Normal file
|
@ -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,
|
||||||
|
)
|
95
shared/nm-platform/tests/test-nm-platform.c
Normal file
95
shared/nm-platform/tests/test-nm-platform.c
Normal file
|
@ -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();
|
||||||
|
}
|
|
@ -5,7 +5,10 @@ src_inc = include_directories('.')
|
||||||
daemon_nm_default_dep = declare_dependency(
|
daemon_nm_default_dep = declare_dependency(
|
||||||
sources: libnm_core_enum_sources[1],
|
sources: libnm_core_enum_sources[1],
|
||||||
include_directories: src_inc,
|
include_directories: src_inc,
|
||||||
dependencies: libnm_core_nm_default_dep,
|
dependencies: [
|
||||||
|
libnm_core_nm_default_dep,
|
||||||
|
libnm_platform_dep,
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
install_data(
|
install_data(
|
||||||
|
@ -28,7 +31,6 @@ sources = files(
|
||||||
'dhcp/nm-dhcp-options.c',
|
'dhcp/nm-dhcp-options.c',
|
||||||
'ndisc/nm-lndp-ndisc.c',
|
'ndisc/nm-lndp-ndisc.c',
|
||||||
'ndisc/nm-ndisc.c',
|
'ndisc/nm-ndisc.c',
|
||||||
'platform/nm-netlink.c',
|
|
||||||
'platform/wifi/nm-wifi-utils-nl80211.c',
|
'platform/wifi/nm-wifi-utils-nl80211.c',
|
||||||
'platform/wifi/nm-wifi-utils.c',
|
'platform/wifi/nm-wifi-utils.c',
|
||||||
'platform/wpan/nm-wpan-utils.c',
|
'platform/wpan/nm-wpan-utils.c',
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
#include "nm-glib-aux/nm-secret-utils.h"
|
#include "nm-glib-aux/nm-secret-utils.h"
|
||||||
#include "nm-glib-aux/nm-c-list.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 "nm-core-utils.h"
|
||||||
#include "nmp-object.h"
|
#include "nmp-object.h"
|
||||||
#include "nmp-netns.h"
|
#include "nmp-netns.h"
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include <linux/nl80211.h>
|
#include <linux/nl80211.h>
|
||||||
#include <linux/if.h>
|
#include <linux/if.h>
|
||||||
|
|
||||||
#include "platform/nm-netlink.h"
|
#include "nm-platform/nm-netlink.h"
|
||||||
#include "nm-wifi-utils-private.h"
|
#include "nm-wifi-utils-private.h"
|
||||||
#include "platform/nm-platform.h"
|
#include "platform/nm-platform.h"
|
||||||
#include "platform/nm-platform-utils.h"
|
#include "platform/nm-platform-utils.h"
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#define __WIFI_UTILS_NL80211_H__
|
#define __WIFI_UTILS_NL80211_H__
|
||||||
|
|
||||||
#include "nm-wifi-utils.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_TYPE_WIFI_UTILS_NL80211 (nm_wifi_utils_nl80211_get_type())
|
||||||
#define NM_WIFI_UTILS_NL80211(obj) \
|
#define NM_WIFI_UTILS_NL80211(obj) \
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include "nm-dbus-interface.h"
|
#include "nm-dbus-interface.h"
|
||||||
#include "nm-setting-wireless.h"
|
#include "nm-setting-wireless.h"
|
||||||
#include "platform/nm-netlink.h"
|
#include "nm-platform/nm-netlink.h"
|
||||||
|
|
||||||
typedef struct NMWifiUtils NMWifiUtils;
|
typedef struct NMWifiUtils NMWifiUtils;
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
#include <linux/if.h>
|
#include <linux/if.h>
|
||||||
|
|
||||||
|
#include "nm-platform/nm-netlink.h"
|
||||||
#include "platform/linux/nl802154.h"
|
#include "platform/linux/nl802154.h"
|
||||||
#include "platform/nm-netlink.h"
|
|
||||||
#include "platform/nm-platform-utils.h"
|
#include "platform/nm-platform-utils.h"
|
||||||
|
|
||||||
#define _NMLOG_PREFIX_NAME "wpan-nl802154"
|
#define _NMLOG_PREFIX_NAME "wpan-nl802154"
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include <net/ethernet.h>
|
#include <net/ethernet.h>
|
||||||
|
|
||||||
#include "nm-dbus-interface.h"
|
#include "nm-dbus-interface.h"
|
||||||
#include "platform/nm-netlink.h"
|
#include "nm-platform/nm-netlink.h"
|
||||||
|
|
||||||
typedef struct NMWpanUtils NMWpanUtils;
|
typedef struct NMWpanUtils NMWpanUtils;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue