summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-02-20 15:58:20 +0100
committerThomas Haller <thaller@redhat.com>2023-02-21 09:30:53 +0100
commit0b4446e252e3a686478d7c080265d0f0e7001cc6 (patch)
treee62f3ca8cd5c8abb17f0b23fa9c6d39a5b5d5fc7
parent05c6a0d6fab2aa9afc60b4a9a80a36df3b45d6c4 (diff)
downloadNetworkManager-0b4446e252e3a686478d7c080265d0f0e7001cc6.tar.gz
libnm: accept ipv[46].dhcp-iaid as hexstr
dhclient exports the currently used IAID in the environment as hex string. We expose this environment in our API, so this is also the format that NetworkManager uses. Accept setting the ipv[46].dhcp-iaid as hex string, so that the same format is accepted on the profile. While at it, also accept a hex number (0x) because it is also convenient, and this change already introduces the precedent that the IAID string is not unique/normalized. (cherry picked from commit e5dc48919721bb41c8acd49e95bc5f174907971a)
-rw-r--r--src/libnm-core-impl/nm-utils.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c
index 8ffc070e90..c389213f3f 100644
--- a/src/libnm-core-impl/nm-utils.c
+++ b/src/libnm-core-impl/nm-utils.c
@@ -5666,7 +5666,8 @@ _nm_utils_ranges_cmp(_NM_SETT_INFO_PROP_COMPARE_FCN_ARGS _nm_nil)
gboolean
_nm_utils_iaid_verify(const char *str, gint64 *out_value)
{
- gint64 iaid;
+ gint64 i64;
+ guint32 u32;
NM_SET_OUT(out_value, -1);
@@ -5676,10 +5677,16 @@ _nm_utils_iaid_verify(const char *str, gint64 *out_value)
if (NM_IAID_IS_SPECIAL(str))
return TRUE;
- if (NM_STRCHAR_ALL(str, ch, ch >= '0' && ch <= '9') && (str[0] != '0' || str[1] == '\0')
- && (iaid = _nm_utils_ascii_str_to_int64(str, 10, 0, G_MAXUINT32, -1)) != -1) {
- NM_SET_OUT(out_value, iaid);
- return TRUE;
+ if (NM_STRCHAR_ALL(str, ch, g_ascii_isxdigit(ch) || NM_IN_SET(ch, 'x', ':'))) {
+ if ((i64 = _nm_utils_ascii_str_to_int64(str, 0, 0, G_MAXUINT32, -1)) != -1) {
+ NM_SET_OUT(out_value, i64);
+ return TRUE;
+ }
+
+ if (nm_dhcp_iaid_from_hexstr(str, &u32)) {
+ NM_SET_OUT(out_value, u32);
+ return TRUE;
+ }
}
return FALSE;