diff options
author | Thomas Haller <thaller@redhat.com> | 2018-01-11 11:15:35 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-02-21 20:28:46 +0100 |
commit | 79980536b98b6319f0c3bd9598aada51768c1a3e (patch) | |
tree | a24f56822c87f537496d1adc6a2f190bdeec4679 | |
parent | 352d063009cdf4bfbff0064c66c63fc48e876340 (diff) | |
download | NetworkManager-79980536b98b6319f0c3bd9598aada51768c1a3e.tar.gz |
platform: add nm_platform_process_events_ensure_link() function
-rw-r--r-- | src/platform/nm-platform.c | 39 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 4 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 2c12359cfc..6f483fa654 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -353,6 +353,45 @@ nm_platform_process_events (NMPlatform *self) klass->process_events (self); } +const NMPlatformLink * +nm_platform_process_events_ensure_link (NMPlatform *self, + int ifindex, + const char *ifname) +{ + const NMPObject *obj; + gboolean refreshed = FALSE; + + g_return_val_if_fail (NM_IS_PLATFORM (self), NULL); + + if (ifindex <= 0 && !ifname) + return NULL; + + /* we look into the cache, whether a link for given ifindex/ifname + * exits. If not, we poll the netlink socket, maybe the event + * with the link is waiting. + * + * Then we try again to find the object. + * + * If the link is already cached the first time, we avoid polling + * the netlink socket. */ +again: + obj = nmp_cache_lookup_link_full (nm_platform_get_cache (self), + ifindex, + ifname, + FALSE, /* also invisible. We don't care here whether udev is ready */ + NM_LINK_TYPE_NONE, + NULL, NULL); + if (obj) + return NMP_OBJECT_CAST_LINK (obj); + if (!refreshed) { + refreshed = TRUE; + nm_platform_process_events (self); + goto again; + } + + return NULL; +} + /*****************************************************************************/ /** diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index a545485183..53b2975bf5 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -1106,6 +1106,10 @@ const char *nm_platform_link_get_type_name (NMPlatform *self, int ifindex); gboolean nm_platform_link_refresh (NMPlatform *self, int ifindex); void nm_platform_process_events (NMPlatform *self); +const NMPlatformLink *nm_platform_process_events_ensure_link (NMPlatform *self, + int ifindex, + const char *ifname); + gboolean nm_platform_link_set_up (NMPlatform *self, int ifindex, gboolean *out_no_firmware); gboolean nm_platform_link_set_down (NMPlatform *self, int ifindex); gboolean nm_platform_link_set_arp (NMPlatform *self, int ifindex); |