From 79ddedabf80d5c4dc42eb7a527545796f7d1e330 Mon Sep 17 00:00:00 2001 From: Evan Hunt Date: Tue, 2 Nov 2021 23:06:10 -0700 Subject: [PATCH] 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". --- bin/tests/system/dlzexternal/driver/driver.c | 12 ++++++++++++ bin/tests/system/dlzexternal/tests.sh | 8 ++++++++ contrib/dlz/example/dlz_example.c | 7 ++++--- contrib/dlz/modules/include/dlz_minimal.h | 4 ++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/bin/tests/system/dlzexternal/driver/driver.c b/bin/tests/system/dlzexternal/driver/driver.c index a113208858..b8c74244e6 100644 --- a/bin/tests/system/dlzexternal/driver/driver.c +++ b/bin/tests/system/dlzexternal/driver/driver.c @@ -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); diff --git a/bin/tests/system/dlzexternal/tests.sh b/bin/tests/system/dlzexternal/tests.sh index 9ae428c232..08ab8a4f90 100644 --- a/bin/tests/system/dlzexternal/tests.sh +++ b/bin/tests/system/dlzexternal/tests.sh @@ -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 diff --git a/contrib/dlz/example/dlz_example.c b/contrib/dlz/example/dlz_example.c index daf9a40457..1ad12ce01a 100644 --- a/contrib/dlz/example/dlz_example.c +++ b/contrib/dlz/example/dlz_example.c @@ -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); diff --git a/contrib/dlz/modules/include/dlz_minimal.h b/contrib/dlz/modules/include/dlz_minimal.h index a820527cd4..0225e7ad31 100644 --- a/contrib/dlz/modules/include/dlz_minimal.h +++ b/contrib/dlz/modules/include/dlz_minimal.h @@ -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 */