diff options
Diffstat (limited to 'libnm-glib/nm-device-ethernet.c')
-rw-r--r-- | libnm-glib/nm-device-ethernet.c | 92 |
1 files changed, 78 insertions, 14 deletions
diff --git a/libnm-glib/nm-device-ethernet.c b/libnm-glib/nm-device-ethernet.c index 44b274276..932c6bda3 100644 --- a/libnm-glib/nm-device-ethernet.c +++ b/libnm-glib/nm-device-ethernet.c @@ -18,9 +18,17 @@ * Boston, MA 02110-1301 USA. * * Copyright (C) 2007 - 2008 Novell, Inc. - * Copyright (C) 2007 - 2010 Red Hat, Inc. + * Copyright (C) 2007 - 2011 Red Hat, Inc. */ +#include <config.h> +#include <string.h> +#include <netinet/ether.h> + +#include <nm-setting-connection.h> +#include <nm-setting-wired.h> +#include <nm-setting-pppoe.h> + #include "nm-device-ethernet.h" #include "nm-device-private.h" #include "nm-object-private.h" @@ -65,7 +73,7 @@ enum { * * Creates a new #NMDeviceEthernet. * - * Returns: a new device + * Returns: (transfer full): a new device **/ GObject * nm_device_ethernet_new (DBusGConnection *connection, const char *path) @@ -99,7 +107,8 @@ nm_device_ethernet_get_hw_address (NMDeviceEthernet *device) if (!priv->hw_address) { priv->hw_address = _nm_object_get_string_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE_WIRED, - DBUS_PROP_HW_ADDRESS); + DBUS_PROP_HW_ADDRESS, + NULL); } return priv->hw_address; @@ -125,7 +134,8 @@ nm_device_ethernet_get_permanent_hw_address (NMDeviceEthernet *device) if (!priv->perm_hw_address) { priv->perm_hw_address = _nm_object_get_string_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE_WIRED, - DBUS_PROP_PERM_HW_ADDRESS); + DBUS_PROP_PERM_HW_ADDRESS, + NULL); } return priv->perm_hw_address; @@ -150,7 +160,8 @@ nm_device_ethernet_get_speed (NMDeviceEthernet *device) if (!priv->speed) { priv->speed = _nm_object_get_uint_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE_WIRED, - DBUS_PROP_SPEED); + DBUS_PROP_SPEED, + NULL); } return priv->speed; @@ -175,13 +186,67 @@ nm_device_ethernet_get_carrier (NMDeviceEthernet *device) if (!priv->carrier_valid) { priv->carrier = _nm_object_get_boolean_property (NM_OBJECT (device), NM_DBUS_INTERFACE_DEVICE_WIRED, - DBUS_PROP_CARRIER); + DBUS_PROP_CARRIER, + NULL); priv->carrier_valid = TRUE; } return priv->carrier; } +static GSList * +filter_connections (NMDevice *device, const GSList *connections) +{ + GSList *filtered = NULL; + const GSList *iter; + + for (iter = connections; iter; iter = g_slist_next (iter)) { + NMConnection *candidate = NM_CONNECTION (iter->data); + NMSettingConnection *s_con; + NMSettingWired *s_wired; + const char *ctype; + gboolean is_pppoe = FALSE; + + s_con = (NMSettingConnection *) nm_connection_get_setting (candidate, NM_TYPE_SETTING_CONNECTION); + g_assert (s_con); + + ctype = nm_setting_connection_get_connection_type (s_con); + if (!strcmp (ctype, NM_SETTING_PPPOE_SETTING_NAME)) + is_pppoe = TRUE; + else if (strcmp (ctype, NM_SETTING_WIRED_SETTING_NAME) != 0) + continue; + + s_wired = (NMSettingWired *) nm_connection_get_setting (candidate, NM_TYPE_SETTING_WIRED); + /* Wired setting optional for PPPoE */ + if (!is_pppoe && !s_wired) + continue; + + if (s_wired) { + const GByteArray *mac; + const char *perm_str; + struct ether_addr *perm_mac; + + /* FIXME: filter using s390 subchannels when they are exported over the bus */ + + /* Check MAC address */ + perm_str = nm_device_ethernet_get_permanent_hw_address (NM_DEVICE_ETHERNET (device)); + if (perm_str) { + perm_mac = ether_aton (perm_str); + mac = nm_setting_wired_get_mac_address (s_wired); + if (mac && perm_mac && memcmp (mac->data, perm_mac->ether_addr_octet, ETH_ALEN)) + continue; + } + } + + /* Connection applies to this device */ + filtered = g_slist_prepend (filtered, candidate); + } + + return g_slist_reverse (filtered); +} + +/***********************************************************/ + static void nm_device_ethernet_init (NMDeviceEthernet *device) { @@ -257,11 +322,8 @@ finalize (GObject *object) { NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (object); - if (priv->hw_address) - g_free (priv->hw_address); - - if (priv->perm_hw_address) - g_free (priv->perm_hw_address); + g_free (priv->hw_address); + g_free (priv->perm_hw_address); G_OBJECT_CLASS (nm_device_ethernet_parent_class)->finalize (object); } @@ -294,17 +356,19 @@ get_property (GObject *object, } static void -nm_device_ethernet_class_init (NMDeviceEthernetClass *device_class) +nm_device_ethernet_class_init (NMDeviceEthernetClass *eth_class) { - GObjectClass *object_class = G_OBJECT_CLASS (device_class); + GObjectClass *object_class = G_OBJECT_CLASS (eth_class); + NMDeviceClass *device_class = NM_DEVICE_CLASS (eth_class); - g_type_class_add_private (device_class, sizeof (NMDeviceEthernetPrivate)); + g_type_class_add_private (eth_class, sizeof (NMDeviceEthernetPrivate)); /* virtual methods */ object_class->constructor = constructor; object_class->dispose = dispose; object_class->finalize = finalize; object_class->get_property = get_property; + device_class->filter_connections = filter_connections; /* properties */ |