diff options
author | Thomas Haller <thaller@redhat.com> | 2021-03-05 11:29:09 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-03-05 11:29:09 +0100 |
commit | 7ad2b8f20a60c5c8faebda343c7ee948e11c0a93 (patch) | |
tree | f042ad6b8bc7d31709c034d5ac8b2f6fc869c111 | |
parent | 1c0932a6e66880f5b4c92fcd2d13cbba29238a14 (diff) | |
parent | 604b1d033126700d26182bb02f3180a80ef388ca (diff) | |
download | NetworkManager-7ad2b8f20a60c5c8faebda343c7ee948e11c0a93.tar.gz |
platform: merge branch 'th/platform-move'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/769
145 files changed, 2168 insertions, 1851 deletions
diff --git a/Makefile.am b/Makefile.am index 5cd624ff1e..38c84732ba 100644 --- a/Makefile.am +++ b/Makefile.am @@ -571,15 +571,42 @@ src_libnm_platform_libnm_platform_la_CPPFLAGS = \ $(NULL) src_libnm_platform_libnm_platform_la_SOURCES = \ + \ + src/linux-headers/nl802154.h \ + \ + src/libnm-platform/nm-linux-platform.c \ + src/libnm-platform/nm-linux-platform.h \ src/libnm-platform/nm-netlink.c \ src/libnm-platform/nm-netlink.h \ + src/libnm-platform/nm-platform-private.h \ src/libnm-platform/nm-platform-utils.c \ src/libnm-platform/nm-platform-utils.h \ + src/libnm-platform/nm-platform.c \ + src/libnm-platform/nm-platform.h \ src/libnm-platform/nmp-base.h \ src/libnm-platform/nmp-netns.c \ src/libnm-platform/nmp-netns.h \ + src/libnm-platform/nmp-object.c \ + src/libnm-platform/nmp-object.h \ + src/libnm-platform/nmp-rules-manager.c \ + src/libnm-platform/nmp-rules-manager.h \ + src/libnm-platform/wifi/nm-wifi-utils-nl80211.c \ + src/libnm-platform/wifi/nm-wifi-utils-nl80211.h \ + src/libnm-platform/wifi/nm-wifi-utils-private.h \ + src/libnm-platform/wifi/nm-wifi-utils.c \ + src/libnm-platform/wifi/nm-wifi-utils.h \ + src/libnm-platform/wpan/nm-wpan-utils.c \ + src/libnm-platform/wpan/nm-wpan-utils.h \ + \ $(NULL) +if WITH_WEXT +src_libnm_platform_libnm_platform_la_SOURCES += \ + src/libnm-platform/wifi/nm-wifi-utils-wext.c \ + src/libnm-platform/wifi/nm-wifi-utils-wext.h \ + $(NULL) +endif + src_libnm_platform_libnm_platform_la_LDFLAGS = \ $(CODE_COVERAGE_LDFLAGS) \ $(SANITIZER_LIB_LDFLAGS) \ @@ -1201,7 +1228,6 @@ src_libnm_core_impl_lib_h_priv = \ src/libnm-core-impl/nm-team-utils.h \ src/libnm-core-impl/nm-utils-private.h \ src/libnm-core-intern/nm-core-internal.h \ - src/libnm-core-intern/nm-core-types-internal.h \ src/libnm-core-intern/nm-keyfile-internal.h \ src/libnm-core-intern/nm-keyfile-utils.h \ src/libnm-core-intern/nm-meta-setting-base-impl.h \ @@ -2310,23 +2336,6 @@ src_core_libNetworkManagerBase_la_SOURCES = \ src/core/NetworkManagerUtils.c \ src/core/NetworkManagerUtils.h \ \ - src/core/platform/nmp-object.c \ - src/core/platform/nmp-object.h \ - src/core/platform/nm-platform.c \ - src/core/platform/nm-platform.h \ - src/core/platform/nm-platform-private.h \ - src/core/platform/nm-linux-platform.c \ - src/core/platform/nm-linux-platform.h \ - src/core/platform/nmp-rules-manager.c \ - src/core/platform/nmp-rules-manager.h \ - src/core/platform/wifi/nm-wifi-utils-nl80211.c \ - src/core/platform/wifi/nm-wifi-utils-nl80211.h \ - src/core/platform/wifi/nm-wifi-utils-private.h \ - src/core/platform/wifi/nm-wifi-utils.c \ - src/core/platform/wifi/nm-wifi-utils.h \ - src/core/platform/wpan/nm-wpan-utils.c \ - src/core/platform/wpan/nm-wpan-utils.h \ - \ src/core/ndisc/nm-lndp-ndisc.c \ src/core/ndisc/nm-lndp-ndisc.h \ src/core/ndisc/nm-ndisc.c \ @@ -2369,12 +2378,6 @@ src_core_libNetworkManagerBase_la_SOURCES = \ \ $(NULL) -if WITH_WEXT -src_core_libNetworkManagerBase_la_SOURCES += \ - src/core/platform/wifi/nm-wifi-utils-wext.c \ - src/core/platform/wifi/nm-wifi-utils-wext.h -endif - src_core_libNetworkManagerBase_la_LIBADD = \ $(GLIB_LIBS) \ $(LIBUDEV_LIBS) \ @@ -2382,9 +2385,6 @@ src_core_libNetworkManagerBase_la_LIBADD = \ $(src_core_libNetworkManagerBase_la_OBJECTS): $(src_libnm_core_public_mkenums_h) -EXTRA_DIST += \ - src/core/platform/linux/nl802154.h - ############################################################################### src_core_libNetworkManager_la_CPPFLAGS = $(src_core_cppflags) diff --git a/docs/libnm/Makefile.am b/docs/libnm/Makefile.am index 3de6976b70..17244c1226 100644 --- a/docs/libnm/Makefile.am +++ b/docs/libnm/Makefile.am @@ -41,7 +41,6 @@ IGNORE_HFILES= \ common.h \ nm-core-internal.h \ nm-core-tests-enum-types.h \ - nm-core-types-internal.h \ nm-crypto-impl.h \ nm-crypto.h \ nm-dbus-helpers.h \ diff --git a/docs/libnm/meson.build b/docs/libnm/meson.build index 746335c4ce..5a87b62a76 100644 --- a/docs/libnm/meson.build +++ b/docs/libnm/meson.build @@ -4,7 +4,6 @@ private_headers = [ 'common.h', 'nm-core-internal.h', 'nm-core-tests-enum-types.h', - 'nm-core-types-internal.h', 'nm-crypto-impl.h', 'nm-crypto.h', 'nm-dbus-helpers.h', diff --git a/src/core/NetworkManagerUtils.c b/src/core/NetworkManagerUtils.c index bb72aaf8d7..a236faac31 100644 --- a/src/core/NetworkManagerUtils.c +++ b/src/core/NetworkManagerUtils.c @@ -20,9 +20,10 @@ #include "nm-setting-ip4-config.h" #include "nm-setting-ip6-config.h" #include "libnm-core-intern/nm-core-internal.h" -#include "platform/nmp-object.h" +#include "libnm-platform/nmp-object.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" +#include "libnm-platform/nm-linux-platform.h" #include "nm-auth-utils.h" #include "libnm-systemd-shared/nm-sd-utils-shared.h" @@ -1829,3 +1830,63 @@ nm_utils_share_rules_add_all_rules(NMUtilsShareRules *self, "INPUT --in-interface %s --protocol tcp --destination-port 53 --jump ACCEPT", ip_iface); } + +/*****************************************************************************/ + +/* Singleton NMPlatform subclass instance and cached class object */ +NM_DEFINE_SINGLETON_INSTANCE(NMPlatform); + +NM_DEFINE_SINGLETON_REGISTER(NMPlatform); + +/** + * nm_platform_setup: + * @instance: the #NMPlatform instance + * + * Failing to set up #NMPlatform singleton results in a fatal error, + * as well as trying to initialize it multiple times without freeing + * it. + * + * NetworkManager will typically use only one platform object during + * its run. Test programs might want to switch platform implementations, + * though. + */ +void +nm_platform_setup(NMPlatform *instance) +{ + g_return_if_fail(NM_IS_PLATFORM(instance)); + g_return_if_fail(!singleton_instance); + + singleton_instance = instance; + + nm_singleton_instance_register(); + + nm_log_dbg(LOGD_CORE, + "setup %s singleton (" NM_HASH_OBFUSCATE_PTR_FMT ")", + "NMPlatform", + NM_HASH_OBFUSCATE_PTR(instance)); +} + +/** + * nm_platform_get: + * @self: platform instance + * + * Retrieve #NMPlatform singleton. Use this whenever you want to connect to + * #NMPlatform signals. It is an error to call it before nm_platform_setup(). + * + * Returns: (transfer none): The #NMPlatform singleton reference. + */ +NMPlatform * +nm_platform_get() +{ + g_assert(singleton_instance); + + return singleton_instance; +} + +/*****************************************************************************/ + +void +nm_linux_platform_setup(void) +{ + nm_platform_setup(nm_linux_platform_new(FALSE, FALSE)); +} diff --git a/src/core/NetworkManagerUtils.h b/src/core/NetworkManagerUtils.h index 28b0531ac0..a004dbb718 100644 --- a/src/core/NetworkManagerUtils.h +++ b/src/core/NetworkManagerUtils.h @@ -11,7 +11,7 @@ #include "libnm-glib-aux/nm-dedup-multi.h" #include "nm-setting-ip-config.h" #include "nm-setting-ip6-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" /*****************************************************************************/ @@ -251,4 +251,13 @@ void nm_utils_share_rules_apply(NMUtilsShareRules *self, gboolean shared); /*****************************************************************************/ +void nm_platform_setup(NMPlatform *instance); +NMPlatform *nm_platform_get(void); + +#define NM_PLATFORM_GET (nm_platform_get()) + +void nm_linux_platform_setup(void); + +/*****************************************************************************/ + #endif /* __NETWORKMANAGER_UTILS_H__ */ diff --git a/src/core/devices/adsl/nm-atm-manager.c b/src/core/devices/adsl/nm-atm-manager.c index 8aa23f5005..bd9ed8cc23 100644 --- a/src/core/devices/adsl/nm-atm-manager.c +++ b/src/core/devices/adsl/nm-atm-manager.c @@ -11,7 +11,7 @@ #include "nm-setting-adsl.h" #include "nm-device-adsl.h" #include "devices/nm-device-factory.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-udev-aux/nm-udev-utils.h" /*****************************************************************************/ diff --git a/src/core/devices/adsl/nm-device-adsl.c b/src/core/devices/adsl/nm-device-adsl.c index 34c062a8db..01a1b39024 100644 --- a/src/core/devices/adsl/nm-device-adsl.c +++ b/src/core/devices/adsl/nm-device-adsl.c @@ -17,7 +17,7 @@ #include "nm-ip4-config.h" #include "devices/nm-device-private.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "ppp/nm-ppp-manager-call.h" #include "ppp/nm-ppp-status.h" #include "nm-setting-adsl.h" diff --git a/src/core/devices/bluetooth/nm-bluez-manager.c b/src/core/devices/bluetooth/nm-bluez-manager.c index a9fdcdd7fd..a16a22a096 100644 --- a/src/core/devices/bluetooth/nm-bluez-manager.c +++ b/src/core/devices/bluetooth/nm-bluez-manager.c @@ -24,7 +24,7 @@ #include "nm-manager.h" #include "nm-bluez5-dun.h" #include "libnm-core-intern/nm-core-internal.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-std-aux/nm-dbus-compat.h" /*****************************************************************************/ diff --git a/src/core/devices/bluetooth/nm-device-bt.c b/src/core/devices/bluetooth/nm-device-bt.c index 2c336587ed..c7f76a5ab8 100644 --- a/src/core/devices/bluetooth/nm-device-bt.c +++ b/src/core/devices/bluetooth/nm-device-bt.c @@ -26,7 +26,7 @@ #include "nm-utils.h" #include "nm-bt-error.h" #include "nm-ip4-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "devices/wwan/nm-modem-manager.h" #include "devices/wwan/nm-modem.h" diff --git a/src/core/devices/nm-acd-manager.c b/src/core/devices/nm-acd-manager.c index b95f90fd45..995abacded 100644 --- a/src/core/devices/nm-acd-manager.c +++ b/src/core/devices/nm-acd-manager.c @@ -12,7 +12,7 @@ #include <sys/wait.h> #include <linux/if_ether.h> -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-utils.h" #include "NetworkManagerUtils.h" #include "n-acd/src/n-acd.h" diff --git a/src/core/devices/nm-device-6lowpan.c b/src/core/devices/nm-device-6lowpan.c index fe116dd47a..96218658c1 100644 --- a/src/core/devices/nm-device-6lowpan.c +++ b/src/core/devices/nm-device-6lowpan.c @@ -9,7 +9,7 @@ #include "nm-device-private.h" #include "settings/nm-settings.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "nm-setting-6lowpan.h" #include "nm-utils.h" diff --git a/src/core/devices/nm-device-bond.c b/src/core/devices/nm-device-bond.c index 9741be8c52..878d3e9e0c 100644 --- a/src/core/devices/nm-device-bond.c +++ b/src/core/devices/nm-device-bond.c @@ -12,7 +12,7 @@ #include "NetworkManagerUtils.h" #include "nm-device-private.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "libnm-core-intern/nm-core-internal.h" #include "nm-ip4-config.h" diff --git a/src/core/devices/nm-device-bridge.c b/src/core/devices/nm-device-bridge.c index 8ace4a4d54..8bed7839ae 100644 --- a/src/core/devices/nm-device-bridge.c +++ b/src/core/devices/nm-device-bridge.c @@ -12,7 +12,7 @@ #include "NetworkManagerUtils.h" #include "nm-device-private.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "libnm-core-intern/nm-core-internal.h" @@ -1033,7 +1033,7 @@ create_and_realize(NMDevice * device, const char * iface = nm_device_get_iface(device); const char * hwaddr; gs_free char * hwaddr_cloned = NULL; - guint8 mac_address[NM_UTILS_HWADDR_LEN_MAX]; + guint8 mac_address[_NM_UTILS_HWADDR_LEN_MAX]; NMPlatformLnkBridge props; int r; guint32 mtu = 0; diff --git a/src/core/devices/nm-device-dummy.c b/src/core/devices/nm-device-dummy.c index b553299ada..bb7150ccc7 100644 --- a/src/core/devices/nm-device-dummy.c +++ b/src/core/devices/nm-device-dummy.c @@ -13,7 +13,7 @@ #include "nm-act-request.h" #include "nm-device-private.h" #include "nm-ip4-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "nm-setting-dummy.h" #include "libnm-core-intern/nm-core-internal.h" diff --git a/src/core/devices/nm-device-ethernet.c b/src/core/devices/nm-device-ethernet.c index 8139cf629c..064d79f5c2 100644 --- a/src/core/devices/nm-device-ethernet.c +++ b/src/core/devices/nm-device-ethernet.c @@ -24,7 +24,7 @@ #include "ppp/nm-ppp-manager.h" #include "ppp/nm-ppp-manager-call.h" #include "ppp/nm-ppp-status.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-platform/nm-platform-utils.h" #include "nm-dcb.h" #include "settings/nm-settings-connection.h" diff --git a/src/core/devices/nm-device-factory.c b/src/core/devices/nm-device-factory.c index 8dbc985ceb..bdc64135d9 100644 --- a/src/core/devices/nm-device-factory.c +++ b/src/core/devices/nm-device-factory.c @@ -11,7 +11,7 @@ #include <sys/stat.h> #include <gmodule.h> -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-utils.h" #include "libnm-core-intern/nm-core-internal.h" #include "nm-setting-bluetooth.h" diff --git a/src/core/devices/nm-device-generic.c b/src/core/devices/nm-device-generic.c index 497a5f94b7..299cb08d27 100644 --- a/src/core/devices/nm-device-generic.c +++ b/src/core/devices/nm-device-generic.c @@ -8,7 +8,7 @@ #include "nm-device-generic.h" #include "nm-device-private.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-core-intern/nm-core-internal.h" /*****************************************************************************/ diff --git a/src/core/devices/nm-device-infiniband.c b/src/core/devices/nm-device-infiniband.c index feee1583aa..954302507b 100644 --- a/src/core/devices/nm-device-infiniband.c +++ b/src/core/devices/nm-device-infiniband.c @@ -14,7 +14,7 @@ #include "nm-device-private.h" #include "nm-act-request.h" #include "nm-ip4-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "libnm-core-intern/nm-core-internal.h" diff --git a/src/core/devices/nm-device-ip-tunnel.c b/src/core/devices/nm-device-ip-tunnel.c index 75cc222e92..1e7f134ae8 100644 --- a/src/core/devices/nm-device-ip-tunnel.c +++ b/src/core/devices/nm-device-ip-tunnel.c @@ -16,7 +16,7 @@ #include "nm-device-private.h" #include "nm-manager.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "libnm-core-intern/nm-core-internal.h" #include "settings/nm-settings.h" diff --git a/src/core/devices/nm-device-macsec.c b/src/core/devices/nm-device-macsec.c index 839a3f094c..14844c4085 100644 --- a/src/core/devices/nm-device-macsec.c +++ b/src/core/devices/nm-device-macsec.c @@ -11,7 +11,7 @@ #include "nm-act-request.h" #include "nm-device-private.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "nm-manager.h" #include "nm-setting-macsec.h" diff --git a/src/core/devices/nm-device-macvlan.c b/src/core/devices/nm-device-macvlan.c index e8b39ed6b0..b9903bc06d 100644 --- a/src/core/devices/nm-device-macvlan.c +++ b/src/core/devices/nm-device-macvlan.c @@ -13,7 +13,7 @@ #include "settings/nm-settings.h" #include "nm-act-request.h" #include "nm-manager.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "nm-setting-macvlan.h" #include "nm-setting-wired.h" diff --git a/src/core/devices/nm-device-ppp.c b/src/core/devices/nm-device-ppp.c index 4040f2d316..b642d0d7de 100644 --- a/src/core/devices/nm-device-ppp.c +++ b/src/core/devices/nm-device-ppp.c @@ -13,7 +13,7 @@ #include "nm-device-private.h" #include "nm-manager.h" #include "nm-setting-pppoe.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "ppp/nm-ppp-manager.h" #include "ppp/nm-ppp-manager-call.h" #include "ppp/nm-ppp-status.h" diff --git a/src/core/devices/nm-device-tun.c b/src/core/devices/nm-device-tun.c index d3050b8c89..1b3348dcba 100644 --- a/src/core/devices/nm-device-tun.c +++ b/src/core/devices/nm-device-tun.c @@ -14,7 +14,7 @@ #include "nm-act-request.h" #include "nm-device-private.h" #include "nm-ip4-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "nm-setting-tun.h" #include "libnm-core-intern/nm-core-internal.h" diff --git a/src/core/devices/nm-device-veth.c b/src/core/devices/nm-device-veth.c index 03e34bd8bc..b1737b5b7f 100644 --- a/src/core/devices/nm-device-veth.c +++ b/src/core/devices/nm-device-veth.c @@ -11,7 +11,7 @@ #include "nm-device-veth.h" #include "nm-device-private.h" #include "nm-manager.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "nm-setting-veth.h" diff --git a/src/core/devices/nm-device-vlan.c b/src/core/devices/nm-device-vlan.c index 85edff5b0a..3b426ef4c9 100644 --- a/src/core/devices/nm-device-vlan.c +++ b/src/core/devices/nm-device-vlan.c @@ -16,11 +16,12 @@ #include "settings/nm-settings.h" #include "nm-act-request.h" #include "nm-ip4-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "nm-manager.h" #include "libnm-core-intern/nm-core-internal.h" -#include "platform/nmp-object.h" +#include "libnm-platform/nmp-object.h" +#include "libnm-platform/nm-platform-utils.h" #define _NMLOG_DEVICE_TYPE NMDeviceVlan #include "nm-device-logging.h" @@ -436,7 +437,7 @@ update_connection(NMDevice *device, NMConnection *connection) const NMPlatformLink *plink; const NMPObject * polnk; guint vlan_id; - guint vlan_flags; + _NMVlanFlags vlan_flags; if (!s_vlan) { s_vlan = (NMSettingVlan *) nm_setting_vlan_new(); @@ -463,9 +464,9 @@ update_connection(NMDevice *device, NMConnection *connection) if (polnk) vlan_flags = polnk->lnk_vlan.flags; else - vlan_flags = NM_VLAN_FLAG_REORDER_HEADERS; - if (vlan_flags != nm_setting_vlan_get_flags(s_vlan)) - g_object_set(s_vlan, NM_SETTING_VLAN_FLAGS, (NMVlanFlags) vlan_flags, NULL); + vlan_flags = _NM_VLAN_FLAG_REORDER_HEADERS; + if (NM_VLAN_FLAGS_CAST(vlan_flags) != nm_setting_vlan_get_flags(s_vlan)) + g_object_set(s_vlan, NM_SETTING_VLAN_FLAGS, NM_VLAN_FLAGS_CAST(vlan_flags), NULL); if (polnk) { _nm_setting_vlan_set_priorities(s_vlan, @@ -507,7 +508,7 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) nm_platform_link_vlan_change(nm_device_get_platform(device), nm_device_get_ifindex(device), - NM_VLAN_FLAGS_ALL, + _NM_VLAN_FLAGS_ALL, nm_setting_vlan_get_flags(s_vlan), TRUE, ingress_map, @@ -674,7 +675,7 @@ get_connection_iface(NMDeviceFactory *factory, NMConnection *connection, const c * device, we create one for it using the VLAN ID and the parent * interface's name. */ - return nm_utils_new_vlan_name(parent_iface, nm_setting_vlan_get_id(s_vlan)); + return nmp_utils_new_vlan_name(parent_iface, nm_setting_vlan_get_id(s_vlan)); } NM_DEVICE_FACTORY_DEFINE_INTERNAL( diff --git a/src/core/devices/nm-device-vrf.c b/src/core/devices/nm-device-vrf.c index ab17197add..2a1f42c646 100644 --- a/src/core/devices/nm-device-vrf.c +++ b/src/core/devices/nm-device-vrf.c @@ -9,7 +9,7 @@ #include "nm-device-private.h" #include "nm-manager.h" #include "nm-setting-vrf.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "settings/nm-settings.h" #define _NMLOG_DEVICE_TYPE NMDeviceVrf diff --git a/src/core/devices/nm-device-vxlan.c b/src/core/devices/nm-device-vxlan.c index c0a11cd042..557b545cf1 100644 --- a/src/core/devices/nm-device-vxlan.c +++ b/src/core/devices/nm-device-vxlan.c @@ -9,7 +9,7 @@ #include "nm-device-private.h" #include "nm-manager.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-utils.h" #include "nm-device-factory.h" #include "nm-setting-vxlan.h" diff --git a/src/core/devices/nm-device-wireguard.c b/src/core/devices/nm-device-wireguard.c index 4ad75d1db5..09030dd8f7 100644 --- a/src/core/devices/nm-device-wireguard.c +++ b/src/core/devices/nm-device-wireguard.c @@ -14,9 +14,9 @@ #include "libnm-core-intern/nm-core-internal.h" #include "libnm-glib-aux/nm-secret-utils.h" #include "nm-device-private.h" -#include "platform/nm-platform.h" -#include "platform/nmp-object.h" -#include "platform/nmp-rules-manager.h" +#include "libnm-platform/nm-platform.h" +#include "libnm-platform/nmp-object.h" +#include "libnm-platform/nmp-rules-manager.h" #include "nm-device-factory.h" #include "nm-active-connection.h" #include "nm-act-request.h" diff --git a/src/core/devices/nm-device-wpan.c b/src/core/devices/nm-device-wpan.c index 7f1f9e3286..73d7941001 100644 --- a/src/core/devices/nm-device-wpan.c +++ b/src/core/devices/nm-device-wpan.c @@ -15,7 +15,7 @@ #include "nm-act-request.h" #include "nm-device-private.h" #include "nm-ip4-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-device-factory.h" #include "nm-setting-wpan.h" #include "libnm-core-intern/nm-core-internal.h" diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index ab66578688..9d44757c08 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -35,10 +35,10 @@ #include "nm-l3-config-data.h" #include "NetworkManagerUtils.h" #include "nm-manager.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-platform/nm-platform-utils.h" -#include "platform/nmp-object.h" -#include "platform/nmp-rules-manager.h" +#include "libnm-platform/nmp-object.h" +#include "libnm-platform/nmp-rules-manager.h" #include "ndisc/nm-ndisc.h" #include "ndisc/nm-lndp-ndisc.h" #include "dhcp/nm-dhcp-manager.h" @@ -1567,7 +1567,7 @@ _prop_get_ipvx_dhcp_iaid(NMDevice * self, iaid = unaligned_read_be32(&pllink->l_address.data[pllink->l_address.len - 4]); goto out_good; } else if (nm_streq0(iaid_str, NM_IAID_PERM_MAC)) { - guint8 hwaddr_buf[NM_UTILS_HWADDR_LEN_MAX]; + guint8 hwaddr_buf[_NM_UTILS_HWADDR_LEN_MAX]; const char *hwaddr_str; gsize hwaddr_len; @@ -1729,7 +1729,7 @@ _prop_get_ipv4_dhcp_client_id(NMDevice *self, NMConnection *connection, GBytes * gs_free char * client_id_default = NULL; guint8 * client_id_buf; const char * fail_reason; - guint8 hwaddr_bin_buf[NM_UTILS_HWADDR_LEN_MAX]; + guint8 hwaddr_bin_buf[_NM_UTILS_HWADDR_LEN_MAX]; const guint8 * hwaddr_bin; int arp_type; gsize hwaddr_len; @@ -5216,11 +5216,11 @@ ndisc_set_router_config(NMNDisc *ndisc, NMDevice *self) if (addr->plen != 64) continue; - lifetime = nm_utils_lifetime_get(addr->timestamp, - addr->lifetime, - addr->preferred, - NM_NDISC_EXPIRY_BASE_TIMESTAMP / 1000, - &preferred); + lifetime = nmp_utils_lifetime_get(addr->timestamp, + addr->lifetime, + addr->preferred, + NM_NDISC_EXPIRY_BASE_TIMESTAMP / 1000, + &preferred); if (!lifetime) continue; @@ -11634,7 +11634,7 @@ share_init(NMDevice *self, GError **error) } for (i = 0; i < G_N_ELEMENTS(modules); i++) - nm_utils_modprobe(NULL, FALSE, modules[i], NULL); + nmp_utils_modprobe(NULL, FALSE, modules[i], NULL); return TRUE; } @@ -16821,7 +16821,7 @@ const char * nm_device_get_hw_address(NMDevice *self) { NMDevicePrivate *priv; - char buf[NM_UTILS_HWADDR_LEN_MAX]; + char buf[_NM_UTILS_HWADDR_LEN_MAX]; gsize l; g_return_val_if_fail(NM_IS_DEVICE(self), NULL); @@ -16915,7 +16915,7 @@ void nm_device_update_permanent_hw_address(NMDevice *self, gboolean force_freeze) { NMDevicePrivate * priv = NM_DEVICE_GET_PRIVATE(self); - guint8 buf[NM_UTILS_HWADDR_LEN_MAX]; + guint8 buf[_NM_UTILS_HWADDR_LEN_MAX]; size_t len = 0; gboolean success_read; int ifindex; @@ -17033,7 +17033,7 @@ _hw_addr_set(NMDevice * self, NMDevicePrivate *priv; gboolean success = FALSE; int r; - guint8 addr_bytes[NM_UTILS_HWADDR_LEN_MAX]; + guint8 addr_bytes[_NM_UTILS_HWADDR_LEN_MAX]; gsize addr_len; gboolean was_taken_down = FALSE; gboolean retry_down; @@ -18216,7 +18216,7 @@ constructor(GType type, guint n_construct_params, GObjectConstructParam *constru } if (priv->hw_addr_perm) { - guint8 buf[NM_UTILS_HWADDR_LEN_MAX]; + guint8 buf[_NM_UTILS_HWADDR_LEN_MAX]; gsize l; if (!_nm_utils_hwaddr_aton(priv->hw_addr_perm, buf, sizeof(buf), &l)) { diff --git a/src/core/devices/nm-lldp-listener.c b/src/core/devices/nm-lldp-listener.c index 41110e2fe3..808c1e2680 100644 --- a/src/core/devices/nm-lldp-listener.c +++ b/src/core/devices/nm-lldp-listener.c @@ -9,8 +9,11 @@ #include <net/ethernet.h> +#include "NetworkManagerUtils.h" +#include "libnm-core-public/nm-errors.h" +#include "libnm-glib-aux/nm-time-utils.h" #include "libnm-std-aux/unaligned.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-glib-aux/nm-c-list.h" #include "nm-utils.h" diff --git a/src/core/devices/ovs/nm-ovs-factory.c b/src/core/devices/ovs/nm-ovs-factory.c index 3a9a736448..6f5d88326b 100644 --- a/src/core/devices/ovs/nm-ovs-factory.c +++ b/src/core/devices/ovs/nm-ovs-factory.c @@ -10,7 +10,7 @@ #include "nm-device-ovs-interface.h" #include "nm-device-ovs-port.h" #include "nm-device-ovs-bridge.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-core-intern/nm-core-internal.h" #include "settings/nm-settings.h" #include "devices/nm-device-factory.h" diff --git a/src/core/devices/team/nm-device-team.c b/src/core/devices/team/nm-device-team.c index 6fc5c78f78..efd71dcb60 100644 --- a/src/core/devices/team/nm-device-team.c +++ b/src/core/devices/team/nm-device-team.c @@ -18,7 +18,7 @@ #include "libnm-glib-aux/nm-jansson.h" #include "NetworkManagerUtils.h" #include "devices/nm-device-private.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-config.h" #include "libnm-core-intern/nm-core-internal.h" #include "nm-dbus-manager.h" diff --git a/src/core/devices/team/nm-team-factory.c b/src/core/devices/team/nm-team-factory.c index 21be23965b..e2040d19fd 100644 --- a/src/core/devices/team/nm-team-factory.c +++ b/src/core/devices/team/nm-team-factory.c @@ -10,7 +10,7 @@ #include "nm-manager.h" #include "devices/nm-device-factory.h" #include "nm-device-team.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-core-intern/nm-core-internal.h" /*****************************************************************************/ diff --git a/src/core/devices/wifi/nm-device-iwd.c b/src/core/devices/wifi/nm-device-iwd.c index d0aae5a5dd..e8a5ccdfc3 100644 --- a/src/core/devices/wifi/nm-device-iwd.c +++ b/src/core/devices/wifi/nm-device-iwd.c @@ -55,7 +55,7 @@ typedef struct { CList aps_lst_head; NMWifiAP * current_ap; GCancellable * cancellable; - NMDeviceWifiCapabilities capabilities; + _NMDeviceWifiCapabilities capabilities; NMActRequestGetSecretsCallId *wifi_secrets_id; guint periodic_scan_id; guint periodic_update_id; @@ -265,7 +265,7 @@ ap_from_network(NMDeviceIwd *self, .bss_path = bss_path, .last_seen_msec = last_seen_msec, .bssid_valid = TRUE, - .mode = NM_802_11_MODE_INFRA, + .mode = _NM_802_11_MODE_INFRA, .rsn_flags = ap_security_flags_from_network_type(type), .ssid = ssid, .signal_percent = nm_wifi_utils_level_to_quality(signal / 100), @@ -801,7 +801,7 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * NMSettingWirelessSecurity *s_wireless_sec = nm_connection_get_setting_wireless_security(connection); - if (!(priv->capabilities & NM_WIFI_DEVICE_CAP_AP)) { + if (!(priv->capabilities & _NM_WIFI_DEVICE_CAP_AP)) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_INCOMPATIBLE, "device does not support Access Point mode"); @@ -819,7 +819,7 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * NMSettingWirelessSecurity *s_wireless_sec = nm_connection_get_setting_wireless_security(connection); - if (!(priv->capabilities & NM_WIFI_DEVICE_CAP_ADHOC)) { + if (!(priv->capabilities & _NM_WIFI_DEVICE_CAP_ADHOC)) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_INCOMPATIBLE, "device does not support Ad-Hoc mode"); @@ -2610,9 +2610,9 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) switch (prop_id) { case PROP_MODE: if (!priv->current_ap) - g_value_set_uint(value, NM_802_11_MODE_UNKNOWN); + g_value_set_uint(value, _NM_802_11_MODE_UNKNOWN); else if (nm_wifi_ap_is_hotspot(priv->current_ap)) - g_value_set_uint(value, NM_802_11_MODE_AP); + g_value_set_uint(value, _NM_802_11_MODE_AP); else g_value_set_uint(value, nm_wifi_ap_get_mode(priv->current_ap)); @@ -3034,7 +3034,7 @@ nm_device_iwd_set_dbus_object(NMDeviceIwd *self, GDBusObject *object) GVariantIter * iter; const char * mode; gboolean powered; - NMDeviceWifiCapabilities capabilities; + _NMDeviceWifiCapabilities capabilities; if (!nm_g_object_ref_set(&priv->dbus_obj, object)) return; @@ -3096,14 +3096,14 @@ nm_device_iwd_set_dbus_object(NMDeviceIwd *self, GDBusObject *object) goto error; } - capabilities = NM_WIFI_DEVICE_CAP_CIPHER_CCMP | NM_WIFI_DEVICE_CAP_RSN; + capabilities = _NM_WIFI_DEVICE_CAP_CIPHER_CCMP | _NM_WIFI_DEVICE_CAP_RSN; g_variant_get(value, "as", &iter); while (g_variant_iter_next(iter, "&s", &mode)) { if (nm_streq(mode, "ap")) - capabilities |= NM_WIFI_DEVICE_CAP_AP; + capabilities |= _NM_WIFI_DEVICE_CAP_AP; else if (nm_streq(mode, "ad-hoc")) - capabilities |= NM_WIFI_DEVICE_CAP_ADHOC; + capabilities |= _NM_WIFI_DEVICE_CAP_ADHOC; } g_variant_iter_free(iter); @@ -3452,9 +3452,9 @@ nm_device_iwd_class_init(NMDeviceIwdClass *klass) obj_properties[PROP_MODE] = g_param_spec_uint(NM_DEVICE_IWD_MODE, "", "", - NM_802_11_MODE_UNKNOWN, - NM_802_11_MODE_AP, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_UNKNOWN, + _NM_802_11_MODE_AP, + _NM_802_11_MODE_INFRA, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); obj_properties[PROP_BITRATE] = g_param_spec_uint(NM_DEVICE_IWD_BITRATE, @@ -3485,7 +3485,7 @@ nm_device_iwd_class_init(NMDeviceIwdClass *klass) "", 0, G_MAXUINT32, - NM_WIFI_DEVICE_CAP_NONE, + _NM_WIFI_DEVICE_CAP_NONE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); obj_properties[PROP_SCANNING] = g_param_spec_boolean(NM_DEVICE_IWD_SCANNING, diff --git a/src/core/devices/wifi/nm-device-olpc-mesh.c b/src/core/devices/wifi/nm-device-olpc-mesh.c index af83c4a334..4ec8b077fb 100644 --- a/src/core/devices/wifi/nm-device-olpc-mesh.c +++ b/src/core/devices/wifi/nm-device-olpc-mesh.c @@ -28,7 +28,7 @@ #include "nm-setting-connection.h" #include "nm-setting-olpc-mesh.h" #include "nm-manager.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #define _NMLOG_DEVICE_TYPE NMDeviceOlpcMesh #include "devices/nm-device-logging.h" diff --git a/src/core/devices/wifi/nm-device-wifi-p2p.c b/src/core/devices/wifi/nm-device-wifi-p2p.c index 0a0955deda..7ff0434ca9 100644 --- a/src/core/devices/wifi/nm-device-wifi-p2p.c +++ b/src/core/devices/wifi/nm-device-wifi-p2p.c @@ -23,8 +23,8 @@ #include "nm-setting-wifi-p2p.h" #include "nm-utils.h" #include "nm-wifi-p2p-peer.h" -#include "platform/nm-platform.h" -#include "platform/nmp-object.h" +#include "libnm-platform/nm-platform.h" +#include "libnm-platform/nmp-object.h" #include "settings/nm-settings.h" #define _NMLOG_DEVICE_TYPE NMDeviceWifiP2P diff --git a/src/core/devices/wifi/nm-device-wifi.c b/src/core/devices/wifi/nm-device-wifi.c index 04fa75f707..6eed0302a2 100644 --- a/src/core/devices/wifi/nm-device-wifi.c +++ b/src/core/devices/wifi/nm-device-wifi.c @@ -33,7 +33,7 @@ #include "nm-setting-ip4-config.h" #include "nm-ip4-config.h" #include "nm-setting-ip6-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-auth-utils.h" #include "settings/nm-settings-connection.h" #include "settings/nm-settings.h" @@ -114,11 +114,11 @@ typedef struct { guint wps_timeout_id; guint sup_timeout_id; /* supplicant association timeout */ - NMDeviceWifiCapabilities capabilities; - NMSettingWirelessWakeOnWLan wowlan_restore; + _NMDeviceWifiCapabilities capabilities; + _NMSettingWirelessWakeOnWLan wowlan_restore; NMDeviceWifiP2P *p2p_device; - NM80211Mode mode; + _NM80211Mode mode; guint32 failed_iface_count; gint32 hw_addr_scan_expire; @@ -487,7 +487,7 @@ _scan_notify_allowed(NMDeviceWifi *self, NMTernary do_kickoff) if (!c_list_is_empty(&priv->scanning_prohibited_lst_head)) { /* something prohibits scanning. */ - } else if (NM_IN_SET(priv->mode, NM_802_11_MODE_ADHOC, NM_802_11_MODE_AP)) { + } else if (NM_IN_SET(priv->mode, _NM_802_11_MODE_ADHOC, _NM_802_11_MODE_AP)) { /* Don't scan when a an AP or Ad-Hoc connection is active as it will * disrupt connected clients or peers. */ } else if (NM_IN_SET(state, NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_FAILED)) { @@ -678,7 +678,7 @@ update_seen_bssids_cache(NMDeviceWifi *self, NMWifiAP *ap) return; /* Don't cache the BSSID for Ad-Hoc APs */ - if (nm_wifi_ap_get_mode(ap) != NM_802_11_MODE_INFRA) + if (nm_wifi_ap_get_mode(ap) != _NM_802_11_MODE_INFRA) return; if (nm_device_get_state(NM_DEVICE(self)) == NM_DEVICE_STATE_ACTIVATED @@ -712,10 +712,11 @@ set_current_ap(NMDeviceWifi *self, NMWifiAP *new_ap, gboolean recheck_available_ priv->current_ap = NULL; if (old_ap) { - NM80211Mode mode = nm_wifi_ap_get_mode(old_ap); + _NM80211Mode mode = nm_wifi_ap_get_mode(old_ap); /* Remove any AP from the internal list if it was created by NM or isn't known to the supplicant */ - if (NM_IN_SET(mode, NM_802_11_MODE_ADHOC, NM_802_11_MODE_AP) || nm_wifi_ap_get_fake(old_ap)) + if (NM_IN_SET(mode, _NM_802_11_MODE_ADHOC, _NM_802_11_MODE_AP) + || nm_wifi_ap_get_fake(old_ap)) ap_add_remove(self, FALSE, old_ap, recheck_available_connections); g_object_unref(old_ap); } @@ -750,7 +751,7 @@ periodic_update(NMDeviceWifi *self) return; } - if (priv->mode == NM_802_11_MODE_AP) { + if (priv->mode == _NM_802_11_MODE_AP) { /* In AP mode we currently have nothing to do. */ return; } @@ -845,14 +846,14 @@ remove_all_aps(NMDeviceWifi *self) static gboolean wake_on_wlan_restore(NMDeviceWifi *self) { - NMDeviceWifiPrivate * priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMSettingWirelessWakeOnWLan w; + NMDeviceWifiPrivate * priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + _NMSettingWirelessWakeOnWLan w; w = priv->wowlan_restore; - if (w == NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE) + if (w == _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE) return TRUE; - priv->wowlan_restore = NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE; + priv->wowlan_restore = _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE; return nm_platform_wifi_set_wake_on_wlan(NM_PLATFORM_GET, nm_device_get_ifindex(NM_DEVICE(self)), w); @@ -937,14 +938,14 @@ deactivate(NMDevice *device) * (usually older ones) don't scan well in adhoc mode. */ if (nm_platform_wifi_get_mode(nm_device_get_platform(device), ifindex) - != NM_802_11_MODE_INFRA) { + != _NM_802_11_MODE_INFRA) { nm_device_take_down(NM_DEVICE(self), TRUE); - nm_platform_wifi_set_mode(nm_device_get_platform(device), ifindex, NM_802_11_MODE_INFRA); + nm_platform_wifi_set_mode(nm_device_get_platform(device), ifindex, _NM_802_11_MODE_INFRA); nm_device_bring_up(NM_DEVICE(self), TRUE, NULL); } - if (priv->mode != NM_802_11_MODE_INFRA) { - priv->mode = NM_802_11_MODE_INFRA; + if (priv->mode != _NM_802_11_MODE_INFRA) { + priv->mode = _NM_802_11_MODE_INFRA; _notify(self, PROP_MODE); } @@ -1010,14 +1011,14 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * /* Early exit if supplicant or device doesn't support requested mode */ mode = nm_setting_wireless_get_mode(s_wireless); if (g_strcmp0(mode, NM_SETTING_WIRELESS_MODE_ADHOC) == 0) { - if (!(priv->capabilities & NM_WIFI_DEVICE_CAP_ADHOC)) { + if (!(priv->capabilities & _NM_WIFI_DEVICE_CAP_ADHOC)) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, "the device does not support Ad-Hoc networks"); return FALSE; } } else if (g_strcmp0(mode, NM_SETTING_WIRELESS_MODE_AP) == 0) { - if (!(priv->capabilities & NM_WIFI_DEVICE_CAP_AP)) { + if (!(priv->capabilities & _NM_WIFI_DEVICE_CAP_AP)) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, "the device does not support Access Point mode"); @@ -1034,7 +1035,7 @@ check_connection_compatible(NMDevice *device, NMConnection *connection, GError * } } } else if (g_strcmp0(mode, NM_SETTING_WIRELESS_MODE_MESH) == 0) { - if (!(priv->capabilities & NM_WIFI_DEVICE_CAP_MESH)) { + if (!(priv->capabilities & _NM_WIFI_DEVICE_CAP_MESH)) { nm_utils_error_set_literal(error, NM_UTILS_ERROR_CONNECTION_AVAILABLE_TEMPORARY, "the device does not support Mesh mode"); @@ -1822,7 +1823,7 @@ _scan_kickoff(NMDeviceWifi *self) strv = g_new(char *, ssids->len + 1u); for (i = 0; i < ssids->len; i++) - strv[i] = _nm_utils_ssid_to_string(ssids->pdata[i]); + strv[i] = _nm_utils_ssid_to_string_gbytes(ssids->pdata[i]); strv[i] = NULL; nm_assert(ssids->len > 0); @@ -1986,19 +1987,19 @@ supplicant_iface_bss_changed_cb(NMSupplicantInterface *iface, /* Let the manager try to fill in the SSID from seen-bssids lists */ ssid = nm_wifi_ap_get_ssid(ap); - if (!ssid || _nm_utils_is_empty_ssid(ssid)) { + if (!ssid || _nm_utils_is_empty_ssid_gbytes(ssid)) { /* Try to fill the SSID from the AP database */ try_fill_ssid_for_hidden_ap(self, ap); ssid = nm_wifi_ap_get_ssid(ap); - if (ssid && !_nm_utils_is_empty_ssid(ssid)) { + if (ssid && !_nm_utils_is_empty_ssid_gbytes(ssid)) { gs_free char *s = NULL; /* Yay, matched it, no longer treat as hidden */ _LOGD(LOGD_WIFI, "matched hidden AP %s => %s", nm_wifi_ap_get_address(ap), - (s = _nm_utils_ssid_to_string(ssid))); + (s = _nm_utils_ssid_to_string_gbytes(ssid))); } else { /* Didn't have an entry for this AP in the database */ _LOGD(LOGD_WIFI, "failed to match hidden AP %s", nm_wifi_ap_get_address(ap)); @@ -2481,9 +2482,9 @@ supplicant_iface_state(NMDeviceWifi * self, _LOGI(LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi) Stage 2 of 5 (Device Configure) successful. %s %s", - priv->mode == NM_802_11_MODE_AP ? "Started Wi-Fi Hotspot" - : "Connected to wireless network", - (ssid_str = _nm_utils_ssid_to_string(ssid))); + priv->mode == _NM_802_11_MODE_AP ? "Started Wi-Fi Hotspot" + : "Connected to wireless network", + (ssid_str = _nm_utils_ssid_to_string_gbytes(ssid))); nm_device_activate_schedule_stage3_ip_config_start(device); } else if (devstate == NM_DEVICE_STATE_ACTIVATED) periodic_update(self); @@ -2599,9 +2600,9 @@ supplicant_iface_notify_current_bss(NMSupplicantInterface *iface, _LOGD(LOGD_WIFI, "roamed from BSSID %s (%s) to %s (%s)", old_bssid ?: "(none)", - (old_ssid_s = _nm_utils_ssid_to_string(old_ssid)), + (old_ssid_s = _nm_utils_ssid_to_string_gbytes(old_ssid)), new_bssid ?: "(none)", - (new_ssid_s = _nm_utils_ssid_to_string(new_ssid))); + (new_ssid_s = _nm_utils_ssid_to_string_gbytes(new_ssid))); if (new_bssid) { /* The new AP could be in a different layer 3 network @@ -2790,21 +2791,21 @@ supplicant_connection_timeout_cb(gpointer user_data) connection = nm_act_request_get_applied_connection(req); g_assert(connection); - if (NM_IN_SET(priv->mode, NM_802_11_MODE_ADHOC, NM_802_11_MODE_MESH, NM_802_11_MODE_AP)) { + if (NM_IN_SET(priv->mode, _NM_802_11_MODE_ADHOC, _NM_802_11_MODE_MESH, _NM_802_11_MODE_AP)) { /* In Ad-Hoc and AP modes there's nothing to check the encryption key * (if any), so supplicant timeouts here are almost certainly the wifi * driver being really stupid. */ _LOGW(LOGD_DEVICE | LOGD_WIFI, "Activation: (wifi) %s network creation took too long, failing activation", - priv->mode == NM_802_11_MODE_ADHOC ? "Ad-Hoc" : "Hotspot"); + priv->mode == _NM_802_11_MODE_ADHOC ? "Ad-Hoc" : "Hotspot"); nm_device_state_changed(device, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT); return FALSE; } - g_assert(priv->mode == NM_802_11_MODE_INFRA); + g_assert(priv->mode == _NM_802_11_MODE_INFRA); if (priv->ssid_found && nm_connection_get_setting_wireless_security(connection)) { guint64 timestamp = 0; @@ -2956,9 +2957,10 @@ error: static gboolean wake_on_wlan_enable(NMDeviceWifi *self) { - NMDeviceWifiPrivate * priv = NM_DEVICE_WIFI_GET_PRIVATE(self); - NMSettingWirelessWakeOnWLan wowl; - NMSettingWireless * s_wireless; + NMDeviceWifiPrivate * priv = NM_DEVICE_WIFI_GET_PRIVATE(self); + NMSettingWirelessWakeOnWLan wowl; + _NMSettingWirelessWakeOnWLan wowl2; + NMSettingWireless * s_wireless; s_wireless = nm_device_get_applied_setting(NM_DEVICE(self), NM_TYPE_SETTING_WIRELESS); if (s_wireless) { @@ -2990,9 +2992,11 @@ wake_on_wlan_enable(NMDeviceWifi *self) goto found; wowl = NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE; + found: - if (wowl == NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE) { - priv->wowlan_restore = wowl; + wowl2 = _NM_SETTING_WIRELESS_WAKE_ON_WLAN_CAST(wowl); + if (wowl2 == _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE) { + priv->wowlan_restore = wowl2; return TRUE; } @@ -3001,7 +3005,7 @@ found: return nm_platform_wifi_set_wake_on_wlan(NM_PLATFORM_GET, nm_device_get_ifindex(NM_DEVICE(self)), - wowl); + wowl2); } static NMActStageReturn @@ -3030,16 +3034,16 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) mode = nm_setting_wireless_get_mode(s_wireless); if (g_strcmp0(mode, NM_SETTING_WIRELESS_MODE_INFRA) == 0) - priv->mode = NM_802_11_MODE_INFRA; + priv->mode = _NM_802_11_MODE_INFRA; else if (g_strcmp0(mode, NM_SETTING_WIRELESS_MODE_ADHOC) == 0) - priv->mode = NM_802_11_MODE_ADHOC; + priv->mode = _NM_802_11_MODE_ADHOC; else if (g_strcmp0(mode, NM_SETTING_WIRELESS_MODE_AP) == 0) { - priv->mode = NM_802_11_MODE_AP; + priv->mode = _NM_802_11_MODE_AP; /* Scanning not done in AP mode; clear the scan list */ remove_all_aps(self); } else if (g_strcmp0(mode, NM_SETTING_WIRELESS_MODE_MESH) == 0) - priv->mode = NM_802_11_MODE_MESH; + priv->mode = _NM_802_11_MODE_MESH; _notify(self, PROP_MODE); /* expire the temporary MAC address used during scanning */ @@ -3052,7 +3056,7 @@ act_stage1_prepare(NMDevice *device, NMDeviceStateReason *out_failure_reason) } /* AP and Mesh modes never use a specific object or existing scanned AP */ - if (!NM_IN_SET(priv->mode, NM_802_11_MODE_AP, NM_802_11_MODE_MESH)) { + if (!NM_IN_SET(priv->mode, _NM_802_11_MODE_AP, _NM_802_11_MODE_MESH)) { ap_path = nm_active_connection_get_specific_object(NM_ACTIVE_CONNECTION(req)); ap = ap_path ? nm_wifi_ap_lookup_for_device(NM_DEVICE(self), ap_path) : NULL; } @@ -3154,7 +3158,7 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) NMDeviceWifi * self = NM_DEVICE_WIFI(device); NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE(self); gs_unref_object NMSupplicantConfig *config = NULL; - NM80211Mode ap_mode; + _NM80211Mode ap_mode; NMActRequest * req; NMWifiAP * ap; NMConnection * connection; @@ -3221,10 +3225,11 @@ act_stage2_config(NMDevice *device, NMDeviceStateReason *out_failure_reason) * if the user didn't specify one and we didn't find an AP that matched * the connection, just pick a frequency the device supports. */ - if (NM_IN_SET(ap_mode, NM_802_11_MODE_ADHOC, NM_802_11_MODE_MESH) || nm_wifi_ap_is_hotspot(ap)) + if (NM_IN_SET(ap_mode, _NM_802_11_MODE_ADHOC, _NM_802_11_MODE_MESH) + || nm_wifi_ap_is_hotspot(ap)) ensure_hotspot_frequency(self, s_wireless, ap); - if (ap_mode == NM_802_11_MODE_INFRA) + if (ap_mode == _NM_802_11_MODE_INFRA) set_powersave(device); /* Build up the supplicant configuration */ @@ -3341,7 +3346,7 @@ act_stage4_ip_config_timeout(NMDevice * device, s_ip = nm_connection_get_setting_ip_config(connection, addr_family); may_fail = nm_setting_ip_config_get_may_fail(s_ip); - if (priv->mode == NM_802_11_MODE_AP) + if (priv->mode == _NM_802_11_MODE_AP) goto call_parent; if (may_fail || !is_static_wep(connection)) { @@ -3694,8 +3699,8 @@ nm_device_wifi_init(NMDeviceWifi *self) priv->scan_last_request_started_at_msec = G_MININT64; priv->hidden_probe_scan_warn = TRUE; - priv->mode = NM_802_11_MODE_INFRA; - priv->wowlan_restore = NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE; + priv->mode = _NM_802_11_MODE_INFRA; + priv->wowlan_restore = _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE; } static void @@ -3706,7 +3711,7 @@ constructed(GObject *object) G_OBJECT_CLASS(nm_device_wifi_parent_class)->constructed(object); - if (priv->capabilities & NM_WIFI_DEVICE_CAP_AP) + if (priv->capabilities & _NM_WIFI_DEVICE_CAP_AP) _LOGI(LOGD_PLATFORM | LOGD_WIFI, "driver supports Access Point (AP) mode"); /* Connect to the supplicant manager */ @@ -3714,7 +3719,7 @@ constructed(GObject *object) } NMDevice * -nm_device_wifi_new(const char *iface, NMDeviceWifiCapabilities capabilities) +nm_device_wifi_new(const char *iface, _NMDeviceWifiCapabilities capabilities) { return g_object_new(NM_TYPE_DEVICE_WIFI, NM_DEVICE_IFACE, @@ -3822,9 +3827,9 @@ nm_device_wifi_class_init(NMDeviceWifiClass *klass) obj_properties[PROP_MODE] = g_param_spec_uint(NM_DEVICE_WIFI_MODE, "", "", - NM_802_11_MODE_UNKNOWN, - NM_802_11_MODE_AP, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_UNKNOWN, + _NM_802_11_MODE_AP, + _NM_802_11_MODE_INFRA, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); obj_properties[PROP_BITRATE] = g_param_spec_uint(NM_DEVICE_WIFI_BITRATE, @@ -3855,7 +3860,7 @@ nm_device_wifi_class_init(NMDeviceWifiClass *klass) "", 0, G_MAXUINT32, - NM_WIFI_DEVICE_CAP_NONE, + _NM_WIFI_DEVICE_CAP_NONE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); obj_properties[PROP_SCANNING] = g_param_spec_boolean(NM_DEVICE_WIFI_SCANNING, diff --git a/src/core/devices/wifi/nm-device-wifi.h b/src/core/devices/wifi/nm-device-wifi.h index d9e9038cc0..c7ff1a140a 100644 --- a/src/core/devices/wifi/nm-device-wifi.h +++ b/src/core/devices/wifi/nm-device-wifi.h @@ -33,7 +33,7 @@ typedef struct _NMDeviceWifiClass NMDeviceWifiClass; GType nm_device_wifi_get_type(void); -NMDevice *nm_device_wifi_new(const char *iface, NMDeviceWifiCapabilities capabilities); +NMDevice *nm_device_wifi_new(const char *iface, _NMDeviceWifiCapabilities capabilities); const CList *_nm_device_wifi_get_aps(NMDeviceWifi *self); diff --git a/src/core/devices/wifi/nm-wifi-ap.c b/src/core/devices/wifi/nm-wifi-ap.c index e07ea0afe4..883593f6a0 100644 --- a/src/core/devices/wifi/nm-wifi-ap.c +++ b/src/core/devices/wifi/nm-wifi-ap.c @@ -19,7 +19,7 @@ #include "nm-setting-wireless.h" #include "nm-utils.h" #include "nm-wifi-utils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "supplicant/nm-supplicant-interface.h" #define PROTO_WPA "wpa" @@ -41,12 +41,12 @@ NM_GOBJECT_PROPERTIES_DEFINE(NMWifiAP, struct _NMWifiAPPrivate { /* Scanned or cached values */ - GBytes * ssid; - char * address; - NM80211Mode mode; - guint8 strength; - guint32 freq; /* Frequency in MHz; ie 2412 (== 2.412 GHz) */ - guint32 max_bitrate; /* Maximum bitrate of the AP in Kbit/s (ie 54000 Kb/s == 54Mbit/s) */ + GBytes * ssid; + char * address; + _NM80211Mode mode; + guint8 strength; + guint32 freq; /* Frequency in MHz; ie 2412 (== 2.412 GHz) */ + guint32 max_bitrate; /* Maximum bitrate of the AP in Kbit/s (ie 54000 Kb/s == 54Mbit/s) */ gint64 last_seen_msec; /* Timestamp when the AP was seen lastly (in nm_utils_get_monotonic_timestamp_*() scale). @@ -191,24 +191,24 @@ nm_wifi_ap_set_address(NMWifiAP *ap, const char *addr) return nm_wifi_ap_set_address_bin(ap, &addr_buf); } -NM80211Mode +_NM80211Mode nm_wifi_ap_get_mode(NMWifiAP *ap) { - g_return_val_if_fail(NM_IS_WIFI_AP(ap), NM_802_11_MODE_UNKNOWN); + g_return_val_if_fail(NM_IS_WIFI_AP(ap), _NM_802_11_MODE_UNKNOWN); return NM_WIFI_AP_GET_PRIVATE(ap)->mode; } static gboolean -nm_wifi_ap_set_mode(NMWifiAP *ap, NM80211Mode mode) +nm_wifi_ap_set_mode(NMWifiAP *ap, _NM80211Mode mode) { NMWifiAPPrivate *priv = NM_WIFI_AP_GET_PRIVATE(ap); nm_assert(NM_IN_SET(mode, - NM_802_11_MODE_UNKNOWN, - NM_802_11_MODE_ADHOC, - NM_802_11_MODE_INFRA, - NM_802_11_MODE_MESH)); + _NM_802_11_MODE_UNKNOWN, + _NM_802_11_MODE_ADHOC, + _NM_802_11_MODE_INFRA, + _NM_802_11_MODE_MESH)); if (priv->mode != mode) { priv->mode = mode; @@ -513,34 +513,35 @@ nm_wifi_ap_to_string(const NMWifiAP *self, char *str_buf, gulong buf_len, gint64 nm_utils_get_monotonic_timestamp_msec_cached(&now_msec); - g_snprintf(str_buf, - buf_len, - "%17s %-35s [ %c %3u %3u%% %c%c %c%c W:%04X R:%04X ] %s sup:%s [nm:%s]", - priv->address ?: "(none)", - (ssid_to_free = _nm_utils_ssid_to_string(priv->ssid)), - (priv->mode == NM_802_11_MODE_ADHOC - ? '*' - : (priv->hotspot - ? '#' - : (priv->fake ? 'f' : (priv->mode == NM_802_11_MODE_MESH ? 'm' : 'a')))), - chan, - priv->strength, - priv->flags & NM_802_11_AP_FLAGS_PRIVACY ? 'P' : '_', - priv->metered ? 'M' : '_', - priv->flags & NM_802_11_AP_FLAGS_WPS ? 'W' : '_', - priv->flags & NM_802_11_AP_FLAGS_WPS_PIN - ? 'p' - : (priv->flags & NM_802_11_AP_FLAGS_WPS_PBC ? '#' : '_'), - priv->wpa_flags & 0xFFFF, - priv->rsn_flags & 0xFFFF, - priv->last_seen_msec != G_MININT64 - ? nm_sprintf_buf(str_buf_ts, - "%3u.%03us", - (guint)((now_msec - priv->last_seen_msec) / 1000), - (guint)((now_msec - priv->last_seen_msec) % 1000)) - : " ", - supplicant_id, - export_path); + g_snprintf( + str_buf, + buf_len, + "%17s %-35s [ %c %3u %3u%% %c%c %c%c W:%04X R:%04X ] %s sup:%s [nm:%s]", + priv->address ?: "(none)", + (ssid_to_free = _nm_utils_ssid_to_string_gbytes(priv->ssid)), + (priv->mode == _NM_802_11_MODE_ADHOC + ? '*' + : (priv->hotspot + ? '#' + : (priv->fake ? 'f' : (priv->mode == _NM_802_11_MODE_MESH ? 'm' : 'a')))), + chan, + priv->strength, + priv->flags & NM_802_11_AP_FLAGS_PRIVACY ? 'P' : '_', + priv->metered ? 'M' : '_', + priv->flags & NM_802_11_AP_FLAGS_WPS ? 'W' : '_', + priv->flags & NM_802_11_AP_FLAGS_WPS_PIN + ? 'p' + : (priv->flags & NM_802_11_AP_FLAGS_WPS_PBC ? '#' : '_'), + priv->wpa_flags & 0xFFFF, + priv->rsn_flags & 0xFFFF, + priv->last_seen_msec != G_MININT64 + ? nm_sprintf_buf(str_buf_ts, + "%3u.%03us", + (guint)((now_msec - priv->last_seen_msec) / 1000), + (guint)((now_msec - priv->last_seen_msec) % 1000)) + : " ", + supplicant_id, + export_path); return str_buf; } @@ -589,13 +590,13 @@ nm_wifi_ap_check_compatible(NMWifiAP *self, NMConnection *connection) mode = nm_setting_wireless_get_mode(s_wireless); if (mode) { - if (!strcmp(mode, "infrastructure") && (priv->mode != NM_802_11_MODE_INFRA)) + if (!strcmp(mode, "infrastructure") && (priv->mode != _NM_802_11_MODE_INFRA)) return FALSE; - if (!strcmp(mode, "adhoc") && (priv->mode != NM_802_11_MODE_ADHOC)) + if (!strcmp(mode, "adhoc") && (priv->mode != _NM_802_11_MODE_ADHOC)) return FALSE; - if (!strcmp(mode, "ap") && (priv->mode != NM_802_11_MODE_INFRA || priv->hotspot != TRUE)) + if (!strcmp(mode, "ap") && (priv->mode != _NM_802_11_MODE_INFRA || priv->hotspot != TRUE)) return FALSE; - if (!strcmp(mode, "mesh") && (priv->mode != NM_802_11_MODE_MESH)) + if (!strcmp(mode, "mesh") && (priv->mode != _NM_802_11_MODE_MESH)) return FALSE; } @@ -624,7 +625,7 @@ nm_wifi_ap_check_compatible(NMWifiAP *self, NMConnection *connection) priv->flags, priv->wpa_flags, priv->rsn_flags, - priv->mode); + NM_802_11_MODE_CAST(priv->mode)); } gboolean @@ -713,7 +714,7 @@ nm_wifi_ap_init(NMWifiAP *self) c_list_init(&self->aps_lst); - priv->mode = NM_802_11_MODE_INFRA; + priv->mode = _NM_802_11_MODE_INFRA; priv->flags = NM_802_11_AP_FLAGS_NONE; priv->wpa_flags = NM_802_11_AP_SEC_NONE; priv->rsn_flags = NM_802_11_AP_SEC_NONE; @@ -758,19 +759,19 @@ nm_wifi_ap_new_fake_from_connection(NMConnection *connection) mode = nm_setting_wireless_get_mode(s_wireless); if (mode) { if (!strcmp(mode, "infrastructure")) - nm_wifi_ap_set_mode(ap, NM_802_11_MODE_INFRA); + nm_wifi_ap_set_mode(ap, _NM_802_11_MODE_INFRA); else if (!strcmp(mode, "adhoc")) { - nm_wifi_ap_set_mode(ap, NM_802_11_MODE_ADHOC); + nm_wifi_ap_set_mode(ap, _NM_802_11_MODE_ADHOC); adhoc = TRUE; } else if (!strcmp(mode, "mesh")) - nm_wifi_ap_set_mode(ap, NM_802_11_MODE_MESH); + nm_wifi_ap_set_mode(ap, _NM_802_11_MODE_MESH); else if (!strcmp(mode, "ap")) { - nm_wifi_ap_set_mode(ap, NM_802_11_MODE_INFRA); + nm_wifi_ap_set_mode(ap, _NM_802_11_MODE_INFRA); NM_WIFI_AP_GET_PRIVATE(ap)->hotspot = TRUE; } else goto error; } else { - nm_wifi_ap_set_mode(ap, NM_802_11_MODE_INFRA); + nm_wifi_ap_set_mode(ap, _NM_802_11_MODE_INFRA); } band = nm_setting_wireless_get_band(s_wireless); @@ -955,9 +956,9 @@ nm_wifi_ap_class_init(NMWifiAPClass *ap_class) obj_properties[PROP_MODE] = g_param_spec_uint(NM_WIFI_AP_MODE, "", "", - NM_802_11_MODE_ADHOC, - NM_802_11_MODE_INFRA, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_ADHOC, + _NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); obj_properties[PROP_MAX_BITRATE] = g_param_spec_uint(NM_WIFI_AP_MAX_BITRATE, diff --git a/src/core/devices/wifi/nm-wifi-ap.h b/src/core/devices/wifi/nm-wifi-ap.h index bdd72415f1..bffd28a8d5 100644 --- a/src/core/devices/wifi/nm-wifi-ap.h +++ b/src/core/devices/wifi/nm-wifi-ap.h @@ -10,6 +10,7 @@ #include "nm-dbus-object.h" #include "nm-dbus-interface.h" #include "nm-connection.h" +#include "libnm-base/nm-base.h" #define NM_TYPE_WIFI_AP (nm_wifi_ap_get_type()) #define NM_WIFI_AP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_WIFI_AP, NMWifiAP)) @@ -69,7 +70,7 @@ gboolean nm_wifi_ap_set_ssid(NMWifiAP *ap, GBytes *ssid); const char * nm_wifi_ap_get_address(const NMWifiAP *ap); gboolean nm_wifi_ap_set_address(NMWifiAP *ap, const char *addr); gboolean nm_wifi_ap_set_address_bin(NMWifiAP *ap, const NMEtherAddr *addr); -NM80211Mode nm_wifi_ap_get_mode(NMWifiAP *ap); +_NM80211Mode nm_wifi_ap_get_mode(NMWifiAP *ap); gboolean nm_wifi_ap_is_hotspot(NMWifiAP *ap); gint8 nm_wifi_ap_get_strength(NMWifiAP *ap); gboolean nm_wifi_ap_set_strength(NMWifiAP *ap, gint8 strength); diff --git a/src/core/devices/wifi/nm-wifi-factory.c b/src/core/devices/wifi/nm-wifi-factory.c index 40375e1c1f..c7be7ab8cb 100644 --- a/src/core/devices/wifi/nm-wifi-factory.c +++ b/src/core/devices/wifi/nm-wifi-factory.c @@ -15,7 +15,7 @@ #include "nm-device-olpc-mesh.h" #include "nm-device-iwd.h" #include "settings/nm-settings-connection.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-config.h" /*****************************************************************************/ @@ -97,9 +97,9 @@ create_device(NMDeviceFactory * factory, NM_PRINT_FMT_QUOTE_STRING(backend), WITH_IWD ? " (iwd support enabled)" : ""); if (!backend || !g_ascii_strcasecmp(backend, "wpa_supplicant")) { - NMDevice * device; - NMDeviceWifiCapabilities capabilities; - NM80211Mode mode; + NMDevice * device; + _NMDeviceWifiCapabilities capabilities; + _NM80211Mode mode; if (!nm_platform_wifi_get_capabilities(NM_PLATFORM_GET, plink->ifindex, &capabilities)) { nm_log_warn(LOGD_PLATFORM | LOGD_WIFI, @@ -114,7 +114,7 @@ create_device(NMDeviceFactory * factory, * them if/when they change to a handled type. */ mode = nm_platform_wifi_get_mode(NM_PLATFORM_GET, plink->ifindex); - if (mode == NM_802_11_MODE_UNKNOWN) { + if (mode == _NM_802_11_MODE_UNKNOWN) { *out_ignore = TRUE; return NULL; } diff --git a/src/core/devices/wifi/nm-wifi-p2p-peer.c b/src/core/devices/wifi/nm-wifi-p2p-peer.c index 6b04204cb1..228a26bf16 100644 --- a/src/core/devices/wifi/nm-wifi-p2p-peer.c +++ b/src/core/devices/wifi/nm-wifi-p2p-peer.c @@ -18,7 +18,7 @@ #include "nm-setting-wireless.h" #include "nm-utils.h" #include "nm-wifi-utils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "supplicant/nm-supplicant-types.h" /*****************************************************************************/ diff --git a/src/core/devices/wifi/nm-wifi-utils.c b/src/core/devices/wifi/nm-wifi-utils.c index 56a324387f..bf34fe16ad 100644 --- a/src/core/devices/wifi/nm-wifi-utils.c +++ b/src/core/devices/wifi/nm-wifi-utils.c @@ -526,7 +526,7 @@ verify_adhoc(NMSettingWirelessSecurity *s_wsec, gboolean nm_wifi_utils_complete_connection(GBytes * ap_ssid, const char * bssid, - NM80211Mode ap_mode, + _NM80211Mode ap_mode, guint32 ap_freq, guint32 ap_flags, guint32 ap_wpa_flags, @@ -575,14 +575,14 @@ nm_wifi_utils_complete_connection(GBytes * ap_ssid, /* Make sure the supplied mode matches the AP's */ if (!strcmp(mode, NM_SETTING_WIRELESS_MODE_INFRA) || !strcmp(mode, NM_SETTING_WIRELESS_MODE_AP)) { - if (ap_mode == NM_802_11_MODE_INFRA) + if (ap_mode == _NM_802_11_MODE_INFRA) valid = TRUE; } else if (!strcmp(mode, NM_SETTING_WIRELESS_MODE_ADHOC)) { - if (ap_mode == NM_802_11_MODE_ADHOC) + if (ap_mode == _NM_802_11_MODE_ADHOC) valid = TRUE; adhoc = TRUE; } else if (!strcmp(mode, NM_SETTING_WIRELESS_MODE_MESH)) { - if (ap_mode == NM_802_11_MODE_MESH) + if (ap_mode == _NM_802_11_MODE_MESH) valid = TRUE; mesh = TRUE; } @@ -600,10 +600,10 @@ nm_wifi_utils_complete_connection(GBytes * ap_ssid, } } else { mode = NM_SETTING_WIRELESS_MODE_INFRA; - if (ap_mode == NM_802_11_MODE_ADHOC) { + if (ap_mode == _NM_802_11_MODE_ADHOC) { mode = NM_SETTING_WIRELESS_MODE_ADHOC; adhoc = TRUE; - } else if (ap_mode == NM_802_11_MODE_MESH) { + } else if (ap_mode == _NM_802_11_MODE_MESH) { mode = NM_SETTING_WIRELESS_MODE_MESH; mesh = TRUE; } diff --git a/src/core/devices/wifi/nm-wifi-utils.h b/src/core/devices/wifi/nm-wifi-utils.h index 474bea41ce..105c1450b5 100644 --- a/src/core/devices/wifi/nm-wifi-utils.h +++ b/src/core/devices/wifi/nm-wifi-utils.h @@ -11,6 +11,7 @@ #include "nm-setting-wireless.h" #include "nm-setting-wireless-security.h" #include "nm-setting-8021x.h" +#include "libnm-base/nm-base.h" typedef enum { NM_IWD_NETWORK_SECURITY_OPEN, @@ -21,7 +22,7 @@ typedef enum { gboolean nm_wifi_utils_complete_connection(GBytes * ssid, const char * bssid, - NM80211Mode mode, + _NM80211Mode mode, guint32 ap_freq, guint32 flags, guint32 wpa_flags, diff --git a/src/core/devices/wifi/tests/test-devices-wifi.c b/src/core/devices/wifi/tests/test-devices-wifi.c index 693bc546da..dc278c947b 100644 --- a/src/core/devices/wifi/tests/test-devices-wifi.c +++ b/src/core/devices/wifi/tests/test-devices-wifi.c @@ -49,7 +49,7 @@ static gboolean complete_connection(const char * ssid, const char * bssid, - NM80211Mode mode, + _NM80211Mode mode, guint32 flags, guint32 wpa_flags, guint32 rsn_flags, @@ -197,7 +197,7 @@ fill_8021x(NMConnection *connection, const KeyData items[]) } static NMConnection * -create_basic(const char *ssid, const char *bssid, NM80211Mode mode) +create_basic(const char *ssid, const char *bssid, _NM80211Mode mode) { NMConnection * connection; NMSettingWireless *s_wifi = NULL; @@ -217,9 +217,9 @@ create_basic(const char *ssid, const char *bssid, NM80211Mode mode) if (bssid) g_object_set(G_OBJECT(s_wifi), NM_SETTING_WIRELESS_BSSID, bssid, NULL); - if (mode == NM_802_11_MODE_INFRA) + if (mode == _NM_802_11_MODE_INFRA) g_object_set(G_OBJECT(s_wifi), NM_SETTING_WIRELESS_MODE, "infrastructure", NULL); - else if (mode == NM_802_11_MODE_ADHOC) + else if (mode == _NM_802_11_MODE_ADHOC) g_object_set(G_OBJECT(s_wifi), NM_SETTING_WIRELESS_MODE, "adhoc", NULL); else g_assert_not_reached(); @@ -241,14 +241,14 @@ test_lock_bssid(void) src = nm_simple_connection_new(); success = complete_connection(ssid, bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_NONE, NM_802_11_AP_SEC_NONE, NM_802_11_AP_SEC_NONE, TRUE, src, &error); - expected = create_basic(ssid, bssid, NM_802_11_MODE_INFRA); + expected = create_basic(ssid, bssid, _NM_802_11_MODE_INFRA); COMPARE(src, expected, success, error, 0, 0); g_object_unref(src); @@ -273,14 +273,14 @@ test_open_ap_empty_connection(void) src = nm_simple_connection_new(); success = complete_connection(ssid, bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_NONE, NM_802_11_AP_SEC_NONE, NM_802_11_AP_SEC_NONE, FALSE, src, &error); - expected = create_basic(ssid, NULL, NM_802_11_MODE_INFRA); + expected = create_basic(ssid, NULL, _NM_802_11_MODE_INFRA); COMPARE(src, expected, success, error, 0, 0); g_object_unref(src); @@ -311,7 +311,7 @@ test_open_ap_leap_connection_1(gconstpointer add_wifi) success = complete_connection("blahblah", bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_NONE, NM_802_11_AP_SEC_NONE, NM_802_11_AP_SEC_NONE, @@ -345,7 +345,7 @@ test_open_ap_leap_connection_2(void) success = complete_connection("blahblah", bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_NONE, NM_802_11_AP_SEC_NONE, NM_802_11_AP_SEC_NONE, @@ -383,7 +383,7 @@ test_open_ap_wep_connection(gconstpointer add_wifi) fill_wsec(src, src_wsec); success = complete_connection("blahblah", bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_NONE, NM_802_11_AP_SEC_NONE, NM_802_11_AP_SEC_NONE, @@ -427,7 +427,7 @@ test_ap_wpa_psk_connection_base(const char * key_mgmt, fill_wsec(src, both_wsec); success = complete_connection(ssid, bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, flags, wpa_flags, rsn_flags, @@ -553,7 +553,7 @@ test_ap_wpa_eap_connection_base(const char *key_mgmt, fill_8021x(src, src_empty); success = complete_connection("blahblah", bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, flags, wpa_flags, rsn_flags, @@ -751,7 +751,7 @@ test_priv_ap_empty_connection(void) src = nm_simple_connection_new(); success = complete_connection(ssid, bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY, NM_802_11_AP_SEC_NONE, NM_802_11_AP_SEC_NONE, @@ -760,7 +760,7 @@ test_priv_ap_empty_connection(void) &error); /* Static WEP connection expected */ - expected = create_basic(ssid, NULL, NM_802_11_MODE_INFRA); + expected = create_basic(ssid, NULL, _NM_802_11_MODE_INFRA); fill_wsec(expected, exp_wsec); COMPARE(src, expected, success, error, 0, 0); @@ -798,7 +798,7 @@ test_priv_ap_leap_connection_1(gconstpointer add_wifi) fill_wsec(src, src_wsec); success = complete_connection(ssid, bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY, NM_802_11_AP_SEC_NONE, NM_802_11_AP_SEC_NONE, @@ -809,7 +809,7 @@ test_priv_ap_leap_connection_1(gconstpointer add_wifi) * there's no way to determine from the AP's beacon whether it's static WEP, * dynamic WEP, or LEAP. */ - expected = create_basic(ssid, NULL, NM_802_11_MODE_INFRA); + expected = create_basic(ssid, NULL, _NM_802_11_MODE_INFRA); fill_wsec(expected, exp_wsec); COMPARE(src, expected, success, error, 0, 0); @@ -840,7 +840,7 @@ test_priv_ap_leap_connection_2(void) fill_wsec(src, src_wsec); success = complete_connection("blahblah", bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY, NM_802_11_AP_SEC_NONE, NM_802_11_AP_SEC_NONE, @@ -885,7 +885,7 @@ test_priv_ap_dynamic_wep_1(void) fill_8021x(src, both_8021x); success = complete_connection(ssid, bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY, NM_802_11_AP_SEC_NONE, NM_802_11_AP_SEC_NONE, @@ -894,7 +894,7 @@ test_priv_ap_dynamic_wep_1(void) &error); /* We expect a completed Dynamic WEP connection */ - expected = create_basic(ssid, NULL, NM_802_11_MODE_INFRA); + expected = create_basic(ssid, NULL, _NM_802_11_MODE_INFRA); fill_wsec(expected, exp_wsec); fill_8021x(expected, both_8021x); COMPARE(src, expected, success, error, 0, 0); @@ -933,7 +933,7 @@ test_priv_ap_dynamic_wep_2(void) fill_8021x(src, both_8021x); success = complete_connection(ssid, bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY, NM_802_11_AP_SEC_NONE, NM_802_11_AP_SEC_NONE, @@ -942,7 +942,7 @@ test_priv_ap_dynamic_wep_2(void) &error); /* We expect a completed Dynamic WEP connection */ - expected = create_basic(ssid, NULL, NM_802_11_MODE_INFRA); + expected = create_basic(ssid, NULL, _NM_802_11_MODE_INFRA); fill_wsec(expected, exp_wsec); fill_8021x(expected, both_8021x); COMPARE(src, expected, success, error, 0, 0); @@ -976,7 +976,7 @@ test_priv_ap_dynamic_wep_3(void) fill_8021x(src, src_8021x); success = complete_connection("blahblah", bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY, NM_802_11_AP_SEC_NONE, NM_802_11_AP_SEC_NONE, @@ -1102,7 +1102,7 @@ test_wpa_ap_empty_connection(gconstpointer data) src = nm_simple_connection_new(); success = complete_connection(ssid, bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY, wpa_flags_for_idx(idx), rsn_flags_for_idx(idx), @@ -1111,7 +1111,7 @@ test_wpa_ap_empty_connection(gconstpointer data) &error); /* WPA connection expected */ - expected = create_basic(ssid, NULL, NM_802_11_MODE_INFRA); + expected = create_basic(ssid, NULL, _NM_802_11_MODE_INFRA); fill_wsec(expected, exp_wsec); COMPARE(src, expected, success, error, 0, 0); @@ -1144,7 +1144,7 @@ test_wpa_ap_leap_connection_1(gconstpointer data) fill_wsec(src, src_wsec); success = complete_connection(ssid, bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY, wpa_flags_for_idx(idx), rsn_flags_for_idx(idx), @@ -1180,7 +1180,7 @@ test_wpa_ap_leap_connection_2(gconstpointer data) fill_wsec(src, src_wsec); success = complete_connection("blahblah", bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY, wpa_flags_for_idx(idx), rsn_flags_for_idx(idx), @@ -1214,7 +1214,7 @@ test_wpa_ap_dynamic_wep_connection(gconstpointer data) fill_wsec(src, src_wsec); success = complete_connection("blahblah", bssid, - NM_802_11_MODE_INFRA, + _NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY, wpa_flags_for_idx(idx), rsn_flags_for_idx(idx), diff --git a/src/core/devices/wwan/nm-modem-broadband.c b/src/core/devices/wwan/nm-modem-broadband.c index 51f7088899..0872a8a1f9 100644 --- a/src/core/devices/wwan/nm-modem-broadband.c +++ b/src/core/devices/wwan/nm-modem-broadband.c @@ -14,7 +14,7 @@ #include "libnm-core-intern/nm-core-internal.h" #include "NetworkManagerUtils.h" #include "devices/nm-device-private.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" diff --git a/src/core/devices/wwan/nm-modem-ofono.c b/src/core/devices/wwan/nm-modem-ofono.c index 6ca78292f0..74b2552a42 100644 --- a/src/core/devices/wwan/nm-modem-ofono.c +++ b/src/core/devices/wwan/nm-modem-ofono.c @@ -10,7 +10,7 @@ #include "libnm-core-intern/nm-core-internal.h" #include "devices/nm-device-private.h" #include "nm-modem.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-ip4-config.h" #define VARIANT_IS_OF_TYPE_BOOLEAN(v) \ diff --git a/src/core/devices/wwan/nm-modem.c b/src/core/devices/wwan/nm-modem.c index 68cd8f00b2..5366562670 100644 --- a/src/core/devices/wwan/nm-modem.c +++ b/src/core/devices/wwan/nm-modem.c @@ -13,7 +13,7 @@ #include <linux/rtnetlink.h> #include "libnm-core-intern/nm-core-internal.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-setting-connection.h" #include "NetworkManagerUtils.h" #include "devices/nm-device-private.h" diff --git a/src/core/devices/wwan/nm-wwan-factory.c b/src/core/devices/wwan/nm-wwan-factory.c index 5d2ce2b320..0d802ae1b4 100644 --- a/src/core/devices/wwan/nm-wwan-factory.c +++ b/src/core/devices/wwan/nm-wwan-factory.c @@ -12,7 +12,7 @@ #include "nm-setting-cdma.h" #include "nm-modem-manager.h" #include "nm-device-modem.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" /*****************************************************************************/ diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c index 1b5aa1060e..c128095aba 100644 --- a/src/core/dhcp/nm-dhcp-client.c +++ b/src/core/dhcp/nm-dhcp-client.c @@ -21,7 +21,7 @@ #include "nm-utils.h" #include "nm-dhcp-utils.h" #include "nm-dhcp-options.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-dhcp-client-logging.h" diff --git a/src/core/dhcp/nm-dhcp-dhclient-utils.c b/src/core/dhcp/nm-dhcp-dhclient-utils.c index 59682fb5ae..83de1c156d 100644 --- a/src/core/dhcp/nm-dhcp-dhclient-utils.c +++ b/src/core/dhcp/nm-dhcp-dhclient-utils.c @@ -17,7 +17,7 @@ #include "nm-dhcp-utils.h" #include "nm-ip4-config.h" #include "nm-utils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "NetworkManagerUtils.h" #define TIMEOUT_TAG "timeout " diff --git a/src/core/dhcp/nm-dhcp-manager.c b/src/core/dhcp/nm-dhcp-manager.c index 9be32e014c..a9ca5a00eb 100644 --- a/src/core/dhcp/nm-dhcp-manager.c +++ b/src/core/dhcp/nm-dhcp-manager.c @@ -252,7 +252,7 @@ client_start(NMDhcpManager * self, } hwaddr_len = g_bytes_get_size(hwaddr); - if (hwaddr_len == 0 || hwaddr_len > NM_UTILS_HWADDR_LEN_MAX) { + if (hwaddr_len == 0 || hwaddr_len > _NM_UTILS_HWADDR_LEN_MAX) { nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "invalid MAC address"); g_return_val_if_reached(NULL); } diff --git a/src/core/dhcp/nm-dhcp-nettools.c b/src/core/dhcp/nm-dhcp-nettools.c index 525fe752a9..dc9cbf58c4 100644 --- a/src/core/dhcp/nm-dhcp-nettools.c +++ b/src/core/dhcp/nm-dhcp-nettools.c @@ -23,7 +23,7 @@ #include "nm-dhcp-options.h" #include "nm-core-utils.h" #include "NetworkManagerUtils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-dhcp-client-logging.h" #include "n-dhcp4/src/n-dhcp4.h" #include "libnm-systemd-shared/nm-sd-utils-shared.h" diff --git a/src/core/dhcp/nm-dhcp-systemd.c b/src/core/dhcp/nm-dhcp-systemd.c index 827ebb77aa..de8e5142a4 100644 --- a/src/core/dhcp/nm-dhcp-systemd.c +++ b/src/core/dhcp/nm-dhcp-systemd.c @@ -21,7 +21,7 @@ #include "nm-dhcp-options.h" #include "nm-core-utils.h" #include "NetworkManagerUtils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-dhcp-client-logging.h" #include "systemd/nm-sd.h" #include "systemd/nm-sd-utils-dhcp.h" diff --git a/src/core/dhcp/nm-dhcp-utils.c b/src/core/dhcp/nm-dhcp-utils.c index 0233943de2..c3cbe610b1 100644 --- a/src/core/dhcp/nm-dhcp-utils.c +++ b/src/core/dhcp/nm-dhcp-utils.c @@ -17,7 +17,7 @@ #include "nm-utils.h" #include "nm-config.h" #include "NetworkManagerUtils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-dhcp-client-logging.h" #include "libnm-core-intern/nm-core-internal.h" diff --git a/src/core/dhcp/tests/test-dhcp-dhclient.c b/src/core/dhcp/tests/test-dhcp-dhclient.c index 24ea9a448f..e9a6209644 100644 --- a/src/core/dhcp/tests/test-dhcp-dhclient.c +++ b/src/core/dhcp/tests/test-dhcp-dhclient.c @@ -16,7 +16,7 @@ #include "dhcp/nm-dhcp-utils.h" #include "nm-utils.h" #include "nm-ip4-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-test-utils-core.h" diff --git a/src/core/dhcp/tests/test-dhcp-utils.c b/src/core/dhcp/tests/test-dhcp-utils.c index 9fd224e339..4d47e7e283 100644 --- a/src/core/dhcp/tests/test-dhcp-utils.c +++ b/src/core/dhcp/tests/test-dhcp-utils.c @@ -14,7 +14,7 @@ #include "dhcp/nm-dhcp-utils.h" #include "dhcp/nm-dhcp-options.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-test-utils-core.h" diff --git a/src/core/dns/nm-dns-dnsmasq.c b/src/core/dns/nm-dns-dnsmasq.c index 6ef9f924ee..126e0a217a 100644 --- a/src/core/dns/nm-dns-dnsmasq.c +++ b/src/core/dns/nm-dns-dnsmasq.c @@ -17,7 +17,7 @@ #include "libnm-glib-aux/nm-dbus-aux.h" #include "libnm-core-intern/nm-core-internal.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-utils.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" diff --git a/src/core/dns/nm-dns-systemd-resolved.c b/src/core/dns/nm-dns-systemd-resolved.c index 236a8283aa..de01cf9fb7 100644 --- a/src/core/dns/nm-dns-systemd-resolved.c +++ b/src/core/dns/nm-dns-systemd-resolved.c @@ -19,7 +19,7 @@ #include "libnm-glib-aux/nm-c-list.h" #include "libnm-glib-aux/nm-dbus-aux.h" #include "libnm-core-intern/nm-core-internal.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-utils.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" diff --git a/src/core/dnsmasq/nm-dnsmasq-utils.c b/src/core/dnsmasq/nm-dnsmasq-utils.c index ea23a78d41..86e18b5640 100644 --- a/src/core/dnsmasq/nm-dnsmasq-utils.c +++ b/src/core/dnsmasq/nm-dnsmasq-utils.c @@ -8,7 +8,7 @@ #include <arpa/inet.h> #include "nm-dnsmasq-utils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-utils.h" gboolean diff --git a/src/core/dnsmasq/nm-dnsmasq-utils.h b/src/core/dnsmasq/nm-dnsmasq-utils.h index 57bbc4c40c..1fabc9bab2 100644 --- a/src/core/dnsmasq/nm-dnsmasq-utils.h +++ b/src/core/dnsmasq/nm-dnsmasq-utils.h @@ -6,7 +6,7 @@ #ifndef __NETWORKMANAGER_DNSMASQ_UTILS_H__ #define __NETWORKMANAGER_DNSMASQ_UTILS_H__ -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" gboolean nm_dnsmasq_utils_get_range(const NMPlatformIP4Address *addr, char * out_first, diff --git a/src/core/initrd/nmi-ibft-reader.c b/src/core/initrd/nmi-ibft-reader.c index 3a5b5d6634..7b631b8ca5 100644 --- a/src/core/initrd/nmi-ibft-reader.c +++ b/src/core/initrd/nmi-ibft-reader.c @@ -18,6 +18,7 @@ #include <linux/if_ether.h> #include "libnm-core-intern/nm-core-internal.h" +#include "libnm-platform/nm-platform-utils.h" #include "NetworkManagerUtils.h" /*****************************************************************************/ @@ -92,7 +93,7 @@ nmi_ibft_read(const char *sysfs_dir) (GDestroyNotify) g_hash_table_unref); if (!g_file_test(ibft_path, G_FILE_TEST_IS_DIR)) - nm_utils_modprobe(NULL, FALSE, "iscsi_ibft", NULL); + nmp_utils_modprobe(NULL, FALSE, "iscsi_ibft", NULL); if (!g_file_test(ibft_path, G_FILE_TEST_IS_DIR)) return ibft; diff --git a/src/core/main.c b/src/core/main.c index 88fd8f20d4..bf8f8d44c4 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -20,7 +20,7 @@ #include "nm-dbus-interface.h" #include "NetworkManagerUtils.h" #include "nm-manager.h" -#include "platform/nm-linux-platform.h" +#include "libnm-platform/nm-linux-platform.h" #include "nm-dbus-manager.h" #include "devices/nm-device.h" #include "dhcp/nm-dhcp-manager.h" diff --git a/src/core/meson.build b/src/core/meson.build index ea23e17f55..f3dc965762 100644 --- a/src/core/meson.build +++ b/src/core/meson.build @@ -34,11 +34,6 @@ subdir('systemd') core_plugins = [] -platform_wifi_wext_source = files() -if enable_wext - platform_wifi_wext_source += files('platform/wifi/nm-wifi-utils-wext.c') -endif - libNetworkManagerBase = static_library( 'NetworkManagerBase', sources: files( @@ -50,13 +45,6 @@ libNetworkManagerBase = static_library( 'dhcp/nm-dhcp-options.c', 'ndisc/nm-lndp-ndisc.c', 'ndisc/nm-ndisc.c', - 'platform/wifi/nm-wifi-utils-nl80211.c', - 'platform/wifi/nm-wifi-utils.c', - 'platform/wpan/nm-wpan-utils.c', - 'platform/nm-linux-platform.c', - 'platform/nm-platform.c', - 'platform/nmp-object.c', - 'platform/nmp-rules-manager.c', 'main-utils.c', 'NetworkManagerUtils.c', 'nm-core-utils.c', @@ -69,7 +57,7 @@ libNetworkManagerBase = static_library( 'nm-ip-config.c', 'nm-ip4-config.c', 'nm-ip6-config.c', - ) + platform_wifi_wext_source, + ), dependencies: [ core_default_dep, libnm_core_public_dep, diff --git a/src/core/ndisc/nm-lndp-ndisc.c b/src/core/ndisc/nm-lndp-ndisc.c index 8b63f92c91..7ba9be3b46 100644 --- a/src/core/ndisc/nm-lndp-ndisc.c +++ b/src/core/ndisc/nm-lndp-ndisc.c @@ -17,7 +17,7 @@ #include "libnm-systemd-shared/nm-sd-utils-shared.h" #include "nm-ndisc-private.h" #include "NetworkManagerUtils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-platform/nmp-netns.h" #define _NMLOG_PREFIX_NAME "ndisc-lndp" diff --git a/src/core/ndisc/nm-ndisc.c b/src/core/ndisc/nm-ndisc.c index e92134c53e..736fc937d7 100644 --- a/src/core/ndisc/nm-ndisc.c +++ b/src/core/ndisc/nm-ndisc.c @@ -14,7 +14,7 @@ #include "nm-ndisc-private.h" #include "nm-utils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-platform/nmp-netns.h" #include "nm-l3-config-data.h" diff --git a/src/core/ndisc/nm-ndisc.h b/src/core/ndisc/nm-ndisc.h index 93aee4db38..31f736a8f0 100644 --- a/src/core/ndisc/nm-ndisc.h +++ b/src/core/ndisc/nm-ndisc.h @@ -13,8 +13,8 @@ #include "nm-setting-ip6-config.h" #include "NetworkManagerUtils.h" -#include "platform/nm-platform.h" -#include "platform/nmp-object.h" +#include "libnm-platform/nm-platform.h" +#include "libnm-platform/nmp-object.h" #define NM_RA_TIMEOUT_DEFAULT ((guint32) 0) #define NM_RA_TIMEOUT_INFINITY ((guint32) G_MAXINT32) diff --git a/src/core/ndisc/tests/test-ndisc-linux.c b/src/core/ndisc/tests/test-ndisc-linux.c index 9a5df60b1c..c84ee142b1 100644 --- a/src/core/ndisc/tests/test-ndisc-linux.c +++ b/src/core/ndisc/tests/test-ndisc-linux.c @@ -10,7 +10,7 @@ #include "ndisc/nm-ndisc.h" #include "ndisc/nm-lndp-ndisc.h" -#include "platform/nm-linux-platform.h" +#include "libnm-platform/nm-linux-platform.h" #include "nm-test-utils-core.h" diff --git a/src/core/nm-config-data.h b/src/core/nm-config-data.h index 07cffb436d..e1a6f853c9 100644 --- a/src/core/nm-config-data.h +++ b/src/core/nm-config-data.h @@ -6,6 +6,8 @@ #ifndef NM_CONFIG_DATA_H #define NM_CONFIG_DATA_H +#include "libnm-platform/nmp-base.h" + /*****************************************************************************/ typedef enum { diff --git a/src/core/nm-connectivity.h b/src/core/nm-connectivity.h index c67668ce4a..0985df9789 100644 --- a/src/core/nm-connectivity.h +++ b/src/core/nm-connectivity.h @@ -8,6 +8,7 @@ #define __NETWORKMANAGER_CONNECTIVITY_H__ #include "nm-dbus-interface.h" +#include "libnm-platform/nmp-base.h" /*****************************************************************************/ diff --git a/src/core/nm-core-utils.c b/src/core/nm-core-utils.c index de3363e48e..6a327fa7fa 100644 --- a/src/core/nm-core-utils.c +++ b/src/core/nm-core-utils.c @@ -22,6 +22,7 @@ #include <net/if_arp.h> #include <net/ethernet.h> +#include "libnm-platform/nmp-base.h" #include "libnm-std-aux/unaligned.h" #include "libnm-glib-aux/nm-random-utils.h" #include "libnm-glib-aux/nm-io-utils.h" @@ -156,37 +157,6 @@ _nm_singleton_instance_register_destruction(GObject *instance) /*****************************************************************************/ -static double -_exp10(guint16 ex) -{ - double v; - - if (ex == 0) - return 1.0; - - v = _exp10(ex / 2); - v = v * v; - if (ex % 2) - v *= 10; - return v; -} - -/* - * nm_utils_exp10: - * @ex: the exponent - * - * Returns: 10^ex, or pow(10, ex), or exp10(ex). - */ -double -nm_utils_exp10(gint16 ex) -{ - if (ex >= 0) - return _exp10(ex); - return 1.0 / _exp10(-((gint32) ex)); -} - -/*****************************************************************************/ - gboolean nm_ether_addr_is_valid(const NMEtherAddr *addr) { @@ -304,85 +274,6 @@ nm_utils_array_remove_at_indexes(GArray *array, const guint *indexes_to_delete, g_array_set_size(array, res_length); } -static const char * -_trunk_first_line(char *str) -{ - char *s; - - s = strchr(str, '\n'); - if (s) - s[0] = '\0'; - return str; -} - -int -nm_utils_modprobe(GError **error, gboolean suppress_error_logging, const char *arg1, ...) -{ - gs_unref_ptrarray GPtrArray *argv = NULL; - int exit_status; - gs_free char * _log_str = NULL; -#define ARGV_TO_STR(argv) \ - (_log_str ? _log_str : (_log_str = g_strjoinv(" ", (char **) argv->pdata))) - GError * local = NULL; - va_list ap; - NMLogLevel llevel = suppress_error_logging ? LOGL_DEBUG : LOGL_ERR; - gs_free char *std_out = NULL, *std_err = NULL; - - g_return_val_if_fail(!error || !*error, -1); - g_return_val_if_fail(arg1, -1); - - /* construct the argument list */ - argv = g_ptr_array_sized_new(4); - g_ptr_array_add(argv, "/sbin/modprobe"); - g_ptr_array_add(argv, "--use-blacklist"); - g_ptr_array_add(argv, (char *) arg1); - - va_start(ap, arg1); - while ((arg1 = va_arg(ap, const char *))) - g_ptr_array_add(argv, (char *) arg1); - va_end(ap); - - g_ptr_array_add(argv, NULL); - - nm_log_dbg(LOGD_CORE, "modprobe: '%s'", ARGV_TO_STR(argv)); - if (!g_spawn_sync(NULL, - (char **) argv->pdata, - NULL, - 0, - NULL, - NULL, - &std_out, - &std_err, - &exit_status, - &local)) { - nm_log(llevel, - LOGD_CORE, - NULL, - NULL, - "modprobe: '%s' failed: %s", - ARGV_TO_STR(argv), - local->message); - g_propagate_error(error, local); - return -1; - } else if (exit_status != 0) { - nm_log(llevel, - LOGD_CORE, - NULL, - NULL, - "modprobe: '%s' exited with error %d%s%s%s%s%s%s", - ARGV_TO_STR(argv), - exit_status, - std_out && *std_out ? " (" : "", - std_out && *std_out ? _trunk_first_line(std_out) : "", - std_out && *std_out ? ")" : "", - std_err && *std_err ? " (" : "", - std_err && *std_err ? _trunk_first_line(std_err) : "", - std_err && *std_err ? ")" : ""); - } - - return exit_status; -} - /*****************************************************************************/ typedef struct { @@ -1269,7 +1160,7 @@ typedef struct { const char *value; gboolean is_parsed; guint len; - guint8 bin[NM_UTILS_HWADDR_LEN_MAX]; + guint8 bin[_NM_UTILS_HWADDR_LEN_MAX]; } hwaddr; struct { const char *value; @@ -2051,65 +1942,6 @@ nm_utils_kernel_cmdline_match_check(const char *const *proc_cmdline, /*****************************************************************************/ -char * -nm_utils_new_vlan_name(const char *parent_iface, guint32 vlan_id) -{ - guint id_len; - gsize parent_len; - char *ifname; - - g_return_val_if_fail(parent_iface && *parent_iface, NULL); - - if (vlan_id < 10) - id_len = 2; - else if (vlan_id < 100) - id_len = 3; - else if (vlan_id < 1000) - id_len = 4; - else { - g_return_val_if_fail(vlan_id < 4095, NULL); - id_len = 5; - } - - ifname = g_new(char, IFNAMSIZ); - - parent_len = strlen(parent_iface); - parent_len = MIN(parent_len, IFNAMSIZ - 1 - id_len); - memcpy(ifname, parent_iface, parent_len); - g_snprintf(&ifname[parent_len], IFNAMSIZ - parent_len, ".%u", vlan_id); - - return ifname; -} - -/* nm_utils_new_infiniband_name: - * @name: the output-buffer where the value will be written. Must be - * not %NULL and point to a string buffer of at least IFNAMSIZ bytes. - * @parent_name: the parent interface name - * @p_key: the partition key. - * - * Returns: the infiniband name will be written to @name and @name - * is returned. - */ -const char * -nm_utils_new_infiniband_name(char *name, const char *parent_name, int p_key) -{ - g_return_val_if_fail(name, NULL); - g_return_val_if_fail(parent_name && parent_name[0], NULL); - g_return_val_if_fail(strlen(parent_name) < IFNAMSIZ, NULL); - - /* technically, p_key of 0x0000 and 0x8000 is not allowed either. But we don't - * want to assert against that in nm_utils_new_infiniband_name(). So be more - * resilient here, and accept those. */ - g_return_val_if_fail(p_key >= 0 && p_key <= 0xffff, NULL); - - /* If parent+suffix is too long, kernel would just truncate - * the name. We do the same. See ipoib_vlan_add(). */ - g_snprintf(name, IFNAMSIZ, "%s.%04x", parent_name, p_key); - return name; -} - -/*****************************************************************************/ - /** * nm_utils_cmp_connection_by_autoconnect_priority: * @a: @@ -2538,134 +2370,6 @@ out: g_array_free(sorted_hashes, TRUE); } -#define IPV6_PROPERTY_DIR "/proc/sys/net/ipv6/conf/" -#define IPV4_PROPERTY_DIR "/proc/sys/net/ipv4/conf/" -G_STATIC_ASSERT(sizeof(IPV4_PROPERTY_DIR) == sizeof(IPV6_PROPERTY_DIR)); -G_STATIC_ASSERT(NM_STRLEN(IPV6_PROPERTY_DIR) + IFNAMSIZ + 60 - == NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE); - -/** - * nm_utils_sysctl_ip_conf_path: - * @addr_family: either AF_INET or AF_INET6. - * @buf: the output buffer where to write the path. It - * must be at least NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE bytes - * long. - * @ifname: an interface name - * @property: a property name - * - * Returns: the path to IPv6 property @property on @ifname. Note that - * this returns the input argument @buf. - */ -const char * -nm_utils_sysctl_ip_conf_path(int addr_family, char *buf, const char *ifname, const char *property) -{ - int len; - - nm_assert(buf); - nm_assert_addr_family(addr_family); - - g_assert(nm_utils_ifname_valid_kernel(ifname, NULL)); - property = NM_ASSERT_VALID_PATH_COMPONENT(property); - - len = g_snprintf(buf, - NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE, - "%s%s/%s", - addr_family == AF_INET6 ? IPV6_PROPERTY_DIR : IPV4_PROPERTY_DIR, - ifname, - property); - g_assert(len < NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE - 1); - return buf; -} - -gboolean -nm_utils_sysctl_ip_conf_is_path(int addr_family, - const char *path, - const char *ifname, - const char *property) -{ - g_return_val_if_fail(path, FALSE); - NM_ASSERT_VALID_PATH_COMPONENT(property); - g_assert(!ifname || nm_utils_ifname_valid_kernel(ifname, NULL)); - - if (addr_family == AF_INET) { - if (!g_str_has_prefix(path, IPV4_PROPERTY_DIR)) - return FALSE; - path += NM_STRLEN(IPV4_PROPERTY_DIR); - } else if (addr_family == AF_INET6) { - if (!g_str_has_prefix(path, IPV6_PROPERTY_DIR)) - return FALSE; - path += NM_STRLEN(IPV6_PROPERTY_DIR); - } else - g_return_val_if_reached(FALSE); - - if (ifname) { - if (!g_str_has_prefix(path, ifname)) - return FALSE; - path += strlen(ifname); - if (path[0] != '/') - return FALSE; - path++; - } else { - const char *slash; - char buf[IFNAMSIZ]; - gsize l; - - slash = strchr(path, '/'); - if (!slash) - return FALSE; - l = slash - path; - if (l >= IFNAMSIZ) - return FALSE; - memcpy(buf, path, l); - buf[l] = '\0'; - if (!nm_utils_ifname_valid_kernel(buf, NULL)) - return FALSE; - path = slash + 1; - } - - if (!nm_streq(path, property)) - return FALSE; - - return TRUE; -} - -gboolean -nm_utils_is_valid_path_component(const char *name) -{ - const char *n; - - if (name == NULL || name[0] == '\0') - return FALSE; - - if (name[0] == '.') { - if (name[1] == '\0') - return FALSE; - if (name[1] == '.' && name[2] == '\0') - return FALSE; - } - n = name; - do { - if (*n == '/') - return FALSE; - } while (*(++n) != '\0'); - - return TRUE; -} - -const char * -NM_ASSERT_VALID_PATH_COMPONENT(const char *name) -{ - if (G_LIKELY(nm_utils_is_valid_path_component(name))) - return name; - - nm_log_err(LOGD_CORE, - "Failed asserting path component: %s%s%s", - NM_PRINT_FMT_QUOTED(name, "\"", name, "\"", "(null)")); - g_error("FATAL: Failed asserting path component: %s%s%s", - NM_PRINT_FMT_QUOTED(name, "\"", name, "\"", "(null)")); - g_assert_not_reached(); -} - /*****************************************************************************/ typedef struct { @@ -3407,89 +3111,6 @@ nm_utils_get_ipv6_interface_identifier(NMLinkType link_type, /*****************************************************************************/ -/** - * nm_utils_ipv6_addr_set_interface_identifier: - * @addr: output token encoded as %in6_addr - * @iid: %NMUtilsIPv6IfaceId interface identifier - * - * Converts the %NMUtilsIPv6IfaceId to an %in6_addr (suitable for use - * with Linux platform). This only copies the lower 8 bytes, ignoring - * the /64 network prefix which is expected to be all-zero for a valid - * token. - */ -void -nm_utils_ipv6_addr_set_interface_identifier(struct in6_addr *addr, const NMUtilsIPv6IfaceId iid) -{ - memcpy(addr->s6_addr + 8, &iid.id_u8, 8); -} - -/** - * nm_utils_ipv6_interface_identifier_get_from_addr: - * @iid: output %NMUtilsIPv6IfaceId interface identifier set from the token - * @addr: token encoded as %in6_addr - * - * Converts the %in6_addr encoded token (as used by Linux platform) to - * the interface identifier. - */ -void -nm_utils_ipv6_interface_identifier_get_from_addr(NMUtilsIPv6IfaceId * iid, - const struct in6_addr *addr) -{ - memcpy(iid, addr->s6_addr + 8, 8); -} - -/** - * nm_utils_ipv6_interface_identifier_get_from_token: - * @iid: output %NMUtilsIPv6IfaceId interface identifier set from the token - * @token: token encoded as string - * - * Converts the %in6_addr encoded token (as used in ip6 settings) to - * the interface identifier. - * - * Returns: %TRUE if the @token is a valid token, %FALSE otherwise - */ -gboolean -nm_utils_ipv6_interface_identifier_get_from_token(NMUtilsIPv6IfaceId *iid, const char *token) -{ - struct in6_addr i6_token; - - g_return_val_if_fail(token, FALSE); - - if (!inet_pton(AF_INET6, token, &i6_token)) - return FALSE; - - if (!_nm_utils_inet6_is_token(&i6_token)) - return FALSE; - - nm_utils_ipv6_interface_identifier_get_from_addr(iid, &i6_token); - return TRUE; -} - -/** - * nm_utils_inet6_interface_identifier_to_token: - * @iid: %NMUtilsIPv6IfaceId interface identifier - * @buf: the destination buffer of at least %NM_UTILS_INET_ADDRSTRLEN - * bytes. - * - * Converts the interface identifier to a string token. - * - * Returns: the input buffer filled with the id as string. - */ -const char * -nm_utils_inet6_interface_identifier_to_token(NMUtilsIPv6IfaceId iid, - char buf[static INET6_ADDRSTRLEN]) -{ - struct in6_addr i6_token = {.s6_addr = { - 0, - }}; - - nm_assert(buf); - nm_utils_ipv6_addr_set_interface_identifier(&i6_token, iid); - return _nm_utils_inet6_ntop(&i6_token, buf); -} - -/*****************************************************************************/ - char * nm_utils_stable_id_random(void) { @@ -4269,89 +3890,6 @@ nm_utils_g_value_set_strv(GValue *value, GPtrArray *strings) /*****************************************************************************/ -/** - * Takes a pair @timestamp and @duration, and returns the remaining duration based - * on the new timestamp @now. - */ -guint32 -nm_utils_lifetime_rebase_relative_time_on_now(guint32 timestamp, guint32 duration, gint32 now) -{ - gint64 t; - - nm_assert(now >= 0); - - if (duration == NM_PLATFORM_LIFETIME_PERMANENT) - return NM_PLATFORM_LIFETIME_PERMANENT; - - if (timestamp == 0) { - /* if the @timestamp is zero, assume it was just left unset and that the relative - * @duration starts counting from @now. This is convenient to construct an address - * and print it in nm_platform_ip4_address_to_string(). - * - * In general it does not make sense to set the @duration without anchoring at - * @timestamp because you don't know the absolute expiration time when looking - * at the address at a later moment. */ - timestamp = now; - } - - /* For timestamp > now, just accept it and calculate the expected(?) result. */ - t = (gint64) timestamp + (gint64) duration - (gint64) now; - - if (t <= 0) - return 0; - if (t >= NM_PLATFORM_LIFETIME_PERMANENT) - return NM_PLATFORM_LIFETIME_PERMANENT - 1; - return t; -} - -guint32 -nm_utils_lifetime_get(guint32 timestamp, - guint32 lifetime, - guint32 preferred, - gint32 now, - guint32 *out_preferred) -{ - guint32 t_lifetime, t_preferred; - - nm_assert(now >= 0); - - if (timestamp == 0 && lifetime == 0) { - /* We treat lifetime==0 && timestamp==0 addresses as permanent addresses to allow easy - * creation of such addresses (without requiring to set the lifetime fields to - * NM_PLATFORM_LIFETIME_PERMANENT). The real lifetime==0 addresses (E.g. DHCP6 telling us - * to drop an address will have timestamp set. - */ - NM_SET_OUT(out_preferred, NM_PLATFORM_LIFETIME_PERMANENT); - g_return_val_if_fail(preferred == 0, NM_PLATFORM_LIFETIME_PERMANENT); - return NM_PLATFORM_LIFETIME_PERMANENT; - } - - if (now <= 0) - now = nm_utils_get_monotonic_timestamp_sec(); - - t_lifetime = nm_utils_lifetime_rebase_relative_time_on_now(timestamp, lifetime, now); - if (!t_lifetime) { - NM_SET_OUT(out_preferred, 0); - return 0; - } - - t_preferred = nm_utils_lifetime_rebase_relative_time_on_now(timestamp, preferred, now); - - NM_SET_OUT(out_preferred, MIN(t_preferred, t_lifetime)); - - /* Assert that non-permanent addresses have a (positive) @timestamp. nm_utils_lifetime_rebase_relative_time_on_now() - * treats addresses with timestamp 0 as *now*. Addresses passed to _address_get_lifetime() always - * should have a valid @timestamp, otherwise on every re-sync, their lifetime will be extended anew. - */ - g_return_val_if_fail(timestamp != 0 - || (lifetime == NM_PLATFORM_LIFETIME_PERMANENT - && preferred == NM_PLATFORM_LIFETIME_PERMANENT), - t_lifetime); - g_return_val_if_fail(t_preferred <= t_lifetime, t_lifetime); - - return t_lifetime; -} - const char * nm_utils_dnsmasq_status_to_string(int status, char *dest, gsize size) { @@ -5102,13 +4640,6 @@ nm_wifi_utils_level_to_quality(int val) /*****************************************************************************/ -NM_UTILS_ENUM2STR_DEFINE(nm_icmpv6_router_pref_to_string, - NMIcmpv6RouterPref, - NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_LOW, "low"), - NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_MEDIUM, "medium"), - NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_HIGH, "high"), - NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_INVALID, "invalid"), ); - NM_UTILS_LOOKUP_STR_DEFINE(nm_activation_type_to_string, NMActivationType, NM_UTILS_LOOKUP_DEFAULT_WARN("(unknown)"), diff --git a/src/core/nm-core-utils.h b/src/core/nm-core-utils.h index 01d8322568..7fd96d3ac5 100644 --- a/src/core/nm-core-utils.h +++ b/src/core/nm-core-utils.h @@ -16,8 +16,6 @@ /*****************************************************************************/ -#define NM_PLATFORM_LIFETIME_PERMANENT G_MAXUINT32 - #define NM_DEFINE_SINGLETON_INSTANCE(TYPE) static TYPE *singleton_instance #define NM_DEFINE_SINGLETON_REGISTER(TYPE) \ @@ -98,73 +96,6 @@ void _nm_singleton_instance_register_destruction(GObject *instance); gboolean nm_ether_addr_is_valid(const NMEtherAddr *addr); gboolean nm_ether_addr_is_valid_str(const char *str); -gconstpointer -nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint8 plen); -in_addr_t nm_utils_ip4_address_clear_host_address(in_addr_t addr, guint8 plen); -const struct in6_addr *nm_utils_ip6_address_clear_host_address(struct in6_addr * dst, - const struct in6_addr *src, - guint8 plen); - -static inline int -nm_utils_ip4_address_same_prefix_cmp(in_addr_t addr_a, in_addr_t addr_b, guint8 plen) -{ - NM_CMP_DIRECT(htonl(nm_utils_ip4_address_clear_host_address(addr_a, plen)), - htonl(nm_utils_ip4_address_clear_host_address(addr_b, plen))); - return 0; -} - -int nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a, - const struct in6_addr *addr_b, - guint8 plen); - -static inline int -nm_utils_ip_address_same_prefix_cmp(int addr_family, - gconstpointer addr_a, - gconstpointer addr_b, - guint8 plen) -{ - nm_assert_addr_family(addr_family); - - NM_CMP_SELF(addr_a, addr_b); - - if (NM_IS_IPv4(addr_family)) { - return nm_utils_ip4_address_same_prefix_cmp(*((const in_addr_t *) addr_a), - *((const in_addr_t *) addr_b), - plen); - } - - return nm_utils_ip6_address_same_prefix_cmp(addr_a, addr_b, plen); -} - -static inline gboolean -nm_utils_ip4_address_same_prefix(in_addr_t addr_a, in_addr_t addr_b, guint8 plen) -{ - return nm_utils_ip4_address_same_prefix_cmp(addr_a, addr_b, plen) == 0; -} - -static inline gboolean -nm_utils_ip6_address_same_prefix(const struct in6_addr *addr_a, - const struct in6_addr *addr_b, - guint8 plen) -{ - return nm_utils_ip6_address_same_prefix_cmp(addr_a, addr_b, plen) == 0; -} - -static inline gboolean -nm_utils_ip_address_same_prefix(int addr_family, - gconstpointer addr_a, - gconstpointer addr_b, - guint8 plen) -{ - return nm_utils_ip_address_same_prefix_cmp(addr_family, addr_a, addr_b, plen) == 0; -} - -#define NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX(a, b, plen) \ - NM_CMP_RETURN(nm_utils_ip4_address_same_prefix_cmp((a), (b), (plen))) - -#define NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX(a, b, plen) \ - NM_CMP_RETURN(nm_utils_ip6_address_same_prefix_cmp((a), (b), (plen))) - static inline void nm_hash_update_in6addr(NMHashState *h, const struct in6_addr *addr) { @@ -185,8 +116,6 @@ nm_hash_update_in6addr_prefix(NMHashState *h, const struct in6_addr *addr, guint nm_hash_update_in6addr(h, &a); } -double nm_utils_exp10(gint16 e); - /** * nm_utils_ip6_route_metric_normalize: * @metric: the route metric @@ -221,9 +150,6 @@ nm_utils_ip_route_metric_penalize(guint32 metric, guint32 penalty) return G_MAXUINT32; } -int nm_utils_modprobe(GError **error, gboolean suppress_error_loggin, const char *arg1, ...) - G_GNUC_NULL_TERMINATED; - void nm_utils_kill_process_sync(pid_t pid, guint64 start_time, int sig, @@ -291,9 +217,6 @@ gboolean nm_utils_connection_has_default_route(NMConnection *connection, int addr_family, gboolean * out_is_never_default); -char * nm_utils_new_vlan_name(const char *parent_iface, guint32 vlan_id); -const char *nm_utils_new_infiniband_name(char *name, const char *parent_name, int p_key); - int nm_utils_cmp_connection_by_autoconnect_priority(NMConnection *a, NMConnection *b); void nm_utils_log_connection_diff(NMConnection *connection, @@ -304,19 +227,6 @@ void nm_utils_log_connection_diff(NMConnection *connection, const char * prefix, const char * dbus_path); -gboolean nm_utils_is_valid_path_component(const char *name); -const char *NM_ASSERT_VALID_PATH_COMPONENT(const char *name); - -#define NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE 100 - -const char * -nm_utils_sysctl_ip_conf_path(int addr_family, char *buf, const char *ifname, const char *property); - -gboolean nm_utils_sysctl_ip_conf_is_path(int addr_family, - const char *path, - const char *ifname, - const char *property); - gboolean nm_utils_is_specific_hostname(const char *name); struct _NMUuid; @@ -344,49 +254,6 @@ nm_utils_arp_type_get_hwaddr_relevant_part(int arp_type, const guint8 **hwaddr, /*****************************************************************************/ -/* IPv6 Interface Identifier helpers */ - -/** - * NMUtilsIPv6IfaceId: - * @id: convenience member for validity checking; never use directly - * @id_u8: the 64-bit Interface Identifier - * - * Holds a 64-bit IPv6 Interface Identifier. The IID is a sequence of bytes - * and should not normally be treated as a %guint64, but this is done for - * convenience of validity checking and initialization. - */ -struct _NMUtilsIPv6IfaceId { - union { - guint64 id; - guint8 id_u8[8]; - }; -}; - -#define NM_UTILS_IPV6_IFACE_ID_INIT \ - { \ - { \ - .id = 0 \ - } \ - } - -void nm_utils_ipv6_addr_set_interface_identifier(struct in6_addr * addr, - const NMUtilsIPv6IfaceId iid); - -void nm_utils_ipv6_interface_identifier_get_from_addr(NMUtilsIPv6IfaceId * iid, - const struct in6_addr *addr); - -gboolean nm_utils_ipv6_interface_identifier_get_from_token(NMUtilsIPv6IfaceId *iid, - const char * token); - -const char *nm_utils_inet6_interface_identifier_to_token(NMUtilsIPv6IfaceId iid, - char buf[static INET6_ADDRSTRLEN]); - -gboolean nm_utils_get_ipv6_interface_identifier(NMLinkType link_type, - const guint8 * hwaddr, - guint len, - guint dev_id, - NMUtilsIPv6IfaceId *out_iid); - typedef enum { /* The stable type. Note that this value is encoded in the * generated addresses, thus the numbers MUST not change. @@ -501,33 +368,6 @@ void _nm_utils_set_testing(NMUtilsTestFlags flags); void nm_utils_g_value_set_strv(GValue *value, GPtrArray *strings); -guint32 -nm_utils_lifetime_rebase_relative_time_on_now(guint32 timestamp, guint32 duration, gint32 now); - -guint32 nm_utils_lifetime_get(guint32 timestamp, - guint32 lifetime, - guint32 preferred, - gint32 now, - guint32 *out_preferred); - -/*****************************************************************************/ - -#define NM_IPV4LL_NETWORK ((in_addr_t)(htonl(0xA9FE0000lu))) -#define NM_IPV4LL_NETMASK ((in_addr_t)(htonl(0xFFFF0000lu))) - -static inline gboolean -nm_utils_ip4_address_is_link_local(in_addr_t addr) -{ - return (addr & NM_IPV4LL_NETMASK) == NM_IPV4LL_NETWORK; -} - -static inline gboolean -nm_utils_ip4_address_is_zeronet(in_addr_t network) -{ - /* Same as ipv4_is_zeronet() from kernel's include/linux/in.h. */ - return (network & htonl(0xFF000000u)) == htonl(0x00000000u); -} - /*****************************************************************************/ const char *nm_utils_dnsmasq_status_to_string(int status, char *dest, gsize size); @@ -556,20 +396,6 @@ char * nm_utils_format_con_diff_for_audit(GHashTable *diff); /*****************************************************************************/ -/* this enum is compatible with ICMPV6_ROUTER_PREF_* (from <linux/icmpv6.h>, - * the values for netlink attribute RTA_PREF) and "enum ndp_route_preference" - * from <ndp.h>. */ -typedef enum _nm_packed { - NM_ICMPV6_ROUTER_PREF_MEDIUM = 0x0, /* ICMPV6_ROUTER_PREF_MEDIUM */ - NM_ICMPV6_ROUTER_PREF_LOW = 0x3, /* ICMPV6_ROUTER_PREF_LOW */ - NM_ICMPV6_ROUTER_PREF_HIGH = 0x1, /* ICMPV6_ROUTER_PREF_HIGH */ - NM_ICMPV6_ROUTER_PREF_INVALID = 0x2, /* ICMPV6_ROUTER_PREF_INVALID */ -} NMIcmpv6RouterPref; - -const char *nm_icmpv6_router_pref_to_string(NMIcmpv6RouterPref pref, char *buf, gsize len); - -/*****************************************************************************/ - const char *nm_activation_type_to_string(NMActivationType activation_type); /*****************************************************************************/ diff --git a/src/core/nm-dcb.c b/src/core/nm-dcb.c index b3958caa51..930a10238f 100644 --- a/src/core/nm-dcb.c +++ b/src/core/nm-dcb.c @@ -8,7 +8,7 @@ #include <sys/wait.h> #include "nm-dcb.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "NetworkManagerUtils.h" static const char *helper_names[] = {"dcbtool", "fcoeadm"}; diff --git a/src/core/nm-dispatcher.c b/src/core/nm-dispatcher.c index 5d9c51aa81..4fdb905dcf 100644 --- a/src/core/nm-dispatcher.c +++ b/src/core/nm-dispatcher.c @@ -20,7 +20,7 @@ #include "nm-ip6-config.h" #include "nm-manager.h" #include "settings/nm-settings-connection.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-core-intern/nm-core-internal.h" #define CALL_TIMEOUT (1000 * 60 * 10) /* 10 minutes for all scripts */ diff --git a/src/core/nm-iface-helper.c b/src/core/nm-iface-helper.c index 9dfee8d9e7..c4d87b96e4 100644 --- a/src/core/nm-iface-helper.c +++ b/src/core/nm-iface-helper.c @@ -20,7 +20,7 @@ #include "main-utils.h" #include "NetworkManagerUtils.h" -#include "platform/nm-linux-platform.h" +#include "libnm-platform/nm-linux-platform.h" #include "libnm-platform/nm-platform-utils.h" #include "dhcp/nm-dhcp-manager.h" #include "ndisc/nm-ndisc.h" diff --git a/src/core/nm-ip4-config.c b/src/core/nm-ip4-config.c index 575d2876f3..e2e4251fe3 100644 --- a/src/core/nm-ip4-config.c +++ b/src/core/nm-ip4-config.c @@ -15,8 +15,8 @@ #include "libnm-glib-aux/nm-dedup-multi.h" #include "nm-utils.h" -#include "platform/nmp-object.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nmp-object.h" +#include "libnm-platform/nm-platform.h" #include "libnm-platform/nm-platform-utils.h" #include "NetworkManagerUtils.h" #include "libnm-core-intern/nm-core-internal.h" diff --git a/src/core/nm-ip4-config.h b/src/core/nm-ip4-config.h index 1196a724cd..7032a2385e 100644 --- a/src/core/nm-ip4-config.h +++ b/src/core/nm-ip4-config.h @@ -11,7 +11,7 @@ #include "nm-setting-ip4-config.h" #include "libnm-glib-aux/nm-dedup-multi.h" -#include "platform/nmp-object.h" +#include "libnm-platform/nmp-object.h" #include "nm-ip-config.h" /*****************************************************************************/ diff --git a/src/core/nm-ip6-config.c b/src/core/nm-ip6-config.c index 5501e02f5f..a5a885f44f 100644 --- a/src/core/nm-ip6-config.c +++ b/src/core/nm-ip6-config.c @@ -16,8 +16,8 @@ #include "libnm-glib-aux/nm-dedup-multi.h" #include "nm-utils.h" -#include "platform/nmp-object.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nmp-object.h" +#include "libnm-platform/nm-platform.h" #include "libnm-platform/nm-platform-utils.h" #include "libnm-core-intern/nm-core-internal.h" #include "NetworkManagerUtils.h" diff --git a/src/core/nm-ip6-config.h b/src/core/nm-ip6-config.h index 7cc00a83f3..4aa0ee4e58 100644 --- a/src/core/nm-ip6-config.h +++ b/src/core/nm-ip6-config.h @@ -11,7 +11,7 @@ #include "nm-setting-ip6-config.h" #include "libnm-glib-aux/nm-dedup-multi.h" -#include "platform/nmp-object.h" +#include "libnm-platform/nmp-object.h" #include "nm-ip-config.h" /*****************************************************************************/ diff --git a/src/core/nm-l3-config-data.c b/src/core/nm-l3-config-data.c index cce7364cd4..bf358f9e47 100644 --- a/src/core/nm-l3-config-data.c +++ b/src/core/nm-l3-config-data.c @@ -10,9 +10,9 @@ #include "libnm-glib-aux/nm-enum-utils.h" #include "libnm-core-intern/nm-core-internal.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-platform/nm-platform-utils.h" -#include "platform/nmp-object.h" +#include "libnm-platform/nmp-object.h" #include "NetworkManagerUtils.h" /*****************************************************************************/ diff --git a/src/core/nm-l3-config-data.h b/src/core/nm-l3-config-data.h index f89095f9b9..229851c588 100644 --- a/src/core/nm-l3-config-data.h +++ b/src/core/nm-l3-config-data.h @@ -6,8 +6,8 @@ #include "libnm-glib-aux/nm-dedup-multi.h" #include "nm-setting-connection.h" #include "nm-setting-ip6-config.h" -#include "platform/nm-platform.h" -#include "platform/nmp-object.h" +#include "libnm-platform/nm-platform.h" +#include "libnm-platform/nmp-object.h" typedef enum { NM_L3_CONFIG_DAT_FLAGS_NONE = 0, diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c index 839213ad51..ef875b71d5 100644 --- a/src/core/nm-l3cfg.c +++ b/src/core/nm-l3cfg.c @@ -9,8 +9,9 @@ #include <linux/if_ether.h> #include <linux/rtnetlink.h> -#include "platform/nm-platform.h" -#include "platform/nmp-object.h" +#include "libnm-glib-aux/nm-time-utils.h" +#include "libnm-platform/nm-platform.h" +#include "libnm-platform/nmp-object.h" #include "nm-netns.h" #include "n-acd/src/n-acd.h" #include "nm-l3-ipv4ll.h" diff --git a/src/core/nm-l3cfg.h b/src/core/nm-l3cfg.h index 5cfc93f643..a477d6c3d1 100644 --- a/src/core/nm-l3cfg.h +++ b/src/core/nm-l3cfg.h @@ -3,7 +3,7 @@ #ifndef __NM_L3CFG_H__ #define __NM_L3CFG_H__ -#include "platform/nmp-object.h" +#include "libnm-platform/nmp-object.h" #include "nm-l3-config-data.h" #define NM_L3CFG_CONFIG_PRIORITY_IPV4LL 0 diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index d67dfab99d..1e9c265fac 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -23,8 +23,8 @@ #include "vpn/nm-vpn-manager.h" #include "devices/nm-device.h" #include "devices/nm-device-generic.h" -#include "platform/nm-platform.h" -#include "platform/nmp-object.h" +#include "libnm-platform/nm-platform.h" +#include "libnm-platform/nmp-object.h" #include "nm-hostname-manager.h" #include "nm-keep-alive.h" #include "nm-rfkill-manager.h" @@ -1305,7 +1305,7 @@ find_device_by_permanent_hw_addr(NMManager *self, const char *hwaddr) NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE(self); NMDevice * device; const char * device_addr; - guint8 hwaddr_bin[NM_UTILS_HWADDR_LEN_MAX]; + guint8 hwaddr_bin[_NM_UTILS_HWADDR_LEN_MAX]; gsize hwaddr_len; g_return_val_if_fail(hwaddr != NULL, NULL); diff --git a/src/core/nm-netns.c b/src/core/nm-netns.c index 17ba5d6453..90728e7a1f 100644 --- a/src/core/nm-netns.c +++ b/src/core/nm-netns.c @@ -13,9 +13,9 @@ #include "NetworkManagerUtils.h" #include "libnm-core-intern/nm-core-internal.h" #include "nm-l3cfg.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "libnm-platform/nmp-netns.h" -#include "platform/nmp-rules-manager.h" +#include "libnm-platform/nmp-rules-manager.h" /*****************************************************************************/ diff --git a/src/core/nm-netns.h b/src/core/nm-netns.h index 58c8265730..78a9121a6c 100644 --- a/src/core/nm-netns.h +++ b/src/core/nm-netns.h @@ -19,13 +19,15 @@ typedef struct _NMNetnsClass NMNetnsClass; +struct _NMPlatform; + GType nm_netns_get_type(void); NMNetns *nm_netns_get(void); -NMNetns *nm_netns_new(NMPlatform *platform); +NMNetns *nm_netns_new(struct _NMPlatform *platform); -NMPlatform *nm_netns_get_platform(NMNetns *self); -NMPNetns * nm_netns_get_platform_netns(NMNetns *self); +struct _NMPlatform *nm_netns_get_platform(NMNetns *self); +NMPNetns * nm_netns_get_platform_netns(NMNetns *self); struct _NMPRulesManager *nm_netns_get_rules_manager(NMNetns *self); diff --git a/src/core/nm-pacrunner-manager.c b/src/core/nm-pacrunner-manager.c index 492580a071..a51d48d57d 100644 --- a/src/core/nm-pacrunner-manager.c +++ b/src/core/nm-pacrunner-manager.c @@ -9,7 +9,7 @@ #include "nm-utils.h" #include "NetworkManagerUtils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-dbus-manager.h" #include "nm-proxy-config.h" #include "nm-ip4-config.h" diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c index 176cc2ebf3..b247fe96e4 100644 --- a/src/core/nm-policy.c +++ b/src/core/nm-policy.c @@ -17,7 +17,7 @@ #include "devices/nm-device.h" #include "nm-setting-ip4-config.h" #include "nm-setting-connection.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "dns/nm-dns-manager.h" #include "vpn/nm-vpn-manager.h" #include "nm-auth-utils.h" diff --git a/src/core/nm-types.h b/src/core/nm-types.h index ab2314594d..b6abc1b984 100644 --- a/src/core/nm-types.h +++ b/src/core/nm-types.h @@ -77,147 +77,6 @@ typedef enum { NM_ACTIVATION_REASON_USER_REQUEST, } NMActivationReason; -/* platform */ -typedef struct _NMPlatform NMPlatform; -typedef struct _NMPlatformObject NMPlatformObject; -typedef struct _NMPlatformObjWithIfindex NMPlatformObjWithIfindex; -typedef struct _NMPlatformIP4Address NMPlatformIP4Address; -typedef struct _NMPlatformIP4Route NMPlatformIP4Route; -typedef struct _NMPlatformIP6Address NMPlatformIP6Address; -typedef struct _NMPlatformIP6Route NMPlatformIP6Route; -typedef struct _NMPlatformLink NMPlatformLink; -typedef struct _NMPObject NMPObject; - -typedef enum { - - /* No type, used as error value */ - NM_LINK_TYPE_NONE, - - NM_LINK_TYPE_UNKNOWN, - - NM_LINK_TYPE_ANY, - -#define _NM_LINK_TYPE_REAL_FIRST NM_LINK_TYPE_ETHERNET - -/* Hardware types */ -#define _NM_LINK_TYPE_HW_FIRST NM_LINK_TYPE_ETHERNET - NM_LINK_TYPE_ETHERNET, - NM_LINK_TYPE_INFINIBAND, - NM_LINK_TYPE_OLPC_MESH, - NM_LINK_TYPE_WIFI, - NM_LINK_TYPE_WWAN_NET, /* WWAN kernel netdevice */ - NM_LINK_TYPE_WIMAX, - NM_LINK_TYPE_WPAN, - NM_LINK_TYPE_6LOWPAN, - NM_LINK_TYPE_WIFI_P2P, -#define _NM_LINK_TYPE_HW_LAST NM_LINK_TYPE_WIFI_P2P - -/* Software types */ -#define _NM_LINK_TYPE_SW_FIRST NM_LINK_TYPE_BNEP - NM_LINK_TYPE_BNEP, /* Bluetooth Ethernet emulation */ - NM_LINK_TYPE_DUMMY, - NM_LINK_TYPE_GRE, - NM_LINK_TYPE_GRETAP, - NM_LINK_TYPE_IFB, - NM_LINK_TYPE_IP6TNL, - NM_LINK_TYPE_IP6GRE, - NM_LINK_TYPE_IP6GRETAP, - NM_LINK_TYPE_IPIP, - NM_LINK_TYPE_LOOPBACK, - NM_LINK_TYPE_MACSEC, - NM_LINK_TYPE_MACVLAN, - NM_LINK_TYPE_MACVTAP, - NM_LINK_TYPE_OPENVSWITCH, - NM_LINK_TYPE_PPP, - NM_LINK_TYPE_SIT, - NM_LINK_TYPE_TUN, - NM_LINK_TYPE_VETH, - NM_LINK_TYPE_VLAN, - NM_LINK_TYPE_VRF, - NM_LINK_TYPE_VXLAN, - NM_LINK_TYPE_WIREGUARD, -#define _NM_LINK_TYPE_SW_LAST NM_LINK_TYPE_WIREGUARD - -/* Software types with slaves */ -#define _NM_LINK_TYPE_SW_MASTER_FIRST NM_LINK_TYPE_BRIDGE - NM_LINK_TYPE_BRIDGE, - NM_LINK_TYPE_BOND, - NM_LINK_TYPE_TEAM, -#define _NM_LINK_TYPE_SW_MASTER_LAST NM_LINK_TYPE_TEAM - -#define _NM_LINK_TYPE_REAL_LAST NM_LINK_TYPE_TEAM - -#define _NM_LINK_TYPE_REAL_NUM ((int) (_NM_LINK_TYPE_REAL_LAST - _NM_LINK_TYPE_REAL_FIRST + 1)) - -} NMLinkType; - -static inline gboolean -nm_link_type_is_software(NMLinkType link_type) -{ - G_STATIC_ASSERT(_NM_LINK_TYPE_SW_LAST + 1 == _NM_LINK_TYPE_SW_MASTER_FIRST); - - return link_type >= _NM_LINK_TYPE_SW_FIRST && link_type <= _NM_LINK_TYPE_SW_MASTER_LAST; -} - -static inline gboolean -nm_link_type_supports_slaves(NMLinkType link_type) -{ - return link_type >= _NM_LINK_TYPE_SW_MASTER_FIRST && link_type <= _NM_LINK_TYPE_SW_MASTER_LAST; -} - -typedef enum { - NMP_OBJECT_TYPE_UNKNOWN, - NMP_OBJECT_TYPE_LINK, - -#define NMP_OBJECT_TYPE_IP_ADDRESS(is_ipv4) \ - ((is_ipv4) ? NMP_OBJECT_TYPE_IP4_ADDRESS : NMP_OBJECT_TYPE_IP6_ADDRESS) - NMP_OBJECT_TYPE_IP4_ADDRESS, - NMP_OBJECT_TYPE_IP6_ADDRESS, - -#define NMP_OBJECT_TYPE_IP_ROUTE(is_ipv4) \ - ((is_ipv4) ? NMP_OBJECT_TYPE_IP4_ROUTE : NMP_OBJECT_TYPE_IP6_ROUTE) - NMP_OBJECT_TYPE_IP4_ROUTE, - NMP_OBJECT_TYPE_IP6_ROUTE, - - NMP_OBJECT_TYPE_ROUTING_RULE, - - NMP_OBJECT_TYPE_QDISC, - - NMP_OBJECT_TYPE_TFILTER, - - NMP_OBJECT_TYPE_LNK_BRIDGE, - NMP_OBJECT_TYPE_LNK_GRE, - NMP_OBJECT_TYPE_LNK_GRETAP, - NMP_OBJECT_TYPE_LNK_INFINIBAND, - NMP_OBJECT_TYPE_LNK_IP6TNL, - NMP_OBJECT_TYPE_LNK_IP6GRE, - NMP_OBJECT_TYPE_LNK_IP6GRETAP, - NMP_OBJECT_TYPE_LNK_IPIP, - NMP_OBJECT_TYPE_LNK_MACSEC, - NMP_OBJECT_TYPE_LNK_MACVLAN, - NMP_OBJECT_TYPE_LNK_MACVTAP, - NMP_OBJECT_TYPE_LNK_SIT, - NMP_OBJECT_TYPE_LNK_TUN, - NMP_OBJECT_TYPE_LNK_VLAN, - NMP_OBJECT_TYPE_LNK_VRF, - NMP_OBJECT_TYPE_LNK_VXLAN, - NMP_OBJECT_TYPE_LNK_WIREGUARD, - - __NMP_OBJECT_TYPE_LAST, - NMP_OBJECT_TYPE_MAX = __NMP_OBJECT_TYPE_LAST - 1, -} NMPObjectType; - -static inline guint32 -nmp_object_type_to_flags(NMPObjectType obj_type) -{ - G_STATIC_ASSERT_EXPR(NMP_OBJECT_TYPE_MAX < 32); - - nm_assert(_NM_INT_NOT_NEGATIVE(obj_type)); - nm_assert(obj_type < NMP_OBJECT_TYPE_MAX); - - return ((guint32) 1u) << obj_type; -} - /** * NMIPConfigMergeFlags: * @NM_IP_CONFIG_MERGE_DEFAULT: no flags set @@ -236,32 +95,12 @@ typedef enum { NM_IP_CONFIG_MERGE_EXTERNAL = (1LL << 3), } NMIPConfigMergeFlags; -/** - * NMIPRouteTableSyncMode: - * @NM_IP_ROUTE_TABLE_SYNC_MODE_NONE: indicate an invalid setting. - * @NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN: only the main table is synced. For all - * other tables, NM won't delete any extra routes. - * @NM_IP_ROUTE_TABLE_SYNC_MODE_FULL: NM will sync all tables, except the - * local table (255). - * @NM_IP_ROUTE_TABLE_SYNC_MODE_ALL: NM will sync all tables, including the - * local table (255). - */ -typedef enum { - NM_IP_ROUTE_TABLE_SYNC_MODE_NONE = 0, - NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN = 1, - NM_IP_ROUTE_TABLE_SYNC_MODE_FULL = 2, - NM_IP_ROUTE_TABLE_SYNC_MODE_ALL = 3, -} NMIPRouteTableSyncMode; - /* settings */ typedef struct _NMAgentManager NMAgentManager; typedef struct _NMSecretAgent NMSecretAgent; typedef struct _NMSettings NMSettings; typedef struct _NMSettingsConnection NMSettingsConnection; -/* utils */ -typedef struct _NMUtilsIPv6IfaceId NMUtilsIPv6IfaceId; - #define NM_SETTING_CONNECTION_MDNS_UNKNOWN ((NMSettingConnectionMdns) -42) #endif /* NM_TYPES_H */ diff --git a/src/core/platform/nm-fake-platform.c b/src/core/platform/nm-fake-platform.c index 2eb3ae66d4..f65dbebd9d 100644 --- a/src/core/platform/nm-fake-platform.c +++ b/src/core/platform/nm-fake-platform.c @@ -13,12 +13,9 @@ #include <linux/if.h> #include <linux/rtnetlink.h> -#include "nm-utils.h" - -#include "nm-core-utils.h" #include "libnm-platform/nm-platform-utils.h" -#include "nm-platform-private.h" -#include "nmp-object.h" +#include "libnm-platform/nm-platform-private.h" +#include "libnm-platform/nmp-object.h" #include "nm-test-utils-core.h" @@ -608,7 +605,7 @@ link_set_address(NMPlatform *platform, int ifindex, gconstpointer addr, size_t l NMFakePlatformLink *device = link_get(platform, ifindex); nm_auto_nmpobj NMPObject *obj_tmp = NULL; - if (len == 0 || len > NM_UTILS_HWADDR_LEN_MAX || !addr) + if (len == 0 || len > _NM_UTILS_HWADDR_LEN_MAX || !addr) g_return_val_if_reached(-NME_BUG); if (!device) @@ -749,8 +746,8 @@ link_release(NMPlatform *platform, int master_idx, int slave_idx) static gboolean link_vlan_change(NMPlatform * platform, int ifindex, - NMVlanFlags flags_mask, - NMVlanFlags flags_set, + _NMVlanFlags flags_mask, + _NMVlanFlags flags_set, gboolean ingress_reset_all, const NMVlanQosMapping *ingress_map, gsize n_ingress_map, @@ -799,7 +796,7 @@ infiniband_partition_add(NMPlatform * platform, parent_device = link_get(platform, parent); g_return_val_if_fail(parent_device != NULL, FALSE); - nm_utils_new_infiniband_name(name, parent_device->obj->link.name, p_key); + nmp_utils_new_infiniband_name(name, parent_device->obj->link.name, p_key); link_add_one(platform, name, NM_LINK_TYPE_INFINIBAND, _infiniband_add_prepare, &d, out_link); return TRUE; @@ -814,12 +811,12 @@ infiniband_partition_delete(NMPlatform *platform, int parent, int p_key) parent_device = link_get(platform, parent); g_return_val_if_fail(parent_device != NULL, FALSE); - nm_utils_new_infiniband_name(name, parent_device->obj->link.name, p_key); + nmp_utils_new_infiniband_name(name, parent_device->obj->link.name, p_key); return link_delete(platform, nm_platform_link_get_ifindex(platform, name)); } static gboolean -wifi_get_capabilities(NMPlatform *platform, int ifindex, NMDeviceWifiCapabilities *caps) +wifi_get_capabilities(NMPlatform *platform, int ifindex, _NMDeviceWifiCapabilities *caps) { NMFakePlatformLink *device = link_get(platform, ifindex); @@ -829,10 +826,10 @@ wifi_get_capabilities(NMPlatform *platform, int ifindex, NMDeviceWifiCapabilitie return FALSE; if (caps) { - *caps = (NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | NM_WIFI_DEVICE_CAP_CIPHER_WEP104 - | NM_WIFI_DEVICE_CAP_CIPHER_TKIP | NM_WIFI_DEVICE_CAP_CIPHER_CCMP - | NM_WIFI_DEVICE_CAP_WPA | NM_WIFI_DEVICE_CAP_RSN | NM_WIFI_DEVICE_CAP_AP - | NM_WIFI_DEVICE_CAP_ADHOC); + *caps = (_NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | _NM_WIFI_DEVICE_CAP_CIPHER_WEP104 + | _NM_WIFI_DEVICE_CAP_CIPHER_TKIP | _NM_WIFI_DEVICE_CAP_CIPHER_CCMP + | _NM_WIFI_DEVICE_CAP_WPA | _NM_WIFI_DEVICE_CAP_RSN | _NM_WIFI_DEVICE_CAP_AP + | _NM_WIFI_DEVICE_CAP_ADHOC); } return TRUE; } @@ -861,14 +858,14 @@ wifi_get_rate(NMPlatform *platform, int ifindex) return 0; } -static NM80211Mode +static _NM80211Mode wifi_get_mode(NMPlatform *platform, int ifindex) { - return NM_802_11_MODE_UNKNOWN; + return _NM_802_11_MODE_UNKNOWN; } static void -wifi_set_mode(NMPlatform *platform, int ifindex, NM80211Mode mode) +wifi_set_mode(NMPlatform *platform, int ifindex, _NM80211Mode mode) { ; } diff --git a/src/core/platform/nm-fake-platform.h b/src/core/platform/nm-fake-platform.h index a1d44f8ff9..8f8571fa1f 100644 --- a/src/core/platform/nm-fake-platform.h +++ b/src/core/platform/nm-fake-platform.h @@ -6,7 +6,7 @@ #ifndef __NETWORKMANAGER_FAKE_PLATFORM_H__ #define __NETWORKMANAGER_FAKE_PLATFORM_H__ -#include "nm-platform.h" +#include "libnm-platform/nm-platform.h" #define NM_TYPE_FAKE_PLATFORM (nm_fake_platform_get_type()) #define NM_FAKE_PLATFORM(obj) \ diff --git a/src/core/platform/tests/monitor.c b/src/core/platform/tests/monitor.c index abdf2cd54b..ff6fae6565 100644 --- a/src/core/platform/tests/monitor.c +++ b/src/core/platform/tests/monitor.c @@ -8,7 +8,7 @@ #include <stdlib.h> #include <syslog.h> -#include "platform/nm-linux-platform.h" +#include "libnm-platform/nm-linux-platform.h" #include "nm-test-utils-core.h" diff --git a/src/core/platform/tests/test-common.h b/src/core/platform/tests/test-common.h index 618645fea9..ff116fa97f 100644 --- a/src/core/platform/tests/test-common.h +++ b/src/core/platform/tests/test-common.h @@ -11,10 +11,10 @@ #include <linux/if_link.h> #include <linux/ip6_tunnel.h> -#include "platform/nm-platform.h" -#include "platform/nmp-object.h" +#include "libnm-platform/nm-platform.h" +#include "libnm-platform/nmp-object.h" #include "platform/nm-fake-platform.h" -#include "platform/nm-linux-platform.h" +#include "libnm-platform/nm-linux-platform.h" #include "nm-test-utils-core.h" diff --git a/src/core/platform/tests/test-link.c b/src/core/platform/tests/test-link.c index d1ca405f97..1613703251 100644 --- a/src/core/platform/tests/test-link.c +++ b/src/core/platform/tests/test-link.c @@ -13,7 +13,7 @@ #include "libnm-glib-aux/nm-io-utils.h" #include "libnm-base/nm-ethtool-base.h" -#include "platform/nmp-object.h" +#include "libnm-platform/nmp-object.h" #include "libnm-platform/nmp-netns.h" #include "libnm-platform/nm-platform-utils.h" @@ -1303,7 +1303,7 @@ test_software_detect(gconstpointer user_data) if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "gre0")) { /* Seems that the ip_gre module is not loaded... try to load it. */ - gracefully_skip = nm_utils_modprobe(NULL, TRUE, "ip_gre", NULL) != 0; + gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "ip_gre", NULL) != 0; } if (!nmtstp_link_gre_add(NULL, ext, DEVICE_NAME, &lnk_gre)) { @@ -1330,7 +1330,7 @@ test_software_detect(gconstpointer user_data) if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "gretap0")) { /* Seems that the ip_gre module is not loaded... try to load it. */ - gracefully_skip = nm_utils_modprobe(NULL, TRUE, "ip_gre", NULL) != 0; + gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "ip_gre", NULL) != 0; } if (!nmtstp_link_gre_add(NULL, ext, DEVICE_NAME, &lnk_gre)) { @@ -1350,7 +1350,7 @@ test_software_detect(gconstpointer user_data) if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "tunl0")) { /* Seems that the ipip module is not loaded... try to load it. */ - gracefully_skip = nm_utils_modprobe(NULL, TRUE, "ipip", NULL) != 0; + gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "ipip", NULL) != 0; } lnk_ipip.local = nmtst_inet4_from_string("1.2.3.4"); @@ -1376,7 +1376,7 @@ test_software_detect(gconstpointer user_data) if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "ip6tnl0")) { /* Seems that the ip6_tunnel module is not loaded... try to load it. */ - gracefully_skip = nm_utils_modprobe(NULL, TRUE, "ip6_tunnel", NULL) != 0; + gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "ip6_tunnel", NULL) != 0; } switch (test_data->test_mode) { @@ -1418,7 +1418,7 @@ test_software_detect(gconstpointer user_data) if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "ip6gre0")) { /* Seems that the ip6_tunnel module is not loaded... try to load it. */ - gracefully_skip = nm_utils_modprobe(NULL, TRUE, "ip6_gre", NULL) != 0; + gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "ip6_gre", NULL) != 0; } lnk_ip6tnl.local = *nmtst_inet6_from_string("fd01::42"); @@ -1445,7 +1445,7 @@ test_software_detect(gconstpointer user_data) if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "ip6gre0")) { /* Seems that the ip6_tunnel module is not loaded... try to load it. */ - gracefully_skip = nm_utils_modprobe(NULL, TRUE, "ip6_gre", NULL) != 0; + gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "ip6_gre", NULL) != 0; } lnk_ip6tnl.local = *nmtst_inet6_from_string("fe80::abcd"); @@ -1526,7 +1526,7 @@ test_software_detect(gconstpointer user_data) if (!nm_platform_link_get_by_ifname(NM_PLATFORM_GET, "sit0")) { /* Seems that the sit module is not loaded... try to load it. */ - gracefully_skip = nm_utils_modprobe(NULL, TRUE, "sit", NULL) != 0; + gracefully_skip = nmp_utils_modprobe(NULL, TRUE, "sit", NULL) != 0; } if (!nmtstp_link_sit_add(NULL, ext, DEVICE_NAME, &lnk_sit)) { @@ -2049,7 +2049,7 @@ _assert_xgress_qos_mappings_impl(int ifindex, gboolean is_ingress_map, int n_ent _assert_xgress_qos_mappings(ifindex, FALSE, n_entries, __VA_ARGS__) static void -_assert_vlan_flags(int ifindex, NMVlanFlags flags) +_assert_vlan_flags(int ifindex, _NMVlanFlags flags) { const NMPlatformLnkVlan *plnk; @@ -2362,8 +2362,8 @@ test_vlan_set_xgress(void) g_assert(nm_platform_link_vlan_change(NM_PLATFORM_GET, ifindex, - NM_VLAN_FLAG_REORDER_HEADERS | NM_VLAN_FLAG_GVRP, - NM_VLAN_FLAG_REORDER_HEADERS, + _NM_VLAN_FLAG_REORDER_HEADERS | _NM_VLAN_FLAG_GVRP, + _NM_VLAN_FLAG_REORDER_HEADERS, TRUE, ingress_map, G_N_ELEMENTS(ingress_map), @@ -2372,7 +2372,7 @@ test_vlan_set_xgress(void) G_N_ELEMENTS(egress_map))); _assert_ingress_qos_mappings(ifindex, 2, 4, 1, 6, 12); _assert_egress_qos_mappings(ifindex, 2, 1, 5, 3232, 7); - _assert_vlan_flags(ifindex, NM_VLAN_FLAG_REORDER_HEADERS); + _assert_vlan_flags(ifindex, _NM_VLAN_FLAG_REORDER_HEADERS); } { @@ -2393,8 +2393,8 @@ test_vlan_set_xgress(void) g_assert(nm_platform_link_vlan_change(NM_PLATFORM_GET, ifindex, - NM_VLAN_FLAG_GVRP, - NM_VLAN_FLAG_GVRP, + _NM_VLAN_FLAG_GVRP, + _NM_VLAN_FLAG_GVRP, FALSE, ingress_map, G_N_ELEMENTS(ingress_map), @@ -2403,7 +2403,7 @@ test_vlan_set_xgress(void) G_N_ELEMENTS(egress_map))); _assert_ingress_qos_mappings(ifindex, 2, 4, 1, 6, 12); _assert_egress_qos_mappings(ifindex, 2, 1, 7, 64, 4); - _assert_vlan_flags(ifindex, NM_VLAN_FLAG_REORDER_HEADERS | NM_VLAN_FLAG_GVRP); + _assert_vlan_flags(ifindex, _NM_VLAN_FLAG_REORDER_HEADERS | _NM_VLAN_FLAG_GVRP); } nmtstp_link_delete(NULL, -1, ifindex, DEVICE_NAME, TRUE); diff --git a/src/core/platform/tests/test-nmp-object.c b/src/core/platform/tests/test-nmp-object.c index 6f8be00d10..6d2236ecb8 100644 --- a/src/core/platform/tests/test-nmp-object.c +++ b/src/core/platform/tests/test-nmp-object.c @@ -8,7 +8,7 @@ #include <libudev.h> #include <linux/pkt_sched.h> -#include "platform/nmp-object.h" +#include "libnm-platform/nmp-object.h" #include "libnm-udev-aux/nm-udev-utils.h" #include "nm-test-utils-core.h" diff --git a/src/core/platform/tests/test-platform-general.c b/src/core/platform/tests/test-platform-general.c index 796500d510..685cd18aa7 100644 --- a/src/core/platform/tests/test-platform-general.c +++ b/src/core/platform/tests/test-platform-general.c @@ -8,7 +8,7 @@ #include <linux/rtnetlink.h> #include "libnm-platform/nm-platform-utils.h" -#include "platform/nm-linux-platform.h" +#include "libnm-platform/nm-linux-platform.h" #include "nm-test-utils-core.h" diff --git a/src/core/platform/tests/test-route.c b/src/core/platform/tests/test-route.c index 6fdb2f5b24..2b9b2f8f67 100644 --- a/src/core/platform/tests/test-route.c +++ b/src/core/platform/tests/test-route.c @@ -10,7 +10,7 @@ #include "nm-core-utils.h" #include "libnm-platform/nm-platform-utils.h" -#include "platform/nmp-rules-manager.h" +#include "libnm-platform/nmp-rules-manager.h" #include "test-common.h" diff --git a/src/core/platform/tests/test-tc.c b/src/core/platform/tests/test-tc.c index e0c102e6cc..cd9536cced 100644 --- a/src/core/platform/tests/test-tc.c +++ b/src/core/platform/tests/test-tc.c @@ -5,7 +5,7 @@ #include <linux/pkt_sched.h> #include "nm-test-utils-core.h" -#include "platform/nmp-object.h" +#include "libnm-platform/nmp-object.h" #include "libnm-platform/nmp-netns.h" #include "libnm-platform/nm-platform-utils.h" #include "test-common.h" diff --git a/src/core/ppp/nm-ppp-manager.c b/src/core/ppp/nm-ppp-manager.c index eebb82311c..137fccf31f 100644 --- a/src/core/ppp/nm-ppp-manager.c +++ b/src/core/ppp/nm-ppp-manager.c @@ -28,7 +28,8 @@ #include <linux/rtnetlink.h> #include "NetworkManagerUtils.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" +#include "libnm-platform/nm-platform-utils.h" #include "libnm-core-intern/nm-core-internal.h" #include "nm-act-request.h" #include "nm-ip4-config.h" @@ -998,7 +999,7 @@ _ppp_manager_start(NMPPPManager *self, /* Make sure /dev/ppp exists (bgo #533064) */ if (stat("/dev/ppp", &st) || !S_ISCHR(st.st_mode)) - nm_utils_modprobe(NULL, FALSE, "ppp_generic", NULL); + nmp_utils_modprobe(NULL, FALSE, "ppp_generic", NULL); connection = nm_act_request_get_applied_connection(req); g_return_val_if_fail(connection, FALSE); diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index cbe363de02..9100beb8ac 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -42,7 +42,7 @@ #include "nm-utils.h" #include "libnm-base/nm-ethtool-base.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "NetworkManagerUtils.h" #include "nms-ifcfg-rh-common.h" diff --git a/src/core/supplicant/nm-supplicant-interface.c b/src/core/supplicant/nm-supplicant-interface.c index 020b2c2c6b..7cb3df9ad8 100644 --- a/src/core/supplicant/nm-supplicant-interface.c +++ b/src/core/supplicant/nm-supplicant-interface.c @@ -557,7 +557,7 @@ _bss_info_properties_changed(NMSupplicantInterface *self, guint16 v_u16; guint32 v_u32; NM80211ApFlags p_ap_flags; - NM80211Mode p_mode; + _NM80211Mode p_mode; guint8 p_signal_percent; const guint8 * arr_data; gsize arr_len; @@ -605,15 +605,15 @@ _bss_info_properties_changed(NMSupplicantInterface *self, if (nm_g_variant_lookup(properties, "Mode", "&s", &v_s)) { if (nm_streq(v_s, "infrastructure")) - p_mode = NM_802_11_MODE_INFRA; + p_mode = _NM_802_11_MODE_INFRA; else if (nm_streq(v_s, "ad-hoc")) - p_mode = NM_802_11_MODE_ADHOC; + p_mode = _NM_802_11_MODE_ADHOC; else if (nm_streq(v_s, "mesh")) - p_mode = NM_802_11_MODE_MESH; + p_mode = _NM_802_11_MODE_MESH; else - p_mode = NM_802_11_MODE_UNKNOWN; + p_mode = _NM_802_11_MODE_UNKNOWN; } else if (initial) - p_mode = NM_802_11_MODE_UNKNOWN; + p_mode = _NM_802_11_MODE_UNKNOWN; else p_mode = bss_info->mode; if (bss_info->mode != p_mode) { diff --git a/src/core/supplicant/nm-supplicant-manager.c b/src/core/supplicant/nm-supplicant-manager.c index e9b084f0bd..8db44c46ef 100644 --- a/src/core/supplicant/nm-supplicant-manager.c +++ b/src/core/supplicant/nm-supplicant-manager.c @@ -14,7 +14,7 @@ #include "libnm-glib-aux/nm-ref-string.h" #include "nm-supplicant-interface.h" #include "nm-supplicant-types.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" /*****************************************************************************/ diff --git a/src/core/supplicant/nm-supplicant-types.h b/src/core/supplicant/nm-supplicant-types.h index ae2db3f6eb..58ec90c4f8 100644 --- a/src/core/supplicant/nm-supplicant-types.h +++ b/src/core/supplicant/nm-supplicant-types.h @@ -7,6 +7,7 @@ #define __NETWORKMANAGER_SUPPLICANT_TYPES_H__ #include "c-list/src/c-list.h" +#include "libnm-base/nm-base.h" #define NM_WPAS_DBUS_SERVICE "fi.w1.wpa_supplicant1" #define NM_WPAS_DBUS_PATH "/fi/w1/wpa_supplicant1" @@ -178,7 +179,7 @@ typedef struct _NMSupplicantBssInfo { NM80211ApFlags ap_flags : 5; - NM80211Mode mode : 4; + _NM80211Mode mode : 4; bool bssid_valid : 1; diff --git a/src/core/tests/test-core-with-expect.c b/src/core/tests/test-core-with-expect.c index 022cf8f39e..01784863b9 100644 --- a/src/core/tests/test-core-with-expect.c +++ b/src/core/tests/test-core-with-expect.c @@ -11,6 +11,7 @@ #include <fcntl.h> #include "NetworkManagerUtils.h" +#include "libnm-platform/nm-platform-utils.h" #include "nm-test-utils-core.h" @@ -586,7 +587,7 @@ test_nm_ethernet_address_is_valid(void) /*****************************************************************************/ static void -test_nm_utils_new_vlan_name(void) +test_nmp_utils_new_vlan_name(void) { guint i, j; const char *parent_names[] = { @@ -614,7 +615,7 @@ test_nm_utils_new_vlan_name(void) vlan_id_s = g_strdup_printf(".%d", vlan_id); - ifname = nm_utils_new_vlan_name(parent_names[i], vlan_id); + ifname = nmp_utils_new_vlan_name(parent_names[i], vlan_id); g_assert(ifname && ifname[0]); g_assert_cmpint(strlen(ifname), ==, @@ -643,7 +644,7 @@ main(int argc, char **argv) g_test_add_func("/general/nm_utils_array_remove_at_indexes", test_nm_utils_array_remove_at_indexes); g_test_add_func("/general/nm_ethernet_address_is_valid", test_nm_ethernet_address_is_valid); - g_test_add_func("/general/nm_utils_new_vlan_name", test_nm_utils_new_vlan_name); + g_test_add_func("/general/nmp_utils_new_vlan_name", test_nmp_utils_new_vlan_name); return g_test_run(); } diff --git a/src/core/tests/test-core.c b/src/core/tests/test-core.c index fc4a217e81..f212886331 100644 --- a/src/core/tests/test-core.c +++ b/src/core/tests/test-core.c @@ -867,7 +867,7 @@ test_connection_no_match_vlan(void) /* Check that the connections do not match if VLAN flags differ */ s_vlan_orig = nm_connection_get_setting_vlan(orig); g_assert(s_vlan_orig); - g_object_set(G_OBJECT(s_vlan_orig), NM_SETTING_VLAN_FLAGS, NM_VLAN_FLAG_REORDER_HEADERS, NULL); + g_object_set(G_OBJECT(s_vlan_orig), NM_SETTING_VLAN_FLAGS, _NM_VLAN_FLAG_REORDER_HEADERS, NULL); s_vlan_copy = nm_connection_get_setting_vlan(copy); g_assert(s_vlan_copy); diff --git a/src/core/tests/test-ip4-config.c b/src/core/tests/test-ip4-config.c index 27b1d61139..3a095d4ad9 100644 --- a/src/core/tests/test-ip4-config.c +++ b/src/core/tests/test-ip4-config.c @@ -8,7 +8,7 @@ #include <arpa/inet.h> #include "nm-ip4-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-test-utils-core.h" diff --git a/src/core/tests/test-ip6-config.c b/src/core/tests/test-ip6-config.c index 3b48fb7f38..ddf4c789c8 100644 --- a/src/core/tests/test-ip6-config.c +++ b/src/core/tests/test-ip6-config.c @@ -10,7 +10,7 @@ #include "nm-ip6-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-test-utils-core.h" static NMIP6Config * diff --git a/src/core/tests/test-l3cfg.c b/src/core/tests/test-l3cfg.c index 43132c6d93..f2af928a8a 100644 --- a/src/core/tests/test-l3cfg.c +++ b/src/core/tests/test-l3cfg.c @@ -5,7 +5,7 @@ #include "nm-l3cfg.h" #include "nm-l3-ipv4ll.h" #include "nm-netns.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "platform/tests/test-common.h" diff --git a/src/core/vpn/nm-vpn-connection.c b/src/core/vpn/nm-vpn-connection.c index 3d110b2888..ba5e36dab2 100644 --- a/src/core/vpn/nm-vpn-connection.c +++ b/src/core/vpn/nm-vpn-connection.c @@ -19,7 +19,7 @@ #include "nm-proxy-config.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" -#include "platform/nm-platform.h" +#include "libnm-platform/nm-platform.h" #include "nm-active-connection.h" #include "NetworkManagerUtils.h" #include "settings/nm-settings-connection.h" diff --git a/src/libnm-base/nm-base.h b/src/libnm-base/nm-base.h index 105d1783e7..138e8b04b2 100644 --- a/src/libnm-base/nm-base.h +++ b/src/libnm-base/nm-base.h @@ -153,6 +153,7 @@ nm_ethtool_id_is_ring(NMEthtoolID id) /*****************************************************************************/ typedef enum { + /* Mirrors libnm's NMSettingWiredWakeOnLan */ _NM_SETTING_WIRED_WAKE_ON_LAN_NONE = 0, _NM_SETTING_WIRED_WAKE_ON_LAN_PHY = 0x2, _NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST = 0x4, @@ -168,6 +169,65 @@ typedef enum { _NM_SETTING_WIRED_WAKE_ON_LAN_EXCLUSIVE_FLAGS = 0x8001, } _NMSettingWiredWakeOnLan; +typedef enum { + /* Mirrors libnm's NMSettingWirelessWakeOnWLan */ + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE = 0, + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_ANY = 0x2, + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_DISCONNECT = 0x4, + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_MAGIC = 0x8, + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_GTK_REKEY_FAILURE = 0x10, + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_EAP_IDENTITY_REQUEST = 0x20, + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_4WAY_HANDSHAKE = 0x40, + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_RFKILL_RELEASE = 0x80, + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_TCP = 0x100, + + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_ALL = 0x1FE, + + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_DEFAULT = 0x1, + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE = 0x8000, + + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_EXCLUSIVE_FLAGS = + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_DEFAULT | _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE, +} _NMSettingWirelessWakeOnWLan; + +typedef enum { + /* Mirrors libnm's NMDeviceWifiCapabilities */ + _NM_WIFI_DEVICE_CAP_NONE = 0x00000000, + _NM_WIFI_DEVICE_CAP_CIPHER_WEP40 = 0x00000001, + _NM_WIFI_DEVICE_CAP_CIPHER_WEP104 = 0x00000002, + _NM_WIFI_DEVICE_CAP_CIPHER_TKIP = 0x00000004, + _NM_WIFI_DEVICE_CAP_CIPHER_CCMP = 0x00000008, + _NM_WIFI_DEVICE_CAP_WPA = 0x00000010, + _NM_WIFI_DEVICE_CAP_RSN = 0x00000020, + _NM_WIFI_DEVICE_CAP_AP = 0x00000040, + _NM_WIFI_DEVICE_CAP_ADHOC = 0x00000080, + _NM_WIFI_DEVICE_CAP_FREQ_VALID = 0x00000100, + _NM_WIFI_DEVICE_CAP_FREQ_2GHZ = 0x00000200, + _NM_WIFI_DEVICE_CAP_FREQ_5GHZ = 0x00000400, + _NM_WIFI_DEVICE_CAP_MESH = 0x00001000, + _NM_WIFI_DEVICE_CAP_IBSS_RSN = 0x00002000, +} _NMDeviceWifiCapabilities; + +typedef enum { + /* Mirrors libnm's NM80211Mode */ + _NM_802_11_MODE_UNKNOWN = 0, + _NM_802_11_MODE_ADHOC = 1, + _NM_802_11_MODE_INFRA = 2, + _NM_802_11_MODE_AP = 3, + _NM_802_11_MODE_MESH = 4, +} _NM80211Mode; + +typedef enum { + /* Mirrors libnm's NMVlanFlags */ + _NM_VLAN_FLAG_REORDER_HEADERS = 0x1, + _NM_VLAN_FLAG_GVRP = 0x2, + _NM_VLAN_FLAG_LOOSE_BINDING = 0x4, + _NM_VLAN_FLAG_MVRP = 0x8, + + _NM_VLAN_FLAGS_ALL = _NM_VLAN_FLAG_REORDER_HEADERS | _NM_VLAN_FLAG_GVRP + | _NM_VLAN_FLAG_LOOSE_BINDING | _NM_VLAN_FLAG_MVRP, +} _NMVlanFlags; + /*****************************************************************************/ typedef enum { @@ -205,6 +265,105 @@ NM_IS_IP_CONFIG_SOURCE_RTPROT(NMIPConfigSource source) return source > NM_IP_CONFIG_SOURCE_UNKNOWN && source <= _NM_IP_CONFIG_SOURCE_RTPROT_LAST; } +/*****************************************************************************/ + +/* IEEE 802.1D-1998 timer values */ +#define NM_BRIDGE_HELLO_TIME_MIN 1u +#define NM_BRIDGE_HELLO_TIME_DEF 2u +#define NM_BRIDGE_HELLO_TIME_DEF_SYS (NM_BRIDGE_HELLO_TIME_DEF * 100u) +#define NM_BRIDGE_HELLO_TIME_MAX 10u + +#define NM_BRIDGE_FORWARD_DELAY_MIN 2u +#define NM_BRIDGE_FORWARD_DELAY_DEF 15u +#define NM_BRIDGE_FORWARD_DELAY_DEF_SYS (NM_BRIDGE_FORWARD_DELAY_DEF * 100u) +#define NM_BRIDGE_FORWARD_DELAY_MAX 30u + +#define NM_BRIDGE_MAX_AGE_MIN 6u +#define NM_BRIDGE_MAX_AGE_DEF 20u +#define NM_BRIDGE_MAX_AGE_DEF_SYS (NM_BRIDGE_MAX_AGE_DEF * 100u) +#define NM_BRIDGE_MAX_AGE_MAX 40u + +/* IEEE 802.1D-1998 Table 7.4 */ +#define NM_BRIDGE_AGEING_TIME_MIN 0u +#define NM_BRIDGE_AGEING_TIME_DEF 300u +#define NM_BRIDGE_AGEING_TIME_DEF_SYS (NM_BRIDGE_AGEING_TIME_DEF * 100u) +#define NM_BRIDGE_AGEING_TIME_MAX 1000000u + +#define NM_BRIDGE_PORT_PRIORITY_MIN 0u +#define NM_BRIDGE_PORT_PRIORITY_DEF 32u +#define NM_BRIDGE_PORT_PRIORITY_MAX 63u + +#define NM_BRIDGE_PORT_PATH_COST_MIN 0u +#define NM_BRIDGE_PORT_PATH_COST_DEF 100u +#define NM_BRIDGE_PORT_PATH_COST_MAX 65535u + +#define NM_BRIDGE_MULTICAST_HASH_MAX_MIN 1u +#define NM_BRIDGE_MULTICAST_HASH_MAX_DEF 4096u +#define NM_BRIDGE_MULTICAST_HASH_MAX_MAX ((guint) G_MAXUINT32) + +#define NM_BRIDGE_STP_DEF TRUE + +#define NM_BRIDGE_GROUP_ADDRESS_DEF_BIN 0x01, 0x80, 0xC2, 0x00, 0x00, 0x00 +#define NM_BRIDGE_GROUP_ADDRESS_DEF_STR "01:80:C2:00:00:00" + +#define NM_BRIDGE_PRIORITY_MIN 0u +#define NM_BRIDGE_PRIORITY_DEF 0x8000u +#define NM_BRIDGE_PRIORITY_MAX ((guint) G_MAXUINT16) + +#define NM_BRIDGE_MULTICAST_LAST_MEMBER_COUNT_MIN 0u +#define NM_BRIDGE_MULTICAST_LAST_MEMBER_COUNT_DEF 2u +#define NM_BRIDGE_MULTICAST_LAST_MEMBER_COUNT_MAX ((guint) G_MAXUINT32) + +#define NM_BRIDGE_MULTICAST_LAST_MEMBER_INTERVAL_MIN ((guint64) 0) +#define NM_BRIDGE_MULTICAST_LAST_MEMBER_INTERVAL_DEF ((guint64) 100) +#define NM_BRIDGE_MULTICAST_LAST_MEMBER_INTERVAL_MAX G_MAXUINT64 + +#define NM_BRIDGE_MULTICAST_MEMBERSHIP_INTERVAL_MIN ((guint64) 0) +#define NM_BRIDGE_MULTICAST_MEMBERSHIP_INTERVAL_DEF ((guint64) 26000) +#define NM_BRIDGE_MULTICAST_MEMBERSHIP_INTERVAL_MAX G_MAXUINT64 + +#define NM_BRIDGE_MULTICAST_QUERIER_INTERVAL_MIN ((guint64) 0) +#define NM_BRIDGE_MULTICAST_QUERIER_INTERVAL_DEF ((guint64) 25500) +#define NM_BRIDGE_MULTICAST_QUERIER_INTERVAL_MAX G_MAXUINT64 + +#define NM_BRIDGE_MULTICAST_QUERIER_DEF FALSE + +#define NM_BRIDGE_MULTICAST_QUERY_INTERVAL_MIN ((guint64) 0) +#define NM_BRIDGE_MULTICAST_QUERY_INTERVAL_DEF ((guint64) 12500) +#define NM_BRIDGE_MULTICAST_QUERY_INTERVAL_MAX G_MAXUINT64 + +#define NM_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL_MIN ((guint64) 0) +#define NM_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL_DEF ((guint64) 1000) +#define NM_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL_MAX G_MAXUINT64 + +#define NM_BRIDGE_MULTICAST_QUERY_USE_IFADDR_DEF FALSE + +#define NM_BRIDGE_MULTICAST_SNOOPING_DEF TRUE + +#define NM_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT_MIN 0u +#define NM_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT_DEF 2u +#define NM_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT_MAX ((guint) G_MAXUINT32) + +#define NM_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL_MIN ((guint64) 0) +#define NM_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL_DEF ((guint64) 3125) +#define NM_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL_MAX G_MAXUINT64 + +#define NM_BRIDGE_VLAN_STATS_ENABLED_DEF FALSE + +#define NM_BRIDGE_VLAN_DEFAULT_PVID_DEF 1u + +/*****************************************************************************/ + +typedef struct { + guint32 from; + guint32 to; +} NMVlanQosMapping; + +#define _NM_IP_TUNNEL_FLAG_ALL_IP6TNL \ + (NM_IP_TUNNEL_FLAG_IP6_IGN_ENCAP_LIMIT | NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_TCLASS \ + | NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FLOWLABEL | NM_IP_TUNNEL_FLAG_IP6_MIP6_DEV \ + | NM_IP_TUNNEL_FLAG_IP6_RCV_DSCP_COPY | NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FWMARK) + /****************************************************************************/ #endif /* __NM_LIBNM_BASE_H__ */ diff --git a/src/libnm-core-aux-intern/nm-libnm-core-utils.c b/src/libnm-core-aux-intern/nm-libnm-core-utils.c index 87dc1e9ebd..78daac44c2 100644 --- a/src/libnm-core-aux-intern/nm-libnm-core-utils.c +++ b/src/libnm-core-aux-intern/nm-libnm-core-utils.c @@ -276,34 +276,6 @@ nm_client_permission_result_to_string(NMClientPermissionResult permission) return NULL; } -NM_UTILS_STRING_TABLE_LOOKUP_DEFINE( - nm_utils_route_type_by_name, - guint8, - { nm_assert(name); }, - { return RTN_UNSPEC; }, - {"blackhole", RTN_BLACKHOLE}, - {"broadcast", RTN_BROADCAST}, - {"local", RTN_LOCAL}, - {"multicast", RTN_MULTICAST}, - {"nat", RTN_NAT}, - {"prohibit", RTN_PROHIBIT}, - {"throw", RTN_THROW}, - {"unicast", RTN_UNICAST}, - {"unreachable", RTN_UNREACHABLE}, ); - -NM_UTILS_ENUM2STR_DEFINE(nm_utils_route_type2str, - guint8, - NM_UTILS_ENUM2STR(RTN_BLACKHOLE, "blackhole"), - NM_UTILS_ENUM2STR(RTN_BROADCAST, "broadcast"), - NM_UTILS_ENUM2STR(RTN_LOCAL, "local"), - NM_UTILS_ENUM2STR(RTN_MULTICAST, "multicast"), - NM_UTILS_ENUM2STR(RTN_NAT, "nat"), - NM_UTILS_ENUM2STR(RTN_PROHIBIT, "prohibit"), - NM_UTILS_ENUM2STR(RTN_THROW, "throw"), - NM_UTILS_ENUM2STR(RTN_UNICAST, "unicast"), - NM_UTILS_ENUM2STR(RTN_UNREACHABLE, "unreachable"), - NM_UTILS_ENUM2STR(RTN_UNSPEC, "unspecified"), ); - gboolean nm_utils_validate_dhcp4_vendor_class_id(const char *vci, GError **error) { diff --git a/src/libnm-core-aux-intern/nm-libnm-core-utils.h b/src/libnm-core-aux-intern/nm-libnm-core-utils.h index 946c7a2c0e..e2a350e57a 100644 --- a/src/libnm-core-aux-intern/nm-libnm-core-utils.h +++ b/src/libnm-core-aux-intern/nm-libnm-core-utils.h @@ -146,10 +146,6 @@ NMClientPermission nm_auth_permission_from_string(const char *str); NMClientPermissionResult nm_client_permission_result_from_string(const char *nm); const char * nm_client_permission_result_to_string(NMClientPermissionResult permission); -guint8 nm_utils_route_type_by_name(const char *name); - -const char *nm_utils_route_type2str(guint8 val, char *buf, gsize len); - gboolean nm_utils_validate_dhcp4_vendor_class_id(const char *vci, GError **error); /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-macsec.c b/src/libnm-core-impl/nm-setting-macsec.c index f9a3a7818c..8cb0f280e0 100644 --- a/src/libnm-core-impl/nm-setting-macsec.c +++ b/src/libnm-core-impl/nm-setting-macsec.c @@ -12,7 +12,6 @@ #include "libnm-glib-aux/nm-secret-utils.h" #include "nm-utils.h" -#include "libnm-core-intern/nm-core-types-internal.h" #include "nm-setting-connection.h" #include "nm-setting-private.h" #include "nm-setting-wired.h" diff --git a/src/libnm-core-impl/nm-setting-vlan.c b/src/libnm-core-impl/nm-setting-vlan.c index e0cad6a614..0d2855587b 100644 --- a/src/libnm-core-impl/nm-setting-vlan.c +++ b/src/libnm-core-impl/nm-setting-vlan.c @@ -11,7 +11,6 @@ #include "libnm-core-aux-intern/nm-libnm-core-utils.h" #include "nm-utils.h" -#include "libnm-core-intern/nm-core-types-internal.h" #include "nm-setting-connection.h" #include "nm-setting-private.h" #include "nm-setting-wired.h" diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index b493b06f50..1296b6db12 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -630,28 +630,7 @@ _nm_utils_ssid_to_utf8(GBytes *ssid) gboolean nm_utils_is_empty_ssid(const guint8 *ssid, gsize len) { - /* Single white space is for Linksys APs */ - if (len == 1 && ssid[0] == ' ') - return TRUE; - - /* Otherwise, if the entire ssid is 0, we assume it is hidden */ - while (len--) { - if (ssid[len] != '\0') - return FALSE; - } - return TRUE; -} - -gboolean -_nm_utils_is_empty_ssid(GBytes *ssid) -{ - const guint8 *p; - gsize l; - - g_return_val_if_fail(ssid, FALSE); - - p = g_bytes_get_data(ssid, &l); - return nm_utils_is_empty_ssid(p, l); + return _nm_utils_is_empty_ssid_arr(ssid, len); } #define ESSID_MAX_SIZE 32 @@ -695,38 +674,6 @@ nm_utils_escape_ssid(const guint8 *ssid, gsize len) return escaped; } -char * -_nm_utils_ssid_to_string_arr(const guint8 *ssid, gsize len) -{ - gs_free char *s_copy = NULL; - const char * s_cnst; - - if (len == 0) - return g_strdup("(empty)"); - - s_cnst = - nm_utils_buf_utf8safe_escape(ssid, len, NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, &s_copy); - nm_assert(s_cnst); - - if (nm_utils_is_empty_ssid(ssid, len)) - return g_strdup_printf("\"%s\" (hidden)", s_cnst); - - return g_strdup_printf("\"%s\"", s_cnst); -} - -char * -_nm_utils_ssid_to_string(GBytes *ssid) -{ - gconstpointer p; - gsize l; - - if (!ssid) - return g_strdup("(none)"); - - p = g_bytes_get_data(ssid, &l); - return _nm_utils_ssid_to_string_arr(p, l); -} - /** * nm_utils_same_ssid: * @ssid1: (array length=len1): the first SSID to compare @@ -877,30 +824,6 @@ _nm_utils_copy_object_array(const GPtrArray *array) return _nm_utils_copy_array(array, g_object_ref, g_object_unref); } -gssize -_nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpointer needle) -{ - gssize i; - - if (len == 0) - return -1; - - if (len > 0) { - g_return_val_if_fail(list, -1); - for (i = 0; i < len; i++) { - if (list[i] == needle) - return i; - } - } else { - g_return_val_if_fail(needle, -1); - for (i = 0; list && list[i]; i++) { - if (list[i] == needle) - return i; - } - } - return -1; -} - void _nm_utils_bytes_from_dbus(GVariant *dbus_value, GValue *prop_value) { @@ -4839,29 +4762,6 @@ nm_utils_ipaddr_valid(int family, const char *ip) } /** - * nm_utils_iinet6_is_token: - * @in6addr: the AF_INET6 address structure - * - * Checks if only the bottom 64bits of the address are set. - * - * Return value: %TRUE or %FALSE - */ -gboolean -_nm_utils_inet6_is_token(const struct in6_addr *in6addr) -{ - if (in6addr->s6_addr[0] || in6addr->s6_addr[1] || in6addr->s6_addr[2] || in6addr->s6_addr[3] - || in6addr->s6_addr[4] || in6addr->s6_addr[5] || in6addr->s6_addr[6] || in6addr->s6_addr[7]) - return FALSE; - - if (in6addr->s6_addr[8] || in6addr->s6_addr[9] || in6addr->s6_addr[10] || in6addr->s6_addr[11] - || in6addr->s6_addr[12] || in6addr->s6_addr[13] || in6addr->s6_addr[14] - || in6addr->s6_addr[15]) - return TRUE; - - return FALSE; -} - -/** * _nm_utils_dhcp_duid_valid: * @duid: the candidate DUID * diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index c1465c9a12..0fb130997c 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -156,6 +156,201 @@ test_wired_wake_on_lan_enum(void) /*****************************************************************************/ +static void +test_wireless_wake_on_wlan_enum(void) +{ + nm_auto_unref_gtypeclass GFlagsClass *flags_class = NULL; + gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); + guint i; + + G_STATIC_ASSERT_EXPR(sizeof(NMSettingWirelessWakeOnWLan) + == sizeof(_NMSettingWirelessWakeOnWLan)); + G_STATIC_ASSERT_EXPR(sizeof(NMSettingWirelessWakeOnWLan) < sizeof(gint64)); + + G_STATIC_ASSERT_EXPR(sizeof(NMSettingWirelessWakeOnWLan) < sizeof(gint64)); + g_assert((((gint64)((NMSettingWirelessWakeOnWLan) -1)) < 0) + == (((gint64)((_NMSettingWirelessWakeOnWLan) -1)) < 0)); + +#define _E(n) \ + G_STMT_START \ + { \ + G_STATIC_ASSERT_EXPR(n == (gint64) _##n); \ + G_STATIC_ASSERT_EXPR(_##n == (gint64) n); \ + g_assert(_##n == _NM_SETTING_WIRELESS_WAKE_ON_WLAN_CAST(n)); \ + if (!g_hash_table_add(vals, GUINT_TO_POINTER(n))) \ + g_assert_not_reached(); \ + } \ + G_STMT_END + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE); + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_ANY); + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_DISCONNECT); + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_MAGIC); + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_GTK_REKEY_FAILURE); + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_EAP_IDENTITY_REQUEST); + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_4WAY_HANDSHAKE); + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_RFKILL_RELEASE); + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_TCP); + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_ALL); + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_DEFAULT); + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE); + _E(NM_SETTING_WIRELESS_WAKE_ON_WLAN_EXCLUSIVE_FLAGS); +#undef _E + + flags_class = G_FLAGS_CLASS(g_type_class_ref(NM_TYPE_SETTING_WIRELESS_WAKE_ON_WLAN)); + for (i = 0; i < flags_class->n_values; i++) { + const GFlagsValue *value = &flags_class->values[i]; + + if (!g_hash_table_contains(vals, GUINT_TO_POINTER(value->value))) { + g_error("The enum value %s from NMSettingWirelessWakeOnWLan is not checked for " + "_NMSettingWirelessWakeOnWLan", + value->value_name); + } + } +} + +/*****************************************************************************/ + +static void +test_device_wifi_capabilities(void) +{ + nm_auto_unref_gtypeclass GFlagsClass *flags_class = NULL; + gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); + guint i; + + G_STATIC_ASSERT_EXPR(sizeof(NMDeviceWifiCapabilities) == sizeof(_NMDeviceWifiCapabilities)); + G_STATIC_ASSERT_EXPR(sizeof(NMDeviceWifiCapabilities) < sizeof(gint64)); + + G_STATIC_ASSERT_EXPR(sizeof(NMDeviceWifiCapabilities) < sizeof(gint64)); + g_assert((((gint64)((NMDeviceWifiCapabilities) -1)) < 0) + == (((gint64)((_NMDeviceWifiCapabilities) -1)) < 0)); + +#define _E(n) \ + G_STMT_START \ + { \ + G_STATIC_ASSERT_EXPR(n == (gint64) _##n); \ + G_STATIC_ASSERT_EXPR(_##n == (gint64) n); \ + if (!g_hash_table_add(vals, GUINT_TO_POINTER(n))) \ + g_assert_not_reached(); \ + } \ + G_STMT_END + _E(NM_WIFI_DEVICE_CAP_NONE); + _E(NM_WIFI_DEVICE_CAP_CIPHER_WEP40); + _E(NM_WIFI_DEVICE_CAP_CIPHER_WEP104); + _E(NM_WIFI_DEVICE_CAP_CIPHER_TKIP); + _E(NM_WIFI_DEVICE_CAP_CIPHER_CCMP); + _E(NM_WIFI_DEVICE_CAP_WPA); + _E(NM_WIFI_DEVICE_CAP_RSN); + _E(NM_WIFI_DEVICE_CAP_AP); + _E(NM_WIFI_DEVICE_CAP_ADHOC); + _E(NM_WIFI_DEVICE_CAP_FREQ_VALID); + _E(NM_WIFI_DEVICE_CAP_FREQ_2GHZ); + _E(NM_WIFI_DEVICE_CAP_FREQ_5GHZ); + _E(NM_WIFI_DEVICE_CAP_MESH); + _E(NM_WIFI_DEVICE_CAP_IBSS_RSN); +#undef _E + + flags_class = G_FLAGS_CLASS(g_type_class_ref(NM_TYPE_DEVICE_WIFI_CAPABILITIES)); + for (i = 0; i < flags_class->n_values; i++) { + const GFlagsValue *value = &flags_class->values[i]; + + if (!g_hash_table_contains(vals, GUINT_TO_POINTER(value->value))) { + g_error("The enum value %s from NMDeviceWifiCapabilities is not checked for " + "_NMDeviceWifiCapabilities", + value->value_name); + } + } +} + +/*****************************************************************************/ + +static void +test_80211_mode(void) +{ + nm_auto_unref_gtypeclass GEnumClass *enum_class = NULL; + gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); + guint i; + + G_STATIC_ASSERT_EXPR(sizeof(NM80211Mode) == sizeof(_NM80211Mode)); + G_STATIC_ASSERT_EXPR(sizeof(NM80211Mode) < sizeof(gint64)); + + G_STATIC_ASSERT_EXPR(sizeof(NM80211Mode) < sizeof(gint64)); + g_assert((((gint64)((NM80211Mode) -1)) < 0) == (((gint64)((_NM80211Mode) -1)) < 0)); + +#define _E(n) \ + G_STMT_START \ + { \ + G_STATIC_ASSERT_EXPR(n == (gint64) _##n); \ + G_STATIC_ASSERT_EXPR(_##n == (gint64) n); \ + g_assert(n == NM_802_11_MODE_CAST(_##n)); \ + if (!g_hash_table_add(vals, GINT_TO_POINTER(n))) \ + g_assert_not_reached(); \ + } \ + G_STMT_END + _E(NM_802_11_MODE_UNKNOWN); + _E(NM_802_11_MODE_ADHOC); + _E(NM_802_11_MODE_INFRA); + _E(NM_802_11_MODE_AP); + _E(NM_802_11_MODE_MESH); +#undef _E + + enum_class = G_ENUM_CLASS(g_type_class_ref(NM_TYPE_802_11_MODE)); + for (i = 0; i < enum_class->n_values; i++) { + const GEnumValue *value = &enum_class->values[i]; + + if (!g_hash_table_contains(vals, GINT_TO_POINTER(value->value))) { + g_error("The enum value %s from NM80211Mode is not checked for " + "_NM80211Mode", + value->value_name); + } + } +} + +/*****************************************************************************/ + +static void +test_vlan_flags(void) +{ + nm_auto_unref_gtypeclass GFlagsClass *flags_class = NULL; + gs_unref_hashtable GHashTable *vals = g_hash_table_new(nm_direct_hash, NULL); + guint i; + + G_STATIC_ASSERT_EXPR(sizeof(NMVlanFlags) == sizeof(_NMVlanFlags)); + G_STATIC_ASSERT_EXPR(sizeof(NMVlanFlags) < sizeof(gint64)); + + G_STATIC_ASSERT_EXPR(sizeof(NMVlanFlags) < sizeof(gint64)); + g_assert((((gint64)((NMVlanFlags) -1)) < 0) == (((gint64)((_NMVlanFlags) -1)) < 0)); + +#define _E(n) \ + G_STMT_START \ + { \ + G_STATIC_ASSERT_EXPR(n == (gint64) _##n); \ + G_STATIC_ASSERT_EXPR(_##n == (gint64) n); \ + g_assert(n == NM_VLAN_FLAGS_CAST(_##n)); \ + if (!g_hash_table_add(vals, GUINT_TO_POINTER(n))) \ + g_assert_not_reached(); \ + } \ + G_STMT_END + _E(NM_VLAN_FLAG_REORDER_HEADERS); + _E(NM_VLAN_FLAG_GVRP); + _E(NM_VLAN_FLAG_LOOSE_BINDING); + _E(NM_VLAN_FLAG_MVRP); + _E(NM_VLAN_FLAGS_ALL); +#undef _E + + flags_class = G_FLAGS_CLASS(g_type_class_ref(NM_TYPE_VLAN_FLAGS)); + for (i = 0; i < flags_class->n_values; i++) { + const GFlagsValue *value = &flags_class->values[i]; + + if (!g_hash_table_contains(vals, GUINT_TO_POINTER(value->value))) { + g_error("The enum value %s from NMVlanFlags is not checked for " + "_NMVlanFlags", + value->value_name); + } + } +} + +/*****************************************************************************/ + typedef struct _nm_packed { int v0; char v1; @@ -8423,7 +8618,7 @@ _test_find_binary_search_do(const int *array, gsize len) for (i = 0; i < len; i++) parray[i] = GINT_TO_POINTER(array[i]); - expected_result = _nm_utils_ptrarray_find_first(parray, len, pneedle); + expected_result = nm_utils_ptrarray_find_first(parray, len, pneedle); idx = nm_utils_ptrarray_find_binary_search(parray, len, @@ -8600,7 +8795,7 @@ test_nm_utils_ptrarray_find_binary_search_with_duplicates(void) &idx_first, &idx_last); - idx_first2 = _nm_utils_ptrarray_find_first(arr, i_len, p); + idx_first2 = nm_utils_ptrarray_find_first(arr, i_len, p); idx2 = nm_utils_array_find_binary_search(arr, sizeof(gpointer), @@ -10326,6 +10521,11 @@ main(int argc, char **argv) g_test_add_func("/core/general/test_nm_ascii_spaces", test_nm_ascii_spaces); g_test_add_func("/core/general/test_wired_wake_on_lan_enum", test_wired_wake_on_lan_enum); + g_test_add_func("/core/general/test_wireless_wake_on_wlan_enum", + test_wireless_wake_on_wlan_enum); + g_test_add_func("/core/general/test_device_wifi_capabilities", test_device_wifi_capabilities); + g_test_add_func("/core/general/test_80211_mode", test_80211_mode); + g_test_add_func("/core/general/test_vlan_flags", test_vlan_flags); g_test_add_func("/core/general/test_nm_hash", test_nm_hash); g_test_add_func("/core/general/test_nm_g_slice_free_fcn", test_nm_g_slice_free_fcn); g_test_add_func("/core/general/test_c_list_sort", test_c_list_sort); diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 237247a92f..8b3ae0c097 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -23,7 +23,6 @@ #include "libnm-base/nm-base.h" #include "nm-connection.h" #include "nm-core-enum-types.h" -#include "nm-core-types-internal.h" #include "nm-meta-setting-base.h" #include "nm-setting-6lowpan.h" #include "nm-setting-8021x.h" @@ -80,91 +79,6 @@ #include "nm-vpn-editor-plugin.h" #include "libnm-core-aux-intern/nm-libnm-core-utils.h" -/* IEEE 802.1D-1998 timer values */ -#define NM_BRIDGE_HELLO_TIME_MIN 1u -#define NM_BRIDGE_HELLO_TIME_DEF 2u -#define NM_BRIDGE_HELLO_TIME_DEF_SYS (NM_BRIDGE_HELLO_TIME_DEF * 100u) -#define NM_BRIDGE_HELLO_TIME_MAX 10u - -#define NM_BRIDGE_FORWARD_DELAY_MIN 2u -#define NM_BRIDGE_FORWARD_DELAY_DEF 15u -#define NM_BRIDGE_FORWARD_DELAY_DEF_SYS (NM_BRIDGE_FORWARD_DELAY_DEF * 100u) -#define NM_BRIDGE_FORWARD_DELAY_MAX 30u - -#define NM_BRIDGE_MAX_AGE_MIN 6u -#define NM_BRIDGE_MAX_AGE_DEF 20u -#define NM_BRIDGE_MAX_AGE_DEF_SYS (NM_BRIDGE_MAX_AGE_DEF * 100u) -#define NM_BRIDGE_MAX_AGE_MAX 40u - -/* IEEE 802.1D-1998 Table 7.4 */ -#define NM_BRIDGE_AGEING_TIME_MIN 0u -#define NM_BRIDGE_AGEING_TIME_DEF 300u -#define NM_BRIDGE_AGEING_TIME_DEF_SYS (NM_BRIDGE_AGEING_TIME_DEF * 100u) -#define NM_BRIDGE_AGEING_TIME_MAX 1000000u - -#define NM_BRIDGE_PORT_PRIORITY_MIN 0u -#define NM_BRIDGE_PORT_PRIORITY_DEF 32u -#define NM_BRIDGE_PORT_PRIORITY_MAX 63u - -#define NM_BRIDGE_PORT_PATH_COST_MIN 0u -#define NM_BRIDGE_PORT_PATH_COST_DEF 100u -#define NM_BRIDGE_PORT_PATH_COST_MAX 65535u - -#define NM_BRIDGE_MULTICAST_HASH_MAX_MIN 1u -#define NM_BRIDGE_MULTICAST_HASH_MAX_DEF 4096u -#define NM_BRIDGE_MULTICAST_HASH_MAX_MAX ((guint) G_MAXUINT32) - -#define NM_BRIDGE_STP_DEF TRUE - -#define NM_BRIDGE_GROUP_ADDRESS_DEF_BIN 0x01, 0x80, 0xC2, 0x00, 0x00, 0x00 -#define NM_BRIDGE_GROUP_ADDRESS_DEF_STR "01:80:C2:00:00:00" - -#define NM_BRIDGE_PRIORITY_MIN 0u -#define NM_BRIDGE_PRIORITY_DEF 0x8000u -#define NM_BRIDGE_PRIORITY_MAX ((guint) G_MAXUINT16) - -#define NM_BRIDGE_MULTICAST_LAST_MEMBER_COUNT_MIN 0u -#define NM_BRIDGE_MULTICAST_LAST_MEMBER_COUNT_DEF 2u -#define NM_BRIDGE_MULTICAST_LAST_MEMBER_COUNT_MAX ((guint) G_MAXUINT32) - -#define NM_BRIDGE_MULTICAST_LAST_MEMBER_INTERVAL_MIN ((guint64) 0) -#define NM_BRIDGE_MULTICAST_LAST_MEMBER_INTERVAL_DEF ((guint64) 100) -#define NM_BRIDGE_MULTICAST_LAST_MEMBER_INTERVAL_MAX G_MAXUINT64 - -#define NM_BRIDGE_MULTICAST_MEMBERSHIP_INTERVAL_MIN ((guint64) 0) -#define NM_BRIDGE_MULTICAST_MEMBERSHIP_INTERVAL_DEF ((guint64) 26000) -#define NM_BRIDGE_MULTICAST_MEMBERSHIP_INTERVAL_MAX G_MAXUINT64 - -#define NM_BRIDGE_MULTICAST_QUERIER_INTERVAL_MIN ((guint64) 0) -#define NM_BRIDGE_MULTICAST_QUERIER_INTERVAL_DEF ((guint64) 25500) -#define NM_BRIDGE_MULTICAST_QUERIER_INTERVAL_MAX G_MAXUINT64 - -#define NM_BRIDGE_MULTICAST_QUERIER_DEF FALSE - -#define NM_BRIDGE_MULTICAST_QUERY_INTERVAL_MIN ((guint64) 0) -#define NM_BRIDGE_MULTICAST_QUERY_INTERVAL_DEF ((guint64) 12500) -#define NM_BRIDGE_MULTICAST_QUERY_INTERVAL_MAX G_MAXUINT64 - -#define NM_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL_MIN ((guint64) 0) -#define NM_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL_DEF ((guint64) 1000) -#define NM_BRIDGE_MULTICAST_QUERY_RESPONSE_INTERVAL_MAX G_MAXUINT64 - -#define NM_BRIDGE_MULTICAST_QUERY_USE_IFADDR_DEF FALSE - -#define NM_BRIDGE_MULTICAST_SNOOPING_DEF TRUE - -#define NM_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT_MIN 0u -#define NM_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT_DEF 2u -#define NM_BRIDGE_MULTICAST_STARTUP_QUERY_COUNT_MAX ((guint) G_MAXUINT32) - -#define NM_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL_MIN ((guint64) 0) -#define NM_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL_DEF ((guint64) 3125) -#define NM_BRIDGE_MULTICAST_STARTUP_QUERY_INTERVAL_MAX G_MAXUINT64 - -#define NM_BRIDGE_VLAN_STATS_ENABLED_DEF FALSE - -#define NM_BRIDGE_VLAN_DEFAULT_PVID_DEF 1u - /* NM_SETTING_COMPARE_FLAG_INFERRABLE: check whether a device-generated * connection can be replaced by a already-defined connection. This flag only * takes into account properties marked with the %NM_SETTING_PARAM_INFERRABLE @@ -222,12 +136,30 @@ _NM_SETTING_WIRED_WAKE_ON_LAN_CAST(NMSettingWiredWakeOnLan v) /* _NMSettingWiredWakeOnLan and NMSettingWiredWakeOnLan enums are really * the same. * - * The former is used by nm-platform (which should have no libnm-core dependency), - * the latter is used by libnm-core. A unit test ensures they are exactly the same, + * The former is used by libnm-platform (which should have no libnm-core* dependency), + * the latter is public API in libnm-core-public. A unit test ensures they are exactly the same, * so we can just cast them. */ return (_NMSettingWiredWakeOnLan) v; } +static inline _NMSettingWirelessWakeOnWLan +_NM_SETTING_WIRELESS_WAKE_ON_WLAN_CAST(NMSettingWirelessWakeOnWLan v) +{ + return (_NMSettingWirelessWakeOnWLan) v; +} + +static inline NM80211Mode +NM_802_11_MODE_CAST(_NM80211Mode v) +{ + return (NM80211Mode) v; +} + +static inline NMVlanFlags +NM_VLAN_FLAGS_CAST(_NMVlanFlags v) +{ + return (NMVlanFlags) v; +} + /*****************************************************************************/ static inline NMTernary @@ -394,8 +326,6 @@ GPtrArray * _nm_utils_copy_array(const GPtrArray *array, NMUtilsCopyFunc copy_func, GDestroyNotify free_func); GPtrArray *_nm_utils_copy_object_array(const GPtrArray *array); -gssize _nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpointer needle); - GSList *_nm_utils_strv_to_slist(char **strv, gboolean deep_copy); char ** _nm_utils_slist_to_strv(const GSList *slist, gboolean deep_copy); @@ -484,10 +414,7 @@ gboolean _nm_dbus_error_has_name(GError *error, const char *dbus_error_name); /*****************************************************************************/ -char * _nm_utils_ssid_to_string_arr(const guint8 *ssid, gsize len); -char * _nm_utils_ssid_to_string(GBytes *ssid); -char * _nm_utils_ssid_to_utf8(GBytes *ssid); -gboolean _nm_utils_is_empty_ssid(GBytes *ssid); +char *_nm_utils_ssid_to_utf8(GBytes *ssid); /*****************************************************************************/ @@ -616,8 +543,6 @@ gboolean _nm_setting_bond_option_supported(const char *option, NMBondMode mode); NMSettingBluetooth *_nm_connection_get_setting_bluetooth_for_nap(NMConnection *connection); -gboolean _nm_utils_inet6_is_token(const struct in6_addr *in6addr); - /*****************************************************************************/ NMTeamLinkWatcher *_nm_team_link_watcher_ref(NMTeamLinkWatcher *watcher); diff --git a/src/libnm-core-intern/nm-core-types-internal.h b/src/libnm-core-intern/nm-core-types-internal.h deleted file mode 100644 index 346458d359..0000000000 --- a/src/libnm-core-intern/nm-core-types-internal.h +++ /dev/null @@ -1,23 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2015 Red Hat, Inc. - */ - -#ifndef NM_CORE_TYPES_INTERNAL_H -#define NM_CORE_TYPES_INTERNAL_H - -#if !((NETWORKMANAGER_COMPILATION) &NM_NETWORKMANAGER_COMPILATION_WITH_LIBNM_CORE_INTERNAL) - #error Cannot use this header. -#endif - -typedef struct { - guint32 from; - guint32 to; -} NMVlanQosMapping; - -#define _NM_IP_TUNNEL_FLAG_ALL_IP6TNL \ - (NM_IP_TUNNEL_FLAG_IP6_IGN_ENCAP_LIMIT | NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_TCLASS \ - | NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FLOWLABEL | NM_IP_TUNNEL_FLAG_IP6_MIP6_DEV \ - | NM_IP_TUNNEL_FLAG_IP6_RCV_DSCP_COPY | NM_IP_TUNNEL_FLAG_IP6_USE_ORIG_FWMARK) - -#endif /* NM_CORE_TYPES_INTERNAL_H */ diff --git a/src/libnm-core-public/nm-setting-vlan.h b/src/libnm-core-public/nm-setting-vlan.h index 4b2ca429cf..af781ee294 100644 --- a/src/libnm-core-public/nm-setting-vlan.h +++ b/src/libnm-core-public/nm-setting-vlan.h @@ -78,6 +78,7 @@ typedef enum { * #NMVlanFlags values control the behavior of the VLAN interface. **/ typedef enum { /*< flags >*/ + NM_VLAN_FLAG_REORDER_HEADERS = 0x1, NM_VLAN_FLAG_GVRP = 0x2, NM_VLAN_FLAG_LOOSE_BINDING = 0x4, @@ -86,7 +87,7 @@ typedef enum { /*< flags >*/ /* NOTE: if adding flags update nm-setting-vlan.c::verify() */ /* NOTE: these flags must correspond to the value from the kernel - * header files. */ + * header files. */ } NMVlanFlags; #define NM_VLAN_FLAGS_ALL \ diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c index 9477cc3e74..d3effc551d 100644 --- a/src/libnm-glib-aux/nm-shared-utils.c +++ b/src/libnm-glib-aux/nm-shared-utils.c @@ -15,6 +15,7 @@ #include <glib-unix.h> #include <net/if.h> #include <net/ethernet.h> +#include <linux/rtnetlink.h> #include "nm-errno.h" #include "nm-str-buf.h" @@ -105,6 +106,112 @@ G_STATIC_ASSERT(ETH_ALEN == 6); /*****************************************************************************/ +/** + * nm_utils_inet6_is_token: + * @in6addr: the AF_INET6 address structure + * + * Checks if only the bottom 64bits of the address are set. + * + * Return value: %TRUE or %FALSE + */ +gboolean +_nm_utils_inet6_is_token(const struct in6_addr *in6addr) +{ + if (in6addr->s6_addr[0] || in6addr->s6_addr[1] || in6addr->s6_addr[2] || in6addr->s6_addr[3] + || in6addr->s6_addr[4] || in6addr->s6_addr[5] || in6addr->s6_addr[6] || in6addr->s6_addr[7]) + return FALSE; + + if (in6addr->s6_addr[8] || in6addr->s6_addr[9] || in6addr->s6_addr[10] || in6addr->s6_addr[11] + || in6addr->s6_addr[12] || in6addr->s6_addr[13] || in6addr->s6_addr[14] + || in6addr->s6_addr[15]) + return TRUE; + + return FALSE; +} + +/** + * nm_utils_ipv6_addr_set_interface_identifier: + * @addr: output token encoded as %in6_addr + * @iid: %NMUtilsIPv6IfaceId interface identifier + * + * Converts the %NMUtilsIPv6IfaceId to an %in6_addr (suitable for use + * with Linux platform). This only copies the lower 8 bytes, ignoring + * the /64 network prefix which is expected to be all-zero for a valid + * token. + */ +void +nm_utils_ipv6_addr_set_interface_identifier(struct in6_addr *addr, const NMUtilsIPv6IfaceId iid) +{ + memcpy(addr->s6_addr + 8, &iid.id_u8, 8); +} + +/** + * nm_utils_ipv6_interface_identifier_get_from_addr: + * @iid: output %NMUtilsIPv6IfaceId interface identifier set from the token + * @addr: token encoded as %in6_addr + * + * Converts the %in6_addr encoded token (as used by Linux platform) to + * the interface identifier. + */ +void +nm_utils_ipv6_interface_identifier_get_from_addr(NMUtilsIPv6IfaceId * iid, + const struct in6_addr *addr) +{ + memcpy(iid, addr->s6_addr + 8, 8); +} + +/** + * nm_utils_ipv6_interface_identifier_get_from_token: + * @iid: output %NMUtilsIPv6IfaceId interface identifier set from the token + * @token: token encoded as string + * + * Converts the %in6_addr encoded token (as used in ip6 settings) to + * the interface identifier. + * + * Returns: %TRUE if the @token is a valid token, %FALSE otherwise + */ +gboolean +nm_utils_ipv6_interface_identifier_get_from_token(NMUtilsIPv6IfaceId *iid, const char *token) +{ + struct in6_addr i6_token; + + g_return_val_if_fail(token, FALSE); + + if (!inet_pton(AF_INET6, token, &i6_token)) + return FALSE; + + if (!_nm_utils_inet6_is_token(&i6_token)) + return FALSE; + + nm_utils_ipv6_interface_identifier_get_from_addr(iid, &i6_token); + return TRUE; +} + +/** + * nm_utils_inet6_interface_identifier_to_token: + * @iid: %NMUtilsIPv6IfaceId interface identifier + * @buf: the destination buffer of at least %NM_UTILS_INET_ADDRSTRLEN + * bytes. + * + * Converts the interface identifier to a string token. + * + * Returns: the input buffer filled with the id as string. + */ +const char * +nm_utils_inet6_interface_identifier_to_token(NMUtilsIPv6IfaceId iid, + char buf[static INET6_ADDRSTRLEN]) +{ + struct in6_addr i6_token = {.s6_addr = { + 0, + }}; + + nm_assert(buf); + nm_utils_ipv6_addr_set_interface_identifier(&i6_token, iid); + return _nm_utils_inet6_ntop(&i6_token, buf); +} + +/*****************************************************************************/ + pid_t nm_utils_gettid(void) { @@ -686,106 +793,6 @@ _nm_utils_ip4_prefix_to_netmask(guint32 prefix) return prefix < 32 ? ~htonl(0xFFFFFFFFu >> prefix) : 0xFFFFFFFFu; } -gconstpointer -nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint8 plen) -{ - g_return_val_if_fail(dst, NULL); - - switch (family) { - case AF_INET: - g_return_val_if_fail(plen <= 32, NULL); - - if (!src) { - /* allow "self-assignment", by specifying %NULL as source. */ - src = dst; - } - - *((guint32 *) dst) = nm_utils_ip4_address_clear_host_address(*((guint32 *) src), plen); - break; - case AF_INET6: - nm_utils_ip6_address_clear_host_address(dst, src, plen); - break; - default: - g_return_val_if_reached(NULL); - } - return dst; -} - -/* nm_utils_ip4_address_clear_host_address: - * @addr: source ip6 address - * @plen: prefix length of network - * - * returns: the input address, with the host address set to 0. - */ -in_addr_t -nm_utils_ip4_address_clear_host_address(in_addr_t addr, guint8 plen) -{ - return addr & _nm_utils_ip4_prefix_to_netmask(plen); -} - -/* nm_utils_ip6_address_clear_host_address: - * @dst: destination output buffer, will contain the network part of the @src address - * @src: source ip6 address - * @plen: prefix length of network - * - * Note: this function is self assignment safe, to update @src inplace, set both - * @dst and @src to the same destination or set @src NULL. - */ -const struct in6_addr * -nm_utils_ip6_address_clear_host_address(struct in6_addr * dst, - const struct in6_addr *src, - guint8 plen) -{ - g_return_val_if_fail(plen <= 128, NULL); - g_return_val_if_fail(dst, NULL); - - if (!src) - src = dst; - - if (plen < 128) { - guint nbytes = plen / 8; - guint nbits = plen % 8; - - if (nbytes && dst != src) - memcpy(dst, src, nbytes); - if (nbits) { - dst->s6_addr[nbytes] = (src->s6_addr[nbytes] & (0xFF << (8 - nbits))); - nbytes++; - } - if (nbytes <= 15) - memset(&dst->s6_addr[nbytes], 0, 16 - nbytes); - } else if (src != dst) - *dst = *src; - - return dst; -} - -int -nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a, - const struct in6_addr *addr_b, - guint8 plen) -{ - int nbytes; - guint8 va, vb, m; - - if (plen >= 128) - NM_CMP_DIRECT_MEMCMP(addr_a, addr_b, sizeof(struct in6_addr)); - else { - nbytes = plen / 8; - if (nbytes) - NM_CMP_DIRECT_MEMCMP(addr_a, addr_b, nbytes); - - plen = plen % 8; - if (plen != 0) { - m = ~((1 << (8 - plen)) - 1); - va = ((((const guint8 *) addr_a))[nbytes]) & m; - vb = ((((const guint8 *) addr_b))[nbytes]) & m; - NM_CMP_DIRECT(va, vb); - } - } - return 0; -} - /*****************************************************************************/ guint32 @@ -1146,6 +1153,15 @@ nm_utils_ipaddr_is_normalized(int addr_family, const char *str_addr) /*****************************************************************************/ +NM_UTILS_ENUM2STR_DEFINE(nm_icmpv6_router_pref_to_string, + NMIcmpv6RouterPref, + NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_LOW, "low"), + NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_MEDIUM, "medium"), + NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_HIGH, "high"), + NM_UTILS_ENUM2STR(NM_ICMPV6_ROUTER_PREF_INVALID, "invalid"), ); + +/*****************************************************************************/ + /** * nm_g_ascii_strtoll() * @nptr: the string to parse @@ -3787,6 +3803,32 @@ _nm_utils_strv_dup_packed(const char *const *strv, gssize len) /*****************************************************************************/ gssize +nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpointer needle) +{ + gssize i; + + if (len == 0) + return -1; + + if (len > 0) { + g_return_val_if_fail(list, -1); + for (i = 0; i < len; i++) { + if (list[i] == needle) + return i; + } + } else { + g_return_val_if_fail(needle, -1); + for (i = 0; list && list[i]; i++) { + if (list[i] == needle) + return i; + } + } + return -1; +} + +/*****************************************************************************/ + +gssize nm_utils_ptrarray_find_binary_search(gconstpointer * list, gsize len, gconstpointer needle, @@ -5708,3 +5750,355 @@ nm_utils_name_to_uid(const char *name, uid_t *out_uid) buf = buf_heap; } } + +/*****************************************************************************/ + +static double +_exp10(guint16 ex) +{ + double v; + + if (ex == 0) + return 1.0; + + v = _exp10(ex / 2); + v = v * v; + if (ex % 2) + v *= 10; + return v; +} + +/* + * nm_utils_exp10: + * @ex: the exponent + * + * Returns: 10^ex, or pow(10, ex), or exp10(ex). + */ +double +nm_utils_exp10(gint16 ex) +{ + if (ex >= 0) + return _exp10(ex); + return 1.0 / _exp10(-((gint32) ex)); +} + +/*****************************************************************************/ + +gboolean +_nm_utils_is_empty_ssid_arr(const guint8 *ssid, gsize len) +{ + /* Single white space is for Linksys APs */ + if (len == 1 && ssid[0] == ' ') + return TRUE; + + /* Otherwise, if the entire ssid is 0, we assume it is hidden */ + while (len--) { + if (ssid[len] != '\0') + return FALSE; + } + return TRUE; +} + +gboolean +_nm_utils_is_empty_ssid_gbytes(GBytes *ssid) +{ + const guint8 *p; + gsize l; + + g_return_val_if_fail(ssid, FALSE); + + p = g_bytes_get_data(ssid, &l); + return _nm_utils_is_empty_ssid_arr(p, l); +} + +char * +_nm_utils_ssid_to_string_arr(const guint8 *ssid, gsize len) +{ + gs_free char *s_copy = NULL; + const char * s_cnst; + + if (len == 0) + return g_strdup("(empty)"); + + s_cnst = + nm_utils_buf_utf8safe_escape(ssid, len, NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, &s_copy); + nm_assert(s_cnst); + + if (_nm_utils_is_empty_ssid_arr(ssid, len)) + return g_strdup_printf("\"%s\" (hidden)", s_cnst); + + return g_strdup_printf("\"%s\"", s_cnst); +} + +char * +_nm_utils_ssid_to_string_gbytes(GBytes *ssid) +{ + gconstpointer p; + gsize l; + + if (!ssid) + return g_strdup("(none)"); + + p = g_bytes_get_data(ssid, &l); + return _nm_utils_ssid_to_string_arr(p, l); +} + +/*****************************************************************************/ + +gconstpointer +nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint8 plen) +{ + g_return_val_if_fail(dst, NULL); + + switch (family) { + case AF_INET: + g_return_val_if_fail(plen <= 32, NULL); + + if (!src) { + /* allow "self-assignment", by specifying %NULL as source. */ + src = dst; + } + + *((guint32 *) dst) = nm_utils_ip4_address_clear_host_address(*((guint32 *) src), plen); + break; + case AF_INET6: + nm_utils_ip6_address_clear_host_address(dst, src, plen); + break; + default: + g_return_val_if_reached(NULL); + } + return dst; +} + +/* nm_utils_ip4_address_clear_host_address: + * @addr: source ip6 address + * @plen: prefix length of network + * + * returns: the input address, with the host address set to 0. + */ +in_addr_t +nm_utils_ip4_address_clear_host_address(in_addr_t addr, guint8 plen) +{ + return addr & _nm_utils_ip4_prefix_to_netmask(plen); +} + +/* nm_utils_ip6_address_clear_host_address: + * @dst: destination output buffer, will contain the network part of the @src address + * @src: source ip6 address + * @plen: prefix length of network + * + * Note: this function is self assignment safe, to update @src inplace, set both + * @dst and @src to the same destination or set @src NULL. + */ +const struct in6_addr * +nm_utils_ip6_address_clear_host_address(struct in6_addr * dst, + const struct in6_addr *src, + guint8 plen) +{ + g_return_val_if_fail(plen <= 128, NULL); + g_return_val_if_fail(dst, NULL); + + if (!src) + src = dst; + + if (plen < 128) { + guint nbytes = plen / 8; + guint nbits = plen % 8; + + if (nbytes && dst != src) + memcpy(dst, src, nbytes); + if (nbits) { + dst->s6_addr[nbytes] = (src->s6_addr[nbytes] & (0xFF << (8 - nbits))); + nbytes++; + } + if (nbytes <= 15) + memset(&dst->s6_addr[nbytes], 0, 16 - nbytes); + } else if (src != dst) + *dst = *src; + + return dst; +} + +int +nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a, + const struct in6_addr *addr_b, + guint8 plen) +{ + int nbytes; + guint8 va, vb, m; + + if (plen >= 128) + NM_CMP_DIRECT_MEMCMP(addr_a, addr_b, sizeof(struct in6_addr)); + else { + nbytes = plen / 8; + if (nbytes) + NM_CMP_DIRECT_MEMCMP(addr_a, addr_b, nbytes); + + plen = plen % 8; + if (plen != 0) { + m = ~((1 << (8 - plen)) - 1); + va = ((((const guint8 *) addr_a))[nbytes]) & m; + vb = ((((const guint8 *) addr_b))[nbytes]) & m; + NM_CMP_DIRECT(va, vb); + } + } + return 0; +} + +/*****************************************************************************/ + +#define IPV6_PROPERTY_DIR "/proc/sys/net/ipv6/conf/" +#define IPV4_PROPERTY_DIR "/proc/sys/net/ipv4/conf/" + +G_STATIC_ASSERT(sizeof(IPV4_PROPERTY_DIR) == sizeof(IPV6_PROPERTY_DIR)); +G_STATIC_ASSERT(NM_STRLEN(IPV6_PROPERTY_DIR) + IFNAMSIZ + 60 + == NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE); + +/** + * nm_utils_sysctl_ip_conf_path: + * @addr_family: either AF_INET or AF_INET6. + * @buf: the output buffer where to write the path. It + * must be at least NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE bytes + * long. + * @ifname: an interface name + * @property: a property name + * + * Returns: the path to IPv6 property @property on @ifname. Note that + * this returns the input argument @buf. + */ +const char * +nm_utils_sysctl_ip_conf_path(int addr_family, char *buf, const char *ifname, const char *property) +{ + int len; + + nm_assert(buf); + nm_assert_addr_family(addr_family); + + g_assert(nm_utils_ifname_valid_kernel(ifname, NULL)); + property = NM_ASSERT_VALID_PATH_COMPONENT(property); + + len = g_snprintf(buf, + NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE, + "%s%s/%s", + addr_family == AF_INET6 ? IPV6_PROPERTY_DIR : IPV4_PROPERTY_DIR, + ifname, + property); + g_assert(len < NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE - 1); + return buf; +} + +gboolean +nm_utils_sysctl_ip_conf_is_path(int addr_family, + const char *path, + const char *ifname, + const char *property) +{ + g_return_val_if_fail(path, FALSE); + NM_ASSERT_VALID_PATH_COMPONENT(property); + g_assert(!ifname || nm_utils_ifname_valid_kernel(ifname, NULL)); + + if (addr_family == AF_INET) { + if (!g_str_has_prefix(path, IPV4_PROPERTY_DIR)) + return FALSE; + path += NM_STRLEN(IPV4_PROPERTY_DIR); + } else if (addr_family == AF_INET6) { + if (!g_str_has_prefix(path, IPV6_PROPERTY_DIR)) + return FALSE; + path += NM_STRLEN(IPV6_PROPERTY_DIR); + } else + g_return_val_if_reached(FALSE); + + if (ifname) { + if (!g_str_has_prefix(path, ifname)) + return FALSE; + path += strlen(ifname); + if (path[0] != '/') + return FALSE; + path++; + } else { + const char *slash; + char buf[IFNAMSIZ]; + gsize l; + + slash = strchr(path, '/'); + if (!slash) + return FALSE; + l = slash - path; + if (l >= IFNAMSIZ) + return FALSE; + memcpy(buf, path, l); + buf[l] = '\0'; + if (!nm_utils_ifname_valid_kernel(buf, NULL)) + return FALSE; + path = slash + 1; + } + + if (!nm_streq(path, property)) + return FALSE; + + return TRUE; +} + +gboolean +nm_utils_is_valid_path_component(const char *name) +{ + const char *n; + + if (name == NULL || name[0] == '\0') + return FALSE; + + if (name[0] == '.') { + if (name[1] == '\0') + return FALSE; + if (name[1] == '.' && name[2] == '\0') + return FALSE; + } + n = name; + do { + if (*n == '/') + return FALSE; + } while (*(++n) != '\0'); + + return TRUE; +} + +const char * +NM_ASSERT_VALID_PATH_COMPONENT(const char *name) +{ + if (G_LIKELY(nm_utils_is_valid_path_component(name))) + return name; + + g_error("FATAL: Failed asserting path component: %s%s%s", + NM_PRINT_FMT_QUOTED(name, "\"", name, "\"", "(null)")); + g_assert_not_reached(); +} + +/*****************************************************************************/ + +NM_UTILS_STRING_TABLE_LOOKUP_DEFINE( + nm_utils_route_type_by_name, + guint8, + { nm_assert(name); }, + { return RTN_UNSPEC; }, + {"blackhole", RTN_BLACKHOLE}, + {"broadcast", RTN_BROADCAST}, + {"local", RTN_LOCAL}, + {"multicast", RTN_MULTICAST}, + {"nat", RTN_NAT}, + {"prohibit", RTN_PROHIBIT}, + {"throw", RTN_THROW}, + {"unicast", RTN_UNICAST}, + {"unreachable", RTN_UNREACHABLE}, ); + +NM_UTILS_ENUM2STR_DEFINE(nm_utils_route_type2str, + guint8, + NM_UTILS_ENUM2STR(RTN_BLACKHOLE, "blackhole"), + NM_UTILS_ENUM2STR(RTN_BROADCAST, "broadcast"), + NM_UTILS_ENUM2STR(RTN_LOCAL, "local"), + NM_UTILS_ENUM2STR(RTN_MULTICAST, "multicast"), + NM_UTILS_ENUM2STR(RTN_NAT, "nat"), + NM_UTILS_ENUM2STR(RTN_PROHIBIT, "prohibit"), + NM_UTILS_ENUM2STR(RTN_THROW, "throw"), + NM_UTILS_ENUM2STR(RTN_UNICAST, "unicast"), + NM_UTILS_ENUM2STR(RTN_UNREACHABLE, "unreachable"), + NM_UTILS_ENUM2STR(RTN_UNSPEC, "unspecified"), ); diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index 7d330458c1..e28a6f825e 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -95,6 +95,87 @@ G_STATIC_ASSERT(sizeof(int) == sizeof(gint32)); /*****************************************************************************/ +typedef enum { + + /* No type, used as error value */ + NM_LINK_TYPE_NONE, + + NM_LINK_TYPE_UNKNOWN, + + NM_LINK_TYPE_ANY, + +#define _NM_LINK_TYPE_REAL_FIRST NM_LINK_TYPE_ETHERNET + +/* Hardware types */ +#define _NM_LINK_TYPE_HW_FIRST NM_LINK_TYPE_ETHERNET + NM_LINK_TYPE_ETHERNET, + NM_LINK_TYPE_INFINIBAND, + NM_LINK_TYPE_OLPC_MESH, + NM_LINK_TYPE_WIFI, + NM_LINK_TYPE_WWAN_NET, /* WWAN kernel netdevice */ + NM_LINK_TYPE_WIMAX, + NM_LINK_TYPE_WPAN, + NM_LINK_TYPE_6LOWPAN, + NM_LINK_TYPE_WIFI_P2P, +#define _NM_LINK_TYPE_HW_LAST NM_LINK_TYPE_WIFI_P2P + +/* Software types */ +#define _NM_LINK_TYPE_SW_FIRST NM_LINK_TYPE_BNEP + NM_LINK_TYPE_BNEP, /* Bluetooth Ethernet emulation */ + NM_LINK_TYPE_DUMMY, + NM_LINK_TYPE_GRE, + NM_LINK_TYPE_GRETAP, + NM_LINK_TYPE_IFB, + NM_LINK_TYPE_IP6TNL, + NM_LINK_TYPE_IP6GRE, + NM_LINK_TYPE_IP6GRETAP, + NM_LINK_TYPE_IPIP, + NM_LINK_TYPE_LOOPBACK, + NM_LINK_TYPE_MACSEC, + NM_LINK_TYPE_MACVLAN, + NM_LINK_TYPE_MACVTAP, + NM_LINK_TYPE_OPENVSWITCH, + NM_LINK_TYPE_PPP, + NM_LINK_TYPE_SIT, + NM_LINK_TYPE_TUN, + NM_LINK_TYPE_VETH, + NM_LINK_TYPE_VLAN, + NM_LINK_TYPE_VRF, + NM_LINK_TYPE_VXLAN, + NM_LINK_TYPE_WIREGUARD, +#define _NM_LINK_TYPE_SW_LAST NM_LINK_TYPE_WIREGUARD + +/* Software types with slaves */ +#define _NM_LINK_TYPE_SW_MASTER_FIRST NM_LINK_TYPE_BRIDGE + NM_LINK_TYPE_BRIDGE, + NM_LINK_TYPE_BOND, + NM_LINK_TYPE_TEAM, +#define _NM_LINK_TYPE_SW_MASTER_LAST NM_LINK_TYPE_TEAM + +#define _NM_LINK_TYPE_REAL_LAST NM_LINK_TYPE_TEAM + +#define _NM_LINK_TYPE_REAL_NUM ((int) (_NM_LINK_TYPE_REAL_LAST - _NM_LINK_TYPE_REAL_FIRST + 1)) + +} NMLinkType; + +static inline gboolean +nm_link_type_is_software(NMLinkType link_type) +{ + G_STATIC_ASSERT(_NM_LINK_TYPE_SW_LAST + 1 == _NM_LINK_TYPE_SW_MASTER_FIRST); + + return link_type >= _NM_LINK_TYPE_SW_FIRST && link_type <= _NM_LINK_TYPE_SW_MASTER_LAST; +} + +static inline gboolean +nm_link_type_supports_slaves(NMLinkType link_type) +{ + return link_type >= _NM_LINK_TYPE_SW_MASTER_FIRST && link_type <= _NM_LINK_TYPE_SW_MASTER_LAST; +} + +/*****************************************************************************/ + +gboolean _nm_utils_inet6_is_token(const struct in6_addr *in6addr); + typedef struct { guint8 ether_addr_octet[6 /*ETH_ALEN*/]; } NMEtherAddr; @@ -229,6 +310,136 @@ nm_utils_ether_addr_equal(const struct ether_addr *a1, const struct ether_addr * /*****************************************************************************/ +/** + * NMUtilsIPv6IfaceId: + * @id: convenience member for validity checking; never use directly + * @id_u8: the 64-bit Interface Identifier + * + * Holds a 64-bit IPv6 Interface Identifier. The IID is a sequence of bytes + * and should not normally be treated as a %guint64, but this is done for + * convenience of validity checking and initialization. + */ +typedef struct _NMUtilsIPv6IfaceId { + union { + guint64 id; + guint8 id_u8[8]; + }; +} NMUtilsIPv6IfaceId; + +#define NM_UTILS_IPV6_IFACE_ID_INIT \ + { \ + { \ + .id = 0 \ + } \ + } + +void nm_utils_ipv6_addr_set_interface_identifier(struct in6_addr * addr, + const NMUtilsIPv6IfaceId iid); + +void nm_utils_ipv6_interface_identifier_get_from_addr(NMUtilsIPv6IfaceId * iid, + const struct in6_addr *addr); + +gboolean nm_utils_ipv6_interface_identifier_get_from_token(NMUtilsIPv6IfaceId *iid, + const char * token); + +const char *nm_utils_inet6_interface_identifier_to_token(NMUtilsIPv6IfaceId iid, + char buf[static INET6_ADDRSTRLEN]); + +gboolean nm_utils_get_ipv6_interface_identifier(NMLinkType link_type, + const guint8 * hwaddr, + guint len, + guint dev_id, + NMUtilsIPv6IfaceId *out_iid); + +/*****************************************************************************/ + +gconstpointer +nm_utils_ipx_address_clear_host_address(int family, gpointer dst, gconstpointer src, guint8 plen); +in_addr_t nm_utils_ip4_address_clear_host_address(in_addr_t addr, guint8 plen); +const struct in6_addr *nm_utils_ip6_address_clear_host_address(struct in6_addr * dst, + const struct in6_addr *src, + guint8 plen); + +static inline int +nm_utils_ip4_address_same_prefix_cmp(in_addr_t addr_a, in_addr_t addr_b, guint8 plen) +{ + NM_CMP_DIRECT(htonl(nm_utils_ip4_address_clear_host_address(addr_a, plen)), + htonl(nm_utils_ip4_address_clear_host_address(addr_b, plen))); + return 0; +} + +int nm_utils_ip6_address_same_prefix_cmp(const struct in6_addr *addr_a, + const struct in6_addr *addr_b, + guint8 plen); + +static inline int +nm_utils_ip_address_same_prefix_cmp(int addr_family, + gconstpointer addr_a, + gconstpointer addr_b, + guint8 plen) +{ + nm_assert_addr_family(addr_family); + + NM_CMP_SELF(addr_a, addr_b); + + if (NM_IS_IPv4(addr_family)) { + return nm_utils_ip4_address_same_prefix_cmp(*((const in_addr_t *) addr_a), + *((const in_addr_t *) addr_b), + plen); + } + + return nm_utils_ip6_address_same_prefix_cmp(addr_a, addr_b, plen); +} + +static inline gboolean +nm_utils_ip4_address_same_prefix(in_addr_t addr_a, in_addr_t addr_b, guint8 plen) +{ + return nm_utils_ip4_address_same_prefix_cmp(addr_a, addr_b, plen) == 0; +} + +static inline gboolean +nm_utils_ip6_address_same_prefix(const struct in6_addr *addr_a, + const struct in6_addr *addr_b, + guint8 plen) +{ + return nm_utils_ip6_address_same_prefix_cmp(addr_a, addr_b, plen) == 0; +} + +static inline gboolean +nm_utils_ip_address_same_prefix(int addr_family, + gconstpointer addr_a, + gconstpointer addr_b, + guint8 plen) +{ + return nm_utils_ip_address_same_prefix_cmp(addr_family, addr_a, addr_b, plen) == 0; +} + +#define NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX(a, b, plen) \ + NM_CMP_RETURN(nm_utils_ip4_address_same_prefix_cmp((a), (b), (plen))) + +#define NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX(a, b, plen) \ + NM_CMP_RETURN(nm_utils_ip6_address_same_prefix_cmp((a), (b), (plen))) + +/*****************************************************************************/ + +#define NM_IPV4LL_NETWORK ((in_addr_t)(htonl(0xA9FE0000lu))) +#define NM_IPV4LL_NETMASK ((in_addr_t)(htonl(0xFFFF0000lu))) + +static inline gboolean +nm_utils_ip4_address_is_link_local(in_addr_t addr) +{ + return (addr & NM_IPV4LL_NETMASK) == NM_IPV4LL_NETWORK; +} + +static inline gboolean +nm_utils_ip4_address_is_zeronet(in_addr_t network) +{ + /* Same as ipv4_is_zeronet() from kernel's include/linux/in.h. */ + return (network & htonl(0xFF000000u)) == htonl(0x00000000u); +} + +/*****************************************************************************/ + #define NM_UTILS_INET_ADDRSTRLEN INET6_ADDRSTRLEN static inline const char * @@ -290,6 +501,20 @@ gboolean nm_utils_ipaddr_is_normalized(int addr_family, const char *str_addr); /*****************************************************************************/ +/* this enum is compatible with ICMPV6_ROUTER_PREF_* (from <linux/icmpv6.h>, + * the values for netlink attribute RTA_PREF) and "enum ndp_route_preference" + * from <ndp.h>. */ +typedef enum _nm_packed { + NM_ICMPV6_ROUTER_PREF_MEDIUM = 0x0, /* ICMPV6_ROUTER_PREF_MEDIUM */ + NM_ICMPV6_ROUTER_PREF_LOW = 0x3, /* ICMPV6_ROUTER_PREF_LOW */ + NM_ICMPV6_ROUTER_PREF_HIGH = 0x1, /* ICMPV6_ROUTER_PREF_HIGH */ + NM_ICMPV6_ROUTER_PREF_INVALID = 0x2, /* ICMPV6_ROUTER_PREF_INVALID */ +} NMIcmpv6RouterPref; + +const char *nm_icmpv6_router_pref_to_string(NMIcmpv6RouterPref pref, char *buf, gsize len); + +/*****************************************************************************/ + gboolean nm_utils_memeqzero(gconstpointer data, gsize length); /*****************************************************************************/ @@ -1802,6 +2027,8 @@ gssize nm_utils_array_find_binary_search(gconstpointer list, GCompareDataFunc cmpfcn, gpointer user_data); +gssize nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpointer needle); + /*****************************************************************************/ void _nm_utils_strv_sort(const char **strv, gssize len); @@ -2198,6 +2425,20 @@ _nm_utils_hwaddr_ntoa(gconstpointer addr, return nm_utils_bin2hexstr_full(addr, addr_len, ':', upper_case, buf); } +#define _nm_utils_hwaddr_ntoa_maybe_a(addr, addr_len, buf_to_free) \ + ({ \ + gconstpointer const _addr = (addr); \ + const gsize _addr_len = (addr_len); \ + char **const _buf_to_free = (buf_to_free); \ + \ + nm_utils_bin2hexstr_full( \ + _addr, \ + _addr_len, \ + ':', \ + TRUE, \ + nm_malloc_maybe_a(3 * 20, _addr_len ? (_addr_len * 3u) : 1u, _buf_to_free)); \ + }) + /*****************************************************************************/ #define _NM_UTILS_STRING_TABLE_LOOKUP_DEFINE(fcn_name, \ @@ -2477,4 +2718,36 @@ gboolean nm_utils_is_specific_hostname(const char *name); char * nm_utils_uid_to_name(uid_t uid); gboolean nm_utils_name_to_uid(const char *name, uid_t *out_uid); +/*****************************************************************************/ + +double nm_utils_exp10(gint16 e); + +/*****************************************************************************/ + +gboolean _nm_utils_is_empty_ssid_arr(const guint8 *ssid, gsize len); +gboolean _nm_utils_is_empty_ssid_gbytes(GBytes *ssid); +char * _nm_utils_ssid_to_string_arr(const guint8 *ssid, gsize len); +char * _nm_utils_ssid_to_string_gbytes(GBytes *ssid); + +/*****************************************************************************/ + +gboolean nm_utils_is_valid_path_component(const char *name); +const char *NM_ASSERT_VALID_PATH_COMPONENT(const char *name); + +#define NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE 100 + +const char * +nm_utils_sysctl_ip_conf_path(int addr_family, char *buf, const char *ifname, const char *property); + +gboolean nm_utils_sysctl_ip_conf_is_path(int addr_family, + const char *path, + const char *ifname, + const char *property); + +/*****************************************************************************/ + +guint8 nm_utils_route_type_by_name(const char *name); + +const char *nm_utils_route_type2str(guint8 val, char *buf, gsize len); + #endif /* __NM_SHARED_UTILS_H__ */ diff --git a/src/libnm-platform/meson.build b/src/libnm-platform/meson.build index c2a8b2e7cf..3e4f41a929 100644 --- a/src/libnm-platform/meson.build +++ b/src/libnm-platform/meson.build @@ -3,10 +3,17 @@ libnm_platform = static_library( 'nm-platform', sources: [ + 'nm-linux-platform.c', 'nm-netlink.c', 'nm-platform-utils.c', + 'nm-platform.c', 'nmp-netns.c', - ], + 'nmp-object.c', + 'nmp-rules-manager.c', + 'wifi/nm-wifi-utils-nl80211.c', + 'wifi/nm-wifi-utils.c', + 'wpan/nm-wpan-utils.c', + ] + (enable_wext ? [ 'wifi/nm-wifi-utils-wext.c' ] : []), include_directories: [ src_inc, top_inc, diff --git a/src/core/platform/nm-linux-platform.c b/src/libnm-platform/nm-linux-platform.c index 679faa5bd8..d689dfae63 100644 --- a/src/core/platform/nm-linux-platform.c +++ b/src/libnm-platform/nm-linux-platform.c @@ -3,7 +3,7 @@ * Copyright (C) 2012 - 2018 Red Hat, Inc. */ -#include "src/core/nm-default-daemon.h" +#include "libnm-glib-aux/nm-default-glib-i18n-lib.h" #include "nm-linux-platform.h" @@ -32,25 +32,21 @@ #include <sys/statvfs.h> #include <unistd.h> -#include "libnm-std-aux/unaligned.h" - -#include "nm-utils.h" -#include "libnm-core-intern/nm-core-internal.h" -#include "nm-setting-vlan.h" - -#include "libnm-glib-aux/nm-secret-utils.h" #include "libnm-glib-aux/nm-c-list.h" +#include "libnm-glib-aux/nm-io-utils.h" +#include "libnm-glib-aux/nm-secret-utils.h" +#include "libnm-glib-aux/nm-time-utils.h" +#include "libnm-log-core/nm-logging.h" #include "libnm-platform/nm-netlink.h" -#include "nm-core-utils.h" -#include "nmp-object.h" -#include "libnm-platform/nmp-netns.h" #include "libnm-platform/nm-platform-utils.h" -#include "nm-platform-private.h" -#include "wifi/nm-wifi-utils.h" -#include "wifi/nm-wifi-utils-wext.h" -#include "wpan/nm-wpan-utils.h" -#include "libnm-glib-aux/nm-io-utils.h" +#include "libnm-platform/nmp-netns.h" +#include "libnm-platform/wifi/nm-wifi-utils-wext.h" +#include "libnm-platform/wifi/nm-wifi-utils.h" +#include "libnm-platform/wpan/nm-wpan-utils.h" +#include "libnm-std-aux/unaligned.h" #include "libnm-udev-aux/nm-udev-utils.h" +#include "nm-platform-private.h" +#include "nmp-object.h" /*****************************************************************************/ @@ -2884,8 +2880,8 @@ _nmp_link_address_set(NMPLinkAddress *dst, const struct nlattr *nla) if (nla) { int l = nla_len(nla); - if (l > 0 && l <= NM_UTILS_HWADDR_LEN_MAX) { - G_STATIC_ASSERT_EXPR(sizeof(dst->data) == NM_UTILS_HWADDR_LEN_MAX); + if (l > 0 && l <= _NM_UTILS_HWADDR_LEN_MAX) { + G_STATIC_ASSERT_EXPR(sizeof(dst->data) == _NM_UTILS_HWADDR_LEN_MAX); memcpy(dst->data, nla_data(nla), l); dst->len = l; } @@ -4156,8 +4152,8 @@ _nl_msg_new_link_set_linkinfo(struct nl_msg *msg, NMLinkType link_type, gconstpo { struct ifla_vlan_flags flags = { - .flags = props->flags & NM_VLAN_FLAGS_ALL, - .mask = NM_VLAN_FLAGS_ALL, + .flags = props->flags & _NM_VLAN_FLAGS_ALL, + .mask = _NM_VLAN_FLAGS_ALL, }; NLA_PUT(msg, IFLA_VLAN_FLAGS, sizeof(flags), &flags); @@ -4433,10 +4429,10 @@ _nl_msg_new_link_set_linkinfo_vlan(struct nl_msg * msg, guint i; gboolean has_any_vlan_properties = FALSE; - G_STATIC_ASSERT(NM_VLAN_FLAG_REORDER_HEADERS == (guint32) VLAN_FLAG_REORDER_HDR); - G_STATIC_ASSERT(NM_VLAN_FLAG_GVRP == (guint32) VLAN_FLAG_GVRP); - G_STATIC_ASSERT(NM_VLAN_FLAG_LOOSE_BINDING == (guint32) VLAN_FLAG_LOOSE_BINDING); - G_STATIC_ASSERT(NM_VLAN_FLAG_MVRP == (guint32) VLAN_FLAG_MVRP); + G_STATIC_ASSERT(_NM_VLAN_FLAG_REORDER_HEADERS == (guint32) VLAN_FLAG_REORDER_HDR); + G_STATIC_ASSERT(_NM_VLAN_FLAG_GVRP == (guint32) VLAN_FLAG_GVRP); + G_STATIC_ASSERT(_NM_VLAN_FLAG_LOOSE_BINDING == (guint32) VLAN_FLAG_LOOSE_BINDING); + G_STATIC_ASSERT(_NM_VLAN_FLAG_MVRP == (guint32) VLAN_FLAG_MVRP); #define VLAN_XGRESS_PRIO_VALID(from) (((from) & ~(guint32) 0x07) == 0) @@ -6000,7 +5996,7 @@ delayed_action_handle_one(NMPlatform *platform) g_ptr_array_remove_index_fast(priv->delayed_action.list_master_connected, 0); if (priv->delayed_action.list_master_connected->len == 0) priv->delayed_action.flags &= ~DELAYED_ACTION_TYPE_MASTER_CONNECTED; - nm_assert(_nm_utils_ptrarray_find_first( + nm_assert(nm_utils_ptrarray_find_first( (gconstpointer *) priv->delayed_action.list_master_connected->pdata, priv->delayed_action.list_master_connected->len, user_data) @@ -6044,7 +6040,7 @@ delayed_action_handle_one(NMPlatform *platform) g_ptr_array_remove_index_fast(priv->delayed_action.list_refresh_link, 0); if (priv->delayed_action.list_refresh_link->len == 0) priv->delayed_action.flags &= ~DELAYED_ACTION_TYPE_REFRESH_LINK; - nm_assert(_nm_utils_ptrarray_find_first( + nm_assert(nm_utils_ptrarray_find_first( (gconstpointer *) priv->delayed_action.list_refresh_link->pdata, priv->delayed_action.list_refresh_link->len, user_data) @@ -6097,7 +6093,7 @@ delayed_action_schedule(NMPlatform *platform, DelayedActionType action_type, gpo switch (action_type) { case DELAYED_ACTION_TYPE_REFRESH_LINK: - if (_nm_utils_ptrarray_find_first( + if (nm_utils_ptrarray_find_first( (gconstpointer *) priv->delayed_action.list_refresh_link->pdata, priv->delayed_action.list_refresh_link->len, user_data) @@ -6105,7 +6101,7 @@ delayed_action_schedule(NMPlatform *platform, DelayedActionType action_type, gpo g_ptr_array_add(priv->delayed_action.list_refresh_link, user_data); break; case DELAYED_ACTION_TYPE_MASTER_CONNECTED: - if (_nm_utils_ptrarray_find_first( + if (nm_utils_ptrarray_find_first( (gconstpointer *) priv->delayed_action.list_master_connected->pdata, priv->delayed_action.list_master_connected->len, user_data) @@ -7359,7 +7355,7 @@ link_add(NMPlatform * platform, * bond0 automatically. */ if (!g_file_test("/sys/class/net/bonding_masters", G_FILE_TEST_EXISTS)) - (void) nm_utils_modprobe(NULL, TRUE, "bonding", "max_bonds=0", NULL); + (void) nmp_utils_modprobe(NULL, TRUE, "bonding", "max_bonds=0", NULL); } nlmsg = _nl_msg_new_link(RTM_NEWLINK, NLM_F_CREATE | NLM_F_EXCL, 0, name); @@ -7732,7 +7728,7 @@ link_set_sriov_params_async(NMPlatform * platform, if (NM_IN_SET(autoprobe, NM_OPTION_BOOL_TRUE, NM_OPTION_BOOL_FALSE) && current_autoprobe != autoprobe && !nm_platform_sysctl_set( - NM_PLATFORM_GET, + platform, NMP_SYSCTL_PATHID_NETDIR(dirfd, ifname, "device/sriov_drivers_autoprobe"), nm_sprintf_buf(buf, "%d", (int) autoprobe))) { g_set_error(&error, @@ -8084,8 +8080,8 @@ _vlan_change_vlan_qos_mapping_create(gboolean is_ingress_map, static gboolean link_vlan_change(NMPlatform * platform, int ifindex, - NMVlanFlags flags_mask, - NMVlanFlags flags_set, + _NMVlanFlags flags_mask, + _NMVlanFlags flags_set, gboolean ingress_reset_all, const NMVlanQosMapping *ingress_map, gsize n_ingress_map, @@ -8210,7 +8206,7 @@ _infiniband_partition_action(NMPlatform * platform, return FALSE; } - nm_utils_new_infiniband_name(name, ifname_parent, p_key); + nmp_utils_new_infiniband_name(name, ifname_parent, p_key); do_request_link(platform, 0, name); if (action == INFINIBAND_ACTION_DELETE_CHILD) @@ -8277,7 +8273,7 @@ get_ext_data(NMPlatform *platform, int ifindex) return retval; static gboolean -wifi_get_capabilities(NMPlatform *platform, int ifindex, NMDeviceWifiCapabilities *caps) +wifi_get_capabilities(NMPlatform *platform, int ifindex, _NMDeviceWifiCapabilities *caps) { WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, FALSE); if (caps) @@ -8303,15 +8299,15 @@ wifi_get_station(NMPlatform * platform, return nm_wifi_utils_get_station(wifi_data, out_bssid, out_quality, out_rate); } -static NM80211Mode +static _NM80211Mode wifi_get_mode(NMPlatform *platform, int ifindex) { - WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, NM_802_11_MODE_UNKNOWN); + WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, _NM_802_11_MODE_UNKNOWN); return nm_wifi_utils_get_mode(wifi_data); } static void -wifi_set_mode(NMPlatform *platform, int ifindex, NM80211Mode mode) +wifi_set_mode(NMPlatform *platform, int ifindex, _NM80211Mode mode) { WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, ); nm_wifi_utils_set_mode(wifi_data, mode); @@ -8338,7 +8334,7 @@ wifi_indicate_addressing_running(NMPlatform *platform, int ifindex, gboolean run nm_wifi_utils_indicate_addressing_running(wifi_data, running); } -static NMSettingWirelessWakeOnWLan +static _NMSettingWirelessWakeOnWLan wifi_get_wake_on_wlan(NMPlatform *platform, int ifindex) { WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, FALSE); @@ -8346,7 +8342,7 @@ wifi_get_wake_on_wlan(NMPlatform *platform, int ifindex) } static gboolean -wifi_set_wake_on_wlan(NMPlatform *platform, int ifindex, NMSettingWirelessWakeOnWLan wowl) +wifi_set_wake_on_wlan(NMPlatform *platform, int ifindex, _NMSettingWirelessWakeOnWLan wowl) { WIFI_GET_WIFI_DATA_NETNS(wifi_data, platform, ifindex, FALSE); return nm_wifi_utils_set_wake_on_wlan(wifi_data, wowl); @@ -8473,8 +8469,8 @@ link_get_wake_on_lan(NMPlatform *platform, int ifindex) return FALSE; return !NM_IN_SET(nm_wifi_utils_get_wake_on_wlan(wifi_data), - NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE, - NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE); + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE, + _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE); } else return FALSE; @@ -9361,14 +9357,6 @@ handle_udev_event(NMUdevClient *udev_client, struct udev_device *udevice, gpoint /*****************************************************************************/ -void -nm_linux_platform_setup(void) -{ - nm_platform_setup(nm_linux_platform_new(FALSE, FALSE)); -} - -/*****************************************************************************/ - static void nm_linux_platform_init(NMLinuxPlatform *self) { diff --git a/src/core/platform/nm-linux-platform.h b/src/libnm-platform/nm-linux-platform.h index 6837e64a70..26c31e3e4c 100644 --- a/src/core/platform/nm-linux-platform.h +++ b/src/libnm-platform/nm-linux-platform.h @@ -25,6 +25,4 @@ GType nm_linux_platform_get_type(void); NMPlatform *nm_linux_platform_new(gboolean log_with_ptr, gboolean netns_support); -void nm_linux_platform_setup(void); - #endif /* __NETWORKMANAGER_LINUX_PLATFORM_H__ */ diff --git a/src/core/platform/nm-platform-private.h b/src/libnm-platform/nm-platform-private.h index cf80568912..cf80568912 100644 --- a/src/core/platform/nm-platform-private.h +++ b/src/libnm-platform/nm-platform-private.h diff --git a/src/libnm-platform/nm-platform-utils.c b/src/libnm-platform/nm-platform-utils.c index 7c101213d9..a46deb5923 100644 --- a/src/libnm-platform/nm-platform-utils.c +++ b/src/libnm-platform/nm-platform-utils.c @@ -20,6 +20,7 @@ #include "libnm-base/nm-ethtool-base.h" #include "libnm-log-core/nm-logging.h" +#include "libnm-glib-aux/nm-time-utils.h" /*****************************************************************************/ @@ -1805,3 +1806,230 @@ nmp_utils_sysctl_open_netdir(int ifindex, const char *ifname_guess, char *out_if return -1; } + +/*****************************************************************************/ + +char * +nmp_utils_new_vlan_name(const char *parent_iface, guint32 vlan_id) +{ + guint id_len; + gsize parent_len; + char *ifname; + + g_return_val_if_fail(parent_iface && *parent_iface, NULL); + + if (vlan_id < 10) + id_len = 2; + else if (vlan_id < 100) + id_len = 3; + else if (vlan_id < 1000) + id_len = 4; + else { + g_return_val_if_fail(vlan_id < 4095, NULL); + id_len = 5; + } + + ifname = g_new(char, IFNAMSIZ); + + parent_len = strlen(parent_iface); + parent_len = MIN(parent_len, IFNAMSIZ - 1 - id_len); + memcpy(ifname, parent_iface, parent_len); + g_snprintf(&ifname[parent_len], IFNAMSIZ - parent_len, ".%u", vlan_id); + + return ifname; +} + +/*****************************************************************************/ + +/* nmp_utils_new_infiniband_name: + * @name: the output-buffer where the value will be written. Must be + * not %NULL and point to a string buffer of at least IFNAMSIZ bytes. + * @parent_name: the parent interface name + * @p_key: the partition key. + * + * Returns: the infiniband name will be written to @name and @name + * is returned. + */ +const char * +nmp_utils_new_infiniband_name(char *name, const char *parent_name, int p_key) +{ + g_return_val_if_fail(name, NULL); + g_return_val_if_fail(parent_name && parent_name[0], NULL); + g_return_val_if_fail(strlen(parent_name) < IFNAMSIZ, NULL); + + /* technically, p_key of 0x0000 and 0x8000 is not allowed either. But we don't + * want to assert against that in nmp_utils_new_infiniband_name(). So be more + * resilient here, and accept those. */ + g_return_val_if_fail(p_key >= 0 && p_key <= 0xffff, NULL); + + /* If parent+suffix is too long, kernel would just truncate + * the name. We do the same. See ipoib_vlan_add(). */ + g_snprintf(name, IFNAMSIZ, "%s.%04x", parent_name, p_key); + return name; +} + +/*****************************************************************************/ + +/** + * Takes a pair @timestamp and @duration, and returns the remaining duration based + * on the new timestamp @now. + */ +guint32 +nmp_utils_lifetime_rebase_relative_time_on_now(guint32 timestamp, guint32 duration, gint32 now) +{ + gint64 t; + + nm_assert(now >= 0); + + if (duration == NM_PLATFORM_LIFETIME_PERMANENT) + return NM_PLATFORM_LIFETIME_PERMANENT; + + if (timestamp == 0) { + /* if the @timestamp is zero, assume it was just left unset and that the relative + * @duration starts counting from @now. This is convenient to construct an address + * and print it in nm_platform_ip4_address_to_string(). + * + * In general it does not make sense to set the @duration without anchoring at + * @timestamp because you don't know the absolute expiration time when looking + * at the address at a later moment. */ + timestamp = now; + } + + /* For timestamp > now, just accept it and calculate the expected(?) result. */ + t = (gint64) timestamp + (gint64) duration - (gint64) now; + + if (t <= 0) + return 0; + if (t >= NM_PLATFORM_LIFETIME_PERMANENT) + return NM_PLATFORM_LIFETIME_PERMANENT - 1; + return t; +} + +guint32 +nmp_utils_lifetime_get(guint32 timestamp, + guint32 lifetime, + guint32 preferred, + gint32 now, + guint32 *out_preferred) +{ + guint32 t_lifetime, t_preferred; + + nm_assert(now >= 0); + + if (timestamp == 0 && lifetime == 0) { + /* We treat lifetime==0 && timestamp==0 addresses as permanent addresses to allow easy + * creation of such addresses (without requiring to set the lifetime fields to + * NM_PLATFORM_LIFETIME_PERMANENT). The real lifetime==0 addresses (E.g. DHCP6 telling us + * to drop an address will have timestamp set. + */ + NM_SET_OUT(out_preferred, NM_PLATFORM_LIFETIME_PERMANENT); + g_return_val_if_fail(preferred == 0, NM_PLATFORM_LIFETIME_PERMANENT); + return NM_PLATFORM_LIFETIME_PERMANENT; + } + + if (now <= 0) + now = nm_utils_get_monotonic_timestamp_sec(); + + t_lifetime = nmp_utils_lifetime_rebase_relative_time_on_now(timestamp, lifetime, now); + if (!t_lifetime) { + NM_SET_OUT(out_preferred, 0); + return 0; + } + + t_preferred = nmp_utils_lifetime_rebase_relative_time_on_now(timestamp, preferred, now); + + NM_SET_OUT(out_preferred, MIN(t_preferred, t_lifetime)); + + /* Assert that non-permanent addresses have a (positive) @timestamp. nmp_utils_lifetime_rebase_relative_time_on_now() + * treats addresses with timestamp 0 as *now*. Addresses passed to _address_get_lifetime() always + * should have a valid @timestamp, otherwise on every re-sync, their lifetime will be extended anew. + */ + g_return_val_if_fail(timestamp != 0 + || (lifetime == NM_PLATFORM_LIFETIME_PERMANENT + && preferred == NM_PLATFORM_LIFETIME_PERMANENT), + t_lifetime); + g_return_val_if_fail(t_preferred <= t_lifetime, t_lifetime); + + return t_lifetime; +} + +/*****************************************************************************/ + +static const char * +_trunk_first_line(char *str) +{ + char *s; + + s = strchr(str, '\n'); + if (s) + s[0] = '\0'; + return str; +} + +int +nmp_utils_modprobe(GError **error, gboolean suppress_error_logging, const char *arg1, ...) +{ + gs_unref_ptrarray GPtrArray *argv = NULL; + int exit_status; + gs_free char * _log_str = NULL; +#define ARGV_TO_STR(argv) \ + (_log_str ? _log_str : (_log_str = g_strjoinv(" ", (char **) argv->pdata))) + GError * local = NULL; + va_list ap; + NMLogLevel llevel = suppress_error_logging ? LOGL_DEBUG : LOGL_ERR; + gs_free char *std_out = NULL, *std_err = NULL; + + g_return_val_if_fail(!error || !*error, -1); + g_return_val_if_fail(arg1, -1); + + /* construct the argument list */ + argv = g_ptr_array_sized_new(4); + g_ptr_array_add(argv, "/sbin/modprobe"); + g_ptr_array_add(argv, "--use-blacklist"); + g_ptr_array_add(argv, (char *) arg1); + + va_start(ap, arg1); + while ((arg1 = va_arg(ap, const char *))) + g_ptr_array_add(argv, (char *) arg1); + va_end(ap); + + g_ptr_array_add(argv, NULL); + + nm_log_dbg(LOGD_CORE, "modprobe: '%s'", ARGV_TO_STR(argv)); + if (!g_spawn_sync(NULL, + (char **) argv->pdata, + NULL, + 0, + NULL, + NULL, + &std_out, + &std_err, + &exit_status, + &local)) { + nm_log(llevel, + LOGD_CORE, + NULL, + NULL, + "modprobe: '%s' failed: %s", + ARGV_TO_STR(argv), + local->message); + g_propagate_error(error, local); + return -1; + } else if (exit_status != 0) { + nm_log(llevel, + LOGD_CORE, + NULL, + NULL, + "modprobe: '%s' exited with error %d%s%s%s%s%s%s", + ARGV_TO_STR(argv), + exit_status, + std_out && *std_out ? " (" : "", + std_out && *std_out ? _trunk_first_line(std_out) : "", + std_out && *std_out ? ")" : "", + std_err && *std_err ? " (" : "", + std_err && *std_err ? _trunk_first_line(std_err) : "", + std_err && *std_err ? ")" : ""); + } + + return exit_status; +} diff --git a/src/libnm-platform/nm-platform-utils.h b/src/libnm-platform/nm-platform-utils.h index 8d9eaa38e0..52fcf8d8bc 100644 --- a/src/libnm-platform/nm-platform-utils.h +++ b/src/libnm-platform/nm-platform-utils.h @@ -70,4 +70,19 @@ int nmp_utils_if_nametoindex(const char *ifname); int nmp_utils_sysctl_open_netdir(int ifindex, const char *ifname_guess, char *out_ifname); +char * nmp_utils_new_vlan_name(const char *parent_iface, guint32 vlan_id); +const char *nmp_utils_new_infiniband_name(char *name, const char *parent_name, int p_key); + +guint32 +nmp_utils_lifetime_rebase_relative_time_on_now(guint32 timestamp, guint32 duration, gint32 now); + +guint32 nmp_utils_lifetime_get(guint32 timestamp, + guint32 lifetime, + guint32 preferred, + gint32 now, + guint32 *out_preferred); + +int nmp_utils_modprobe(GError **error, gboolean suppress_error_logging, const char *arg1, ...) + G_GNUC_NULL_TERMINATED; + #endif /* __NM_PLATFORM_UTILS_H__ */ diff --git a/src/core/platform/nm-platform.c b/src/libnm-platform/nm-platform.c index 3a76a1e5a6..6049906a62 100644 --- a/src/core/platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -3,7 +3,7 @@ * Copyright (C) 2012 - 2018 Red Hat, Inc. */ -#include "src/core/nm-default-daemon.h" +#include "libnm-glib-aux/nm-default-glib-i18n-lib.h" #include "nm-platform.h" @@ -22,17 +22,15 @@ #include <linux/tc_act/tc_mirred.h> #include <libudev.h> -#include "nm-utils.h" -#include "libnm-core-intern/nm-core-internal.h" #include "libnm-glib-aux/nm-dedup-multi.h" -#include "libnm-udev-aux/nm-udev-utils.h" #include "libnm-glib-aux/nm-secret-utils.h" - -#include "nm-core-utils.h" +#include "libnm-glib-aux/nm-time-utils.h" +#include "libnm-log-core/nm-logging.h" #include "libnm-platform/nm-platform-utils.h" +#include "libnm-platform/nmp-netns.h" +#include "libnm-udev-aux/nm-udev-utils.h" #include "nm-platform-private.h" #include "nmp-object.h" -#include "libnm-platform/nmp-netns.h" /*****************************************************************************/ @@ -55,18 +53,22 @@ G_STATIC_ASSERT(_nm_alignof(NMPlatformIPAddress) == _nm_alignof(NMPlatformIPXAdd /*****************************************************************************/ -G_STATIC_ASSERT(sizeof(((NMPLinkAddress *) NULL)->data) == NM_UTILS_HWADDR_LEN_MAX); -G_STATIC_ASSERT(sizeof(((NMPlatformLink *) NULL)->l_address.data) == NM_UTILS_HWADDR_LEN_MAX); -G_STATIC_ASSERT(sizeof(((NMPlatformLink *) NULL)->l_broadcast.data) == NM_UTILS_HWADDR_LEN_MAX); +G_STATIC_ASSERT(sizeof(((NMPLinkAddress *) NULL)->data) == _NM_UTILS_HWADDR_LEN_MAX); +G_STATIC_ASSERT(sizeof(((NMPlatformLink *) NULL)->l_address.data) == _NM_UTILS_HWADDR_LEN_MAX); +G_STATIC_ASSERT(sizeof(((NMPlatformLink *) NULL)->l_broadcast.data) == _NM_UTILS_HWADDR_LEN_MAX); static const char * _nmp_link_address_to_string(const NMPLinkAddress *addr, - char buf[static(NM_UTILS_HWADDR_LEN_MAX * 3)]) + char buf[static(_NM_UTILS_HWADDR_LEN_MAX * 3)]) { nm_assert(addr); if (addr->len > 0) { - if (!_nm_utils_hwaddr_ntoa(addr->data, addr->len, TRUE, buf, NM_UTILS_HWADDR_LEN_MAX * 3)) { + if (!_nm_utils_hwaddr_ntoa(addr->data, + addr->len, + TRUE, + buf, + _NM_UTILS_HWADDR_LEN_MAX * 3)) { buf[0] = '\0'; g_return_val_if_reached(buf); } @@ -84,7 +86,7 @@ nmp_link_address_get(const NMPLinkAddress *addr, size_t *length) return NULL; } - if (addr->len > NM_UTILS_HWADDR_LEN_MAX) { + if (addr->len > _NM_UTILS_HWADDR_LEN_MAX) { NM_SET_OUT(length, 0); g_return_val_if_reached(NULL); } @@ -221,11 +223,6 @@ _nm_platform_signal_id_get(NMPlatformSignalIdType signal_type) /*****************************************************************************/ -/* Singleton NMPlatform subclass instance and cached class object */ -NM_DEFINE_SINGLETON_INSTANCE(NMPlatform); - -NM_DEFINE_SINGLETON_REGISTER(NMPlatform); - /* Just always initialize a @klass instance. NM_PLATFORM_GET_CLASS() * is only a plain read on the self instance, which the compiler * like can optimize out. @@ -257,51 +254,6 @@ NM_DEFINE_SINGLETON_REGISTER(NMPlatform); return (err_val); \ } while (0) -/** - * nm_platform_setup: - * @instance: the #NMPlatform instance - * - * Failing to set up #NMPlatform singleton results in a fatal error, - * as well as trying to initialize it multiple times without freeing - * it. - * - * NetworkManager will typically use only one platform object during - * its run. Test programs might want to switch platform implementations, - * though. - */ -void -nm_platform_setup(NMPlatform *instance) -{ - g_return_if_fail(NM_IS_PLATFORM(instance)); - g_return_if_fail(!singleton_instance); - - singleton_instance = instance; - - nm_singleton_instance_register(); - - nm_log_dbg(LOGD_CORE, - "setup %s singleton (" NM_HASH_OBFUSCATE_PTR_FMT ")", - "NMPlatform", - NM_HASH_OBFUSCATE_PTR(instance)); -} - -/** - * nm_platform_get: - * @self: platform instance - * - * Retrieve #NMPlatform singleton. Use this whenever you want to connect to - * #NMPlatform signals. It is an error to call it before nm_platform_setup(). - * - * Returns: (transfer none): The #NMPlatform singleton reference. - */ -NMPlatform * -nm_platform_get() -{ - g_assert(singleton_instance); - - return singleton_instance; -} - /*****************************************************************************/ NMDedupMultiIndex * @@ -1159,7 +1111,7 @@ nm_platform_link_get_by_address(NMPlatform * self, if (length == 0) return NULL; - if (length > NM_UTILS_HWADDR_LEN_MAX) + if (length > _NM_UTILS_HWADDR_LEN_MAX) g_return_val_if_reached(NULL); if (!address) g_return_val_if_reached(NULL); @@ -1235,7 +1187,7 @@ nm_platform_link_add(NMPlatform * self, const NMPlatformLink **out_link) { int r; - char addr_buf[NM_UTILS_HWADDR_LEN_MAX * 3]; + char addr_buf[_NM_UTILS_HWADDR_LEN_MAX * 3]; char mtu_buf[16]; char parent_buf[64]; char buf[512]; @@ -1244,7 +1196,7 @@ nm_platform_link_add(NMPlatform * self, g_return_val_if_fail(name, -NME_BUG); g_return_val_if_fail((address != NULL) ^ (address_len == 0), -NME_BUG); - g_return_val_if_fail(address_len <= NM_UTILS_HWADDR_LEN_MAX, -NME_BUG); + g_return_val_if_fail(address_len <= _NM_UTILS_HWADDR_LEN_MAX, -NME_BUG); g_return_val_if_fail(parent >= 0, -NME_BUG); r = _link_add_check_existing(self, name, type, out_link); @@ -1756,7 +1708,9 @@ nm_platform_link_set_address(NMPlatform *self, int ifindex, gconstpointer addres g_return_val_if_fail(address, -NME_BUG); g_return_val_if_fail(length > 0, -NME_BUG); - _LOG3D("link: setting hardware address to %s", (mac = nm_utils_hwaddr_ntoa(address, length))); + _LOG3D("link: setting hardware address to %s", + _nm_utils_hwaddr_ntoa_maybe_a(address, length, &mac)); + return klass->link_set_address(self, ifindex, address, length); } @@ -1782,7 +1736,7 @@ nm_platform_link_get_address(NMPlatform *self, int ifindex, size_t *length) * nm_platform_link_get_permanent_address: * @self: platform instance * @ifindex: Interface index - * @buf: buffer of at least %NM_UTILS_HWADDR_LEN_MAX bytes, on success + * @buf: buffer of at least %_NM_UTILS_HWADDR_LEN_MAX bytes, on success * the permanent hardware address * @length: Pointer to a variable to store address length * @@ -2684,8 +2638,8 @@ nm_platform_sysctl_slave_get_option(NMPlatform *self, int ifindex, const char *o gboolean nm_platform_link_vlan_change(NMPlatform * self, int ifindex, - NMVlanFlags flags_mask, - NMVlanFlags flags_set, + _NMVlanFlags flags_mask, + _NMVlanFlags flags_set, gboolean ingress_reset_all, const NMVlanQosMapping *ingress_map, gsize n_ingress_map, @@ -2800,7 +2754,7 @@ _infiniband_add_add_or_delete(NMPlatform * self, if (parent_link->type != NM_LINK_TYPE_INFINIBAND) return -NME_PL_WRONG_TYPE; - nm_utils_new_infiniband_name(name, parent_link->name, p_key); + nmp_utils_new_infiniband_name(name, parent_link->name, p_key); if (add) { r = _link_add_check_existing(self, name, NM_LINK_TYPE_INFINIBAND, out_link); @@ -3042,7 +2996,7 @@ nm_platform_link_tun_get_properties(NMPlatform *self, int ifindex, NMPlatformLnk } gboolean -nm_platform_wifi_get_capabilities(NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps) +nm_platform_wifi_get_capabilities(NMPlatform *self, int ifindex, _NMDeviceWifiCapabilities *caps) { _CHECK_SELF(self, klass, FALSE); @@ -3075,18 +3029,18 @@ nm_platform_wifi_get_station(NMPlatform * self, return klass->wifi_get_station(self, ifindex, out_bssid, out_quality, out_rate); } -NM80211Mode +_NM80211Mode nm_platform_wifi_get_mode(NMPlatform *self, int ifindex) { - _CHECK_SELF(self, klass, NM_802_11_MODE_UNKNOWN); + _CHECK_SELF(self, klass, _NM_802_11_MODE_UNKNOWN); - g_return_val_if_fail(ifindex > 0, NM_802_11_MODE_UNKNOWN); + g_return_val_if_fail(ifindex > 0, _NM_802_11_MODE_UNKNOWN); return klass->wifi_get_mode(self, ifindex); } void -nm_platform_wifi_set_mode(NMPlatform *self, int ifindex, NM80211Mode mode) +nm_platform_wifi_set_mode(NMPlatform *self, int ifindex, _NM80211Mode mode) { _CHECK_SELF_VOID(self, klass); @@ -3132,7 +3086,7 @@ nm_platform_wifi_indicate_addressing_running(NMPlatform *self, int ifindex, gboo klass->wifi_indicate_addressing_running(self, ifindex, running); } -NMSettingWirelessWakeOnWLan +_NMSettingWirelessWakeOnWLan nm_platform_wifi_get_wake_on_wlan(NMPlatform *self, int ifindex) { _CHECK_SELF(self, klass, FALSE); @@ -3143,7 +3097,7 @@ nm_platform_wifi_get_wake_on_wlan(NMPlatform *self, int ifindex) } gboolean -nm_platform_wifi_set_wake_on_wlan(NMPlatform *self, int ifindex, NMSettingWirelessWakeOnWLan wowl) +nm_platform_wifi_set_wake_on_wlan(NMPlatform *self, int ifindex, _NMSettingWirelessWakeOnWLan wowl) { _CHECK_SELF(self, klass, FALSE); @@ -3731,7 +3685,7 @@ _addr_array_clean_expired(int addr_family, goto clear_and_next; } - if (!nm_utils_lifetime_get(a->timestamp, a->lifetime, a->preferred, now, NULL)) + if (!nmp_utils_lifetime_get(a->timestamp, a->lifetime, a->preferred, now, NULL)) goto clear_and_next; if (idx) { @@ -4216,11 +4170,11 @@ next_plat:; known_address = NMP_OBJECT_CAST_IPX_ADDRESS(o); - lifetime = nm_utils_lifetime_get(known_address->ax.timestamp, - known_address->ax.lifetime, - known_address->ax.preferred, - now, - &preferred); + lifetime = nmp_utils_lifetime_get(known_address->ax.timestamp, + known_address->ax.lifetime, + known_address->ax.preferred, + now, + &preferred); nm_assert(lifetime > 0); if (IS_IPv4) { @@ -5415,7 +5369,7 @@ _lifetime_to_string(guint32 timestamp, guint32 lifetime, gint32 now, char *buf, g_snprintf(buf, buf_size, "%usec", - nm_utils_lifetime_rebase_relative_time_on_now(timestamp, lifetime, now)); + nmp_utils_lifetime_rebase_relative_time_on_now(timestamp, lifetime, now)); return buf; } @@ -5457,8 +5411,8 @@ nm_platform_link_to_string(const NMPlatformLink *link, char *buf, gsize len) char * s; gsize l; char str_addrmode[30]; - char str_address[NM_UTILS_HWADDR_LEN_MAX * 3]; - char str_broadcast[NM_UTILS_HWADDR_LEN_MAX * 3]; + char str_address[_NM_UTILS_HWADDR_LEN_MAX * 3]; + char str_broadcast[_NM_UTILS_HWADDR_LEN_MAX * 3]; char str_inet6_token[NM_UTILS_INET_ADDRSTRLEN]; const char *str_link_type; diff --git a/src/core/platform/nm-platform.h b/src/libnm-platform/nm-platform.h index b88969e89e..981465b6ce 100644 --- a/src/core/platform/nm-platform.h +++ b/src/libnm-platform/nm-platform.h @@ -6,18 +6,9 @@ #ifndef __NETWORKMANAGER_PLATFORM_H__ #define __NETWORKMANAGER_PLATFORM_H__ -#include "nm-dbus-interface.h" -#include "libnm-core-intern/nm-core-types-internal.h" - #include "libnm-platform/nmp-base.h" #include "libnm-base/nm-base.h" -#include "nm-core-utils.h" -#include "nm-setting-vlan.h" -#include "nm-setting-wired.h" -#include "nm-setting-wireless.h" -#include "nm-setting-ip-tunnel.h" - #define NM_TYPE_PLATFORM (nm_platform_get_type()) #define NM_PLATFORM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NM_TYPE_PLATFORM, NMPlatform)) #define NM_PLATFORM_CLASS(klass) \ @@ -152,7 +143,7 @@ typedef enum { typedef struct { union { - guint8 data[20 /* NM_UTILS_HWADDR_LEN_MAX */]; + guint8 data[20 /* _NM_UTILS_HWADDR_LEN_MAX */]; NMEtherAddr ether_addr; }; guint8 len; @@ -799,7 +790,7 @@ typedef struct { guint num_vlans; NMPlatformVFVlan *vlans; struct { - guint8 data[20]; /* NM_UTILS_HWADDR_LEN_MAX */ + guint8 data[20]; /* _NM_UTILS_HWADDR_LEN_MAX */ guint8 len; } mac; gint8 spoofchk; @@ -939,8 +930,8 @@ typedef struct { typedef struct { /* rtnl_link_vlan_get_id(), IFLA_VLAN_ID */ - guint16 id; - NMVlanFlags flags; + guint16 id; + _NMVlanFlags flags; } NMPlatformLnkVlan; typedef struct { @@ -1156,8 +1147,8 @@ typedef struct { gboolean (*link_vlan_change)(NMPlatform * self, int ifindex, - NMVlanFlags flags_mask, - NMVlanFlags flags_set, + _NMVlanFlags flags_mask, + _NMVlanFlags flags_set, gboolean ingress_reset_all, const NMVlanQosMapping *ingress_map, gsize n_ingress_map, @@ -1176,9 +1167,9 @@ typedef struct { const NMPlatformLink **out_link); gboolean (*infiniband_partition_delete)(NMPlatform *self, int parent, int p_key); - gboolean (*wifi_get_capabilities)(NMPlatform * self, - int ifindex, - NMDeviceWifiCapabilities *caps); + gboolean (*wifi_get_capabilities)(NMPlatform * self, + int ifindex, + _NMDeviceWifiCapabilities *caps); gboolean (*wifi_get_station)(NMPlatform * self, int ifindex, NMEtherAddr *out_bssid, @@ -1188,15 +1179,15 @@ typedef struct { guint32 (*wifi_get_frequency)(NMPlatform *self, int ifindex); int (*wifi_get_quality)(NMPlatform *self, int ifindex); guint32 (*wifi_get_rate)(NMPlatform *self, int ifindex); - NM80211Mode (*wifi_get_mode)(NMPlatform *self, int ifindex); - void (*wifi_set_mode)(NMPlatform *self, int ifindex, NM80211Mode mode); + _NM80211Mode (*wifi_get_mode)(NMPlatform *self, int ifindex); + void (*wifi_set_mode)(NMPlatform *self, int ifindex, _NM80211Mode mode); void (*wifi_set_powersave)(NMPlatform *self, int ifindex, guint32 powersave); guint32 (*wifi_find_frequency)(NMPlatform *self, int ifindex, const guint32 *freqs); void (*wifi_indicate_addressing_running)(NMPlatform *self, int ifindex, gboolean running); - NMSettingWirelessWakeOnWLan (*wifi_get_wake_on_wlan)(NMPlatform *self, int ifindex); - gboolean (*wifi_set_wake_on_wlan)(NMPlatform * self, - int ifindex, - NMSettingWirelessWakeOnWLan wowl); + _NMSettingWirelessWakeOnWLan (*wifi_get_wake_on_wlan)(NMPlatform *self, int ifindex); + gboolean (*wifi_set_wake_on_wlan)(NMPlatform * self, + int ifindex, + _NMSettingWirelessWakeOnWLan wowl); guint32 (*mesh_get_channel)(NMPlatform *self, int ifindex); gboolean (*mesh_set_channel)(NMPlatform *self, int ifindex, guint32 channel); @@ -1283,11 +1274,6 @@ const char *nm_platform_signal_change_type_to_string(NMPlatformSignalChangeType GType nm_platform_get_type(void); -void nm_platform_setup(NMPlatform *instance); -NMPlatform *nm_platform_get(void); - -#define NM_PLATFORM_GET (nm_platform_get()) - /*****************************************************************************/ static inline in_addr_t @@ -1937,8 +1923,8 @@ gboolean nm_platform_link_vlan_set_ingress_map(NMPlatform *self, int ifindex, in gboolean nm_platform_link_vlan_set_egress_map(NMPlatform *self, int ifindex, int from, int to); gboolean nm_platform_link_vlan_change(NMPlatform * self, int ifindex, - NMVlanFlags flags_mask, - NMVlanFlags flags_set, + _NMVlanFlags flags_mask, + _NMVlanFlags flags_set, gboolean ingress_reset_all, const NMVlanQosMapping *ingress_map, gsize n_ingress_map, @@ -1963,21 +1949,21 @@ gboolean nm_platform_link_tun_get_properties(NMPlatform * self, NMPlatformLnkTun *out_properties); gboolean -nm_platform_wifi_get_capabilities(NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps); -guint32 nm_platform_wifi_get_frequency(NMPlatform *self, int ifindex); -gboolean nm_platform_wifi_get_station(NMPlatform * self, - int ifindex, - NMEtherAddr *out_bssid, - int * out_quality, - guint32 * out_rate); -NM80211Mode nm_platform_wifi_get_mode(NMPlatform *self, int ifindex); -void nm_platform_wifi_set_mode(NMPlatform *self, int ifindex, NM80211Mode mode); -void nm_platform_wifi_set_powersave(NMPlatform *self, int ifindex, guint32 powersave); -guint32 nm_platform_wifi_find_frequency(NMPlatform *self, int ifindex, const guint32 *freqs); +nm_platform_wifi_get_capabilities(NMPlatform *self, int ifindex, _NMDeviceWifiCapabilities *caps); +guint32 nm_platform_wifi_get_frequency(NMPlatform *self, int ifindex); +gboolean nm_platform_wifi_get_station(NMPlatform * self, + int ifindex, + NMEtherAddr *out_bssid, + int * out_quality, + guint32 * out_rate); +_NM80211Mode nm_platform_wifi_get_mode(NMPlatform *self, int ifindex); +void nm_platform_wifi_set_mode(NMPlatform *self, int ifindex, _NM80211Mode mode); +void nm_platform_wifi_set_powersave(NMPlatform *self, int ifindex, guint32 powersave); +guint32 nm_platform_wifi_find_frequency(NMPlatform *self, int ifindex, const guint32 *freqs); void nm_platform_wifi_indicate_addressing_running(NMPlatform *self, int ifindex, gboolean running); -NMSettingWirelessWakeOnWLan nm_platform_wifi_get_wake_on_wlan(NMPlatform *self, int ifindex); +_NMSettingWirelessWakeOnWLan nm_platform_wifi_get_wake_on_wlan(NMPlatform *self, int ifindex); gboolean -nm_platform_wifi_set_wake_on_wlan(NMPlatform *self, int ifindex, NMSettingWirelessWakeOnWLan wowl); +nm_platform_wifi_set_wake_on_wlan(NMPlatform *self, int ifindex, _NMSettingWirelessWakeOnWLan wowl); guint32 nm_platform_mesh_get_channel(NMPlatform *self, int ifindex); gboolean nm_platform_mesh_set_channel(NMPlatform *self, int ifindex, guint32 channel); diff --git a/src/libnm-platform/nmp-base.h b/src/libnm-platform/nmp-base.h index e5f134185c..8a53f97c1d 100644 --- a/src/libnm-platform/nmp-base.h +++ b/src/libnm-platform/nmp-base.h @@ -7,6 +7,10 @@ /*****************************************************************************/ +#define NM_PLATFORM_LIFETIME_PERMANENT G_MAXUINT32 + +/*****************************************************************************/ + typedef enum { NM_PLATFORM_LINK_DUPLEX_UNKNOWN, NM_PLATFORM_LINK_DUPLEX_HALF, @@ -89,6 +93,87 @@ typedef struct { /*****************************************************************************/ -typedef struct _NMPNetns NMPNetns; +typedef struct _NMPNetns NMPNetns; +typedef struct _NMPlatform NMPlatform; +typedef struct _NMPlatformObject NMPlatformObject; +typedef struct _NMPlatformObjWithIfindex NMPlatformObjWithIfindex; +typedef struct _NMPlatformIP4Address NMPlatformIP4Address; +typedef struct _NMPlatformIP4Route NMPlatformIP4Route; +typedef struct _NMPlatformIP6Address NMPlatformIP6Address; +typedef struct _NMPlatformIP6Route NMPlatformIP6Route; +typedef struct _NMPlatformLink NMPlatformLink; +typedef struct _NMPObject NMPObject; + +typedef enum { + NMP_OBJECT_TYPE_UNKNOWN, + NMP_OBJECT_TYPE_LINK, + +#define NMP_OBJECT_TYPE_IP_ADDRESS(is_ipv4) \ + ((is_ipv4) ? NMP_OBJECT_TYPE_IP4_ADDRESS : NMP_OBJECT_TYPE_IP6_ADDRESS) + NMP_OBJECT_TYPE_IP4_ADDRESS, + NMP_OBJECT_TYPE_IP6_ADDRESS, + +#define NMP_OBJECT_TYPE_IP_ROUTE(is_ipv4) \ + ((is_ipv4) ? NMP_OBJECT_TYPE_IP4_ROUTE : NMP_OBJECT_TYPE_IP6_ROUTE) + NMP_OBJECT_TYPE_IP4_ROUTE, + NMP_OBJECT_TYPE_IP6_ROUTE, + + NMP_OBJECT_TYPE_ROUTING_RULE, + + NMP_OBJECT_TYPE_QDISC, + + NMP_OBJECT_TYPE_TFILTER, + + NMP_OBJECT_TYPE_LNK_BRIDGE, + NMP_OBJECT_TYPE_LNK_GRE, + NMP_OBJECT_TYPE_LNK_GRETAP, + NMP_OBJECT_TYPE_LNK_INFINIBAND, + NMP_OBJECT_TYPE_LNK_IP6TNL, + NMP_OBJECT_TYPE_LNK_IP6GRE, + NMP_OBJECT_TYPE_LNK_IP6GRETAP, + NMP_OBJECT_TYPE_LNK_IPIP, + NMP_OBJECT_TYPE_LNK_MACSEC, + NMP_OBJECT_TYPE_LNK_MACVLAN, + NMP_OBJECT_TYPE_LNK_MACVTAP, + NMP_OBJECT_TYPE_LNK_SIT, + NMP_OBJECT_TYPE_LNK_TUN, + NMP_OBJECT_TYPE_LNK_VLAN, + NMP_OBJECT_TYPE_LNK_VRF, + NMP_OBJECT_TYPE_LNK_VXLAN, + NMP_OBJECT_TYPE_LNK_WIREGUARD, + + __NMP_OBJECT_TYPE_LAST, + NMP_OBJECT_TYPE_MAX = __NMP_OBJECT_TYPE_LAST - 1, +} NMPObjectType; + +static inline guint32 +nmp_object_type_to_flags(NMPObjectType obj_type) +{ + G_STATIC_ASSERT_EXPR(NMP_OBJECT_TYPE_MAX < 32); + + nm_assert(_NM_INT_NOT_NEGATIVE(obj_type)); + nm_assert(obj_type < NMP_OBJECT_TYPE_MAX); + + return ((guint32) 1u) << obj_type; +} + +/*****************************************************************************/ + +/** + * NMIPRouteTableSyncMode: + * @NM_IP_ROUTE_TABLE_SYNC_MODE_NONE: indicate an invalid setting. + * @NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN: only the main table is synced. For all + * other tables, NM won't delete any extra routes. + * @NM_IP_ROUTE_TABLE_SYNC_MODE_FULL: NM will sync all tables, except the + * local table (255). + * @NM_IP_ROUTE_TABLE_SYNC_MODE_ALL: NM will sync all tables, including the + * local table (255). + */ +typedef enum { + NM_IP_ROUTE_TABLE_SYNC_MODE_NONE = 0, + NM_IP_ROUTE_TABLE_SYNC_MODE_MAIN = 1, + NM_IP_ROUTE_TABLE_SYNC_MODE_FULL = 2, + NM_IP_ROUTE_TABLE_SYNC_MODE_ALL = 3, +} NMIPRouteTableSyncMode; #endif /* __NMP_FWD_H__ */ diff --git a/src/core/platform/nmp-object.c b/src/libnm-platform/nmp-object.c index 49a8f5987b..b27d8dfd99 100644 --- a/src/core/platform/nmp-object.c +++ b/src/libnm-platform/nmp-object.c @@ -3,7 +3,7 @@ * Copyright (C) 2015 - 2018 Red Hat, Inc. */ -#include "src/core/nm-default-daemon.h" +#include "libnm-glib-aux/nm-default-glib-i18n-lib.h" #include "nmp-object.h" @@ -12,14 +12,10 @@ #include <linux/if.h> #include <libudev.h> -#include "nm-utils.h" #include "libnm-glib-aux/nm-secret-utils.h" - -#include "nm-core-utils.h" #include "libnm-platform/nm-platform-utils.h" - -#include "wifi/nm-wifi-utils.h" -#include "wpan/nm-wpan-utils.h" +#include "libnm-platform/wifi/nm-wifi-utils.h" +#include "libnm-platform/wpan/nm-wpan-utils.h" /*****************************************************************************/ diff --git a/src/core/platform/nmp-object.h b/src/libnm-platform/nmp-object.h index 14cf1e3f09..14cf1e3f09 100644 --- a/src/core/platform/nmp-object.h +++ b/src/libnm-platform/nmp-object.h diff --git a/src/core/platform/nmp-rules-manager.c b/src/libnm-platform/nmp-rules-manager.c index bdaefc8eab..636c90b299 100644 --- a/src/core/platform/nmp-rules-manager.c +++ b/src/libnm-platform/nmp-rules-manager.c @@ -1,12 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "src/core/nm-default-daemon.h" +#include "libnm-glib-aux/nm-default-glib-i18n-lib.h" #include "nmp-rules-manager.h" #include <linux/fib_rules.h> #include <linux/rtnetlink.h> +#include "libnm-log-core/nm-logging.h" #include "libnm-std-aux/c-list-util.h" #include "nmp-object.h" diff --git a/src/core/platform/nmp-rules-manager.h b/src/libnm-platform/nmp-rules-manager.h index 69cf907555..69cf907555 100644 --- a/src/core/platform/nmp-rules-manager.h +++ b/src/libnm-platform/nmp-rules-manager.h diff --git a/src/core/platform/wifi/nm-wifi-utils-nl80211.c b/src/libnm-platform/wifi/nm-wifi-utils-nl80211.c index 175451830f..148657ea27 100644 --- a/src/core/platform/wifi/nm-wifi-utils-nl80211.c +++ b/src/libnm-platform/wifi/nm-wifi-utils-nl80211.c @@ -5,7 +5,7 @@ * Copyright (C) 2011 Intel Corporation. All rights reserved. */ -#include "src/core/nm-default-daemon.h" +#include "libnm-glib-aux/nm-default-glib-i18n-lib.h" #include "nm-wifi-utils-nl80211.h" @@ -15,11 +15,10 @@ #include <linux/nl80211.h> #include <linux/if.h> +#include "libnm-log-core/nm-logging.h" #include "libnm-platform/nm-netlink.h" #include "nm-wifi-utils-private.h" -#include "platform/nm-platform.h" #include "libnm-platform/nm-platform-utils.h" -#include "nm-utils.h" #define _NMLOG_PREFIX_NAME "wifi-nl80211" #define _NMLOG_DOMAIN LOGD_PLATFORM | LOGD_WIFI @@ -162,8 +161,8 @@ dispose(GObject *object) } struct nl80211_iface_info { - NM80211Mode mode; - uint32_t freq; + _NM80211Mode mode; + uint32_t freq; }; static int @@ -181,16 +180,16 @@ nl80211_iface_info_handler(struct nl_msg *msg, void *arg) switch (nla_get_u32(tb[NL80211_ATTR_IFTYPE])) { case NL80211_IFTYPE_ADHOC: - info->mode = NM_802_11_MODE_ADHOC; + info->mode = _NM_802_11_MODE_ADHOC; break; case NL80211_IFTYPE_AP: - info->mode = NM_802_11_MODE_AP; + info->mode = _NM_802_11_MODE_AP; break; case NL80211_IFTYPE_STATION: - info->mode = NM_802_11_MODE_INFRA; + info->mode = _NM_802_11_MODE_INFRA; break; case NL80211_IFTYPE_MESH_POINT: - info->mode = NM_802_11_MODE_MESH; + info->mode = _NM_802_11_MODE_MESH; break; } @@ -200,25 +199,25 @@ nl80211_iface_info_handler(struct nl_msg *msg, void *arg) return NL_SKIP; } -static NM80211Mode +static _NM80211Mode wifi_nl80211_get_mode(NMWifiUtils *data) { NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; struct nl80211_iface_info iface_info = { - .mode = NM_802_11_MODE_UNKNOWN, + .mode = _NM_802_11_MODE_UNKNOWN, }; nm_auto_nlmsg struct nl_msg *msg = NULL; msg = nl80211_alloc_msg(self, NL80211_CMD_GET_INTERFACE, 0); if (nl80211_send_and_recv(self, msg, nl80211_iface_info_handler, &iface_info) < 0) - return NM_802_11_MODE_UNKNOWN; + return _NM_802_11_MODE_UNKNOWN; return iface_info.mode; } static gboolean -wifi_nl80211_set_mode(NMWifiUtils *data, const NM80211Mode mode) +wifi_nl80211_set_mode(NMWifiUtils *data, const _NM80211Mode mode) { NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; nm_auto_nlmsg struct nl_msg *msg = NULL; @@ -227,16 +226,16 @@ wifi_nl80211_set_mode(NMWifiUtils *data, const NM80211Mode mode) msg = nl80211_alloc_msg(self, NL80211_CMD_SET_INTERFACE, 0); switch (mode) { - case NM_802_11_MODE_INFRA: + case _NM_802_11_MODE_INFRA: NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_STATION); break; - case NM_802_11_MODE_ADHOC: + case _NM_802_11_MODE_ADHOC: NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_ADHOC); break; - case NM_802_11_MODE_AP: + case _NM_802_11_MODE_AP: NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_AP); break; - case NM_802_11_MODE_MESH: + case _NM_802_11_MODE_MESH: NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_MESH_POINT); break; default: @@ -271,10 +270,10 @@ nla_put_failure: static int nl80211_get_wake_on_wlan_handler(struct nl_msg *msg, void *arg) { - NMSettingWirelessWakeOnWLan *wowl = arg; - struct nlattr * attrs[NL80211_ATTR_MAX + 1]; - struct nlattr * trig[NUM_NL80211_WOWLAN_TRIG]; - struct genlmsghdr * gnlh = nlmsg_data(nlmsg_hdr(msg)); + _NMSettingWirelessWakeOnWLan *wowl = arg; + struct nlattr * attrs[NL80211_ATTR_MAX + 1]; + struct nlattr * trig[NUM_NL80211_WOWLAN_TRIG]; + struct genlmsghdr * gnlh = nlmsg_data(nlmsg_hdr(msg)); nla_parse_arr(attrs, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL); @@ -286,32 +285,32 @@ nl80211_get_wake_on_wlan_handler(struct nl_msg *msg, void *arg) nla_len(attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), NULL); - *wowl = NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE; + *wowl = _NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE; if (trig[NL80211_WOWLAN_TRIG_ANY]) - *wowl |= NM_SETTING_WIRELESS_WAKE_ON_WLAN_ANY; + *wowl |= _NM_SETTING_WIRELESS_WAKE_ON_WLAN_ANY; if (trig[NL80211_WOWLAN_TRIG_DISCONNECT]) - *wowl |= NM_SETTING_WIRELESS_WAKE_ON_WLAN_DISCONNECT; + *wowl |= _NM_SETTING_WIRELESS_WAKE_ON_WLAN_DISCONNECT; if (trig[NL80211_WOWLAN_TRIG_MAGIC_PKT]) - *wowl |= NM_SETTING_WIRELESS_WAKE_ON_WLAN_MAGIC; + *wowl |= _NM_SETTING_WIRELESS_WAKE_ON_WLAN_MAGIC; if (trig[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) - *wowl |= NM_SETTING_WIRELESS_WAKE_ON_WLAN_GTK_REKEY_FAILURE; + *wowl |= _NM_SETTING_WIRELESS_WAKE_ON_WLAN_GTK_REKEY_FAILURE; if (trig[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) - *wowl |= NM_SETTING_WIRELESS_WAKE_ON_WLAN_EAP_IDENTITY_REQUEST; + *wowl |= _NM_SETTING_WIRELESS_WAKE_ON_WLAN_EAP_IDENTITY_REQUEST; if (trig[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) - *wowl |= NM_SETTING_WIRELESS_WAKE_ON_WLAN_4WAY_HANDSHAKE; + *wowl |= _NM_SETTING_WIRELESS_WAKE_ON_WLAN_4WAY_HANDSHAKE; if (trig[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) - *wowl |= NM_SETTING_WIRELESS_WAKE_ON_WLAN_RFKILL_RELEASE; + *wowl |= _NM_SETTING_WIRELESS_WAKE_ON_WLAN_RFKILL_RELEASE; if (trig[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) - *wowl |= NM_SETTING_WIRELESS_WAKE_ON_WLAN_TCP; + *wowl |= _NM_SETTING_WIRELESS_WAKE_ON_WLAN_TCP; return NL_SKIP; } -static NMSettingWirelessWakeOnWLan +static _NMSettingWirelessWakeOnWLan wifi_nl80211_get_wake_on_wlan(NMWifiUtils *data) { NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; - NMSettingWirelessWakeOnWLan wowl = NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE; + _NMSettingWirelessWakeOnWLan wowl = _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE; nm_auto_nlmsg struct nl_msg *msg = NULL; msg = nl80211_alloc_msg(self, NL80211_CMD_GET_WOWLAN, 0); @@ -322,14 +321,14 @@ wifi_nl80211_get_wake_on_wlan(NMWifiUtils *data) } static gboolean -wifi_nl80211_set_wake_on_wlan(NMWifiUtils *data, NMSettingWirelessWakeOnWLan wowl) +wifi_nl80211_set_wake_on_wlan(NMWifiUtils *data, _NMSettingWirelessWakeOnWLan wowl) { NMWifiUtilsNl80211 * self = (NMWifiUtilsNl80211 *) data; nm_auto_nlmsg struct nl_msg *msg = NULL; struct nlattr * triggers; int err; - if (wowl == NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE) + if (wowl == _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE) return TRUE; msg = nl80211_alloc_msg(self, NL80211_CMD_SET_WOWLAN, 0); @@ -338,19 +337,19 @@ wifi_nl80211_set_wake_on_wlan(NMWifiUtils *data, NMSettingWirelessWakeOnWLan wow if (!triggers) goto nla_put_failure; - if (NM_FLAGS_HAS(wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_ANY)) + if (NM_FLAGS_HAS(wowl, _NM_SETTING_WIRELESS_WAKE_ON_WLAN_ANY)) NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); - if (NM_FLAGS_HAS(wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_DISCONNECT)) + if (NM_FLAGS_HAS(wowl, _NM_SETTING_WIRELESS_WAKE_ON_WLAN_DISCONNECT)) NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); - if (NM_FLAGS_HAS(wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_MAGIC)) + if (NM_FLAGS_HAS(wowl, _NM_SETTING_WIRELESS_WAKE_ON_WLAN_MAGIC)) NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); - if (NM_FLAGS_HAS(wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_GTK_REKEY_FAILURE)) + if (NM_FLAGS_HAS(wowl, _NM_SETTING_WIRELESS_WAKE_ON_WLAN_GTK_REKEY_FAILURE)) NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE); - if (NM_FLAGS_HAS(wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_EAP_IDENTITY_REQUEST)) + if (NM_FLAGS_HAS(wowl, _NM_SETTING_WIRELESS_WAKE_ON_WLAN_EAP_IDENTITY_REQUEST)) NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST); - if (NM_FLAGS_HAS(wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_4WAY_HANDSHAKE)) + if (NM_FLAGS_HAS(wowl, _NM_SETTING_WIRELESS_WAKE_ON_WLAN_4WAY_HANDSHAKE)) NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE); - if (NM_FLAGS_HAS(wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_RFKILL_RELEASE)) + if (NM_FLAGS_HAS(wowl, _NM_SETTING_WIRELESS_WAKE_ON_WLAN_RFKILL_RELEASE)) NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE); nla_nest_end(msg, triggers); @@ -687,12 +686,12 @@ nl80211_wiphy_info_handler(struct nl_msg *msg, void *arg) info->freqs[freq_idx] = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]); - info->caps |= NM_WIFI_DEVICE_CAP_FREQ_VALID; + info->caps |= _NM_WIFI_DEVICE_CAP_FREQ_VALID; if (info->freqs[freq_idx] > 2400 && info->freqs[freq_idx] < 2500) - info->caps |= NM_WIFI_DEVICE_CAP_FREQ_2GHZ; + info->caps |= _NM_WIFI_DEVICE_CAP_FREQ_2GHZ; if (info->freqs[freq_idx] > 4900 && info->freqs[freq_idx] < 6000) - info->caps |= NM_WIFI_DEVICE_CAP_FREQ_5GHZ; + info->caps |= _NM_WIFI_DEVICE_CAP_FREQ_5GHZ; freq_idx++; } @@ -707,16 +706,16 @@ nl80211_wiphy_info_handler(struct nl_msg *msg, void *arg) for (i = 0; i < num; i++) { switch (ciphers[i]) { case WLAN_CIPHER_SUITE_WEP40: - info->caps |= NM_WIFI_DEVICE_CAP_CIPHER_WEP40; + info->caps |= _NM_WIFI_DEVICE_CAP_CIPHER_WEP40; break; case WLAN_CIPHER_SUITE_WEP104: - info->caps |= NM_WIFI_DEVICE_CAP_CIPHER_WEP104; + info->caps |= _NM_WIFI_DEVICE_CAP_CIPHER_WEP104; break; case WLAN_CIPHER_SUITE_TKIP: - info->caps |= (NM_WIFI_DEVICE_CAP_CIPHER_TKIP | NM_WIFI_DEVICE_CAP_WPA); + info->caps |= (_NM_WIFI_DEVICE_CAP_CIPHER_TKIP | _NM_WIFI_DEVICE_CAP_WPA); break; case WLAN_CIPHER_SUITE_CCMP: - info->caps |= (NM_WIFI_DEVICE_CAP_CIPHER_CCMP | NM_WIFI_DEVICE_CAP_RSN); + info->caps |= (_NM_WIFI_DEVICE_CAP_CIPHER_CCMP | _NM_WIFI_DEVICE_CAP_RSN); break; case WLAN_CIPHER_SUITE_AES_CMAC: case WLAN_CIPHER_SUITE_GCMP: @@ -736,13 +735,13 @@ nl80211_wiphy_info_handler(struct nl_msg *msg, void *arg) nla_for_each_nested (nl_mode, tb[NL80211_ATTR_SUPPORTED_IFTYPES], i) { switch (nla_type(nl_mode)) { case NL80211_IFTYPE_AP: - info->caps |= NM_WIFI_DEVICE_CAP_AP; + info->caps |= _NM_WIFI_DEVICE_CAP_AP; break; case NL80211_IFTYPE_ADHOC: - info->caps |= NM_WIFI_DEVICE_CAP_ADHOC; + info->caps |= _NM_WIFI_DEVICE_CAP_ADHOC; break; case NL80211_IFTYPE_MESH_POINT: - info->caps |= NM_WIFI_DEVICE_CAP_MESH; + info->caps |= _NM_WIFI_DEVICE_CAP_MESH; break; } } @@ -752,7 +751,7 @@ nl80211_wiphy_info_handler(struct nl_msg *msg, void *arg) info->can_wowlan = TRUE; if (tb[NL80211_ATTR_SUPPORT_IBSS_RSN]) - info->caps |= NM_WIFI_DEVICE_CAP_IBSS_RSN; + info->caps |= _NM_WIFI_DEVICE_CAP_IBSS_RSN; info->success = TRUE; diff --git a/src/core/platform/wifi/nm-wifi-utils-nl80211.h b/src/libnm-platform/wifi/nm-wifi-utils-nl80211.h index 4a63330739..4a63330739 100644 --- a/src/core/platform/wifi/nm-wifi-utils-nl80211.h +++ b/src/libnm-platform/wifi/nm-wifi-utils-nl80211.h diff --git a/src/core/platform/wifi/nm-wifi-utils-private.h b/src/libnm-platform/wifi/nm-wifi-utils-private.h index 9ed5745383..bc1e75ec56 100644 --- a/src/core/platform/wifi/nm-wifi-utils-private.h +++ b/src/libnm-platform/wifi/nm-wifi-utils-private.h @@ -6,24 +6,23 @@ #ifndef __WIFI_UTILS_PRIVATE_H__ #define __WIFI_UTILS_PRIVATE_H__ -#include "nm-dbus-interface.h" #include "nm-wifi-utils.h" typedef struct { GObjectClass parent; - NM80211Mode (*get_mode)(NMWifiUtils *data); + _NM80211Mode (*get_mode)(NMWifiUtils *data); - gboolean (*set_mode)(NMWifiUtils *data, const NM80211Mode mode); + gboolean (*set_mode)(NMWifiUtils *data, const _NM80211Mode mode); /* Set power saving mode on an interface */ gboolean (*set_powersave)(NMWifiUtils *data, guint32 powersave); /* Get WakeOnWLAN configuration on an interface */ - NMSettingWirelessWakeOnWLan (*get_wake_on_wlan)(NMWifiUtils *data); + _NMSettingWirelessWakeOnWLan (*get_wake_on_wlan)(NMWifiUtils *data); /* Set WakeOnWLAN mode on an interface */ - gboolean (*set_wake_on_wlan)(NMWifiUtils *data, NMSettingWirelessWakeOnWLan wowl); + gboolean (*set_wake_on_wlan)(NMWifiUtils *data, _NMSettingWirelessWakeOnWLan wowl); /* Return current frequency in MHz (really associated BSS frequency) */ guint32 (*get_freq)(NMWifiUtils *data); @@ -59,8 +58,8 @@ typedef struct { struct NMWifiUtils { GObject parent; - int ifindex; - NMDeviceWifiCapabilities caps; + int ifindex; + _NMDeviceWifiCapabilities caps; }; #endif /* __WIFI_UTILS_PRIVATE_H__ */ diff --git a/src/core/platform/wifi/nm-wifi-utils-wext.c b/src/libnm-platform/wifi/nm-wifi-utils-wext.c index 1e1652fe61..9da7924320 100644 --- a/src/core/platform/wifi/nm-wifi-utils-wext.c +++ b/src/libnm-platform/wifi/nm-wifi-utils-wext.c @@ -4,7 +4,7 @@ * Copyright (C) 2006 - 2008 Novell, Inc. */ -#include "src/core/nm-default-daemon.h" +#include "libnm-glib-aux/nm-default-glib-i18n-lib.h" #include "nm-wifi-utils-wext.h" @@ -21,11 +21,9 @@ #include <sys/socket.h> #include <linux/wireless.h> +#include "libnm-log-core/nm-logging.h" #include "nm-wifi-utils-private.h" -#include "nm-utils.h" #include "libnm-platform/nm-platform-utils.h" -#include "libnm-core-intern/nm-core-internal.h" -#include "nm-core-utils.h" typedef struct { NMWifiUtils parent; @@ -114,7 +112,7 @@ get_ifname(int ifindex, char *buffer, const char *op) return TRUE; } -static NM80211Mode +static _NM80211Mode wifi_wext_get_mode_ifname(NMWifiUtils *data, const char *ifname) { NMWifiUtilsWext *wext = (NMWifiUtilsWext *) data; @@ -129,24 +127,24 @@ wifi_wext_get_mode_ifname(NMWifiUtils *data, const char *ifname) if (errsv != ENODEV) { _LOGW(LOGD_PLATFORM | LOGD_WIFI, "(%s): error %d getting card mode", ifname, errsv); } - return NM_802_11_MODE_UNKNOWN; + return _NM_802_11_MODE_UNKNOWN; } switch (wrq.u.mode) { case IW_MODE_ADHOC: - return NM_802_11_MODE_ADHOC; + return _NM_802_11_MODE_ADHOC; case IW_MODE_MASTER: - return NM_802_11_MODE_AP; + return _NM_802_11_MODE_AP; case IW_MODE_INFRA: case IW_MODE_AUTO: /* hack for WEXT devices reporting IW_MODE_AUTO */ - return NM_802_11_MODE_INFRA; + return _NM_802_11_MODE_INFRA; default: break; } - return NM_802_11_MODE_UNKNOWN; + return _NM_802_11_MODE_UNKNOWN; } -static NM80211Mode +static _NM80211Mode wifi_wext_get_mode(NMWifiUtils *data) { char ifname[IFNAMSIZ]; @@ -158,7 +156,7 @@ wifi_wext_get_mode(NMWifiUtils *data) } static gboolean -wifi_wext_set_mode(NMWifiUtils *data, const NM80211Mode mode) +wifi_wext_set_mode(NMWifiUtils *data, const _NM80211Mode mode) { NMWifiUtilsWext *wext = (NMWifiUtilsWext *) data; struct iwreq wrq; @@ -172,13 +170,13 @@ wifi_wext_set_mode(NMWifiUtils *data, const NM80211Mode mode) memset(&wrq, 0, sizeof(struct iwreq)); switch (mode) { - case NM_802_11_MODE_ADHOC: + case _NM_802_11_MODE_ADHOC: wrq.u.mode = IW_MODE_ADHOC; break; - case NM_802_11_MODE_AP: + case _NM_802_11_MODE_AP: wrq.u.mode = IW_MODE_MASTER; break; - case NM_802_11_MODE_INFRA: + case _NM_802_11_MODE_INFRA: wrq.u.mode = IW_MODE_INFRA; break; default: @@ -637,36 +635,36 @@ wext_get_range_ifname(NMWifiUtilsWext *wext, return success; } -#define WPA_CAPS \ - (NM_WIFI_DEVICE_CAP_CIPHER_TKIP | NM_WIFI_DEVICE_CAP_CIPHER_CCMP | NM_WIFI_DEVICE_CAP_WPA \ - | NM_WIFI_DEVICE_CAP_RSN) +#define WPA_CAPS \ + (_NM_WIFI_DEVICE_CAP_CIPHER_TKIP | _NM_WIFI_DEVICE_CAP_CIPHER_CCMP | _NM_WIFI_DEVICE_CAP_WPA \ + | _NM_WIFI_DEVICE_CAP_RSN) static guint32 wext_get_caps(NMWifiUtilsWext *wext, const char *ifname, struct iw_range *range) { - guint32 caps = NM_WIFI_DEVICE_CAP_NONE; + guint32 caps = _NM_WIFI_DEVICE_CAP_NONE; - g_return_val_if_fail(wext != NULL, NM_WIFI_DEVICE_CAP_NONE); - g_return_val_if_fail(range != NULL, NM_WIFI_DEVICE_CAP_NONE); + g_return_val_if_fail(wext != NULL, _NM_WIFI_DEVICE_CAP_NONE); + g_return_val_if_fail(range != NULL, _NM_WIFI_DEVICE_CAP_NONE); /* All drivers should support WEP by default */ - caps |= NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | NM_WIFI_DEVICE_CAP_CIPHER_WEP104; + caps |= _NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | _NM_WIFI_DEVICE_CAP_CIPHER_WEP104; if (range->enc_capa & IW_ENC_CAPA_CIPHER_TKIP) - caps |= NM_WIFI_DEVICE_CAP_CIPHER_TKIP; + caps |= _NM_WIFI_DEVICE_CAP_CIPHER_TKIP; if (range->enc_capa & IW_ENC_CAPA_CIPHER_CCMP) - caps |= NM_WIFI_DEVICE_CAP_CIPHER_CCMP; + caps |= _NM_WIFI_DEVICE_CAP_CIPHER_CCMP; if (range->enc_capa & IW_ENC_CAPA_WPA) - caps |= NM_WIFI_DEVICE_CAP_WPA; + caps |= _NM_WIFI_DEVICE_CAP_WPA; if (range->enc_capa & IW_ENC_CAPA_WPA2) - caps |= NM_WIFI_DEVICE_CAP_RSN; + caps |= _NM_WIFI_DEVICE_CAP_RSN; /* Check for cipher support but not WPA support */ - if ((caps & (NM_WIFI_DEVICE_CAP_CIPHER_TKIP | NM_WIFI_DEVICE_CAP_CIPHER_CCMP)) - && !(caps & (NM_WIFI_DEVICE_CAP_WPA | NM_WIFI_DEVICE_CAP_RSN))) { + if ((caps & (_NM_WIFI_DEVICE_CAP_CIPHER_TKIP | _NM_WIFI_DEVICE_CAP_CIPHER_CCMP)) + && !(caps & (_NM_WIFI_DEVICE_CAP_WPA | _NM_WIFI_DEVICE_CAP_RSN))) { _LOGW(LOGD_WIFI, "%s: device supports WPA ciphers but not WPA protocol; WPA unavailable.", ifname); @@ -674,8 +672,8 @@ wext_get_caps(NMWifiUtilsWext *wext, const char *ifname, struct iw_range *range) } /* Check for WPA support but not cipher support */ - if ((caps & (NM_WIFI_DEVICE_CAP_WPA | NM_WIFI_DEVICE_CAP_RSN)) - && !(caps & (NM_WIFI_DEVICE_CAP_CIPHER_TKIP | NM_WIFI_DEVICE_CAP_CIPHER_CCMP))) { + if ((caps & (_NM_WIFI_DEVICE_CAP_WPA | _NM_WIFI_DEVICE_CAP_RSN)) + && !(caps & (_NM_WIFI_DEVICE_CAP_CIPHER_TKIP | _NM_WIFI_DEVICE_CAP_CIPHER_CCMP))) { _LOGW(LOGD_WIFI, "%s: device supports WPA protocol but not WPA ciphers; WPA unavailable.", ifname); @@ -686,7 +684,7 @@ wext_get_caps(NMWifiUtilsWext *wext, const char *ifname, struct iw_range *range) * (other than actually trying to do it), so just assume that * Ad-Hoc is supported and AP isn't. */ - caps |= NM_WIFI_DEVICE_CAP_ADHOC; + caps |= _NM_WIFI_DEVICE_CAP_ADHOC; return caps; } @@ -793,11 +791,11 @@ nm_wifi_utils_wext_new(int ifindex, gboolean check_scan) wext->parent.caps = wext_get_caps(wext, ifname, &range); if (freq_valid) - wext->parent.caps |= NM_WIFI_DEVICE_CAP_FREQ_VALID; + wext->parent.caps |= _NM_WIFI_DEVICE_CAP_FREQ_VALID; if (has_2ghz) - wext->parent.caps |= NM_WIFI_DEVICE_CAP_FREQ_2GHZ; + wext->parent.caps |= _NM_WIFI_DEVICE_CAP_FREQ_2GHZ; if (has_5ghz) - wext->parent.caps |= NM_WIFI_DEVICE_CAP_FREQ_5GHZ; + wext->parent.caps |= _NM_WIFI_DEVICE_CAP_FREQ_5GHZ; _LOGI(LOGD_PLATFORM | LOGD_WIFI, "(%s): using WEXT for Wi-Fi device control", ifname); diff --git a/src/core/platform/wifi/nm-wifi-utils-wext.h b/src/libnm-platform/wifi/nm-wifi-utils-wext.h index d6f3453c2e..d6f3453c2e 100644 --- a/src/core/platform/wifi/nm-wifi-utils-wext.h +++ b/src/libnm-platform/wifi/nm-wifi-utils-wext.h diff --git a/src/core/platform/wifi/nm-wifi-utils.c b/src/libnm-platform/wifi/nm-wifi-utils.c index ff2c9a30fa..3c952b6fcd 100644 --- a/src/core/platform/wifi/nm-wifi-utils.c +++ b/src/libnm-platform/wifi/nm-wifi-utils.c @@ -4,7 +4,7 @@ * Copyright (C) 2006 - 2008 Novell, Inc. */ -#include "src/core/nm-default-daemon.h" +#include "libnm-glib-aux/nm-default-glib-i18n-lib.h" #include "nm-wifi-utils.h" @@ -17,8 +17,6 @@ #if HAVE_WEXT #include "nm-wifi-utils-wext.h" #endif -#include "nm-core-utils.h" - #include "libnm-platform/nm-platform-utils.h" G_DEFINE_ABSTRACT_TYPE(NMWifiUtils, nm_wifi_utils, G_TYPE_OBJECT) @@ -50,29 +48,29 @@ nm_wifi_utils_new(int ifindex, struct nl_sock *genl, gboolean check_scan) return ret; } -NMDeviceWifiCapabilities +_NMDeviceWifiCapabilities nm_wifi_utils_get_caps(NMWifiUtils *data) { - g_return_val_if_fail(data != NULL, NM_WIFI_DEVICE_CAP_NONE); + g_return_val_if_fail(data != NULL, _NM_WIFI_DEVICE_CAP_NONE); return data->caps; } -NM80211Mode +_NM80211Mode nm_wifi_utils_get_mode(NMWifiUtils *data) { - g_return_val_if_fail(data != NULL, NM_802_11_MODE_UNKNOWN); + g_return_val_if_fail(data != NULL, _NM_802_11_MODE_UNKNOWN); return NM_WIFI_UTILS_GET_CLASS(data)->get_mode(data); } gboolean -nm_wifi_utils_set_mode(NMWifiUtils *data, const NM80211Mode mode) +nm_wifi_utils_set_mode(NMWifiUtils *data, const _NM80211Mode mode) { NMWifiUtilsClass *klass; g_return_val_if_fail(data != NULL, FALSE); - g_return_val_if_fail((mode == NM_802_11_MODE_INFRA) || (mode == NM_802_11_MODE_AP) - || (mode == NM_802_11_MODE_ADHOC) || (mode == NM_802_11_MODE_MESH), + g_return_val_if_fail((mode == _NM_802_11_MODE_INFRA) || (mode == _NM_802_11_MODE_AP) + || (mode == _NM_802_11_MODE_ADHOC) || (mode == _NM_802_11_MODE_MESH), FALSE); klass = NM_WIFI_UTILS_GET_CLASS(data); @@ -92,21 +90,21 @@ nm_wifi_utils_set_powersave(NMWifiUtils *data, guint32 powersave) return klass->set_powersave ? klass->set_powersave(data, powersave) : TRUE; } -NMSettingWirelessWakeOnWLan +_NMSettingWirelessWakeOnWLan nm_wifi_utils_get_wake_on_wlan(NMWifiUtils *data) { NMWifiUtilsClass *klass; - g_return_val_if_fail(data != NULL, NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE); + g_return_val_if_fail(data != NULL, _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE); klass = NM_WIFI_UTILS_GET_CLASS(data); return klass->get_wake_on_wlan ? klass->get_wake_on_wlan(data) - : NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE; + : _NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE; } gboolean -nm_wifi_utils_set_wake_on_wlan(NMWifiUtils *data, NMSettingWirelessWakeOnWLan wowl) +nm_wifi_utils_set_wake_on_wlan(NMWifiUtils *data, _NMSettingWirelessWakeOnWLan wowl) { NMWifiUtilsClass *klass; diff --git a/src/core/platform/wifi/nm-wifi-utils.h b/src/libnm-platform/wifi/nm-wifi-utils.h index 7bb1cd8e0f..157522ee26 100644 --- a/src/core/platform/wifi/nm-wifi-utils.h +++ b/src/libnm-platform/wifi/nm-wifi-utils.h @@ -9,9 +9,8 @@ #include <net/ethernet.h> -#include "nm-dbus-interface.h" -#include "nm-setting-wireless.h" #include "libnm-platform/nm-netlink.h" +#include "libnm-base/nm-base.h" typedef struct NMWifiUtils NMWifiUtils; @@ -30,11 +29,11 @@ gboolean nm_wifi_utils_is_wifi(int dirfd, const char *ifname); NMWifiUtils *nm_wifi_utils_new(int ifindex, struct nl_sock *genl, gboolean check_scan); -NMDeviceWifiCapabilities nm_wifi_utils_get_caps(NMWifiUtils *data); +_NMDeviceWifiCapabilities nm_wifi_utils_get_caps(NMWifiUtils *data); -NM80211Mode nm_wifi_utils_get_mode(NMWifiUtils *data); +_NM80211Mode nm_wifi_utils_get_mode(NMWifiUtils *data); -gboolean nm_wifi_utils_set_mode(NMWifiUtils *data, const NM80211Mode mode); +gboolean nm_wifi_utils_set_mode(NMWifiUtils *data, const _NM80211Mode mode); /* Returns frequency in MHz */ guint32 nm_wifi_utils_get_freq(NMWifiUtils *data); @@ -60,9 +59,9 @@ gboolean nm_wifi_utils_indicate_addressing_running(NMWifiUtils *data, gboolean r gboolean nm_wifi_utils_set_powersave(NMWifiUtils *data, guint32 powersave); -NMSettingWirelessWakeOnWLan nm_wifi_utils_get_wake_on_wlan(NMWifiUtils *data); +_NMSettingWirelessWakeOnWLan nm_wifi_utils_get_wake_on_wlan(NMWifiUtils *data); -gboolean nm_wifi_utils_set_wake_on_wlan(NMWifiUtils *data, NMSettingWirelessWakeOnWLan wowl); +gboolean nm_wifi_utils_set_wake_on_wlan(NMWifiUtils *data, _NMSettingWirelessWakeOnWLan wowl); /* OLPC Mesh-only functions */ guint32 nm_wifi_utils_get_mesh_channel(NMWifiUtils *data); diff --git a/src/core/platform/wpan/nm-wpan-utils.c b/src/libnm-platform/wpan/nm-wpan-utils.c index 9fa23793af..5c2917b4dc 100644 --- a/src/core/platform/wpan/nm-wpan-utils.c +++ b/src/libnm-platform/wpan/nm-wpan-utils.c @@ -3,14 +3,15 @@ * Copyright (C) 2018 Red Hat, Inc. */ -#include "src/core/nm-default-daemon.h" +#include "libnm-glib-aux/nm-default-glib-i18n-lib.h" #include "nm-wpan-utils.h" #include <linux/if.h> +#include "libnm-log-core/nm-logging.h" #include "libnm-platform/nm-netlink.h" -#include "platform/linux/nl802154.h" +#include "linux-headers/nl802154.h" #include "libnm-platform/nm-platform-utils.h" #define _NMLOG_PREFIX_NAME "wpan-nl802154" diff --git a/src/core/platform/wpan/nm-wpan-utils.h b/src/libnm-platform/wpan/nm-wpan-utils.h index 50ecd6fe84..6130c41e56 100644 --- a/src/core/platform/wpan/nm-wpan-utils.h +++ b/src/libnm-platform/wpan/nm-wpan-utils.h @@ -8,7 +8,6 @@ #include <net/ethernet.h> -#include "nm-dbus-interface.h" #include "libnm-platform/nm-netlink.h" typedef struct NMWpanUtils NMWpanUtils; diff --git a/src/core/platform/linux/nl802154.h b/src/linux-headers/nl802154.h index c21bd0791c..c21bd0791c 100644 --- a/src/core/platform/linux/nl802154.h +++ b/src/linux-headers/nl802154.h |