libnm-core, etc: add nm_utils_hwaddr_matches()

Add nm_utils_hwaddr_matches(), for comparing hardware addresses for
equality, allowing either binary or ASCII hardware addresses to be
passed, and handling the special rules for InfiniBand hardware
addresses automatically. Update code to use it.
This commit is contained in:
Dan Winship
2014-06-16 11:30:47 -04:00
parent 357efd26e4
commit 44b9a8708b
26 changed files with 240 additions and 136 deletions

View File

@@ -585,18 +585,22 @@ nm_match_spec_string (const GSList *specs, const char *match)
gboolean
nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr)
{
char *hwaddr_match;
gboolean matched;
const GSList *iter;
g_return_val_if_fail (hwaddr != NULL, FALSE);
if (nm_match_spec_string (specs, hwaddr))
return TRUE;
for (iter = specs; iter; iter = g_slist_next (iter)) {
const char *spec_str = iter->data;
hwaddr_match = g_strdup_printf ("mac:%s", hwaddr);
matched = nm_match_spec_string (specs, hwaddr_match);
g_free (hwaddr_match);
return matched;
if ( !g_ascii_strncasecmp (spec_str, "mac:", 4)
&& nm_utils_hwaddr_matches (spec_str + 4, -1, hwaddr, -1))
return TRUE;
if (nm_utils_hwaddr_matches (spec_str, -1, hwaddr, -1))
return TRUE;
}
return FALSE;
}
gboolean