Re: rpki-client: add rsync baseuri-based batching

Job Snijders <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
On Wed, Jul 08, 2026 at 02:26:41PM +0200, Theo Buehler wrote:
> > -LIST_HEAD(fqdns, fqdnlistentry);
> > +LIST_HEAD(strlist_head, strlistentry);
> 
> I would prefer omitting the _head here. I find such long struct names
> hard to read and in this case it's rather unhelpful.

ok

> > +void strlist_insert(struct strlist_head *, const char *);
> > +int strlist_find(const struct strlist_head *, const char *, size_t);
> > +void strlist_free(struct strlist_head *);
> 
> Do you anticipate using the strlist_free more than once? I think we can
> do without this abstraction.

Sure, we can add a function if duplicate code shows up in the future.

> > +	if ((sle = malloc(sizeof(*sle))) == NULL)
> 
> I would prefer calloc(), but others might disagre :)

calloc it is!

> > +	shortlisted = strlist_find(&shortlist, host, hostsz);
> > +
> 
> I think we can drop shortlisted and do:
> 
>   	if (shortlistmode && !strlist_find(&shortlist, host, hostsz)) {

ok

> > +		strlist_insert(&skiplist, line);
> >  
> 
> I'd drop the extra empty line.

ok

> > +	strlist_insert(&shortlist, fqdn);
> >  
> 
> zap empty line

ok

> > +		strlist_insert(&batchlist, nca_hist->notify);
> 
> Fine to leave it as-is, but I wonder if the logic should not be inverted
> to be the shorter:
> 
> 		if (nca_hist->notify != NULL)
> 			strlist_insert(&batchlist, nca_hist->notify);

sure


Index: extern.h
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/extern.h,v
diff -u -p -r1.287 extern.h
--- extern.h	1 Jul 2026 11:09:12 -0000	1.287
+++ extern.h	8 Jul 2026 12:36:34 -0000
@@ -29,11 +29,16 @@
 
 #define MAX_MSG_SIZE	(50 * 1024 * 1024)
 
-struct fqdnlistentry {
-	LIST_ENTRY(fqdnlistentry)	entry;
-	char				*fqdn;
+struct strlistentry {
+	LIST_ENTRY(strlistentry) entry;
+	char *str;
+	size_t str_len;
 };
-LIST_HEAD(fqdns, fqdnlistentry);
+LIST_HEAD(strlist, strlistentry);
+
+void strlist_insert(struct strlist *, const char *);
+int strlist_find(const struct strlist *, const char *, size_t);
+void strlist_free(struct strlist *);
 
 enum cert_as_type {
 	CERT_AS_ID, /* single identifier */
Index: main.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/main.c,v
diff -u -p -r1.309 main.c
--- main.c	24 Jun 2026 09:06:20 -0000	1.309
+++ main.c	8 Jul 2026 12:36:34 -0000
@@ -85,8 +85,37 @@ int64_t  evaluation_time = X509_TIME_MIN
 
 struct stats	 stats;
 
-struct fqdns shortlist = LIST_HEAD_INITIALIZER(fqdns);
-struct fqdns skiplist = LIST_HEAD_INITIALIZER(fqdns);
+static struct strlist shortlist = LIST_HEAD_INITIALIZER(shortlist);
+static struct strlist skiplist = LIST_HEAD_INITIALIZER(skiplist);
+
+void
+strlist_insert(struct strlist *strlist, const char *str)
+{
+	struct strlistentry *sle;
+
+	if ((sle = calloc(1, sizeof(*sle))) == NULL)
+		err(1, NULL);
+
+	if ((sle->str = strdup(str)) == NULL)
+		err(1, NULL);
+
+	sle->str_len = strlen(sle->str);
+
+	LIST_INSERT_HEAD(strlist, sle, entry);
+}
+
+int
+strlist_find(const struct strlist *strlist, const char *str, size_t len)
+{
+	struct strlistentry *sle;
+
+	LIST_FOREACH(sle, strlist, entry) {
+		if (sle->str_len == len && strncasecmp(str, sle->str, len) == 0)
+			return 1;
+	}
+
+	return 0;
+}
 
 /*
  * Log a message to stderr if and only if "verbose" is non-zero.
@@ -509,33 +538,21 @@ static void
 queue_add_from_cert(const struct cert *cert, struct nca_tree *ncas)
 {
 	struct repo		*repo;
-	struct fqdnlistentry	*le;
 	char			*nfile, *npath, *host;
 	const char		*uri, *repouri, *file;
 	size_t			 hostsz, repourisz;
-	int			 shortlisted = 0;
 
 	if (strncmp(cert->repo, RSYNC_PROTO, RSYNC_PROTO_LEN) != 0)
 		errx(1, "unexpected protocol");
 	host = cert->repo + RSYNC_PROTO_LEN;
 	hostsz = strcspn(host, "/");
 
-	LIST_FOREACH(le, &skiplist, entry) {
-		if (strlen(le->fqdn) == hostsz &&
-		    strncasecmp(host, le->fqdn, hostsz) == 0) {
-			warnx("skipping %s (listed in skiplist)", cert->repo);
-			return;
-		}
+	if (strlist_find(&skiplist, host, hostsz)) {
+		warnx("skipping %s (listed in skiplist)", cert->repo);
+		return;
 	}
 
-	LIST_FOREACH(le, &shortlist, entry) {
-		if (strlen(le->fqdn) == hostsz &&
-		    strncasecmp(host, le->fqdn, hostsz) == 0) {
-			shortlisted = 1;
-			break;
-		}
-	}
-	if (shortlistmode && shortlisted == 0) {
+	if (shortlistmode && strlist_find(&shortlist, host, hostsz)) {
 		if (verbose)
 			warnx("skipping %s (not shortlisted)", cert->repo);
 		return;
@@ -881,7 +898,6 @@ tal_load_default(void)
 static void
 load_skiplist(const char *slf)
 {
-	struct fqdnlistentry	*le;
 	FILE			*fp;
 	char			*line = NULL;
 	size_t			 linesize = 0, linelen;
@@ -910,12 +926,7 @@ load_skiplist(const char *slf)
 		if (!valid_uri(line, linelen, NULL))
 			errx(1, "invalid entry in skiplist: %s", line);
 
-		if ((le = malloc(sizeof(struct fqdnlistentry))) == NULL)
-			err(1, NULL);
-		if ((le->fqdn = strdup(line)) == NULL)
-			err(1, NULL);
-
-		LIST_INSERT_HEAD(&skiplist, le, entry);
+		strlist_insert(&skiplist, line);
 		stats.skiplistentries++;
 	}
 	if (ferror(fp))
@@ -931,18 +942,10 @@ load_skiplist(const char *slf)
 static void
 load_shortlist(const char *fqdn)
 {
-	struct fqdnlistentry	*le;
-
 	if (!valid_uri(fqdn, strlen(fqdn), NULL))
 		errx(1, "invalid fqdn passed to -q: %s", fqdn);
 
-	if ((le = malloc(sizeof(struct fqdnlistentry))) == NULL)
-		err(1, NULL);
-
-	if ((le->fqdn = strdup(fqdn)) == NULL)
-		err(1, NULL);
-
-	LIST_INSERT_HEAD(&shortlist, le, entry);
+	strlist_insert(&shortlist, fqdn);
 }
 
 static void
Index: nca.c
===================================================================
RCS file: /cvs/src/usr.sbin/rpki-client/nca.c,v
diff -u -p -r1.8 nca.c
--- nca.c	8 Jul 2026 05:33:28 -0000	1.8
+++ nca.c	8 Jul 2026 12:36:34 -0000
@@ -123,7 +123,7 @@ certidcmp(const struct nonfunc_ca *a, co
 
 RB_GENERATE(nca_tree, nonfunc_ca, entry, certidcmp);
 
-static LIST_HEAD(, fqdnlistentry) notifys = LIST_HEAD_INITIALIZER(notifys);
+static struct strlist batchlist = LIST_HEAD_INITIALIZER(batchlist);
 
 static RB_HEAD(nca_hist_tree, nca_hist) ncas_hist = RB_INITIALIZER(&ncas_hist);
 
@@ -229,8 +229,7 @@ static void
 ncas_plan_retries(void)
 {
 	struct nca_hist *nca_hist;
-	struct fqdnlistentry *fle, *fle_tmp;
-	size_t notify_len;
+	struct strlistentry *sle, *sle_tmp;
 
 	RB_FOREACH(nca_hist, nca_hist_tree, &ncas_hist) {
 		if (nca_decide_retry(nca_hist) == 0) {
@@ -238,38 +237,25 @@ ncas_plan_retries(void)
 			continue;
 		}
 
-		if (nca_hist->notify == NULL)
-			continue;
-
-		if ((fle = malloc(sizeof(*fle))) == NULL)
-			err(1, NULL);
-
-		if ((fle->fqdn = strdup(nca_hist->notify)) == NULL)
-			err(1, NULL);
-
-		LIST_INSERT_HEAD(&notifys, fle, entry);
+		if (nca_hist->notify != NULL)
+			strlist_insert(&batchlist, nca_hist->notify);
 	}
 
 	RB_FOREACH(nca_hist, nca_hist_tree, &ncas_hist) {
 		if (nca_hist->notify == NULL)
 			continue;
 
-		notify_len = strlen(nca_hist->notify);
-
-		LIST_FOREACH(fle, &notifys, entry) {
-			if (strlen(fle->fqdn) == notify_len &&
-			    strncasecmp(nca_hist->notify, fle->fqdn,
-			    notify_len) == 0) {
-				nca_hist->defer = 0;
-				break;
-			}
+		if (strlist_find(&batchlist, nca_hist->notify,
+		    strlen(nca_hist->notify))) {
+			nca_hist->defer = 0;
+			break;
 		}
 	}
 
-	LIST_FOREACH_SAFE(fle, &notifys, entry, fle_tmp) {
-		LIST_REMOVE(fle, entry);
-		free(fle->fqdn);
-		free(fle);
+	LIST_FOREACH_SAFE(sle, &batchlist, entry, sle_tmp) {
+		LIST_REMOVE(sle, entry);
+		free(sle->str);
+		free(sle);
 	}
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.