diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkctl.c | 124 | ||||
-rw-r--r-- | src/network/networkctl.h | 2 | ||||
-rw-r--r-- | src/network/networkd-json.c | 496 | ||||
-rw-r--r-- | src/network/networkd-json.h | 6 | ||||
-rw-r--r-- | src/network/networkd-link-bus.c | 4 | ||||
-rw-r--r-- | src/network/networkd-manager-bus.c | 4 | ||||
-rw-r--r-- | src/network/networkd-manager-varlink.c | 75 |
7 files changed, 358 insertions, 353 deletions
diff --git a/src/network/networkctl.c b/src/network/networkctl.c index a447c39a64..1384a83216 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -16,6 +16,7 @@ #include "sd-device.h" #include "sd-dhcp-client.h" #include "sd-hwdb.h" +#include "sd-json.h" #include "sd-netlink.h" #include "sd-network.h" @@ -39,6 +40,7 @@ #include "hwdb-util.h" #include "ipvlan-util.h" #include "journal-internal.h" +#include "json-util.h" #include "local-addresses.h" #include "locale-util.h" #include "logs-show.h" @@ -90,13 +92,13 @@ bool arg_full = false; bool arg_runtime = false; unsigned arg_lines = 10; char *arg_drop_in = NULL; -JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF; +sd_json_format_flags_t arg_json_format_flags = SD_JSON_FORMAT_OFF; STATIC_DESTRUCTOR_REGISTER(arg_drop_in, freep); static int varlink_connect_networkd(Varlink **ret_varlink) { _cleanup_(varlink_flush_close_unrefp) Varlink *vl = NULL; - JsonVariant *reply; + sd_json_variant *reply; uint64_t id; int r; @@ -114,12 +116,12 @@ static int varlink_connect_networkd(Varlink **ret_varlink) { if (r < 0) return r; - static const JsonDispatch dispatch_table[] = { - { "NamespaceId", JSON_VARIANT_UNSIGNED, json_dispatch_uint64, 0, JSON_MANDATORY }, + static const sd_json_dispatch_field dispatch_table[] = { + { "NamespaceId", SD_JSON_VARIANT_UNSIGNED, sd_json_dispatch_uint64, 0, SD_JSON_MANDATORY }, {}, }; - r = json_dispatch(reply, dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &id); + r = sd_json_dispatch(reply, dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &id); if (r < 0) return r; @@ -181,7 +183,7 @@ int acquire_bus(sd_bus **ret) { return 0; } -static int get_description(sd_bus *bus, JsonVariant **ret) { +static int get_description(sd_bus *bus, sd_json_variant **ret) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; const char *text; @@ -198,7 +200,7 @@ static int get_description(sd_bus *bus, JsonVariant **ret) { if (r < 0) return bus_log_parse_error(r); - r = json_parse(text, 0, ret, NULL, NULL); + r = sd_json_parse(text, 0, ret, NULL, NULL); if (r < 0) return log_error_errno(r, "Failed to parse JSON: %m"); @@ -206,7 +208,7 @@ static int get_description(sd_bus *bus, JsonVariant **ret) { } static int dump_manager_description(sd_bus *bus) { - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; int r; assert(bus); @@ -215,14 +217,14 @@ static int dump_manager_description(sd_bus *bus) { if (r < 0) return r; - json_variant_dump(v, arg_json_format_flags, NULL, NULL); + sd_json_variant_dump(v, arg_json_format_flags, NULL, NULL); return 0; } static int dump_link_description(sd_bus *bus, char * const *patterns) { - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; _cleanup_free_ bool *matched_patterns = NULL; - JsonVariant *i; + sd_json_variant *i; size_t c = 0; int r; @@ -237,23 +239,23 @@ static int dump_link_description(sd_bus *bus, char * const *patterns) { if (!matched_patterns) return log_oom(); - JSON_VARIANT_ARRAY_FOREACH(i, json_variant_by_key(v, "Interfaces")) { + JSON_VARIANT_ARRAY_FOREACH(i, sd_json_variant_by_key(v, "Interfaces")) { char ifindex_str[DECIMAL_STR_MAX(int64_t)]; const char *name; int64_t index; size_t pos; - name = json_variant_string(json_variant_by_key(i, "Name")); - index = json_variant_integer(json_variant_by_key(i, "Index")); + name = sd_json_variant_string(sd_json_variant_by_key(i, "Name")); + index = sd_json_variant_integer(sd_json_variant_by_key(i, "Index")); xsprintf(ifindex_str, "%" PRIi64, index); if (!strv_fnmatch_full(patterns, ifindex_str, 0, &pos) && !strv_fnmatch_full(patterns, name, 0, &pos)) { bool match = false; - JsonVariant *a; + sd_json_variant *a; - JSON_VARIANT_ARRAY_FOREACH(a, json_variant_by_key(i, "AlternativeNames")) - if (strv_fnmatch_full(patterns, json_variant_string(a), 0, &pos)) { + JSON_VARIANT_ARRAY_FOREACH(a, sd_json_variant_by_key(i, "AlternativeNames")) + if (strv_fnmatch_full(patterns, sd_json_variant_string(a), 0, &pos)) { match = true; break; } @@ -263,7 +265,7 @@ static int dump_link_description(sd_bus *bus, char * const *patterns) { } matched_patterns[pos] = true; - json_variant_dump(i, arg_json_format_flags, NULL, NULL); + sd_json_variant_dump(i, arg_json_format_flags, NULL, NULL); c++; } @@ -921,7 +923,7 @@ static int list_links(int argc, char *argv[], void *userdata) { if (r < 0) return r; - if (arg_json_format_flags != JSON_FORMAT_OFF) { + if (arg_json_format_flags != SD_JSON_FORMAT_OFF) { if (arg_all || argc <= 1) return dump_manager_description(bus); else @@ -1322,7 +1324,7 @@ typedef struct InterfaceInfo { int ifindex; const char *ifname; char **altnames; - JsonVariant *v; + sd_json_variant *v; } InterfaceInfo; static void interface_info_done(InterfaceInfo *p) { @@ -1330,14 +1332,14 @@ static void interface_info_done(InterfaceInfo *p) { return; strv_free(p->altnames); - json_variant_unref(p->v); + sd_json_variant_unref(p->v); } -static const JsonDispatch interface_info_dispatch_table[] = { - { "InterfaceIndex", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(InterfaceInfo, ifindex), JSON_MANDATORY }, - { "InterfaceName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(InterfaceInfo, ifname), JSON_MANDATORY }, - { "InterfaceAlternativeNames", JSON_VARIANT_ARRAY, json_dispatch_strv, offsetof(InterfaceInfo, altnames), 0 }, - { "Neighbors", JSON_VARIANT_ARRAY, json_dispatch_variant, offsetof(InterfaceInfo, v), 0 }, +static const sd_json_dispatch_field interface_info_dispatch_table[] = { + { "InterfaceIndex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(InterfaceInfo, ifindex), SD_JSON_MANDATORY }, + { "InterfaceName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(InterfaceInfo, ifname), SD_JSON_MANDATORY }, + { "InterfaceAlternativeNames", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_strv, offsetof(InterfaceInfo, altnames), 0 }, + { "Neighbors", SD_JSON_VARIANT_ARRAY, sd_json_dispatch_variant, offsetof(InterfaceInfo, v), 0 }, {}, }; @@ -1350,19 +1352,19 @@ typedef struct LLDPNeighborInfo { uint16_t capabilities; } LLDPNeighborInfo; -static const JsonDispatch lldp_neighbor_dispatch_table[] = { - { "ChassisID", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LLDPNeighborInfo, chassis_id), 0 }, - { "PortID", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LLDPNeighborInfo, port_id), 0 }, - { "PortDescription", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LLDPNeighborInfo, port_description), 0 }, - { "SystemName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LLDPNeighborInfo, system_name), 0 }, - { "SystemDescription", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(LLDPNeighborInfo, system_description), 0 }, - { "EnabledCapabilities", _JSON_VARIANT_TYPE_INVALID, json_dispatch_uint16, offsetof(LLDPNeighborInfo, capabilities), 0 }, +static const sd_json_dispatch_field lldp_neighbor_dispatch_table[] = { + { "ChassisID", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LLDPNeighborInfo, chassis_id), 0 }, + { "PortID", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LLDPNeighborInfo, port_id), 0 }, + { "PortDescription", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LLDPNeighborInfo, port_description), 0 }, + { "SystemName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LLDPNeighborInfo, system_name), 0 }, + { "SystemDescription", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(LLDPNeighborInfo, system_description), 0 }, + { "EnabledCapabilities", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_uint16, offsetof(LLDPNeighborInfo, capabilities), 0 }, {}, }; static int dump_lldp_neighbors(Varlink *vl, Table *table, int ifindex) { _cleanup_strv_free_ char **buf = NULL; - JsonVariant *reply; + sd_json_variant *reply; int r; assert(vl); @@ -1370,26 +1372,26 @@ static int dump_lldp_neighbors(Varlink *vl, Table *table, int ifindex) { assert(ifindex > 0); r = varlink_callb_and_log(vl, "io.systemd.Network.GetLLDPNeighbors", &reply, - JSON_BUILD_OBJECT(JSON_BUILD_PAIR_INTEGER("InterfaceIndex", ifindex))); + SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_INTEGER("InterfaceIndex", ifindex))); if (r < 0) return r; - JsonVariant *i; - JSON_VARIANT_ARRAY_FOREACH(i, json_variant_by_key(reply, "Neighbors")) { + sd_json_variant *i; + JSON_VARIANT_ARRAY_FOREACH(i, sd_json_variant_by_key(reply, "Neighbors")) { _cleanup_(interface_info_done) InterfaceInfo info = {}; - r = json_dispatch(i, interface_info_dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &info); + r = sd_json_dispatch(i, interface_info_dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &info); if (r < 0) return r; if (info.ifindex != ifindex) continue; - JsonVariant *neighbor; + sd_json_variant *neighbor; JSON_VARIANT_ARRAY_FOREACH(neighbor, info.v) { LLDPNeighborInfo neighbor_info = {}; - r = json_dispatch(neighbor, lldp_neighbor_dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &neighbor_info); + r = sd_json_dispatch(neighbor, lldp_neighbor_dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &neighbor_info); if (r < 0) return r; @@ -2431,7 +2433,7 @@ static int link_status(int argc, char *argv[], void *userdata) { if (r < 0) return r; - if (arg_json_format_flags != JSON_FORMAT_OFF) { + if (arg_json_format_flags != SD_JSON_FORMAT_OFF) { if (arg_all || argc <= 1) return dump_manager_description(bus); else @@ -2547,47 +2549,47 @@ static bool interface_match_pattern(const InterfaceInfo *info, char * const *pat return false; } -static int dump_lldp_neighbors_json(JsonVariant *reply, char * const *patterns) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL, *v = NULL; +static int dump_lldp_neighbors_json(sd_json_variant *reply, char * const *patterns) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL, *v = NULL; int r; assert(reply); if (strv_isempty(patterns)) - return json_variant_dump(reply, arg_json_format_flags, NULL, NULL); + return sd_json_variant_dump(reply, arg_json_format_flags, NULL, NULL); /* Filter and dump the result. */ - JsonVariant *i; - JSON_VARIANT_ARRAY_FOREACH(i, json_variant_by_key(reply, "Neighbors")) { + sd_json_variant *i; + JSON_VARIANT_ARRAY_FOREACH(i, sd_json_variant_by_key(reply, "Neighbors")) { _cleanup_(interface_info_done) InterfaceInfo info = {}; - r = json_dispatch(i, interface_info_dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &info); + r = sd_json_dispatch(i, interface_info_dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &info); if (r < 0) return r; if (!interface_match_pattern(&info, patterns)) continue; - r = json_variant_append_array(&array, i); + r = sd_json_variant_append_array(&array, i); if (r < 0) return log_error_errno(r, "Failed to append json variant to array: %m"); } - r = json_build(&v, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_CONDITION(json_variant_is_blank_array(array), "Neighbors", JSON_BUILD_EMPTY_ARRAY), - JSON_BUILD_PAIR_CONDITION(!json_variant_is_blank_array(array), "Neighbors", JSON_BUILD_VARIANT(array)))); + r = sd_json_build(&v, + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_CONDITION(sd_json_variant_is_blank_array(array), "Neighbors", SD_JSON_BUILD_EMPTY_ARRAY), + SD_JSON_BUILD_PAIR_CONDITION(!sd_json_variant_is_blank_array(array), "Neighbors", SD_JSON_BUILD_VARIANT(array)))); if (r < 0) return log_error_errno(r, "Failed to build json varinat: %m"); - return json_variant_dump(v, arg_json_format_flags, NULL, NULL); + return sd_json_variant_dump(v, arg_json_format_flags, NULL, NULL); } static int link_lldp_status(int argc, char *argv[], void *userdata) { _cleanup_(varlink_flush_close_unrefp) Varlink *vl = NULL; _cleanup_(table_unrefp) Table *table = NULL; - JsonVariant *reply; + sd_json_variant *reply; uint64_t all = 0; TableCell *cell; size_t m = 0; @@ -2601,7 +2603,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) { if (r < 0) return r; - if (arg_json_format_flags != JSON_FORMAT_OFF) + if (arg_json_format_flags != SD_JSON_FORMAT_OFF) return dump_lldp_neighbors_json(reply, strv_skip(argv, 1)); pager_open(arg_pager_flags); @@ -2629,22 +2631,22 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) { assert_se(cell = table_get_cell(table, 0, 7)); table_set_minimum_width(table, cell, 11); - JsonVariant *i; - JSON_VARIANT_ARRAY_FOREACH(i, json_variant_by_key(reply, "Neighbors")) { + sd_json_variant *i; + JSON_VARIANT_ARRAY_FOREACH(i, sd_json_variant_by_key(reply, "Neighbors")) { _cleanup_(interface_info_done) InterfaceInfo info = {}; - r = json_dispatch(i, interface_info_dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &info); + r = sd_json_dispatch(i, interface_info_dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &info); if (r < 0) return r; if (!interface_match_pattern(&info, strv_skip(argv, 1))) continue; - JsonVariant *neighbor; + sd_json_variant *neighbor; JSON_VARIANT_ARRAY_FOREACH(neighbor, info.v) { LLDPNeighborInfo neighbor_info = {}; - r = json_dispatch(neighbor, lldp_neighbor_dispatch_table, JSON_LOG|JSON_ALLOW_EXTENSIONS, &neighbor_info); + r = sd_json_dispatch(neighbor, lldp_neighbor_dispatch_table, SD_JSON_LOG|SD_JSON_ALLOW_EXTENSIONS, &neighbor_info); if (r < 0) return r; @@ -2954,7 +2956,7 @@ static int verb_persistent_storage(int argc, char *argv[], void *userdata) { } return varlink_callb_and_log(vl, "io.systemd.Network.SetPersistentStorage", /* reply = */ NULL, - JSON_BUILD_OBJECT(JSON_BUILD_PAIR_BOOLEAN("Ready", ready))); + SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_BOOLEAN("Ready", ready))); } static int help(void) { diff --git a/src/network/networkctl.h b/src/network/networkctl.h index 46b44f7975..1765a8f83d 100644 --- a/src/network/networkctl.h +++ b/src/network/networkctl.h @@ -17,7 +17,7 @@ extern bool arg_full; extern bool arg_runtime; extern unsigned arg_lines; extern char *arg_drop_in; -extern JsonFormatFlags arg_json_format_flags; +extern sd_json_format_flags_t arg_json_format_flags; bool networkd_is_running(void); int acquire_bus(sd_bus **ret); diff --git a/src/network/networkd-json.c b/src/network/networkd-json.c index fb9f492be4..2fddd6796c 100644 --- a/src/network/networkd-json.c +++ b/src/network/networkd-json.c @@ -8,6 +8,7 @@ #include "dhcp6-lease-internal.h" #include "dns-domain.h" #include "ip-protocol-list.h" +#include "json-util.h" #include "netif-util.h" #include "networkd-address.h" #include "networkd-dhcp-common.h" @@ -22,11 +23,12 @@ #include "networkd-route.h" #include "networkd-routing-policy-rule.h" #include "sort-util.h" +#include "strv.h" #include "udev-util.h" #include "user-util.h" #include "wifi-util.h" -static int address_append_json(Address *address, JsonVariant **array) { +static int address_append_json(Address *address, sd_json_variant **array) { _cleanup_free_ char *scope = NULL, *flags = NULL, *state = NULL; int r; @@ -45,30 +47,30 @@ static int address_append_json(Address *address, JsonVariant **array) { if (r < 0) return r; - return json_variant_append_arrayb( + return sd_json_variant_append_arrayb( array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_INTEGER("Family", address->family), + SD_JSON_BUILD_OBJECT( + SD_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), JSON_BUILD_PAIR_IN4_ADDR_NON_NULL("Broadcast", &address->broadcast), - JSON_BUILD_PAIR_UNSIGNED("PrefixLength", address->prefixlen), - JSON_BUILD_PAIR_UNSIGNED("Scope", address->scope), - JSON_BUILD_PAIR_STRING("ScopeString", scope), - JSON_BUILD_PAIR_UNSIGNED("Flags", address->flags), - JSON_BUILD_PAIR_STRING("FlagsString", flags), + SD_JSON_BUILD_PAIR_UNSIGNED("PrefixLength", address->prefixlen), + SD_JSON_BUILD_PAIR_UNSIGNED("Scope", address->scope), + SD_JSON_BUILD_PAIR_STRING("ScopeString", scope), + SD_JSON_BUILD_PAIR_UNSIGNED("Flags", address->flags), + SD_JSON_BUILD_PAIR_STRING("FlagsString", flags), JSON_BUILD_PAIR_STRING_NON_EMPTY("Label", address->label), JSON_BUILD_PAIR_FINITE_USEC("PreferredLifetimeUSec", address->lifetime_preferred_usec), JSON_BUILD_PAIR_FINITE_USEC("PreferredLifetimeUsec", address->lifetime_preferred_usec), /* for backward compat */ JSON_BUILD_PAIR_FINITE_USEC("ValidLifetimeUSec", address->lifetime_valid_usec), JSON_BUILD_PAIR_FINITE_USEC("ValidLifetimeUsec", address->lifetime_valid_usec), /* for backward compat */ - JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(address->source)), - JSON_BUILD_PAIR_STRING("ConfigState", state), + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(address->source)), + SD_JSON_BUILD_PAIR_STRING("ConfigState", state), JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", &address->provider, address->family))); } -static int addresses_append_json(Set *addresses, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int addresses_append_json(Set *addresses, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; Address *address; int r; @@ -83,7 +85,7 @@ static int addresses_append_json(Set *addresses, JsonVariant **v) { return json_variant_set_field_non_null(v, "Addresses", array); } -static int neighbor_append_json(Neighbor *n, JsonVariant **array) { +static int neighbor_append_json(Neighbor *n, sd_json_variant **array) { _cleanup_free_ char *state = NULL; int r; @@ -94,18 +96,18 @@ static int neighbor_append_json(Neighbor *n, JsonVariant **array) { if (r < 0) return r; - return json_variant_append_arrayb( + return sd_json_variant_append_arrayb( array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_INTEGER("Family", n->family), + SD_JSON_BUILD_OBJECT( + SD_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), - JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(n->source)), - JSON_BUILD_PAIR_STRING("ConfigState", state))); + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(n->source)), + SD_JSON_BUILD_PAIR_STRING("ConfigState", state))); } -static int neighbors_append_json(Set *neighbors, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int neighbors_append_json(Set *neighbors, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; Neighbor *neighbor; int r; @@ -120,8 +122,8 @@ static int neighbors_append_json(Set *neighbors, JsonVariant **v) { return json_variant_set_field_non_null(v, "Neighbors", array); } -static int nexthop_group_build_json(NextHop *nexthop, JsonVariant **ret) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int nexthop_group_build_json(NextHop *nexthop, sd_json_variant **ret) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; struct nexthop_grp *g; int r; @@ -129,11 +131,11 @@ static int nexthop_group_build_json(NextHop *nexthop, JsonVariant **ret) { assert(ret); HASHMAP_FOREACH(g, nexthop->group) { - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( &array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_UNSIGNED("ID", g->id), - JSON_BUILD_PAIR_UNSIGNED("Weight", g->weight+1))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_UNSIGNED("ID", g->id), + SD_JSON_BUILD_PAIR_UNSIGNED("Weight", g->weight+1))); if (r < 0) return r; } @@ -142,8 +144,8 @@ static int nexthop_group_build_json(NextHop *nexthop, JsonVariant **ret) { return 0; } -static int nexthop_append_json(NextHop *n, JsonVariant **array) { - _cleanup_(json_variant_unrefp) JsonVariant *group = NULL; +static int nexthop_append_json(NextHop *n, sd_json_variant **array) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *group = NULL; _cleanup_free_ char *flags = NULL, *protocol = NULL, *state = NULL; int r; @@ -166,23 +168,23 @@ static int nexthop_append_json(NextHop *n, JsonVariant **array) { if (r < 0) return r; - return json_variant_append_arrayb( + return sd_json_variant_append_arrayb( array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_UNSIGNED("ID", n->id), + SD_JSON_BUILD_OBJECT( + SD_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), - JSON_BUILD_PAIR_STRING("FlagsString", strempty(flags)), - JSON_BUILD_PAIR_UNSIGNED("Protocol", n->protocol), - JSON_BUILD_PAIR_STRING("ProtocolString", protocol), - JSON_BUILD_PAIR_BOOLEAN("Blackhole", n->blackhole), + SD_JSON_BUILD_PAIR_UNSIGNED("Flags", n->flags), + SD_JSON_BUILD_PAIR_STRING("FlagsString", strempty(flags)), + SD_JSON_BUILD_PAIR_UNSIGNED("Protocol", n->protocol), + SD_JSON_BUILD_PAIR_STRING("ProtocolString", protocol), + SD_JSON_BUILD_PAIR_BOOLEAN("Blackhole", n->blackhole), JSON_BUILD_PAIR_VARIANT_NON_NULL("Group", group), - JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(n->source)), - JSON_BUILD_PAIR_STRING("ConfigState", state))); + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(n->source)), + SD_JSON_BUILD_PAIR_STRING("ConfigState", state))); } -static int nexthops_append_json(Manager *manager, int ifindex, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int nexthops_append_json(Manager *manager, int ifindex, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; NextHop *nexthop; int r; @@ -201,7 +203,7 @@ static int nexthops_append_json(Manager *manager, int ifindex, JsonVariant **v) return json_variant_set_field_non_null(v, "NextHops", array); } -static int route_append_json(Route *route, JsonVariant **array) { +static int route_append_json(Route *route, sd_json_variant **array) { _cleanup_free_ char *scope = NULL, *protocol = NULL, *table = NULL, *flags = NULL, *state = NULL; int r; @@ -228,38 +230,38 @@ static int route_append_json(Route *route, JsonVariant **array) { if (r < 0) return r; - return json_variant_append_arrayb( + return sd_json_variant_append_arrayb( array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_INTEGER("Family", route->family), + SD_JSON_BUILD_OBJECT( + SD_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), + SD_JSON_BUILD_PAIR_UNSIGNED("DestinationPrefixLength", route->dst_prefixlen), JSON_BUILD_PAIR_IN_ADDR_NON_NULL("Gateway", &route->nexthop.gw, route->nexthop.family), - JSON_BUILD_PAIR_CONDITION(route->src_prefixlen > 0, + SD_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), JSON_BUILD_PAIR_IN_ADDR_NON_NULL("PreferredSource", &route->prefsrc, route->family), - JSON_BUILD_PAIR_UNSIGNED("Scope", route->scope), - JSON_BUILD_PAIR_STRING("ScopeString", scope), - JSON_BUILD_PAIR_UNSIGNED("Protocol", route->protocol), - JSON_BUILD_PAIR_STRING("ProtocolString", protocol), - JSON_BUILD_PAIR_UNSIGNED("Type", route->type), - JSON_BUILD_PAIR_STRING("TypeString", route_type_to_string(route->type)), - JSON_BUILD_PAIR_UNSIGNED("Priority", route->priority), - JSON_BUILD_PAIR_UNSIGNED("Table", route->table), - JSON_BUILD_PAIR_STRING("TableString", table), + SD_JSON_BUILD_PAIR_UNSIGNED("Scope", route->scope), + SD_JSON_BUILD_PAIR_STRING("ScopeString", scope), + SD_JSON_BUILD_PAIR_UNSIGNED("Protocol", route->protocol), + SD_JSON_BUILD_PAIR_STRING("ProtocolString", protocol), + SD_JSON_BUILD_PAIR_UNSIGNED("Type", route->type), + SD_JSON_BUILD_PAIR_STRING("TypeString", route_type_to_string(route->type)), + SD_JSON_BUILD_PAIR_UNSIGNED("Priority", route->priority), + SD_JSON_BUILD_PAIR_UNSIGNED("Table", route->table), + SD_JSON_BUILD_PAIR_STRING("TableString", table), 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)), + SD_JSON_BUILD_PAIR_UNSIGNED("Preference", route->pref), + SD_JSON_BUILD_PAIR_UNSIGNED("Flags", route->flags), + SD_JSON_BUILD_PAIR_STRING("FlagsString", strempty(flags)), JSON_BUILD_PAIR_FINITE_USEC("LifetimeUSec", route->lifetime_usec), - JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(route->source)), - JSON_BUILD_PAIR_STRING("ConfigState", state), + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(route->source)), + SD_JSON_BUILD_PAIR_STRING("ConfigState", state), JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", &route->provider, route->family))); } -static int routes_append_json(Manager *manager, int ifindex, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int routes_append_json(Manager *manager, int ifindex, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; Route *route; int r; @@ -278,7 +280,7 @@ static int routes_append_json(Manager *manager, int ifindex, JsonVariant **v) { return json_variant_set_field_non_null(v, "Routes", array); } -static int routing_policy_rule_append_json(RoutingPolicyRule *rule, JsonVariant **array) { +static int routing_policy_rule_append_json(RoutingPolicyRule *rule, sd_json_variant **array) { _cleanup_free_ char *table = NULL, *protocol = NULL, *state = NULL; int r; @@ -298,47 +300,47 @@ static int routing_policy_rule_append_json(RoutingPolicyRule *rule, JsonVariant if (r < 0) return r; - return json_variant_append_arrayb( + return sd_json_variant_append_arrayb( array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_INTEGER("Family", rule->family), + SD_JSON_BUILD_OBJECT( + SD_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), - "FromPrefixLength", JSON_BUILD_UNSIGNED(rule->from_prefixlen)), + SD_JSON_BUILD_PAIR_CONDITION(in_addr_is_set(rule->family, &rule->from), + "FromPrefixLength", SD_JSON_BUILD_UNSIGNED(rule->from_prefixlen)), JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ToPrefix", &rule->to, rule->family), - JSON_BUILD_PAIR_CONDITION(in_addr_is_set(rule->family, &rule->to), - "ToPrefixLength", JSON_BUILD_UNSIGNED(rule->to_prefixlen)), - JSON_BUILD_PAIR_UNSIGNED("Protocol", rule->protocol), - JSON_BUILD_PAIR_STRING("ProtocolString", protocol), - JSON_BUILD_PAIR_UNSIGNED("TOS", rule->tos), - JSON_BUILD_PAIR_UNSIGNED("Type", rule->type), - JSON_BUILD_PAIR_STRING("TypeString", fr_act_type_full_to_string(rule->type)), - JSON_BUILD_PAIR_UNSIGNED("IPProtocol", rule->ipproto), - JSON_BUILD_PAIR_STRING("IPProtocolString", ip_protocol_to_name(rule->ipproto)), - JSON_BUILD_PAIR_UNSIGNED("Priority", rule->priority), - JSON_BUILD_PAIR_UNSIGNED("FirewallMark", rule->fwmark), - JSON_BUILD_PAIR_UNSIGNED("FirewallMask", rule->fwmask), + SD_JSON_BUILD_PAIR_CONDITION(in_addr_is_set(rule->family, &rule->to), + "ToPrefixLength", SD_JSON_BUILD_UNSIGNED(rule->to_prefixlen)), + SD_JSON_BUILD_PAIR_UNSIGNED("Protocol", rule->protocol), + SD_JSON_BUILD_PAIR_STRING("ProtocolString", protocol), + SD_JSON_BUILD_PAIR_UNSIGNED("TOS", rule->tos), + SD_JSON_BUILD_PAIR_UNSIGNED("Type", rule->type), + SD_JSON_BUILD_PAIR_STRING("TypeString", fr_act_type_full_to_string(rule->type)), + SD_JSON_BUILD_PAIR_UNSIGNED("IPProtocol", rule->ipproto), + SD_JSON_BUILD_PAIR_STRING("IPProtocolString", ip_protocol_to_name(rule->ipproto)), + SD_JSON_BUILD_PAIR_UNSIGNED("Priority", rule->priority), + SD_JSON_BUILD_PAIR_UNSIGNED("FirewallMark", rule->fwmark), + SD_JSON_BUILD_PAIR_UNSIGNED("FirewallMask", rule->fwmask), JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("Table", rule->table), JSON_BUILD_PAIR_STRING_NON_EMPTY("TableString", table), - JSON_BUILD_PAIR_BOOLEAN("Invert", rule->invert_rule), - JSON_BUILD_PAIR_CONDITION(rule->suppress_prefixlen >= 0, - "SuppressPrefixLength", JSON_BUILD_UNSIGNED(rule->suppress_prefixlen)), - JSON_BUILD_PAIR_CONDITION(rule->suppress_ifgroup >= 0, - "SuppressInterfaceGroup", JSON_BUILD_UNSIGNED(rule->suppress_ifgroup)), - JSON_BUILD_PAIR_CONDITION(rule->sport.start != 0 || rule->sport.end != 0, "SourcePort", - JSON_BUILD_ARRAY(JSON_BUILD_UNSIGNED(rule->sport.start), JSON_BUILD_UNSIGNED(rule->sport.end))), - JSON_BUILD_PAIR_CONDITION(rule->dport.start != 0 || rule->dport.end != 0, "DestinationPort", - JSON_BUILD_ARRAY(JSON_BUILD_UNSIGNED(rule->dport.start), JSON_BUILD_UNSIGNED(rule->dport.end))), - JSON_BUILD_PAIR_CONDITION(rule->uid_range.start != UID_INVALID && rule->uid_range.end != UID_INVALID, "User", - JSON_BUILD_ARRAY(JSON_BUILD_UNSIGNED(rule->uid_range.start), JSON_BUILD_UNSIGNED(rule->uid_range.end))), + SD_JSON_BUILD_PAIR_BOOLEAN("Invert", rule->invert_rule), + SD_JSON_BUILD_PAIR_CONDITION(rule->suppress_prefixlen >= 0, + "SuppressPrefixLength", SD_JSON_BUILD_UNSIGNED(rule->suppress_prefixlen)), + SD_JSON_BUILD_PAIR_CONDITION(rule->suppress_ifgroup >= 0, + "SuppressInterfaceGroup", SD_JSON_BUILD_UNSIGNED(rule->suppress_ifgroup)), + SD_JSON_BUILD_PAIR_CONDITION(rule->sport.start != 0 || rule->sport.end != 0, "SourcePort", + SD_JSON_BUILD_ARRAY(SD_JSON_BUILD_UNSIGNED(rule->sport.start), SD_JSON_BUILD_UNSIGNED(rule->sport.end))), + SD_JSON_BUILD_PAIR_CONDITION(rule->dport.start != 0 || rule->dport.end != 0, "DestinationPort", + SD_JSON_BUILD_ARRAY(SD_JSON_BUILD_UNSIGNED(rule->dport.start), SD_JSON_BUILD_UNSIGNED(rule->dport.end))), + SD_JSON_BUILD_PAIR_CONDITION(rule->uid_range.start != UID_INVALID && rule->uid_range.end != UID_INVALID, "User", + SD_JSON_BUILD_ARRAY(SD_JSON_BUILD_UNSIGNED(rule->uid_range.start), SD_JSON_BUILD_UNSIGNED(rule->uid_range.end))), JSON_BUILD_PAIR_STRING_NON_EMPTY("IncomingInterface", rule->iif), JSON_BUILD_PAIR_STRING_NON_EMPTY("OutgoingInterface", rule->oif), - JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(rule->source)), - JSON_BUILD_PAIR_STRING("ConfigState", state))); + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(rule->source)), + SD_JSON_BUILD_PAIR_STRING("ConfigState", state))); } -static int routing_policy_rules_append_json(Set *rules, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int routing_policy_rules_append_json(Set *rules, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; RoutingPolicyRule *rule; int r; @@ -353,27 +355,27 @@ static int routing_policy_rules_append_json(Set *rules, JsonVariant **v) { return json_variant_set_field_non_null(v, "RoutingPolicyRules", array); } -static int network_append_json(Network *network, JsonVariant **v) { +static int network_append_json(Network *network, sd_json_variant **v) { assert(v); if (!network) return 0; - return json_variant_merge_objectb( - v, JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_STRING("NetworkFile", network->filename), - JSON_BUILD_PAIR_STRV("NetworkFileDropins", network->dropins), - JSON_BUILD_PAIR_BOOLEAN("RequiredForOnline", network->required_for_online), - JSON_BUILD_PAIR("RequiredOperationalStateForOnline", - JSON_BUILD_ARRAY(JSON_BUILD_STRING(link_operstate_to_string(network->required_operstate_for_online.min)), - JSON_BUILD_STRING(link_operstate_to_string(network->required_operstate_for_online.max)))), - JSON_BUILD_PAIR_STRING("RequiredFamilyForOnline", + return sd_json_variant_merge_objectb( + v, SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_STRING("NetworkFile", network->filename), + SD_JSON_BUILD_PAIR_STRV("NetworkFileDropins", network->dropins), + SD_JSON_BUILD_PAIR_BOOLEAN("RequiredForOnline", network->required_for_online), + SD_JSON_BUILD_PAIR("RequiredOperationalStateForOnline", + SD_JSON_BUILD_ARRAY(SD_JSON_BUILD_STRING(link_operstate_to_string(network->required_operstate_for_online.min)), + SD_JSON_BUILD_STRING(link_operstate_to_string(network->required_operstate_for_online.max)))), + SD_JSON_BUILD_PAIR_STRING("RequiredFamilyForOnline", link_required_address_family_to_string(network->required_family_for_online)), - JSON_BUILD_PAIR_STRING("ActivationPolicy", + SD_JSON_BUILD_PAIR_STRING("ActivationPolicy", activation_policy_to_string(network->activation_policy)))); } -static int device_append_json(sd_device *device, JsonVariant **v) { +static int device_append_json(sd_device *device, sd_json_variant **v) { _cleanup_strv_free_ char **link_dropins = NULL; const char *link = NULL, *path = NULL, *vendor = NULL, *model = NULL, *joined; int r; @@ -396,9 +398,9 @@ static int device_append_json(sd_device *device, JsonVariant **v) { (void) device_get_vendor_string(device, &vendor); (void) device_get_model_string(device, &model); - return json_variant_merge_objectb( + return sd_json_variant_merge_objectb( v, - JSON_BUILD_OBJECT( + SD_JSON_BUILD_OBJECT( JSON_BUILD_PAIR_STRING_NON_EMPTY("LinkFile", link), JSON_BUILD_PAIR_STRV_NON_EMPTY("LinkFileDropins", link_dropins), JSON_BUILD_PAIR_STRING_NON_EMPTY("Path", path), @@ -406,7 +408,7 @@ static int device_append_json(sd_device *device, JsonVariant **v) { JSON_BUILD_PAIR_STRING_NON_EMPTY("Model", model))); } -static int dns_append_json_one(Link *link, const struct in_addr_full *a, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **array) { +static int dns_append_json_one(Link *link, const struct in_addr_full *a, NetworkConfigSource s, const union in_addr_union *p, sd_json_variant **array) { assert(link); assert(a); assert(array); @@ -414,20 +416,20 @@ static int dns_append_json_one(Link *link, const struct in_addr_full *a, Network if (a->ifindex != 0 && a->ifindex != link->ifindex) return 0; - return json_variant_append_arrayb( + return sd_json_variant_append_arrayb( array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_INTEGER("Family", a->family), + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_INTEGER("Family", a->family), JSON_BUILD_PAIR_IN_ADDR("Address", &a->address, a->family), JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("Port", a->port), - JSON_BUILD_PAIR_CONDITION(a->ifindex != 0, "InterfaceIndex", JSON_BUILD_INTEGER(a->ifindex)), + SD_JSON_BUILD_PAIR_CONDITION(a->ifindex != 0, "InterfaceIndex", SD_JSON_BUILD_INTEGER(a->ifindex)), JSON_BUILD_PAIR_STRING_NON_EMPTY("ServerName", a->server_name), - JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)), + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)), JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", p, a->family))); } -static int dns_append_json(Link *link, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int dns_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; int r; assert(link); @@ -509,34 +511,34 @@ static int dns_append_json(Link *link, JsonVariant **v) { return json_variant_set_field_non_null(v, "DNS", array); } -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) { +static int server_append_json_one_addr(int family, const union in_addr_union *a, NetworkConfigSource s, const union in_addr_union *p, sd_json_variant **array) { assert(IN_SET(family, AF_INET, AF_INET6)); assert(a); assert(array); - return json_variant_append_arrayb( + return sd_json_variant_append_arrayb( array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_INTEGER("Family", family), + SD_JSON_BUILD_OBJECT( + SD_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)), + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)), JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", p, family))); } -static int server_append_json_one_fqdn(int family, const char *fqdn, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **array) { +static int server_append_json_one_fqdn(int family, const char *fqdn, NetworkConfigSource s, const union in_addr_union *p, sd_json_variant **array) { assert(IN_SET(family, AF_UNSPEC, AF_INET, AF_INET6)); assert(fqdn); assert(array); - return json_variant_append_arrayb( + return sd_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)), + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_STRING("Server", fqdn), + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)), JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", p, family))); } -static int server_append_json_one_string(const char *str, NetworkConfigSource s, JsonVariant **array) { +static int server_append_json_one_string(const char *str, NetworkConfigSource s, sd_json_variant **array) { union in_addr_union a; int family; @@ -548,8 +550,8 @@ static int server_append_json_one_string(const char *str, NetworkConfigSource s, return server_append_json_one_fqdn(AF_UNSPEC, str, s, NULL, array); } -static int ntp_append_json(Link *link, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int ntp_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; int r; assert(link); @@ -623,8 +625,8 @@ static int ntp_append_json(Link *link, JsonVariant **v) { return json_variant_set_field_non_null(v, "NTP", array); } -static int sip_append_json(Link *link, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int sip_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; const struct in_addr *sip; union in_addr_union s; int n_sip, r; @@ -656,21 +658,21 @@ static int sip_append_json(Link *link, JsonVariant **v) { return json_variant_set_field_non_null(v, "SIP", array); } -static int domain_append_json(int family, const char *domain, NetworkConfigSource s, const union in_addr_union *p, JsonVariant **array) { +static int domain_append_json(int family, const char *domain, NetworkConfigSource s, const union in_addr_union *p, sd_json_variant **array) { assert(IN_SET(family, AF_UNSPEC, AF_INET, AF_INET6)); assert(domain); assert(array); - return json_variant_append_arrayb( + return sd_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)), + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_STRING("Domain", domain), + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)), JSON_BUILD_PAIR_IN_ADDR_NON_NULL("ConfigProvider", p, family))); } -static int domains_append_json(Link *link, bool is_route, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int domains_append_json(Link *link, bool is_route, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; OrderedSet *link_domains, *network_domains; UseDomains use_domains; union in_addr_union s; @@ -747,19 +749,19 @@ static int domains_append_json(Link *link, bool is_route, JsonVariant **v) { return json_variant_set_field_non_null(v, is_route ? "RouteDomains" : "SearchDomains", array); } -static int nta_append_json(const char *nta, NetworkConfigSource s, JsonVariant **array) { +static int nta_append_json(const char *nta, NetworkConfigSource s, sd_json_variant **array) { assert(nta); assert(array); - return json_variant_append_arrayb( + return sd_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)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_STRING("DNSSECNegativeTrustAnchor", nta), + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(s)))); } -static int ntas_append_json(Link *link, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int ntas_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; const char *nta; int r; @@ -780,8 +782,8 @@ static int ntas_append_json(Link *link, JsonVariant **v) { return json_variant_set_field_non_null(v, "DNSSECNegativeTrustAnchors", array); } -static int dns_misc_append_json(Link *link, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int dns_misc_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; ResolveSupport resolve_support; NetworkConfigSource source; DnsOverTlsMode mode; @@ -797,11 +799,11 @@ static int dns_misc_append_json(Link *link, JsonVariant **v) { if (resolve_support >= 0) { source = link->llmnr >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC; - r = json_variant_append_arrayb( + r = sd_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)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_STRING("LLMNR", resolve_support_to_string(resolve_support)), + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source)))); if (r < 0) return r; } @@ -810,11 +812,11 @@ static int dns_misc_append_json(Link *link, JsonVariant **v) { if (resolve_support >= 0) { source = link->mdns >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC; - r = json_variant_append_arrayb( + r = sd_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)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_STRING("MDNS", resolve_support_to_string(resolve_support)), + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source)))); if (r < 0) return r; } @@ -823,11 +825,11 @@ static int dns_misc_append_json(Link *link, JsonVariant **v) { if (t >= 0) { source = link->dns_default_route >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC; - r = json_variant_append_arrayb( + r = sd_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)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_BOOLEAN("DNSDefaultRoute", t), + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source)))); if (r < 0) return r; } @@ -836,11 +838,11 @@ static int dns_misc_append_json(Link *link, JsonVariant **v) { if (mode >= 0) { source = link->dns_over_tls_mode >= 0 ? NETWORK_CONFIG_SOURCE_RUNTIME : NETWORK_CONFIG_SOURCE_STATIC; - r = json_variant_append_arrayb( + r = sd_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)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_STRING("DNSOverTLS", dns_over_tls_mode_to_string(mode)), + SD_JSON_BUILD_PAIR_STRING("ConfigSource", network_config_source_to_string(source)))); if (r < 0) return r; } @@ -848,7 +850,7 @@ static int dns_misc_append_json(Link *link, JsonVariant **v) { return json_variant_set_field_non_null(v, "DNSSettings", array); } -static int captive_portal_append_json(Link *link, JsonVariant **v) { +static int captive_portal_append_json(Link *link, sd_json_variant **v) { const char *captive_portal; int r; @@ -859,11 +861,11 @@ static int captive_portal_append_json(Link *link, JsonVariant **v) { if (r <= 0) return r; - return json_variant_merge_objectb(v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_STRING("CaptivePortal", captive_portal))); + return sd_json_variant_merge_objectb(v, SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_STRING("CaptivePortal", captive_portal))); } -static int pref64_append_json(Link *link, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL, *w = NULL; +static int pref64_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL, *w = NULL; NDiscPREF64 *i; int r; @@ -874,10 +876,10 @@ static int pref64_append_json(Link *link, JsonVariant **v) { return 0; SET_FOREACH(i, link->ndisc_pref64) { - r = json_variant_append_arrayb(&array, - JSON_BUILD_OBJECT( + r = sd_json_variant_append_arrayb(&array, + SD_JSON_BUILD_OBJECT( JSON_BUILD_PAIR_IN6_ADDR_NON_NULL("Prefix", &i->prefix), - JSON_BUILD_PAIR_UNSIGNED("PrefixLength", i->prefix_len), + SD_JSON_BUILD_PAIR_UNSIGNED("PrefixLength", i->prefix_len), JSON_BUILD_PAIR_FINITE_USEC("LifetimeUSec", i->lifetime_usec), JSON_BUILD_PAIR_IN6_ADDR_NON_NULL("ConfigProvider", &i->router))); if (r < 0) @@ -891,8 +893,8 @@ static int pref64_append_json(Link *link, JsonVariant **v) { return json_variant_set_field_non_null(v, "NDisc", w); } -static int dhcp_server_append_json(Link *link, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *w = NULL; +static int dhcp_server_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL; int r; assert(link); @@ -901,10 +903,10 @@ static int dhcp_server_append_json(Link *link, JsonVariant **v) { if (!link->dhcp_server) return 0; - r = json_build(&w, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_UNSIGNED("PoolOffset", link->dhcp_server->pool_offset), - JSON_BUILD_PAIR_UNSIGNED("PoolSize", link->dhcp_server->pool_size))); + r = sd_json_build(&w, + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_UNSIGNED("PoolOffset", link->dhcp_server->pool_offset), + SD_JSON_BUILD_PAIR_UNSIGNED("PoolSize", link->dhcp_server->pool_size))); if (r < 0) return r; @@ -919,8 +921,8 @@ static int dhcp_server_append_json(Link *link, JsonVariant **v) { return json_variant_set_field_non_null(v, "DHCPServer", w); } -static int dhcp6_client_vendor_options_append_json(Link *link, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int dhcp6_client_vendor_options_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; sd_dhcp6_option **options = NULL; int r, n_vendor_options; @@ -933,11 +935,11 @@ static int dhcp6_client_vendor_options_append_json(Link *link, JsonVariant **v) n_vendor_options = sd_dhcp6_lease_get_vendor_options(link->dhcp6_lease, &options); FOREACH_ARRAY(option, options, n_vendor_options) { - r = json_variant_append_arrayb(&array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_UNSIGNED("EnterpriseId", (*option)->enterprise_identifier), - JSON_BUILD_PAIR_UNSIGNED("SubOptionCode", (*option)->option), - JSON_BUILD_PAIR_HEX("SubOptionData", (*option)->data, (*option)->length))); + r = sd_json_variant_append_arrayb(&array, + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_UNSIGNED("EnterpriseId", (*option)->enterprise_identifier), + SD_JSON_BUILD_PAIR_UNSIGNED("SubOptionCode", (*option)->option), + SD_JSON_BUILD_PAIR_HEX("SubOptionData", (*option)->data, (*option)->length))); if (r < 0) return r; } @@ -945,8 +947,8 @@ static int dhcp6_client_vendor_options_append_json(Link *link, JsonVariant **v) return json_variant_set_field_non_null(v, "VendorSpecificOptions", array); } -static int dhcp6_client_lease_append_json(Link *link, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *w = NULL; +static int dhcp6_client_lease_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL; usec_t ts = USEC_INFINITY, t1 = USEC_INFINITY, t2 = USEC_INFINITY; int r; @@ -968,7 +970,7 @@ static int dhcp6_client_lease_append_json(Link *link, JsonVariant **v) { if (r < 0 && r != -ENODATA) return r; - r = json_build(&w, JSON_BUILD_OBJECT( + r = sd_json_build(&w, SD_JSON_BUILD_OBJECT( JSON_BUILD_PAIR_FINITE_USEC("Timeout1USec", t1), JSON_BUILD_PAIR_FINITE_USEC("Timeout2USec", t2), JSON_BUILD_PAIR_FINITE_USEC("LeaseTimestampUSec", ts))); @@ -978,8 +980,8 @@ static int dhcp6_client_lease_append_json(Link *link, JsonVariant **v) { return json_variant_set_field_non_null(v, "Lease", w); } -static int dhcp6_client_pd_append_json(Link *link, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int dhcp6_client_pd_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; int r; assert(link); @@ -1004,9 +1006,9 @@ static int dhcp6_client_pd_append_json(Link *link, JsonVariant **v) { if (r < 0) return r; - r = json_variant_append_arrayb(&array, JSON_BUILD_OBJECT( + r = sd_json_variant_append_arrayb(&array, SD_JSON_BUILD_OBJECT( JSON_BUILD_PAIR_IN6_ADDR("Prefix", &prefix), - JSON_BUILD_PAIR_UNSIGNED("PrefixLength", prefix_len), + SD_JSON_BUILD_PAIR_UNSIGNED("PrefixLength", prefix_len), JSON_BUILD_PAIR_FINITE_USEC("PreferredLifetimeUSec", lifetime_preferred_usec), JSON_BUILD_PAIR_FINITE_USEC("ValidLifetimeUSec", lifetime_valid_usec))); if (r < 0) @@ -1016,7 +1018,7 @@ 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) { +static int dhcp6_client_duid_append_json(Link *link, sd_json_variant **v) { const sd_dhcp_duid *duid; const void *data; size_t data_size; @@ -1036,11 +1038,11 @@ static int dhcp6_client_duid_append_json(Link *link, JsonVariant **v) { if (r < 0) return 0; - return json_variant_merge_objectb(v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_BYTE_ARRAY("DUID", data, data_size))); + return sd_json_variant_merge_objectb(v, SD_JSON_BUILD_OBJECT(SD_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; +static int dhcp6_client_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL; int r; assert(link); @@ -1068,8 +1070,8 @@ static int dhcp6_client_append_json(Link *link, JsonVariant **v) { return json_variant_set_field_non_null(v, "DHCPv6Client", w); } -static int dhcp_client_lease_append_json(Link *link, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *w = NULL; +static int dhcp_client_lease_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL; usec_t lease_timestamp_usec = USEC_INFINITY, t1 = USEC_INFINITY, t2 = USEC_INFINITY; int r; @@ -1091,7 +1093,7 @@ static int dhcp_client_lease_append_json(Link *link, JsonVariant **v) { if (r < 0 && r != -ENODATA) return r; - r = json_build(&w, JSON_BUILD_OBJECT( + r = sd_json_build(&w, SD_JSON_BUILD_OBJECT( JSON_BUILD_PAIR_FINITE_USEC("LeaseTimestampUSec", lease_timestamp_usec), JSON_BUILD_PAIR_FINITE_USEC("Timeout1USec", t1), JSON_BUILD_PAIR_FINITE_USEC("Timeout2USec", t2))); @@ -1101,8 +1103,8 @@ static int dhcp_client_lease_append_json(Link *link, JsonVariant **v) { return json_variant_set_field_non_null(v, "Lease", w); } -static int dhcp_client_pd_append_json(Link *link, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *addresses = NULL, *array = NULL; +static int dhcp_client_pd_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *addresses = NULL, *array = NULL; uint8_t ipv4masklen, sixrd_prefixlen; struct in6_addr sixrd_prefix; const struct in_addr *br_addresses; @@ -1121,15 +1123,15 @@ static int dhcp_client_pd_append_json(Link *link, JsonVariant **v) { return r; FOREACH_ARRAY(br_address, br_addresses, n_br_addresses) { - r = json_variant_append_arrayb(&addresses, JSON_BUILD_IN4_ADDR(br_address)); + r = sd_json_variant_append_arrayb(&addresses, JSON_BUILD_IN4_ADDR(br_address)); if (r < 0) return r; } - r = json_build(&array, JSON_BUILD_OBJECT( + r = sd_json_build(&array, SD_JSON_BUILD_OBJECT( JSON_BUILD_PAIR_IN6_ADDR("Prefix", &sixrd_prefix), - JSON_BUILD_PAIR_UNSIGNED("PrefixLength", sixrd_prefixlen), - JSON_BUILD_PAIR_UNSIGNED("IPv4MaskLength", ipv4masklen), + SD_JSON_BUILD_PAIR_UNSIGNED("PrefixLength", sixrd_prefixlen), + SD_JSON_BUILD_PAIR_UNSIGNED("IPv4MaskLength", ipv4masklen), JSON_BUILD_PAIR_VARIANT_NON_NULL("BorderRouters", addresses))); if (r < 0) return r; @@ -1137,8 +1139,8 @@ 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; +static int dhcp_client_private_options_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; int r; assert(link); @@ -1149,18 +1151,18 @@ static int dhcp_client_private_options_append_json(Link *link, JsonVariant **v) LIST_FOREACH(options, option, link->dhcp_lease->private_options) { - r = json_variant_append_arrayb( + r = sd_json_variant_append_arrayb( &array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_UNSIGNED("Option", option->tag), - JSON_BUILD_PAIR_HEX("PrivateOptionData", option->data, option->length))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_UNSIGNED("Option", option->tag), + SD_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) { +static int dhcp_client_id_append_json(Link *link, sd_json_variant **v) { const sd_dhcp_client_id *client_id; const void *data; size_t l; @@ -1180,11 +1182,11 @@ static int dhcp_client_id_append_json(Link *link, JsonVariant **v) { if (r < 0) return 0; - return json_variant_merge_objectb(v, JSON_BUILD_OBJECT(JSON_BUILD_PAIR_BYTE_ARRAY("ClientIdentifier", data, l))); + return sd_json_variant_merge_objectb(v, SD_JSON_BUILD_OBJECT(SD_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; +static int dhcp_client_append_json(Link *link, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *w = NULL; int r; assert(link); @@ -1212,8 +1214,8 @@ static int dhcp_client_append_json(Link *link, JsonVariant **v) { return json_variant_set_field_non_null(v, "DHCPv4Client", w); } -int link_build_json(Link *link, JsonVariant **ret) { - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; +int link_build_json(Link *link, sd_json_variant **ret) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; _cleanup_free_ char *type = NULL, *flags = NULL; int r; @@ -1228,42 +1230,42 @@ int link_build_json(Link *link, JsonVariant **ret) { if (r < 0) return r; - r = json_build(&v, JSON_BUILD_OBJECT( + r = sd_json_build(&v, SD_JSON_BUILD_OBJECT( /* basic information */ - JSON_BUILD_PAIR_INTEGER("Index", link->ifindex), - JSON_BUILD_PAIR_STRING("Name", link->ifname), + SD_JSON_BUILD_PAIR_INTEGER("Index", link->ifindex), + SD_JSON_BUILD_PAIR_STRING("Name", link->ifname), JSON_BUILD_PAIR_STRV_NON_EMPTY("AlternativeNames", link->alternative_names), - JSON_BUILD_PAIR_CONDITION(link->master_ifindex > 0, - "MasterInterfaceIndex", JSON_BUILD_INTEGER(link->master_ifindex)), + SD_JSON_BUILD_PAIR_CONDITION(link->master_ifindex > 0, + "MasterInterfaceIndex", SD_JSON_BUILD_INTEGER(link->master_ifindex)), JSON_BUILD_PAIR_STRING_NON_EMPTY("Kind", link->kind), - JSON_BUILD_PAIR_STRING("Type", type), + SD_JSON_BUILD_PAIR_STRING("Type", type), JSON_BUILD_PAIR_STRING_NON_EMPTY("Driver", link->driver), - JSON_BUILD_PAIR_UNSIGNED("Flags", link->flags), - JSON_BUILD_PAIR_STRING("FlagsString", flags), - JSON_BUILD_PAIR_UNSIGNED("KernelOperationalState", link->kernel_operstate), - JSON_BUILD_PAIR_STRING("KernelOperationalStateString", kernel_operstate_to_string(link->kernel_operstate)), - JSON_BUILD_PAIR_UNSIGNED("MTU", link->mtu), - JSON_BUILD_PAIR_UNSIGNED("MinimumMTU", link->min_mtu), - JSON_BUILD_PAIR_UNSIGNED("MaximumMTU", link->max_mtu), + SD_JSON_BUILD_PAIR_UNSIGNED("Flags", link->flags), + SD_JSON_BUILD_PAIR_STRING("FlagsString", flags), + SD_JSON_BUILD_PAIR_UNSIGNED("KernelOperationalState", link->kernel_operstate), + SD_JSON_BUILD_PAIR_STRING("KernelOperationalStateString", kernel_operstate_to_string(link->kernel_operstate)), + SD_JSON_BUILD_PAIR_UNSIGNED("MTU", link->mtu), + SD_JSON_BUILD_PAIR_UNSIGNED("MinimumMTU", link->min_mtu), + SD_JSON_BUILD_PAIR_UNSIGNED("MaximumMTU", link->max_mtu), JSON_BUILD_PAIR_HW_ADDR_NON_NULL("HardwareAddress", &link->hw_addr), JSON_BUILD_PAIR_HW_ADDR_NON_NULL("PermanentHardwareAddress", &link->permanent_hw_addr), JSON_BUILD_PAIR_HW_ADDR_NON_NULL("BroadcastAddress", &link->bcast_addr), JSON_BUILD_PAIR_IN6_ADDR_NON_NULL("IPv6LinkLocalAddress", &link->ipv6ll_address), /* wlan information */ - JSON_BUILD_PAIR_CONDITION(link->wlan_iftype > 0, "WirelessLanInterfaceType", - JSON_BUILD_UNSIGNED(link->wlan_iftype)), - JSON_BUILD_PAIR_CONDITION(link->wlan_iftype > 0, "WirelessLanInterfaceTypeString", - JSON_BUILD_STRING(nl80211_iftype_to_string(link->wlan_iftype))), + SD_JSON_BUILD_PAIR_CONDITION(link->wlan_iftype > 0, "WirelessLanInterfaceType", + SD_JSON_BUILD_UNSIGNED(link->wlan_iftype)), + SD_JSON_BUILD_PAIR_CONDITION(link->wlan_iftype > 0, "WirelessLanInterfaceTypeString", + SD_JSON_BUILD_STRING(nl80211_iftype_to_string(link->wlan_iftype))), JSON_BUILD_PAIR_STRING_NON_EMPTY("SSID", link->ssid), JSON_BUILD_PAIR_ETHER_ADDR_NON_NULL("BSSID", &link->bssid), /* link state */ - JSON_BUILD_PAIR_STRING("AdministrativeState", link_state_to_string(link->state)), - JSON_BUILD_PAIR_STRING("OperationalState", link_operstate_to_string(link->operstate)), - JSON_BUILD_PAIR_STRING("CarrierState", link_carrier_state_to_string(link->carrier_state)), - JSON_BUILD_PAIR_STRING("AddressState", link_address_state_to_string(link->address_state)), - JSON_BUILD_PAIR_STRING("IPv4AddressState", link_address_state_to_string(link->ipv4_address_state)), - JSON_BUILD_PAIR_STRING("IPv6AddressState", link_address_state_to_string(link->ipv6_address_state)), - JSON_BUILD_PAIR_STRING("OnlineState", link_online_state_to_string(link->online_state)))); + SD_JSON_BUILD_PAIR_STRING("AdministrativeState", link_state_to_string(link->state)), + SD_JSON_BUILD_PAIR_STRING("OperationalState", link_operstate_to_string(link->operstate)), + SD_JSON_BUILD_PAIR_STRING("CarrierState", link_carrier_state_to_string(link->carrier_state)), + SD_JSON_BUILD_PAIR_STRING("AddressState", link_address_state_to_string(link->address_state)), + SD_JSON_BUILD_PAIR_STRING("IPv4AddressState", link_address_state_to_string(link->ipv4_address_state)), + SD_JSON_BUILD_PAIR_STRING("IPv6AddressState", link_address_state_to_string(link->ipv6_address_state)), + SD_JSON_BUILD_PAIR_STRING("OnlineState", link_online_state_to_string(link->online_state)))); if (r < 0) return r; @@ -1343,8 +1345,8 @@ int link_build_json(Link *link, JsonVariant **ret) { return 0; } -static int links_append_json(Manager *manager, JsonVariant **v) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int links_append_json(Manager *manager, sd_json_variant **v) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; _cleanup_free_ Link **links = NULL; size_t n_links = 0; int r; @@ -1357,13 +1359,13 @@ static int links_append_json(Manager *manager, JsonVariant **v) { return r; FOREACH_ARRAY(link, links, n_links) { - _cleanup_(json_variant_unrefp) JsonVariant *e = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *e = NULL; r = link_build_json(*link, &e); if (r < 0) return r; - r = json_variant_append_array(&array, e); + r = sd_json_variant_append_array(&array, e); if (r < 0) return r; } @@ -1371,8 +1373,8 @@ static int links_append_json(Manager *manager, JsonVariant **v) { return json_variant_set_field_non_null(v, "Interfaces", array); } -int manager_build_json(Manager *manager, JsonVariant **ret) { - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; +int manager_build_json(Manager *manager, sd_json_variant **ret) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; int r; assert(manager); diff --git a/src/network/networkd-json.h b/src/network/networkd-json.h index 25018fa097..b3cdb5cae8 100644 --- a/src/network/networkd-json.h +++ b/src/network/networkd-json.h @@ -1,10 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "json.h" +#include "sd-json.h" typedef struct Link Link; typedef struct Manager Manager; -int link_build_json(Link *link, JsonVariant **ret); -int manager_build_json(Manager *manager, JsonVariant **ret); +int link_build_json(Link *link, sd_json_variant **ret); +int manager_build_json(Manager *manager, sd_json_variant **ret); diff --git a/src/network/networkd-link-bus.c b/src/network/networkd-link-bus.c index 743957d27c..f5b8dc726b 100644 --- a/src/network/networkd-link-bus.c +++ b/src/network/networkd-link-bus.c @@ -680,7 +680,7 @@ int bus_link_method_reconfigure(sd_bus_message *message, void *userdata, sd_bus_ int bus_link_method_describe(sd_bus_message *message, void *userdata, sd_bus_error *error) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; _cleanup_free_ char *text = NULL; Link *link = ASSERT_PTR(userdata); int r; @@ -691,7 +691,7 @@ int bus_link_method_describe(sd_bus_message *message, void *userdata, sd_bus_err if (r < 0) return log_link_error_errno(link, r, "Failed to build JSON data: %m"); - r = json_variant_format(v, 0, &text); + r = sd_json_variant_format(v, 0, &text); if (r < 0) return log_link_error_errno(link, r, "Failed to format JSON data: %m"); diff --git a/src/network/networkd-manager-bus.c b/src/network/networkd-manager-bus.c index 3c3d815a4a..04a986a38d 100644 --- a/src/network/networkd-manager-bus.c +++ b/src/network/networkd-manager-bus.c @@ -231,7 +231,7 @@ static int bus_method_describe_link(sd_bus_message *message, void *userdata, sd_ static int bus_method_describe(sd_bus_message *message, void *userdata, sd_bus_error *error) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; _cleanup_free_ char *text = NULL; Manager *manager = ASSERT_PTR(userdata); int r; @@ -242,7 +242,7 @@ static int bus_method_describe(sd_bus_message *message, void *userdata, sd_bus_e if (r < 0) return log_error_errno(r, "Failed to build JSON data: %m"); - r = json_variant_format(v, 0, &text); + r = sd_json_variant_format(v, 0, &text); if (r < 0) return log_error_errno(r, "Failed to format JSON data: %m"); diff --git a/src/network/networkd-manager-varlink.c b/src/network/networkd-manager-varlink.c index 5eeed95791..8422f124f1 100644 --- a/src/network/networkd-manager-varlink.c +++ b/src/network/networkd-manager-varlink.c @@ -4,6 +4,7 @@ #include "bus-polkit.h" #include "fd-util.h" +#include "json-util.h" #include "lldp-rx-internal.h" #include "networkd-dhcp-server.h" #include "networkd-manager-varlink.h" @@ -11,32 +12,32 @@ #include "varlink.h" #include "varlink-io.systemd.Network.h" -static int vl_method_get_states(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_states(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { Manager *m = ASSERT_PTR(userdata); assert(link); - if (json_variant_elements(parameters) > 0) + if (sd_json_variant_elements(parameters) > 0) return varlink_error_invalid_parameter(link, parameters); return varlink_replyb(link, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_STRING("AddressState", link_address_state_to_string(m->address_state)), - JSON_BUILD_PAIR_STRING("IPv4AddressState", link_address_state_to_string(m->ipv4_address_state)), - JSON_BUILD_PAIR_STRING("IPv6AddressState", link_address_state_to_string(m->ipv6_address_state)), - JSON_BUILD_PAIR_STRING("CarrierState", link_carrier_state_to_string(m->carrier_state)), - JSON_BUILD_PAIR_CONDITION(m->online_state >= 0, "OnlineState", JSON_BUILD_STRING(link_online_state_to_string(m->online_state))), - JSON_BUILD_PAIR_STRING("OperationalState", link_operstate_to_string(m->operational_state)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_STRING("AddressState", link_address_state_to_string(m->address_state)), + SD_JSON_BUILD_PAIR_STRING("IPv4AddressState", link_address_state_to_string(m->ipv4_address_state)), + SD_JSON_BUILD_PAIR_STRING("IPv6AddressState", link_address_state_to_string(m->ipv6_address_state)), + SD_JSON_BUILD_PAIR_STRING("CarrierState", link_carrier_state_to_string(m->carrier_state)), + SD_JSON_BUILD_PAIR_CONDITION(m->online_state >= 0, "OnlineState", SD_JSON_BUILD_STRING(link_online_state_to_string(m->online_state))), + SD_JSON_BUILD_PAIR_STRING("OperationalState", link_operstate_to_string(m->operational_state)))); } -static int vl_method_get_namespace_id(Varlink *link, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { +static int vl_method_get_namespace_id(Varlink *link, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { uint64_t inode = 0; uint32_t nsid = UINT32_MAX; int r; assert(link); - if (json_variant_elements(parameters) > 0) + if (sd_json_variant_elements(parameters) > 0) return varlink_error_invalid_parameter(link, parameters); /* Network namespaces have two identifiers: the inode number (which all namespace types have), and @@ -55,10 +56,10 @@ static int vl_method_get_namespace_id(Varlink *link, JsonVariant *parameters, Va log_full_errno(r == -ENODATA ? LOG_DEBUG : LOG_WARNING, r, "Failed to query network nsid, ignoring: %m"); return varlink_replyb(link, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_UNSIGNED("NamespaceId", inode), - JSON_BUILD_PAIR_CONDITION(nsid == UINT32_MAX, "NamespaceNSID", JSON_BUILD_NULL), - JSON_BUILD_PAIR_CONDITION(nsid != UINT32_MAX, "NamespaceNSID", JSON_BUILD_UNSIGNED(nsid)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_UNSIGNED("NamespaceId", inode), + SD_JSON_BUILD_PAIR_CONDITION(nsid == UINT32_MAX, "NamespaceNSID", SD_JSON_BUILD_NULL), + SD_JSON_BUILD_PAIR_CONDITION(nsid != UINT32_MAX, "NamespaceNSID", SD_JSON_BUILD_UNSIGNED(nsid)))); } typedef struct InterfaceInfo { @@ -66,10 +67,10 @@ typedef struct InterfaceInfo { const char *ifname; } InterfaceInfo; -static int dispatch_interface(Varlink *vlink, JsonVariant *parameters, Manager *manager, Link **ret) { - static const JsonDispatch dispatch_table[] = { - { "InterfaceIndex", _JSON_VARIANT_TYPE_INVALID, json_dispatch_int, offsetof(InterfaceInfo, ifindex), 0 }, - { "InterfaceName", JSON_VARIANT_STRING, json_dispatch_const_string, offsetof(InterfaceInfo, ifname), 0 }, +static int dispatch_interface(Varlink *vlink, sd_json_variant *parameters, Manager *manager, Link **ret) { + static const sd_json_dispatch_field dispatch_table[] = { + { "InterfaceIndex", _SD_JSON_VARIANT_TYPE_INVALID, sd_json_dispatch_int, offsetof(InterfaceInfo, ifindex), 0 }, + { "InterfaceName", SD_JSON_VARIANT_STRING, sd_json_dispatch_const_string, offsetof(InterfaceInfo, ifname), 0 }, {} }; @@ -106,21 +107,21 @@ static int dispatch_interface(Varlink *vlink, JsonVariant *parameters, Manager * return 0; } -static int link_append_lldp_neighbors(Link *link, JsonVariant *v, JsonVariant **array) { +static int link_append_lldp_neighbors(Link *link, sd_json_variant *v, sd_json_variant **array) { assert(link); assert(array); - return json_variant_append_arrayb(array, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_INTEGER("InterfaceIndex", link->ifindex), - JSON_BUILD_PAIR_STRING("InterfaceName", link->ifname), + return sd_json_variant_append_arrayb(array, + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_INTEGER("InterfaceIndex", link->ifindex), + SD_JSON_BUILD_PAIR_STRING("InterfaceName", link->ifname), JSON_BUILD_PAIR_STRV_NON_EMPTY("InterfaceAlternativeNames", link->alternative_names), - JSON_BUILD_PAIR_CONDITION(json_variant_is_blank_array(v), "Neighbors", JSON_BUILD_EMPTY_ARRAY), - JSON_BUILD_PAIR_CONDITION(!json_variant_is_blank_array(v), "Neighbors", JSON_BUILD_VARIANT(v)))); + SD_JSON_BUILD_PAIR_CONDITION(sd_json_variant_is_blank_array(v), "Neighbors", SD_JSON_BUILD_EMPTY_ARRAY), + SD_JSON_BUILD_PAIR_CONDITION(!sd_json_variant_is_blank_array(v), "Neighbors", SD_JSON_BUILD_VARIANT(v)))); } -static int vl_method_get_lldp_neighbors(Varlink *vlink, JsonVariant *parameters, VarlinkMethodFlags flags, Manager *manager) { - _cleanup_(json_variant_unrefp) JsonVariant *array = NULL; +static int vl_method_get_lldp_neighbors(Varlink *vlink, sd_json_variant *parameters, VarlinkMethodFlags flags, Manager *manager) { + _cleanup_(sd_json_variant_unrefp) sd_json_variant *array = NULL; Link *link = NULL; int r; @@ -132,7 +133,7 @@ static int vl_method_get_lldp_neighbors(Varlink *vlink, JsonVariant *parameters, return r; if (link) { - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; if (link->lldp_rx) { r = lldp_rx_build_neighbors_json(link->lldp_rx, &v); @@ -145,7 +146,7 @@ static int vl_method_get_lldp_neighbors(Varlink *vlink, JsonVariant *parameters, return r; } else HASHMAP_FOREACH(link, manager->links_by_index) { - _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; + _cleanup_(sd_json_variant_unrefp) sd_json_variant *v = NULL; if (!link->lldp_rx) continue; @@ -154,7 +155,7 @@ static int vl_method_get_lldp_neighbors(Varlink *vlink, JsonVariant *parameters, if (r < 0) return r; - if (json_variant_is_blank_array(v)) + if (sd_json_variant_is_blank_array(v)) continue; r = link_append_lldp_neighbors(link, v, &array); @@ -163,14 +164,14 @@ static int vl_method_get_lldp_neighbors(Varlink *vlink, JsonVariant *parameters, } return varlink_replyb(vlink, - JSON_BUILD_OBJECT( - JSON_BUILD_PAIR_CONDITION(json_variant_is_blank_array(array), "Neighbors", JSON_BUILD_EMPTY_ARRAY), - JSON_BUILD_PAIR_CONDITION(!json_variant_is_blank_array(array), "Neighbors", JSON_BUILD_VARIANT(array)))); + SD_JSON_BUILD_OBJECT( + SD_JSON_BUILD_PAIR_CONDITION(sd_json_variant_is_blank_array(array), "Neighbors", SD_JSON_BUILD_EMPTY_ARRAY), + SD_JSON_BUILD_PAIR_CONDITION(!sd_json_variant_is_blank_array(array), "Neighbors", SD_JSON_BUILD_VARIANT(array)))); } -static int vl_method_set_persistent_storage(Varlink *vlink, JsonVariant *parameters, VarlinkMethodFlags flags, void *userdata) { - static const JsonDispatch dispatch_table[] = { - { "Ready", JSON_VARIANT_BOOLEAN, json_dispatch_boolean, 0, 0 }, +static int vl_method_set_persistent_storage(Varlink *vlink, sd_json_variant *parameters, VarlinkMethodFlags flags, void *userdata) { + static const sd_json_dispatch_field dispatch_table[] = { + { "Ready", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool, 0, 0 }, {} }; |