diff options
author | 2019-11-30 02:31:12 +0000 | |
---|---|---|
committer | 2019-11-30 02:31:12 +0000 | |
commit | ed26e04b57e06c219aba7ad2a75b7b85452788a6 (patch) | |
tree | f9b77312b360d0efcee3c83b0f2382994b425f42 | |
parent | Revert previous - the stability was not as improved as we had thought and (diff) | |
download | wireguard-openbsd-ed26e04b57e06c219aba7ad2a75b7b85452788a6.tar.xz wireguard-openbsd-ed26e04b57e06c219aba7ad2a75b7b85452788a6.zip |
Tweak rpki-client to create all 4 output file formats from a single
compute, based upon flags. OpenBGPD compatible format by default if
no options, to integrate with bgpd.conf and bgpctl reload. Adapt
mtree and stuff. This will receive further refactoring...
ok benno job
-rw-r--r-- | etc/Makefile | 4 | ||||
-rw-r--r-- | etc/examples/bgpd.conf | 4 | ||||
-rw-r--r-- | usr.sbin/rpki-client/extern.h | 13 | ||||
-rw-r--r-- | usr.sbin/rpki-client/main.c | 87 | ||||
-rw-r--r-- | usr.sbin/rpki-client/output-bgpd.c | 9 | ||||
-rw-r--r-- | usr.sbin/rpki-client/output-bird.c | 9 | ||||
-rw-r--r-- | usr.sbin/rpki-client/output-csv.c | 9 | ||||
-rw-r--r-- | usr.sbin/rpki-client/output-json.c | 10 | ||||
-rw-r--r-- | usr.sbin/rpki-client/rpki-client.8 | 8 |
9 files changed, 88 insertions, 65 deletions
diff --git a/etc/Makefile b/etc/Makefile index 239d892b881..d0b55839487 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.473 2019/11/29 03:22:13 deraadt Exp $ +# $OpenBSD: Makefile,v 1.474 2019/11/30 02:31:12 deraadt Exp $ .include <bsd.own.mk> @@ -183,7 +183,7 @@ distribution-etc-root-var: distrib-dirs ${INSTALL} -c -o root -g wheel -m 444 /dev/null \ ${DESTDIR}/var/db/locate.database ${INSTALL} -c -o _rpki-client -g wheel -m 644 /dev/null \ - ${DESTDIR}/var/db/rpki-client/roa + ${DESTDIR}/var/db/rpki-client/openbsd ${INSTALL} -c -o ${BINOWN} -g wheel -m 640 /dev/null \ ${DESTDIR}/var/log/authlog ${INSTALL} -c -o ${BINOWN} -g wheel -m 640 /dev/null \ diff --git a/etc/examples/bgpd.conf b/etc/examples/bgpd.conf index 2396d63b382..76a95dfb4ce 100644 --- a/etc/examples/bgpd.conf +++ b/etc/examples/bgpd.conf @@ -1,4 +1,4 @@ -# $OpenBSD: bgpd.conf,v 1.16 2019/11/29 03:42:10 deraadt Exp $ +# $OpenBSD: bgpd.conf,v 1.17 2019/11/30 02:31:12 deraadt Exp $ # example bgpd configuration file, see bgpd.conf(5) # define our own ASN as a macro @@ -14,7 +14,7 @@ prefix-set mynetworks { \ 2001:db8:abcd::/48 \ } -include "/var/db/rpki-client/roa" +include "/var/db/rpki-client/openbgpd" # define bogon prefixes which should not be part of the DFZ prefix-set bogons { diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index 576ac9155c9..901ed8ee416 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.19 2019/11/29 04:40:04 claudio Exp $ */ +/* $OpenBSD: extern.h,v 1.20 2019/11/30 02:31:12 deraadt Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -364,11 +364,12 @@ char *x509_crl_get_aki(X509_CRL *); FILE *output_createtmp(char *); void output_cleantmp(void); -void output_bgpd(FILE *, struct vrp_tree *); -void output_bird(FILE *, struct vrp_tree *, const char *); -void output_csv(FILE *, struct vrp_tree *); -void output_json(FILE *, struct vrp_tree *); +void output_finish(FILE *, char *); +void output_bgpd(struct vrp_tree *); +void output_bird(struct vrp_tree *, const char *); +void output_csv(struct vrp_tree *); +void output_json(struct vrp_tree *); -#define _PATH_ROA "/var/db/rpki-client/roa" +#define _PATH_ROA_DIR "/var/db/rpki-client" #endif /* ! EXTERN_H */ diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index 1ed8b4976f4..cbc767a448f 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.47 2019/11/29 23:31:29 claudio Exp $ */ +/* $OpenBSD: main.c,v 1.48 2019/11/30 02:31:12 deraadt Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -71,9 +71,10 @@ #include "extern.h" -char *outputname = _PATH_ROA; +char *outputdir = _PATH_ROA_DIR; FILE *output = NULL; char output_tmpname[PATH_MAX]; +char output_name[PATH_MAX]; void sig_handler(int); void set_signal_handler(void); @@ -170,12 +171,11 @@ static void build_chain(const struct auth *, STACK_OF(X509) **); static void build_crls(const struct auth *, struct crl_tree *, STACK_OF(X509_CRL) **); -enum output_fmt { - BGPD, - BIRD, - CSV, - JSON -}; +int outformats; +#define FORMAT_OPENBGPD 0x01 +#define FORMAT_BIRD 0x02 +#define FORMAT_CSV 0x04 +#define FORMAT_JSON 0x08 int verbose; @@ -1419,7 +1419,6 @@ main(int argc, char *argv[]) const char *tals[TALSZ_MAX]; const char *tablename = "roa"; struct vrp_tree v = RB_INITIALIZER(&v); - enum output_fmt outfmt = BGPD; /* If started as root, priv-drop to _rpki-client */ if (getuid() == 0) { @@ -1437,16 +1436,16 @@ main(int argc, char *argv[]) if (pledge("stdio rpath wpath cpath fattr proc exec unveil", NULL) == -1) err(1, "pledge"); - while ((c = getopt(argc, argv, "b:Bce:fjnrt:T:v")) != -1) + while ((c = getopt(argc, argv, "b:Bce:fjnort:T:v")) != -1) switch (c) { case 'b': bind_addr = optarg; break; case 'B': - outfmt = BIRD; + outformats |= FORMAT_BIRD; break; case 'c': - outfmt = CSV; + outformats |= FORMAT_CSV; break; case 'e': rsync_prog = optarg; @@ -1455,11 +1454,14 @@ main(int argc, char *argv[]) force = 1; break; case 'j': - outfmt = JSON; + outformats = FORMAT_JSON; break; case 'n': noop = 1; break; + case 'o': + outformats |= FORMAT_OPENBGPD; + break; case 't': if (talsz >= TALSZ_MAX) err(1, @@ -1479,10 +1481,13 @@ main(int argc, char *argv[]) argv += optind; argc -= optind; if (argc == 1) - outputname = argv[0]; + outputdir = argv[0]; else if (argc > 1) goto usage; + if (outformats == 0) + outformats = FORMAT_OPENBGPD; + if (talsz == 0) talsz = tal_load_default(tals, TALSZ_MAX); if (talsz == 0) @@ -1659,31 +1664,14 @@ main(int argc, char *argv[]) atexit(output_cleantmp); set_signal_handler(); - output = output_createtmp(outputname); - if (output == NULL) - err(1, "failed to open temp file for %s", outputname); - - switch (outfmt) { - case BGPD: - output_bgpd(output, &v); - break; - case BIRD: - output_bird(output, &v, tablename); - break; - case CSV: - output_csv(output, &v); - break; - case JSON: - output_json(output, &v); - break; - } - - fclose(output); - - if (rc == 0) { - rename(output_tmpname, outputname); - output_tmpname[0] = '\0'; - } + if (outformats & FORMAT_OPENBGPD) + output_bgpd(&v); + if (outformats & FORMAT_BIRD) + output_bird(&v, tablename); + if (outformats & FORMAT_CSV) + output_csv(&v); + if (outformats & FORMAT_JSON) + output_json(&v); logx("Route Origin Authorizations: %zu (%zu failed parse, %zu invalid)", stats.roas, stats.roas_fail, stats.roas_invalid); @@ -1712,8 +1700,8 @@ main(int argc, char *argv[]) usage: fprintf(stderr, - "usage: rpki-client [-Bcfjnv] [-b bind_addr] [-e rsync_prog] " - "[-T table] [-t tal] [output]\n"); + "usage: rpki-client [-Bcfjnov] [-b bind_addr] [-e rsync_prog] " + "[-T table] [-t tal] [outputdir]\n"); return 1; } @@ -1723,14 +1711,18 @@ output_createtmp(char *name) FILE *f; int fd, r; + r = snprintf(output_name, sizeof output_name, + "%s/%s", outputdir, name); + if (r < 0 || r > (int)sizeof(output_name)) + err(1, "path too long"); r = snprintf(output_tmpname, sizeof output_tmpname, - "%s.XXXXXXXXXXX", name); + "%s.XXXXXXXXXXX", output_name); if (r < 0 || r > (int)sizeof(output_tmpname)) err(1, "path too long"); fd = mkostemp(output_tmpname, O_CLOEXEC); - (void) fchmod(fd, 0644); if (fd == -1) err(1, "mkostemp"); + (void) fchmod(fd, 0644); f = fdopen(fd, "w"); if (f == NULL) err(1, "fdopen"); @@ -1745,6 +1737,15 @@ output_cleantmp(void) output_tmpname[0] = '\0'; } +void +output_finish(FILE *out, char *name) +{ + fclose(out); + + rename(output_tmpname, output_name); + output_tmpname[0] = '\0'; +} + /* * Signal handler that clears the temporary files. */ diff --git a/usr.sbin/rpki-client/output-bgpd.c b/usr.sbin/rpki-client/output-bgpd.c index 8eb1195d662..d7f4933a1e6 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.12 2019/10/16 17:38:46 claudio Exp $ */ +/* $OpenBSD: output-bgpd.c,v 1.13 2019/11/30 02:31:12 deraadt Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -21,10 +21,13 @@ #include "extern.h" void -output_bgpd(FILE *out, struct vrp_tree *vrps) +output_bgpd(struct vrp_tree *vrps) { char buf1[64], buf2[32]; struct vrp *v; + FILE *out; + + out = output_createtmp("openbgpd"); fprintf(out, "roa-set {\n"); @@ -39,4 +42,6 @@ output_bgpd(FILE *out, struct vrp_tree *vrps) } fprintf(out, "}\n"); + + output_finish(out, "openbgpd"); } diff --git a/usr.sbin/rpki-client/output-bird.c b/usr.sbin/rpki-client/output-bird.c index 6759fb0de1d..d39ceef7ff4 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.2 2019/11/18 08:36:38 claudio Exp $ */ +/* $OpenBSD: output-bird.c,v 1.3 2019/11/30 02:31:12 deraadt Exp $ */ /* * Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org> * @@ -21,10 +21,13 @@ #include "extern.h" void -output_bird(FILE *out, struct vrp_tree *vrps, const char *tablename) +output_bird(struct vrp_tree *vrps, const char *tablename) { char buf[64]; struct vrp *v; + FILE *out; + + out = output_createtmp("bird"); fprintf(out, "roa table %s {\n", tablename); @@ -35,4 +38,6 @@ output_bird(FILE *out, struct vrp_tree *vrps, const char *tablename) } fprintf(out, "}\n"); + + output_finish(out, "bird"); } diff --git a/usr.sbin/rpki-client/output-csv.c b/usr.sbin/rpki-client/output-csv.c index 67807e0c960..834d13f8d75 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.2 2019/11/18 08:36:38 claudio Exp $ */ +/* $OpenBSD: output-csv.c,v 1.3 2019/11/30 02:31:12 deraadt Exp $ */ /* * Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org> * @@ -21,10 +21,13 @@ #include "extern.h" void -output_csv(FILE *out, struct vrp_tree *vrps) +output_csv(struct vrp_tree *vrps) { char buf[64]; struct vrp *v; + FILE *out; + + out = output_createtmp("csv"); fprintf(out, "ASN,IP Prefix,Max Length,Trust Anchor\n"); @@ -33,4 +36,6 @@ output_csv(FILE *out, struct vrp_tree *vrps) fprintf(out, "AS%u,%s,%u,%s\n", v->asid, buf, v->maxlength, v->tal); } + + output_finish(out, "csv"); } diff --git a/usr.sbin/rpki-client/output-json.c b/usr.sbin/rpki-client/output-json.c index 952e7f8422c..b762ddef143 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.2 2019/10/16 17:38:46 claudio Exp $ */ +/* $OpenBSD: output-json.c,v 1.3 2019/11/30 02:31:12 deraadt Exp $ */ /* * Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org> * @@ -21,11 +21,14 @@ #include "extern.h" void -output_json(FILE *out, struct vrp_tree *vrps) +output_json(struct vrp_tree *vrps) { char buf[64]; struct vrp *v; int first = 1; + FILE *out; + + out = output_createtmp("json"); fprintf(out, "{\n\t\"roas\": [\n"); @@ -43,4 +46,7 @@ output_json(FILE *out, struct vrp_tree *vrps) } fprintf(out, "\n\t]\n}\n"); + + output_finish(out, "json"); } + diff --git a/usr.sbin/rpki-client/rpki-client.8 b/usr.sbin/rpki-client/rpki-client.8 index cbd7430385e..5c9722d0ef5 100644 --- a/usr.sbin/rpki-client/rpki-client.8 +++ b/usr.sbin/rpki-client/rpki-client.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: rpki-client.8,v 1.11 2019/11/29 17:30:05 benno Exp $ +.\" $OpenBSD: rpki-client.8,v 1.12 2019/11/30 02:31:12 deraadt Exp $ .\" .\" Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: November 29 2019 $ +.Dd $Mdocdate: November 30 2019 $ .Dt RPKI-CLIENT 8 .Os .Sh NAME @@ -22,12 +22,12 @@ .Nd RPKI validation for bgpd Route Origin Validation .Sh SYNOPSIS .Nm -.Op Fl Bcfjnrv +.Op Fl Bcfjnorv .Op Fl b Ar bind_addr .Op Fl e Ar rsync_prog .Op Fl T Ar table .Op Fl t Ar tal -.Op Ar output +.Op Ar outputdir .Sh DESCRIPTION The .Nm |