]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
test ECS information is passed in dlzexternal
authorEvan Hunt <each@isc.org>
Wed, 3 Nov 2021 06:06:10 +0000 (23:06 -0700)
committerEvan Hunt <each@isc.org>
Thu, 27 Jan 2022 21:53:59 +0000 (13:53 -0800)
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
bin/tests/system/dlzexternal/tests.sh
contrib/dlz/example/dlz_example.c
contrib/dlz/modules/include/dlz_minimal.h

index a1132088585cc96305dbd16925a90de10b157450..b8c74244e6b8bf1186116b5540126e8fa6d1978a 100644 (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);
 
index 9ae428c2322a68dd9008336fbd7dd2b53936f89a..08ab8a4f900ccf8dc1c1be07f5b018ec6d127168 100644 (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
index daf9a4045789eb502a2fadb6c959096771d042ca..1ad12ce01a9eb1062ecc375c03a88ea75f786bf6 100644 (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);
index a820527cd4050827083e7845a0b0bd5404f82659..0225e7ad31df1ce6fa860ff47d30b5c6782a6416 100644 (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
  */