From edc37b3adf7d39057e7f06aa4ab736b38f7c8162 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Thu, 2 Dec 2021 18:34:10 -0700 Subject: [PATCH] build: allow configuring default for wifi.backend setting Distributions may want to change the default wifi.backend, if for example they are building without wpa_supplicant support. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/869 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1040 --- Makefile.am | 3 ++- config.h.meson | 3 +++ configure.ac | 19 +++++++++++++++++++ contrib/fedora/rpm/build_clean.sh | 1 + man/NetworkManager.conf.xml | 1 + man/common.ent.in | 1 + meson.build | 9 +++++++++ meson_options.txt | 1 + src/core/devices/wifi/nm-wifi-factory.c | 5 ++++- src/core/nm-config-data.c | 3 +++ 10 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 98b1507c7c..6023b457c2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -202,7 +202,8 @@ data_edit = sed \ -e 's|@NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT[@]|$(NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT)|g' \ -e 's|@NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT[@]|$(NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT)|g' \ -e 's|@NM_CONFIG_DEFAULT_MAIN_RC_MANAGER[@]|$(NM_CONFIG_DEFAULT_MAIN_RC_MANAGER)|g' \ - -e 's|@NM_CONFIG_DEFAULT_MAIN_DHCP[@]|$(NM_CONFIG_DEFAULT_MAIN_DHCP)|g' + -e 's|@NM_CONFIG_DEFAULT_MAIN_DHCP[@]|$(NM_CONFIG_DEFAULT_MAIN_DHCP)|g' \ + -e 's|@NM_CONFIG_DEFAULT_WIFI_BACKEND_TEXT[@]|$(NM_CONFIG_DEFAULT_WIFI_BACKEND_TEXT)|g' ############################################################################### diff --git a/config.h.meson b/config.h.meson index 901535cf9f..192246e558 100644 --- a/config.h.meson +++ b/config.h.meson @@ -100,6 +100,9 @@ /* Default value for main.rc-manager setting */ #mesondefine NM_CONFIG_DEFAULT_MAIN_RC_MANAGER +/* Default configuration option for wifi.backend */ +#mesondefine NM_CONFIG_DEFAULT_WIFI_BACKEND + /* Define the distribution version string */ #mesondefine NM_DIST_VERSION diff --git a/configure.ac b/configure.ac index 035ce04639..af89392a49 100644 --- a/configure.ac +++ b/configure.ac @@ -404,6 +404,25 @@ AC_DEFINE_UNQUOTED(NM_CONFIG_DEFAULT_LOGGING_BACKEND, "$nm_config_logging_backen NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT="$nm_config_logging_backend_default" AC_SUBST(NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT) +AC_ARG_WITH(config-wifi-backend-default, + AS_HELP_STRING([--with-config-wifi-backend-default=backend], + [Default value for wifi.backend]), + nm_config_wifi_backend_default="$withval", + nm_config_wifi_backend_default="wpa_supplicant") + +if test "$nm_config_wifi_backend_default" != 'iwd' \ + -a "$nm_config_wifi_backend_default" != 'wpa_supplicant'; then + AC_MSG_ERROR([The default Wi-Fi backend must be either wpa_supplicant or iwd.]) +fi +if test "$nm_config_wifi_backend_default" = "iwd"; then + if test "$ac_with_iwd" != "yes"; then + AC_MSG_ERROR([Setting the default Wi-Fi backend to iwd requires iwd support.]) + fi +fi +AC_DEFINE_UNQUOTED(NM_CONFIG_DEFAULT_WIFI_BACKEND, "$nm_config_wifi_backend_default", [Default configuration option for wifi.backend]) +NM_CONFIG_DEFAULT_WIFI_BACKEND_TEXT="$nm_config_wifi_backend_default" +AC_SUBST(NM_CONFIG_DEFAULT_WIFI_BACKEND_TEXT) + # Session tracking support AC_ARG_WITH(systemd-logind, AS_HELP_STRING([--with-systemd-logind=yes|no], diff --git a/contrib/fedora/rpm/build_clean.sh b/contrib/fedora/rpm/build_clean.sh index 82b804fa49..7c221d69a5 100755 --- a/contrib/fedora/rpm/build_clean.sh +++ b/contrib/fedora/rpm/build_clean.sh @@ -198,6 +198,7 @@ if [[ $NO_DIST != 1 ]]; then --enable-ifcfg-rh \ --enable-ifupdown \ --with-config-logging-backend-default=syslog \ + --with-config-wifi-backend-default=wpa_supplicant \ --with-libaudit=yes-disabled-by-default \ --enable-polkit=yes \ --with-nm-cloud-setup=yes \ diff --git a/man/NetworkManager.conf.xml b/man/NetworkManager.conf.xml index 545ac68dc9..c1afaad050 100644 --- a/man/NetworkManager.conf.xml +++ b/man/NetworkManager.conf.xml @@ -1237,6 +1237,7 @@ managed=1 Specify the Wi-Fi backend used for the device. Currently, supported are wpa_supplicant and iwd (experimental). + If unspecified, the default is "&NM_CONFIG_DEFAULT_WIFI_BACKEND_TEXT;". diff --git a/man/common.ent.in b/man/common.ent.in index 9632b4efba..ae792f2529 100644 --- a/man/common.ent.in +++ b/man/common.ent.in @@ -8,3 +8,4 @@ + diff --git a/meson.build b/meson.build index c4976f69fb..6f2885ab7b 100644 --- a/meson.build +++ b/meson.build @@ -389,6 +389,14 @@ if config_logging_backend_default == 'default' endif config_h.set_quoted('NM_CONFIG_DEFAULT_LOGGING_BACKEND', config_logging_backend_default) +config_wifi_backend_default = get_option('config_wifi_backend_default') +if config_wifi_backend_default == 'default' + config_wifi_backend_default = 'wpa_supplicant' +elif config_wifi_backend_default == 'iwd' + assert(enable_iwd, 'Setting the default Wi-Fi backend to iwd requires iwd support.') +endif +config_h.set_quoted('NM_CONFIG_DEFAULT_WIFI_BACKEND', config_wifi_backend_default) + session_tracking = get_option('session_tracking') session_trackers = [] @@ -890,6 +898,7 @@ data_conf.set('NM_CONFIG_DEFAULT_LOGGING_BACKEND_TEXT', config_logging_backend_ data_conf.set('NM_CONFIG_DEFAULT_MAIN_AUTH_POLKIT_TEXT', config_auth_polkit_default) data_conf.set('NM_CONFIG_DEFAULT_MAIN_DHCP', config_dhcp_default) data_conf.set('NM_CONFIG_DEFAULT_MAIN_RC_MANAGER', config_dns_rc_manager_default) +data_conf.set('NM_CONFIG_DEFAULT_WIFI_BACKEND_TEXT', config_wifi_backend_default) data_conf.set('NM_MAJOR_VERSION', nm_major_version) data_conf.set('NM_MICRO_VERSION', nm_micro_version) data_conf.set('NM_MINOR_VERSION', nm_minor_version) diff --git a/meson_options.txt b/meson_options.txt index 76a131ad05..cfebe44619 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -21,6 +21,7 @@ option('polkit_agent_helper_1', type: 'string', value: '', description: 'Path na option('selinux', type: 'boolean', value: true, description: 'Build with SELinux') option('systemd_journal', type: 'boolean', value: true, description: 'Use systemd journal for logging') option('config_logging_backend_default', type: 'combo', choices: ['default', 'syslog', 'journal'], value: 'default', description: 'Default value for logging.backend') +option('config_wifi_backend_default', type: 'combo', choices: ['default', 'wpa_supplicant', 'iwd'], value: 'default', description: 'Default value for wifi.backend') option('hostname_persist', type: 'combo', choices: ['default', 'suse', 'gentoo', 'slackware'], value: 'default', description: 'Hostname persist method') option('libaudit', type: 'combo', choices: ['yes', 'yes-disabled-by-default', 'no'], value: 'yes', description: 'Build with audit daemon support. yes-disabled-by-default enables support, but disables it unless explicitly configured via NetworkManager.conf') diff --git a/src/core/devices/wifi/nm-wifi-factory.c b/src/core/devices/wifi/nm-wifi-factory.c index 8f152413b8..d17d04cee7 100644 --- a/src/core/devices/wifi/nm-wifi-factory.c +++ b/src/core/devices/wifi/nm-wifi-factory.c @@ -92,12 +92,15 @@ create_device(NMDeviceFactory *factory, NULL); backend = nm_strstrip_avoid_copy_a(300, backend, &backend_free); + if (!backend) + backend = "" NM_CONFIG_DEFAULT_WIFI_BACKEND; + nm_log_dbg(LOGD_PLATFORM | LOGD_WIFI, "(%s) config: backend is %s%s%s%s", iface, NM_PRINT_FMT_QUOTE_STRING(backend), WITH_IWD ? " (iwd support enabled)" : ""); - if (!backend || !g_ascii_strcasecmp(backend, "wpa_supplicant")) { + if (!g_ascii_strcasecmp(backend, "wpa_supplicant")) { NMDevice *device; _NMDeviceWifiCapabilities capabilities; _NM80211Mode mode; diff --git a/src/core/nm-config-data.c b/src/core/nm-config-data.c index 2b9094cbe2..ddb7787fef 100644 --- a/src/core/nm-config-data.c +++ b/src/core/nm-config-data.c @@ -711,6 +711,9 @@ static const struct { {NM_CONFIG_KEYFILE_GROUP_MAIN, NM_CONFIG_KEYFILE_KEY_MAIN_IWD_CONFIG_PATH, ""}, {NM_CONFIG_KEYFILE_GROUP_LOGGING, "backend", NM_CONFIG_DEFAULT_LOGGING_BACKEND}, {NM_CONFIG_KEYFILE_GROUP_LOGGING, "audit", NM_CONFIG_DEFAULT_LOGGING_AUDIT}, + {NM_CONFIG_KEYFILE_GROUPPREFIX_DEVICE, + NM_CONFIG_KEYFILE_KEY_DEVICE_WIFI_BACKEND, + NM_CONFIG_DEFAULT_WIFI_BACKEND}, }; void