mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-08 14:48:10 +02:00
platform: add nm_platform_link_get_by_address()
This commit is contained in:
parent
29ccb8851c
commit
fa74ed7ca1
4 changed files with 79 additions and 0 deletions
|
|
@ -167,6 +167,28 @@ _nm_platform_link_get (NMPlatform *platform, int ifindex, NMPlatformLink *l)
|
||||||
return !!device;
|
return !!device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_nm_platform_link_get_by_address (NMPlatform *platform,
|
||||||
|
gconstpointer address,
|
||||||
|
size_t length,
|
||||||
|
NMPlatformLink *l)
|
||||||
|
{
|
||||||
|
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
for (i = 0; i < priv->links->len; i++) {
|
||||||
|
NMFakePlatformLink *device = &g_array_index (priv->links, NMFakePlatformLink, i);
|
||||||
|
|
||||||
|
if ( device->address
|
||||||
|
&& g_bytes_get_size (device->address) == length
|
||||||
|
&& memcmp (g_bytes_get_data (device->address, NULL), address, length) == 0) {
|
||||||
|
*l = device->link;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
link_add (NMPlatform *platform,
|
link_add (NMPlatform *platform,
|
||||||
const char *name,
|
const char *name,
|
||||||
|
|
@ -1370,6 +1392,7 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
|
||||||
platform_class->sysctl_get = sysctl_get;
|
platform_class->sysctl_get = sysctl_get;
|
||||||
|
|
||||||
platform_class->link_get = _nm_platform_link_get;
|
platform_class->link_get = _nm_platform_link_get;
|
||||||
|
platform_class->link_get_by_address = _nm_platform_link_get_by_address;
|
||||||
platform_class->link_get_all = link_get_all;
|
platform_class->link_get_all = link_get_all;
|
||||||
platform_class->link_add = link_add;
|
platform_class->link_add = link_add;
|
||||||
platform_class->link_delete = link_delete;
|
platform_class->link_delete = link_delete;
|
||||||
|
|
|
||||||
|
|
@ -2318,6 +2318,30 @@ _nm_platform_link_get (NMPlatform *platform, int ifindex, NMPlatformLink *l)
|
||||||
return (rtnllink && init_link (platform, l ? l : &tmp, rtnllink));
|
return (rtnllink && init_link (platform, l ? l : &tmp, rtnllink));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_nm_platform_link_get_by_address (NMPlatform *platform,
|
||||||
|
gconstpointer address,
|
||||||
|
size_t length,
|
||||||
|
NMPlatformLink *l)
|
||||||
|
{
|
||||||
|
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
|
||||||
|
struct nl_object *object;
|
||||||
|
|
||||||
|
for (object = nl_cache_get_first (priv->link_cache); object; object = nl_cache_get_next (object)) {
|
||||||
|
struct rtnl_link *rtnl_link = (struct rtnl_link *) object;
|
||||||
|
struct nl_addr *nladdr;
|
||||||
|
gconstpointer hwaddr;
|
||||||
|
|
||||||
|
nladdr = rtnl_link_get_addr (rtnl_link);
|
||||||
|
if (nladdr && (nl_addr_get_len (nladdr) == length)) {
|
||||||
|
hwaddr = nl_addr_get_binary_addr (nladdr);
|
||||||
|
if (hwaddr && memcmp (hwaddr, address, length) == 0)
|
||||||
|
return init_link (platform, l, rtnl_link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static struct nl_object *
|
static struct nl_object *
|
||||||
build_rtnl_link (int ifindex, const char *name, NMLinkType type)
|
build_rtnl_link (int ifindex, const char *name, NMLinkType type)
|
||||||
{
|
{
|
||||||
|
|
@ -4705,6 +4729,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
|
||||||
platform_class->sysctl_get = sysctl_get;
|
platform_class->sysctl_get = sysctl_get;
|
||||||
|
|
||||||
platform_class->link_get = _nm_platform_link_get;
|
platform_class->link_get = _nm_platform_link_get;
|
||||||
|
platform_class->link_get_by_address = _nm_platform_link_get_by_address;
|
||||||
platform_class->link_get_all = link_get_all;
|
platform_class->link_get_all = link_get_all;
|
||||||
platform_class->link_add = link_add;
|
platform_class->link_add = link_add;
|
||||||
platform_class->link_delete = link_delete;
|
platform_class->link_delete = link_delete;
|
||||||
|
|
|
||||||
|
|
@ -541,6 +541,35 @@ nm_platform_link_get (NMPlatform *self, int ifindex, NMPlatformLink *link)
|
||||||
return !!klass->link_get (self, ifindex, link);
|
return !!klass->link_get (self, ifindex, link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nm_platform_link_get_by_address:
|
||||||
|
* @self: platform instance
|
||||||
|
* @address: a pointer to the binary hardware address
|
||||||
|
* @length: the size of @address in bytes
|
||||||
|
* @link: (out): output NMPlatformLink structure.
|
||||||
|
*
|
||||||
|
* If a link with given @address 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_by_address (NMPlatform *self,
|
||||||
|
gconstpointer address,
|
||||||
|
size_t length,
|
||||||
|
NMPlatformLink *link)
|
||||||
|
{
|
||||||
|
_CHECK_SELF (self, klass, FALSE);
|
||||||
|
|
||||||
|
g_return_val_if_fail (address != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (length > 0, FALSE);
|
||||||
|
g_return_val_if_fail (link, FALSE);
|
||||||
|
|
||||||
|
g_return_val_if_fail (klass->link_get_by_address, FALSE);
|
||||||
|
return !!klass->link_get_by_address (self, address, length, link);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_platform_link_add:
|
* nm_platform_link_add:
|
||||||
* @self: platform instance
|
* @self: platform instance
|
||||||
|
|
|
||||||
|
|
@ -374,6 +374,7 @@ typedef struct {
|
||||||
char * (*sysctl_get) (NMPlatform *, const char *path);
|
char * (*sysctl_get) (NMPlatform *, const char *path);
|
||||||
|
|
||||||
gboolean (*link_get) (NMPlatform *platform, int ifindex, NMPlatformLink *link);
|
gboolean (*link_get) (NMPlatform *platform, int ifindex, NMPlatformLink *link);
|
||||||
|
gboolean (*link_get_by_address) (NMPlatform *platform, gconstpointer address, size_t length, NMPlatformLink *link);
|
||||||
GArray *(*link_get_all) (NMPlatform *);
|
GArray *(*link_get_all) (NMPlatform *);
|
||||||
gboolean (*link_add) (NMPlatform *,
|
gboolean (*link_add) (NMPlatform *,
|
||||||
const char *name,
|
const char *name,
|
||||||
|
|
@ -531,6 +532,7 @@ gboolean nm_platform_sysctl_set_ip6_hop_limit_safe (NMPlatform *self, const char
|
||||||
|
|
||||||
gboolean nm_platform_link_get (NMPlatform *self, int ifindex, NMPlatformLink *link);
|
gboolean nm_platform_link_get (NMPlatform *self, int ifindex, NMPlatformLink *link);
|
||||||
GArray *nm_platform_link_get_all (NMPlatform *self);
|
GArray *nm_platform_link_get_all (NMPlatform *self);
|
||||||
|
gboolean nm_platform_link_get_by_address (NMPlatform *self, gconstpointer address, size_t length, NMPlatformLink *link);
|
||||||
gboolean nm_platform_dummy_add (NMPlatform *self, const char *name, NMPlatformLink *out_link);
|
gboolean nm_platform_dummy_add (NMPlatform *self, const char *name, NMPlatformLink *out_link);
|
||||||
gboolean nm_platform_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, NMPlatformLink *out_link);
|
gboolean nm_platform_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, NMPlatformLink *out_link);
|
||||||
gboolean nm_platform_bond_add (NMPlatform *self, const char *name, NMPlatformLink *out_link);
|
gboolean nm_platform_bond_add (NMPlatform *self, const char *name, NMPlatformLink *out_link);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue