From f0265b8fa691c41975e395dfd58dc41699adb902 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Wed, 24 Mar 2021 10:58:09 +1100 Subject: [PATCH] Make whether to follow additional data records generic Adds dns_rdatatype_followadditional() and DNS_RDATATYPEATTR_FOLLOWADDITIONAL --- lib/dns/include/dns/rdata.h | 17 +++++++++++++++++ lib/dns/rdata.c | 9 +++++++++ lib/dns/rdata/in_1/srv_33.c | 2 +- lib/ns/query.c | 19 ++++--------------- 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/lib/dns/include/dns/rdata.h b/lib/dns/include/dns/rdata.h index 359f69d674..476ef5f9c7 100644 --- a/lib/dns/include/dns/rdata.h +++ b/lib/dns/include/dns/rdata.h @@ -695,6 +695,21 @@ dns_rdatatype_atcname(dns_rdatatype_t type); * */ +bool +dns_rdatatype_followadditional(dns_rdatatype_t type); +/*%< + * Return true if adding a record of type 'type' to the ADDITIONAL section + * of a message can itself trigger the addition of still more data to the + * additional section. + * + * (For example: adding SRV to the ADDITIONAL section may trigger + * the addition of address records associated with that SRV.) + * + * Requires: + * \li 'type' is a valid rdata type. + * + */ + unsigned int dns_rdatatype_attributes(dns_rdatatype_t rdtype); /*%< @@ -729,6 +744,8 @@ dns_rdatatype_attributes(dns_rdatatype_t rdtype); #define DNS_RDATATYPEATTR_ATPARENT 0x00000200U /*% Can exist along side a CNAME */ #define DNS_RDATATYPEATTR_ATCNAME 0x00000400U +/*% Follow additional */ +#define DNS_RDATATYPEATTR_FOLLOWADDITIONAL 0x00000800U dns_rdatatype_t dns_rdata_covers(dns_rdata_t *rdata); diff --git a/lib/dns/rdata.c b/lib/dns/rdata.c index 6fb7bc3d22..c8d684a38c 100644 --- a/lib/dns/rdata.c +++ b/lib/dns/rdata.c @@ -2131,6 +2131,15 @@ dns_rdatatype_atparent(dns_rdatatype_t type) { return (false); } +bool +dns_rdatatype_followadditional(dns_rdatatype_t type) { + if ((dns_rdatatype_attributes(type) & + DNS_RDATATYPEATTR_FOLLOWADDITIONAL) != 0) { + return (true); + } + return (false); +} + bool dns_rdataclass_ismeta(dns_rdataclass_t rdclass) { if (rdclass == dns_rdataclass_reserved0 || diff --git a/lib/dns/rdata/in_1/srv_33.c b/lib/dns/rdata/in_1/srv_33.c index 268c0e9385..80dd1d637c 100644 --- a/lib/dns/rdata/in_1/srv_33.c +++ b/lib/dns/rdata/in_1/srv_33.c @@ -14,7 +14,7 @@ #ifndef RDATA_IN_1_SRV_33_C #define RDATA_IN_1_SRV_33_C -#define RRTYPE_SRV_ATTRIBUTES (0) +#define RRTYPE_SRV_ATTRIBUTES (DNS_RDATATYPEATTR_FOLLOWADDITIONAL) static inline isc_result_t fromtext_in_srv(ARGS_FROMTEXT) { diff --git a/lib/ns/query.c b/lib/ns/query.c index a9b1cd9dbb..81ff6abfe7 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -2041,22 +2041,11 @@ addname: fname = NULL; /* - * In a few cases, we want to add additional data for additional - * data. It's simpler to just deal with special cases here than - * to try to create a general purpose mechanism and allow the - * rdata implementations to do it themselves. - * - * This involves recursion, but the depth is limited. The - * most complex case is adding a SRV rdataset, which involves - * recursing to add address records, which in turn can cause - * recursion to add KEYs. + * In some cases, a record that has been added as additional + * data may *also* trigger the addition of additional data. + * This cannot go more than MAX_RESTARTS levels deep. */ - if (type == dns_rdatatype_srv && trdataset != NULL) { - /* - * If we're adding SRV records to the additional data - * section, it's helpful if we add the SRV additional data - * as well. - */ + if (trdataset != NULL && dns_rdatatype_followadditional(type)) { eresult = dns_rdataset_additionaldata( trdataset, query_additional_cb, qctx); }