summaryrefslogtreecommitdiffstats
path: root/src/network/networkd-json.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/network/networkd-json.c371
1 files changed, 168 insertions, 203 deletions
diff --git a/src/network/networkd-json.c b/src/network/networkd-json.c
index eed8d9f..fb9f492 100644
--- a/src/network/networkd-json.c
+++ b/src/network/networkd-json.c
@@ -2,7 +2,8 @@
#include <linux/nexthop.h>
-#include "dhcp-server-internal.h"
+#include "dhcp-lease-internal.h"
+#include "dhcp-server-lease-internal.h"
#include "dhcp6-internal.h"
#include "dhcp6-lease-internal.h"
#include "dns-domain.h"
@@ -16,6 +17,7 @@
#include "networkd-neighbor.h"
#include "networkd-network.h"
#include "networkd-nexthop.h"
+#include "networkd-ntp.h"
#include "networkd-route-util.h"
#include "networkd-route.h"
#include "networkd-routing-policy-rule.h"
@@ -24,12 +26,12 @@
#include "user-util.h"
#include "wifi-util.h"
-static int address_build_json(Address *address, JsonVariant **ret) {
+static int address_append_json(Address *address, JsonVariant **array) {
_cleanup_free_ char *scope = NULL, *flags = NULL, *state = NULL;
int r;
assert(address);
- assert(ret);
+ assert(array);
r = route_scope_to_string_alloc(address->scope, &scope);
if (r < 0)
@@ -43,7 +45,9 @@ static int address_build_json(Address *address, JsonVariant **ret) {
if (r < 0)
return r;
- return json_build(ret, JSON_BUILD_OBJECT(
+ return json_variant_append_arrayb(
+ array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_INTEGER("Family", address->family),
JSON_BUILD_PAIR_IN_ADDR("Address", &address->in_addr, address->family),
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("Peer", &address->in_addr_peer, address->family),
@@ -71,13 +75,7 @@ static int addresses_append_json(Set *addresses, JsonVariant **v) {
assert(v);
SET_FOREACH(address, addresses) {
- _cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
-
- r = address_build_json(address, &e);
- if (r < 0)
- return r;
-
- r = json_variant_append_array(&array, e);
+ r = address_append_json(address, &array);
if (r < 0)
return r;
}
@@ -85,18 +83,20 @@ static int addresses_append_json(Set *addresses, JsonVariant **v) {
return json_variant_set_field_non_null(v, "Addresses", array);
}
-static int neighbor_build_json(Neighbor *n, JsonVariant **ret) {
+static int neighbor_append_json(Neighbor *n, JsonVariant **array) {
_cleanup_free_ char *state = NULL;
int r;
assert(n);
- assert(ret);
+ assert(array);
r = network_config_state_to_string_alloc(n->state, &state);
if (r < 0)
return r;
- return json_build(ret, JSON_BUILD_OBJECT(
+ return json_variant_append_arrayb(
+ array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_INTEGER("Family", n->family),
JSON_BUILD_PAIR_IN_ADDR("Destination", &n->in_addr, n->family),
JSON_BUILD_PAIR_HW_ADDR("LinkLayerAddress", &n->ll_addr),
@@ -112,13 +112,7 @@ static int neighbors_append_json(Set *neighbors, JsonVariant **v) {
assert(v);
SET_FOREACH(neighbor, neighbors) {
- _cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
-
- r = neighbor_build_json(neighbor, &e);
- if (r < 0)
- return r;
-
- r = json_variant_append_array(&array, e);
+ r = neighbor_append_json(neighbor, &array);
if (r < 0)
return r;
}
@@ -148,13 +142,13 @@ static int nexthop_group_build_json(NextHop *nexthop, JsonVariant **ret) {
return 0;
}
-static int nexthop_build_json(NextHop *n, JsonVariant **ret) {
+static int nexthop_append_json(NextHop *n, JsonVariant **array) {
_cleanup_(json_variant_unrefp) JsonVariant *group = NULL;
_cleanup_free_ char *flags = NULL, *protocol = NULL, *state = NULL;
int r;
assert(n);
- assert(ret);
+ assert(array);
r = route_flags_to_string_alloc(n->flags, &flags);
if (r < 0)
@@ -172,7 +166,9 @@ static int nexthop_build_json(NextHop *n, JsonVariant **ret) {
if (r < 0)
return r;
- return json_build(ret, JSON_BUILD_OBJECT(
+ return json_variant_append_arrayb(
+ array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_UNSIGNED("ID", n->id),
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("Gateway", &n->gw, n->family),
JSON_BUILD_PAIR_UNSIGNED("Flags", n->flags),
@@ -185,21 +181,19 @@ static int nexthop_build_json(NextHop *n, JsonVariant **ret) {
JSON_BUILD_PAIR_STRING("ConfigState", state)));
}
-static int nexthops_append_json(Set *nexthops, JsonVariant **v) {
+static int nexthops_append_json(Manager *manager, int ifindex, JsonVariant **v) {
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
NextHop *nexthop;
int r;
+ assert(manager);
assert(v);
- SET_FOREACH(nexthop, nexthops) {
- _cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
-
- r = nexthop_build_json(nexthop, &e);
- if (r < 0)
- return r;
+ HASHMAP_FOREACH(nexthop, manager->nexthops_by_id) {
+ if (nexthop->ifindex != ifindex)
+ continue;
- r = json_variant_append_array(&array, e);
+ r = nexthop_append_json(nexthop, &array);
if (r < 0)
return r;
}
@@ -207,17 +201,12 @@ static int nexthops_append_json(Set *nexthops, JsonVariant **v) {
return json_variant_set_field_non_null(v, "NextHops", array);
}
-static int route_build_json(Route *route, JsonVariant **ret) {
+static int route_append_json(Route *route, JsonVariant **array) {
_cleanup_free_ char *scope = NULL, *protocol = NULL, *table = NULL, *flags = NULL, *state = NULL;
- Manager *manager;
int r;
assert(route);
- assert(ret);
-
- manager = route->link ? route->link->manager : route->manager;
-
- assert(manager);
+ assert(array);
r = route_scope_to_string_alloc(route->scope, &scope);
if (r < 0)
@@ -227,7 +216,7 @@ static int route_build_json(Route *route, JsonVariant **ret) {
if (r < 0)
return r;
- r = manager_get_route_table_to_string(manager, route->table, /* append_num = */ false, &table);
+ r = manager_get_route_table_to_string(route->manager, route->table, /* append_num = */ false, &table);
if (r < 0)
return r;
@@ -239,11 +228,13 @@ static int route_build_json(Route *route, JsonVariant **ret) {
if (r < 0)
return r;
- return json_build(ret, JSON_BUILD_OBJECT(
+ return json_variant_append_arrayb(
+ array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_INTEGER("Family", route->family),
JSON_BUILD_PAIR_IN_ADDR("Destination", &route->dst, route->family),
JSON_BUILD_PAIR_UNSIGNED("DestinationPrefixLength", route->dst_prefixlen),
- JSON_BUILD_PAIR_IN_ADDR_NON_NULL("Gateway", &route->gw, route->gw_family),
+ JSON_BUILD_PAIR_IN_ADDR_NON_NULL("Gateway", &route->nexthop.gw, route->nexthop.family),
JSON_BUILD_PAIR_CONDITION(route->src_prefixlen > 0,
"Source", JSON_BUILD_IN_ADDR(&route->src, route->family)),
JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("SourcePrefixLength", route->src_prefixlen),
@@ -257,7 +248,7 @@ static int route_build_json(Route *route, JsonVariant **ret) {
JSON_BUILD_PAIR_UNSIGNED("Priority", route->priority),
JSON_BUILD_PAIR_UNSIGNED("Table", route->table),
JSON_BUILD_PAIR_STRING("TableString", table),
- JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("MTU", route->mtu),
+ JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("MTU", route_metric_get(&route->metric, RTAX_MTU)),
JSON_BUILD_PAIR_UNSIGNED("Preference", route->pref),
JSON_BUILD_PAIR_UNSIGNED("Flags", route->flags),
JSON_BUILD_PAIR_STRING("FlagsString", strempty(flags)),
@@ -267,21 +258,19 @@ static int route_build_json(Route *route, JsonVariant **ret) {
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", &route->provider, route->family)));
}
-static int routes_append_json(Set *routes, JsonVariant **v) {
+static int routes_append_json(Manager *manager, int ifindex, JsonVariant **v) {
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
Route *route;
int r;
+ assert(manager);
assert(v);
- SET_FOREACH(route, routes) {
- _cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
+ SET_FOREACH(route, manager->routes) {
+ if (route->nexthop.ifindex != ifindex)
+ continue;
- r = route_build_json(route, &e);
- if (r < 0)
- return r;
-
- r = json_variant_append_array(&array, e);
+ r = route_append_json(route, &array);
if (r < 0)
return r;
}
@@ -289,13 +278,13 @@ static int routes_append_json(Set *routes, JsonVariant **v) {
return json_variant_set_field_non_null(v, "Routes", array);
}
-static int routing_policy_rule_build_json(RoutingPolicyRule *rule, JsonVariant **ret) {
+static int routing_policy_rule_append_json(RoutingPolicyRule *rule, JsonVariant **array) {
_cleanup_free_ char *table = NULL, *protocol = NULL, *state = NULL;
int r;
assert(rule);
assert(rule->manager);
- assert(ret);
+ assert(array);
r = manager_get_route_table_to_string(rule->manager, rule->table, /* append_num = */ false, &table);
if (r < 0 && r != -EINVAL)
@@ -309,7 +298,9 @@ static int routing_policy_rule_build_json(RoutingPolicyRule *rule, JsonVariant *
if (r < 0)
return r;
- return json_build(ret, JSON_BUILD_OBJECT(
+ return json_variant_append_arrayb(
+ array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_INTEGER("Family", rule->family),
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("FromPrefix", &rule->from, rule->family),
JSON_BUILD_PAIR_CONDITION(in_addr_is_set(rule->family, &rule->from),
@@ -354,13 +345,7 @@ static int routing_policy_rules_append_json(Set *rules, JsonVariant **v) {
assert(v);
SET_FOREACH(rule, rules) {
- _cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
-
- r = routing_policy_rule_build_json(rule, &e);
- if (r < 0)
- return r;
-
- r = json_variant_append_array(&array, e);
+ r = routing_policy_rule_append_json(rule, &array);
if (r < 0)
return r;
}
@@ -464,7 +449,7 @@ static int dns_append_json(Link *link, JsonVariant **v) {
return r;
}
- if (link->dhcp_lease && link->network->dhcp_use_dns) {
+ if (link->dhcp_lease && link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP4)) {
const struct in_addr *dns;
union in_addr_union s;
int n_dns;
@@ -485,7 +470,7 @@ static int dns_append_json(Link *link, JsonVariant **v) {
}
}
- if (link->dhcp6_lease && link->network->dhcp6_use_dns) {
+ if (link->dhcp6_lease && link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP6)) {
const struct in6_addr *dns;
union in_addr_union s;
int n_dns;
@@ -506,7 +491,7 @@ static int dns_append_json(Link *link, JsonVariant **v) {
}
}
- if (link->network->ipv6_accept_ra_use_dns) {
+ if (link_get_use_dns(link, NETWORK_CONFIG_SOURCE_NDISC)) {
NDiscRDNSS *a;
SET_FOREACH(a, link->ndisc_rdnss) {
@@ -525,40 +510,30 @@ static int dns_append_json(Link *link, JsonVariant **v) {
}
static int server_append_json_one_addr(int family, const union in_addr_union *a, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **array) {
- _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
- int r;
-
assert(IN_SET(family, AF_INET, AF_INET6));
assert(a);
assert(array);
- r = json_build(&v, JSON_BUILD_OBJECT(
+ return json_variant_append_arrayb(
+ array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_INTEGER("Family", family),
JSON_BUILD_PAIR_IN_ADDR("Address", a, family),
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)),
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", p, family)));
- if (r < 0)
- return r;
-
- return json_variant_append_array(array, v);
}
static int server_append_json_one_fqdn(int family, const char *fqdn, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **array) {
- _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
- int r;
-
assert(IN_SET(family, AF_UNSPEC, AF_INET, AF_INET6));
assert(fqdn);
assert(array);
- r = json_build(&v, JSON_BUILD_OBJECT(
+ return json_variant_append_arrayb(
+ array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_STRING("Server", fqdn),
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)),
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", p, family)));
- if (r < 0)
- return r;
-
- return json_variant_append_array(array, v);
}
static int server_append_json_one_string(const char *str, NetworkConfigSource s, JsonVariant **array) {
@@ -590,7 +565,7 @@ static int ntp_append_json(Link *link, JsonVariant **v) {
}
if (!link->ntp) {
- if (link->dhcp_lease && link->network->dhcp_use_ntp) {
+ if (link->dhcp_lease && link_get_use_ntp(link, NETWORK_CONFIG_SOURCE_DHCP4)) {
const struct in_addr *ntp;
union in_addr_union s;
int n_ntp;
@@ -611,7 +586,7 @@ static int ntp_append_json(Link *link, JsonVariant **v) {
}
}
- if (link->dhcp6_lease && link->network->dhcp6_use_ntp) {
+ if (link->dhcp6_lease && link_get_use_ntp(link, NETWORK_CONFIG_SOURCE_DHCP6)) {
const struct in6_addr *ntp_addr;
union in_addr_union s;
char **ntp_fqdn;
@@ -682,27 +657,22 @@ static int sip_append_json(Link *link, JsonVariant **v) {
}
static int domain_append_json(int family, const char *domain, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **array) {
- _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
- int r;
-
assert(IN_SET(family, AF_UNSPEC, AF_INET, AF_INET6));
assert(domain);
assert(array);
- r = json_build(&v, JSON_BUILD_OBJECT(
+ return json_variant_append_arrayb(
+ array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_STRING("Domain", domain),
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)),
JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", p, family)));
- if (r < 0)
- return r;
-
- return json_variant_append_array(array, v);
}
static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
_cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
OrderedSet *link_domains, *network_domains;
- DHCPUseDomains use_domains;
+ UseDomains use_domains;
union in_addr_union s;
char **domains;
const char *domain;
@@ -716,7 +686,7 @@ static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
link_domains = is_route ? link->route_domains : link->search_domains;
network_domains = is_route ? link->network->route_domains : link->network->search_domains;
- use_domains = is_route ? DHCP_USE_DOMAINS_ROUTE : DHCP_USE_DOMAINS_YES;
+ use_domains = is_route ? USE_DOMAINS_ROUTE : USE_DOMAINS_YES;
ORDERED_SET_FOREACH(domain, link_domains ?: network_domains) {
r = domain_append_json(AF_UNSPEC, domain,
@@ -728,7 +698,7 @@ static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
if (!link_domains) {
if (link->dhcp_lease &&
- link->network->dhcp_use_domains == use_domains) {
+ link_get_use_domains(link, NETWORK_CONFIG_SOURCE_DHCP4) == use_domains) {
r = sd_dhcp_lease_get_server_identifier(link->dhcp_lease, &s.in);
if (r < 0)
return r;
@@ -748,7 +718,7 @@ static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
}
if (link->dhcp6_lease &&
- link->network->dhcp6_use_domains == use_domains) {
+ link_get_use_domains(link, NETWORK_CONFIG_SOURCE_DHCP6) == use_domains) {
r = sd_dhcp6_lease_get_server_address(link->dhcp6_lease, &s.in6);
if (r < 0)
return r;
@@ -761,7 +731,7 @@ static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
}
}
- if (link->network->ipv6_accept_ra_use_domains == use_domains) {
+ if (link_get_use_domains(link, NETWORK_CONFIG_SOURCE_NDISC) == use_domains) {
NDiscDNSSL *a;
SET_FOREACH(a, link->ndisc_dnssl) {
@@ -778,19 +748,14 @@ static int domains_append_json(Link *link, bool is_route, JsonVariant **v) {
}
static int nta_append_json(const char *nta, NetworkConfigSource s, JsonVariant **array) {
- _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
- int r;
-
assert(nta);
assert(array);
- r = json_build(&v, JSON_BUILD_OBJECT(
+ return json_variant_append_arrayb(
+ array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_STRING("DNSSECNegativeTrustAnchor", nta),
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s))));
- if (r < 0)
- return r;
-
- return json_variant_append_array(array, v);
}
static int ntas_append_json(Link *link, JsonVariant **v) {
@@ -830,70 +795,54 @@ static int dns_misc_append_json(Link *link, JsonVariant **v) {
resolve_support = link->llmnr >= 0 ? link->llmnr : link->network->llmnr;
if (resolve_support >= 0) {
- _cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
-
source = link->llmnr >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC;
- r = json_build(&e, JSON_BUILD_OBJECT(
+ r = json_variant_append_arrayb(
+ &array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_STRING("LLMNR", resolve_support_to_string(resolve_support)),
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
if (r < 0)
return r;
-
- r = json_variant_append_array(&array, e);
- if (r < 0)
- return r;
}
resolve_support = link->mdns >= 0 ? link->mdns : link->network->mdns;
if (resolve_support >= 0) {
- _cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
-
source = link->mdns >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC;
- r = json_build(&e, JSON_BUILD_OBJECT(
+ r = json_variant_append_arrayb(
+ &array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_STRING("MDNS", resolve_support_to_string(resolve_support)),
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
if (r < 0)
return r;
-
- r = json_variant_append_array(&array, e);
- if (r < 0)
- return r;
}
t = link->dns_default_route >= 0 ? link->dns_default_route : link->network->dns_default_route;
if (t >= 0) {
- _cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
-
source = link->dns_default_route >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC;
- r = json_build(&e, JSON_BUILD_OBJECT(
+ r = json_variant_append_arrayb(
+ &array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_BOOLEAN("DNSDefaultRoute", t),
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
if (r < 0)
return r;
-
- r = json_variant_append_array(&array, e);
- if (r < 0)
- return r;
}
mode = link->dns_over_tls_mode >= 0 ? link->dns_over_tls_mode : link->network->dns_over_tls_mode;
if (mode >= 0) {
- _cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
-
source = link->dns_over_tls_mode >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC;
- r = json_build(&e, JSON_BUILD_OBJECT(
+ r = json_variant_append_arrayb(
+ &array,
+ JSON_BUILD_OBJECT(
JSON_BUILD_PAIR_STRING("DNSOverTLS", dns_over_tls_mode_to_string(mode)),
JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source))));
if (r < 0)
return r;
-
- r = json_variant_append_array(&array, e);
- if (r < 0)
- return r;
}
return json_variant_set_field_non_null(v, "DNSSettings", array);
@@ -921,7 +870,7 @@ static int pref64_append_json(Link *link, JsonVariant **v) {
assert(link);
assert(v);
- if (!link->network || !link->network->ipv6_accept_ra_use_pref64)
+ if (!link->network || !link->network->ndisc_use_pref64)
return 0;
SET_FOREACH(i, link->ndisc_pref64) {
@@ -942,71 +891,6 @@ static int pref64_append_json(Link *link, JsonVariant **v) {
return json_variant_set_field_non_null(v, "NDisc", w);
}
-static int dhcp_server_offered_leases_append_json(Link *link, JsonVariant **v) {
- _cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
- DHCPLease *lease;
- int r;
-
- assert(link);
- assert(v);
-
- if (!link->dhcp_server)
- return 0;
-
- HASHMAP_FOREACH(lease, link->dhcp_server->bound_leases_by_client_id) {
- struct in_addr address = { .s_addr = lease->address };
-
- r = json_variant_append_arrayb(
- &array,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_BYTE_ARRAY(
- "ClientId",
- lease->client_id.data,
- lease->client_id.length),
- JSON_BUILD_PAIR_IN4_ADDR_NON_NULL("Address", &address),
- JSON_BUILD_PAIR_STRING_NON_EMPTY("Hostname", lease->hostname),
- JSON_BUILD_PAIR_FINITE_USEC(
- "ExpirationUSec", lease->expiration)));
- if (r < 0)
- return r;
- }
-
- return json_variant_set_field_non_null(v, "Leases", array);
-}
-
-static int dhcp_server_static_leases_append_json(Link *link, JsonVariant **v) {
- _cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
- DHCPLease *lease;
- int r;
-
- assert(link);
- assert(v);
-
- if (!link->dhcp_server)
- return 0;
-
- HASHMAP_FOREACH(lease, link->dhcp_server->static_leases_by_client_id) {
- _cleanup_(json_variant_unrefp) JsonVariant *e = NULL;
- struct in_addr address = { .s_addr = lease->address };
-
- r = json_build(&e,
- JSON_BUILD_OBJECT(
- JSON_BUILD_PAIR_BYTE_ARRAY(
- "ClientId",
- lease->client_id.data,
- lease->client_id.length),
- JSON_BUILD_PAIR_IN4_ADDR_NON_NULL("Address", &address)));
- if (r < 0)
- return r;
-
- r = json_variant_append_array(&array, e);
- if (r < 0)
- return r;
- }
-
- return json_variant_set_field_non_null(v, "StaticLeases", array);
-}
-
static int dhcp_server_append_json(Link *link, JsonVariant **v) {
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
int r;
@@ -1024,11 +908,11 @@ static int dhcp_server_append_json(Link *link, JsonVariant **v) {
if (r < 0)
return r;
- r = dhcp_server_offered_leases_append_json(link, &w);
+ r = dhcp_server_bound_leases_append_json(link->dhcp_server, &w);
if (r < 0)
return r;
- r = dhcp_server_static_leases_append_json(link, &w);
+ r = dhcp_server_static_leases_append_json(link->dhcp_server, &w);
if (r < 0)
return r;
@@ -1132,6 +1016,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(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;
@@ -1154,6 +1061,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);
}
@@ -1226,6 +1137,52 @@ static int dhcp_client_pd_append_json(Link *link, JsonVariant **v) {
return json_variant_set_field_non_null(v, "6rdPrefix", array);
}
+static int dhcp_client_private_options_append_json(Link *link, JsonVariant **v) {
+ _cleanup_(json_variant_unrefp) JsonVariant *array = NULL;
+ int r;
+
+ assert(link);
+ assert(v);
+
+ if (!link->dhcp_lease)
+ return 0;
+
+ LIST_FOREACH(options, option, link->dhcp_lease->private_options) {
+
+ r = json_variant_append_arrayb(
+ &array,
+ JSON_BUILD_OBJECT(
+ JSON_BUILD_PAIR_UNSIGNED("Option", option->tag),
+ JSON_BUILD_PAIR_HEX("PrivateOptionData", option->data, option->length)));
+ if (r < 0)
+ return 0;
+ }
+ return json_variant_set_field_non_null(v, "PrivateOptions", array);
+}
+
+static int dhcp_client_id_append_json(Link *link, JsonVariant **v) {
+ const sd_dhcp_client_id *client_id;
+ const void *data;
+ size_t l;
+ int r;
+
+ assert(link);
+ assert(v);
+
+ if (!link->dhcp_client)
+ return 0;
+
+ r = sd_dhcp_client_get_client_id(link->dhcp_client, &client_id);
+ if (r < 0)
+ return 0;
+
+ r = sd_dhcp_client_id_get_raw(client_id, &data, &l);
+ if (r < 0)
+ return 0;
+
+ return json_variant_merge_objectb(v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_BYTE_ARRAY("ClientIdentifier", data, l)));
+}
+
static int dhcp_client_append_json(Link *link, JsonVariant **v) {
_cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
int r;
@@ -1244,6 +1201,14 @@ static int dhcp_client_append_json(Link *link, JsonVariant **v) {
if (r < 0)
return r;
+ r = dhcp_client_private_options_append_json(link, &w);
+ if (r < 0)
+ return r;
+
+ r = dhcp_client_id_append_json(link, &w);
+ if (r < 0)
+ return r;
+
return json_variant_set_field_non_null(v, "DHCPv4Client", w);
}
@@ -1354,11 +1319,11 @@ int link_build_json(Link *link, JsonVariant **ret) {
if (r < 0)
return r;
- r = nexthops_append_json(link->nexthops, &v);
+ r = nexthops_append_json(link->manager, link->ifindex, &v);
if (r < 0)
return r;
- r = routes_append_json(link->routes, &v);
+ r = routes_append_json(link->manager, link->ifindex, &v);
if (r < 0)
return r;
@@ -1417,11 +1382,11 @@ int manager_build_json(Manager *manager, JsonVariant **ret) {
if (r < 0)
return r;
- r = nexthops_append_json(manager->nexthops, &v);
+ r = nexthops_append_json(manager, /* ifindex = */ 0, &v);
if (r < 0)
return r;
- r = routes_append_json(manager->routes, &v);
+ r = routes_append_json(manager, /* ifindex = */ 0, &v);
if (r < 0)
return r;