vmod_geoip2(3)

Name
vmod_geoip2 - Varnish GeoIP2 Lookup Module

SYNOPSIS

            import geoip2 [as name] [from "path"]

            new xgeoip2 = geoip2.geoip2(STRING filename)

                STRING xgeoip2.lookup(STRING path, IP ip, BOOL json)

DESCRIPTION

  new xgeoip2 = geoip2.geoip2(STRING filename)

    Description
        Opens the GeoIP2 MaxMind binary DB file.

        Databases in CSV format are not supported.

    Example
        new country = geoip2.geoip2("/path/to/GeoLite2-Country.mmdb");

  STRING xgeoip2.lookup(STRING path, IP ip, BOOL json=0)

    Description
        Looks up the IP address ip using the lookup path path.

        The path consists of a set of map keys and array indexes separated by slash (/), e.g. "subdivisions/0/names/en".

        Returns the value associated with the specified path, or an empty string if the IP address or the path are not found, the value type is not supported or an error occurred.

        If the value associated with the specified path is bytes or string type and json is true, the result will be converted to a JSON string.

        Supported value types include: boolean, bytes, double, float, int32, uint16, uint32, uint64 and (UTF-8) string.

        Diagnostic and error messages, if any, are logged to the VSL using the Debug and Error tags, respectively.

    Example
        if (country.lookup("country/names/en", client.ip) != "Japan") {
        ...
        }

ERRORS

    •   "geoip2.geoip2: %s"

    •   "geoip2.geoip2: Using maxminddb %s"

    •   "geoip2.lookup: Database not open"

    •   "geoip2.lookup: Invalid or missing path (%s)"

    •   "geoip2.lookup: MMDB_aget_value: %s"

    •   "geoip2.lookup: MMDB_lookup_sockaddr: %s"

    •   "geoip2.lookup: Missing ip address"

    •   "geoip2.lookup: No data for this path (%s)"

    •   "geoip2.lookup: No entry for this IP address (%s)"

    •   "geoip2.lookup: Out of workspace"

    •   "geoip2.lookup: Unsupported data type (%d)"

NOTES

This implementation limits the path to a maximum of 9 map keys and/or array indexes.

SEE ALSO

    •   mmdblookup(1)

    •   varnishlog(1)

    •   vsl(7)

    •   GeoIP2 Databases <https://www.maxmind.com/en/geoip2-databases>

    •   GeoIP2 Update program <https://github.com/maxmind/geoipupdate>

COPYRIGHT

            Copyright (c) 2014-2016, Federico G. Schwindt <fgsch@lodoss.net>
            All rights reserved.

            Redistribution and use in source and binary forms, with or without
            modification, are permitted provided that the following conditions
            are met:

            1. Redistributions of source code must retain the above copyright
               notice, this list of conditions and the following disclaimer.

            2. Redistributions in binary form must reproduce the above copyright
               notice, this list of conditions and the following disclaimer in the
               documentation and/or other materials provided with the distribution.

            THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
            "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
            LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
            A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
            HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
            SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
            TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
            PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
            LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
            NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
            SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.