[PATCH 3/4] device: deduplicate match_hwaddr()



---
 src/devices/nm-device-macvlan.c | 28 ++--------------------------
 src/devices/nm-device-private.h |  3 +++
 src/devices/nm-device-vlan.c    | 28 ++--------------------------
 src/devices/nm-device.c         | 26 ++++++++++++++++++++++++++
 4 files changed, 33 insertions(+), 52 deletions(-)

diff --git a/src/devices/nm-device-macvlan.c b/src/devices/nm-device-macvlan.c
index ffaa094cb..2a461543b 100644
--- a/src/devices/nm-device-macvlan.c
+++ b/src/devices/nm-device-macvlan.c
@@ -287,30 +287,6 @@ is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
 /*****************************************************************************/
 
 static gboolean
-match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr)
-{
-       NMSettingWired *s_wired;
-       NMDevice *parent_device;
-       const char *setting_mac;
-       const char *parent_mac;
-
-       s_wired = nm_connection_get_setting_wired (connection);
-       if (!s_wired)
-               return !fail_if_no_hwaddr;
-
-       setting_mac = nm_setting_wired_get_mac_address (s_wired);
-       if (!setting_mac)
-               return !fail_if_no_hwaddr;
-
-       parent_device = nm_device_parent_get_device (device);
-       if (!parent_device)
-               return !fail_if_no_hwaddr;
-
-       parent_mac = nm_device_get_permanent_hw_address (parent_device);
-       return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1);
-}
-
-static gboolean
 check_connection_compatible (NMDevice *device, NMConnection *connection)
 {
        NMDeviceMacvlanPrivate *priv = NM_DEVICE_MACVLAN_GET_PRIVATE ((NMDeviceMacvlan *) device);
@@ -343,7 +319,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
                                return FALSE;
                } else {
                        /* Parent could be a MAC address in an NMSettingWired */
-                       if (!match_hwaddr (device, connection, TRUE))
+                       if (!nm_device_match_hwaddr (device, connection, TRUE))
                                return FALSE;
                }
        }
@@ -380,7 +356,7 @@ complete_connection (NMDevice *device,
         * settings, then there's not enough information to complete the setting.
         */
        if (   !nm_setting_macvlan_get_parent (s_macvlan)
-           && !match_hwaddr (device, connection, TRUE)) {
+           && !nm_device_match_hwaddr (device, connection, TRUE)) {
                g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
                                     "The 'macvlan' setting had no interface name, parent, or hardware 
address.");
                return FALSE;
diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h
index f3c301d48..416ae845c 100644
--- a/src/devices/nm-device-private.h
+++ b/src/devices/nm-device-private.h
@@ -133,5 +133,8 @@ gboolean _nm_device_hash_check_invalid_keys (GHashTable *hash, const char *setti
        _nm_device_hash_check_invalid_keys (hash, setting_name, error, ((const char *[]) { __VA_ARGS__, NULL 
}))
 
 gboolean nm_device_match_parent (NMDevice *device, const char *parent);
+gboolean nm_device_match_hwaddr (NMDevice *device,
+                                 NMConnection *connection,
+                                 gboolean fail_if_no_hwaddr);
 
 #endif /* NM_DEVICE_PRIVATE_H */
diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c
index 0badfd285..06f19c408 100644
--- a/src/devices/nm-device-vlan.c
+++ b/src/devices/nm-device-vlan.c
@@ -315,30 +315,6 @@ is_available (NMDevice *device, NMDeviceCheckDevAvailableFlags flags)
 /*****************************************************************************/
 
 static gboolean
-match_hwaddr (NMDevice *device, NMConnection *connection, gboolean fail_if_no_hwaddr)
-{
-       NMSettingWired *s_wired;
-       NMDevice *parent_device;
-       const char *setting_mac;
-       const char *parent_mac;
-
-       s_wired = nm_connection_get_setting_wired (connection);
-       if (!s_wired)
-               return !fail_if_no_hwaddr;
-
-       setting_mac = nm_setting_wired_get_mac_address (s_wired);
-       if (!setting_mac)
-               return !fail_if_no_hwaddr;
-
-       parent_device = nm_device_parent_get_device (device);
-       if (!parent_device)
-               return !fail_if_no_hwaddr;
-
-       parent_mac = nm_device_get_permanent_hw_address (parent_device);
-       return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1);
-}
-
-static gboolean
 check_connection_compatible (NMDevice *device, NMConnection *connection)
 {
        NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE ((NMDeviceVlan *) device);
@@ -364,7 +340,7 @@ check_connection_compatible (NMDevice *device, NMConnection *connection)
                                return FALSE;
                } else {
                        /* Parent could be a MAC address in an NMSettingWired */
-                       if (!match_hwaddr (device, connection, TRUE))
+                       if (!nm_device_match_hwaddr (device, connection, TRUE))
                                return FALSE;
                }
        }
@@ -413,7 +389,7 @@ complete_connection (NMDevice *device,
         * settings, then there's not enough information to complete the setting.
         */
        if (   !nm_setting_vlan_get_parent (s_vlan)
-           && !match_hwaddr (device, connection, TRUE)) {
+           && !nm_device_match_hwaddr (device, connection, TRUE)) {
                g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
                                     "The 'vlan' setting had no interface name, parent, or hardware 
address.");
                return FALSE;
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index e14a15f79..6d51641f2 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -4427,6 +4427,32 @@ nm_device_match_parent (NMDevice *self, const char *parent)
        return TRUE;
 }
 
+gboolean
+nm_device_match_hwaddr (NMDevice *device,
+                        NMConnection *connection,
+                        gboolean fail_if_no_hwaddr)
+{
+       NMSettingWired *s_wired;
+       NMDevice *parent_device;
+       const char *setting_mac;
+       const char *parent_mac;
+
+       s_wired = nm_connection_get_setting_wired (connection);
+       if (!s_wired)
+               return !fail_if_no_hwaddr;
+
+       setting_mac = nm_setting_wired_get_mac_address (s_wired);
+       if (!setting_mac)
+               return !fail_if_no_hwaddr;
+
+       parent_device = nm_device_parent_get_device (device);
+       if (!parent_device)
+               return !fail_if_no_hwaddr;
+
+       parent_mac = nm_device_get_permanent_hw_address (parent_device);
+       return parent_mac && nm_utils_hwaddr_matches (setting_mac, -1, parent_mac, -1);
+}
+
 static gboolean
 check_connection_compatible (NMDevice *self, NMConnection *connection)
 {
-- 
2.13.5



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]