summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Cardace <acardace@redhat.com>2020-05-20 10:37:14 +0200
committerAntonio Cardace <acardace@redhat.com>2020-05-21 15:19:22 +0200
commit7d5c0de4b93d63c2c9ff045c88c0b61e25e5a598 (patch)
treef610f6261acbc84e66b615c5bb32ef7318480b62
parent7774d837d76f98b0a29b50a157cd5d0582e40d77 (diff)
downloadNetworkManager-7d5c0de4b93d63c2c9ff045c88c0b61e25e5a598.tar.gz
dhcpv4: allow client-ids up to 255 bytes lengthac/dhcpv4_clientid
client identifiers were truncated to 133 bytes which is an arbitrary number first chosen by systemd's DHCP implementation, the actual maximum length for the option is 255 bytes.
-rw-r--r--src/dhcp/nm-dhcp-nettools.c2
-rw-r--r--src/dhcp/nm-dhcp-utils.c39
2 files changed, 23 insertions, 18 deletions
diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c
index 1019f33a2a..dbc4d8b17d 100644
--- a/src/dhcp/nm-dhcp-nettools.c
+++ b/src/dhcp/nm-dhcp-nettools.c
@@ -1194,7 +1194,7 @@ nettools_create (NMDhcpNettools *self,
n_dhcp4_client_config_set_broadcast_mac (config, bcast_hwaddr_arr, bcast_hwaddr_len);
r = n_dhcp4_client_config_set_client_id (config,
client_id_arr,
- NM_MIN (client_id_len, 1 + _NM_SD_MAX_CLIENT_ID_LEN));
+ client_id_len);
if (r) {
set_error_nettools (error, r, "failed to set client-id");
return FALSE;
diff --git a/src/dhcp/nm-dhcp-utils.c b/src/dhcp/nm-dhcp-utils.c
index d8e5a65328..e665db61f5 100644
--- a/src/dhcp/nm-dhcp-utils.c
+++ b/src/dhcp/nm-dhcp-utils.c
@@ -18,6 +18,8 @@
#include "nm-dhcp-client-logging.h"
#include "nm-core-internal.h"
+#define NM_DHCP_CLIENT_ID_LEN_MAX (255)
+
/*****************************************************************************/
static gboolean
@@ -722,32 +724,35 @@ nm_dhcp_utils_duid_to_string (GBytes *duid)
GBytes *
nm_dhcp_utils_client_id_string_to_bytes (const char *client_id)
{
- GBytes *bytes = NULL;
- guint len;
- char *c;
+ guint8 *buffer = NULL;
+ gsize len;
g_return_val_if_fail (client_id && client_id[0], NULL);
/* Try as hex encoded */
if (strchr (client_id, ':')) {
- bytes = nm_utils_hexstr2bin (client_id);
-
- /* the result must be at least two bytes long,
- * because @client_id contains a delimiter
- * but nm_utils_hexstr2bin() does not allow
- * leading nor trailing delimiters. */
- nm_assert (!bytes || g_bytes_get_size (bytes) >= 2);
+ buffer = nm_utils_hexstr2bin_alloc (client_id,
+ TRUE,
+ FALSE,
+ ":",
+ 0,
+ &len);
+ if (len > NM_DHCP_CLIENT_ID_LEN_MAX) {
+ len = NM_DHCP_CLIENT_ID_LEN_MAX;
+ buffer = g_realloc (buffer, len);
+ }
}
- if (!bytes) {
+ if (!buffer) {
/* Fall back to string */
- len = strlen (client_id);
- c = g_malloc (len + 1);
- c[0] = 0; /* type: non-hardware address per RFC 2132 section 9.14 */
- memcpy (c + 1, client_id, len);
- bytes = g_bytes_new_take (c, len + 1);
+ len = NM_MIN (NM_DHCP_CLIENT_ID_LEN_MAX, strlen (client_id) + 1);
+ buffer = g_malloc (len);
+ buffer[0] = 0; /* type: non-hardware address per RFC 2132 section 9.14 */
+ memcpy (buffer + 1, client_id, len - 1);
}
- return bytes;
+ nm_assert (buffer && len >= 2 && len <= NM_DHCP_CLIENT_ID_LEN_MAX);
+ return g_bytes_new_take (buffer, len);
+;
}
/**