When RRDP support was added a repo was added for every caRepository URI
that was different from the others. Now the big RIR repos have many
caRepoistory URIs that are just subdirs and are covered by the same rsync
or RRDP source.

This diff changes this back to not create a new repo for every
caRepository URI. Instead it uses both the rsync base repo URI
(rsync://hostname/module) and RRDP notify URI to decide if a repo is the
same for different certs. With this the reported number of repositories
goes from 26k down to 50.

The lookup function needs to handle the fact that the notifyuri can be
NULL. This is why this is not just two simple strcmp calls.

More cleanup is possible but this is a good first step.
-- 
:wq Claudio

Index: repo.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/repo.c,v
retrieving revision 1.9
diff -u -p -r1.9 repo.c
--- repo.c      12 Aug 2021 15:27:15 -0000      1.9
+++ repo.c      4 Nov 2021 12:04:33 -0000
@@ -88,7 +88,8 @@ SLIST_HEAD(, tarepo)  tarepos = SLIST_HEA
 
 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)

Reply via email to