]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: DHCP6 Allow to export DHCP6 DUID (#31355)
authorSusant Sahani <ssahani@vmware.com>
Wed, 21 Feb 2024 10:32:27 +0000 (16:02 +0530)
committerGitHub <noreply@github.com>
Wed, 21 Feb 2024 10:32:27 +0000 (19:32 +0900)
We did not support the export of DHCP6 DUID. Let's add this. Some
applications may use it.

src/network/networkd-json.c

index 4db622b638de9ae8ecd2a53978094e5fc6f72b50..134fb6bb2aa5d22ea459dbc1fb30f9ef7547561e 100644 (file)
@@ -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);
 }