mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-05 04:30:16 +01:00
core: unify parsing of device specs using nm_match_spec_split()
There are three configuration options that contain device specs:
'main.ignore-carrier', 'main.no-auto-default', and
'keyfile.unmanaged-devices'.
Unify the parsing of them by splitting the device spec with
nm_match_spec_split(). This changes behavior for parsing of these
properties.
Also get rid of logging warnings when parsing 'keyfile.unmanaged-devices'.
(cherry picked from commit c6778ad1b7)
This commit is contained in:
parent
832023fe1c
commit
2be628334c
3 changed files with 31 additions and 51 deletions
|
|
@ -32,6 +32,7 @@
|
|||
#include "NetworkManagerUtils.h"
|
||||
#include "gsystem-local-alloc.h"
|
||||
#include "nm-enum-types.h"
|
||||
#include "nm-core-internal.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
|
@ -74,7 +75,7 @@ typedef struct {
|
|||
|
||||
char *debug;
|
||||
|
||||
char **ignore_carrier;
|
||||
GSList *ignore_carrier;
|
||||
|
||||
gboolean configure_and_quit;
|
||||
} NMConfigPrivate;
|
||||
|
|
@ -227,21 +228,10 @@ nm_config_get_configure_and_quit (NMConfig *config)
|
|||
gboolean
|
||||
nm_config_get_ignore_carrier (NMConfig *config, NMDevice *device)
|
||||
{
|
||||
NMConfigPrivate *priv = NM_CONFIG_GET_PRIVATE (config);
|
||||
GSList *specs = NULL;
|
||||
int i;
|
||||
gboolean match;
|
||||
g_return_val_if_fail (NM_IS_CONFIG (config), FALSE);
|
||||
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
|
||||
|
||||
if (!priv->ignore_carrier)
|
||||
return FALSE;
|
||||
|
||||
for (i = 0; priv->ignore_carrier[i]; i++)
|
||||
specs = g_slist_prepend (specs, priv->ignore_carrier[i]);
|
||||
|
||||
match = nm_device_spec_match_list (device, specs);
|
||||
|
||||
g_slist_free (specs);
|
||||
return match;
|
||||
return nm_device_spec_match_list (device, NM_CONFIG_GET_PRIVATE (config)->ignore_carrier);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
|
@ -679,6 +669,15 @@ read_entire_config (const NMConfigCmdLineOptions *cli,
|
|||
return keyfile;
|
||||
}
|
||||
|
||||
GSList *
|
||||
nm_config_get_device_match_spec (const GKeyFile *keyfile, const char *group, const char *key)
|
||||
{
|
||||
gs_free char *value = NULL;
|
||||
|
||||
value = g_key_file_get_string ((GKeyFile *) keyfile, group, key, NULL);
|
||||
return nm_match_spec_split (value);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
void
|
||||
|
|
@ -805,7 +804,8 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
|
|||
char *config_main_file = NULL;
|
||||
char *config_description = NULL;
|
||||
char **no_auto_default;
|
||||
char **no_auto_default_orig;
|
||||
GSList *no_auto_default_orig_list;
|
||||
GPtrArray *no_auto_default_orig;
|
||||
|
||||
if (priv->config_dir) {
|
||||
/* Object is already initialized. */
|
||||
|
|
@ -850,17 +850,22 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
|
|||
|
||||
priv->debug = g_key_file_get_value (keyfile, "main", "debug", NULL);
|
||||
|
||||
priv->ignore_carrier = g_key_file_get_string_list (keyfile, "main", "ignore-carrier", NULL, NULL);
|
||||
priv->ignore_carrier = nm_config_get_device_match_spec (keyfile, "main", "ignore-carrier");
|
||||
|
||||
priv->configure_and_quit = _get_bool_value (keyfile, "main", "configure-and-quit", FALSE);
|
||||
|
||||
no_auto_default_orig = g_key_file_get_string_list (keyfile, "main", "no-auto-default", NULL, NULL);
|
||||
no_auto_default = no_auto_default_merge_from_file (priv->no_auto_default_file, (const char *const *) no_auto_default_orig);
|
||||
no_auto_default_orig_list = nm_config_get_device_match_spec (keyfile, "main", "no-auto-default");
|
||||
|
||||
no_auto_default_orig = _nm_utils_copy_slist_to_array (no_auto_default_orig_list, NULL, NULL);
|
||||
g_ptr_array_add (no_auto_default_orig, NULL);
|
||||
no_auto_default = no_auto_default_merge_from_file (priv->no_auto_default_file, (const char *const *) no_auto_default_orig->pdata);
|
||||
g_ptr_array_unref (no_auto_default_orig);
|
||||
|
||||
g_slist_free_full (no_auto_default_orig_list, g_free);
|
||||
|
||||
priv->config_data_orig = nm_config_data_new (config_main_file, config_description, (const char *const*) no_auto_default, keyfile);
|
||||
|
||||
g_strfreev (no_auto_default);
|
||||
g_strfreev (no_auto_default_orig);
|
||||
|
||||
priv->config_data = g_object_ref (priv->config_data_orig);
|
||||
|
||||
|
|
@ -900,7 +905,7 @@ finalize (GObject *gobject)
|
|||
g_free (priv->log_level);
|
||||
g_free (priv->log_domains);
|
||||
g_free (priv->debug);
|
||||
g_strfreev (priv->ignore_carrier);
|
||||
g_slist_free_full (priv->ignore_carrier, g_free);
|
||||
|
||||
_nm_config_cmd_line_options_clear (&priv->cli);
|
||||
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ NMConfig *nm_config_setup (const NMConfigCmdLineOptions *cli, GError **error);
|
|||
void nm_config_reload (NMConfig *config);
|
||||
|
||||
GKeyFile *nm_config_create_keyfile (void);
|
||||
GSList *nm_config_get_device_match_spec (const GKeyFile *keyfile, const char *group, const char *key);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -585,45 +585,19 @@ get_unmanaged_specs (NMSystemConfigInterface *config)
|
|||
GKeyFile *key_file;
|
||||
GSList *specs = NULL;
|
||||
GError *error = NULL;
|
||||
char *str;
|
||||
|
||||
if (!priv->conf_file)
|
||||
return NULL;
|
||||
|
||||
key_file = g_key_file_new ();
|
||||
if (!parse_key_file_allow_none (priv, key_file, &error))
|
||||
goto out;
|
||||
key_file = nm_config_create_keyfile ();
|
||||
if (parse_key_file_allow_none (priv, key_file, &error))
|
||||
specs = nm_config_get_device_match_spec (key_file, "keyfile", "unmanaged-devices");
|
||||
|
||||
str = g_key_file_get_value (key_file, "keyfile", "unmanaged-devices", NULL);
|
||||
if (str) {
|
||||
char **udis;
|
||||
int i;
|
||||
|
||||
udis = g_strsplit_set (str, ";,", -1);
|
||||
g_free (str);
|
||||
|
||||
for (i = 0; udis[i] != NULL; i++) {
|
||||
/* Verify unmanaged specification and add it to the list */
|
||||
if (!strncmp (udis[i], "mac:", 4) && nm_utils_hwaddr_valid (udis[i] + 4, -1)) {
|
||||
specs = g_slist_append (specs, udis[i]);
|
||||
} else if (!strncmp (udis[i], "interface-name:", 15) && nm_utils_iface_valid_name (udis[i] + 15)) {
|
||||
specs = g_slist_append (specs, udis[i]);
|
||||
} else {
|
||||
nm_log_warn (LOGD_SETTINGS, "keyfile: error in file '%s': invalid unmanaged-devices entry: '%s'", priv->conf_file, udis[i]);
|
||||
g_free (udis[i]);
|
||||
}
|
||||
}
|
||||
|
||||
g_free (udis); /* Yes, g_free, not g_strfreev because we need the strings in the list */
|
||||
}
|
||||
|
||||
out:
|
||||
if (error) {
|
||||
nm_log_warn (LOGD_SETTINGS, "keyfile: error getting unmanaged specs: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
if (key_file)
|
||||
g_key_file_free (key_file);
|
||||
g_key_file_free (key_file);
|
||||
|
||||
return specs;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue