merge: branch 'bg/reject-unsupported-conns'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2299
This commit is contained in:
Beniamino Galvani 2025-10-21 15:34:19 +02:00
commit ce26d85ad1
7 changed files with 173 additions and 4 deletions

View file

@ -239,6 +239,15 @@
/* Whether we build with OVS plugin */
#mesondefine WITH_OPENVSWITCH
/* Whether we build with team support */
#mesondefine WITH_TEAMDCTL
/* Whether we build with Wi-Fi support */
#mesondefine WITH_WIFI
/* Whether we build with WWAN support */
#mesondefine WITH_WWAN
/* Define if you have PPP support */
#mesondefine WITH_PPP

View file

@ -327,6 +327,7 @@ config_h.set10('WITH_CONFIG_PLUGIN_IFUPDOWN', enable_ifupdown)
config_h.set_quoted('NM_DIST_VERSION', dist_version)
enable_wifi = get_option('wifi')
config_h.set10('WITH_WIFI', enable_wifi)
enable_iwd = get_option('iwd')
assert((not enable_iwd) or enable_wifi, 'Enabling iwd support requires Wi-Fi support as well')
@ -507,6 +508,7 @@ if enable_teamdctl
libteamdctl_dep = dependency('libteamdctl', version: '>= 1.9')
assert(libteamdctl_dep.found(), 'You must have libteamdctl installed to build. Use -Dteamdctl=false to disable it')
endif
config_h.set10('WITH_TEAMDCTL', enable_teamdctl)
# polkit
enable_polkit = get_option('polkit')
@ -616,6 +618,7 @@ if enable_modem_manager
endif
config_h.set_quoted('MOBILE_BROADBAND_PROVIDER_INFO_DATABASE', mobile_broadband_provider_info_database)
endif
config_h.set10('WITH_WWAN', enable_modem_manager)
# Bluez5 DUN support
enable_bluez5_dun = get_option('bluez5_dun')

View file

@ -5474,3 +5474,96 @@ nm_utils_shorten_hostname(const char *hostname, char **shortened)
*shortened = g_steal_pointer(&s);
return TRUE;
}
/**
* nm_utils_connection_supported:
* @connection: the connection
* @error: on return, the reason why the connection in not supported
*
* Returns whether the given connection is supported by this version
* of NetworkManager.
*/
gboolean
nm_utils_connection_supported(NMConnection *connection, GError **error)
{
const char *type;
const char *feature = NULL;
g_return_val_if_fail(connection, FALSE);
g_return_val_if_fail(!error || !*error, FALSE);
type = nm_connection_get_connection_type(connection);
if (!WITH_TEAMDCTL) {
NMSettingConnection *s_con;
if (nm_streq0(type, NM_SETTING_TEAM_SETTING_NAME)) {
feature = "team";
goto out_disabled;
}
/* Match team ports */
if ((s_con = nm_connection_get_setting_connection(connection))
&& nm_streq0(nm_setting_connection_get_port_type(s_con),
NM_SETTING_TEAM_SETTING_NAME)) {
feature = "team";
goto out_disabled;
}
}
if (!WITH_OPENVSWITCH) {
if (NM_IN_STRSET(type,
NM_SETTING_OVS_BRIDGE_SETTING_NAME,
NM_SETTING_OVS_PORT_SETTING_NAME,
NM_SETTING_OVS_INTERFACE_SETTING_NAME)) {
feature = "Open vSwitch";
goto out_disabled;
}
/* Match OVS system interfaces */
if (nm_connection_get_setting_ovs_interface(connection)) {
feature = "Open vSwitch";
goto out_disabled;
}
}
if (!WITH_WIFI
&& NM_IN_STRSET(type,
NM_SETTING_WIRELESS_SETTING_NAME,
NM_SETTING_OLPC_MESH_SETTING_NAME,
NM_SETTING_WIFI_P2P_SETTING_NAME)) {
feature = "Wi-Fi";
goto out_disabled;
}
if (!WITH_WWAN
&& NM_IN_STRSET(type, NM_SETTING_GSM_SETTING_NAME, NM_SETTING_CDMA_SETTING_NAME)) {
feature = "WWAN";
goto out_disabled;
}
if (nm_streq0(type, NM_SETTING_WIMAX_SETTING_NAME)) {
feature = "WiMAX";
goto out_removed;
}
return TRUE;
out_disabled:
nm_assert(feature);
g_set_error(error,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_FEATURE_DISABLED,
"%s support is disabled in this build",
feature);
return FALSE;
out_removed:
nm_assert(feature);
g_set_error(error,
NM_SETTINGS_ERROR,
NM_SETTINGS_ERROR_FEATURE_REMOVED,
"%s is no longer supported",
feature);
return FALSE;
}

View file

@ -490,4 +490,8 @@ uid_t nm_utils_get_nm_uid(void);
gid_t nm_utils_get_nm_gid(void);
/*****************************************************************************/
gboolean nm_utils_connection_supported(NMConnection *connection, GError **error);
#endif /* __NM_CORE_UTILS_H__ */

View file

