summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-11-29 11:31:50 +0100
committerThomas Haller <thaller@redhat.com>2018-11-29 13:50:10 +0100
commitb445b1f8fe4eff23f59b7e7efaba137e53a6b70e (patch)
tree9c6c4497cab01011863bb21496a7ab5343d5d9ef
parentdc0cdbb57e646d9bcf33cdd2900355f19d8e68bf (diff)
downloadNetworkManager-b445b1f8fe4eff23f59b7e7efaba137e53a6b70e.tar.gz
platform: add nm_platform_link_get_ifi_flags() helper
Add helper nm_platform_link_get_ifi_flags() to access the ifi-flags. This replaces the internal API _link_get_flags() and makes it public. However, the return value also allows to distinguish between errors and valid flags. Also, consider non-visible links. These are links that are in netlink, but not visible in udev. The ifi-flags are inherrently netlink specific, so it seems wrong to pretend that the link doesn't exist.
-rw-r--r--src/platform/nm-platform.c38
-rw-r--r--src/platform/nm-platform.h1
2 files changed, 30 insertions, 9 deletions
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 494e2ddaf6..f0a80cb8b5 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1217,13 +1217,29 @@ nm_platform_link_refresh (NMPlatform *self, int ifindex)
return TRUE;
}
-static guint
-_link_get_flags (NMPlatform *self, int ifindex)
+int
+nm_platform_link_get_ifi_flags (NMPlatform *self,
+ int ifindex,
+ guint requested_flags)
{
const NMPlatformLink *pllink;
- pllink = nm_platform_link_get (self, ifindex);
- return pllink ? pllink->n_ifi_flags : IFF_NOARP;
+ _CHECK_SELF (self, klass, -EINVAL);
+
+ if (ifindex <= 0)
+ return -EINVAL;
+
+ /* include invisible links (only in netlink, not udev). */
+ pllink = NMP_OBJECT_CAST_LINK (nm_platform_link_get_obj (self, ifindex, FALSE));
+ if (!pllink)
+ return -ENODEV;
+
+ /* Errors are signaled as negative values. That means, you cannot request
+ * the most significant bit (2^31) with this API. Assert against that. */
+ nm_assert ((int) requested_flags >= 0);
+ nm_assert (requested_flags < (guint) G_MAXINT);
+
+ return (int) (pllink->n_ifi_flags & requested_flags);
}
/**
@@ -1236,9 +1252,7 @@ _link_get_flags (NMPlatform *self, int ifindex)
gboolean
nm_platform_link_is_up (NMPlatform *self, int ifindex)
{
- _CHECK_SELF (self, klass, FALSE);
-
- return NM_FLAGS_HAS (_link_get_flags (self, ifindex), IFF_UP);
+ return nm_platform_link_get_ifi_flags (self, ifindex, IFF_UP) == IFF_UP;
}
/**
@@ -1269,9 +1283,15 @@ nm_platform_link_is_connected (NMPlatform *self, int ifindex)
gboolean
nm_platform_link_uses_arp (NMPlatform *self, int ifindex)
{
- _CHECK_SELF (self, klass, FALSE);
+ int f;
- return !NM_FLAGS_HAS (_link_get_flags (self, ifindex), IFF_NOARP);
+ f = nm_platform_link_get_ifi_flags (self, ifindex, IFF_NOARP);
+
+ if (f < 0)
+ return FALSE;
+ if (f == IFF_NOARP)
+ return FALSE;
+ return TRUE;
}
/**
diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h
index 2a18d8adf2..dff5102d85 100644
--- a/src/platform/nm-platform.h
+++ b/src/platform/nm-platform.h
@@ -1166,6 +1166,7 @@ int nm_platform_link_get_ifindex (NMPlatform *self, const char *name);
const char *nm_platform_link_get_name (NMPlatform *self, int ifindex);
NMLinkType nm_platform_link_get_type (NMPlatform *self, int ifindex);
gboolean nm_platform_link_is_software (NMPlatform *self, int ifindex);
+int nm_platform_link_get_ifi_flags (NMPlatform *self, int ifindex, guint requested_flags);
gboolean nm_platform_link_is_up (NMPlatform *self, int ifindex);
gboolean nm_platform_link_is_connected (NMPlatform *self, int ifindex);
gboolean nm_platform_link_uses_arp (NMPlatform *self, int ifindex);