diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2024-03-01 07:59:21 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2024-03-01 07:59:21 +0000 |
commit | fc0a52bd2f7ac7934cd0637d83f8046e1cd3756c (patch) | |
tree | d0ec777848563c5a937c530df4b85ddeab60cfd1 /usr.sbin/rpki-client | |
parent | f648891feeab7dda33f0c8995c88c73cab919ec5 (diff) |
Factor signed prefix list JSON output into a helper
ok claudio job (as part of a larger diff)
Diffstat (limited to 'usr.sbin/rpki-client')
-rw-r--r-- | usr.sbin/rpki-client/output-json.c | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/usr.sbin/rpki-client/output-json.c b/usr.sbin/rpki-client/output-json.c index f19a49c5eee..bd4c82e110f 100644 --- a/usr.sbin/rpki-client/output-json.c +++ b/usr.sbin/rpki-client/output-json.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output-json.c,v 1.44 2024/02/26 15:40:33 job Exp $ */ +/* $OpenBSD: output-json.c,v 1.45 2024/03/01 07:59:20 tb Exp $ */ /* * Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org> * @@ -113,6 +113,31 @@ output_aspa(struct vap_tree *vaps) json_do_end(); } +static void +output_spl(struct vsp_tree *vsps) +{ + struct vsp *vsp; + char buf[64]; + size_t i; + + json_do_array("signedprefixlists"); + RB_FOREACH(vsp, vsp_tree, vsps) { + json_do_object("vsp", 1); + json_do_int("origin_as", vsp->asid); + json_do_array("prefixes"); + for (i = 0; i < vsp->prefixesz; i++) { + ip_addr_print(&vsp->prefixes[i].prefix, + vsp->prefixes[i].afi, buf, sizeof(buf)); + json_do_string("prefix", buf); + } + json_do_end(); + json_do_int("expires", vsp->expires); + json_do_string("ta", taldescs[vsp->talid]); + json_do_end(); + } + json_do_end(); +} + int output_json(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, struct vap_tree *vaps, struct vsp_tree *vsps, struct stats *st) @@ -120,8 +145,6 @@ output_json(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, char buf[64]; struct vrp *v; struct brk *b; - struct vsp *vsp; - size_t i; json_do_start(out); outputheader_json(st); @@ -155,22 +178,7 @@ output_json(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, if (!excludeaspa) output_aspa(vaps); - json_do_array("signedprefixlists"); - RB_FOREACH(vsp, vsp_tree, vsps) { - json_do_object("vsp", 1); - json_do_int("origin_as", vsp->asid); - json_do_array("prefixes"); - for (i = 0; i < vsp->prefixesz; i++) { - ip_addr_print(&vsp->prefixes[i].prefix, - vsp->prefixes[i].afi, buf, sizeof(buf)); - json_do_string("prefix", buf); - } - json_do_end(); - json_do_int("expires", vsp->expires); - json_do_string("ta", taldescs[vsp->talid]); - json_do_end(); - } - json_do_end(); + output_spl(vsps); return json_do_finish(); } |