From 66f5256b94dc26c782266e1ecc8288811398aa31 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 11 Feb 2014 13:58:00 +0100 Subject: [PATCH] core: add nm_platform_link_refresh() function to refresh the libnl cache for links Signed-off-by: Thomas Haller --- src/platform/nm-linux-platform.c | 16 ++++++++++++++++ src/platform/nm-platform.c | 19 +++++++++++++++++++ src/platform/nm-platform.h | 4 ++++ 3 files changed, 39 insertions(+) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index b47ee7481b..96274353bc 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -1668,6 +1668,20 @@ link_get_flags (NMPlatform *platform, int ifindex) return rtnl_link_get_flags (rtnllink); } +static gboolean +link_refresh (NMPlatform *platform, int ifindex) +{ + auto_nl_object struct rtnl_link *rtnllink = rtnl_link_alloc (); + + if (rtnllink) { + rtnl_link_set_ifindex (rtnllink, ifindex); + return refresh_object (platform, (struct nl_object *) rtnllink, FALSE, NM_PLATFORM_REASON_EXTERNAL); + } else + error ("link_refresh failed with out of memory"); + + return FALSE; +} + static gboolean link_is_up (NMPlatform *platform, int ifindex) { @@ -3026,6 +3040,8 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass) platform_class->link_get_type = link_get_type; platform_class->link_get_type_name = link_get_type_name; + platform_class->link_refresh = link_refresh; + platform_class->link_set_up = link_set_up; platform_class->link_set_down = link_set_down; platform_class->link_set_arp = link_set_arp; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index fcd4b192c5..eb84b6d7fe 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -639,6 +639,25 @@ nm_platform_link_supports_slaves (int ifindex) return (nm_platform_link_get_type (ifindex) & 0x20000); } +/** + * nm_platform_link_refresh: + * @ifindex: Interface index + * + * Reload the cache for ifindex synchronously. + */ +gboolean +nm_platform_link_refresh (int ifindex) +{ + reset_error (); + + g_return_val_if_fail (ifindex > 0, FALSE); + + if (klass->link_refresh) + return klass->link_refresh (platform, ifindex); + + return TRUE; +} + /** * nm_platform_link_is_up: * @ifindex: Interface index diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 465a64ab7c..bdf82b39fd 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -271,6 +271,8 @@ typedef struct { NMLinkType (*link_get_type) (NMPlatform *, int ifindex); const char *(*link_get_type_name) (NMPlatform *, int ifindex); + gboolean (*link_refresh) (NMPlatform *, int ifindex); + gboolean (*link_set_up) (NMPlatform *, int ifindex); gboolean (*link_set_down) (NMPlatform *, int ifindex); gboolean (*link_set_arp) (NMPlatform *, int ifindex); @@ -397,6 +399,8 @@ const char *nm_platform_link_get_type_name (int ifindex); gboolean nm_platform_link_is_software (int ifindex); gboolean nm_platform_link_supports_slaves (int ifindex); +gboolean nm_platform_link_refresh (int ifindex); + gboolean nm_platform_link_set_up (int ifindex); gboolean nm_platform_link_set_down (int ifindex); gboolean nm_platform_link_set_arp (int ifindex);