From: claudio Date: Fri, 6 Jan 2023 16:06:43 +0000 (+0000) Subject: Rework the main <-> parser/filemode communication protocol a bit. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=39c0924a938f1186e824b42cf3ee8d09d0073d76;p=openbsd Rework the main <-> parser/filemode communication protocol a bit. Swap repo_id and filename to simplify the code in parser.c. In filemode both repo_id and filename are ignored. Additionally do not errx() in case of unknown file types. Instead send back enough info that the code can move on. OK tb@ --- diff --git a/usr.sbin/rpki-client/filemode.c b/usr.sbin/rpki-client/filemode.c index f546f099aa9..85da152a27f 100644 --- a/usr.sbin/rpki-client/filemode.c +++ b/usr.sbin/rpki-client/filemode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filemode.c,v 1.18 2022/11/29 10:33:09 claudio Exp $ */ +/* $OpenBSD: filemode.c,v 1.19 2023/01/06 16:06:43 claudio Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -534,6 +534,7 @@ parse_file(struct entityq *q, struct msgbuf *msgq) b = io_new_buffer(); io_simple_buffer(b, &entp->type, sizeof(entp->type)); + io_simple_buffer(b, &entp->repoid, sizeof(entp->repoid)); io_str_buffer(b, entp->file); io_close_buffer(msgq, b); entity_free(entp); diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index d93aaeb1a6f..2be19c9a74b 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.229 2022/12/15 12:02:29 claudio Exp $ */ +/* $OpenBSD: main.c,v 1.230 2023/01/06 16:06:43 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -548,6 +548,7 @@ entity_process(struct ibuf *b, struct stats *st, struct vrp_tree *tree, * We follow that up with whether the resources didn't parse. */ io_read_buf(b, &type, sizeof(type)); + io_read_buf(b, &id, sizeof(id)); io_read_str(b, &file); /* in filemode messages can be ignored, only the accounting matters */ @@ -559,7 +560,6 @@ entity_process(struct ibuf *b, struct stats *st, struct vrp_tree *tree, goto done; } - io_read_buf(b, &id, sizeof(id)); rp = repo_byid(id); repo_stat_inc(rp, type, STYPE_OK); switch (type) { @@ -638,7 +638,8 @@ entity_process(struct ibuf *b, struct stats *st, struct vrp_tree *tree, case RTYPE_FILE: break; default: - errx(1, "unknown entity type %d", type); + warnx("%s: unknown entity type %d", file, type); + break; } done: diff --git a/usr.sbin/rpki-client/parser.c b/usr.sbin/rpki-client/parser.c index deb09e77afb..d558981d713 100644 --- a/usr.sbin/rpki-client/parser.c +++ b/usr.sbin/rpki-client/parser.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parser.c,v 1.81 2022/12/15 12:02:29 claudio Exp $ */ +/* $OpenBSD: parser.c,v 1.82 2023/01/06 16:06:43 claudio Exp $ */ /* * Copyright (c) 2019 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -630,14 +630,13 @@ parse_entity(struct entityq *q, struct msgbuf *msgq) /* pass back at least type, repoid and filename */ b = io_new_buffer(); io_simple_buffer(b, &entp->type, sizeof(entp->type)); + io_simple_buffer(b, &entp->repoid, sizeof(entp->repoid)); file = NULL; f = NULL; switch (entp->type) { case RTYPE_TAL: io_str_buffer(b, entp->file); - io_simple_buffer(b, &entp->repoid, - sizeof(entp->repoid)); if ((tal = tal_parse(entp->file, entp->data, entp->datasz)) == NULL) errx(1, "%s: could not parse tal file", @@ -649,8 +648,6 @@ parse_entity(struct entityq *q, struct msgbuf *msgq) case RTYPE_CER: file = parse_load_file(entp, &f, &flen); io_str_buffer(b, file); - io_simple_buffer(b, &entp->repoid, - sizeof(entp->repoid)); if (entp->data != NULL) cert = proc_parser_root_cert(file, f, flen, entp->data, entp->datasz, @@ -677,14 +674,10 @@ parse_entity(struct entityq *q, struct msgbuf *msgq) file = parse_filepath(entp->repoid, entp->path, entp->file, entp->location); io_str_buffer(b, file); - io_simple_buffer(b, &entp->repoid, - sizeof(entp->repoid)); break; case RTYPE_MFT: file = proc_parser_mft(entp, &mft); io_str_buffer(b, file); - io_simple_buffer(b, &entp->repoid, - sizeof(entp->repoid)); c = (mft != NULL); io_simple_buffer(b, &c, sizeof(int)); if (mft != NULL) @@ -694,8 +687,6 @@ parse_entity(struct entityq *q, struct msgbuf *msgq) case RTYPE_ROA: file = parse_load_file(entp, &f, &flen); io_str_buffer(b, file); - io_simple_buffer(b, &entp->repoid, - sizeof(entp->repoid)); roa = proc_parser_roa(file, f, flen); c = (roa != NULL); io_simple_buffer(b, &c, sizeof(int)); @@ -706,15 +697,11 @@ parse_entity(struct entityq *q, struct msgbuf *msgq) case RTYPE_GBR: file = parse_load_file(entp, &f, &flen); io_str_buffer(b, file); - io_simple_buffer(b, &entp->repoid, - sizeof(entp->repoid)); proc_parser_gbr(file, f, flen); break; case RTYPE_ASPA: file = parse_load_file(entp, &f, &flen); io_str_buffer(b, file); - io_simple_buffer(b, &entp->repoid, - sizeof(entp->repoid)); aspa = proc_parser_aspa(file, f, flen); c = (aspa != NULL); io_simple_buffer(b, &c, sizeof(int)); @@ -725,12 +712,14 @@ parse_entity(struct entityq *q, struct msgbuf *msgq) case RTYPE_TAK: file = parse_load_file(entp, &f, &flen); io_str_buffer(b, file); - io_simple_buffer(b, &entp->repoid, - sizeof(entp->repoid)); proc_parser_tak(file, f, flen); break; default: - errx(1, "unhandled entity type %d", entp->type); + file = parse_filepath(entp->repoid, entp->path, + entp->file, entp->location); + io_str_buffer(b, file); + warnx("%s: unhandled type %d", file, entp->type); + break; } free(f);