networkd: include captive portal information in link json description
authorRonan Pigott <ronan@rjp.ie>
Thu, 29 Jun 2023 23:36:50 +0000 (16:36 -0700)
committerRonan Pigott <ronan@rjp.ie>
Sun, 2 Jul 2023 08:13:43 +0000 (01:13 -0700)
src/network/networkd-json.c

index 15cd1a93f68c82720d5851f12dc6cd9286cf1e4d..31ccb9679a5e0a4d7684eae67ca43ae4e0697ebd 100644 (file)
@@ -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;