mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-21 08:20:33 +01:00
device,config: for virtual devices store the interface name to "no-auto-default.state"
For devices that have no real MAC address (virtual devices) it makes no sense to store the MAC address to "no-auto-default.state" file. Also, because we later would not match the MAC address during nm_match_spec_device(). Instead, extend the format and add a "interface-name:=$IFACE" match-spec. Maybe we generally should prefer the interface-name over the MAC address. Anyway, for now, just extend the previously non-working case.
This commit is contained in:
parent
c43a32ea5f
commit
fb8d1cda94
2 changed files with 45 additions and 19 deletions
|
|
@ -1634,17 +1634,30 @@ set_property (GObject *object,
|
|||
|
||||
for (i = 0; i < len; i++) {
|
||||
const char *s = value_arr[i];
|
||||
gboolean is_mac;
|
||||
char *spec;
|
||||
|
||||
if (!s[0])
|
||||
continue;
|
||||
if (!nm_utils_hwaddr_valid (s, -1))
|
||||
|
||||
if (NM_STR_HAS_PREFIX (s, NM_MATCH_SPEC_INTERFACE_NAME_TAG"="))
|
||||
is_mac = FALSE;
|
||||
else if (nm_utils_hwaddr_valid (s, -1))
|
||||
is_mac = TRUE;
|
||||
else {
|
||||
/* we drop all lines that we don't understand. */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nm_utils_strv_find_first (priv->no_auto_default.arr, j, s) >= 0)
|
||||
continue;
|
||||
|
||||
spec = is_mac
|
||||
? g_strdup_printf (NM_MATCH_SPEC_MAC_TAG"%s", s)
|
||||
: g_strdup (s);
|
||||
|
||||
priv->no_auto_default.arr[j++] = g_strdup (s);
|
||||
priv->no_auto_default.specs = g_slist_prepend (priv->no_auto_default.specs,
|
||||
g_strdup_printf (NM_MATCH_SPEC_MAC_TAG"%s", s));
|
||||
priv->no_auto_default.specs = g_slist_prepend (priv->no_auto_default.specs, spec);
|
||||
}
|
||||
nm_assert (j <= len);
|
||||
priv->no_auto_default.arr[j++] = NULL;
|
||||
|
|
|
|||
|
|
@ -368,8 +368,14 @@ no_auto_default_from_file (const char *no_auto_default_file)
|
|||
|
||||
s = nm_utils_str_utf8safe_unescape (s, &s_to_free);
|
||||
|
||||
if (!nm_utils_hwaddr_valid (s, -1))
|
||||
if ( !NM_STR_HAS_PREFIX (s, NM_MATCH_SPEC_INTERFACE_NAME_TAG"=")
|
||||
&& !nm_utils_hwaddr_valid (s, -1)) {
|
||||
/* Maybe we shouldn't pre-validate the device specs that we read
|
||||
* from the file. After all, nm_match_spec_*() API silently ignores
|
||||
* all unknown value. However, lets just be strict here for now
|
||||
* and only accept what we also write. */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nm_utils_strv_find_first ((char **) list, l, s) >= 0)
|
||||
continue;
|
||||
|
|
@ -433,7 +439,10 @@ nm_config_set_no_auto_default_for_device (NMConfig *self, NMDevice *device)
|
|||
NMConfigPrivate *priv;
|
||||
GError *error = NULL;
|
||||
NMConfigData *new_data = NULL;
|
||||
gs_free char *spec_to_free = NULL;
|
||||
const char *ifname;
|
||||
const char *hw_address;
|
||||
const char *spec;
|
||||
const char *const*no_auto_default_current;
|
||||
GPtrArray *no_auto_default_new = NULL;
|
||||
gboolean is_fake;
|
||||
|
|
@ -446,25 +455,29 @@ nm_config_set_no_auto_default_for_device (NMConfig *self, NMDevice *device)
|
|||
|
||||
hw_address = nm_device_get_permanent_hw_address_full (device, TRUE, &is_fake);
|
||||
|
||||
if (!hw_address)
|
||||
return;
|
||||
|
||||
if (is_fake) {
|
||||
/* this is a problem. The MAC address is fake, it's possibly only valid
|
||||
* until reboot (or even less).
|
||||
*
|
||||
* Also, nm_device_spec_match_list() ignores fake addresses, so even if
|
||||
* we would persist it, it wouldn't work (well, maybe it should?).
|
||||
*
|
||||
* Anyway, let's do nothing here. NMSettings needs to remember this
|
||||
* in memory. */
|
||||
if (!hw_address) {
|
||||
/* No MAC address, not even a fake one. We don't do anything for this device. */
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_fake) {
|
||||
/* A fake MAC address, no point in storing it to the file.
|
||||
* Also, nm_match_spec_device() would ignore fake MAC addresses.
|
||||
*
|
||||
* Instead, try the interface-name... */
|
||||
ifname = nm_device_get_ip_iface (device);
|
||||
if (!nm_utils_is_valid_iface_name (ifname, NULL))
|
||||
return;
|
||||
|
||||
spec_to_free = g_strdup_printf (NM_MATCH_SPEC_INTERFACE_NAME_TAG"=%s", ifname);
|
||||
spec = spec_to_free;
|
||||
} else
|
||||
spec = hw_address;
|
||||
|
||||
no_auto_default_current = nm_config_data_get_no_auto_default (priv->config_data);
|
||||
|
||||
if (nm_utils_strv_find_first ((char **) no_auto_default_current, -1, hw_address) >= 0) {
|
||||
/* @hw_address is already blocked. We don't have to update our in-memory representation.
|
||||
if (nm_utils_strv_find_first ((char **) no_auto_default_current, -1, spec) >= 0) {
|
||||
/* @spec is already blocked. We don't have to update our in-memory representation.
|
||||
* Maybe we should write to no_auto_default_file anew, but let's save that too. */
|
||||
return;
|
||||
}
|
||||
|
|
@ -472,7 +485,7 @@ nm_config_set_no_auto_default_for_device (NMConfig *self, NMDevice *device)
|
|||
no_auto_default_new = g_ptr_array_new ();
|
||||
for (i = 0; no_auto_default_current && no_auto_default_current[i]; i++)
|
||||
g_ptr_array_add (no_auto_default_new, (char *) no_auto_default_current[i]);
|
||||
g_ptr_array_add (no_auto_default_new, (char *) hw_address);
|
||||
g_ptr_array_add (no_auto_default_new, (char *) spec);
|
||||
g_ptr_array_add (no_auto_default_new, NULL);
|
||||
|
||||
if (!no_auto_default_to_file (priv->no_auto_default_file, (const char *const*) no_auto_default_new->pdata, &error)) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue