Skip to content
Snippets Groups Projects
Commit 6e6ff5d1 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

nameserver: refactor EDNS EXPIRE setting

parent 5d4d5765
No related branches found
No related tags found
No related merge requests found
Pipeline #130975 passed
......@@ -363,20 +363,23 @@ static int answer_edns_put(knot_pkt_t *resp, knotd_qdata_t *qdata)
/* Add EXPIRE if space and not catalog zone, which cannot expire. */
if (knot_pkt_edns_option(qdata->query, KNOT_EDNS_OPTION_EXPIRE) != NULL &&
qdata->extra->contents != NULL && !qdata->extra->zone->is_catalog_flag) {
int64_t timer = qdata->extra->zone->timers.next_expire;
timer = knot_time_min(timer, ATOMIC_GET(qdata->extra->contents->dnssec_expire)); // NOOP if zero
timer = (timer == 0 ? zone_soa_expire(qdata->extra->zone) : timer - time(NULL));
timer = MAX(timer, 0);
uint32_t timer_be;
knot_wire_write_u32((uint8_t *)&timer_be, (uint32_t)timer);
uint16_t expire_size = KNOT_EDNS_OPTION_HDRLEN + sizeof(timer_be);
knot_time_t expire = knot_time_min(ATOMIC_GET(qdata->extra->contents->dnssec_expire),
qdata->extra->zone->timers.next_expire);
uint32_t timer;
if (expire == 0) {
timer = zone_soa_expire(qdata->extra->zone);
} else {
timer = MAX(0, expire - time(NULL));
}
timer = htobe32(timer);
uint16_t expire_size = KNOT_EDNS_OPTION_HDRLEN + sizeof(timer);
if (knot_pkt_reserve(resp, expire_size) == KNOT_EOK) {
ret = knot_pkt_reclaim(resp, expire_size);
assert(ret == KNOT_EOK);
ret = knot_edns_add_option(&qdata->opt_rr, KNOT_EDNS_OPTION_EXPIRE,
sizeof(timer_be), (uint8_t *)&timer_be,
sizeof(timer), (uint8_t *)&timer,
qdata->mm);
if (ret != KNOT_EOK) {
return ret;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment