platform: add nm_platform_link_get()
Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
@@ -184,6 +184,16 @@ link_added_emit (gpointer user_data)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_nm_platform_link_get (NMPlatform *platform, int ifindex, NMPlatformLink *link)
|
||||
{
|
||||
NMFakePlatformLink *device = link_get (platform, ifindex);
|
||||
|
||||
if (device)
|
||||
*link = device->link;
|
||||
return !!device;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
link_add (NMPlatform *platform, const char *name, NMLinkType type, const void *address, size_t address_len)
|
||||
{
|
||||
@@ -1288,6 +1298,7 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
|
||||
platform_class->sysctl_set = sysctl_set;
|
||||
platform_class->sysctl_get = sysctl_get;
|
||||
|
||||
platform_class->link_get = _nm_platform_link_get;
|
||||
platform_class->link_get_all = link_get_all;
|
||||
platform_class->link_add = link_add;
|
||||
platform_class->link_delete = link_delete;
|
||||
|
@@ -1877,6 +1877,22 @@ link_get_all (NMPlatform *platform)
|
||||
return links;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_nm_platform_link_get (NMPlatform *platform, int ifindex, NMPlatformLink *link)
|
||||
{
|
||||
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
|
||||
auto_nl_object struct rtnl_link *rtnllink;
|
||||
|
||||
rtnllink = rtnl_link_get (priv->link_cache, ifindex);
|
||||
if (rtnllink) {
|
||||
if (link_is_announceable (platform, rtnllink)) {
|
||||
if (init_link (platform, link, rtnllink))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static struct nl_object *
|
||||
build_rtnl_link (int ifindex, const char *name, NMLinkType type)
|
||||
{
|
||||
@@ -3804,6 +3820,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
|
||||
platform_class->sysctl_set = sysctl_set;
|
||||
platform_class->sysctl_get = sysctl_get;
|
||||
|
||||
platform_class->link_get = _nm_platform_link_get;
|
||||
platform_class->link_get_all = link_get_all;
|
||||
platform_class->link_add = link_add;
|
||||
platform_class->link_delete = link_delete;
|
||||
|
@@ -439,6 +439,27 @@ nm_platform_link_get_all (void)
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_platform_link_get:
|
||||
* @ifindex: ifindex of the link
|
||||
* @link: (out): output NMPlatformLink structure.
|
||||
*
|
||||
* If a link with given @ifindex exists, fill the given NMPlatformLink
|
||||
* structure.
|
||||
*
|
||||
* Returns: %TRUE, if such a link exists, %FALSE otherwise.
|
||||
* If the link does not exist, the content of @link is undefined.
|
||||
**/
|
||||
gboolean
|
||||
nm_platform_link_get (int ifindex, NMPlatformLink *link)
|
||||
{
|
||||
g_return_val_if_fail (ifindex > 0, FALSE);
|
||||
g_return_val_if_fail (link, FALSE);
|
||||
|
||||
g_return_val_if_fail (klass->link_get, FALSE);
|
||||
return !!klass->link_get (platform, ifindex, link);
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_platform_link_add:
|
||||
* @name: Interface name
|
||||
|
@@ -346,6 +346,7 @@ typedef struct {
|
||||
gboolean (*sysctl_set) (NMPlatform *, const char *path, const char *value);
|
||||
char * (*sysctl_get) (NMPlatform *, const char *path);
|
||||
|
||||
gboolean (*link_get) (NMPlatform *platform, int ifindex, NMPlatformLink *link);
|
||||
GArray *(*link_get_all) (NMPlatform *);
|
||||
gboolean (*link_add) (NMPlatform *, const char *name, NMLinkType type, const void *address, size_t address_len);
|
||||
gboolean (*link_delete) (NMPlatform *, int ifindex);
|
||||
@@ -477,6 +478,7 @@ char *nm_platform_sysctl_get (const char *path);
|
||||
gint32 nm_platform_sysctl_get_int32 (const char *path, gint32 fallback);
|
||||
gint64 nm_platform_sysctl_get_int_checked (const char *path, guint base, gint64 min, gint64 max, gint64 fallback);
|
||||
|
||||
gboolean nm_platform_link_get (int ifindex, NMPlatformLink *link);
|
||||
GArray *nm_platform_link_get_all (void);
|
||||
gboolean nm_platform_dummy_add (const char *name);
|
||||
gboolean nm_platform_bridge_add (const char *name, const void *address, size_t address_len);
|
||||
|
Reference in New Issue
Block a user