From: claudio Date: Fri, 2 Sep 2022 19:10:36 +0000 (+0000) Subject: Use the abort commands when a repo timeout happens. This is cleaner X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0cda9bffbfac5c6c8096c77cd94916bcbc2d1040;p=openbsd Use the abort commands when a repo timeout happens. This is cleaner then just failing the repo fetch but leaving the backends running. OK tb@ --- diff --git a/usr.sbin/rpki-client/extern.h b/usr.sbin/rpki-client/extern.h index f385359cca7..f6d5a3b512b 100644 --- a/usr.sbin/rpki-client/extern.h +++ b/usr.sbin/rpki-client/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.152 2022/09/02 18:37:17 claudio Exp $ */ +/* $OpenBSD: extern.h,v 1.153 2022/09/02 19:10:36 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons * @@ -653,9 +653,11 @@ void rrdp_finish(unsigned int, int); void rsync_fetch(unsigned int, const char *, const char *, const char *); +void rsync_abort(unsigned int); void http_fetch(unsigned int, const char *, const char *, int); void rrdp_fetch(unsigned int, const char *, const char *, struct rrdp_session *); +void rrdp_abort(unsigned int); void rrdp_http_done(unsigned int, enum http_result, const char *); int repo_check_timeout(int); diff --git a/usr.sbin/rpki-client/main.c b/usr.sbin/rpki-client/main.c index e04e153c1c5..89e22f71070 100644 --- a/usr.sbin/rpki-client/main.c +++ b/usr.sbin/rpki-client/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.215 2022/08/30 22:42:32 tb Exp $ */ +/* $OpenBSD: main.c,v 1.216 2022/09/02 19:10:37 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -256,6 +256,18 @@ rrdp_fetch(unsigned int id, const char *uri, const char *local, io_close_buffer(&rrdpq, b); } +void +rrdp_abort(unsigned int id) +{ + enum rrdp_msg type = RRDP_ABORT; + struct ibuf *b; + + b = io_new_buffer(); + io_simple_buffer(b, &type, sizeof(type)); + io_simple_buffer(b, &id, sizeof(id)); + io_close_buffer(&rrdpq, b); +} + /* * Request a repository sync via rsync URI to directory local. */ @@ -273,6 +285,19 @@ rsync_fetch(unsigned int id, const char *uri, const char *local, io_close_buffer(&rsyncq, b); } +void +rsync_abort(unsigned int id) +{ + struct ibuf *b; + + b = io_new_buffer(); + io_simple_buffer(b, &id, sizeof(id)); + io_str_buffer(b, NULL); + io_str_buffer(b, NULL); + io_str_buffer(b, NULL); + io_close_buffer(&rsyncq, b); +} + /* * Request a file from a https uri, data is written to the file descriptor fd. */ diff --git a/usr.sbin/rpki-client/repo.c b/usr.sbin/rpki-client/repo.c index 69cf849b245..c953d55a339 100644 --- a/usr.sbin/rpki-client/repo.c +++ b/usr.sbin/rpki-client/repo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: repo.c,v 1.37 2022/09/02 15:09:19 job Exp $ */ +/* $OpenBSD: repo.c,v 1.38 2022/09/02 19:10:37 claudio Exp $ */ /* * Copyright (c) 2021 Claudio Jeker * Copyright (c) 2019 Kristaps Dzonsons @@ -1204,6 +1204,20 @@ repo_fail(struct repo *rp) errx(1, "%s: bad repo", rp->repouri); } +static void +repo_abort(struct repo *rp) +{ + /* reset the alarm */ + rp->alarm = getmonotime() + repo_timeout; + + if (rp->rsync) + rsync_abort(rp->rsync->id); + else if (rp->rrdp) + rrdp_abort(rp->rrdp->id); + else + repo_fail(rp); +} + int repo_check_timeout(int timeout) { @@ -1217,7 +1231,7 @@ repo_check_timeout(int timeout) if (rp->alarm <= now) { warnx("%s: synchronisation timeout", rp->repouri); - repo_fail(rp); + repo_abort(rp); } else { int diff = rp->alarm - now; diff *= 1000;