]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make "geoip-use-ecs yes;" work for GeoIP2
authorMichał Kępień <michal@isc.org>
Wed, 30 Oct 2019 15:05:28 +0000 (16:05 +0100)
committerMichał Kępień <michal@isc.org>
Wed, 30 Oct 2019 15:05:28 +0000 (16:05 +0100)
Add a missing preprocessor condition to make "geoip-use-ecs yes;" work
for GeoIP2.

bin/named/server.c
bin/tests/system/geoip2/ns2/named14.conf.in [new file with mode: 0644]
bin/tests/system/geoip2/tests.sh

index 0af069c3c43fff6f93604376b5bce71ac3922d82..ad2cd5f23bd896feb403b66cb5f0e74691ced923 100644 (file)
@@ -5894,7 +5894,7 @@ static isc_result_t
 scan_interfaces(ns_server_t *server, bool verbose) {
        isc_result_t result;
        bool match_mapped = server->aclenv.match_mapped;
-#ifdef HAVE_GEOIP
+#if defined(HAVE_GEOIP) || defined(HAVE_GEOIP2)
        bool use_ecs = server->aclenv.geoip_use_ecs;
 #endif
 
@@ -5907,7 +5907,7 @@ scan_interfaces(ns_server_t *server, bool verbose) {
                        ns_interfacemgr_getaclenv(server->interfacemgr));
 
        server->aclenv.match_mapped = match_mapped;
-#ifdef HAVE_GEOIP
+#if defined(HAVE_GEOIP) || defined(HAVE_GEOIP2)
        server->aclenv.geoip_use_ecs = use_ecs;
 #endif
 
diff --git a/bin/tests/system/geoip2/ns2/named14.conf.in b/bin/tests/system/geoip2/ns2/named14.conf.in
new file mode 100644 (file)
index 0000000..b61867a
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+// NS2
+
+options {
+       query-source address 10.53.0.2;
+       notify-source 10.53.0.2;
+       transfer-source 10.53.0.2;
+       port @PORT@;
+       pid-file "named.pid";
+       listen-on { 127.0.0.1; 10.53.0.2; };
+       listen-on-v6 { none; };
+       recursion no;
+       geoip-directory "../data";
+       geoip-use-ecs yes;
+};
+
+key rndc_key {
+       secret "1234abcd8765";
+       algorithm hmac-sha256;
+};
+
+controls {
+       inet 10.53.0.2 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
+};
+
+acl gAU { geoip db country country AU; };
+acl gUS { geoip db country country US; };
+acl gGB { geoip db country country GB; };
+acl gCA { geoip db country country CA; };
+acl gCL { geoip db country country CL; };
+acl gDE { geoip db country country DE; };
+acl gEH { geoip db country country EH; };
+
+view one {
+       match-clients { gAU; };
+       zone "example" {
+               type master;
+               file "example1.db";
+       };
+};
+
+view two {
+       match-clients { gUS; };
+       zone "example" {
+               type master;
+               file "example2.db";
+       };
+};
+
+view three {
+       match-clients { gGB; };
+       zone "example" {
+               type master;
+               file "example3.db";
+       };
+};
+
+view four {
+       match-clients { gCA; };
+       zone "example" {
+               type master;
+               file "example4.db";
+       };
+};
+
+view five {
+       match-clients { gCL; };
+       zone "example" {
+               type master;
+               file "example5.db";
+       };
+};
+
+view six {
+       match-clients { gDE; };
+       zone "example" {
+               type master;
+               file "example6.db";
+       };
+};
+
+view seven {
+       match-clients { gEH; };
+       zone "example" {
+               type master;
+               file "example7.db";
+       };
+};
+
+view none {
+       match-clients { any; };
+       zone "example" {
+               type master;
+               file "examplebogus.db";
+       };
+};
index b035b9a2d690de1d5cce57e0d4627ed1f63416b3..d2e1022ab854dff62b3e4419d99f5f99d4249bc9 100644 (file)
@@ -489,7 +489,7 @@ $RNDCCMD 10.53.0.2 reload 2>&1 | sed 's/^/ns2 /' | cat_i
 sleep 3
 
 n=`expr $n + 1`
-echo_i "checking geoip-use-ecs ($n)"
+echo_i "checking 'geoip-use-ecs no;' ($n)"
 ret=0
 lret=0
 for i in 1 2 3 4 5 6 7; do
@@ -507,5 +507,29 @@ done
 [ $ret -eq 0 ] || echo_i "failed"
 status=`expr $status + $ret`
 
+echo_i "reloading server"
+copy_setports ns2/named14.conf.in ns2/named.conf
+$RNDCCMD 10.53.0.2 reload 2>&1 | sed 's/^/ns2 /' | cat_i
+sleep 3
+
+n=`expr $n + 1`
+echo_i "checking 'geoip-use-ecs yes;' ($n)"
+ret=0
+lret=0
+for i in 1 2 3 4 5 6 7; do
+    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
+    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
+    [ "$i" = "$j" ] || lret=1
+    [ $lret -eq 1 ] && break
+
+    $DIG $DIGOPTS txt example -b 127.0.0.1 +subnet="10.53.0.$i/32" > dig.out.ns2.test$n.ecs.$i || lret=1
+    j=`cat dig.out.ns2.test$n.ecs.$i | tr -d '"'`
+    [ "$i" = "$j" ] || lret=1
+    [ $lret -eq 1 ] && break
+done
+[ $lret -eq 1 ] && ret=1
+[ $ret -eq 0 ] || echo_i "failed"
+status=`expr $status + $ret`
+
 echo_i "exit status: $status"
 [ $status -eq 0 ] || exit 1