[PATCH 1/6] utils: Move dev_valid_name() to libnm-utils and make it public



The bridging code needs it as well.
---
 libnm-util/libnm-util.ver    |    1 +
 libnm-util/nm-setting-bond.c |   27 +--------------------------
 libnm-util/nm-utils.c        |   30 ++++++++++++++++++++++++++++++
 libnm-util/nm-utils.h        |    2 ++
 4 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index 9eec05c..d8850a5 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -499,6 +499,7 @@ global:
 	nm_utils_hwaddr_len;
 	nm_utils_hwaddr_ntoa;
 	nm_utils_hwaddr_type;
+	nm_utils_iface_valid_name;
 	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 fe874ab..fef6870 100644
--- a/libnm-util/nm-setting-bond.c
+++ b/libnm-util/nm-setting-bond.c
@@ -329,31 +329,6 @@ nm_setting_bond_get_option_default (NMSettingBond *setting, const char *name)
 	g_assert_not_reached ();
 }
 
-/*
- * 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 gint
 find_setting_by_name (gconstpointer a, gconstpointer b)
 {
@@ -388,7 +363,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
 		return FALSE;
 	}
 
-	if (!dev_valid_name (priv->interface_name)) {
+	if (!nm_utils_iface_valid_name (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 a880620..c0d398b 100644
--- a/libnm-util/nm-utils.c
+++ b/libnm-util/nm-utils.c
@@ -2568,3 +2568,33 @@ 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_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;
+}
diff --git a/libnm-util/nm-utils.h b/libnm-util/nm-utils.h
index 7bc536a..8f91283 100644
--- a/libnm-util/nm-utils.h
+++ b/libnm-util/nm-utils.h
@@ -134,6 +134,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_valid_name(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]