diff --git a/lib/dns/include/dns/name.h b/lib/dns/include/dns/name.h index c3cd5aafe5..58d8849fbc 100644 --- a/lib/dns/include/dns/name.h +++ b/lib/dns/include/dns/name.h @@ -497,6 +497,39 @@ dns_name_issubdomain(dns_name_t *name1, dns_name_t *name2); * FALSE 'name1' is not a subdomain of 'name2' */ +isc_boolean_t +dns_name_matcheswildcard(dns_name_t *name, dns_name_t *wname); +/* + * Does 'name' match the wildcard specified in 'wname'? + * + * Notes: + * name matches the wildcard specified in wname if all labels + * following the wildcard in wname are identical to the same number + * of labels at the end of name. + * + * It makes no sense for one of the names to be relative and the + * other absolute. If both names are relative, then to be meaningfully + * compared the caller must ensure that they are both relative to the + * same domain. + * + * Requires: + * 'name' is a valid name + * + * dns_name_countlabels(name) > 0 + * + * 'wname' is a valid name + * + * dns_name_countlabels(wname) > 0 + * + * dns_name_iswildcard(wname) is true + * + * Either name is absolute and wname is absolute, or neither is. + * + * Returns: + * TRUE 'name' matches the wildcard specified in 'wname' + * FALSE 'name' does not match the wildcard specified in 'wname' + */ + /*** *** Labels diff --git a/lib/dns/name.c b/lib/dns/name.c index 2461179c63..7b44739c12 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -820,6 +820,22 @@ dns_name_issubdomain(dns_name_t *name1, dns_name_t *name2) { return (ISC_FALSE); } +isc_boolean_t +dns_name_matcheswildcard(dns_name_t *name, dns_name_t *wname) { + unsigned int labels; + dns_name_t tname; + + REQUIRE(VALID_NAME(name)); + REQUIRE(dns_name_countlabels(name) > 0); + REQUIRE(VALID_NAME(wname)); + REQUIRE((labels = dns_name_countlabels(wname)) > 0); + REQUIRE(dns_name_iswildcard(wname)); + + dns_name_init(&tname, NULL); + dns_name_getlabelsequence(wname, 1, labels - 1, &tname); + return (dns_name_issubdomain(name, &tname)); +} + unsigned int dns_name_countlabels(dns_name_t *name) { /*