]> 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>
Fri, 28 Jan 2022 00:20:55 +0000 (16:20 -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.

(cherry picked from commit f81debe1c83cb3fe9ef51e2ad6082c13f45852f0)

bin/tests/system/dlzexternal/driver.c
contrib/dlz/example/dlz_example.c
contrib/dlz/modules/include/dlz_minimal.h
contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c
lib/dns/include/dns/clientinfo.h
lib/dns/include/dns/ecs.h
lib/dns/win32/libdns.def.in
lib/isc/include/isc/netaddr.h
lib/isc/include/isc/sockaddr.h

index f7abdf373e7e11329d91e872de2f540571a46cfe..eb8c7343faa63c9df1b6ca760690a703ca996cfe 100644 (file)
@@ -463,8 +463,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 8e736fe2bbc45c55effdd34cd324d7b897c31b53..3b75ffab9145a21e437efbcf6d65e72eb98ab469 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 93d3a56828ec0fe852d182f84784224721e28d20..8962c0b5e216c29d2486f8141e4ccfd685216f68 100644 (file)
@@ -112,11 +112,30 @@ typedef struct isc_sockaddr {
        void         *link;
 } isc_sockaddr_t;
 
-#define DNS_CLIENTINFO_VERSION 2
+typedef struct isc_netaddr {
+       unsigned int family;
+       union {
+               struct in_addr  in;
+               struct in6_addr in6;
+#ifdef ISC_PLATFORM_HAVESYSUNH
+               char un[sizeof(((struct sockaddr_un *)0)->sun_path)];
+#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */
+       } type;
+       uint32_t zone;
+} isc_netaddr_t;
+
+typedef struct dns_ecs {
+       isc_netaddr_t addr;
+       uint8_t       source;
+       uint8_t       scope;
+} dns_ecs_t;
+
+#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,
@@ -131,7 +150,6 @@ typedef struct dns_clientinfomethods {
        uint16_t                  version;
        uint16_t                  age;
        dns_clientinfo_sourceip_t sourceip;
-       dns_clientinfo_version_t  dbversion;
 } dns_clientinfomethods_t;
 #endif /* DLZ_DLOPEN_VERSION > 1 */
 
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;
index 667cf7c5de0216f287f43e20448bc9247c2ee7f6..a1241a2739b1be9326e505e48d30246a7eaaca7a 100644 (file)
@@ -52,6 +52,10 @@ ISC_LANG_BEGINDECLS
 *****/
 
 #define DNS_CLIENTINFO_VERSION 3
+/*
+ * Any updates to this structure should also be applied in
+ * contrib/modules/dlz/dlz_minmal.h.
+ */
 typedef struct dns_clientinfo {
        uint16_t  version;
        void     *data;
@@ -65,6 +69,10 @@ typedef isc_result_t (*dns_clientinfo_sourceip_t)(dns_clientinfo_t *client,
 #define DNS_CLIENTINFOMETHODS_VERSION 2
 #define DNS_CLIENTINFOMETHODS_AGE     1
 
+/*
+ * Any updates to this structure should also be applied in
+ * contrib/modules/dlz/dlz_minmal.h.
+ */
 typedef struct dns_clientinfomethods {
        uint16_t                  version;
        uint16_t                  age;
index 449a2beb293602afd1ad65bfc1e8db92c53e60a8..b4b0d6b7b425676f450efd59919aed794f4ec622 100644 (file)
 #define ECS_MAX_V6_SCOPE 56
 #endif
 
+/*
+ * Any updates to this structure should also be applied in
+ * contrib/modules/dlz/dlz_minmal.h.
+ */
 struct dns_ecs {
        isc_netaddr_t addr;
        uint8_t       source;
index 1e0f7cf64ae28561fb799b6d80ee3ab7e06ce105..2b393552bd3126a47ff0fc347844b6897712a268 100644 (file)
@@ -376,6 +376,7 @@ dns_dyndb_createctx
 dns_dyndb_destroyctx
 dns_ecdb_register
 dns_ecdb_unregister
+dns_ecs_equals
 dns_ecs_init
 dns_ecs_format
 dns_fixedname_init
index 3084009d39265880b5ad70781efe096b10827408..519aec7f8dcedc773b18425a4bd317ea77a8bd5c 100644 (file)
 
 ISC_LANG_BEGINDECLS
 
+/*
+ * Any updates to this structure should also be applied in
+ * contrib/modules/dlz/dlz_minmal.h.
+ */
 struct isc_netaddr {
        unsigned int family;
        union {
index a0c0c73261314aae20bee02b167295eb82dcf474..b776bb305892743c16828a26b44a913773cc04cc 100644 (file)
 #include <sys/un.h>
 #endif /* ifdef ISC_PLATFORM_HAVESYSUNH */
 
+/*
+ * Any updates to this structure should also be applied in
+ * contrib/modules/dlz/dlz_minmal.h.
+ */
 struct isc_sockaddr {
        union {
                struct sockaddr         sa;