]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Fix deltas update and fetch (serial wasn't correctly used)
authorpcarana <pc.moreno2099@gmail.com>
Thu, 2 May 2019 20:10:47 +0000 (15:10 -0500)
committerpcarana <pc.moreno2099@gmail.com>
Thu, 2 May 2019 20:10:47 +0000 (15:10 -0500)
src/rtr/db/vrps.c

index b5b753ed0d0eb271c9ad8b6a84d96a02f7e2138d..0be01e5243ac98505114ecbfcfc8aee05fc1e447 100644 (file)
@@ -91,7 +91,7 @@ vrps_update(struct roa_table *new_roas, struct deltas *new_deltas)
        rwlock_write_lock(&lock);
 
        if (new_deltas != NULL) {
-               new_delta.serial = state.current_serial + 1;
+               new_delta.serial = state.current_serial;
                new_delta.deltas = new_deltas;
                error = deltas_db_add(&state.deltas, &new_delta);
                if (error)
@@ -140,11 +140,17 @@ deltas_db_status(uint32_t *serial, enum delta_status *result)
        }
 
        /* Is the last version? */
-       if (*serial == state.current_serial) {
+       if (*serial == (state.current_serial - 1)) {
                *result = DS_NO_DIFF;
                goto rlock_succeed;
        }
 
+       /* The first serial isn't at deltas */
+       if (*serial == START_SERIAL) {
+               *result = DS_DIFF_AVAILABLE;
+               goto rlock_succeed;
+       }
+
        /* Get the delta corresponding to the serial */
        ARRAYLIST_FOREACH(&state.deltas, delta)
                if (delta->serial == *serial) {
@@ -155,12 +161,6 @@ deltas_db_status(uint32_t *serial, enum delta_status *result)
        /* No match yet, release lock */
        rwlock_unlock(&lock);
 
-       /* The first serial isn't at deltas */
-       if (*serial == START_SERIAL) {
-               *result = DS_DIFF_AVAILABLE;
-               return 0;
-       }
-
        /* Reached end, diff can't be determined */
        *result = DS_DIFF_UNDETERMINED;
        return 0;
@@ -201,15 +201,16 @@ vrps_foreach_delta_roa(uint32_t from, uint32_t to, vrp_foreach_cb cb, void *arg)
 
        ARRAYLIST_FOREACH(&state.deltas, d) {
                if (!from_found) {
-                       if (d->serial >= from)
+                       if (d->serial > from)
                                from_found = true;
-               } else {
-                       if (d->serial > to)
-                               break;
-                       error = deltas_foreach(d->deltas, cb, arg);
-                       if (error)
-                               break;
+                       else
+                               continue;
                }
+               if (d->serial > to)
+                       break;
+               error = deltas_foreach(d->deltas, cb, arg);
+               if (error)
+                       break;
        }
 
        rwlock_unlock(&lock);