Errors with latest mod_geoip and 1.4.4 library

This section is where GeoLite users can find support from other users.

Errors with latest mod_geoip and 1.4.4 library

Postby diamond » Mon Mar 17, 2008 7:49 am

I'm using the GeoIPLite binary database. I recently upgraded to the version 1.4.4 C library and mod_geoip 1.3.0 for apache 1.3.x. Since the upgrade, I'm getting a lot of errors in my apache logs like the following:

Error Traversing Database for ipnum = 2701579873 - Perhaps database is corrupt?
Error Traversing Database for ipnum = 3420906021 - Perhaps database is corrupt?
Error Traversing Database for ipnum = 3720674319 - Perhaps database is corrupt?

I downloaded the latest GeoIPLite binary database and reinstalled it to make sure there's nothing wrong with the database file itself. Unfortunately, that didn't help. This error doesn't happen all the time, but it's pretty frequent. I never saw these errors with the older version we had installed, which I believe was version 1.3.8 of the C library. I'm not sure what our old version of mod_geoip was.

Has anyone else seen this type of error? Any insight on how to fix it would be appreciated.

Thanks,
--jeff
diamond
 
Posts: 10
Joined: Mon Mar 17, 2008 7:36 am

Postby diamond » Mon Mar 17, 2008 10:32 pm

Well, I figured this one out, so hopefully posting here will save somebody else the trouble. There definitely seems to be a problem with the 1.3.0 version of mod_geoip. After looking at the file dates on the download page and realizing that 1.3.0 is *very* recent, while 1.2.9 has been around for a couple of years, I decided to downgrade. No more error messages in the log files.

Gee, if somebody from MaxMind actually *read* these boards, they'd know there was a bug, too...

--jeff
diamond
 
Posts: 10
Joined: Mon Mar 17, 2008 7:36 am

Postby borisz_maxmind » Tue Mar 18, 2008 8:15 pm

Hi Jeff,

I think the error is fixed now. Thanks for your report.
Please try the attached patch and let me know if it fix your issue.

Or pm/email me for the whole tarball.

Have a nice day

Code: Select all
diff -Nur mod_geoip_1.3.0/Changes mod_geoip_1.3.1-b1/Changes
--- mod_geoip_1.3.0/Changes   2008-02-27 20:21:58.000000000 +0100
+++ mod_geoip_1.3.1-b1/Changes   2008-03-18 20:46:00.000000000 +0100
@@ -1,3 +1,7 @@
+1.3.1 Mar 18th 2008
+        - Fix race condition for IO based caches like Standard
+but not MMapCache and MemoryCache
+        ( Boris Zentner, Nick Lott, Jeff )
1.2.10 Dec 18th 2007
     - Added MMapCache option (Boris Zentner)
     - Change GeoIPEnabled from a serverwide option to a server/directory/location keyword. (Boris Zentner)
diff -Nur mod_geoip_1.3.0/mod_geoip.c mod_geoip_1.3.1-b1/mod_geoip.c
--- mod_geoip_1.3.0/mod_geoip.c   2008-02-27 20:25:13.000000000 +0100
+++ mod_geoip_1.3.1-b1/mod_geoip.c   2008-03-18 20:38:58.000000000 +0100
@@ -301,7 +301,7 @@

/**/
static void
-geoip_child_init(server_rec * s, pool * p)
+geoip_server_init(server_rec * s, pool * p)
{
   geoip_server_cfg *cfg;
   int             i;
@@ -556,7 +556,63 @@
static void
geoip_post_config(server_rec * s, pool *p)
{
-   geoip_child_init(s, p);
+   geoip_server_init(s, p);
+}
+
+
+/**/
+static void
+geoip_child_init(server_rec * s, pool * p)
+{
+   geoip_server_cfg *cfg;
+   int             i, flags;
+   
+   
+   cfg = (geoip_server_cfg *)
+    ap_get_module_config(s->module_config, &geoip_module);
+   
+   
+   if (cfg->gips) {
+      if (cfg->GeoIPFilenames != NULL) {
+         for (i = 0; i < cfg->numGeoIPFiles; i++) {
+            /*
+             * Use flags associated with filename, or if not available, use
+             * global flags
+             */
+            flags = (cfg->GeoIPFlags2[i] == GEOIP_UNKNOWN) ? cfg->GeoIPFlags : cfg->GeoIPFlags2[i];
+            if (flags & (GEOIP_MEMORY_CACHE | GEOIP_MMAP_CACHE))
+               continue;
+
+            /* reopen anything other than memory based files */
+            if ( cfg->gips[i] )
+               GeoIP_delete(cfg->gips[i]);
+            cfg->gips[i] = GeoIP_open(cfg->GeoIPFilenames[i], flags);
+            if (cfg->gips[i]) {
+               if (cfg->GeoIPEnableUTF8) {
+                  GeoIP_set_charset(cfg->gips[i], GEOIP_CHARSET_UTF8);
+               }
+            }
+            else {
+               ap_log_error(APLOG_MARK, APLOG_ERR, s, "[mod_geoip]: Error while opening data file %s", cfg->GeoIPFilenames[i]);
+               return;
+            }
+         }
+      }
+      else {
+         if (!(cfg->GeoIPFlags & (GEOIP_MEMORY_CACHE | GEOIP_MMAP_CACHE))) {
+            /* reopen anything other than memory based files */
+                if ( cfg->gips[0] )
+               GeoIP_delete(cfg->gips[0]);
+            
+            cfg->gips[0] = GeoIP_new(cfg->GeoIPFlags);
+         }
+         if (!cfg->gips[0]) {
+            ap_log_error(APLOG_MARK, APLOG_ERR, s, "[mod_geoip]: Error while opening data file");
+            return;
+         }
+         cfg->numGeoIPFiles = 1;
+      }
+   }
}


@@ -577,7 +633,7 @@
     NULL,                       /* fixups */
     NULL,                       /* logger */
     geoip_per_dir,              /* header parser */
-    NULL,                       /* child_init */
+    geoip_child_init,           /* child_init */
     geoip_child_exit,           /* child_exit */
     geoip_post_read_request,    /* post read-request */
};


[/code]
--
boris
borisz_maxmind
 
Posts: 317
Joined: Tue Mar 18, 2008 7:51 pm

Postby diamond » Wed Mar 19, 2008 4:56 pm

Hi Boris,

I'd like to get the whole tarball, but I'm not sure how to contact you. I don't see your email anywhere and pm is turned off on these forums.

Also, after reverting to mod_geoip 1.2.9, the error messages went away, but I found another interesting quirk that isn't mentioned in your docs. The order of the LoadModule/AddModule statements in httpd.conf affects the blocking by country code capabilities. For example:

Code: Select all
GeoIPEnable On
GeoIPDBFile /path/to/GeoIP.dat

SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry

Deny from env=BlockCountry


The above code does not work if the modules aren't loaded in the correct order. The following module order DID NOT work for me:

Code: Select all
LoadModule env_module         libexec/mod_env.so
LoadModule config_log_module  libexec/mod_log_config.so
LoadModule mime_magic_module  libexec/mod_mime_magic.so
LoadModule mime_module        libexec/mod_mime.so
LoadModule negotiation_module libexec/mod_negotiation.so
LoadModule status_module      libexec/mod_status.so
LoadModule info_module        libexec/mod_info.so
LoadModule dir_module         libexec/mod_dir.so
LoadModule cgi_module         libexec/mod_cgi.so
LoadModule asis_module        libexec/mod_asis.so
LoadModule userdir_module     libexec/mod_userdir.so
LoadModule alias_module       libexec/mod_alias.so
LoadModule rewrite_module     libexec/mod_rewrite.so
LoadModule access_module      libexec/mod_access.so
LoadModule auth_module        libexec/mod_auth.so
LoadModule dbmcookie_auth_module libexec/mod_auth_dbmcookie.so
LoadModule expires_module     libexec/mod_expires.so
LoadModule headers_module     libexec/mod_headers.so
LoadModule geoip_module       libexec/mod_geoip.so
LoadModule setenvif_module    libexec/mod_setenvif.so
LoadModule php5_module        libexec/libphp5.so
<IfDefine SSL>
LoadModule ssl_module         libexec/libssl.so
</IfDefine>


However, this order DOES work:

