summary refs log tree commit diff
path: root/libnm/nm-device.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2018-06-04 00:07:45 +0200
committerMichael Biebl <biebl@debian.org>2018-06-04 00:07:45 +0200
commit04bc9e1cd3544445d883ad29ea108c1645c8e7b7 (patch)
treed10c354b1b980ca8a7b9e48ec9019e8ed88bde2b /libnm/nm-device.c
parentee9c73a923909e23a649407be77e25235d769e25 (diff)
New upstream version 1.11.4 upstream/1.11.4
Diffstat (limited to 'libnm/nm-device.c')
-rw-r--r--libnm/nm-device.c293
1 files changed, 146 insertions, 147 deletions
diff --git a/libnm/nm-device.c b/libnm/nm-device.c
index ffdfca9c..57f0bedd 100644
--- a/libnm/nm-device.c
+++ b/libnm/nm-device.c
@@ -735,11 +735,9 @@ nm_device_class_init (NMDeviceClass *device_class)
 		                      G_PARAM_STATIC_STRINGS));
 
 	/**
-	 * NMDevice:available-connections:
+	 * NMDevice:available-connections: (type GPtrArray(NMRemoteConnection))
 	 *
 	 * The available connections of the device
-	 *
-	 * Element-type: NMRemoteConnection
 	 **/
 	g_object_class_install_property
 		(object_class, PROP_AVAILABLE_CONNECTIONS,
@@ -1297,6 +1295,136 @@ nm_device_get_available_connections (NMDevice *device)
 	return NM_DEVICE_GET_PRIVATE (device)->available_connections;
 }
 
+static const char *
+get_type_name (NMDevice *device)
+{
+	switch (nm_device_get_device_type (device)) {
+	case NM_DEVICE_TYPE_ETHERNET:
+		return _("Ethernet");
+	case NM_DEVICE_TYPE_WIFI:
+		return _("Wi-Fi");
+	case NM_DEVICE_TYPE_BT:
+		return _("Bluetooth");
+	case NM_DEVICE_TYPE_OLPC_MESH:
+		return _("OLPC Mesh");
+	case NM_DEVICE_TYPE_OVS_INTERFACE:
+		return _("OpenVSwitch Interface");
+	case NM_DEVICE_TYPE_OVS_PORT:
+		return _("OpenVSwitch Port");
+	case NM_DEVICE_TYPE_OVS_BRIDGE:
+		return _("OpenVSwitch Bridge");
+	case NM_DEVICE_TYPE_WIMAX:
+		return _("WiMAX");
+	case NM_DEVICE_TYPE_MODEM:
+		return _("Mobile Broadband");
+	case NM_DEVICE_TYPE_INFINIBAND:
+		return _("InfiniBand");
+	case NM_DEVICE_TYPE_BOND:
+		return _("Bond");
+	case NM_DEVICE_TYPE_TEAM:
+		return _("Team");
+	case NM_DEVICE_TYPE_BRIDGE:
+		return _("Bridge");
+	case NM_DEVICE_TYPE_VLAN:
+		return _("VLAN");
+	case NM_DEVICE_TYPE_ADSL:
+		return _("ADSL");
+	case NM_DEVICE_TYPE_MACVLAN:
+		return _("MACVLAN");
+	case NM_DEVICE_TYPE_VXLAN:
+		return _("VXLAN");
+	case NM_DEVICE_TYPE_IP_TUNNEL:
+		return _("IPTunnel");
+	case NM_DEVICE_TYPE_TUN:
+		return _("Tun");
+	case NM_DEVICE_TYPE_VETH:
+		return _("Veth");
+	case NM_DEVICE_TYPE_MACSEC:
+		return _("MACsec");
+	case NM_DEVICE_TYPE_DUMMY:
+		return _("Dummy");
+	case NM_DEVICE_TYPE_PPP:
+		return _("PPP");
+	case NM_DEVICE_TYPE_GENERIC:
+	case NM_DEVICE_TYPE_UNUSED1:
+	case NM_DEVICE_TYPE_UNUSED2:
+	case NM_DEVICE_TYPE_UNKNOWN:
+		break;
+	}
+	return _("Unknown");
+}
+
+static char *
+get_device_type_name_with_iface (NMDevice *device)
+{
+	const char *type_name = get_type_name (device);
+
+	switch (nm_device_get_device_type (device)) {
+	case NM_DEVICE_TYPE_BOND:
+	case NM_DEVICE_TYPE_TEAM:
+	case NM_DEVICE_TYPE_BRIDGE:
+	case NM_DEVICE_TYPE_VLAN:
+		return g_strdup_printf ("%s (%s)", type_name, nm_device_get_iface (device));
+	default:
+		return g_strdup (type_name);
+	}
+}
+
+static char *
+get_device_generic_type_name_with_iface (NMDevice *device)
+{
+	switch (nm_device_get_device_type (device)) {
+	case NM_DEVICE_TYPE_ETHERNET:
+	case NM_DEVICE_TYPE_INFINIBAND:
+		return g_strdup (_("Wired"));
+	default:
+		return get_device_type_name_with_iface (device);
+	}
+}
+
+static const char *
+get_bus_name (NMDevice *device)
+{
+	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
+	struct udev_device *udevice;
+	const char *ifname, *bus;
+
+	if (priv->bus_name)
+		goto out;
+
+	if (!priv->udev)
+		return NULL;
+
+	ifname = nm_device_get_iface (device);
+	if (!ifname)
+		return NULL;
+
+	udevice = udev_device_new_from_subsystem_sysname (priv->udev, "net", ifname);
+	if (!udevice) {
+		udevice = udev_device_new_from_subsystem_sysname (priv->udev, "tty", ifname);
+		if (!udevice)
+			return NULL;
+	}
+	bus = udev_device_get_property_value (udevice, "ID_BUS");
+	if (!g_strcmp0 (bus, "pci"))
+		priv->bus_name = g_strdup (_("PCI"));
+	else if (!g_strcmp0 (bus, "usb"))
+		priv->bus_name = g_strdup (_("USB"));
+	else {
+		/* Use "" instead of NULL so we can tell later that we've
+		 * already tried.
+		 */
+		priv->bus_name = g_strdup ("");
+	}
+	udev_device_unref (udevice);
+
+out:
+	if (*priv->bus_name)
+		return priv->bus_name;
+	else
+		return NULL;
+}
+
 void
 _nm_device_set_udev (NMDevice *device, struct udev *udev)
 {
@@ -1350,15 +1478,14 @@ _get_udev_property (NMDevice *device,
 	}
 	udev_device_unref (udev_device);
 
-	/* Prefer the encoded value which comes directly from the device
-	 * over the hwdata database value.
-	 */
-	if (enc_value) {
-		g_free (db_value);
-		return enc_value;
+	/* Prefer the hwdata database value over what comes directly
+	 * from the device. */
+	if (db_value) {
+		g_free (enc_value);
+		return db_value;
 	}
 
-	return db_value;
+	return enc_value;
 }
 
 static char *
@@ -1443,7 +1570,7 @@ ensure_description (NMDevice *device)
 	GParamSpec *name_prop;
 	gs_free char *short_product = NULL;
 
-	priv->short_vendor = nm_str_realloc (nm_utils_fixup_desc_string (nm_device_get_vendor (device)));
+	priv->short_vendor = nm_str_realloc (nm_utils_fixup_vendor_string (nm_device_get_vendor (device)));
 
 	/* Grab device's preferred name, if any */
 	name_prop = g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (device)), "name");
