diff options
author | Thomas Haller <thaller@redhat.com> | 2023-02-14 09:44:31 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-02-21 09:12:59 +0100 |
commit | 69106d0aef1022bb1959f9badc0515134969e5d5 (patch) | |
tree | bc79496ac331c66252499577d2723073abd283fe | |
parent | d403ac3d40264876c75298e7b4d475a8b49c0921 (diff) | |
download | NetworkManager-69106d0aef1022bb1959f9badc0515134969e5d5.tar.gz |
core: reuse _nm_utils_iaid_verify() for parsing
There should be one function for parsing the string. Use it everywhere.
Also, because we will accept specifying the IAID as hex string so the
same parsing code should be used everywhere.
-rw-r--r-- | src/core/devices/nm-device.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c index a6c66a96d3..8629a3ef7d 100644 --- a/src/core/devices/nm-device.c +++ b/src/core/devices/nm-device.c @@ -1810,6 +1810,7 @@ _prop_get_ipvx_dhcp_iaid(NMDevice *self, const char *iface; const char *fail_reason; gboolean is_explicit = TRUE; + gint64 i64; s_ip = nm_connection_get_setting_ip_config(connection, addr_family); iaid_str = nm_setting_ip_config_get_dhcp_iaid(s_ip); @@ -1868,7 +1869,7 @@ _prop_get_ipvx_dhcp_iaid(NMDevice *self, iaid = unaligned_read_be32(&hwaddr_buf[hwaddr_len - 4]); goto out_good; - } else if (nm_streq(iaid_str, "stable")) { + } else if (nm_streq(iaid_str, NM_IAID_STABLE)) { nm_auto_free_checksum GChecksum *sum = NULL; guint8 digest[NM_UTILS_CHECKSUM_LENGTH_SHA1]; NMUtilsStableType stable_type; @@ -1891,14 +1892,21 @@ _prop_get_ipvx_dhcp_iaid(NMDevice *self, iaid = unaligned_read_be32(digest); goto out_good; - } else if ((iaid = _nm_utils_ascii_str_to_int64(iaid_str, 10, 0, G_MAXUINT32, -1)) != -1) { - goto out_good; - } else { + } else if (nm_streq(iaid_str, NM_IAID_IFNAME)) { iface = nm_device_get_ip_iface(self); iaid = nm_utils_create_dhcp_iaid(TRUE, (const guint8 *) iface, strlen(iface)); goto out_good; + } else if (_nm_utils_iaid_verify(iaid_str, &i64)) { + if (i64 < 0) { + fail_reason = nm_assert_unreachable_val("bug handling iaid value"); + goto out_fail; + } + nm_assert(i64 <= G_MAXUINT32); + iaid = (guint32) i64; + goto out_good; } + fail_reason = nm_assert_unreachable_val("bug handling iaid code"); out_fail: nm_assert(fail_reason); if (!log_silent) { |