Code: Select all
LoadModule env_module         libexec/mod_env.so
LoadModule config_log_module  libexec/mod_log_config.so
LoadModule mime_magic_module  libexec/mod_mime_magic.so
LoadModule mime_module        libexec/mod_mime.so
LoadModule negotiation_module libexec/mod_negotiation.so
LoadModule status_module      libexec/mod_status.so
LoadModule info_module        libexec/mod_info.so
LoadModule dir_module         libexec/mod_dir.so
LoadModule cgi_module         libexec/mod_cgi.so
LoadModule asis_module        libexec/mod_asis.so
LoadModule userdir_module     libexec/mod_userdir.so
LoadModule alias_module       libexec/mod_alias.so
LoadModule rewrite_module     libexec/mod_rewrite.so
LoadModule access_module      libexec/mod_access.so
LoadModule auth_module        libexec/mod_auth.so
LoadModule dbmcookie_auth_module libexec/mod_auth_dbmcookie.so
LoadModule expires_module     libexec/mod_expires.so
LoadModule headers_module     libexec/mod_headers.so
LoadModule setenvif_module    libexec/mod_setenvif.so
LoadModule php5_module        libexec/libphp5.so
LoadModule geoip_module       libexec/mod_geoip.so
<IfDefine SSL>
LoadModule ssl_module         libexec/libssl.so
</IfDefine>


Does mod_geoip have to be loaded after mod_setenvif, in order to use the country blocking example above? If so, that should be part of your docs.

Thanks,
--jeff
diamond
 
Posts: 10
Joined: Mon Mar 17, 2008 7:36 am

Postby diamond » Wed Mar 19, 2008 5:07 pm

Hi Boris,

I just realized that we had an old account with you guys back in 2006, so I have sent a message referencing this post to support@maxmind.com.

Thanks,
--jeff
diamond
 
Posts: 10
Joined: Mon Mar 17, 2008 7:36 am

Postby borisz_maxmind » Wed Mar 19, 2008 5:21 pm

Hi Jeff,

the whole tarball is here:

http://www.maxmind.com/download/geoip/api/mod_geoip/mod_geoip_1.3.1.tar.gz

your other issue is just a misconfiguration.

basically you need to move the Deny Statment.
Code: Select all
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPOutput All
GeoIPDBFile /usr/local/share/GeoIP/GeoIP.dat
</IfModule>


<Location />
SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry=1
SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry=1
Deny from env=BlockCountry
</Location>

Have a nice day.
--
boris
borisz_maxmind
 
Posts: 317
Joined: Tue Mar 18, 2008 7:51 pm

Postby diamond » Wed Mar 19, 2008 7:00 pm

Hi Boris,

I will try the new version 1.3.1 later today.

The config example above I copied from your README file. My actual config is:

Code: Select all
<IfModule mod_geoip.c>
    GeoIPEnable On
    GeoIPDBFile /home/common/www/lib/GeoIP/Lite/GeoIP.dat

    # Block unwanted countries
    SetEnvIf GEOIP_COUNTRY_CODE CN BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE RU BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE UA BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE VN BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE LK BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE TR BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE RW BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE BY BlockCountry
    SetEnvIf GEOIP_COUNTRY_CODE JO BlockCountry

    <Directory /home/common/www/sites>
        Deny from env=BlockCountry
    </Directory>
</IfModule>


The above config had no effect when the modules weren't loaded in the correct order. The GEOIP_COUNTRY_CODE and GEOIP_COUNTRY_NAME variables were still being set, but the country block using SetEnvIf had no effect. When I changed the order of the module loading in httpd.conf, the country blocking using SetEnvIf started to work.

It's working for me now, so it's not an issue. I just thought you might like to mention it in your README.

--jeff
diamond
 
Posts: 10
Joined: Mon Mar 17, 2008 7:36 am

Postby borisz_maxmind » Wed Mar 19, 2008 7:28 pm

Hi Jeff,

nice to hear, it is working now.

I'm going to add a notice in the README to clearify that you should not change the order of LoadlModule statements without a good reason.

And I try to improve example with the Deny statement.
--
boris
borisz_maxmind
 
Posts: 317
Joined: Tue Mar 18, 2008 7:51 pm

Postby diamond » Wed Mar 19, 2008 7:37 pm

Hi Boris,

I have installed mod_geoip version 1.3.1 using the GeoIP 1.4.4 C library. Everything seems to be working fine now, so the problem with version 1.3.0 has been fixed. Just a suggestion, but you should probably remove version 1.3.0 from your download directory.

Thanks!
--jeff
diamond
 
Posts: 10
Joined: Mon Mar 17, 2008 7:36 am


Return to GeoLite Support

Who is online

Users browsing this forum: No registered users and 1 guest