]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
RRDP: Fix underutilization of the filename stack
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 8 Nov 2021 22:06:18 +0000 (16:06 -0600)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Mon, 8 Nov 2021 22:11:06 +0000 (16:11 -0600)
Lots of error messages were referring to the wrong file, and several of
them printed the correct file manually as what I can only describe as a
quick workaround.

It's not perfect; not all the RRDP code has been patched. That'll have
to wait until the deep RRDP refactor.

src/http/http.c
src/rrdp/rrdp_loader.c
src/rrdp/rrdp_parser.c
src/thread_var.c

index 87312e370fc57aff417fbe3efb31d3c029d6ca96..147be88c3ba9666dd58cd5b799644bfb530c3452 100644 (file)
@@ -254,11 +254,11 @@ http_fetch(struct http_handler *handler, char const *uri, long *response_code,
        *response_code = http_code;
 
        if (res != CURLE_OK) {
-               pr_val_err("Error requesting URL %s: %s. (HTTP code: %ld)",
-                   uri, curl_err_string(handler, res), http_code);
+               pr_val_err("Error requesting URL: %s. (HTTP code: %ld)",
+                   curl_err_string(handler, res), http_code);
                if (log_operation)
-                       pr_op_err("Error requesting URL %s: %s. (HTTP code: %ld)",
-                           uri, curl_err_string(handler, res), http_code);
+                       pr_op_err("Error requesting URL: %s. (HTTP code: %ld)",
+                           curl_err_string(handler, res), http_code);
 
                switch (res) {
                case CURLE_FILESIZE_EXCEEDED:
@@ -391,12 +391,11 @@ __http_download_file(struct rpki_uri *uri, long *response_code, long ims_value,
 
                if (retries == config_get_http_retry_count()) {
                        if (retries > 0)
-                               pr_val_warn("Max HTTP retries (%u) reached requesting for '%s', won't retry again.",
-                                   retries, uri_get_global(uri));
+                               pr_val_warn("Max HTTP retries (%u) reached. Won't retry again.",
+                                   retries);
                        break;
                }
-               pr_val_warn("Retrying HTTP request '%s' in %u seconds, %u attempts remaining.",
-                   uri_get_global(uri),
+               pr_val_warn("Retrying HTTP request in %u seconds. %u attempts remaining.",
                    config_get_http_retry_interval(),
                    config_get_http_retry_count() - retries);
                retries++;
index 89fffc6113c7e0812a2e6a13876a7889b9d33e65..b43c48fa58ebf0ca0f73683335cf407f97446c25 100644 (file)
@@ -197,7 +197,6 @@ __rrdp_load(struct rpki_uri *uri, bool force_snapshot, bool *data_updated)
        if (error)
                goto upd_end;
 
-       /* No updates at the file (yet), didn't pushed to fnstack */
        if (upd_notification == NULL) {
                pr_val_debug("The Update Notification has not changed.");
                goto upd_end;
@@ -274,10 +273,8 @@ set_update:
            uri_get_global(uri));
        db_rrdp_uris_set_last_update(uri_get_global(uri));
 upd_destroy:
-       if (upd_notification != NULL) {
+       if (upd_notification != NULL)
                update_notification_destroy(upd_notification);
-               fnstack_pop(); /* Pop from rrdp_parse_notification */
-       }
 upd_end:
        /* Just return on success */
        if (!error) {
index 46808fa17886e4d08a4dad064254b7cdc6c74ca6..34d840ca2f90a2f6f23b20b42a45687c31919398 100644 (file)
@@ -909,6 +909,8 @@ process_delta(struct delta_head *delta_head, void *arg)
        if (error)
                return error;
 
+       fnstack_push_uri(uri);
+
        error = download_file(uri, 0, args->log_operation);
        if (error)
                goto release_uri;
@@ -918,6 +920,7 @@ process_delta(struct delta_head *delta_head, void *arg)
        delete_from_uri(uri, NULL);
        /* Error 0 its ok */
 release_uri:
+       fnstack_pop();
        uri_refput(uri);
        return error;
 }
@@ -942,21 +945,23 @@ rrdp_parse_notification(struct rpki_uri *uri, bool log_operation, bool force,
        if (uri == NULL || uri_is_rsync(uri))
                pr_crit("Wrong call, trying to parse a non HTTPS URI");
 
-       pr_val_debug("Processing notification '%s'.", uri_get_global(uri));
+       fnstack_push_uri(uri);
+       pr_val_debug("Processing notification.");
+
        last_update = 0;
        if (!force) {
                error = db_rrdp_uris_get_last_update(uri_get_global(uri), &last_update);
                if (error && error != -ENOENT)
-                       return error;
+                       goto end;
        }
 
        error = download_file(uri, last_update, log_operation);
        if (error < 0)
-               return error;
+               goto end;
 
        /* Request error, stop processing to handle as such */
        if (error == EREQFAILED)
-               return error;
+               goto end;
 
        /*
         * Mark as visited, if it doesn't exists yet, there's no problem since
@@ -965,26 +970,24 @@ rrdp_parse_notification(struct rpki_uri *uri, bool log_operation, bool force,
         */
        vis_err = db_rrdp_uris_set_request_status(uri_get_global(uri),
            RRDP_URI_REQ_VISITED);
-       if (vis_err && vis_err != -ENOENT)
-               return pr_val_err("Couldn't mark '%s' as visited",
-                   uri_get_global(uri));
+       if (vis_err && vis_err != -ENOENT) {
+               error = pr_val_err("Couldn't mark file as visited.");
+               goto end;
+       }
 
        /* No updates yet */
        if (error > 0) {
                delete_from_uri(uri, NULL);
                *result = NULL;
-               return 0;
+               error = 0;
+               goto end;
        }
 
-       fnstack_push_uri(uri);
        error = parse_notification(uri, result);
-       delete_from_uri(uri, NULL);
-       if (error) {
-               fnstack_pop();
-               return error;
-       }
 
-       return 0;
+       delete_from_uri(uri, NULL);
+end:   fnstack_pop();
+       return error;
 }
 
 int
@@ -1004,6 +1007,8 @@ rrdp_parse_snapshot(struct update_notification *parent,
        if (error)
                return error;
 
+       fnstack_push_uri(uri);
+
        error = download_file(uri, 0, log_operation);
        if (error)
                goto release_uri;
@@ -1013,6 +1018,7 @@ rrdp_parse_snapshot(struct update_notification *parent,
        delete_from_uri(uri, NULL);
        /* Error 0 is ok */
 release_uri:
+       fnstack_pop();
        uri_refput(uri);
        return error;
 }
index e6eab3fa9f2b0dac7e731749767ec29d63cd57e0..ab7a206d858cf050ccd7d2bf7d7cad998eb5061e 100644 (file)
@@ -153,6 +153,26 @@ fnstack_cleanup(void)
  * Any pr_op_err()s and friends will now include the new file name.
  * Use fnstack_pop() to revert back to the previously stacked file name.
  * @file is not cloned; it's expected to outlive the push/pop operation.
+ *
+ * Sample usage:
+ *
+ *     void
+ *     test_fnstack(void)
+ *     {
+ *             fnstack_push("text.txt");
+ *             pr_val_info("Message 1");
+ *             fnstack_push("image.png");
+ *             pr_val_info("Message 2");
+ *             fnstack_pop();
+ *             pr_val_info("Message 3");
+ *             fnstack_pop();
+ *     }
+ *
+ * Prints
+ *
+ *     text.txt: Message 1
+ *     image.png: Message 2
+ *     text.txt: Message 3
  */
 void
 fnstack_push(char const *file)