networkd: Add T1 and T2 DHCPv6 options to expose in dbus API

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.
This commit is contained in:
Nandakumar Raghavan
2023-08-02 10:34:17 +00:00
committed by Yu Watanabe
parent 856532ef01
commit a2fc6f2d59
2 changed files with 42 additions and 0 deletions

View 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"

View 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;
}