test ECS information is passed in dlzexternal

the dlzexternal test driver now includes ECS, if present in the
query, in the TXT record returned for QNAME "source-addr".
This commit is contained in:
Evan Hunt 2021-11-02 23:06:10 -07:00
parent f81debe1c8
commit 79ddedabf8
4 changed files with 28 additions and 3 deletions

View file

@ -488,6 +488,7 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
}
if (strcmp(name, "source-addr") == 0) {
char ecsbuf[DNS_ECS_FORMATSIZE] = "not supported";
strncpy(buf, "unknown", sizeof(buf));
if (methods != NULL && methods->sourceip != NULL &&
(methods->version - methods->age <=
@ -497,6 +498,17 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
methods->sourceip(clientinfo, &src);
fmt_address(src, buf, sizeof(buf));
}
if (clientinfo != NULL && clientinfo->version >= 3) {
if (clientinfo->ecs.addr.family != AF_UNSPEC) {
dns_ecs_format(&clientinfo->ecs, ecsbuf,
sizeof(ecsbuf));
} else {
snprintf(ecsbuf, sizeof(ecsbuf), "%s",
"not present");
}
}
i = strlen(buf);
snprintf(buf + i, sizeof(buf) - i - 1, " ECS %s", ecsbuf);
loginfo("dlz_example: lookup connection from %s", buf);

View file

@ -217,5 +217,13 @@ lookups=`grep "lookup #.*\.not\.there" ns1/named.run | wc -l`
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
newtest "checking ECS data is passed to driver in clientinfo"
$DIG $DIGOPTS +short +subnet=192.0/16 source-addr.example.nil txt > dig.out.ns1.test$n.1 || ret=1
grep "192.0.0.0/16/0" dig.out.ns1.test$n.1 > /dev/null || ret=1
$DIG $DIGOPTS +short source-addr.example.nil txt > dig.out.ns1.test$n.2 || ret=1
grep "not.*present" dig.out.ns1.test$n.2 > /dev/null || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
echo_i "exit status: $status"
[ $status -eq 0 ] || exit 1

View file

@ -438,8 +438,8 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
}
if (strcmp(name, "source-addr") == 0) {
char ecsbuf[100] = "not supported";
strcpy(buf, "unknown");
char ecsbuf[DNS_ECS_FORMATSIZE] = "not supported";
strncpy(buf, "unknown", sizeof(buf));
if (methods != NULL && methods->sourceip != NULL &&
(methods->version - methods->age <=
DNS_CLIENTINFOMETHODS_VERSION) &&
@ -453,7 +453,8 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
dns_ecs_format(&clientinfo->ecs, ecsbuf,
sizeof(ecsbuf));
} else {
strcpy(ecsbuf, "not present");
snprintf(ecsbuf, sizeof(ecsbuf), "%s",
"not present");
}
}
i = strlen(buf);

View file

@ -130,6 +130,10 @@ typedef struct dns_clientinfomethods {
} dns_clientinfomethods_t;
#endif /* DLZ_DLOPEN_VERSION > 1 */
#define DNS_ECS_FORMATSIZE \
sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX%SSSSSSSSSS" \
"/NNN/NNN")
/*
* Method definitions for callbacks provided by the dlopen driver
*/