platform: add nm_platform_link_get_dev_id()
Some devices (s390 OSA and ipvlan) use the same link layer address for different interfaces, and dev_id is what differentiates them.
This commit is contained in:
@@ -488,6 +488,15 @@ link_get_physical_port_id (NMPlatform *platform, int ifindex)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static guint
|
||||||
|
link_get_dev_id (NMPlatform *platform, int ifindex)
|
||||||
|
{
|
||||||
|
/* We call link_get just to cause an error to be set if @ifindex is bad. */
|
||||||
|
link_get (platform, ifindex);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
link_get_wake_on_lan (NMPlatform *platform, int ifindex)
|
link_get_wake_on_lan (NMPlatform *platform, int ifindex)
|
||||||
{
|
{
|
||||||
@@ -1406,6 +1415,7 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
|
|||||||
platform_class->link_set_mtu = link_set_mtu;
|
platform_class->link_set_mtu = link_set_mtu;
|
||||||
|
|
||||||
platform_class->link_get_physical_port_id = link_get_physical_port_id;
|
platform_class->link_get_physical_port_id = link_get_physical_port_id;
|
||||||
|
platform_class->link_get_dev_id = link_get_dev_id;
|
||||||
platform_class->link_get_wake_on_lan = link_get_wake_on_lan;
|
platform_class->link_get_wake_on_lan = link_get_wake_on_lan;
|
||||||
|
|
||||||
platform_class->link_supports_carrier_detect = link_supports_carrier_detect;
|
platform_class->link_supports_carrier_detect = link_supports_carrier_detect;
|
||||||
|
@@ -2744,6 +2744,30 @@ link_get_physical_port_id (NMPlatform *platform, int ifindex)
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static guint
|
||||||
|
link_get_dev_id (NMPlatform *platform, int ifindex)
|
||||||
|
{
|
||||||
|
const char *ifname;
|
||||||
|
gs_free char *path = NULL, *id = NULL;
|
||||||
|
gint64 int_val;
|
||||||
|
|
||||||
|
ifname = nm_platform_link_get_name (ifindex);
|
||||||
|
if (!ifname)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ifname = ASSERT_VALID_PATH_COMPONENT (ifname);
|
||||||
|
|
||||||
|
path = g_strdup_printf ("/sys/class/net/%s/dev_id", ifname);
|
||||||
|
id = sysctl_get (platform, path);
|
||||||
|
if (!id || !*id)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Value is reported as hex */
|
||||||
|
int_val = _nm_utils_ascii_str_to_int64 (id, 16, 0, G_MAXUINT16, 0);
|
||||||
|
|
||||||
|
return errno ? 0 : (int) int_val;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint32 vlan_flags)
|
vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint32 vlan_flags)
|
||||||
{
|
{
|
||||||
@@ -4608,6 +4632,7 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
|
|||||||
platform_class->link_set_mtu = link_set_mtu;
|
platform_class->link_set_mtu = link_set_mtu;
|
||||||
|
|
||||||
platform_class->link_get_physical_port_id = link_get_physical_port_id;
|
platform_class->link_get_physical_port_id = link_get_physical_port_id;
|
||||||
|
platform_class->link_get_dev_id = link_get_dev_id;
|
||||||
platform_class->link_get_wake_on_lan = link_get_wake_on_lan;
|
platform_class->link_get_wake_on_lan = link_get_wake_on_lan;
|
||||||
|
|
||||||
platform_class->link_supports_carrier_detect = link_supports_carrier_detect;
|
platform_class->link_supports_carrier_detect = link_supports_carrier_detect;
|
||||||
|
@@ -1031,6 +1031,28 @@ nm_platform_link_get_physical_port_id (int ifindex)
|
|||||||
return klass->link_get_physical_port_id (platform, ifindex);
|
return klass->link_get_physical_port_id (platform, ifindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nm_platform_link_get_dev_id:
|
||||||
|
* @ifindex: Interface index
|
||||||
|
*
|
||||||
|
* In contrast to the physical device ID (which indicates which parent a
|
||||||
|
* child has) the device ID differentiates sibling devices that may share
|
||||||
|
* the same MAC address.
|
||||||
|
*
|
||||||
|
* Returns: device ID for the interface, or 0 on error or if the
|
||||||
|
* interface has no device ID.
|
||||||
|
*/
|
||||||
|
guint
|
||||||
|
nm_platform_link_get_dev_id (int ifindex)
|
||||||
|
{
|
||||||
|
reset_error ();
|
||||||
|
|
||||||
|
g_return_val_if_fail (ifindex >= 0, 0);
|
||||||
|
g_return_val_if_fail (klass->link_get_dev_id, 0);
|
||||||
|
|
||||||
|
return klass->link_get_dev_id (platform, ifindex);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* nm_platform_link_get_wake_onlan:
|
* nm_platform_link_get_wake_onlan:
|
||||||
* @ifindex: Interface index
|
* @ifindex: Interface index
|
||||||
|
@@ -374,6 +374,7 @@ typedef struct {
|
|||||||
gboolean (*link_set_mtu) (NMPlatform *, int ifindex, guint32 mtu);
|
gboolean (*link_set_mtu) (NMPlatform *, int ifindex, guint32 mtu);
|
||||||
|
|
||||||
char * (*link_get_physical_port_id) (NMPlatform *, int ifindex);
|
char * (*link_get_physical_port_id) (NMPlatform *, int ifindex);
|
||||||
|
guint (*link_get_dev_id) (NMPlatform *, int ifindex);
|
||||||
gboolean (*link_get_wake_on_lan) (NMPlatform *, int ifindex);
|
gboolean (*link_get_wake_on_lan) (NMPlatform *, int ifindex);
|
||||||
|
|
||||||
gboolean (*link_supports_carrier_detect) (NMPlatform *, int ifindex);
|
gboolean (*link_supports_carrier_detect) (NMPlatform *, int ifindex);
|
||||||
@@ -524,6 +525,7 @@ guint32 nm_platform_link_get_mtu (int ifindex);
|
|||||||
gboolean nm_platform_link_set_mtu (int ifindex, guint32 mtu);
|
gboolean nm_platform_link_set_mtu (int ifindex, guint32 mtu);
|
||||||
|
|
||||||
char *nm_platform_link_get_physical_port_id (int ifindex);
|
char *nm_platform_link_get_physical_port_id (int ifindex);
|
||||||
|
guint nm_platform_link_get_dev_id (int ifindex);
|
||||||
gboolean nm_platform_link_get_wake_on_lan (int ifindex);
|
gboolean nm_platform_link_get_wake_on_lan (int ifindex);
|
||||||
|
|
||||||
gboolean nm_platform_link_supports_carrier_detect (int ifindex);
|
gboolean nm_platform_link_supports_carrier_detect (int ifindex);
|
||||||
|
Reference in New Issue
Block a user