diff options
author | Thomas Graf <tgraf@redhat.com> | 2012-05-23 16:19:25 +0200 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2012-08-29 17:46:54 -0500 |
commit | b46508b5c66ab179fb7560859289cc327eef09fa (patch) | |
tree | 0c135bb91fc1d28f1f16525d516368dc8d8d90c3 /libnm-util | |
parent | c8c7690bb49e50a740e01e2d543f27bfac72b2e1 (diff) | |
download | NetworkManager-b46508b5c66ab179fb7560859289cc327eef09fa.tar.gz |
libnm-util: move dev_valid_name() to libnm-util and make it public
The bridging code needs it as well.
Diffstat (limited to 'libnm-util')
-rw-r--r-- | libnm-util/libnm-util.ver | 1 | ||||
-rw-r--r-- | libnm-util/nm-setting-bond.c | 27 | ||||
-rw-r--r-- | libnm-util/nm-utils.c | 30 | ||||
-rw-r--r-- | 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 4f0c27c5b4..bc14f248c1 100644 --- a/libnm-util/libnm-util.ver +++ b/libnm-util/libnm-util.ver @@ -500,6 +500,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 b7994f4a74..2cabe40c05 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 ad966c25bf..36876ab67d 100644 --- a/libnm-util/nm-utils.c +++ b/libnm-util/nm-utils.c @@ -2582,3 +2582,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 dd29230b41..28514864f4 100644 --- a/libnm-util/nm-utils.h +++ b/libnm-util/nm-utils.h @@ -135,6 +135,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 */ |