Rework the main <-> parser/filemode communication protocol a bit.
authorclaudio <claudio@openbsd.org>
Fri, 6 Jan 2023 16:06:43 +0000 (16:06 +0000)
committerclaudio <claudio@openbsd.org>
Fri, 6 Jan 2023 16:06:43 +0000 (16:06 +0000)
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@

usr.sbin/rpki-client/filemode.c
usr.sbin/rpki-client/main.c
usr.sbin/rpki-client/parser.c

index f546f09..85da152 100644 (file)
@@ -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 <claudio@openbsd.org>
  * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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);
index d93aaeb..2be19c9 100644 (file)
@@ -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 <claudio@openbsd.org>
  * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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:
index deb09e7..d558981 100644 (file)
@@ -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 <claudio@openbsd.org>
  * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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);