The following code block repeats quite often: if (rdata.type == dns_rdatatype_dnskey || rdata.type == dns_rdatatype_cdnskey || rdata.type == dns_rdatatype_cds) Introduce a new function to reduce the repetition.