libnm-util: move dev_valid_name() to libnm-util and make it public

The bridging code needs it as well.
This commit is contained in:
Thomas Graf 2012-05-23 16:19:25 +02:00 committed by Dan Williams
parent c8c7690bb4
commit b46508b5c6
4 changed files with 34 additions and 26 deletions

View file

@ -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;

View file

@ -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,

View file

@ -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;
}

View file

@ -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 */