From 9eefe27a1c7879e6f94bbb7dec5c9efe722888fa Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 1 May 2019 16:34:27 +0200 Subject: [PATCH] device: don't rely on nm_platform_link_get_ifindex() returning 0 While nm_platform_link_get_ifindex() is documented to return 0 if the device is not found, don't rely on it. Instead, check that a valid(!) ifindex was returned, and only then set the ifindex. Otherwise leave it at zero. There is of course no difference in practice, but we generally treat invalid ifindexes as <= 0, so it's not immediately clear what nm_platform_link_get_ifindex() returns to signal no device. --- src/devices/nm-device.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index d317fccec7..33b85f5f14 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -6508,7 +6508,7 @@ tc_commit (NMDevice *self) ip_ifindex = nm_device_get_ip_ifindex (self); if (!ip_ifindex) - return s_tc == NULL; + return s_tc == NULL; if (s_tc) { nqdiscs = nm_setting_tc_config_get_num_qdiscs (s_tc); @@ -6595,9 +6595,12 @@ tc_commit (NMDevice *self) var = nm_tc_action_get_attribute (action, "dev"); if (var && g_variant_is_of_type (var, G_VARIANT_TYPE_STRING)) { - int ifindex = nm_platform_link_get_ifindex (nm_device_get_platform (self), - g_variant_get_string (var, NULL)); - tfilter->action.mirred.ifindex = ifindex; + int ifindex; + + ifindex = nm_platform_link_get_ifindex (nm_device_get_platform (self), + g_variant_get_string (var, NULL)); + if (ifindex > 0) + tfilter->action.mirred.ifindex = ifindex; } } }