From 8628267f31b291e91d707da91813885bcb70946f Mon Sep 17 00:00:00 2001 From: Ronan Pigott Date: Thu, 29 Jun 2023 16:36:50 -0700 Subject: [PATCH] networkd: include captive portal information in link json description --- src/network/networkd-json.c | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/network/networkd-json.c b/src/network/networkd-json.c index 15cd1a93f68..31ccb9679a5 100644 --- a/src/network/networkd-json.c +++ b/src/network/networkd-json.c @@ -873,6 +873,41 @@ finalize: return r; } +static int captive_portal_build_json(Link *link, JsonVariant **ret) { + int r; + const char *captive_portal = NULL; + + assert(link); + assert(ret); + + if (!link->network) { + *ret = NULL; + return 0; + } + + if (link->network->dhcp_use_captive_portal && link->dhcp_lease) { + r = sd_dhcp_lease_get_captive_portal(link->dhcp_lease, &captive_portal); + if (r < 0 && r != -ENODATA) + return r; + } + + if (link->network->dhcp6_use_captive_portal && link->dhcp6_lease && !captive_portal) { + r = sd_dhcp6_lease_get_captive_portal(link->dhcp6_lease, &captive_portal); + if (r < 0 && r != -ENODATA) + return r; + } + + if (link->network->ipv6_accept_ra_use_captive_portal && !captive_portal) + captive_portal = link->ndisc_captive_portal; + + if (!captive_portal) { + *ret = NULL; + return 0; + } + + return json_build(ret, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_STRING("CaptivePortal", captive_portal))); +} + static int domain_build_json(int family, const char *domain, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **ret) { assert(IN_SET(family, AF_UNSPEC, AF_INET, AF_INET6)); assert(domain); @@ -1390,6 +1425,16 @@ int link_build_json(Link *link, JsonVariant **ret) { w = json_variant_unref(w); + r = captive_portal_build_json(link, &w); + if (r < 0) + return r; + + r = json_variant_merge(&v, w); + if (r < 0) + return r; + + w = json_variant_unref(w); + r = domains_build_json(link, /* is_route = */ false, &w); if (r < 0) return r;