From: pcarana Date: Thu, 2 May 2019 20:10:47 +0000 (-0500) Subject: Fix deltas update and fetch (serial wasn't correctly used) X-Git-Tag: v0.0.2~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c81526b4dce6ef3732d8887f1b1f657788a95fd3;p=thirdparty%2FFORT-validator.git Fix deltas update and fetch (serial wasn't correctly used) --- diff --git a/src/rtr/db/vrps.c b/src/rtr/db/vrps.c index b5b753ed..0be01e52 100644 --- a/src/rtr/db/vrps.c +++ b/src/rtr/db/vrps.c @@ -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);