]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Random TODO patching
authorAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 23 Apr 2019 21:57:04 +0000 (16:57 -0500)
committerAlberto Leiva Popper <ydahhrk@gmail.com>
Tue, 23 Apr 2019 22:03:29 +0000 (17:03 -0500)
27 files changed:
src/certificate_refs.c
src/certificate_refs.h
src/clients.c
src/clients.h
src/config.c
src/config.h
src/config/string_array.c
src/config/string_array.h
src/data_structure/array_list.h
src/data_structure/circular_indexer.c
src/data_structure/circular_indexer.h
src/main.c
src/object/certificate.c
src/object/certificate.h
src/object/roa.c
src/object/tal.c
src/rpp.c
src/rtr/db/delta.c
src/rtr/db/roa.c
src/rtr/db/roa_tree.c
src/rtr/db/roa_tree.h
src/rtr/db/vrps.c
src/rtr/db/vrps.h
src/rtr/pdu_handler.c
src/rtr/rtr.c
src/state.c
src/updates_daemon.c

index 13db4d57dbe053e2a1bea17c06fa056d5d70b55b..f3ddf2a362dc6653c3487f6989cf4fb41f466814 100644 (file)
@@ -77,14 +77,20 @@ validate_signedObject(struct certificate_refs *refs,
        return 0;
 }
 
+/**
+ * Ensures the @refs URIs match the parent Manifest's URIs. Assumes @refs came
+ * from a CA certificate.
+ *
+ * @refs: References you want validated.
+ * @pp: Repository Publication Point, as described by the parent Manifest.
+ */
 int
-refs_validate_ca(struct certificate_refs *refs, bool is_ta,
-    struct rpp const *pp)
+refs_validate_ca(struct certificate_refs *refs, struct rpp const *pp)
 {
        int error;
 
-       if (is_ta)
-               return 0;
+       if (pp == NULL)
+               return 0; /* This CA is the TA, and therefore lacks a parent. */
 
        error = validate_cdp(refs, pp);
        if (error)
@@ -102,6 +108,14 @@ refs_validate_ca(struct certificate_refs *refs, bool is_ta,
        return 0;
 }
 
+/**
+ * Ensures the @refs URIs match the Manifest URIs. Assumes @refs came from an
+ * EE certificate.
+ *
+ * @refs: References you want validated.
+ * @pp: Repository Publication Point, as described by the Manifest.
+ * @uri: URL of the signed object that contains the EE certificate.
+ */
 int
 refs_validate_ee(struct certificate_refs *refs, struct rpp const *pp,
     struct rpki_uri const *uri)
index 55d55c3c04f0a90cf4f5e7cb73e5cf01c8688806..a2dc8818431246edc6e0a009855ebef03460eb60 100644 (file)
@@ -1,7 +1,6 @@
 #ifndef SRC_CERTIFICATE_REFS_H_
 #define SRC_CERTIFICATE_REFS_H_
 
-#include <stdbool.h>
 #include "rpp.h"
 
 /**
@@ -39,7 +38,7 @@ struct certificate_refs {
 
 void refs_init(struct certificate_refs *);
 void refs_cleanup(struct certificate_refs *);
-int refs_validate_ca(struct certificate_refs *, bool, struct rpp const *);
+int refs_validate_ca(struct certificate_refs *, struct rpp const *);
 int refs_validate_ee(struct certificate_refs *, struct rpp const *,
     struct rpki_uri const *);
 
index bd072f37f34936a6356a5a5a6d695f7395b21b89..54431964f5ae3e2e2be3f5b8be319091b7e388bd 100644 (file)
@@ -11,25 +11,18 @@ ARRAY_LIST(clientsdb, struct client)
 static struct clientsdb clients_db;
 
 /* Read and Write locks */
-sem_t rlock, wlock;
+static sem_t rlock, wlock;
 
 /* Readers counter */
-unsigned int rcounter;
+static unsigned int rcounter;
 
-int
+void
 clients_db_init(void)
 {
-       int error;
-
-       error = clientsdb_init(&clients_db);
-       if (error)
-               return error;
-
+       clientsdb_init(&clients_db);
        sem_init(&rlock, 0, 1);
        sem_init(&wlock, 0, 1);
        rcounter = 0;
-
-       return error;
 }
 
 static struct client *
@@ -45,6 +38,7 @@ get_client(struct sockaddr_storage *addr)
                                    SADDR_IN(addr)->sin_addr.s_addr &&
                                    ptr->sin_port ==
                                    SADDR_IN(addr)->sin_port) {
+                                       /* TODO (urgent) incorrect locking */
                                        read_unlock(&rlock, &wlock, &rcounter);
                                        return ptr;
                                }
