]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
extend DLZ interface and example with ECS support
authorPetr Špaček <pspacek@isc.org>
Wed, 3 Nov 2021 05:43:30 +0000 (22:43 -0700)
committerEvan Hunt <each@isc.org>
Thu, 27 Jan 2022 21:53:59 +0000 (13:53 -0800)
Apparently we forgot about DLZ when updating DNS_CLIENTINFO_VERSION
constant for ECS, which is at value "3" since ECS was introduced.

The code in example drivers and tests now hardcodes version numbers
2 (without ECS) and 3 (with ECS) depending on what a given code path
requires.

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

index 28b9639598bbe1ecada24413dc3cc67736ace2df..a1132088585cc96305dbd16925a90de10b157450 100644 (file)
@@ -480,8 +480,7 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
         * If the DLZ only operates on 'live' data, then version
         * wouldn't necessarily be needed.
         */
-       if (clientinfo != NULL && clientinfo->version >= DNS_CLIENTINFO_VERSION)
-       {
+       if (clientinfo != NULL && clientinfo->version >= 2) {
                dbversion = clientinfo->dbversion;
                if (dbversion != NULL && *(bool *)dbversion) {
                        loginfo("dlz_example: lookup against live transaction");
index 969334fd839796296c14cb6573dd34aeb4094c30..daf9a4045789eb502a2fadb6c959096771d042ca 100644 (file)
@@ -428,8 +428,7 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
         * If the DLZ only operates on 'live' data, then version
         * wouldn't necessarily be needed.
         */
-       if (clientinfo != NULL && clientinfo->version >= DNS_CLIENTINFO_VERSION)
-       {
+       if (clientinfo != NULL && clientinfo->version >= 2) {
                dbversion = clientinfo->dbversion;
                if (dbversion != NULL && *(bool *)dbversion) {
                        state->log(ISC_LOG_INFO, "dlz_example: lookup against "
@@ -439,6 +438,7 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
        }
 
        if (strcmp(name, "source-addr") == 0) {
+               char ecsbuf[100] = "not supported";
                strcpy(buf, "unknown");
                if (methods != NULL && methods->sourceip != NULL &&
                    (methods->version - methods->age <=
@@ -448,12 +448,25 @@ 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 {
+                               strcpy(ecsbuf, "not present");
+                       }
+               }
+               i = strlen(buf);
+               snprintf(buf + i, sizeof(buf) - i - 1, " ECS %s", ecsbuf);
 
                state->log(ISC_LOG_INFO,
                           "dlz_example: lookup connection from: %s", buf);
 
                found = true;
                result = state->putrr(lookup, "TXT", 0, buf);
+               /* We could also generate a CNAME RR:
+               snprintf(buf, sizeof(buf), "%s.redirect.example.", ecsbuf);
+               result = state->putrr(lookup, "CNAME", 0, buf); */
                if (result != ISC_R_SUCCESS) {
                        return (result);
                }
index 24447844efb586b756fa3996d4786af8d89070cd..a820527cd4050827083e7845a0b0bd5404f82659 100644 (file)
@@ -28,6 +28,8 @@
 #include <inttypes.h>
 #include <stdbool.h>
 
+#include <dns/ecs.h>
+
 #include <arpa/inet.h>
 #include <net/if.h>
 #include <netinet/in.h>
@@ -35,8 +37,7 @@
 #include <sys/types.h>
 #include <sys/un.h>
 
-typedef unsigned int isc_result_t;
-typedef uint32_t     dns_ttl_t;
+typedef uint32_t dns_ttl_t;
 
 /*
  * Define DLZ_DLOPEN_VERSION to different values to use older versions
@@ -88,8 +89,6 @@ typedef uint32_t     dns_ttl_t;
 /* opaque structures */
 typedef void *dns_sdlzlookup_t;
 typedef void *dns_sdlzallnodes_t;
-typedef void *dns_view_t;
-typedef void *dns_dlzdb_t;
 
 #if DLZ_DLOPEN_VERSION > 1
 /*
@@ -107,11 +106,12 @@ typedef struct isc_sockaddr {
        void         *link;
 } isc_sockaddr_t;
 
-#define DNS_CLIENTINFO_VERSION 2
+#define DNS_CLIENTINFO_VERSION 3
 typedef struct dns_clientinfo {
-       uint16_t version;
-       void    *data;
-       void    *dbversion;
+       uint16_t  version;
+       void     *data;
+       void     *dbversion;
+       dns_ecs_t ecs;
 } dns_clientinfo_t;
 
 typedef isc_result_t (*dns_clientinfo_sourceip_t)(dns_clientinfo_t *client,
index 97ff486e5d3a632a5fb000364e2c8fa1cf137b4c..d0204c6b993154daadc6a19cc505d3c70425d156 100644 (file)
@@ -1128,8 +1128,7 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
        }
 
        /* Are we okay to try to find the txn version?  */
-       if (clientinfo != NULL && clientinfo->version >= DNS_CLIENTINFO_VERSION)
-       {
+       if (clientinfo != NULL && clientinfo->version >= 2) {
                txn = (mysql_transaction_t *)clientinfo->dbversion;
                if (txn != NULL && validate_txn(state, txn) == ISC_R_SUCCESS) {
                        dbi = txn->dbi;