]> 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>
Fri, 28 Jan 2022 00:20:55 +0000 (16:20 -0800)
the dlzexternal test driver now includes ECS, if present in the
query, in the TXT record returned for QNAME "source-addr".

(cherry picked from commit 79ddedabf80d5c4dc42eb7a527545796f7d1e330)

bin/tests/system/dlzexternal/driver.c
bin/tests/system/dlzexternal/tests.sh
contrib/dlz/example/dlz_example.c
contrib/dlz/modules/include/dlz_minimal.h

index eb8c7343faa63c9df1b6ca760690a703ca996cfe..12cb83f12fb5568801038eacabf11c6ab4285a77 100644 (file)
@@ -471,6 +471,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 <=
@@ -480,6 +481,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 2e0d7877f78e700240e01ab7d0f8ff3bae2ee9ef..1e48fc8770c5db43c0ddb58318c0449501363a24 100644 (file)
@@ -218,5 +218,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 3b75ffab9145a21e437efbcf6d65e72eb98ab469..88c009ef5276373fdee43f6da0e1cc8837e58a78 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 8962c0b5e216c29d2486f8141e4ccfd685216f68..aaf6729928495a050498e5d88663f80cca58b681 100644 (file)
@@ -153,6 +153,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
  */