diff options
| author | Michael Biebl <biebl@debian.org> | 2018-04-23 18:00:21 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2018-04-23 18:00:21 +0200 |
| commit | f60117b41d5433be1b4a96d82cd11d0c3dce9b63 (patch) | |
| tree | 2dd55c4ab0fdcbe9cddb26adb4a554b1a45c73c8 /libnm/nm-device.c | |
| parent | 7e9ff09fcb2366b383b7ebbec80d2f6fff117290 (diff) | |
New upstream version 1.11.3 upstream/1.11.3
Diffstat (limited to 'libnm/nm-device.c')
| -rw-r--r-- | libnm/nm-device.c | 290 |
1 files changed, 145 insertions, 145 deletions
diff --git a/libnm/nm-device.c b/libnm/nm-device.c index ffdfca9c..9bb8f391 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 @@ -2578,7 +2578,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; |