After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 693684 - allow matching devices by interface name
allow matching devices by interface name
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: NetworkManager maintainer(s)
NetworkManager maintainer(s)
: 683102 692880 696988 (view as bug list)
Depends on:
Blocks: nm-0.9.10
 
 
Reported: 2013-02-12 23:06 UTC by Dan Winship
Modified: 2013-09-30 09:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
core: move most spec_match_list handling into NMDevice (8.50 KB, patch)
2013-02-12 23:06 UTC, Dan Winship
none Details | Review
core: allow marking a device unmanaged by its interface name (8.10 KB, patch)
2013-02-12 23:06 UTC, Dan Winship
none Details | Review
core: fix NMDeviceEthernet matching (2.58 KB, patch)
2013-03-08 20:25 UTC, Dan Winship
reviewed Details | Review
core: simplify nm_device_spec_match_list() (8.60 KB, patch)
2013-03-08 20:25 UTC, Dan Winship
reviewed Details | Review
core: simplify/rename nm_device_connection_match_config() (17.93 KB, patch)
2013-03-08 20:25 UTC, Dan Winship
reviewed Details | Review
core: simplify nm_device_get_best_auto_connection() (34.65 KB, patch)
2013-03-08 20:25 UTC, Dan Winship
reviewed Details | Review
libnm-util: add NMSettingConnection:interface-name (7.71 KB, patch)
2013-03-08 20:25 UTC, Dan Winship
reviewed Details | Review
settings: read/write NMSettingConnection:interface-name (4.32 KB, patch)
2013-03-08 20:25 UTC, Dan Winship
reviewed Details | Review
core: make nm_device_check_connection_compatible() check interface-name (8.46 KB, patch)
2013-03-08 20:26 UTC, Dan Winship
reviewed Details | Review
core: allow marking a device unmanaged by its interface name (13.92 KB, patch)
2013-03-08 20:26 UTC, Dan Winship
reviewed Details | Review
libnm-glib: match interface name in nm_device_connection_compatible() (13.90 KB, patch)
2013-03-11 14:18 UTC, Dan Winship
reviewed Details | Review

Description Dan Winship 2013-02-12 23:06:12 UTC
patches aren't tested yet beyond "it compiles", and I have to add
ifcfg-rh and keyfile tests as well. Just wanted buy-in on the proof of
concept first...
Comment 1 Dan Winship 2013-02-12 23:06:14 UTC
Created attachment 235831 [details] [review]
core: move most spec_match_list handling into NMDevice

Since NMDevice has a generic get_hw_address() method now, it can do
nm_device_spec_match_list() itself (for everything except ethernet,
which needs to match against s390 subchannels too).
Comment 2 Dan Winship 2013-02-12 23:06:16 UTC
Created attachment 235832 [details] [review]
core: allow marking a device unmanaged by its interface name

Virtual devices often don't have stable hardware addresses. So allow
for marking a device unmanaged via its interface name instead.
Comment 3 Dan Winship 2013-02-18 20:19:53 UTC
*** Bug 692880 has been marked as a duplicate of this bug. ***
Comment 4 Dan Winship 2013-02-18 20:21:41 UTC
https://bugzilla.redhat.com/show_bug.cgi?id=902907 points out additional issues involving matching bridge interfaces
Comment 5 Dan Williams 2013-02-19 16:02:18 UTC
Yeah, we can create any number of unmanaged specs we want here, but again this will go away when we cooperatively handle the interfaces.  SO maybe some hacks here that we remove later, if that's possible.
Comment 6 Dan Winship 2013-03-08 20:25:21 UTC
Created attachment 238399 [details] [review]
core: fix NMDeviceEthernet matching

nm_device_connection_match_config() on an ethernet connection could
succeed for a device that was in the connection's
mac-address-blacklist, but then NM would immediately fail to activate
the connection because nm_device_connection_compatible() would check
the blacklist and return FALSE. Fix the former to match the latter.
Comment 7 Dan Winship 2013-03-08 20:25:33 UTC
Created attachment 238401 [details] [review]
core: simplify nm_device_spec_match_list()

Since NMDevice has a generic get_hw_address() method now, it can do
nm_device_spec_match_list() itself (for everything except ethernet,
which needs to match against s390 subchannels too).
Comment 8 Dan Winship 2013-03-08 20:25:38 UTC
Created attachment 238402 [details] [review]
core: simplify/rename nm_device_connection_match_config()

