diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2020-10-01 10:25:27 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2020-10-01 10:25:27 +0000 |
commit | 59be033cf0ba57827e08b540ac3dbbef79ba5d43 (patch) | |
tree | a6bacbb0dfe8ac3c68b5675dd2e49436d52b6186 | |
parent | 10a1141c4034c67f669b7a9581343776e12d0237 (diff) |
Make the repotab (rt) a global instead of passing the value around as
an argument. Will help with further changes.
OK benno@
-rw-r--r-- | usr.sbin/rpki-client/main.c | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index 40d8b9051bb..2d4b7bd1d4a 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.80 2020/10/01 08:27:33 claudio Exp $ */ +/* $OpenBSD: main.c,v 1.81 2020/10/01 10:25:26 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -94,10 +94,10 @@ void suicide(int sig); /* * Table of all known repositories. */ -struct repotab { +static struct repotab { struct repo *repos; /* repositories */ size_t reposz; /* number of repos */ -}; +} rt; /* * An entity (MFT, ROA, certificate, etc.) that needs to be downloaded @@ -308,7 +308,7 @@ entityq_flush(int fd, struct entityq *q, const struct repo *repo) * Look up a repository, queueing it for discovery if not found. */ static const struct repo * -repo_lookup(int fd, struct repotab *rt, const char *uri) +repo_lookup(int fd, const char *uri) { const char *host, *mod; size_t hostsz, modsz, i; @@ -320,32 +320,32 @@ repo_lookup(int fd, struct repotab *rt, const char *uri) /* Look up in repository table. */ - for (i = 0; i < rt->reposz; i++) { - if (strlen(rt->repos[i].host) != hostsz) + for (i = 0; i < rt.reposz; i++) { + if (strlen(rt.repos[i].host) != hostsz) continue; - if (strlen(rt->repos[i].module) != modsz) + if (strlen(rt.repos[i].module) != modsz) continue; - if (strncasecmp(rt->repos[i].host, host, hostsz)) + if (strncasecmp(rt.repos[i].host, host, hostsz)) continue; - if (strncasecmp(rt->repos[i].module, mod, modsz)) + if (strncasecmp(rt.repos[i].module, mod, modsz)) continue; - return &rt->repos[i]; + return &rt.repos[i]; } - rt->repos = reallocarray(rt->repos, - rt->reposz + 1, sizeof(struct repo)); - if (rt->repos == NULL) + rt.repos = reallocarray(rt.repos, + rt.reposz + 1, sizeof(struct repo)); + if (rt.repos == NULL) err(1, "reallocarray"); - rp = &rt->repos[rt->reposz++]; + rp = &rt.repos[rt.reposz++]; memset(rp, 0, sizeof(struct repo)); - rp->id = rt->reposz - 1; + rp->id = rt.reposz - 1; if ((rp->host = strndup(host, hostsz)) == NULL || (rp->module = strndup(mod, modsz)) == NULL) err(1, "strndup"); - i = rt->reposz - 1; + i = rt.reposz - 1; if (!noop) { logx("%s/%s: pulling from network", rp->host, rp->module); @@ -547,7 +547,7 @@ queue_add_tal(int fd, struct entityq *q, const char *file, size_t *eid) */ static void queue_add_from_tal(int proc, int rsync, struct entityq *q, - const struct tal *tal, struct repotab *rt, size_t *eid) + const struct tal *tal, size_t *eid) { char *nfile; const struct repo *repo; @@ -559,7 +559,7 @@ queue_add_from_tal(int proc, int rsync, struct entityq *q, /* Look up the repository. */ assert(rtype_resolve(uri) == RTYPE_CER); - repo = repo_lookup(rsync, rt, uri); + repo = repo_lookup(rsync, uri); uri += 8 + strlen(repo->host) + 1 + strlen(repo->module) + 1; if (asprintf(&nfile, "%s/%s/%s", repo->host, repo->module, uri) == -1) @@ -574,7 +574,7 @@ queue_add_from_tal(int proc, int rsync, struct entityq *q, */ static void queue_add_from_cert(int proc, int rsync, struct entityq *q, - const char *uri, struct repotab *rt, size_t *eid) + const char *uri, size_t *eid) { char *nfile; enum rtype type; @@ -587,7 +587,7 @@ queue_add_from_cert(int proc, int rsync, struct entityq *q, /* Look up the repository. */ - repo = repo_lookup(rsync, rt, uri); + repo = repo_lookup(rsync, uri); uri += 8 + strlen(repo->host) + 1 + strlen(repo->module) + 1; if (asprintf(&nfile, "%s/%s/%s", repo->host, repo->module, uri) == -1) @@ -1159,7 +1159,7 @@ out: */ static void entity_process(int proc, int rsync, struct stats *st, - struct entityq *q, const struct entity *ent, struct repotab *rt, + struct entityq *q, const struct entity *ent, size_t *eid, struct vrp_tree *tree) { struct tal *tal; @@ -1179,7 +1179,7 @@ entity_process(int proc, int rsync, struct stats *st, case RTYPE_TAL: st->tals++; tal = tal_read(proc); - queue_add_from_tal(proc, rsync, q, tal, rt, eid); + queue_add_from_tal(proc, rsync, q, tal, eid); tal_free(tal); break; case RTYPE_CER: @@ -1199,7 +1199,7 @@ entity_process(int proc, int rsync, struct stats *st, */ if (cert->mft != NULL) queue_add_from_cert(proc, rsync, - q, cert->mft, rt, eid); + q, cert->mft, eid); } else st->certs_invalid++; cert_free(cert); @@ -1287,7 +1287,7 @@ add_to_del(char **del, size_t *dsz, char *file) } static size_t -repo_cleanup(const char *cachedir, struct repotab *rt) +repo_cleanup(const char *cachedir) { size_t i, delsz = 0; char *argv[2], **del = NULL; @@ -1298,9 +1298,9 @@ repo_cleanup(const char *cachedir, struct repotab *rt) if (chdir(cachedir) == -1) err(1, "%s: chdir", cachedir); - for (i = 0; i < rt->reposz; i++) { - if (asprintf(&argv[0], "%s/%s", rt->repos[i].host, - rt->repos[i].module) == -1) + for (i = 0; i < rt.reposz; i++) { + if (asprintf(&argv[0], "%s/%s", rt.repos[i].host, + rt.repos[i].module) == -1) err(1, NULL); argv[1] = NULL; if ((fts = fts_open(argv, FTS_PHYSICAL | FTS_NOSTAT, @@ -1379,7 +1379,6 @@ main(int argc, char *argv[]) struct entityq q; struct entity *ent; struct pollfd pfd[2]; - struct repotab rt; struct roa **out = NULL; char *rsync_prog = "openrsync"; char *bind_addr = NULL; @@ -1487,7 +1486,6 @@ main(int argc, char *argv[]) if (talsz == 0) err(1, "no TAL files found in %s", "/etc/rpki"); - memset(&rt, 0, sizeof(struct repotab)); TAILQ_INIT(&q); /* @@ -1636,7 +1634,7 @@ main(int argc, char *argv[]) if ((pfd[1].revents & POLLIN)) { ent = entityq_next(proc, &q); entity_process(proc, rsync, &stats, - &q, ent, &rt, &eid, &v); + &q, ent, &eid, &v); if (verbose > 2) fprintf(stderr, "%s\n", ent->uri); entity_free(ent); @@ -1684,7 +1682,7 @@ main(int argc, char *argv[]) if (outputfiles(&v, &stats)) rc = 1; - stats.del_files = repo_cleanup(cachedir, &rt); + stats.del_files = repo_cleanup(cachedir); logx("Route Origin Authorizations: %zu (%zu failed parse, %zu invalid)", stats.roas, stats.roas_fail, stats.roas_invalid); |