Commit 3cca22d9 authored by Daniel Salzman's avatar Daniel Salzman

conf: add caching of some edns parameters

parent 312109ec
......@@ -234,6 +234,9 @@ int conf_post_open(
conf->hostname = sockaddr_hostname();
conf->cache.srv_nsid = conf_get(conf, C_SRV, C_NSID);
conf->cache.srv_max_udp_payload = conf_get(conf, C_SRV, C_MAX_UDP_PAYLOAD);
conf_activate_modules(conf, NULL, &conf->query_modules, &conf->query_plan);
return KNOT_EOK;
......
......@@ -44,6 +44,23 @@
log_msg(severity, "config, " msg, ##__VA_ARGS__); \
} while (0)
/*! Configuration getter output. */
typedef struct {
/*! Item description. */
const yp_item_t *item;
/*! Whole data (can be array). */
const uint8_t *blob;
/*! Whole data length. */
size_t blob_len;
// Public items.
/*! Current single data. */
const uint8_t *data;
/*! Current single data length. */
size_t len;
/*! Value getter return code. */
int code;
} conf_val_t;
/*! Configuration context. */
typedef struct {
/*! Currently used namedb api. */
......@@ -70,6 +87,12 @@ typedef struct {
/*! Current config file (for reload if started with config file). */
char *filename;
/*! Cached critical confdb items. */
struct {
conf_val_t srv_nsid;
conf_val_t srv_max_udp_payload;
} cache;
/*! List of active query modules. */
list_t query_modules;
/*! Default query modules plan. */
......
......@@ -42,23 +42,6 @@ typedef struct {
knot_tsig_key_t key;
} conf_remote_t;
/*! Configuration getter output. */
typedef struct {
/*! Item description. */
const yp_item_t *item;
/*! Whole data (can be array). */
const uint8_t *blob;
/*! Whole data length. */
size_t blob_len;
// Public items.
/*! Current single data. */
const uint8_t *data;
/*! Current single data length. */
size_t len;
/*! Value getter return code. */
int code;
} conf_val_t;
/*! Configuration section iterator. */
typedef struct {
/*! Item description. */
......
......@@ -221,8 +221,8 @@ static int answer_edns_init(const knot_pkt_t *query, knot_pkt_t *resp,
}
/* Initialize OPT record. */
conf_val_t val = conf_get(conf(), C_SRV, C_MAX_UDP_PAYLOAD);
int ret = knot_edns_init(&qdata->opt_rr, conf_int(&val), 0,
conf_val_t *max_payload = &conf()->cache.srv_max_udp_payload;
int ret = knot_edns_init(&qdata->opt_rr, conf_int(max_payload), 0,
KNOT_EDNS_VERSION, qdata->mm);
if (ret != KNOT_EOK) {
return ret;
......@@ -239,12 +239,12 @@ static int answer_edns_init(const knot_pkt_t *query, knot_pkt_t *resp,
}
/* Append NSID if requested and available. */
val = conf_get(conf(), C_SRV, C_NSID);
if (knot_edns_has_option(query->opt_rr, KNOT_EDNS_OPTION_NSID)) {
conf_val_t *nsid = &conf()->cache.srv_nsid;
size_t nsid_len;
const uint8_t *nsid_data = conf_bin(&val, &nsid_len);
const uint8_t *nsid_data = conf_bin(nsid, &nsid_len);
if (val.code != KNOT_EOK) {
if (nsid->code != KNOT_EOK) {
ret = knot_edns_add_option(&qdata->opt_rr,
KNOT_EDNS_OPTION_NSID,
strlen(conf()->hostname),
......@@ -336,9 +336,9 @@ static int prepare_answer(const knot_pkt_t *query, knot_pkt_t *resp, knot_layer_
if (has_limit) {
resp->max_size = KNOT_WIRE_MIN_PKTSIZE;
if (knot_pkt_has_edns(query)) {
conf_val_t val = conf_get(conf(), C_SRV, C_MAX_UDP_PAYLOAD);
conf_val_t *max_payload = &conf()->cache.srv_max_udp_payload;
uint16_t client = knot_edns_get_payload(query->opt_rr);
uint16_t server = conf_int(&val);
uint16_t server = conf_int(max_payload);
uint16_t transfer = MIN(client, server);
resp->max_size = MAX(resp->max_size, transfer);
}
......
......@@ -103,8 +103,8 @@ static int prepare_edns(zone_t *zone, knot_pkt_t *pkt)
}
knot_rrset_t opt_rr;
conf_val_t udp_max = conf_get(conf(), C_SRV, C_MAX_UDP_PAYLOAD);
int ret = knot_edns_init(&opt_rr, conf_int(&udp_max), 0,
conf_val_t *max_payload = &conf()->cache.srv_max_udp_payload;
int ret = knot_edns_init(&opt_rr, conf_int(max_payload), 0,
KNOT_EDNS_VERSION, &pkt->mm);
if (ret != KNOT_EOK) {
return ret;
......
......@@ -64,8 +64,8 @@ int zone_load_check(conf_t *conf, zone_contents_t *contents)
/* Check minimum EDNS0 payload if signed. (RFC4035/sec. 3) */
if (zone_contents_is_signed(contents)) {
conf_val_t val = conf_get(conf, C_SRV, C_MAX_UDP_PAYLOAD);
if (conf_int(&val) < KNOT_EDNS_MIN_DNSSEC_PAYLOAD) {
conf_val_t *max_payload = &conf->cache.srv_max_udp_payload;
if (conf_int(max_payload) < KNOT_EDNS_MIN_DNSSEC_PAYLOAD) {
log_zone_error(zone_name, "EDNS payload size is "
"lower than %u bytes for DNSSEC zone",
KNOT_EDNS_MIN_DNSSEC_PAYLOAD);
......
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