diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 7194707b2..8288fb9fc 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -488,6 +488,15 @@ link_get_physical_port_id (NMPlatform *platform, int ifindex) 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 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_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_supports_carrier_detect = link_supports_carrier_detect; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 14f791106..76a2feb52 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -2744,6 +2744,30 @@ link_get_physical_port_id (NMPlatform *platform, int ifindex) 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 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_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_supports_carrier_detect = link_supports_carrier_detect; diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 39bf75a3f..e4e5dbaa6 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -1031,6 +1031,28 @@ nm_platform_link_get_physical_port_id (int 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: * @ifindex: Interface index diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index bc7b84c9f..b90343d79 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -373,7 +373,8 @@ typedef struct { guint32 (*link_get_mtu) (NMPlatform *, int ifindex); 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_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); 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_supports_carrier_detect (int ifindex);