From: Alberto Leiva Popper Date: Tue, 27 Jun 2023 19:31:25 +0000 (-0600) Subject: Remove the working_repo module X-Git-Tag: 1.6.0~80^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b1f229816358462f4df2c94aa8311b1442a522d8;p=thirdparty%2FFORT-validator.git Remove the working_repo module It's a thread variable that keeps track of a URI that roughly represents the publication point currently being traversed. I would have moved it to the validation state, but given the two previous commits, it wasn't really doing anything anymore. --- diff --git a/src/object/certificate.c b/src/object/certificate.c index 3c94df8a..b72d8887 100644 --- a/src/object/certificate.c +++ b/src/object/certificate.c @@ -2113,7 +2113,6 @@ use_access_method(struct sia_ca_uris *sia_uris, access_method_exec rsync_cb, } if (primary_rrdp) { - working_repo_push(uri_get_global(sia_uris->rpkiNotify.uri)); if (error != -EPERM) pr_val_info("Couldn't fetch data from RRDP repository '%s', trying to fetch data now from '%s'.", uri_get_global(sia_uris->rpkiNotify.uri), @@ -2123,7 +2122,6 @@ use_access_method(struct sia_ca_uris *sia_uris, access_method_exec rsync_cb, uri_get_global(sia_uris->rpkiNotify.uri), uri_get_global(sia_uris->caRepository.uri)); } else { - working_repo_push(uri_get_global(sia_uris->caRepository.uri)); pr_val_info("Couldn't fetch data from repository '%s', trying to fetch data now from RRDP '%s'.", uri_get_global(sia_uris->caRepository.uri), uri_get_global(sia_uris->rpkiNotify.uri)); @@ -2132,8 +2130,6 @@ use_access_method(struct sia_ca_uris *sia_uris, access_method_exec rsync_cb, /* Retry if rrdp was the first option but failed */ (*retry_repo_sync) = primary_rrdp; error = cb_secondary(sia_uris); - /* No need to remember the working repository anymore */ - working_repo_pop(); verify_mft: /* Reach here on error or when both access methods were utilized */ diff --git a/src/object/tal.c b/src/object/tal.c index 8f96a132..62881fb2 100644 --- a/src/object/tal.c +++ b/src/object/tal.c @@ -458,8 +458,7 @@ tal_get_spki(struct tal *tal, unsigned char const **buffer, size_t *len) * have been extracted from a TAL. */ static int -handle_tal_uri(struct tal *tal, struct rpki_uri *uri, - struct validation_thread *thread) +handle_tal_uri(struct tal *tal, struct rpki_uri *uri, void *arg) { /* * Because of the way the foreach iterates, this function must return @@ -476,11 +475,14 @@ handle_tal_uri(struct tal *tal, struct rpki_uri *uri, */ struct validation_handler validation_handler; + struct validation_thread *thread; struct validation *state; struct cert_stack *certstack; struct deferred_cert deferred; int error; + thread = arg; + validation_handler.handle_roa_v4 = handle_roa_v4; validation_handler.handle_roa_v6 = handle_roa_v6; validation_handler.handle_router_key = handle_router_key; @@ -507,7 +509,6 @@ handle_tal_uri(struct tal *tal, struct rpki_uri *uri, /* Reminder: there's a positive error: EREQFAILED */ if (error) { - working_repo_push(uri_get_global(uri)); validation_destroy(state); return pr_val_warn( "TAL URI '%s' could not be downloaded.", @@ -524,7 +525,6 @@ handle_tal_uri(struct tal *tal, struct rpki_uri *uri, /* At least one URI was sync'd */ thread->retry_local = false; - working_repo_pop(); pr_val_debug("TAL URI '%s' {", uri_val_get_printable(uri)); @@ -592,25 +592,6 @@ end: validation_destroy(state); return error; } -static int -__handle_tal_uri_sync(struct tal *tal, struct rpki_uri *uri, void *arg) -{ - int error; - - error = handle_tal_uri(tal, uri, arg); - if (error) - return error; - working_repo_push(uri_get_global(uri)); - - return 0; -} - -static int -__handle_tal_uri_local(struct tal *tal, struct rpki_uri *uri, void *arg) -{ - return handle_tal_uri(tal, uri, arg); -} - static void do_file_validation(void *thread_arg) { @@ -621,15 +602,13 @@ do_file_validation(void *thread_arg) fnstack_init(); fnstack_push(thread->tal_file); - working_repo_init(); - error = tal_load(thread->tal_file, &tal); if (error) goto end; tal_order_uris(tal); - error = foreach_uri(tal, __handle_tal_uri_sync, thread); + error = foreach_uri(tal, handle_tal_uri, thread); if (error > 0) { error = 0; goto destroy_tal; @@ -646,7 +625,7 @@ do_file_validation(void *thread_arg) thread->sync_files = false; pr_val_warn("Looking for the TA certificate at the local files."); - error = foreach_uri(tal, __handle_tal_uri_local, thread); + error = foreach_uri(tal, handle_tal_uri, thread); if (error > 0) error = 0; else if (error == 0) @@ -656,7 +635,6 @@ do_file_validation(void *thread_arg) destroy_tal: tal_destroy(tal); end: - working_repo_cleanup(); fnstack_cleanup(); thread->exit_status = error; } diff --git a/src/thread_var.c b/src/thread_var.c index 35cd5d8f..8fa3961c 100644 --- a/src/thread_var.c +++ b/src/thread_var.c @@ -13,7 +13,6 @@ static pthread_key_t state_key; static pthread_key_t filenames_key; -static pthread_key_t repository_key; struct filename_stack { /* This can be NULL. Abort all operations if this is the case. */ @@ -22,10 +21,6 @@ struct filename_stack { unsigned int size; }; -struct working_repo { - char const *uri; -}; - static void fnstack_discard(void *arg) { @@ -34,13 +29,6 @@ fnstack_discard(void *arg) free(files); } -static void -working_repo_discard(void *arg) -{ - struct working_repo *repo = arg; - free(repo); -} - /** Initializes this entire module. Call once per runtime lifetime. */ int thvar_init(void) @@ -69,14 +57,6 @@ thvar_init(void) return error; } - error = pthread_key_create(&repository_key, working_repo_discard); - if (error) { - pr_op_err( - "Fatal: Errcode %d while initializing the 'working repository' thread variable.", - error); - return error; - } - return 0; } @@ -226,81 +206,6 @@ fnstack_pop(void) files->len--; } -/** Initializes the current thread's working repo. Call once per thread. */ -void -working_repo_init(void) -{ - struct working_repo *repo; - int error; - - repo = pmalloc(sizeof(struct working_repo)); - - repo->uri = NULL; - - error = pthread_setspecific(repository_key, repo); - if (error) - pr_op_err("pthread_setspecific() returned %d.", error); -} - -void -working_repo_cleanup(void) -{ - struct working_repo *repo; - int error; - - repo = pthread_getspecific(repository_key); - if (repo == NULL) - return; - - working_repo_discard(repo); - - error = pthread_setspecific(repository_key, NULL); - if (error) - pr_op_err("pthread_setspecific() returned %d.", error); -} - -/* - * Call whenever a certificate has more than one repository where its childs - * live (rsync or RRDP). - */ -void -working_repo_push(char const *location) -{ - struct working_repo *repo; - - repo = pthread_getspecific(repository_key); - if (repo == NULL) - return; - - repo->uri = location; -} - -char const * -working_repo_peek(void) -{ - struct working_repo *repo; - - repo = pthread_getspecific(repository_key); - - return repo == NULL ? NULL : repo->uri; -} - -/* - * Call once the certificate's repositories were downloaded (either successful - * or erroneously). - */ -void -working_repo_pop(void) -{ - struct working_repo *repo; - - repo = pthread_getspecific(repository_key); - if (repo == NULL) - return; - - repo->uri = NULL; -} - static char const * addr2str(int af, void const *addr, char *(*buffer_cb)(struct validation *)) { diff --git a/src/thread_var.h b/src/thread_var.h index 4dfe1abc..15769964 100644 --- a/src/thread_var.h +++ b/src/thread_var.h @@ -16,14 +16,6 @@ void fnstack_push_uri(struct rpki_uri *); char const *fnstack_peek(void); void fnstack_pop(void); -void working_repo_init(void); -void working_repo_cleanup(void); - -/* TODO (#78) remove? */ -void working_repo_push(char const *); -char const *working_repo_peek(void); -void working_repo_pop(void); - /* Please remember that these functions can only be used during validations. */ char const *v4addr2str(struct in_addr const *); char const *v4addr2str2(struct in_addr const *);