libnm-base,all: add and use NM_LOOPBACK_IFINDEX define

Co-authored-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Wen Liang 2022-06-12 19:50:09 -04:00 committed by Thomas Haller
parent 75349dc566
commit ef51d0f980
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
4 changed files with 11 additions and 4 deletions

View file

@ -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

View file

@ -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;
}

View file

@ -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).

View file

@ -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)) {