core: add nm_platform_link_refresh() function to refresh the libnl cache for links

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller 2014-02-11 13:58:00 +01:00
parent eac0573d5e
commit 66f5256b94
3 changed files with 39 additions and 0 deletions

View file

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

View file

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

View file

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