diff options
author | Fernando Fernandez Mancera <ffmancera@riseup.net> | 2023-03-06 17:57:16 +0100 |
---|---|---|
committer | Fernando Fernandez Mancera <ffmancera@riseup.net> | 2023-03-08 14:49:01 +0100 |
commit | 7f96d4d2cd9caa9f3f3a804919b31ce49f9dfdfa (patch) | |
tree | 694a2f779339aaa57fa76081549ad1a72ec306ce | |
parent | 5a9a7623c5a4bae2001b30eb99e640e2e3285c3e (diff) |
devices: drop wrong assertion on parent when ifindex is not presentff/fix_networking_off
When creating a parent dependent device it can have software device as
parent without an ifindex. In that case, it will fail on an ssertion on
parent being missing.
In order to avoid this, we are handling the situation similar to what we
do for VLAN devices. NetworkManager will raise different error and block
the autoconnection instead of asserting.
This solves the assert error for the following commands:
```
nmcli connection add type macvlan ifname mv1 con-name mv1+ macvlan.parent dummy0 mode vepa
nmcli connection add type dummy ifname dummy0 con-name dummy0+ autoconnect no
```
-rw-r--r-- | src/core/devices/nm-device-6lowpan.c | 14 | ||||
-rw-r--r-- | src/core/devices/nm-device-macvlan.c | 14 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/core/devices/nm-device-6lowpan.c b/src/core/devices/nm-device-6lowpan.c index 870a1c14ef..f3386ddb58 100644 --- a/src/core/devices/nm-device-6lowpan.c +++ b/src/core/devices/nm-device-6lowpan.c @@ -72,14 +72,22 @@ create_and_realize(NMDevice *device, s_6lowpan = NM_SETTING_6LOWPAN(nm_connection_get_setting(connection, NM_TYPE_SETTING_6LOWPAN)); g_return_val_if_fail(s_6lowpan, FALSE); - parent_ifindex = parent ? nm_device_get_ifindex(parent) : 0; + if (!parent) { + g_set_error(error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_MISSING_DEPENDENCIES, + "6LoWPAN device can not be created without a parent interface"); + return FALSE; + } + parent_ifindex = nm_device_get_ifindex(parent); if (parent_ifindex <= 0) { g_set_error(error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES, - "6LoWPAN devices can not be created without a parent interface"); - g_return_val_if_fail(!parent, FALSE); + "cannot retrieve ifindex of interface %s (%s)", + nm_device_get_iface(parent), + nm_device_get_type_desc(parent)); return FALSE; } diff --git a/src/core/devices/nm-device-macvlan.c b/src/core/devices/nm-device-macvlan.c index 3f57bfb1fc..06c0df07e9 100644 --- a/src/core/devices/nm-device-macvlan.c +++ b/src/core/devices/nm-device-macvlan.c @@ -208,14 +208,22 @@ create_and_realize(NMDevice *device, s_macvlan = nm_connection_get_setting_macvlan(connection); g_return_val_if_fail(s_macvlan, FALSE); - parent_ifindex = parent ? nm_device_get_ifindex(parent) : 0; + if (!parent) { + g_set_error(error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_MISSING_DEPENDENCIES, + "MACVLAN device can not be created without a parent interface"); + return FALSE; + } + parent_ifindex = nm_device_get_ifindex(parent); if (parent_ifindex <= 0) { g_set_error(error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_MISSING_DEPENDENCIES, - "MACVLAN devices can not be created without a parent interface"); - g_return_val_if_fail(!parent, FALSE); + "cannot retrieve ifindex of interface %s (%s)", + nm_device_get_iface(parent), + nm_device_get_type_desc(parent)); return FALSE; } |