}
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),
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));
/* 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 */
* 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
*/
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;
/* 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.",
/* 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));
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)
{
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;
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)
destroy_tal:
tal_destroy(tal);
end:
- working_repo_cleanup();
fnstack_cleanup();
thread->exit_status = error;
}
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. */
unsigned int size;
};
-struct working_repo {
- char const *uri;
-};
-
static void
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)
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;
}
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 *))
{
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 *);