For some reasons various ids were stored as size_t (probably because once they used to be the index in an array). This is just silly and annoyed me for long enough. I think this fixes all of them.
While there also stop using size_t for maxlength of a prefix. Everywhere else the code uses just a unsigned char for that so do it there as well. Shuffle struct a little bit in hope for better packing. Seems to work with RRDP and RSYNC. -- :wq Claudio Index: extern.h =================================================================== RCS file: /cvs/src/usr.sbin/rpki-client/extern.h,v retrieving revision 1.98 diff -u -p -r1.98 extern.h --- extern.h 25 Nov 2021 14:03:40 -0000 1.98 +++ extern.h 21 Dec 2021 17:26:16 -0000 @@ -179,10 +179,10 @@ struct mft { */ struct roa_ip { enum afi afi; /* AFI value */ - size_t maxlength; /* max length or zero */ + struct ip_addr addr; /* the address prefix itself */ unsigned char min[16]; /* full range minimum */ unsigned char max[16]; /* full range maximum */ - struct ip_addr addr; /* the address prefix itself */ + unsigned char maxlength; /* max length or zero */ }; /* @@ -498,8 +498,8 @@ void proc_rrdp(int); /* Repository handling */ int filepath_add(struct filepath_tree *, char *); -void rrdp_save_state(size_t, struct rrdp_session *); -int rrdp_handle_file(size_t, enum publish_type, char *, +void rrdp_save_state(unsigned int, struct rrdp_session *); +int rrdp_handle_file(unsigned int, enum publish_type, char *, char *, size_t, char *, size_t); char *repo_filename(const struct repo *, const char *); struct repo *ta_lookup(int, struct tal *); @@ -508,15 +508,15 @@ int repo_queued(struct repo *, struct void repo_cleanup(struct filepath_tree *); void repo_free(void); -void rsync_finish(size_t, int); -void http_finish(size_t, enum http_result, const char *); -void rrdp_finish(size_t, int); - -void rsync_fetch(size_t, const char *, const char *); -void http_fetch(size_t, const char *, const char *, int); -void rrdp_fetch(size_t, const char *, const char *, +void rsync_finish(unsigned int, int); +void http_finish(unsigned int, enum http_result, const char *); +void rrdp_finish(unsigned int, int); + +void rsync_fetch(unsigned int, const char *, const char *); +void http_fetch(unsigned int, const char *, const char *, int); +void rrdp_fetch(unsigned int, const char *, const char *, struct rrdp_session *); -void rrdp_http_done(size_t, enum http_result, const char *); +void rrdp_http_done(unsigned int, enum http_result, const char *); int repo_next_timeout(int); void repo_check_timeout(void); Index: http.c =================================================================== RCS file: /cvs/src/usr.sbin/rpki-client/http.c,v retrieving revision 1.50 diff -u -p -r1.50 http.c --- http.c 10 Nov 2021 09:13:30 -0000 1.50 +++ http.c 21 Dec 2021 17:19:29 -0000 @@ -140,7 +140,7 @@ struct http_request { char *host; char *port; const char *path; /* points into uri */ - size_t id; + unsigned int id; int outfd; int redirect_loop; }; @@ -150,7 +150,7 @@ TAILQ_HEAD(http_req_queue, http_request) static struct http_conn_list active = LIST_HEAD_INITIALIZER(active); static struct http_conn_list idle = LIST_HEAD_INITIALIZER(idle); static struct http_req_queue queue = TAILQ_HEAD_INITIALIZER(queue); -static size_t http_conn_count; +static unsigned int http_conn_count; static struct msgbuf msgq; static struct sockaddr_storage http_bindaddr; @@ -159,10 +159,10 @@ static uint8_t *tls_ca_mem; static size_t tls_ca_size; /* HTTP request API */ -static void http_req_new(size_t, char *, char *, int, int); +static void http_req_new(unsigned int, char *, char *, int, int); static void http_req_free(struct http_request *); -static void http_req_done(size_t, enum http_result, const char *); -static void http_req_fail(size_t); +static void http_req_done(unsigned int, enum http_result, const char *); +static void http_req_fail(unsigned int); static int http_req_schedule(struct http_request *); /* HTTP connection API */ @@ -509,7 +509,8 @@ http_resolv(struct addrinfo **res, const * Create and queue a new request. */ static void -http_req_new(size_t id, char *uri, char *modified_since, int count, int outfd) +http_req_new(unsigned int id, char *uri, char *modified_since, int count, + int outfd) { struct http_request *req; char *host, *port, *path; @@ -560,7 +561,7 @@ http_req_free(struct http_request *req) * Enqueue request response */ static void -http_req_done(size_t id, enum http_result res, const char *last_modified) +http_req_done(unsigned int id, enum http_result res, const char *last_modified) { struct ibuf *b; @@ -575,7 +576,7 @@ http_req_done(size_t id, enum http_resul * Enqueue request failure response */ static void -http_req_fail(size_t id) +http_req_fail(unsigned int id) { struct ibuf *b; enum http_result res = HTTP_FAILED; @@ -1862,7 +1863,7 @@ proc_http(char *bind_addr, int fd) if (pfds[0].revents & POLLIN) { b = io_buf_recvfd(fd, &inbuf); if (b != NULL) { - size_t id; + unsigned int id; char *uri; char *mod; Index: main.c =================================================================== RCS file: /cvs/src/usr.sbin/rpki-client/main.c,v retrieving revision 1.167 diff -u -p -r1.167 main.c --- main.c 25 Nov 2021 15:03:04 -0000 1.167 +++ main.c 21 Dec 2021 17:40:09 -0000 @@ -228,7 +228,7 @@ entityq_add(char *file, enum rtype type, } static void -rrdp_file_resp(size_t id, int ok) +rrdp_file_resp(unsigned int id, int ok) { enum rrdp_msg type = RRDP_FILE; struct ibuf *b; @@ -241,7 +241,7 @@ rrdp_file_resp(size_t id, int ok) } void -rrdp_fetch(size_t id, const char *uri, const char *local, +rrdp_fetch(unsigned int id, const char *uri, const char *local, struct rrdp_session *s) { enum rrdp_msg type = RRDP_START; @@ -262,7 +262,7 @@ rrdp_fetch(size_t id, const char *uri, c * Request a repository sync via rsync URI to directory local. */ void -rsync_fetch(size_t id, const char *uri, const char *local) +rsync_fetch(unsigned int id, const char *uri, const char *local) { struct ibuf *b; @@ -277,7 +277,7 @@ rsync_fetch(size_t id, const char *uri, * Request a file from a https uri, data is written to the file descriptor fd. */ void -http_fetch(size_t id, const char *uri, const char *last_mod, int fd) +http_fetch(unsigned int id, const char *uri, const char *last_mod, int fd) { struct ibuf *b; @@ -295,7 +295,7 @@ http_fetch(size_t id, const char *uri, c * Create a pipe and pass the pipe endpoints to the http and rrdp process. */ static void -rrdp_http_fetch(size_t id, const char *uri, const char *last_mod) +rrdp_http_fetch(unsigned int id, const char *uri, const char *last_mod) { enum rrdp_msg type = RRDP_HTTP_INI; struct ibuf *b; @@ -314,7 +314,7 @@ rrdp_http_fetch(size_t id, const char *u } void -rrdp_http_done(size_t id, enum http_result res, const char *last_mod) +rrdp_http_done(unsigned int id, enum http_result res, const char *last_mod) { enum rrdp_msg type = RRDP_HTTP_FIN; struct ibuf *b; @@ -397,22 +397,22 @@ queue_add_from_mft_set(const struct mft * Add a local TAL file (RFC 7730) to the queue of files to fetch. */ static void -queue_add_tal(const char *file, int id) +queue_add_tal(const char *file, int talid) { unsigned char *buf; char *nfile; size_t len; - if ((nfile = strdup(file)) == NULL) - err(1, NULL); buf = load_file(file, &len); if (buf == NULL) { warn("%s", file); return; } + if ((nfile = strdup(file)) == NULL) + err(1, NULL); /* Not in a repository, so directly add to queue. */ - entityq_add(nfile, RTYPE_TAL, NULL, buf, len, id); + entityq_add(nfile, RTYPE_TAL, NULL, buf, len, talid); } /* @@ -437,8 +437,7 @@ queue_add_from_tal(struct tal *tal) /* steal the pkey from the tal structure */ data = tal->pkey; tal->pkey = NULL; - entityq_add(NULL, RTYPE_CER, repo, data, - tal->pkeysz, tal->id); + entityq_add(NULL, RTYPE_CER, repo, data, tal->pkeysz, tal->id); } /* @@ -563,7 +562,8 @@ rrdp_process(struct ibuf *b) struct rrdp_session s; char *uri, *last_mod, *data; char hash[SHA256_DIGEST_LENGTH]; - size_t dsz, id; + size_t dsz; + unsigned int id; int ok; io_read_buf(b, &type, sizeof(type)); @@ -674,9 +674,9 @@ suicide(int sig __attribute__((unused))) int main(int argc, char *argv[]) { - int rc, c, st, proc, rsync, http, rrdp, ok, hangup = 0; + int rc, c, st, proc, rsync, http, rrdp, hangup = 0; int fl = SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK; - size_t i, id; + size_t i; pid_t pid, procpid, rsyncpid, httppid, rrdppid; int fd[2]; struct pollfd pfd[NPFD]; @@ -1069,6 +1069,9 @@ main(int argc, char *argv[]) if ((pfd[1].revents & POLLIN)) { b = io_buf_read(rsync, &rsyncbuf); if (b != NULL) { + unsigned int id; + int ok; + io_read_buf(b, &id, sizeof(id)); io_read_buf(b, &ok, sizeof(ok)); rsync_finish(id, ok); @@ -1079,6 +1082,7 @@ main(int argc, char *argv[]) if ((pfd[2].revents & POLLIN)) { b = io_buf_read(http, &httpbuf); if (b != NULL) { + unsigned int id; enum http_result res; char *last_mod; Index: repo.c =================================================================== RCS file: /cvs/src/usr.sbin/rpki-client/repo.c,v retrieving revision 1.15 diff -u -p -r1.15 repo.c --- repo.c 7 Dec 2021 12:46:47 -0000 1.15 +++ repo.c 21 Dec 2021 17:05:38 -0000 @@ -61,7 +61,7 @@ struct rrdprepo { char *temp; struct filepath_tree added; struct filepath_tree deleted; - size_t id; + unsigned int id; enum repo_state state; }; SLIST_HEAD(, rrdprepo) rrdprepos = SLIST_HEAD_INITIALIZER(rrdprepos); @@ -70,7 +70,7 @@ struct rsyncrepo { SLIST_ENTRY(rsyncrepo) entry; char *repouri; char *basedir; - size_t id; + unsigned int id; enum repo_state state; }; SLIST_HEAD(, rsyncrepo) rsyncrepos = SLIST_HEAD_INITIALIZER(rsyncrepos); @@ -83,7 +83,7 @@ struct tarepo { char **uri; size_t urisz; size_t uriidx; - size_t id; + unsigned int id; enum repo_state state; }; SLIST_HEAD(, tarepo) tarepos = SLIST_HEAD_INITIALIZER(tarepos); @@ -98,12 +98,12 @@ struct repo { struct entityq queue; /* files waiting for repo */ time_t alarm; /* sync timeout */ int talid; - size_t id; /* identifier */ + unsigned int id; /* identifier */ }; SLIST_HEAD(, repo) repos = SLIST_HEAD_INITIALIZER(repos); /* counter for unique repo id */ -size_t repoid; +unsigned int repoid; /* * Database of all file path accessed during a run. @@ -421,7 +421,7 @@ ta_get(struct tal *tal, int nofetch) } static struct tarepo * -ta_find(size_t id) +ta_find(unsigned int id) { struct tarepo *tr; @@ -490,7 +490,7 @@ rsync_get(const char *uri, int nofetch) } static struct rsyncrepo * -rsync_find(size_t id) +rsync_find(unsigned int id) { struct rsyncrepo *rr; @@ -563,7 +563,7 @@ rrdp_get(const char *uri, int nofetch) } static struct rrdprepo * -rrdp_find(size_t id) +rrdp_find(unsigned int id) { struct rrdprepo *rr; @@ -710,7 +710,7 @@ fail: * Carefully write the RRDP session state file back. */ void -rrdp_save_state(size_t id, struct rrdp_session *state) +rrdp_save_state(unsigned int id, struct rrdp_session *state) { struct rrdprepo *rr; char *temp, *file; @@ -719,7 +719,7 @@ rrdp_save_state(size_t id, struct rrdp_s rr = rrdp_find(id); if (rr == NULL) - errx(1, "non-existant rrdp repo %zu", id); + errx(1, "non-existant rrdp repo %u", id); file = rrdp_state_filename(rr, 0); temp = rrdp_state_filename(rr, 1); @@ -769,7 +769,7 @@ fail: * Returns 1 on success, 0 if the repo is corrupt, -1 on IO error */ int -rrdp_handle_file(size_t id, enum publish_type pt, char *uri, +rrdp_handle_file(unsigned int id, enum publish_type pt, char *uri, char *hash, size_t hlen, char *data, size_t dlen) { struct rrdprepo *rr; @@ -780,7 +780,7 @@ rrdp_handle_file(size_t id, enum publish rr = rrdp_find(id); if (rr == NULL) - errx(1, "non-existant rrdp repo %zu", id); + errx(1, "non-existant rrdp repo %u", id); if (rr->state == REPO_FAILED) return -1; @@ -929,7 +929,7 @@ rrdp_clean_temp(struct rrdprepo *rr) * RSYNC sync finished, either with or without success. */ void -rsync_finish(size_t id, int ok) +rsync_finish(unsigned int id, int ok) { struct rsyncrepo *rr; struct tarepo *tr; @@ -960,7 +960,7 @@ rsync_finish(size_t id, int ok) rr = rsync_find(id); if (rr == NULL) - errx(1, "unknown rsync repo %zu", id); + errx(1, "unknown rsync repo %u", id); /* repository changed state already, ignore request */ if (rr->state != REPO_LOADING) @@ -985,14 +985,14 @@ rsync_finish(size_t id, int ok) * RRDP sync finshed, either with or without success. */ void -rrdp_finish(size_t id, int ok) +rrdp_finish(unsigned int id, int ok) { struct rrdprepo *rr; struct repo *rp; rr = rrdp_find(id); if (rr == NULL) - errx(1, "unknown RRDP repo %zu", id); + errx(1, "unknown RRDP repo %u", id); /* repository changed state already, ignore request */ if (rr->state != REPO_LOADING) return; @@ -1035,7 +1035,7 @@ rrdp_finish(size_t id, int ok) * over to the rrdp process. */ void -http_finish(size_t id, enum http_result res, const char *last_mod) +http_finish(unsigned int id, enum http_result res, const char *last_mod) { struct tarepo *tr; struct repo *rp; Index: rrdp.c =================================================================== RCS file: /cvs/src/usr.sbin/rpki-client/rrdp.c,v retrieving revision 1.18 diff -u -p -r1.18 rrdp.c --- rrdp.c 24 Nov 2021 15:24:16 -0000 1.18 +++ rrdp.c 21 Dec 2021 17:12:34 -0000 @@ -49,7 +49,7 @@ static struct msgbuf msgq; struct rrdp { TAILQ_ENTRY(rrdp) entry; - size_t id; + unsigned int id; char *notifyuri; char *local; char *last_mod; @@ -89,7 +89,7 @@ xstrdup(const char *s) * ok should only be set to 1 if the cache is now up-to-date. */ static void -rrdp_done(size_t id, int ok) +rrdp_done(unsigned int id, int ok) { enum rrdp_msg type = RRDP_END; struct ibuf *b; @@ -110,7 +110,7 @@ rrdp_done(size_t id, int ok) * should be set to NULL, else it should point to a proper date string. */ static void -rrdp_http_req(size_t id, const char *uri, const char *last_mod) +rrdp_http_req(unsigned int id, const char *uri, const char *last_mod) { enum rrdp_msg type = RRDP_HTTP_REQ; struct ibuf *b; @@ -167,7 +167,7 @@ rrdp_publish_file(struct rrdp *s, struct } static struct rrdp * -rrdp_new(size_t id, char *local, char *notify, char *session_id, +rrdp_new(unsigned int id, char *local, char *notify, char *session_id, long long serial, char *last_mod) { struct rrdp *s; @@ -223,7 +223,7 @@ rrdp_free(struct rrdp *s) } static struct rrdp * -rrdp_get(size_t id) +rrdp_get(unsigned int id) { struct rrdp *s; @@ -236,7 +236,7 @@ rrdp_get(size_t id) static void rrdp_failed(struct rrdp *s) { - size_t id = s->id; + unsigned int id = s->id; /* reset file state before retrying */ s->file_failed = 0; @@ -264,7 +264,7 @@ rrdp_failed(struct rrdp *s) static void rrdp_finished(struct rrdp *s) { - size_t id = s->id; + unsigned int id = s->id; /* check if all parts of the process have finished */ if ((s->state & RRDP_STATE_DONE) != RRDP_STATE_DONE) @@ -365,7 +365,7 @@ rrdp_input_handler(int fd) enum rrdp_msg type; enum http_result res; long long serial; - size_t id; + unsigned int id; int ok; b = io_buf_recvfd(fd, &inbuf); @@ -392,7 +392,7 @@ rrdp_input_handler(int fd) errx(1, "expected fd not received"); s = rrdp_get(id); if (s == NULL) - errx(1, "rrdp session %zu does not exist", id); + errx(1, "rrdp session %u does not exist", id); if (s->state != RRDP_STATE_WAIT) errx(1, "%s: bad internal state", s->local); @@ -407,7 +407,7 @@ rrdp_input_handler(int fd) s = rrdp_get(id); if (s == NULL) - errx(1, "rrdp session %zu does not exist", id); + errx(1, "rrdp session %u does not exist", id); if (!(s->state & RRDP_STATE_PARSE)) errx(1, "%s: bad internal state", s->local); @@ -419,7 +419,7 @@ rrdp_input_handler(int fd) case RRDP_FILE: s = rrdp_get(id); if (s == NULL) - errx(1, "rrdp session %zu does not exist", id); + errx(1, "rrdp session %u does not exist", id); if (b->fd != -1) errx(1, "received unexpected fd"); io_read_buf(b, &ok, sizeof(ok)); Index: rsync.c =================================================================== RCS file: /cvs/src/usr.sbin/rpki-client/rsync.c,v retrieving revision 1.30 diff -u -p -r1.30 rsync.c --- rsync.c 3 Nov 2021 14:59:37 -0000 1.30 +++ rsync.c 21 Dec 2021 17:07:29 -0000 @@ -42,9 +42,9 @@ * of which process maps to which request. */ struct rsyncproc { - char *uri; /* uri of this rsync proc */ - size_t id; /* identity of request */ - pid_t pid; /* pid of process or 0 if unassociated */ + char *uri; /* uri of this rsync proc */ + unsigned int id; /* identity of request */ + pid_t pid; /* pid of process or 0 if unassociated */ }; /* @@ -182,7 +182,7 @@ proc_rsync(char *prog, char *bind_addr, for (;;) { char *uri = NULL, *dst = NULL; - size_t id; + unsigned int id; pid_t pid; int st; @@ -222,7 +222,8 @@ proc_rsync(char *prog, char *bind_addr, } b = io_new_buffer(); - io_simple_buffer(b, &ids[i].id, sizeof(size_t)); + io_simple_buffer(b, &ids[i].id, + sizeof(ids[i].id)); io_simple_buffer(b, &ok, sizeof(ok)); io_close_buffer(&msgq, b);