summaryrefslogtreecommitdiff
path: root/libnm-glib/nm-device-ethernet.c
diff options
context:
space:
mode:
Diffstat (limited to 'libnm-glib/nm-device-ethernet.c')
-rw-r--r--libnm-glib/nm-device-ethernet.c69
1 files changed, 66 insertions, 3 deletions
diff --git a/libnm-glib/nm-device-ethernet.c b/libnm-glib/nm-device-ethernet.c
index e7a1fe2504..6584a3f96c 100644
--- a/libnm-glib/nm-device-ethernet.c
+++ b/libnm-glib/nm-device-ethernet.c
@@ -21,6 +21,14 @@
* 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"
@@ -186,6 +194,59 @@ nm_device_ethernet_get_carrier (NMDeviceEthernet *device)
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)
{
@@ -298,17 +359,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 */