You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2021/05/05 15:55:54 UTC

[trafficserver] branch 9.1.x updated (8b0c2c8 -> 840e70b)

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a change to branch 9.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git.


    from 8b0c2c8  header_rewrite: allow for use of maxminddb as source of geo truth (#7695)
     new 1e408bd  header_rewrite: Allow for relative path to geo database files (#7727)
     new 840e70b  header_rewrite: Various fixes for MaxMind support (#7746)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 plugins/header_rewrite/conditions_geo_maxmind.cc | 13 ++++++++++--
 plugins/header_rewrite/header_rewrite.cc         | 25 +++++++++++++++++++-----
 2 files changed, 31 insertions(+), 7 deletions(-)

[trafficserver] 01/02: header_rewrite: Allow for relative path to geo database files (#7727)

Posted by zw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 1e408bd6282d1aa6a99a562b3cdf00fde5cfabbf
Author: Randall Meyer <rr...@apache.org>
AuthorDate: Wed Apr 21 09:00:40 2021 -0700

    header_rewrite: Allow for relative path to geo database files (#7727)
    
    (cherry picked from commit 3159b63e9ef6afd8af47b75e5577359f9fe6b895)
---
 plugins/header_rewrite/header_rewrite.cc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/plugins/header_rewrite/header_rewrite.cc b/plugins/header_rewrite/header_rewrite.cc
index 55d8f0f..78e9f42 100644
--- a/plugins/header_rewrite/header_rewrite.cc
+++ b/plugins/header_rewrite/header_rewrite.cc
@@ -426,6 +426,10 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSE
     }
   }
 
+  if (geoDBPath.find("/") != 0) {
+    geoDBPath = std::string(TSConfigDirGet()) + '/' + geoDBPath;
+  }
+
   std::call_once(initGeoLibs, [&geoDBPath]() { initGeoLib(geoDBPath); });
 
   RulesConfig *conf = new RulesConfig;

[trafficserver] 02/02: header_rewrite: Various fixes for MaxMind support (#7746)

Posted by zw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 9.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 840e70b502b80a83ca748f917074c040c375c04e
Author: Randall Meyer <rr...@apache.org>
AuthorDate: Tue Apr 27 18:31:30 2021 -0700

    header_rewrite: Various fixes for MaxMind support (#7746)
    
    Including:
    * Demote scary errors and other log changes
    * ASN fieldname correction
    
    (cherry picked from commit 1b5139d19f9707edf40cd6865f948b1ff235b84c)
---
 plugins/header_rewrite/conditions_geo_maxmind.cc | 13 ++++++++++--
 plugins/header_rewrite/header_rewrite.cc         | 27 +++++++++++++++++-------
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/plugins/header_rewrite/conditions_geo_maxmind.cc b/plugins/header_rewrite/conditions_geo_maxmind.cc
index 8438e1c..5e0e76c 100644
--- a/plugins/header_rewrite/conditions_geo_maxmind.cc
+++ b/plugins/header_rewrite/conditions_geo_maxmind.cc
@@ -36,14 +36,21 @@ void
 MMConditionGeo::initLibrary(const std::string &path)
 {
   if (path.empty()) {
-    TSError("[%s] Empty db path specified. Not initializing!", PLUGIN_NAME);
+    TSDebug(PLUGIN_NAME, "Empty MaxMind db path specified. Not initializing!");
     return;
   }
+
+  if (gMaxMindDB != nullptr) {
+    TSDebug(PLUGIN_NAME, "Maxmind library already initialized");
+    return;
+  }
+
   gMaxMindDB = new MMDB_s;
 
   int status = MMDB_open(path.c_str(), MMDB_MODE_MMAP, gMaxMindDB);
   if (MMDB_SUCCESS != status) {
     TSDebug(PLUGIN_NAME, "Cannot open %s - %s", path.c_str(), MMDB_strerror(status));
+    delete gMaxMindDB;
     return;
   }
   TSDebug(PLUGIN_NAME, "Loaded %s", path.c_str());
@@ -56,6 +63,7 @@ MMConditionGeo::get_geo_string(const sockaddr *addr) const
   int mmdb_error;
 
   if (gMaxMindDB == nullptr) {
+    TSDebug(PLUGIN_NAME, "MaxMind not initialized; using default value");
     return ret;
   }
 
@@ -120,6 +128,7 @@ MMConditionGeo::get_geo_int(const sockaddr *addr) const
   int mmdb_error;
 
   if (gMaxMindDB == nullptr) {
+    TSDebug(PLUGIN_NAME, "MaxMind not initialized; using default value");
     return ret;
   }
 
@@ -150,7 +159,7 @@ MMConditionGeo::get_geo_int(const sockaddr *addr) const
   const char *field_name;
   switch (_geo_qual) {
   case GEO_QUAL_ASN:
-    field_name = "autonomous_system";
+    field_name = "autonomous_system_number";
     break;
   default:
     TSDebug(PLUGIN_NAME, "Unsupported field %d", _geo_qual);
diff --git a/plugins/header_rewrite/header_rewrite.cc b/plugins/header_rewrite/header_rewrite.cc
index 78e9f42..09593ea 100644
--- a/plugins/header_rewrite/header_rewrite.cc
+++ b/plugins/header_rewrite/header_rewrite.cc
@@ -40,6 +40,7 @@ static std::once_flag initGeoLibs;
 static void
 initGeoLib(const std::string &dbPath)
 {
+  TSDebug(PLUGIN_NAME, "Loading geo db %s", dbPath.c_str());
 #if TS_USE_HRW_GEOIP
   GeoIPConditionGeo::initLibrary(dbPath);
 #elif TS_USE_HRW_MAXMINDDB
@@ -334,13 +335,19 @@ TSPluginInit(int argc, const char *argv[])
     }
   }
 
+  if (!geoDBpath.empty() && geoDBpath.find("/") != 0) {
+    geoDBpath = std::string(TSConfigDirGet()) + '/' + geoDBpath;
+  }
+
+  TSDebug(PLUGIN_NAME, "Global geo db %s", geoDBpath.c_str());
+
+  std::call_once(initGeoLibs, [&geoDBpath]() { initGeoLib(geoDBpath); });
+
   // Parse the global config file(s). All rules are just appended
   // to the "global" Rules configuration.
   RulesConfig *conf = new RulesConfig;
   bool got_config   = false;
 
-  std::call_once(initGeoLibs, [&geoDBpath]() { initGeoLib(geoDBpath); });
-
   for (int i = optind; i < argc; ++i) {
     // Parse the config file(s). Note that multiple config files are
     // just appended to the configurations.
@@ -412,13 +419,13 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSE
   --argc;
   ++argv;
 
-  std::string geoDBPath;
+  std::string geoDBpath;
   while (true) {
     int opt = getopt_long(argc, (char *const *)argv, "m:", longopt, NULL);
 
     switch (opt) {
     case 'm': {
-      geoDBPath = optarg;
+      geoDBpath = optarg;
     } break;
     }
     if (opt == -1) {
@@ -426,11 +433,15 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSE
     }
   }
 
-  if (geoDBPath.find("/") != 0) {
-    geoDBPath = std::string(TSConfigDirGet()) + '/' + geoDBPath;
-  }
+  if (!geoDBpath.empty()) {
+    if (geoDBpath.find("/") != 0) {
+      geoDBpath = std::string(TSConfigDirGet()) + '/' + geoDBpath;
+    }
+
+    TSDebug(PLUGIN_NAME, "Remap geo db %s", geoDBpath.c_str());
 
-  std::call_once(initGeoLibs, [&geoDBPath]() { initGeoLib(geoDBPath); });
+    std::call_once(initGeoLibs, [&geoDBpath]() { initGeoLib(geoDBpath); });
+  }
 
   RulesConfig *conf = new RulesConfig;