diff options
author | Wen Liang <liangwen12year@gmail.com> | 2022-06-12 19:50:09 -0400 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2022-09-08 19:42:02 +0200 |
commit | ef51d0f980bdadd8274aafc609f92a9730f0c55e (patch) | |
tree | 196af06a32ea5371ed7b8a6a4febc1cb58e5e205 | |
parent | 75349dc56669b06009d3d1cd13e6f21fd248a5b8 (diff) | |
download | NetworkManager-ef51d0f980bdadd8274aafc609f92a9730f0c55e.tar.gz |
libnm-base,all: add and use NM_LOOPBACK_IFINDEX define
Co-authored-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | src/core/devices/nm-device.c | 3 | ||||
-rw-r--r-- | src/core/nm-manager.c | 2 | ||||
-rw-r--r-- | src/libnm-base/nm-base.h | 6 | ||||
-rw-r--r-- | src/libnm-platform/nm-platform.c | 4 |
4 files changed, 11 insertions, 4 deletions
diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index 9f4c5bb7e8..132825af41 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -2737,7 +2737,8 @@ _ethtool_state_set(NMDevice *self) static gboolean is_loopback(NMDevice *self) { - return NM_IS_DEVICE_GENERIC(self) && NM_DEVICE_GET_PRIVATE(self)->ifindex == 1; + return NM_IS_DEVICE_GENERIC(self) + && NM_DEVICE_GET_PRIVATE(self)->ifindex == NM_LOOPBACK_IFINDEX; } gboolean diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c index e198385c87..df890cdb6f 100644 --- a/src/core/nm-manager.c +++ b/src/core/nm-manager.c @@ -7087,7 +7087,7 @@ nm_manager_write_device_state(NMManager *self, NMDevice *device, int *out_ifinde ifindex = nm_device_get_ip_ifindex(device); if (ifindex <= 0) return FALSE; - if (ifindex == 1) { + if (ifindex == NM_LOOPBACK_IFINDEX) { /* ignore loopback */ return FALSE; } diff --git a/src/libnm-base/nm-base.h b/src/libnm-base/nm-base.h index ff062a18b8..a8d6b2c892 100644 --- a/src/libnm-base/nm-base.h +++ b/src/libnm-base/nm-base.h @@ -393,6 +393,12 @@ typedef struct { #define NM_BOND_PORT_QUEUE_ID_DEF 0 +/****************************************************************************/ + +/* ifindex generation is per-net namespace, and loopback is always the first + * device in the network namespace, thus any loopback device should get ifindex 1. */ +#define NM_LOOPBACK_IFINDEX 1 + /*****************************************************************************/ /* NM_CRYPTO_ERROR is part of public API in libnm (implemented in libnm-core). diff --git a/src/libnm-platform/nm-platform.c b/src/libnm-platform/nm-platform.c index b4ecc34e4e..e2c2df866b 100644 --- a/src/libnm-platform/nm-platform.c +++ b/src/libnm-platform/nm-platform.c @@ -948,9 +948,9 @@ _link_get_all_presort(gconstpointer p_a, gconstpointer p_b, gpointer sort_by_nam const NMPlatformLink *b = NMP_OBJECT_CAST_LINK(*((const NMPObject **) p_b)); /* Loopback always first */ - if (a->ifindex == 1) + if (a->ifindex == NM_LOOPBACK_IFINDEX) return -1; - if (b->ifindex == 1) + if (b->ifindex == NM_LOOPBACK_IFINDEX) return 1; if (GPOINTER_TO_INT(sort_by_name)) { |