@ -27,6 +27,19 @@
struct _NMSettingsPlugin;
/**
* NMSettingsStorage:
* @_plugin: The settings plugin that provides this storage.
* @_uuid: UUID of the profile represented by this storage.
* @_filename: Backing filename (can be NULL for in-memory or meta-data).
* @_storage_lst: Node in the per-plugin storage list.
* @_storage_by_uuid_lst: Node in the per-UUID storage list.
*
* Describes the origin and identity of one profile instance as provided by a
* specific settings plugin and (optionally) a backing file. A single UUID may
* have multiple storages from different plugins; plugin order determines
* priority.
*/
typedef struct NMSettingsStorage {
GObject parent;
struct _NMSettingsPlugin *_plugin;

View file

@ -76,6 +76,17 @@ static NM_CACHED_QUARK_FCN("default-wired-connection-blocked",
/*****************************************************************************/
/**
* StorageData:
* @sd_lst: Node used in per-UUID storage lists.
* @storage: Storage provider instance for this UUID.
* @connection: Connection object backed by @storage, or NULL for meta-data.
* @prioritize: Request to prioritize this storage during merge.
*
* Per-UUID storage entry used to accumulate and merge updates from plugins.
* Items live temporarily in the dirty list and are merged into the current list
* with stable priority ordering.
*/
typedef struct _StorageData {
CList sd_lst;
NMSettingsStorage *storage;
@ -165,6 +176,20 @@ _storage_data_is_alive(StorageData *sd)
/*****************************************************************************/
/**
* SettConnEntry:
* @uuid: Normalized UUID key for this entry (points to @_uuid_data).
* @sett_conn: Current NMSettingsConnection selected for @uuid, or NULL.
* @storage: The storage that currently owns @sett_conn, or NULL.
* @sd_lst_head: Head of current storages list for @uuid (high to low priority).
* @dirty_sd_lst_head: Head of pending storage updates to merge.
* @sce_dirty_lst: Node in the global dirty queue.
* @_uuid_data: Inline storage backing @uuid.
*
* Tracks one connection profile across all storages and its dirty state.
* It holds the authoritative in-memory connection and the sets of storages
* providing or updating it.
*/
typedef struct {
const char *uuid;
NMSettingsConnection *sett_conn;
@ -1368,10 +1393,11 @@ _connection_changed_track(NMSettings *self,
NMConnection *connection,
gboolean prioritize)
{
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self);
SettConnEntry *sett_conn_entry;
StorageData *sd;
const char *uuid;
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE(self);
SettConnEntry *sett_conn_entry;
StorageData *sd;
const char *uuid;
gs_free_error GError *error = NULL;
nm_assert_valid_settings_storage(NULL, storage);
@ -1382,6 +1408,17 @@ _connection_changed_track(NMSettings *self,
|| (_nm_connection_verify(connection, NULL) == NM_SETTING_VERIFY_SUCCESS));
nm_assert(!connection || nm_streq0(uuid, nm_connection_get_uuid(connection)));
if (connection && !nm_utils_connection_supported(connection, &error)) {
_LOGD("storage[%s," NM_SETTINGS_STORAGE_PRINT_FMT
"]: ignoring connection \"%s\" from file \"%s\": %s",
uuid,
NM_SETTINGS_STORAGE_PRINT_ARG(storage),
nm_connection_get_id(connection),
nm_settings_storage_get_filename(storage),
error->message);
connection = NULL;
}
nm_assert_connection_unchanging(connection);
sett_conn_entry =
@ -1851,6 +1888,9 @@ nm_settings_add_connection(NMSettings *self,
NM_SET_OUT(out_sett_conn, NULL);
if (!nm_utils_connection_supported(connection, error))
return FALSE;
uuid = nm_connection_get_uuid(connection);
sett_conn_entry = _sett_conn_entries_get(self, uuid);

View file

@ -256,6 +256,11 @@ GQuark nm_secret_agent_error_quark(void);
* @NM_SETTINGS_ERROR_NOT_SUPPORTED_BY_PLUGIN: the requested operation is not
* supported by the settings plugin currently in use for the specified object.
* Since: 1.44.
* @NM_SETTINGS_ERROR_FEATURE_DISABLED: the requested operation failed because it
* requires a feature that is disabled in this build of NetworkManager.
* Since: 1.56
* @NM_SETTINGS_ERROR_FEATURE_REMOVED: the requested operation failed because it
* requires a feature that is no longer supported. Since: 1.56
*
* Errors related to the settings/persistent configuration interface of
* NetworkManager.
@ -275,6 +280,8 @@ typedef enum {
NM_SETTINGS_ERROR_INVALID_ARGUMENTS, /*< nick=InvalidArguments >*/
NM_SETTINGS_ERROR_VERSION_ID_MISMATCH, /*< nick=VersionIdMismatch >*/
NM_SETTINGS_ERROR_NOT_SUPPORTED_BY_PLUGIN, /*< nick=NotSupportedByPlugin >*/
NM_SETTINGS_ERROR_FEATURE_DISABLED, /*< nick=FeatureDisabled >*/
NM_SETTINGS_ERROR_FEATURE_REMOVED, /*< nick=FeatureRemoved >*/
} NMSettingsError;
GQuark nm_settings_error_quark(void);