Move the code to match an ethernet device with a connection to libnm-glib
and support bonding connections.

Signed-off-by: Thomas Graf <[email protected]>
---
 cli/src/connections.c           |   60 +-------------------------------------
 libnm-glib/libnm-glib.ver       |    1 +
 libnm-glib/nm-device-ethernet.c |   61 ++++++++++++++++++++++++++++++---------
 libnm-glib/nm-device-ethernet.h |    2 +
 4 files changed, 51 insertions(+), 73 deletions(-)

diff --git a/cli/src/connections.c b/cli/src/connections.c
index acb396e..79bd1dd 100644
--- a/cli/src/connections.c
+++ b/cli/src/connections.c
@@ -664,64 +664,6 @@ error:
  * These function should be moved to libnm-glib in the end.
  */
 static gboolean
-check_ethernet_compatible (NMDeviceEthernet *device, NMConnection *connection, 
GError **error)
-{
-       NMSettingConnection *s_con;
-       NMSettingWired *s_wired;
-       const char *connection_type;
-       gboolean is_pppoe = FALSE;
-
-       g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-
-       s_con = nm_connection_get_setting_connection (connection);
-       g_assert (s_con);
-
-       connection_type = nm_setting_connection_get_connection_type (s_con);
-       if (   strcmp (connection_type, NM_SETTING_WIRED_SETTING_NAME)
-           && strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME)) {
-               g_set_error (error, 0, 0,
-                            "The connection was not a wired or PPPoE 
connection.");
-               return FALSE;
-       }
-
-       if (!strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME))
-               is_pppoe = TRUE;
-
-       s_wired = nm_connection_get_setting_wired (connection);
-       /* Wired setting is optional for PPPoE */
-       if (!is_pppoe && !s_wired) {
-               g_set_error (error, 0, 0,
-                            "The connection was not a valid wired 
connection.");
-               return FALSE;
-       }
-
-       if (s_wired) {
-               const GByteArray *mac;
-               const char *device_mac_str;
-               struct ether_addr *device_mac = NULL;
-
-               device_mac_str = nm_device_ethernet_get_permanent_hw_address 
(device);
-               if (device_mac_str)
-                       device_mac = ether_aton (device_mac_str);
-               if (!device_mac) {
-                       g_set_error (error, 0, 0, "Invalid device MAC 
address.");
-                       return FALSE;
-               }
-
-               mac = nm_setting_wired_get_mac_address (s_wired);
-               if (mac && memcmp (mac->data, device_mac->ether_addr_octet, 
ETH_ALEN)) {
-                       g_set_error (error, 0, 0,
-                                    "The connection's MAC address did not 
match this device.");
-                       return FALSE;
-               }
-       }
-
-       // FIXME: check bitrate against device capabilities
-
-       return TRUE;
-}
-
-static gboolean
 check_wifi_compatible (NMDeviceWifi *device, NMConnection *connection, GError 
**error)
 {
        NMSettingConnection *s_con;
@@ -966,7 +908,7 @@ nm_device_is_connection_compatible (NMDevice *device, 
NMConnection *connection,
        g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
 
        if (NM_IS_DEVICE_ETHERNET (device))
-               return check_ethernet_compatible (NM_DEVICE_ETHERNET (device), 
connection, error);
+               return nm_device_ethernet_compatible (device, connection, 
error);
        else if (NM_IS_DEVICE_WIFI (device))
                return check_wifi_compatible (NM_DEVICE_WIFI (device), 
connection, error);
        else if (NM_IS_DEVICE_BT (device))
diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver
index 1a4a68c..22ce83b 100644
--- a/libnm-glib/libnm-glib.ver
+++ b/libnm-glib/libnm-glib.ver
@@ -60,6 +60,7 @@ global:
        nm_device_bt_new;
        nm_device_connection_valid;
        nm_device_disconnect;
+       nm_device_ethernet_compatible;
        nm_device_ethernet_get_carrier;
        nm_device_ethernet_get_hw_address;
        nm_device_ethernet_get_permanent_hw_address;
diff --git a/libnm-glib/nm-device-ethernet.c b/libnm-glib/nm-device-ethernet.c
index 5801321..a1c33c2 100644
--- a/libnm-glib/nm-device-ethernet.c
+++ b/libnm-glib/nm-device-ethernet.c
@@ -194,48 +194,81 @@ nm_device_ethernet_get_carrier (NMDeviceEthernet *device)
        return priv->carrier;
 }
 
-static gboolean
-connection_valid (NMDevice *device, NMConnection *connection)
+gboolean
+nm_device_ethernet_compatible (NMDevice *device, NMConnection *connection,
+                               GError **error)
 {
+       const char *type, *iface;
        NMSettingConnection *s_con;
+       NMDeviceEthernet *self = NM_DEVICE_ETHERNET (device);
        NMSettingWired *s_wired;
-       const char *ctype;
-       gboolean is_pppoe = FALSE;
 
+       s_wired = nm_connection_get_setting_wired (connection);
        s_con = nm_connection_get_setting_connection (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)
+       iface = nm_connection_get_virtual_iface_name (connection);
+       if (iface && strcmp (nm_device_get_iface (device), iface))
                return FALSE;
 
-       s_wired = nm_connection_get_setting_wired (connection);
-       /* Wired setting optional for PPPoE */
-       if (!is_pppoe && !s_wired)
+       type = nm_setting_connection_get_connection_type (s_con);
+       g_assert (type);
+
+       if (!strcmp (type, NM_SETTING_PPPOE_SETTING_NAME)) {
+               /* NOP */
+       } else if (!strcmp (type, NM_SETTING_BOND_SETTING_NAME)) {
+               /* NOP */
+       } else if (!strcmp (type, NM_SETTING_WIRED_SETTING_NAME)) {
+               if (!s_wired) {
+                       if (error)
+                               g_set_error (error, 0, 0,
+                                            "The connection was not a valid 
wired connection.");
+                       return FALSE;
+               }
+       } else {
+               if (error) 
+                               g_set_error (error, 0, 0,
+                                            "The connection was not a wired, 
bond, or PPPoE connection.");
+                       
                return FALSE;
+       }
 
        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));
+               perm_str = nm_device_ethernet_get_permanent_hw_address (self);
                if (perm_str) {
                        perm_mac = ether_aton (perm_str);
+                       if (!perm_mac) {
+                               if (error)
+                                       g_set_error (error, 0, 0, "Invalid 
device MAC address.");
+                               return FALSE;
+                       }
+
                        mac = nm_setting_wired_get_mac_address (s_wired);
-                       if (mac && perm_mac && memcmp (mac->data, 
perm_mac->ether_addr_octet, ETH_ALEN))
+                       if (mac && memcmp (mac->data, 
perm_mac->ether_addr_octet, ETH_ALEN)) {
+                               if (error)
+                                       g_set_error (error, 0, 0,
+                                                    "The connection's MAC 
address did not match this device.");
                                return FALSE;
+                       }
                }
        }
 
        return TRUE;
 }
 
+static gboolean
+connection_valid (NMDevice *device, NMConnection *connection)
+{
+       return nm_device_ethernet_compatible (device, connection, NULL);
+}
+
 /***********************************************************/
 
 static void
diff --git a/libnm-glib/nm-device-ethernet.h b/libnm-glib/nm-device-ethernet.h
index 305ca02..d3cb13a 100644
--- a/libnm-glib/nm-device-ethernet.h
+++ b/libnm-glib/nm-device-ethernet.h
@@ -65,6 +65,8 @@ const char * nm_device_ethernet_get_permanent_hw_address 
(NMDeviceEthernet *devi
 guint32      nm_device_ethernet_get_speed   (NMDeviceEthernet *device);
 gboolean     nm_device_ethernet_get_carrier (NMDeviceEthernet *device);
 
+gboolean     nm_device_ethernet_compatible (NMDevice *device, NMConnection 
*connection, GError **error);
+
 G_END_DECLS
 
 #endif /* NM_DEVICE_ETHERNET_H */
-- 
1.7.7.3

_______________________________________________
networkmanager-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/networkmanager-list

Reply via email to