From: claudio Date: Tue, 20 Jun 2023 15:15:14 +0000 (+0000) Subject: Use new ibuf API in rpki-client. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=cf954fffd137c52451bba3ca43e43cbfce3ab2a2;p=openbsd Use new ibuf API in rpki-client. Use ibuf_fd_get/set/avail in the file descriptor passing code. Switch some ibuf_seek() calls to ibuf_set() and use ibuf_add_zero() instead of ibuf_reserve(). OK tb@ job@ --- diff --git a/usr.sbin/rpki-client/http.c b/usr.sbin/rpki-client/http.c index c1927529e21..4544eac2371 100644 --- a/usr.sbin/rpki-client/http.c +++ b/usr.sbin/rpki-client/http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: http.c,v 1.76 2023/06/12 15:27:52 claudio Exp $ */ +/* $OpenBSD: http.c,v 1.77 2023/06/20 15:15:14 claudio Exp $ */ /* * Copyright (c) 2020 Nils Fisher * Copyright (c) 2020 Claudio Jeker @@ -2150,7 +2150,7 @@ proc_http(char *bind_addr, int fd) io_read_str(b, &mod); /* queue up new requests */ - http_req_new(id, uri, mod, 0, b->fd); + http_req_new(id, uri, mod, 0, ibuf_fd_get(b)); ibuf_free(b); } } diff --git a/usr.sbin/rpki-client/io.c b/usr.sbin/rpki-client/io.c index 043331e32b6..a3b988ef0b1 100644 --- a/usr.sbin/rpki-client/io.c +++ b/usr.sbin/rpki-client/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.22 2022/12/14 15:19:16 claudio Exp $ */ +/* $OpenBSD: io.c,v 1.23 2023/06/20 15:15:14 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -41,7 +41,7 @@ io_new_buffer(void) if ((b = ibuf_dynamic(64, INT32_MAX)) == NULL) err(1, NULL); - ibuf_reserve(b, sizeof(size_t)); /* can not fail */ + ibuf_add_zero(b, sizeof(size_t)); /* can not fail */ return b; } @@ -88,7 +88,7 @@ io_close_buffer(struct msgbuf *msgbuf, struct ibuf *b) size_t len; len = ibuf_size(b) - sizeof(len); - memcpy(ibuf_seek(b, 0, sizeof(len)), &len, sizeof(len)); + ibuf_set(b, 0, &len, sizeof(len)); ibuf_close(msgbuf, b); } @@ -280,7 +280,7 @@ io_buf_recvfd(int fd, struct ibuf **ib) for (i = 0; i < j; i++) { f = ((int *)CMSG_DATA(cmsg))[i]; if (i == 0) - b->fd = f; + ibuf_fd_set(b, f); else close(f); } diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index 1982e2747be..39fd2931ca3 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.241 2023/05/30 16:02:28 job Exp $ */ +/* $OpenBSD: main.c,v 1.242 2023/06/20 15:15:14 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -341,7 +341,7 @@ http_fetch(unsigned int id, const char *uri, const char *last_mod, int fd) io_str_buffer(b, uri); io_str_buffer(b, last_mod); /* pass file as fd */ - b->fd = fd; + ibuf_fd_set(b, fd); io_close_buffer(&httpq, b); } @@ -362,7 +362,7 @@ rrdp_http_fetch(unsigned int id, const char *uri, const char *last_mod) b = io_new_buffer(); io_simple_buffer(b, &type, sizeof(type)); io_simple_buffer(b, &id, sizeof(id)); - b->fd = pi[0]; + ibuf_fd_set(b, pi[0]); io_close_buffer(&rrdpq, b); http_fetch(id, uri, last_mod, pi[1]); diff --git a/usr.sbin/rpki-client/rrdp.c b/usr.sbin/rpki-client/rrdp.c index d254beca5d4..08a861a4e32 100644 --- a/usr.sbin/rpki-client/rrdp.c +++ b/usr.sbin/rpki-client/rrdp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rrdp.c,v 1.30 2023/05/03 07:51:08 claudio Exp $ */ +/* $OpenBSD: rrdp.c,v 1.31 2023/06/20 15:15:14 claudio Exp $ */ /* * Copyright (c) 2020 Nils Fisher * Copyright (c) 2021 Claudio Jeker @@ -431,20 +431,20 @@ rrdp_input_handler(int fd) io_read_str(b, &session_id); io_read_buf(b, &serial, sizeof(serial)); io_read_str(b, &last_mod); - if (b->fd != -1) + if (ibuf_fd_avail(b)) errx(1, "received unexpected fd"); rrdp_new(id, local, notify, session_id, serial, last_mod); break; case RRDP_HTTP_INI: - if (b->fd == -1) - errx(1, "expected fd not received"); s = rrdp_get(id); if (s == NULL) errx(1, "http ini, rrdp session %u does not exist", id); if (s->state != RRDP_STATE_WAIT) errx(1, "%s: bad internal state", s->local); - s->infd = b->fd; + s->infd = ibuf_fd_get(b); + if (s->infd == -1) + errx(1, "expected fd not received"); s->state = RRDP_STATE_PARSE; if (s->aborted) { rrdp_abort_req(s); @@ -454,7 +454,7 @@ rrdp_input_handler(int fd) case RRDP_HTTP_FIN: io_read_buf(b, &res, sizeof(res)); io_read_str(b, &last_mod); - if (b->fd != -1) + if (ibuf_fd_avail(b)) errx(1, "received unexpected fd"); s = rrdp_get(id); @@ -472,7 +472,7 @@ rrdp_input_handler(int fd) s = rrdp_get(id); if (s == NULL) errx(1, "file, rrdp session %u does not exist", id);; - if (b->fd != -1) + if (ibuf_fd_avail(b)) errx(1, "received unexpected fd"); io_read_buf(b, &ok, sizeof(ok)); if (ok != 1) @@ -482,7 +482,7 @@ rrdp_input_handler(int fd) rrdp_finished(s); break; case RRDP_ABORT: - if (b->fd != -1) + if (ibuf_fd_avail(b)) errx(1, "received unexpected fd"); s = rrdp_get(id); if (s != NULL)