Commit 77a3e384 authored by Marek Vavrusa's avatar Marek Vavrusa

utils: renamed knot_serial_compare and added headers

parent 5a99c7ce
......@@ -8,6 +8,7 @@
#include "libknot/rdata.h"
#include "knot/server/zones.h"
#include "common/descriptor.h"
#include "libknot/util/utils.h"
/*! \brief Current IXFR answer sections. */
enum {
......@@ -134,7 +135,7 @@ static int ixfr_load_chsets(knot_changesets_t **chgsets, const zone_t *zone,
const knot_rrset_t *our_soa = knot_node_rrset(apex, KNOT_RRTYPE_SOA);
uint32_t serial_to = knot_rdata_soa_serial(our_soa);
uint32_t serial_from = knot_rdata_soa_serial(their_soa);
int ret = ns_serial_compare(serial_to, serial_from);
int ret = knot_serial_compare(serial_to, serial_from);
if (ret <= 0) { /* We have older/same age zone. */
return KNOT_EUPTODATE;
}
......@@ -390,7 +391,7 @@ int ixfr_process_answer(knot_ns_xfr_t *xfr)
return KNOT_ERROR;
}
if (ns_serial_compare(
if (knot_serial_compare(
knot_rdata_soa_serial(chgsets->first_soa),
knot_rdata_soa_serial(zone_soa))
> 0) {
......
......@@ -39,11 +39,11 @@
#include "knot/updates/changesets.h"
#include "knot/updates/ddns.h"
#include "knot/updates/xfr-in.h"
#include "libknot/packet/wire.h"
#include "knot/zone/zone-contents.h"
#include "knot/zone/zone-diff.h"
#include "knot/zone/zone.h"
#include "knot/zone/zonedb.h"
#include "libknot/util/utils.h"
/*!
* \brief Apply jitter to time interval.
......@@ -839,7 +839,7 @@ uint32_t zones_next_serial(zone_t *zone)
}
/* If the new serial is 'lower' or equal than the new one, warn the user.*/
if (ns_serial_compare(old_serial, new_serial) >= 0) {
if (knot_serial_compare(old_serial, new_serial) >= 0) {
log_zone_warning("New serial will be lower than "
"the current one. Old: %"PRIu32" "
"new: %"PRIu32".\n",
......
......@@ -842,7 +842,7 @@ static int knot_ddns_process_add_soa(knot_node_t *node,
}
/* Check that the serial is indeed larger than the current one*/
assert(ns_serial_compare(knot_rdata_soa_serial(removed),
assert(knot_serial_compare(knot_rdata_soa_serial(removed),
knot_rdata_soa_serial(rr)) < 0);
/* 1) Store it to 'changes', together with its RRSIGs. */
......@@ -1798,7 +1798,7 @@ int knot_ddns_process_update(knot_zone_contents_t *zone,
if (knot_rrset_type(rr) == KNOT_RRTYPE_SOA
&& (knot_rrset_class(rr) == KNOT_CLASS_NONE
|| knot_rrset_class(rr) == KNOT_CLASS_ANY
|| ns_serial_compare(knot_rdata_soa_serial(rr),
|| knot_serial_compare(knot_rdata_soa_serial(rr),
sn) <= 0)) {
// This ignores also SOA removals
dbg_ddns_verb("Ignoring SOA...\n");
......@@ -1823,7 +1823,7 @@ int knot_ddns_process_update(knot_zone_contents_t *zone,
int64_t sn_rr = knot_rdata_soa_serial(rr);
dbg_ddns_verb("Replacing SOA. Old serial: %"PRId64", "
"new serial: %"PRId64"\n", sn_new, sn_rr);
assert(ns_serial_compare(sn_rr, sn) > 0);
assert(knot_serial_compare(sn_rr, sn) > 0);
assert(rr_copy != NULL);
sn_new = sn_rr;
soa_end = rr_copy;
......
......@@ -38,6 +38,7 @@
#include "common/lists.h"
#include "common/descriptor.h"
#include "libknot/rdata.h"
#include "libknot/util/utils.h"
#define KNOT_NS_TSIG_FREQ 100
......@@ -98,7 +99,7 @@ dbg_xfrin_exec(
return KNOT_EMALF; // maybe some other error
}
return (ns_serial_compare(local_serial, remote_serial) < 0);
return (knot_serial_compare(local_serial, remote_serial) < 0);
}
/*----------------------------------------------------------------------------*/
......
......@@ -24,6 +24,7 @@
#include "knot/zone/zone-diff.h"
#include "common/descriptor.h"
#include "libknot/rdata.h"
#include "libknot/util/utils.h"
struct zone_diff_param {
knot_zone_tree_t *nodes;
......@@ -79,7 +80,7 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
dbg_zonediff("zone_diff: load_soas: Got bad SOA.\n");
}
if (ns_serial_compare(soa_serial1, soa_serial2) == 0) {
if (knot_serial_compare(soa_serial1, soa_serial2) == 0) {
dbg_zonediff("zone_diff: "
"second zone must have higher serial than the "
"first one. (%"PRId64" vs. %"PRId64")\n",
......@@ -87,7 +88,7 @@ static int knot_zone_diff_load_soas(const knot_zone_contents_t *zone1,
return KNOT_ENODIFF;
}
if (ns_serial_compare(soa_serial1, soa_serial2) > 0) {
if (knot_serial_compare(soa_serial1, soa_serial2) > 0) {
dbg_zonediff("zone_diff: "
"second zone must have higher serial than the "
"first one. (%"PRId64" vs. %"PRId64")\n",
......
......@@ -55,14 +55,14 @@ knot_lookup_table_t *knot_lookup_by_id(knot_lookup_table_t *table,
/*----------------------------------------------------------------------------*/
static int32_t ns_serial_difference(uint32_t s1, uint32_t s2)
static int32_t serial_difference(uint32_t s1, uint32_t s2)
{
return (((int64_t)s1 - s2) % ((int64_t)1 << 32));
}
int ns_serial_compare(uint32_t s1, uint32_t s2)
int knot_serial_compare(uint32_t s1, uint32_t s2)
{
int32_t diff = ns_serial_difference(s1, s2);
int32_t diff = serial_difference(s1, s2);
return (s1 == s2) /* s1 equal to s2 */
? 0
:((diff >= 1 && diff < ((uint32_t)1 << 31))
......
......@@ -182,7 +182,7 @@ static inline void knot_wire_write_u64(uint8_t *pos, uint64_t data)
* \retval > 0 if s1 is larger than s2.
* \retval == 0 if s1 is equal to s2.
*/
int ns_serial_compare(uint32_t s1, uint32_t s2);
int knot_serial_compare(uint32_t s1, uint32_t s2);
#endif /* _KNOT_UTILS_H_ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment