From: Susant Sahani Date: Wed, 21 Feb 2024 10:32:27 +0000 (+0530) Subject: network: DHCP6 Allow to export DHCP6 DUID (#31355) X-Git-Tag: v256-rc1~791 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e5aa8c193d730bca26fe123258d9a73834509f26;p=thirdparty%2Fsystemd.git network: DHCP6 Allow to export DHCP6 DUID (#31355) We did not support the export of DHCP6 DUID. Let's add this. Some applications may use it. --- diff --git a/src/network/networkd-json.c b/src/network/networkd-json.c index 4db622b638d..134fb6bb2aa 100644 --- a/src/network/networkd-json.c +++ b/src/network/networkd-json.c @@ -1076,6 +1076,29 @@ static int dhcp6_client_pd_append_json(Link *link, JsonVariant **v) { return json_variant_set_field_non_null(v, "Prefixes", array); } +static int dhcp6_client_duid_append_json(Link *link, JsonVariant **v) { + const sd_dhcp_duid *duid; + const void *data; + size_t data_size; + int r; + + assert(link); + assert(v); + + if (!link->dhcp6_client) + return 0; + + r = sd_dhcp6_client_get_duid(link->dhcp6_client, &duid); + if (r < 0) + return 0; + + r = sd_dhcp_duid_get_raw(&link->dhcp6_client->duid, &data, &data_size); + if (r < 0) + return 0; + + return json_variant_merge_objectb(v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_BYTE_ARRAY("DUID", data, data_size))); +} + static int dhcp6_client_append_json(Link *link, JsonVariant **v) { _cleanup_(json_variant_unrefp) JsonVariant *w = NULL; int r; @@ -1098,6 +1121,10 @@ static int dhcp6_client_append_json(Link *link, JsonVariant **v) { if (r < 0) return r; + r = dhcp6_client_duid_append_json(link, &w); + if (r < 0) + return r; + return json_variant_set_field_non_null(v, "DHCPv6Client", w); }