From a260f1c59142bb9df9666ade4a4e353f040beafd Mon Sep 17 00:00:00 2001 From: claudio Date: Thu, 4 Nov 2021 17:35:09 +0000 Subject: [PATCH] Instead of creating a struct repo for each unique caRepository URI use the rsync URI (a base version of caRepository) and the notify URI to identify repositories. If both rsync URI and notify URI are the same then the repo is the same. The notify URI is optional and can be NULL so the lookup needs to be a bit careful. This reduces the number of struct repos from 26k to around 50. OK tb@ --- usr.sbin/rpki-client/repo.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/usr.sbin/rpki-client/repo.c b/usr.sbin/rpki-client/repo.c index 59c0e6b5a4c..02580d53e6e 100644 --- a/usr.sbin/rpki-client/repo.c +++ b/usr.sbin/rpki-client/repo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: repo.c,v 1.9 2021/08/12 15:27:15 claudio Exp $ */ +/* $OpenBSD: repo.c,v 1.10 2021/11/04 17:35:09 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -88,7 +88,8 @@ SLIST_HEAD(, tarepo) tarepos = SLIST_HEAD_INITIALIZER(tarepos); struct repo { SLIST_ENTRY(repo) entry; - char *repouri; /* CA repository base URI */ + char *repouri; + char *notifyuri; const struct rrdprepo *rrdp; const struct rsyncrepo *rsync; const struct tarepo *ta; @@ -1089,18 +1090,33 @@ ta_lookup(struct tal *tal) struct repo * repo_lookup(const char *uri, const char *notify) { - struct repo *rp; + struct repo *rp; + char *repouri; + + if ((repouri = rsync_base_uri(uri)) == NULL) + errx(1, "bad caRepository URI: %s", uri); /* Look up in repository table. */ SLIST_FOREACH(rp, &repos, entry) { - if (strcmp(rp->repouri, uri) != 0) + if (strcmp(rp->repouri, repouri) != 0) continue; + if (rp->notifyuri != NULL) { + if (notify == NULL) + continue; + if (strcmp(rp->notifyuri, notify) != 0) + continue; + } else if (notify != NULL) + continue; + /* found matching repo */ + free(repouri); return rp; } rp = repo_alloc(); - if ((rp->repouri = strdup(uri)) == NULL) - err(1, NULL); + rp->repouri = repouri; + if (notify != NULL) + if ((rp->notifyuri = strdup(notify)) == NULL) + err(1, NULL); /* try RRDP first if available */ if (notify != NULL) -- 2.20.1