]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: Add T1 and T2 DHCPv6 options to expose in dbus API
authorNandakumar Raghavan <naraghavan@microsoft.com>
Wed, 2 Aug 2023 10:34:17 +0000 (10:34 +0000)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Aug 2023 03:43:09 +0000 (12:43 +0900)
Include T1 and T2 DHCPv6 options to expose in dbus API.
Introduced new field DHCPv6lease where these options are
added. This will be added to the JSON output when we query
org.freedesktop.network1.Manager object.

src/libsystemd-network/dhcp6-lease-internal.h
src/network/networkd-json.c

index f4c12ca7c4a598d0e400802c2b9540622c4a2287..470fc798709f0cace42fa755afefbfe809e7e09c 100644 (file)
@@ -10,6 +10,7 @@
 #include "sd-dhcp6-lease.h"
 
 #include "dhcp6-option.h"
+#include "dhcp6-protocol.h"
 #include "macro.h"
 #include "time-util.h"
 
index bb83a359678c460a06a80de254ae2f86a9b75e5a..78bf8705070c0c14d5736da3fc2eaaee2b704721 100644 (file)
@@ -3,6 +3,7 @@
 #include <linux/nexthop.h>
 
 #include "dhcp-server-internal.h"
+#include "dhcp6-lease-internal.h"
 #include "dns-domain.h"
 #include "ip-protocol-list.h"
 #include "netif-util.h"
@@ -1023,6 +1024,42 @@ static int dhcp_server_append_json(Link *link, JsonVariant **v) {
         return json_append_one(v, "DHCPServer", w);
 }
 
+static int dhcp6_client_lease_append_json(Link *link, JsonVariant **v) {
+        _cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
+        int r;
+
+        assert(link);
+        assert(v);
+
+        if (!link->dhcp6_lease)
+                return 0;
+
+        r = json_build(&w, JSON_BUILD_OBJECT(
+                                JSON_BUILD_PAIR_FINITE_USEC("T1", link->dhcp6_lease->lifetime_t1),
+                                JSON_BUILD_PAIR_FINITE_USEC("T2", link->dhcp6_lease->lifetime_t2)));
+        if (r < 0)
+                return r;
+
+        return json_append_one(v, "Lease", w);
+}
+
+static int dhcp6_client_append_json(Link *link, JsonVariant **v) {
+        _cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
+        int r;
+
+        assert(link);
+        assert(v);
+
+        if (!link->dhcp6_client)
+                return 0;
+
+        r = dhcp6_client_lease_append_json(link, &w);
+        if (r < 0)
+                return r;
+
+        return json_append_one(v, "DHCPv6Client", w);
+}
+
 int link_build_json(Link *link, JsonVariant **ret) {
         _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
         _cleanup_free_ char *type = NULL, *flags = NULL;
@@ -1138,6 +1175,10 @@ int link_build_json(Link *link, JsonVariant **ret) {
         if (r < 0)
                 return r;
 
+        r = dhcp6_client_append_json(link, &v);
+        if (r < 0)
+                return r;
+
         *ret = TAKE_PTR(v);
         return 0;
 }