diff options
author | Thomas Haller <thaller@redhat.com> | 2019-07-18 15:42:37 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-07-25 10:52:19 +0200 |
commit | fb8d1cda94a3f2c27b091ac2f3696080654d25ff (patch) | |
tree | a392fa231107ab7e776a29548997304e40961afe | |
parent | c43a32ea5f4e149cf1337711c67e3e58d75e72ba (diff) | |
download | NetworkManager-fb8d1cda94a3f2c27b091ac2f3696080654d25ff.tar.gz |
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.
-rw-r--r-- | src/nm-config-data.c | 19 | ||||
-rw-r--r-- | src/nm-config.c | 41 |
2 files changed, 43 insertions, 17 deletions
diff --git a/src/nm-config-data.c b/src/nm-config-data.c index 9cc1054f6c..77368b4dad 100644 --- a/src/nm-config-data.c +++ b/src/nm-config-data.c @@ -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; diff --git a/src/nm-config.c b/src/nm-config.c index 21f4c21b06..f92e5a5846 100644 --- a/src/nm-config.c +++ b/src/nm-config.c @@ -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) + if (!hw_address) { + /* No MAC address, not even a fake one. We don't do anything for this device. */ return; + } if (is_fake) { - /* this is a problem. The MAC address is fake, it's possibly only valid - * until reboot (or even less). + /* A fake MAC address, no point in storing it to the file. + * Also, nm_match_spec_device() would ignore fake MAC addresses. * - * 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. */ - return; - } + * 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)) { |