mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-08 20:12:06 -04:00
Add dns_name_isdnssvcb
dns_name_isdnssvcb looks for a name which starts with the label _dns or _<port>._dns labels.
This commit is contained in:
parent
f8a741c104
commit
f1043f19dd
2 changed files with 62 additions and 1 deletions
|
|
@ -1298,10 +1298,17 @@ dns_name_isula(const dns_name_t *owner);
|
|||
|
||||
bool
|
||||
dns_name_istat(const dns_name_t *name);
|
||||
/*
|
||||
/*%<
|
||||
* Determine if 'name' is a potential 'trust-anchor-telemetry' name.
|
||||
*/
|
||||
|
||||
bool
|
||||
dns_name_isdnssvcb(const dns_name_t *name);
|
||||
/*%<
|
||||
* Determine if 'name' is a dns service name,
|
||||
* i.e. it starts with and optional _port label followed by a _dns label.
|
||||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -2376,3 +2376,57 @@ dns_name_istat(const dns_name_t *name) {
|
|||
}
|
||||
return (true);
|
||||
}
|
||||
|
||||
bool
|
||||
dns_name_isdnssvcb(const dns_name_t *name) {
|
||||
unsigned char len, len1;
|
||||
const unsigned char *ndata;
|
||||
|
||||
REQUIRE(VALID_NAME(name));
|
||||
|
||||
if (name->labels < 1 || name->length < 5) {
|
||||
return (false);
|
||||
}
|
||||
|
||||
ndata = name->ndata;
|
||||
len = len1 = ndata[0];
|
||||
INSIST(len <= name->length);
|
||||
ndata++;
|
||||
|
||||
if (len < 2 || ndata[0] != '_') {
|
||||
return (false);
|
||||
}
|
||||
if (isdigit(ndata[1]) && name->labels > 1) {
|
||||
char buf[sizeof("65000")];
|
||||
long port;
|
||||
char *endp;
|
||||
|
||||
/*
|
||||
* Do we have a valid _port label?
|
||||
*/
|
||||
if (len > 6U || (ndata[1] == '0' && len != 2)) {
|
||||
return (false);
|
||||
}
|
||||
memcpy(buf, ndata + 1, len - 1);
|
||||
buf[len - 1] = 0;
|
||||
port = strtol(buf, &endp, 10);
|
||||
if (*endp != 0 || port < 0 || port > 0xffff) {
|
||||
return (false);
|
||||
}
|
||||
|
||||
/*
|
||||
* Move to next label.
|
||||
*/
|
||||
ndata += len;
|
||||
INSIST(len1 + 1U < name->length);
|
||||
len = *ndata;
|
||||
INSIST(len + len1 + 1U <= name->length);
|
||||
ndata++;
|
||||
}
|
||||
|
||||
if (len == 4U && strncasecmp((const char *)ndata, "_dns", 4) == 0) {
|
||||
return (true);
|
||||
}
|
||||
|
||||
return (false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue