summaryrefslogtreecommitdiff
path: root/src/libsystemd-network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-01-16 13:08:55 +0900
committerLuca Boccassi <luca.boccassi@gmail.com>2023-01-16 20:00:08 +0000
commit841dfd3dc0dd370a21f190a5b7b870db1c95f7e6 (patch)
tree799d4bb98ababb6ea51ca1fc474568546333f20c /src/libsystemd-network
parentec56edf55c26ed2c65cf8e86b81ab0b516c94dd9 (diff)
downloadsystemd-841dfd3dc0dd370a21f190a5b7b870db1c95f7e6.tar.gz
sd-dhcp-client: gracefully handle invalid ether type client ID
Currently, sd-dhcp-server accepts spurious client IDs, then the leases exposed by networkd may be invalid. Let's make networkctl gracefully show such leases. Fixes #25984.
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r--src/libsystemd-network/sd-dhcp-client.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index f5abb1bf86..e482450cd4 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -195,35 +195,33 @@ int sd_dhcp_client_id_to_string(const void *data, size_t len, char **ret) {
r = asprintf(&t, "DATA");
break;
case 1:
- if (len != sizeof_field(sd_dhcp_client_id, eth))
- return -EINVAL;
-
- r = asprintf(&t, "%02x:%02x:%02x:%02x:%02x:%02x",
- client_id->eth.haddr[0],
- client_id->eth.haddr[1],
- client_id->eth.haddr[2],
- client_id->eth.haddr[3],
- client_id->eth.haddr[4],
- client_id->eth.haddr[5]);
+ if (len == sizeof_field(sd_dhcp_client_id, eth))
+ r = asprintf(&t, "%02x:%02x:%02x:%02x:%02x:%02x",
+ client_id->eth.haddr[0],
+ client_id->eth.haddr[1],
+ client_id->eth.haddr[2],
+ client_id->eth.haddr[3],
+ client_id->eth.haddr[4],
+ client_id->eth.haddr[5]);
+ else
+ r = asprintf(&t, "ETHER");
break;
case 2 ... 254:
r = asprintf(&t, "ARP/LL");
break;
case 255:
- if (len < 6)
- return -EINVAL;
-
- uint32_t iaid = be32toh(client_id->ns.iaid);
- uint16_t duid_type = be16toh(client_id->ns.duid.type);
- if (dhcp_validate_duid_len(duid_type, len - 6, true) < 0)
- return -EINVAL;
-
- r = asprintf(&t, "IAID:0x%x/DUID", iaid);
+ if (len < sizeof(uint32_t))
+ r = asprintf(&t, "IAID/DUID");
+ else {
+ uint32_t iaid = be32toh(client_id->ns.iaid);
+ /* TODO: check and stringify DUID */
+ r = asprintf(&t, "IAID:0x%x/DUID", iaid);
+ }
break;
}
-
if (r < 0)
return -ENOMEM;
+
*ret = TAKE_PTR(t);
return 0;
}