[PATCH 1/4] utils: Move dev_valid_name() to libnm-util as nm_utils_iface_name_valid()



Bridiging will make use of it.

Signed-off-by: Thomas Graf <tgraf redhat com>
---
 libnm-util/libnm-util.ver    |    1 +
 libnm-util/nm-setting-bond.c |   27 +--------------------------
 libnm-util/nm-utils.c        |   32 ++++++++++++++++++++++++++++++++
 libnm-util/nm-utils.h        |    2 ++
 4 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index cd676fe..0e8b30b 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -460,6 +460,7 @@ global:
 	nm_utils_hwaddr_len;
 	nm_utils_hwaddr_ntoa;
 	nm_utils_hwaddr_type;
+	nm_utils_iface_name_valid;
 	nm_utils_init;
 	nm_utils_ip4_addresses_from_gvalue;
 	nm_utils_ip4_addresses_to_gvalue;
diff --git a/libnm-util/nm-setting-bond.c b/libnm-util/nm-setting-bond.c
index 3aa9cf3..a6e7447 100644
--- a/libnm-util/nm-setting-bond.c
+++ b/libnm-util/nm-setting-bond.c
@@ -220,31 +220,6 @@ nm_setting_bond_get_arp_ip_target (NMSettingBond *setting)
 	return NM_SETTING_BOND_GET_PRIVATE (setting)->arp_ip_target;
 }
 
-/*
- * This function is a 1:1 copy of the kernel's
- * dev_valid_name() in net/core/dev.c
- */
-static gboolean
-dev_valid_name(const char *name)
-{
-	if (*name == '\0')
-		return FALSE;
-
-	if (strlen (name) >= 16)
-		return FALSE;
-
-	if (!strcmp (name, ".") || !strcmp (name, ".."))
-		return FALSE;
-
-	while (*name) {
-		if (*name == '/' || isspace (*name))
-			return FALSE;
-		name++;
-	}
-
-	return TRUE;
-}
-
 static gboolean
 verify (NMSetting *setting, GSList *all_settings, GError **error)
 {
@@ -266,7 +241,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
 		return FALSE;
 	}
 
-	if (!dev_valid_name (priv->interface_name)) {
+	if (!nm_utils_iface_name_valid (priv->interface_name)) {
 		g_set_error (error,
 		             NM_SETTING_BOND_ERROR,
 		             NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
diff --git a/libnm-util/nm-utils.c b/libnm-util/nm-utils.c
index bef0ca0..de000bf 100644
--- a/libnm-util/nm-utils.c
+++ b/libnm-util/nm-utils.c
@@ -2531,3 +2531,35 @@ nm_utils_hwaddr_ntoa (gconstpointer addr, int type)
 
 	return g_string_free (out, FALSE);
 }
+
+/**
+ * nm_utils_iface_name_valid:
+ * @name: Name of interface
+ *
+ * This function is a 1:1 copy of the kernel's interface validation
+ * function in net/core/dev.c.
+ *
+ * Returns: %TRUE if interface name is valid, otherwise %FALSE is returned.
+ */
+gboolean
+nm_utils_iface_name_valid (const char *name)
+{
+	g_return_val_if_fail (name != NULL, FALSE);
+
+	if (*name == '\0')
+		return FALSE;
+
+	if (strlen (name) >= 16)
+		return FALSE;
+
+	if (!strcmp (name, ".") || !strcmp (name, ".."))
+		return FALSE;
+
+	while (*name) {
+		if (*name == '/' || isspace (*name))
+			return FALSE;
+		name++;
+	}
+
+	return TRUE;
+}
diff --git a/libnm-util/nm-utils.h b/libnm-util/nm-utils.h
index 7684ed6..c29feba 100644
--- a/libnm-util/nm-utils.h
+++ b/libnm-util/nm-utils.h
@@ -133,6 +133,8 @@ char       *nm_utils_hwaddr_ntoa  (gconstpointer addr, int type);
 GByteArray *nm_utils_hwaddr_atoba (const char *asc, int type);
 guint8     *nm_utils_hwaddr_aton  (const char *asc, int type, gpointer buffer);
 
+gboolean nm_utils_iface_name_valid (const char *name);
+
 G_END_DECLS
 
 #endif /* NM_UTILS_H */
-- 
1.7.7.6



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