mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-04 23:28:08 +02:00
device: fix nm_device_get_type_description() for veth devices
Without this, nm_device_get_type_description() would quite likely
return "ethernet" for NMDeviceVeth types. This is wrong and was
broken recently.
Fixes: 0775602574
This commit is contained in:
parent
5f8f427361
commit
9731b06b78
2 changed files with 17 additions and 2 deletions
|
|
@ -2133,8 +2133,20 @@ get_type_description (NMDevice *self)
|
|||
|
||||
nm_assert (NM_IS_DEVICE (self));
|
||||
|
||||
/* the default implementation for the description just returns the (modified)
|
||||
* class name and depends entirely on the type of self. Note that we cache the
|
||||
* description in the klass itself.
|
||||
*
|
||||
* Also note, that as the GObject class gets inited, it inherrits the fields
|
||||
* of the parent class. That means, if NMDeviceVethClass was initialized after
|
||||
* NMDeviceEthernetClass already has the description cached in the class
|
||||
* (because we already fetched the description for an ethernet device),
|
||||
* then default_type_description will wrongly contain "ethernet".
|
||||
* To avoid that, and catch the situation, also cache the klass for
|
||||
* which the description was cached. If that doesn't match, it was
|
||||
* inherited and we need to reset it. */
|
||||
klass = NM_DEVICE_GET_CLASS (self);
|
||||
if (G_UNLIKELY (!klass->default_type_description)) {
|
||||
if (G_UNLIKELY (klass->default_type_description_klass != klass)) {
|
||||
const char *typename;
|
||||
gs_free char *s = NULL;
|
||||
|
||||
|
|
@ -2143,8 +2155,10 @@ get_type_description (NMDevice *self)
|
|||
typename += 8;
|
||||
s = g_ascii_strdown (typename, -1);
|
||||
klass->default_type_description = g_intern_string (s);
|
||||
klass->default_type_description_klass = klass;
|
||||
}
|
||||
|
||||
nm_assert (klass->default_type_description);
|
||||
return klass->default_type_description;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -189,9 +189,10 @@ typedef enum { /*< skip >*/
|
|||
NM_DEVICE_CHECK_DEV_AVAILABLE_ALL = (1L << 1) - 1,
|
||||
} NMDeviceCheckDevAvailableFlags;
|
||||
|
||||
typedef struct {
|
||||
typedef struct _NMDeviceClass {
|
||||
NMDBusObjectClass parent;
|
||||
|
||||
struct _NMDeviceClass *default_type_description_klass;
|
||||
const char *default_type_description;
|
||||
|
||||
const char *connection_type;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue