summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2015-03-24 12:35:36 -0500
committerDan Williams <dcbw@redhat.com>2015-03-27 15:11:34 -0500
commit25a286e999510a8abeb65c1c47cf28e22df649ec (patch)
tree130a11e54d3f575befb4a1fb6951a7dcb3cb7175
parent32e1d6a9a96fcf32518e8f7b7770041ce933655c (diff)
downloadNetworkManager-25a286e999510a8abeb65c1c47cf28e22df649ec.tar.gz
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.
-rw-r--r--src/platform/nm-fake-platform.c10
-rw-r--r--src/platform/nm-linux-platform.c25
-rw-r--r--src/platform/nm-platform.c22
-rw-r--r--src/platform/nm-platform.h4
4 files changed, 60 insertions, 1 deletions
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index 7194707b29..8288fb9fc4 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 14f791106d..76a2feb52b 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 39bf75a3fb..e4e5dbaa6a 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1032,6 +1032,28 @@ nm_platform_link_get_physical_port_id (int 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 bc7b84c9ff..b90343d79f 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);