nm_device_connection_match_config() sounded more generic than it
really was; rename it to nm_device_find_assumable_connection(), which
is what it really does.

There was also a lot of redundancy/cut+paste in the subclass
implementations of connection_match_config(); Improve things by moving
the looping-over-connections code into NMDevice itself, and also doing
the general-device-compatibility and IP-config checking there, leaving
the device subclasses to just verify L2 properties. Which most of them
aren't doing...
Comment 9 Dan Winship 2013-03-08 20:25:45 UTC
Created attachment 238403 [details] [review]
core: simplify nm_device_get_best_auto_connection()

As with the other connection-matching methods, move the loop and the
device-independent bits into NMDevice. By reusing
nm_device_check_connection_compatible(), this means that most device
types now no longer need any type-specific code for this.
Comment 10 Dan Winship 2013-03-08 20:25:54 UTC
Created attachment 238404 [details] [review]
libnm-util: add NMSettingConnection:interface-name
Comment 11 Dan Winship 2013-03-08 20:25:59 UTC
Created attachment 238405 [details] [review]
settings: read/write NMSettingConnection:interface-name
Comment 12 Dan Winship 2013-03-08 20:26:09 UTC
Created attachment 238406 [details] [review]
core: make nm_device_check_connection_compatible() check interface-name

If an NMConnection specifies an interface-name, it is only compatible
with a device with the same ip-iface.
Comment 13 Dan Winship 2013-03-08 20:26:15 UTC
Created attachment 238407 [details] [review]
core: allow marking a device unmanaged by its interface name

