From 0ba5db8debcbab9757cfbcce51f0f14b28d77907 Mon Sep 17 00:00:00 2001 From: job Date: Tue, 8 Jul 2025 14:19:21 +0000 Subject: [PATCH] Use a container struct instead of individual tree head pointers Should help reduce churn in the future OK claudio@ tb@ --- usr.sbin/rpki-client/extern.h | 33 ++++++++++++------------- usr.sbin/rpki-client/main.c | 35 +++++++++++++-------------- usr.sbin/rpki-client/output-bgpd.c | 10 +++----- usr.sbin/rpki-client/output-bird.c | 12 ++++----- usr.sbin/rpki-client/output-csv.c | 8 +++--- usr.sbin/rpki-client/output-json.c | 16 ++++++------ usr.sbin/rpki-client/output-ometric.c | 6 ++--- usr.sbin/rpki-client/output.c | 13 ++++------ 8 files changed, 58 insertions(+), 75 deletions(-) diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index de35f66d366..419b3e3e206 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.244 2025/07/08 13:25:54 tb Exp $ */ +/* $OpenBSD: extern.h,v 1.245 2025/07/08 14:19:21 job Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -501,6 +501,14 @@ struct brk { RB_HEAD(brk_tree, brk); RB_PROTOTYPE(brk_tree, brk, entry, brkcmp); +struct validation_data { + struct vrp_tree vrps; + struct brk_tree brks; + struct vap_tree vaps; + struct vsp_tree vsps; + struct nca_tree ncas; +}; + /* * A single CRL */ @@ -996,24 +1004,13 @@ extern int outformats; #define FORMAT_JSON 0x08 #define FORMAT_OMETRIC 0x10 -int outputfiles(struct vrp_tree *v, struct brk_tree *b, - struct vap_tree *, struct vsp_tree *, struct nca_tree *, - struct stats *); +int outputfiles(struct validation_data *, struct stats *); int outputheader(FILE *, struct stats *); -int output_bgpd(FILE *, struct vrp_tree *, struct brk_tree *, - struct vap_tree *, struct vsp_tree *, struct nca_tree *, - struct stats *); -int output_bird(FILE *, struct vrp_tree *, struct brk_tree *, - struct vap_tree *, struct vsp_tree *, struct nca_tree *, - struct stats *); -int output_csv(FILE *, struct vrp_tree *, struct brk_tree *, - struct vap_tree *, struct vsp_tree *, struct nca_tree *, - struct stats *); -int output_json(FILE *, struct vrp_tree *, struct brk_tree *, - struct vap_tree *, struct vsp_tree *, struct nca_tree *, - struct stats *); -int output_ometric(FILE *, struct vrp_tree *, struct brk_tree *, - struct vap_tree *, struct vsp_tree *, struct nca_tree *, +int output_bgpd(FILE *, struct validation_data *, struct stats *); +int output_bird(FILE *, struct validation_data *, struct stats *); +int output_csv(FILE *, struct validation_data *, struct stats *); +int output_json(FILE *, struct validation_data *, struct stats *); +int output_ometric(FILE *, struct validation_data *, struct stats *); void logx(const char *fmt, ...) diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index c5880cd7baa..d28908d4d52 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.284 2025/06/26 06:00:32 tb Exp $ */ +/* $OpenBSD: main.c,v 1.285 2025/07/08 14:19:21 job Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -561,9 +561,7 @@ queue_add_from_cert(const struct cert *cert, struct nca_tree *ncas) * In all cases, we gather statistics. */ static void -entity_process(struct ibuf *b, struct stats *st, struct vrp_tree *tree, - struct brk_tree *brktree, struct vap_tree *vaptree, - struct vsp_tree *vsptree, struct nca_tree *ncatree) +entity_process(struct ibuf *b, struct validation_data *vd, struct stats *st) { enum rtype type; struct tal *tal; @@ -620,10 +618,10 @@ entity_process(struct ibuf *b, struct stats *st, struct vrp_tree *tree, switch (cert->purpose) { case CERT_PURPOSE_TA: case CERT_PURPOSE_CA: - queue_add_from_cert(cert, ncatree); + queue_add_from_cert(cert, &vd->ncas); break; case CERT_PURPOSE_BGPSEC_ROUTER: - cert_insert_brks(brktree, cert); + cert_insert_brks(&vd->brks, cert); repo_stat_inc(rp, talid, type, STYPE_BGPSEC); break; default: @@ -642,7 +640,7 @@ entity_process(struct ibuf *b, struct stats *st, struct vrp_tree *tree, if (mft->seqnum_gap) repo_stat_inc(rp, talid, type, STYPE_SEQNUM_GAP); queue_add_from_mft(mft); - cert_remove_nca(ncatree, mft->certid, rp); + cert_remove_nca(&vd->ncas, mft->certid, rp); mft_free(mft); break; case RTYPE_CRL: @@ -657,7 +655,7 @@ entity_process(struct ibuf *b, struct stats *st, struct vrp_tree *tree, } roa = roa_read(b); if (roa->valid) - roa_insert_vrps(tree, roa, rp); + roa_insert_vrps(&vd->vrps, roa, rp); else repo_stat_inc(rp, talid, type, STYPE_INVALID); roa_free(roa); @@ -672,7 +670,7 @@ entity_process(struct ibuf *b, struct stats *st, struct vrp_tree *tree, } aspa = aspa_read(b); if (aspa->valid) - aspa_insert_vaps(file, vaptree, aspa, rp); + aspa_insert_vaps(file, &vd->vaps, aspa, rp); else repo_stat_inc(rp, talid, type, STYPE_INVALID); aspa_free(aspa); @@ -686,7 +684,7 @@ entity_process(struct ibuf *b, struct stats *st, struct vrp_tree *tree, } spl = spl_read(b); if (spl->valid) - spl_insert_vsps(vsptree, spl, rp); + spl_insert_vsps(&vd->vsps, spl, rp); else repo_stat_inc(rp, talid, type, STYPE_INVALID); spl_free(spl); @@ -989,16 +987,18 @@ main(int argc, char *argv[]) const char *cachedir = NULL, *outputdir = NULL; const char *errs, *name; const char *skiplistfile = NULL; - struct vrp_tree vrps = RB_INITIALIZER(&vrps); - struct vsp_tree vsps = RB_INITIALIZER(&vsps); - struct brk_tree brks = RB_INITIALIZER(&brks); - struct vap_tree vaps = RB_INITIALIZER(&vaps); - struct nca_tree ncas = RB_INITIALIZER(&ncas); struct rusage ru; struct timespec start_time, now_time; + struct validation_data vd; clock_gettime(CLOCK_MONOTONIC, &start_time); + RB_INIT(&vd.vrps); + RB_INIT(&vd.brks); + RB_INIT(&vd.vaps); + RB_INIT(&vd.vsps); + RB_INIT(&vd.ncas); + /* If started as root, priv-drop to _rpki-client */ if (getuid() == 0) { struct passwd *pw; @@ -1414,8 +1414,7 @@ main(int argc, char *argv[]) errx(1, "ibuf_read: connection closed"); } while ((b = io_buf_get(queues[0])) != NULL) { - entity_process(b, &stats, &vrps, &brks, &vaps, - &vsps, &ncas); + entity_process(b, &vd, &stats); ibuf_free(b); } } @@ -1508,7 +1507,7 @@ main(int argc, char *argv[]) } repo_stats_collect(sum_repostats, &stats.repo_stats); - if (outputfiles(&vrps, &brks, &vaps, &vsps, &ncas, &stats)) + if (outputfiles(&vd, &stats)) rc = 1; printf("Processing time %lld seconds " diff --git a/usr.sbin/rpki-client/output-bgpd.c b/usr.sbin/rpki-client/output-bgpd.c index 2221d873123..ddf69e9319e 100644 --- a/usr.sbin/rpki-client/output-bgpd.c +++ b/usr.sbin/rpki-client/output-bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output-bgpd.c,v 1.33 2025/03/27 05:03:09 tb Exp $ */ +/* $OpenBSD: output-bgpd.c,v 1.34 2025/07/08 14:19:21 job Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -20,9 +20,7 @@ #include "extern.h" int -output_bgpd(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, - struct vap_tree *vaps, struct vsp_tree *vsps, struct nca_tree *ncas, - struct stats *st) +output_bgpd(FILE *out, struct validation_data *vd, struct stats *st) { struct vrp *vrp; struct vap *vap; @@ -34,7 +32,7 @@ output_bgpd(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, if (fprintf(out, "roa-set {\n") < 0) return -1; - RB_FOREACH(vrp, vrp_tree, vrps) { + RB_FOREACH(vrp, vrp_tree, &vd->vrps) { char ipbuf[64], maxlenbuf[100]; ip_addr_print(&vrp->addr, vrp->afi, ipbuf, sizeof(ipbuf)); @@ -58,7 +56,7 @@ output_bgpd(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, if (fprintf(out, "\naspa-set {\n") < 0) return -1; - RB_FOREACH(vap, vap_tree, vaps) { + RB_FOREACH(vap, vap_tree, &vd->vaps) { if (vap->overflowed) continue; if (fprintf(out, "\tcustomer-as %d expires %lld " diff --git a/usr.sbin/rpki-client/output-bird.c b/usr.sbin/rpki-client/output-bird.c index 6bc206fb115..26f477f38b2 100644 --- a/usr.sbin/rpki-client/output-bird.c +++ b/usr.sbin/rpki-client/output-bird.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output-bird.c,v 1.23 2025/03/27 05:03:09 tb Exp $ */ +/* $OpenBSD: output-bird.c,v 1.24 2025/07/08 14:19:21 job Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * Copyright (c) 2020 Robert Scheck @@ -21,9 +21,7 @@ #include "extern.h" int -output_bird(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, - struct vap_tree *vaps, struct vsp_tree *vsps, struct nca_tree *ncas, - struct stats *st) +output_bird(FILE *out, struct validation_data *vd, struct stats *st) { struct vrp *v; struct vap *vap; @@ -49,7 +47,7 @@ output_bird(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, "\troa4 { table ROAS4; };\n\n") < 0) return -1; - RB_FOREACH(v, vrp_tree, vrps) { + RB_FOREACH(v, vrp_tree, &vd->vrps) { char buf[64]; if (v->afi == AFI_IPV4) { @@ -64,7 +62,7 @@ output_bird(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, "\troa6 { table ROAS6; };\n\n") < 0) return -1; - RB_FOREACH(v, vrp_tree, vrps) { + RB_FOREACH(v, vrp_tree, &vd->vrps) { char buf[64]; if (v->afi == AFI_IPV6) { @@ -85,7 +83,7 @@ output_bird(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, "};\n\n") < 0) return -1; - RB_FOREACH(vap, vap_tree, vaps) { + RB_FOREACH(vap, vap_tree, &vd->vaps) { if (vap->overflowed) continue; if (fprintf(out, "\troute aspa %d providers ", diff --git a/usr.sbin/rpki-client/output-csv.c b/usr.sbin/rpki-client/output-csv.c index ef39ef4cb34..6238a60c02d 100644 --- a/usr.sbin/rpki-client/output-csv.c +++ b/usr.sbin/rpki-client/output-csv.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output-csv.c,v 1.15 2025/03/27 05:03:09 tb Exp $ */ +/* $OpenBSD: output-csv.c,v 1.16 2025/07/08 14:19:21 job Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * @@ -20,16 +20,14 @@ #include "extern.h" int -output_csv(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, - struct vap_tree *vaps, struct vsp_tree *vsps, struct nca_tree *ncas, - struct stats *st) +output_csv(FILE *out, struct validation_data *vd, struct stats *st) { struct vrp *v; if (fprintf(out, "ASN,IP Prefix,Max Length,Trust Anchor,Expires\n") < 0) return -1; - RB_FOREACH(v, vrp_tree, vrps) { + RB_FOREACH(v, vrp_tree, &vd->vrps) { char buf[64]; ip_addr_print(&v->addr, v->afi, buf, sizeof(buf)); diff --git a/usr.sbin/rpki-client/output-json.c b/usr.sbin/rpki-client/output-json.c index 595902218bb..6c9570375f3 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.53 2025/04/03 14:29:44 tb Exp $ */ +/* $OpenBSD: output-json.c,v 1.54 2025/07/08 14:19:21 job Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * @@ -145,9 +145,7 @@ output_spl(struct vsp_tree *vsps) } int -output_json(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, - struct vap_tree *vaps, struct vsp_tree *vsps, struct nca_tree *ncas, - struct stats *st) +output_json(FILE *out, struct validation_data *vd, struct stats *st) { char buf[64]; struct vrp *v; @@ -158,7 +156,7 @@ output_json(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, outputheader_json(st); json_do_array("roas"); - RB_FOREACH(v, vrp_tree, vrps) { + RB_FOREACH(v, vrp_tree, &vd->vrps) { ip_addr_print(&v->addr, v->afi, buf, sizeof(buf)); json_do_object("roa", 1); @@ -172,7 +170,7 @@ output_json(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, json_do_end(); json_do_array("bgpsec_keys"); - RB_FOREACH(b, brk_tree, brks) { + RB_FOREACH(b, brk_tree, &vd->brks) { json_do_object("brks", 0); json_do_int("asn", b->asid); json_do_string("ski", b->ski); @@ -184,7 +182,7 @@ output_json(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, json_do_end(); json_do_array("nonfunc_cas"); - RB_FOREACH(nca, nca_tree, ncas) { + RB_FOREACH(nca, nca_tree, &vd->ncas) { json_do_object("nca", 1); json_do_string("location", nca->location); json_do_string("ta", taldescs[nca->talid]); @@ -196,10 +194,10 @@ output_json(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, json_do_end(); if (!excludeaspa) - output_aspa(vaps); + output_aspa(&vd->vaps); if (experimental) - output_spl(vsps); + output_spl(&vd->vsps); return json_do_finish(); } diff --git a/usr.sbin/rpki-client/output-ometric.c b/usr.sbin/rpki-client/output-ometric.c index c76e8bbc034..b779f058b33 100644 --- a/usr.sbin/rpki-client/output-ometric.c +++ b/usr.sbin/rpki-client/output-ometric.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output-ometric.c,v 1.14 2025/04/03 14:29:44 tb Exp $ */ +/* $OpenBSD: output-ometric.c,v 1.15 2025/07/08 14:19:21 job Exp $ */ /* * Copyright (c) 2022 Claudio Jeker * @@ -167,9 +167,7 @@ repo_stats(const struct repo *rp, const struct repostats *in, void *arg) } int -output_ometric(FILE *out, struct vrp_tree *vrps, struct brk_tree *brks, - struct vap_tree *vaps, struct vsp_tree *vsps, struct nca_tree *ncas, - struct stats *st) +output_ometric(FILE *out, struct validation_data *vd, struct stats *st) { struct olabels *ol; const char *keys[4] = { "nodename", "domainname", "release", NULL }; diff --git a/usr.sbin/rpki-client/output.c b/usr.sbin/rpki-client/output.c index c95c81f6d87..0fb69565f09 100644 --- a/usr.sbin/rpki-client/output.c +++ b/usr.sbin/rpki-client/output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: output.c,v 1.40 2025/04/03 14:29:44 tb Exp $ */ +/* $OpenBSD: output.c,v 1.41 2025/07/08 14:19:21 job Exp $ */ /* * Copyright (c) 2019 Theo de Raadt * @@ -63,9 +63,7 @@ static char output_name[PATH_MAX]; static const struct outputs { int format; char *name; - int (*fn)(FILE *, struct vrp_tree *, struct brk_tree *, - struct vap_tree *, struct vsp_tree *, struct nca_tree *, - struct stats *); + int (*fn)(FILE *, struct validation_data *, struct stats *); } outputs[] = { { FORMAT_OPENBGPD, "openbgpd", output_bgpd }, { FORMAT_BIRD, "bird", output_bird }, @@ -124,8 +122,7 @@ prune_as0_tals(struct vrp_tree *vrps) } int -outputfiles(struct vrp_tree *v, struct brk_tree *b, struct vap_tree *a, - struct vsp_tree *p, struct nca_tree *ncas, struct stats *st) +outputfiles(struct validation_data *vd, struct stats *st) { int i, rc = 0; @@ -133,7 +130,7 @@ outputfiles(struct vrp_tree *v, struct brk_tree *b, struct vap_tree *a, set_signal_handler(); if (excludeas0) - prune_as0_tals(v); + prune_as0_tals(&vd->vrps); for (i = 0; outputs[i].name; i++) { FILE *fout; @@ -147,7 +144,7 @@ outputfiles(struct vrp_tree *v, struct brk_tree *b, struct vap_tree *a, rc = 1; continue; } - if ((*outputs[i].fn)(fout, v, b, a, p, ncas, st) != 0) { + if ((*outputs[i].fn)(fout, vd, st) != 0) { warn("output for %s format failed", outputs[i].name); fclose(fout); output_cleantmp();