GeoIP-plugin : Varnish won't start

Julien Cornuwel cornuwel at gmail.com
Wed Mar 20 18:01:08 CET 2013


Hi,

I installed Varnish 3.0.3 from repo.varnish-cache.org on Debian Squeeze.
I got the plugin from
https://www.varnish-cache.org/trac/wiki/GeoipUsingInlineC (
GeoIP-plugin-2.tar.gz ).

The plugin seems to work on its own :
# make test
gcc geoip_plugin_test.c -o geoip_plugin_test -ldl
LD_LIBRARY_PATH=$PWD ./geoip_plugin_test
GeoIP plugin loaded successfully.
Testing IPs:
195.110.128.11 => IT (OK)
157.166.224.25 => US (OK)
212.58.224.138 => GB (OK)
80.91.37.210 => NO (OK)
192.168.0.1 => Unknown (OK)
(null) => Unknown (OK)

However, Varnish fails to start :
# /etc/init.d/varnish start
Starting HTTP accelerator: varnishd failed!
Message from C-compiler:
./vcl.IoMQyW5q.c: In function ‘VGC_function_vcl_hash’:
./vcl.IoMQyW5q.c:569: warning: implicit declaration of function
‘VRT_l_req_hash’
Message from dlopen:
Compiled VCL program failed to load:
  ./vcl.IoMQyW5q.so: undefined symbol: VRT_l_req_hash
Running dlopen failed, exit 1

VCL compilation failed


Any idea what could cause that ?
If not, any alternative that is known to work ?


Below is my default.vcl configuration (which is the file provided with the
plugin, with just the correct path added) :

#################################
# This block of inline C loads the library
C{
  #include <dlfcn.h>
  #include <stdlib.h>
  #include <stdio.h>

static const char* (*get_country_code)(char* ip) = NULL;

__attribute__((constructor)) void
load_module()
{
    const char* symbol_name = "get_country_code";
    const char* plugin_name = "/usr/local/lib/geoip_plugin.so";
    void* handle = NULL;

    handle = dlopen( plugin_name, RTLD_NOW );
    if (handle != NULL) {
        get_country_code = dlsym( handle, symbol_name );
        if (get_country_code == NULL)
            fprintf( stderr, "\nError: Could not load GeoIP
plugin:\n%s\n\n", dlerror() );
        else
            printf( "GeoIP plugin loaded successfully.\n");
    }
    else
        fprintf( stderr, "\nError: Could not load GeoIP plugin:\n%s\n\n",
dlerror() );
}
}C

# A sample backend declaration used for testing
backend default {
    .host = "localhost";
    .port = "8080";
}

sub vcl_hash {
# This block of inline C adds the country code to the hash
    C{
        if (get_country_code)
            VRT_l_req_hash(sp, (*get_country_code)( VRT_IP_string(sp,
VRT_r_server_ip(sp))));
    }C

# Insert any custom hashing here

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130320/a91c6350/attachment.html>


More information about the varnish-misc mailing list