Virtual devices often don't have stable hardware addresses. So allow
for marking a device unmanaged via its interface name instead.
Comment 14 Dan Winship 2013-03-08 20:27:55 UTC
(In reply to comment #11)
> Created an attachment (id=238405) [details] [review]
> settings: read/write NMSettingConnection:interface-name

the non-ifcfg-rh non-keyfile parts of this are untested and probably completely wrong...
Comment 15 Dan Winship 2013-03-08 20:28:19 UTC
also pushed to danw/iface-match
Comment 16 Dan Winship 2013-03-11 14:18:19 UTC
Created attachment 238580 [details] [review]
libnm-glib: match interface name in nm_device_connection_compatible()

Do NMSettingConnection:interface-name matching on the client side as
well, so that, eg, nm-applet does not list connections under the wrong
device.

(Also, move some return-if-fail checks from the subclass method
implementations into the wrapper function.)
Comment 17 Dan Williams 2013-03-13 16:01:40 UTC
Review of attachment 238399 [details] [review]:

Looks good.
Comment 18 Dan Williams 2013-03-13 16:03:43 UTC
Review of attachment 238401 [details] [review]:

Looks good.
Comment 19 Dan Williams 2013-03-13 16:09:48 UTC
Review of attachment 238402 [details] [review]:

One thing to note is that find_assumable_connection() now uses check_connection_compatible().  There's a behavioral difference between the two; find_assumable() matches a connection specifically to a device's existing configuration, while check_connection_compatible() is a much looser check to determine if the device *could*, if reconfigured, use this connection.  I don't think that matters right now but coudn't you note that in some docs for find_assumable_connection?
Comment 20 Dan Williams 2013-03-13 16:21:45 UTC
Review of attachment 238403 [details] [review]:

Looks good.
Comment 21 Dan Williams 2013-03-13 16:35:11 UTC
Review of attachment 238404 [details] [review]:

Looks good, though one docs change suggestion.

::: libnm-util/nm-setting-connection.c
@@ +1041,3 @@
+	 **/
+	g_object_class_install_property
+		(object_class, PROP_INTERFACE_NAME,

For the last part, let's go with something more like:

For connection types where interface names cannot easily be made persistent (eg, mobile broadband or USB ethernet), this property should not be used.  Setting this property restricts the interfaces a connection can be used with, and if interface names change or are reordered the connection may be applied to the wrong interface.
Comment 22 Dan Williams 2013-03-13 16:40:16 UTC
Review of attachment 238405 [details] [review]:

Looks good.
Comment 23 Dan Williams 2013-03-13 16:44:58 UTC
Review of attachment 238406 [details] [review]:

::: src/nm-device.c
@@ +1474,3 @@
+
+	config_iface = nm_setting_connection_get_interface_name (s_con);
+	device_iface = nm_device_get_ip_iface (device);

We should be checking nm_device_get_iface() here, not ip_iface.  Using ip_iface() here would mean that when eth0 has an active PPPoE connection, suddenly any connection with the interface name "eth0" no longer applies to the NMDevice because the IP iface is ppp0, not eth0.

Also, the IP iface is dynamically allocated, so it could be ppp1, ppp2, nas5, etc.

@@ +1475,3 @@
+	config_iface = nm_setting_connection_get_interface_name (s_con);
+	device_iface = nm_device_get_ip_iface (device);
+	if (config_iface && device_iface && strcmp (config_iface, device_iface) != 0)

nm_device_get_iface() should always return something, otherwise the sky is falling.  We don't need the check for "device_iface" here.  Feel free to g_assert (device_iface) if you want.
Comment 24 Dan Winship 2013-03-13 16:48:28 UTC
(In reply to comment #19)
> Review of attachment 238402 [details] [review]:
> 
> One thing to note is that find_assumable_connection() now uses
> check_connection_compatible().

It doesn't *only* use check_connection_compatible() though; that's just one of several checks it makes.

Passing check_connection_compatible() is a necessary (but not sufficient) condition for being assumable, because if NMManager decides to assume a connection, it will call internal_activate_device() on it, which then immediately calls nm_device_check_connection_compatible().
Comment 25 Dan Williams 2013-03-13 16:52:48 UTC
Review of attachment 238407 [details] [review]:

::: src/nm-device.c
@@ +5504,3 @@
+	if (matched)
+		return TRUE;
+	else if (nm_match_spec_interface_name (specs, nm_device_get_ip_iface (device)))

We want nm_device_get_iface() here, not ip_iface.

@@ +5507,3 @@
+		return TRUE;
+	else
+		return FALSE;

Seems a bit clearer to do something like:

if (!matched)
    matched = nm_match_spec_interface_name (specs, nm_device_get_ip_iface (device));

return matched;

::: src/settings/plugins/keyfile/plugin.c
@@ +457,3 @@
 		for (i = 0; udis[i] != NULL; i++) {
 			/* Verify unmanaged specification and add it to the list */
+			if (!strncmp (udis[i], "mac:", 4) && ether_aton (udis[i] + 4)) {

g_str_has_prefix()?

@@ +467,3 @@
 				}
 				specs = g_slist_append (specs, udis[i]);
+			} else if (!strncmp (udis[i], "interface-name:", 10) && nm_utils_iface_valid_name (udis[i] + 10)) {

g_str_has_prefix()?
Comment 26 Dan Williams 2013-03-13 16:55:36 UTC
Review of attachment 238580 [details] [review]:

It kinda burns me that we have this API, since we now have AvailableConnections and I can't think of a good use for checking some random connection against the device that's not already in NetworkManager's AvailableConnections list for the device, which means a lot of duplicated code between libnm-glib and NM itself.  Oh well...

::: libnm-glib/nm-device.c
@@ +1619,3 @@
+
+	config_iface = nm_setting_connection_get_interface_name (s_con);
+	device_iface = nm_device_get_ip_iface (device);

nm_device_get_iface()
Comment 27 Dan Williams 2013-03-13 16:57:06 UTC
(In reply to comment #25)
> @@ +5507,3 @@
> +        return TRUE;
> +    else
> +        return FALSE;
> 
> Seems a bit clearer to do something like:
> 
> if (!matched)
>     matched = nm_match_spec_interface_name (specs, nm_device_get_ip_iface
> (device));
> 
> return matched;

And of course here I mean to use nm_device_get_iface() too...
Comment 28 Dan Winship 2013-03-13 17:58:44 UTC
(In reply to comment #25)
> +            if (!strncmp (udis[i], "mac:", 4) && ether_aton (udis[i] + 4)) {
> 
> g_str_has_prefix()?

thought about that, but I left it as it was because we'd still be hardcoding the length later on in the line anyway
Comment 29 Dan Winship 2013-03-13 21:08:37 UTC
fixed and pushed
Comment 30 Dan Williams 2013-04-03 13:28:15 UTC
*** Bug 696988 has been marked as a duplicate of this bug. ***
Comment 31 Pavel Simerda 2013-09-30 09:34:35 UTC
*** Bug 683102 has been marked as a duplicate of this bug. ***