]> granicus.if.org Git - pdns/commitdiff
geoipbackend: Support city databases in region lookup
authorAki Tuomi <cmouse@cmouse.fi>
Fri, 21 Apr 2017 19:11:17 +0000 (22:11 +0300)
committerAki Tuomi <cmouse@cmouse.fi>
Mon, 24 Apr 2017 11:37:11 +0000 (14:37 +0300)
City database contains region information as well.

Fixes #5255 and #4122

modules/geoipbackend/geoipbackend.cc

index b26f2249e8e5d59c3a9fb6777a630d0179d29abd..799c6d4423592978bfdc9236111fb84efb93afa1 100644 (file)
@@ -576,6 +576,14 @@ bool GeoIPBackend::queryRegion(string &ret, GeoIPLookup* gl, const string &ip, c
       ret = valueOrEmpty<char*,string>(gir->region);
       return true;
     }
+  } else if (gi.first == GEOIP_CITY_EDITION_REV0 ||
+             gi.first == GEOIP_CITY_EDITION_REV1) {
+    GeoIPRecord *gir = GeoIP_record_by_addr(gi.second.get(), ip.c_str());
+    if (gir) {
+      ret = valueOrEmpty<char*,string>(gir->region);
+      gl->netmask = gir->netmask;
+      return true;
+    }
   }
   return false;
 }
@@ -588,6 +596,14 @@ bool GeoIPBackend::queryRegionV6(string &ret, GeoIPLookup* gl, const string &ip,
       ret = valueOrEmpty<char*,string>(gir->region);
       return true;
     }
+  } else if (gi.first == GEOIP_CITY_EDITION_REV0_V6 ||
+             gi.first == GEOIP_CITY_EDITION_REV1_V6) {
+    GeoIPRecord *gir = GeoIP_record_by_addr_v6(gi.second.get(), ip.c_str());
+    if (gir) {
+      ret = valueOrEmpty<char*,string>(gir->region);
+      gl->netmask = gir->netmask;
+      return true;
+    }
   }
   return false;
 }