mirror of
https://github.com/openbsd/src.git
synced 2026-04-30 17:16:30 +00:00
Use a container struct instead of individual tree head pointers
Should help reduce churn in the future OK claudio@ tb@
This commit is contained in:
@@ -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 <kristaps@bsd.lv>
|
||||
*
|
||||
@@ -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, ...)
|
||||
|
||||
@@ -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 <claudio@openbsd.org>
|
||||
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
|
||||
@@ -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 "
|
||||
|
||||
@@ -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 <kristaps@bsd.lv>
|
||||
*
|
||||
@@ -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 "
|
||||
|
||||
@@ -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 <claudio@openbsd.org>
|
||||
* Copyright (c) 2020 Robert Scheck <robert@fedoraproject.org>
|
||||
@@ -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 ",
|
||||
|
||||
@@ -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 <claudio@openbsd.org>
|
||||
*
|
||||
@@ -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));
|
||||
|
||||
@@ -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 <claudio@openbsd.org>
|
||||
*
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 <claudio@openbsd.org>
|
||||
*
|
||||
@@ -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 };
|
||||
|
||||
@@ -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 <deraadt@openbsd.org>
|
||||
*
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user