@@ -125,45 +119,35 @@ client_list(struct client **clients)
        len = clients_db.len;
        read_unlock(&rlock, &wlock, &rcounter);
 
+       /* TODO (urgent) incorrect locking */
        return len;
 }
 
-static void
-client_destroy(struct client *client)
-{
-       /* Didn't allocate something, so do nothing */
-}
-
 void
 clients_forget(int fd)
 {
-       struct clientsdb *new_db;
+       struct clientsdb new_db;
        struct client *ptr;
 
-       new_db = malloc(sizeof(struct clientsdb));
-       if (new_db == NULL) {
-               pr_err("Couldn't allocate new clients DB");
-               return; /* TODO This is not acceptable... */
-       }
-       clientsdb_init(new_db);
+       clientsdb_init(&new_db);
+       /* TODO (urgent) incorrect locking */
        read_lock(&rlock, &wlock, &rcounter);
        ARRAYLIST_FOREACH(&clients_db, ptr)
                if (ptr->fd != fd)
-                       clientsdb_add(new_db, ptr);
+                       clientsdb_add(&new_db, ptr);
        read_unlock(&rlock, &wlock, &rcounter);
 
        sem_wait(&wlock);
-       clientsdb_cleanup(&clients_db, client_destroy);
-       clients_db = *new_db;
+       clientsdb_cleanup(&clients_db, NULL);
+       clients_db = new_db;
        sem_post(&wlock);
-       free(new_db);
 }
 
 void
 clients_db_destroy(void)
 {
        sem_wait(&wlock);
-       clientsdb_cleanup(&clients_db, client_destroy);
+       clientsdb_cleanup(&clients_db, NULL);
        sem_post(&wlock);
 
        sem_destroy(&wlock);
index db1a460b848e731797d5f22fb9bd8dd4a42f4727..41b88ccc6c755fcb95d753db7f1cd281e6006aeb 100644 (file)
@@ -14,7 +14,7 @@ struct client {
        uint8_t rtr_version;
 };
 
-int clients_db_init(void);
+void clients_db_init(void);
 int update_client(int, struct sockaddr_storage *, uint8_t);
 size_t client_list(struct client **);
 
index bae3f2b22076eee75b3da421d5a27da0106a638f..f4c7aaa3e3b06ca14f2924e204148b16ebe53457 100644 (file)
@@ -26,7 +26,7 @@
  * Assuming you don't need to create a data type, that should be all.
  */
 struct rpki_config {
-       /** TAL file name or directory. TODO support directories */
+       /** TAL file name or directory. TODO (urgent) support directories */
        char *tal;
        /** Path of our local clone of the repository */
        char *local_repository;
@@ -45,16 +45,15 @@ struct rpki_config {
        unsigned int maximum_certificate_depth;
 
        struct {
-               /** The listener address of the RTR server. */
+               /** The bound listening address of the RTR server. */
                char *address;
-               /** TODO document */
+               /** The bound listening port of the RTR server. */
                char *port;
                /** Maximum accepted client connections */
                unsigned int queue;
 
                /** Interval used to look for updates at VRPs location */
-               /* TODO rename */
-               unsigned int vrps_check_interval;
+               unsigned int validation_interval;
 
                /** Intervals use at RTR v1 End of data PDU **/
                uint32_t refresh_interval;
@@ -183,13 +182,13 @@ static const struct option_field options[] = {
                .name = "server.address",
                .type = &gt_string,
                .offset = offsetof(struct rpki_config, server.address),
-               .doc = "The listener address of the RTR server.",
+               .doc = "Address the RTR server will bind itself to. Can be a name, in which case an address will be resolved.",
        }, {
                .id = 5001,
                .name = "server.port",
                .type = &gt_string,
                .offset = offsetof(struct rpki_config, server.port),
-               .doc = "", /* TODO */
+               .doc = "Port the RTR server will bind itself to. Can be a string, in which case a number will be resolved.",
        }, {
                .id = 5003,
                .name = "server.queue",
@@ -200,9 +199,10 @@ static const struct option_field options[] = {
                .max = SOMAXCONN,
        }, {
                .id = 5004,
-               .name = "server.vrps-check-interval",
+               .name = "server.validation-interval",
                .type = &gt_uint,
-               .offset = offsetof(struct rpki_config, server.vrps_check_interval),
+               .offset = offsetof(struct rpki_config,
+                   server.validation_interval),
                .doc = "Interval used to look for updates at VRPs location",
                /*
                 * RFC 6810 and 8210:
@@ -431,7 +431,7 @@ set_default_values(void)
                return pr_enomem();
 
        rpki_config.server.queue = 10;
-       rpki_config.server.vrps_check_interval = 60;
+       rpki_config.server.validation_interval = 60;
        rpki_config.server.refresh_interval = 3600;
        rpki_config.server.retry_interval = 600;
        rpki_config.server.expire_interval = 7200;
@@ -621,9 +621,9 @@ config_get_server_queue(void)
 }
 
 unsigned int
-config_get_vrps_check_interval(void)
+config_get_validation_interval(void)
 {
-       return rpki_config.server.vrps_check_interval;
+       return rpki_config.server.validation_interval;
 }
 
 uint32_t
@@ -708,8 +708,7 @@ config_get_rsync_args(bool is_ta)
                break;
        }
 
-       pr_crit("Invalid sync strategy: '%u'",
-           rpki_config.sync_strategy);
+       pr_crit("Invalid sync strategy: '%u'", rpki_config.sync_strategy);
        /*
         * Return something usable anyway; don't want to check NULL.
         * This is supposed to be unreachable code anyway.
index 1eca1e09b8c9e2e57750df6ece99802c1cb259c6..c2e470f3e87786ea7e4952410da4fbca2248d6a6 100644 (file)
@@ -17,7 +17,7 @@ void free_rpki_config(void);
 char const *config_get_server_address(void);
 char const *config_get_server_port(void);
 int config_get_server_queue(void);
-unsigned int config_get_vrps_check_interval(void);
+unsigned int config_get_validation_interval(void);
 uint32_t config_get_refresh_interval(void);
 uint32_t config_get_retry_interval(void);
 uint32_t config_get_expire_interval(void);
index ccbb68037bede2e378992d96370d252865395317..c0ccae9d947f08110b37b175c9ccab2be830f668 100644 (file)
@@ -16,6 +16,11 @@ string_array_init(struct string_array *array, char const *const *values,
 
        array->length = len;
 
+       if (len == 0) {
+               array->array = NULL;
+               return 0;
+       }
+
        array->array = calloc(len, sizeof(char *));
        if (array->array == NULL)
                return -ENOMEM;
index ce0a836fdc8812598051c7ad3a379cbcbfceb7d8..14e0eb9d46a0ab901c804345dcd3e77c2557486c 100644 (file)
@@ -5,10 +5,7 @@
 #include "config/types.h"
 
 struct string_array {
-       /*
-        * BTW: The array size can be zero, in which case this will be NULL.
-        * TODO Remember to handle properly.
-        */
+       /* BTW: The array size can be zero, in which case this will be NULL. */
        char **array;
        size_t length;
 };
index 595600c575f4d2cb409810eceeb444334a2cccb8..a4f5e08997680321b7f17d775b06fefa8681f587 100644 (file)
@@ -6,10 +6,9 @@
 #include "log.h"
 #include "data_structure/common.h"
 
-/* TODO sizes used to be unsigned ints. Check callers. */
 #define DEFINE_ARRAY_LIST_STRUCT(name, elem_type)                      \
        struct name {                                                   \
-               /** Unidimensional array. */                            \
+               /** Unidimensional array. Initialized lazily. */        \
                elem_type *array;                                       \
                /** Number of elements in @array. */                    \
                size_t len;                                             \
        }
 
 #define DEFINE_ARRAY_LIST_FUNCTIONS(name, elem_type)                   \
-       static int                                                      \
+       static void                                                     \
        name##_init(struct name *list)                                  \
        {                                                               \
-               list->capacity = 8;                                     \
+               list->array = NULL;                                     \
                list->len = 0;                                          \
-               /* TODO I need lazy initialization of this badly */     \
-               list->array = malloc(list->capacity                     \
-                   * sizeof(elem_type));                               \
-               return (list->array != NULL) ? 0 : pr_enomem();         \
+               list->capacity = 0;                                     \
        }                                                               \
                                                                        \
        static void                                                     \
        name##_cleanup(struct name *list, void (*cb)(elem_type *))      \
        {                                                               \
                array_index i;                                          \
-               /* TODO recently added this. Use it more */             \
                if (cb != NULL)                                         \
                        for (i = 0; i < list->len; i++)                 \
                                cb(&list->array[i]);                    \
        {                                                               \
                elem_type *tmp;                                         \
                                                                        \
+               if (list->array == NULL) {                              \
+                       list->capacity = 8;                             \
+                       list->array = malloc(list->capacity             \
+                           * sizeof(elem_type));                       \
+                       if (list->array == NULL)                        \
+                               return pr_enomem();                     \
+               }                                                       \
+                                                                       \
                list->len++;                                            \
                while (list->len >= list->capacity) {                   \
                        list->capacity *= 2;                            \
        DEFINE_ARRAY_LIST_STRUCT(name, elem_type);                      \
        DEFINE_ARRAY_LIST_FUNCTIONS(name, elem_type)
 
-#define ARRAYLIST_FOREACH(list, cursor) for (                          \
-       cursor = (list)->array;                                         \
-       (cursor - ((typeof(cursor)) ((list)->array))) < (list)->len;    \
-       cursor++                                                        \
+/* c = cursor */
+#define ARRAYLIST_FOREACH(list, c) for (                               \
+       (c) = (list)->array;                                            \
+       ((c) != NULL) && (((c) - (typeof(c)) ((list)->array)) < (list)->len); \
+       (c)++                                                           \
 )
 
 #endif /* SRC_DATA_STRUCTURE_ARRAY_LIST_H_ */
index f12a3ca67983554b32eeaa360e6ef0dd8dde4213..d405137a81a1f06f69b6ae7a5fa82f87cb42ab90 100644 (file)
@@ -142,23 +142,3 @@ success:
        indexer->len--;
        return 0;
 }
-
-void
-arridx_print(char const *prefix, struct circular_indexer *i)
-{
-       array_index o;
-       array_index p;
-
-       pr_info("%s:", prefix);
-       if (i->indexes != NULL) {
-               pr_info("  indexes:");
-               p = i->first;
-               for (o = 0; o < i->len; o++) {
-                       pr_info("    %zu", p);
-                       p = i->indexes[p].next;
-               }
-       }
-
-       pr_info("  first:%zu current:%zu top:%zu len:%zu allow:%d", i->first,
-           i->current, i->top, i->len, i->allow_another_lap);
-}
index f065d8e3e630893a9b715bcc9be7eaeaddcc1ba7..b79db979f56c45c1df56c850d7a5fe6f2c2a7060 100644 (file)
@@ -102,7 +102,4 @@ array_index *arridx_next(struct circular_indexer *);
 /* Removes the *current* element. (You must be iterating.) */
 int arridx_remove(struct circular_indexer *);
 
-/* TODO remove me */
-void arridx_print(char const *, struct circular_indexer *);
-
 #endif /* SRC_DATA_STRUCTURE_CIRCULAR_INDEXER_H_ */
index 909eead71cb16e39f1c73af33d4fdca0b7c40f2e..73cd3a5fd9b3377125a4242c1f2682d72b3b43a2 100644 (file)
@@ -14,20 +14,15 @@ start_rtr_server(void)
 {
        int error;
 
-       error = vrps_init();
-       if (error)
-               goto end1;
-
-       error = clients_db_init();
-       if (error)
-               goto end2;
+       vrps_init();
+       clients_db_init();
 
        error = rtr_listen();
        rtr_cleanup(); /* TODO shouldn't this only happen on !error? */
 
        clients_db_destroy();
-end2:  vrps_destroy();
-end1:  return error;
+       vrps_destroy();
+       return error;
 }
 
 int
index fe02b76951dfe593812f3c6e634b143ad6e4aed4..0d728eff4ca41436f17a70eaea2f4ebeef9a3322 100644 (file)
@@ -643,6 +643,9 @@ certificate_validate_chain(X509 *cert, STACK_OF(X509_CRL) *crls)
        int ok;
        int error;
 
+       if (crls == NULL)
+               return 0; /* Certificate is TA; no chain validation needed. */
+
        state = state_retrieve();
        if (state == NULL)
                return -EINVAL;
@@ -661,8 +664,7 @@ certificate_validate_chain(X509 *cert, STACK_OF(X509_CRL) *crls)
        }
 
        X509_STORE_CTX_trusted_stack(ctx, validation_certs(state));
-       if (crls != NULL)
-               X509_STORE_CTX_set0_crls(ctx, crls);
+       X509_STORE_CTX_set0_crls(ctx, crls);
 
        /*
         * HERE'S THE MEAT OF LIBCRYPTO'S VALIDATION.
@@ -1437,8 +1439,11 @@ certificate_validate_extensions_ee(X509 *cert, OCTET_STRING_t *sid,
 /* Boilerplate code for CA certificate validation and recursive traversal. */
 int
 certificate_traverse(struct rpp *rpp_parent, struct rpki_uri const *cert_uri,
-    STACK_OF(X509_CRL) *crls, bool is_ta)
+    STACK_OF(X509_CRL) *crls)
 {
+/** Is the CA certificate the TA certificate? */
+#define IS_TA (rpp_parent == NULL)
+
        struct validation *state;
        X509 *cert;
        struct rfc5280_name *subject_name;
@@ -1463,26 +1468,24 @@ certificate_traverse(struct rpp *rpp_parent, struct rpki_uri const *cert_uri,
        error = certificate_load(cert_uri, &cert);
        if (error)
                goto revert_fnstack_and_debug;
-       if (!is_ta) {
-               error = certificate_validate_chain(cert, crls);
-               if (error)
-                       goto revert_cert;
-       }
-       error = certificate_validate_rfc6487(cert, &subject_name, is_ta);
+       error = certificate_validate_chain(cert, crls);
+       if (error)
+               goto revert_cert;
+       error = certificate_validate_rfc6487(cert, &subject_name, IS_TA);
        if (error)
                goto revert_cert;
-       error = is_ta
+       error = IS_TA
            ? certificate_validate_extensions_ta(cert, &mft, &policy)
            : certificate_validate_extensions_ca(cert, &mft, &refs, &policy);
        if (error)
                goto revert_subject_name;
 
-       error = refs_validate_ca(&refs, is_ta, rpp_parent);
+       error = refs_validate_ca(&refs, rpp_parent);
        if (error)
                goto revert_uri_and_refs;
 
        /* -- Validate the manifest (@mft) pointed by the certificate -- */
-       error = validation_push_cert(state, cert_uri, cert, policy, is_ta);
+       error = validation_push_cert(state, cert_uri, cert, policy, IS_TA);
        if (error)
                goto revert_uri_and_refs;
 
index 2c879d5d929a506d0a86fe210eb3fe76e2c30391..023d538b8efdd3dbd7264ecdb2355275011aa92d 100644 (file)
@@ -66,6 +66,6 @@ int certificate_validate_extensions_ee(X509 *, OCTET_STRING_t *,
     struct certificate_refs *, enum rpki_policy *);
 
 int certificate_traverse(struct rpp *, struct rpki_uri const *,
-    STACK_OF(X509_CRL) *, bool);
+    STACK_OF(X509_CRL) *);
 
 #endif /* SRC_OBJECT_CERTIFICATE_H_ */
index 7de259aece1b2681a56fb100b797dd749083bb79..58d3783f3edc59b4c842dec45c772271cc96974f 100644 (file)
@@ -200,33 +200,32 @@ roa_traverse(struct rpki_uri const *uri, struct rpp *pp,
 
        error = signed_object_args_init(&sobj_args, uri, crls, false);
        if (error)
-               goto end1;
+               goto revert_fnstack;
 
        error = signed_object_decode(&sobj_args, &arcs, roa_decode, &roa);
        if (error)
-               goto end2;
+               goto revert_sobj;
+
+       error = refs_validate_ee(&sobj_args.refs, pp, sobj_args.uri);
+       if (error)
+               goto revert_roa;
 
        error = vhandler_traverse_down(sobj_args.subject_name);
        if (error)
-               goto end3;
+               goto revert_roa;
 
        error = __handle_roa(roa, sobj_args.res);
        if (error)
-               goto end3;
+               goto revert_roa;
 
        error = vhandler_traverse_up();
-       if (error)
-               goto end3;
 
-       /* TODO why is this happening so late? */
-       error = refs_validate_ee(&sobj_args.refs, pp, sobj_args.uri);
-
-end3:
+revert_roa:
        ASN_STRUCT_FREE(asn_DEF_RouteOriginAttestation, roa);
-end2:
+revert_sobj:
        signed_object_args_cleanup(&sobj_args);
-end1:
-       pr_debug_rm("}");
+revert_fnstack:
        fnstack_pop();
+       pr_debug_rm("}");
        return error;
 }
index 16a69aa808edd0282fb7e376b4415e9dda3df1bd..6e98757ae01791d99f4d4314b78607c901db2257 100644 (file)
@@ -315,7 +315,7 @@ handle_tal_uri(struct tal *tal, struct rpki_uri const *uri, void *arg)
                goto end;
        }
 
-       error = certificate_traverse(NULL, uri, NULL, true);
+       error = certificate_traverse(NULL, uri, NULL);
        if (error) {
                switch (validation_pubkey_state(state)) {
                case PKS_INVALID:
index 1896355e2a649c0127de12a2a99f1d383fa71cb0..afed7e2d41515f57cf3341df8bc9e880b6744781 100644 (file)
--- a/src/rpp.c
+++ b/src/rpp.c
@@ -33,26 +33,14 @@ rpp_create(void)
 
        result = malloc(sizeof(struct rpp));
        if (result == NULL)
-               goto fail1;
+               return NULL;
 
-       if (uris_init(&result->certs) != 0)
-               goto fail2;
+       uris_init(&result->certs);
        result->crl_set = false;
-       if (uris_init(&result->roas) != 0)
-               goto fail3;
-       if (uris_init(&result->ghostbusters) != 0)
-               goto fail4;
+       uris_init(&result->roas);
+       uris_init(&result->ghostbusters);
 
        return result;
-
-fail4:
-       uris_cleanup(&result->roas, uri_cleanup);
-fail3:
-       uris_cleanup(&result->certs, uri_cleanup);
-fail2:
-       free(result);
-fail1:
-       return NULL;
 }
 
 void
@@ -146,7 +134,7 @@ rpp_traverse(struct rpp *pp)
 
        /* Use CRL stack to validate certificates, and also traverse them. */
        ARRAYLIST_FOREACH(&pp->certs, uri)
-               certificate_traverse(pp, uri, crls, false);
+               certificate_traverse(pp, uri, crls);
 
        /* Use valid address ranges to print ROAs that match them. */
        ARRAYLIST_FOREACH(&pp->roas, uri)
index 71fa960d8e1a4ba14198822f75b8225da61ac1de..d53085f0f413acee02e0eccbd9988ce74247d9e0 100644 (file)
@@ -32,37 +32,18 @@ int
 deltas_create(struct deltas **_result)
 {
        struct deltas *result;
-       int error;
 
        result = malloc(sizeof(struct deltas));
        if (result == NULL)
                return pr_enomem();
 
-       error = deltas_v4_init(&result->v4.adds);
-       if (error)
-               goto revert_result;
-       error = deltas_v4_init(&result->v4.removes);
-       if (error)
-               goto revert_v4_adds;
-       error = deltas_v6_init(&result->v6.adds);
-       if (error)
-               goto revert_v4_removes;
-       error = deltas_v6_init(&result->v6.removes);
-       if (error)
-               goto revert_v6_adds;
+       deltas_v4_init(&result->v4.adds);
+       deltas_v4_init(&result->v4.removes);
+       deltas_v6_init(&result->v6.adds);
+       deltas_v6_init(&result->v6.removes);
 
        *_result = result;
        return 0;
-
-revert_v6_adds:
-       deltas_v6_cleanup(&result->v6.adds, NULL);
-revert_v4_removes:
-       deltas_v4_cleanup(&result->v4.removes, NULL);
-revert_v4_adds:
-       deltas_v4_cleanup(&result->v4.adds, NULL);
-revert_result:
-       free(result);
-       return error;
 }
 
 void
index b40bda2e2502dab41ebe5382ae14ec5d2462a7d6..63940f33b7f2fa55fc3f9ac4d8d5eed8965d41a1 100644 (file)
@@ -3,51 +3,28 @@
 DEFINE_ARRAY_LIST_FUNCTIONS(v4_addresses, struct v4_address)
 DEFINE_ARRAY_LIST_FUNCTIONS(v6_addresses, struct v6_address)
 
-static void
-v4_address_destroy(struct v4_address *addr)
-{
-       free(addr);
-}
-
-static void
-v6_address_destroy(struct v6_address *addr)
-{
-       free(addr);
-}
-
 int
 roa_create(u_int32_t as, struct roa **_result)
 {
        struct roa *result;
-       int error;
 
        result = malloc(sizeof(struct roa));
        if (result == NULL)
                return pr_enomem();
 
        result->as = as;
-       error = v4_addresses_init(&result->addrs4);
-       if (error)
-               goto revert_result;
-       error = v6_addresses_init(&result->addrs6);
-       if (error)
-               goto revert_addrs4;
+       v4_addresses_init(&result->addrs4);
+       v6_addresses_init(&result->addrs6);
 
        *_result = result;
        return 0;
-
-revert_addrs4:
-       v4_addresses_cleanup(&result->addrs4, v4_address_destroy);
-revert_result:
-       free(result);
-       return error;
 }
 
 void
 roa_destroy(struct roa *roa)
 {
-       v4_addresses_cleanup(&roa->addrs4, v4_address_destroy);
-       v6_addresses_cleanup(&roa->addrs6, v6_address_destroy);
+       v4_addresses_cleanup(&roa->addrs4, NULL);
+       v6_addresses_cleanup(&roa->addrs6, NULL);
 }
 
 int
index 86d84df73b3c540f4915ec20cc33159fba4bebe0..7bd0a7b676f83b6bdfa59ecb89eb425c94623257 100644 (file)
@@ -38,7 +38,7 @@ node_create(struct rfc5280_name *subject_name, struct node *parent)
        node->subject_name = subject_name;
        x509_name_get(subject_name);
        node->parent = parent;
-       node->children.array = NULL;
+       nodes_init(&node->children);
        node->roa = NULL;
        return node;
 }
@@ -47,8 +47,7 @@ static void
 node_destroy(struct node *node)
 {
        x509_name_put(node->subject_name);
-       if (node->children.array != NULL)
-               nodes_cleanup(&node->children, node_destroy);
+       nodes_cleanup(&node->children, node_destroy);
        if (node->roa != NULL)
                roa_destroy(node->roa);
        free(node);
@@ -60,12 +59,6 @@ node_add_child(struct node *parent, struct rfc5280_name *subject_name)
        struct node *child;
        int error;
 
-       if (parent->children.array == NULL) {
-               error = nodes_init(&parent->children);
-               if (error)
-                       return error;
-       }
-
        child = node_create(subject_name, parent);
        if (child == NULL)
                return pr_enomem();
@@ -363,8 +356,7 @@ handle_delta_children(struct nodes *children1, struct nodes *children2,
         * Changes to one function might need to cascade to the other.
         */
 
-       struct node *c1array;
-       array_index c1; /* counter for c1array */
+       struct node *c1node;
 
        struct node *c2array;
        array_index c2; /* counter for c2array */
@@ -374,21 +366,20 @@ handle_delta_children(struct nodes *children1, struct nodes *children2,
 
        int error = 0;
 
-       c1array = children1->array;
        c2array = children2->array;
        arridx_init(&c2indexer, children2->len);
 
-       for (c1 = 0; c1 < children1->len; c1++) {
-               if (find_subject_name(&c2indexer, c1array[c1].subject_name,
+       ARRAYLIST_FOREACH(children1, c1node) {
+               if (find_subject_name(&c2indexer, c1node->subject_name,
                    c2array, &c2)) {
-                       error = compute_deltas_node(&c1array[c1], &c2array[c2],
+                       error = compute_deltas_node(c1node, &c2array[c2],
                            deltas);
                        if (error)
                                goto end;
 
                        error = arridx_remove(&c2indexer);
                } else {
-                       error = add_all_deltas(&c1array[c1], deltas, DELTA_RM);
+                       error = add_all_deltas(c1node, deltas, DELTA_RM);
                }
                if (error)
                        goto end;
index b80c6bcb8a123316a3ac47f08f9c4e9429153424..b6b370878dede729448e0b11b00ccf99333a5a7e 100644 (file)
@@ -16,7 +16,7 @@ void roa_tree_put(struct roa_tree *);
 
 int roa_tree_foreach_roa(struct roa_tree *, vrp_foreach_cb, void *);
 
-/* TODO rename to tree handler or whatever */
+/* TODO (urgent) rename to tree handler or whatever */
 int forthandler_reset(struct roa_tree *);
 int forthandler_go_down(struct roa_tree *, struct rfc5280_name *);
 int forthandler_go_up(struct roa_tree *);
index b94c0767b99f8c8c98431b0b144ec0f223e5d04f..97d7cbcee9d81da34ce47ad699cf7081fe97a3de 100644 (file)
@@ -41,16 +41,12 @@ delta_destroy(struct delta *delta)
        deltas_destroy(delta->deltas);
 }
 
-int
+void
 vrps_init(void)
 {
-       int error;
-
        state.base = NULL;
 
-       error = deltas_db_init(&state.deltas);
-       if (error)
-               return error;
+       deltas_db_init(&state.deltas);
 
        /*
         * Use the same start serial, the session ID will avoid
@@ -62,17 +58,13 @@ vrps_init(void)
        /* Get the bits that'll fit in session_id */
        state.v0_session_id = time(NULL) & 0xFFFF;
        /* Minus 1 to prevent same ID */
-       /*
-        * TODO Assigning an int (and potentially negative) to a uint16_t.
-        * Is this legal?
-        */
-       state.v1_session_id = state.v0_session_id - 1;
+       state.v1_session_id = (state.v0_session_id != 0)
+           ? (state.v0_session_id - 1)
+           : (0xFFFFu);
 
        sem_init(&rlock, 0, 1);
        sem_init(&wlock, 0, 1);
        rcounter = 0;
-
-       return 0;
 }
 
 void
index 40cbb6b3da3970f48edf4c19e827b7007fa5455f..6b7eed6fbe8ec23474621a6d9b1866f8b524f7f6 100644 (file)
@@ -17,7 +17,7 @@ enum delta_status {
        DS_DIFF_AVAILABLE,
 };
 
-int vrps_init(void);
+void vrps_init(void);
 void vrps_destroy(void);
 
 int vrps_update(struct roa_tree *, struct deltas *);
index 6a5313e9631aeed451d036f02ff34be30c40cdbb..2b09b85e330ce383b6b5fa8702f78d62eee1e925 100644 (file)
@@ -47,8 +47,8 @@ send_commmon_exchange(struct sender_common *common,
 }
 
 /*
- * TODO The semaphoring is bonkers. The code keeps locking, storing a value,
- * unlocking, locking again, and using the old value.
+ * TODO (urgent) The semaphoring is bonkers. The code keeps locking, storing a
+ * value, unlocking, locking again, and using the old value.
  * It doesn't look like it's a problem for now, but eventually will be, when old
  * delta forgetting is implemented.
  * I'm going to defer this because it shouldn't be done during the merge.
index 66316b6f9095ccf9bc40af3a7e1a2052e54717f2..7a73ec1ac7689c7ca9ef8f74035e4a8e8a97c463 100644 (file)
@@ -19,7 +19,7 @@
 #include "rtr/err_pdu.h"
 #include "rtr/pdu.h"
 
-/* TODO Support both RTR v0 an v1 */
+/* TODO (next iteration) Support both RTR v0 an v1 */
 #define RTR_VERSION_SUPPORTED  RTR_V0
 
 volatile bool loop;
index ef0be1794adaf2584be4702e02a6d0580d111c87..828259251a306cc27d4967aa2b74e1e93c340605 100644 (file)
@@ -264,12 +264,8 @@ validation_push_cert(struct validation *state, struct rpki_uri const *cert_uri,
        }
 
        cert->uri = *cert_uri;
-       error = serial_numbers_init(&cert->serials);
-       if (error)
-               goto end2;
-       error = subjects_init(&cert->subjects);
-       if (error)
-               goto end3;
+       serial_numbers_init(&cert->serials);
+       subjects_init(&cert->subjects);
        cert->resources = resources_create(false);
        if (cert->resources == NULL) {
                error = pr_enomem();
@@ -306,8 +302,8 @@ validation_push_cert(struct validation *state, struct rpki_uri const *cert_uri,
 
 end5:  resources_destroy(cert->resources);
 end4:  subjects_cleanup(&cert->subjects, subject_cleanup);
-end3:  serial_numbers_cleanup(&cert->serials, serial_cleanup);
-end2:  free(cert);
+       serial_numbers_cleanup(&cert->serials, serial_cleanup);
+       free(cert);
 end1:  return error;
 }
 
index 9c07a5128b5ae60b1fe7a23711af3e8c029b7da6..621ce1fbf3ff796440e7192fce74f29c623a6a52 100644 (file)
@@ -116,7 +116,7 @@ check_vrps_updates(void *param_void)
                pr_debug("Database updated successfully. Sleeping...");
 
 sleep:
-               sleep(config_get_vrps_check_interval());
+               sleep(config_get_validation_interval());
        } while (true);
 
        return NULL;