mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-03 01:17:45 +03:00
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. (cherry picked from commit841dfd3dc0
) (cherry picked from commita674a398e7
)
This commit is contained in:
parent
48251e428f
commit
088d6c8521
@ -189,35 +189,33 @@ int sd_dhcp_client_id_to_string(const void *data, size_t len, char **ret) {
|
|||||||
r = asprintf(&t, "DATA");
|
r = asprintf(&t, "DATA");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
if (len != sizeof_field(sd_dhcp_client_id, eth))
|
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],
|
||||||
r = asprintf(&t, "%02x:%02x:%02x:%02x:%02x:%02x",
|
client_id->eth.haddr[1],
|
||||||
client_id->eth.haddr[0],
|
client_id->eth.haddr[2],
|
||||||
client_id->eth.haddr[1],
|
client_id->eth.haddr[3],
|
||||||
client_id->eth.haddr[2],
|
client_id->eth.haddr[4],
|
||||||
client_id->eth.haddr[3],
|
client_id->eth.haddr[5]);
|
||||||
client_id->eth.haddr[4],
|
else
|
||||||
client_id->eth.haddr[5]);
|
r = asprintf(&t, "ETHER");
|
||||||
break;
|
break;
|
||||||
case 2 ... 254:
|
case 2 ... 254:
|
||||||
r = asprintf(&t, "ARP/LL");
|
r = asprintf(&t, "ARP/LL");
|
||||||
break;
|
break;
|
||||||
case 255:
|
case 255:
|
||||||
if (len < 6)
|
if (len < sizeof(uint32_t))
|
||||||
return -EINVAL;
|
r = asprintf(&t, "IAID/DUID");
|
||||||
|
else {
|
||||||
uint32_t iaid = be32toh(client_id->ns.iaid);
|
uint32_t iaid = be32toh(client_id->ns.iaid);
|
||||||
uint16_t duid_type = be16toh(client_id->ns.duid.type);
|
/* TODO: check and stringify DUID */
|
||||||
if (dhcp_validate_duid_len(duid_type, len - 6, true) < 0)
|
r = asprintf(&t, "IAID:0x%x/DUID", iaid);
|
||||||
return -EINVAL;
|
}
|
||||||
|
|
||||||
r = asprintf(&t, "IAID:0x%x/DUID", iaid);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
*ret = TAKE_PTR(t);
|
*ret = TAKE_PTR(t);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user