diff options
author | Vladimír Čunát <vladimir.cunat@nic.cz> | 2023-08-04 19:22:23 +0200 |
---|---|---|
committer | Vladimír Čunát <vladimir.cunat@nic.cz> | 2023-08-17 15:58:24 +0200 |
commit | 321b39bdebbead9dfd339b40197d4c7e0bd27d61 (patch) | |
tree | d35228daf68553ed3f4535ede5a5e8661a5a19cf /modules | |
parent | Merge branch 'rm-poetry-lock' into '6.0' (diff) | |
download | knot-resolver-321b39bdebbead9dfd339b40197d4c7e0bd27d61.tar.xz knot-resolver-321b39bdebbead9dfd339b40197d4c7e0bd27d61.zip |
hints: merge RRs instead of replacing them
We had this behavior in 5.x.
Lua level: affects hints.set() and hints['name'] and hints.add_hosts()
YAML level: /local-data/addresses and /local-data/addresses-files
I considered various approaches when writing this. This one won because
in /etc/hosts like files a name can be repeated with arbitrary lines
in between, and users can reasonably expect it to collect all addresses.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/hints/hints.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/modules/hints/hints.c b/modules/hints/hints.c index ccbc9880..b5f8e3de 100644 --- a/modules/hints/hints.c +++ b/modules/hints/hints.c @@ -142,11 +142,12 @@ static int add_pair(const struct hints_data *data, const char *name, const char } else { ret = knot_rrset_add_rdata(&rrs, (const uint8_t *)&ia.ip4.sin_addr, 4, NULL); } - if (!ret) ret = kr_rule_local_data_ins(&rrs, NULL, KR_RULE_TAGS_ALL); + if (!ret) ret = kr_rule_local_data_merge(&rrs, KR_RULE_TAGS_ALL); if (!ret && data->use_nodata) { rrs.type = KNOT_RRTYPE_CNAME; rrs.rrs.count = 0; rrs.rrs.size = 0; + // no point in the _merge() variant here ret = kr_rule_local_data_ins(&rrs, NULL, KR_RULE_TAGS_ALL); } @@ -167,7 +168,9 @@ static int add_reverse_pair(const struct hints_data *data, const char *name, con return kr_error(EINVAL); int ret = knot_rrset_add_rdata(&rrs, ptr_name, knot_dname_size(ptr_name), NULL); if (!ret) { - ret = kr_rule_local_data_ins(&rrs, NULL, KR_RULE_TAGS_ALL); + // We use _merge(). Using multiple PTR RRs is not recommended generally, + // but here it seems better than choosing any "arbitrarily". + ret = kr_rule_local_data_merge(&rrs, KR_RULE_TAGS_ALL); knot_rdataset_clear(&rrs.rrs, NULL); } return ret; @@ -481,15 +484,13 @@ int hints_init(struct kr_module *module) module->layer = &layer; static const struct kr_prop props[] = { - /* FIXME(decide): .set() and .del() used to work on individual RRs; - * now they overwrite or delete whole RRsets. - * Also, .get() doesn't work at all. + /* TODO(decide): .del() used to work on individual RRs; + * now it deletes whole RRsets. Also, .get() doesn't work at all. + * + * We'll probably be deprecating access direct through these non-declarative + * commands (set, get, del) which are also usable dynamically. * - * It really depends what kind of config/API we'll be exposing to user. - * - Manipulating whole RRsets generally makes more sense to me. - * (But hints.set() currently can't even insert larger sets.) - * - We'll probably be deprecating access through these non-declarative - * commands (set, get, del) which are also usable dynamically. + * For .set() and .add_hosts() see the RW transaction note at kr_rule_local_data_merge() */ { &hint_set, "set", "Set {name, address} hint.", }, { &hint_del, "del", "Delete one {name, address} hint or all addresses for the name.", }, |