@@ -1454,12 +1581,15 @@ ensure_description (NMDevice *device)
 		g_clear_pointer (&priv->description, g_free);
 	}
 
-	if (   !priv->short_vendor
-	    || !(short_product = nm_utils_fixup_desc_string (nm_device_get_product (device)))) {
+	if (!priv->short_vendor) {
 		priv->description = g_strdup (nm_device_get_iface (device) ?: "");
 		return;
 	}
 
+	short_product = nm_utils_fixup_product_string (nm_device_get_product (device));
+	if (short_product == NULL)
+		short_product = g_strdup (get_type_name (device));
+
 	/* Another quick hack; if all of the fixed up vendor string
 	 * is found in product, ignore the vendor.
 	 */
@@ -1513,136 +1643,6 @@ nm_device_get_description (NMDevice *device)
 	return priv->description;
 }
 
-static const char *
-get_type_name (NMDevice *device)
-{
-	switch (nm_device_get_device_type (device)) {
-	case NM_DEVICE_TYPE_ETHERNET:
-		return _("Ethernet");
-	case NM_DEVICE_TYPE_WIFI:
-		return _("Wi-Fi");
-	case NM_DEVICE_TYPE_BT:
-		return _("Bluetooth");
-	case NM_DEVICE_TYPE_OLPC_MESH:
-		return _("OLPC Mesh");
-	case NM_DEVICE_TYPE_OVS_INTERFACE:
-		return _("OpenVSwitch Interface");
-	case NM_DEVICE_TYPE_OVS_PORT:
-		return _("OpenVSwitch Port");
-	case NM_DEVICE_TYPE_OVS_BRIDGE:
-		return _("OpenVSwitch Bridge");
-	case NM_DEVICE_TYPE_WIMAX:
-		return _("WiMAX");
-	case NM_DEVICE_TYPE_MODEM:
-		return _("Mobile Broadband");
-	case NM_DEVICE_TYPE_INFINIBAND:
-		return _("InfiniBand");
-	case NM_DEVICE_TYPE_BOND:
-		return _("Bond");
-	case NM_DEVICE_TYPE_TEAM:
-		return _("Team");
-	case NM_DEVICE_TYPE_BRIDGE:
-		return _("Bridge");
-	case NM_DEVICE_TYPE_VLAN:
-		return _("VLAN");
-	case NM_DEVICE_TYPE_ADSL:
-		return _("ADSL");
-	case NM_DEVICE_TYPE_MACVLAN:
-		return _("MACVLAN");
-	case NM_DEVICE_TYPE_VXLAN:
-		return _("VXLAN");
-	case NM_DEVICE_TYPE_IP_TUNNEL:
-		return _("IPTunnel");
-	case NM_DEVICE_TYPE_TUN:
-		return _("Tun");
-	case NM_DEVICE_TYPE_VETH:
-		return _("Veth");
-	case NM_DEVICE_TYPE_MACSEC:
-		return _("MACsec");
-	case NM_DEVICE_TYPE_DUMMY:
-		return _("Dummy");
-	case NM_DEVICE_TYPE_PPP:
-		return _("PPP");
-	case NM_DEVICE_TYPE_GENERIC:
-	case NM_DEVICE_TYPE_UNUSED1:
-	case NM_DEVICE_TYPE_UNUSED2:
-	case NM_DEVICE_TYPE_UNKNOWN:
-		break;
-	}
-	return _("Unknown");
-}
-
-static char *
-get_device_type_name_with_iface (NMDevice *device)
-{
-	const char *type_name = get_type_name (device);
-
-	switch (nm_device_get_device_type (device)) {
-	case NM_DEVICE_TYPE_BOND:
-	case NM_DEVICE_TYPE_TEAM:
-	case NM_DEVICE_TYPE_BRIDGE:
-	case NM_DEVICE_TYPE_VLAN:
-		return g_strdup_printf ("%s (%s)", type_name, nm_device_get_iface (device));
-	default:
-		return g_strdup (type_name);
-	}
-}
-
-static char *
-get_device_generic_type_name_with_iface (NMDevice *device)
-{
-	switch (nm_device_get_device_type (device)) {
-	case NM_DEVICE_TYPE_ETHERNET:
-	case NM_DEVICE_TYPE_INFINIBAND:
-		return g_strdup (_("Wired"));
-	default:
-		return get_device_type_name_with_iface (device);
-	}
-}
-
-static const char *
-get_bus_name (NMDevice *device)
-{
-	NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (device);
-	struct udev_device *udevice;
-	const char *ifname, *bus;
-
-	if (priv->bus_name)
-		goto out;
-
-	if (!priv->udev)
-		return NULL;
-
-	ifname = nm_device_get_iface (device);
-	if (!ifname)
-		return NULL;
-
-	udevice = udev_device_new_from_subsystem_sysname (priv->udev, "net", ifname);
-	if (!udevice) {
-		udevice = udev_device_new_from_subsystem_sysname (priv->udev, "tty", ifname);
-		if (!udevice)
-			return NULL;
-	}
-	bus = udev_device_get_property_value (udevice, "ID_BUS");
-	if (!g_strcmp0 (bus, "pci"))
-		priv->bus_name = g_strdup (_("PCI"));
-	else if (!g_strcmp0 (bus, "usb"))
-		priv->bus_name = g_strdup (_("USB"));
-	else {
-		/* Use "" instead of NULL so we can tell later that we've
-		 * already tried.
-		 */
-		priv->bus_name = g_strdup ("");
-	}
-	udev_device_unref (udevice);
-
-out:
-	if (*priv->bus_name)
-		return priv->bus_name;
-	else
-		return NULL;
-}
-
 static gboolean
 find_duplicates (char     **names,
                  gboolean  *duplicates,
@@ -1716,7 +1716,7 @@ nm_device_disambiguate_names (NMDevice **devices,
 
 			g_free (names[i]);
 			name = get_device_type_name_with_iface (devices[i]);
-			/* Translators: the first %s is a bus name (eg, "USB") or
+			/* TRANSLATORS: the first %s is a bus name (eg, "USB") or
 			 * product name, the second is a device type (eg,
 			 * "Ethernet"). You can change this to something like
 			 * "%2$s (%1$s)" if there's no grammatical way to combine
@@ -1819,7 +1819,7 @@ nm_device_get_physical_port_id (NMDevice *device)
  *
  * Gets the  MTU of the #NMDevice.
  *
- * Returns: the MTU of the device.
+ * Returns: the MTU of the device in bytes.
  **/
 guint32
 nm_device_get_mtu (NMDevice *device)
@@ -1940,7 +1940,6 @@ nm_device_reapply (NMDevice *device,
 	if (!dict)
 		dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
 
-
 	ret = nmdbus_device_call_reapply_sync (NM_DEVICE_GET_PRIVATE (device)->proxy,
 	                                       dict, version_id, flags, cancellable, error);
 	if (error && *error)
@@ -2578,7 +2577,7 @@ nm_lldp_neighbor_new (void)
 
 	neigh = g_new0 (NMLldpNeighbor, 1);
 	neigh->refcount = 1;
-	neigh->attrs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
+	neigh->attrs = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free,
 	                                      (GDestroyNotify) g_variant_unref);
 
 	return neigh;