1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/* Copyright (C) 2022 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <stdbool.h>
#include <stdint.h>
#define SERIAL_MAX_INCREMENT 2147483647
/*!
* \brief result of serial comparison. LOWER means that the first serial is lower that the second.
*
* Example: (serial_compare(a, b) & SERIAL_MASK_LEQ) means "a <= b".
*/
typedef enum {
SERIAL_INCOMPARABLE = 0x0,
SERIAL_LOWER = 0x1,
SERIAL_GREATER = 0x2,
SERIAL_EQUAL = 0x3,
SERIAL_MASK_LEQ = SERIAL_LOWER,
SERIAL_MASK_GEQ = SERIAL_GREATER,
} serial_cmp_result_t;
/*!
* \brief Compares two zone serials.
*/
serial_cmp_result_t serial_compare(uint32_t s1, uint32_t s2);
inline static bool serial_equal(uint32_t a, uint32_t b)
{
return serial_compare(a, b) == SERIAL_EQUAL;
}
/*!
* \brief Get (next) serial for given serial update policy.
*
* \param current Current SOA serial.
* \param policy SERIAL_POLICY_INCREMENT, SERIAL_POLICY_UNIXTIME or
* SERIAL_POLICY_DATESERIAL.
* \param must_increment The minimum difference to the current value.
* 0 only ensures policy; 1 also increments.
*
* \return New serial.
*/
uint32_t serial_next(uint32_t current, int policy, uint32_t must_increment);
typedef struct {
uint32_t serial;
bool valid;
} kserial_t;
/*!
* \brief Compares two kserials.
*
* If any of them is invalid, they are INCOMPARABLE.
*/
serial_cmp_result_t kserial_cmp(kserial_t a, kserial_t b);
inline static bool kserial_equal(kserial_t a, kserial_t b)
{
return kserial_cmp(a, b) == SERIAL_EQUAL;
}
|