diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..eaaf784 --- /dev/null +++ b/COPYING @@ -0,0 +1,4 @@ +Copyright (c) 2011 Varnish Software AS +Copyright (c) 2013 Martin Probst +... +See LICENSE for details. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c8831fd --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +Copyright (c) 2011 Varnish Software AS +Copyright (c) 2013 Martin Probst + +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 AUTHOR 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 AUTHOR 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. diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..ca6044c --- /dev/null +++ b/Makefile.am @@ -0,0 +1,3 @@ +ACLOCAL_AMFLAGS = -I m4 + +SUBDIRS = src man diff --git a/README.md b/README.md index b277bc1..3ae089e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ varnish-libvmod-geoip ===================== +Varnish VMOD for using GeoIP functionality inside VCL code. +For further details, please have a look into the manpage. -Varnish VMOD for using GeoIP +This module is tested and used in production on CentOS 5/6 systems. diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..9a12ef5 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +warn() { + echo "WARNING: $@" 1>&2 +} + +case `uname -s` in +Darwin) + LIBTOOLIZE=glibtoolize + ;; +FreeBSD) + LIBTOOLIZE=libtoolize + ;; +Linux) + LIBTOOLIZE=libtoolize + ;; +SunOS) + LIBTOOLIZE=libtoolize + ;; +*) + warn "unrecognized platform:" `uname -s` + LIBTOOLIZE=libtoolize +esac + +automake_version=`automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+'` +if [ -z "$automake_version" ] ; then + warn "unable to determine automake version" +else + case $automake_version in + 0.*|1.[0-8]|1.[0-8][.-]*) + warn "automake ($automake_version) detected; 1.9 or newer recommended" + ;; + *) + ;; + esac +fi + +set -ex + +aclocal -I m4 +$LIBTOOLIZE --copy --force +autoheader +automake --add-missing --copy --foreign +autoconf diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..35a98ca --- /dev/null +++ b/configure.ac @@ -0,0 +1,74 @@ +AC_PREREQ(2.59) +AC_COPYRIGHT([Copyright (c) 2013 Martin Probst]) +AC_INIT([libvmod-geoip], [trunk], [github@megamaddin.org]) +AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_SRCDIR(src/vmod_geoip.vcc) +AM_CONFIG_HEADER(config.h) + +AC_CANONICAL_SYSTEM +AC_LANG(C) + +AM_INIT_AUTOMAKE([foreign]) + +AC_GNU_SOURCE +AC_PROG_CC +AC_PROG_CC_STDC +if test "x$ac_cv_prog_cc_c99" = xno; then + AC_MSG_ERROR([Could not find a C99 compatible compiler]) +fi +AC_PROG_CPP + +AC_PROG_INSTALL +AC_PROG_LIBTOOL +AC_PROG_MAKE_SET + +# Check for rst utilities +AC_CHECK_PROGS(RST2MAN, [rst2man rst2man.py], "no") +if test "x$RST2MAN" = "xno"; then + AC_MSG_WARN([rst2man not found - not building man pages]) +fi +AM_CONDITIONAL(HAVE_RST2MAN, [test "x$RST2MAN" != "xno"]) + +# Check for pkg-config +PKG_PROG_PKG_CONFIG + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([sys/stdlib.h]) +AC_CHECK_HEADERS([GeoIP.h]) + +# Check for python +AC_CHECK_PROGS(PYTHON, [python3 python3.1 python3.2 python2.7 python2.6 python2.5 python2 python], [AC_MSG_ERROR([Python is needed to build this vmod, please install python.])]) + +# Varnish source tree +AC_ARG_VAR([VARNISHSRC], [path to Varnish source tree (mandatory)]) +if test "x$VARNISHSRC" = x; then + AC_MSG_ERROR([No Varnish source tree specified]) +fi +VARNISHSRC=`cd $VARNISHSRC && pwd` +AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h], + [], + [AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])] +) + +# Check that varnishtest is built in the varnish source directory +AC_CHECK_FILE([$VARNISHSRC/bin/varnishtest/varnishtest], + [], + [AC_MSG_FAILURE([Can't find "$VARNISHSRC/bin/varnishtest/varnishtest". Please build your varnish source directory])] +) + +# vmod installation dir +AC_ARG_VAR([VMODDIR], [vmod installation directory @<:@LIBDIR/varnish/vmods@:>@]) +if test "x$VMODDIR" = x; then + VMODDIR=`pkg-config --variable=vmoddir varnishapi` + if test "x$VMODDIR" = x; then + AC_MSG_FAILURE([Can't determine vmod installation directory]) + fi +fi + +AC_CONFIG_FILES([ + Makefile + src/Makefile + man/Makefile +]) +AC_OUTPUT diff --git a/m4/PLACEHOLDER b/m4/PLACEHOLDER new file mode 100644 index 0000000..e69de29 diff --git a/man/Makefile.am b/man/Makefile.am new file mode 100644 index 0000000..d008322 --- /dev/null +++ b/man/Makefile.am @@ -0,0 +1,4 @@ +ACLOCAL_AMFLAGS = -I $(top_srcdir)/m4 + +dist_man_MANS = vmod_geoip.3 +MAINTAINERCLEANFILES = $(dist_man_MANS) diff --git a/man/vmod_geoip.3 b/man/vmod_geoip.3 new file mode 100644 index 0000000..985f894 --- /dev/null +++ b/man/vmod_geoip.3 @@ -0,0 +1,183 @@ +.\" Man page generated from reStructeredText. +. +.TH VMOD_GEOIP 3 "2013-05-13" "0.4" "" +.SH NAME +vmod_geoip \- Varnish Geoip Module +. +.nr rst2man-indent-level 0 +. +.de1 rstReportMargin +\\$1 \\n[an-margin] +level \\n[rst2man-indent-level] +level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] +- +\\n[rst2man-indent0] +\\n[rst2man-indent1] +\\n[rst2man-indent2] +.. +.de1 INDENT +.\" .rstReportMargin pre: +. RS \\$1 +. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] +. nr rst2man-indent-level +1 +.\" .rstReportMargin post: +.. +.de UNINDENT +. RE +.\" indent \\n[an-margin] +.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] +.nr rst2man-indent-level -1 +.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] +.in \\n[rst2man-indent\\n[rst2man-indent-level]]u +.. +.SH SYNOPSIS +.sp +import geoip; +.SH DESCRipTION +.sp +libvmod\-geoip extends Varnish, to use Geoip functionality from inside VCL. +.SH FUNCTIONS +.SS load_geoip_db +.INDENT 0.0 +.TP +.B Prototype +.sp +.nf +.ft C +load_geoip_db(STRING S) +.ft P +.fi +.TP +.B Return value +. +VOID +.TP +.B Description +. +Loads the Geoip database file. +.TP +.B Example +.sp +.nf +.ft C +vcl_init { + geoip.load_geoip_db("/var/lib/Geoip/Geoip.dat"); + return (ok); +} +.ft P +.fi +.UNINDENT +.SS get_country_code +.INDENT 0.0 +.TP +.B Prototype +.sp +.nf +.ft C +get_country_code(STRING S) +.ft P +.fi +.TP +.B Return value +. +STRING country code, NULL as STRING if ip address was not found in the Geoip database. +.TP +.B Description +. +Returns the country code which belongs to the passed ip address. +.TP +.B Example +.sp +.nf +.ft C +vcl_recv { + set req.http.X\-Forwarded\-For = client.ip; + set req.http.X\-Country\-Code = geoip.get_country_code(req.http.X\-Forwarded\-For); +} +.ft P +.fi +.UNINDENT +.SS get_country_name +.INDENT 0.0 +.TP +.B Prototype +.sp +.nf +.ft C +get_country_name(STRING S) +.ft P +.fi +.TP +.B Return value +. +STRING country name, NULL as STRING if ip address was not found in the Geoip database. +.TP +.B Description +. +Returns the country name which belongs to the passed ip address. +.TP +.B Example +.sp +.nf +.ft C +vcl_recv { + set req.http.X\-Forwarded\-For = client.ip; + set req.http.X\-Country\-Name = geoip.get_country_name(req.http.X\-Forwarded\-For); +} +.ft P +.fi +.UNINDENT +.SH INSTALLATION +.sp +The source tree is based on autotools to configure the building, and +does also have the necessary bits in place to do functional unit tests +using the varnishtest tool. +.sp +Usage: +.sp +.nf +.ft C +\&./configure VARNISHSRC=DIR [VMODDIR=DIR] +.ft P +.fi +.sp +\fIVARNISHSRC\fP is the directory of the Varnish source tree for which to +compile your vmod. Both the \fIVARNISHSRC\fP and \fIVARNISHSRC/include\fP +will be added to the include search paths for your module. +.sp +Optionally you can also set the vmod install directory by adding +\fIVMODDIR=DIR\fP (defaults to the pkg\-config discovered directory from your +Varnish installation). +.sp +Make targets: +.INDENT 0.0 +.IP \(bu 2 +. +make \- builds the vmod +.IP \(bu 2 +. +make install \- installs your vmod in \fIVMODDIR\fP +.IP \(bu 2 +. +make check \- runs the unit tests in \fCsrc/tests/*.vtc\fP +.UNINDENT +.SH HISTORY +.sp +This manual page was released as part of the libvmod\-geoip package. +.SH COPYRIGHT +.sp +This document is licensed under the same license as the +libvmod\-geoip project. See LICENSE for details. +.INDENT 0.0 +.IP \(bu 2 +. +Copyright (c) 2011 Varnish Software +.IP \(bu 2 +. +Copyright (c) 2013 Martin Probst +.UNINDENT +.SH AUTHOR +Martin Probst +.\" Generated by docutils manpage writer. +.\" +. diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..37c2c42 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,29 @@ +INCLUDES = -I$(VARNISHSRC)/include -I$(VARNISHSRC) + +vmoddir = $(VMODDIR) +vmod_LTLIBRARIES = libvmod_geoip.la + +libvmod_geoip_la_LIBADD = -lGeoIP +libvmod_geoip_la_LDFLAGS = -module -export-dynamic -avoid-version -shared + +libvmod_geoip_la_SOURCES = \ + vcc_if.c \ + vcc_if.h \ + vmod_geoip.c + +vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_geoip.vcc + @PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod_geoip.vcc + +VMOD_TESTS = tests/*.vtc +.PHONY: $(VMOD_TESTS) + +tests/*.vtc: + $(VARNISHSRC)/bin/varnishtest/varnishtest -Dvarnishd=$(VARNISHSRC)/bin/varnishd/varnishd -Dvmod_topbuild=$(abs_top_builddir) $@ + +check: $(VMOD_TESTS) + +EXTRA_DIST = \ + vmod_geoip.vcc \ + $(VMOD_TESTS) + +CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h diff --git a/src/tests/el5-test01.vtc b/src/tests/el5-test01.vtc new file mode 100644 index 0000000..6de1a03 --- /dev/null +++ b/src/tests/el5-test01.vtc @@ -0,0 +1,28 @@ +varnishtest "Test libvmod-geoip functionality" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { + import geoip from "${vmod_topbuild}/src/.libs/libvmod_geoip.so"; + + sub vcl_init { + geoip.load_geoip_db("/var/lib/GeoIP/GeoIP.dat"); + } + + sub vcl_deliver { + set resp.http.Country-Code = geoip.get_country_code("20.30.40.50"); + set resp.http.Country-Name = geoip.get_country_name("20.30.40.50"); + } +} -start + +client c1 { + txreq -url "/" + rxresp + expect resp.http.Country-Code == "US" + expect resp.http.Country-Name == "United States" +} + +client c1 -run diff --git a/src/tests/el6-test01.vtc b/src/tests/el6-test01.vtc new file mode 100644 index 0000000..8408f24 --- /dev/null +++ b/src/tests/el6-test01.vtc @@ -0,0 +1,28 @@ +varnishtest "Test libvmod-geoip functionality" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { + import geoip from "${vmod_topbuild}/src/.libs/libvmod_geoip.so"; + + sub vcl_init { + geoip.load_geoip_db("/usr/share/GeoIP/GeoIP.dat"); + } + + sub vcl_deliver { + set resp.http.Country-Code = geoip.get_country_code("20.30.40.50"); + set resp.http.Country-Name = geoip.get_country_name("20.30.40.50"); + } +} -start + +client c1 { + txreq -url "/" + rxresp + expect resp.http.Country-Code == "US" + expect resp.http.Country-Name == "United States" +} + +client c1 -run diff --git a/src/vmod_geoip.c b/src/vmod_geoip.c new file mode 100644 index 0000000..be74022 --- /dev/null +++ b/src/vmod_geoip.c @@ -0,0 +1,147 @@ +/*- + * Copyright (c) 2010-2011 Varnish Software AS + * Copyright (c) 2013 Martin Probst + * All rights reserved. + * + * Author: Poul-Henning Kamp + * Author: Martin Probst + * + * 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 AUTHOR 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 AUTHOR 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. + */ + +#include +#include +#include +#include +#include "vrt.h" +#include "bin/varnishd/cache.h" + +#include "vcc_if.h" + +#define VMOD_NAME "vmod_geoip" + +typedef struct vmod_geoip { + unsigned magic; +#define VMGEOIP_MAGIC 0xafda74a9 + GeoIP *geoip; +} vmod_geoip; + +static const char *not_found = "NULL"; + +void __match_proto__() +vmod_load_geoip_db(struct sess *sp, struct vmod_priv *priv, const char *geoip_db) +{ + (void)sp; + AN(priv); + + vmod_geoip *vmg = (vmod_geoip *)priv->priv; + CHECK_OBJ_NOTNULL(vmg, VMGEOIP_MAGIC); + + if(!(access(geoip_db, R_OK))) { + VSL(SLT_Debug, 0, "%s: loading GeoIP-DB %s", VMOD_NAME, geoip_db); + vmg->geoip = GeoIP_open(geoip_db, GEOIP_MMAP_CACHE); + if(vmg->geoip == NULL) + VSL(SLT_Debug, 0, "%s: failed loading %s: %s", VMOD_NAME, geoip_db, strerror(errno)); + } else { + VSL(SLT_Debug, 0, "%s: failed to access %s: %s", VMOD_NAME, geoip_db, strerror(errno)); + } +} + +const char * __match_proto__() +vmod_get_country_code(struct sess *sp, struct vmod_priv *priv, const char *ip) +{ + vmod_geoip *vmg = (vmod_geoip *)priv->priv; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(vmg, VMGEOIP_MAGIC); + const char *cc; + + if(vmg->geoip == NULL) { + VSL(SLT_Debug, 0, "%s: GeoIP is not correctly initialized, maybe failed to load the database?", VMOD_NAME); + cc = not_found; + return(cc); + } + + if(ip == NULL) { + VSL(SLT_Debug, 0, "%s: IP string is NULL, passed the correct header?", VMOD_NAME); + cc = not_found; + return(cc); + } + + cc = GeoIP_country_code_by_addr(vmg->geoip, ip); + + if(cc == NULL) + cc = not_found; + + return(cc); +} + +const char * __match_proto__() +vmod_get_country_name(struct sess *sp, struct vmod_priv *priv, const char *ip) +{ + vmod_geoip *vmg = (vmod_geoip *)priv->priv; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(vmg, VMGEOIP_MAGIC); + const char *cn; + + if(vmg->geoip == NULL) { + VSL(SLT_Debug, 0, "%s: GeoIP is not correctly initialized, maybe failed to load the database?", VMOD_NAME); + cn = not_found; + return(cn); + } + + if(ip == NULL) { + VSL(SLT_Debug, 0, "%s: IP string is NULL, passed the correct header?", VMOD_NAME); + cn = not_found; + return(cn); + } + + cn = GeoIP_country_name_by_addr(vmg->geoip, ip); + + if(cn == NULL) + cn = not_found; + + return(cn); +} + +void +geoip_cleanup(void *gi) +{ + vmod_geoip *vmg = gi; + CHECK_OBJ_NOTNULL(vmg, VMGEOIP_MAGIC); + + GeoIP_delete(vmg->geoip); + FREE_OBJ(vmg); +} + +int +geoip_init(struct vmod_priv *priv, const struct VCL_conf *cfg) +{ + (void)cfg; + + vmod_geoip *vmg; + ALLOC_OBJ(vmg, VMGEOIP_MAGIC); + AN(vmg); + + priv->priv = vmg; + priv->free = geoip_cleanup; + return (0); +} diff --git a/src/vmod_geoip.vcc b/src/vmod_geoip.vcc new file mode 100644 index 0000000..63c90da --- /dev/null +++ b/src/vmod_geoip.vcc @@ -0,0 +1,34 @@ +#- +# Copyright (c) 2010-2011 Varnish Software AS +# Copyright (c) 2013 Martin Probst +# All rights reserved. +# +# Author: Poul-Henning Kamp +# Author: Martin Probst +# +# 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 AUTHOR 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 AUTHOR 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. + +Module geoip +Init geoip_init +Function VOID load_geoip_db(PRIV_VCL, STRING) +Function STRING get_country_code(PRIV_VCL, STRING) +Function STRING get_country_name(PRIV_VCL, STRING) diff --git a/varnish-libvmod-geoip.spec b/varnish-libvmod-geoip.spec new file mode 100644 index 0000000..abb3b8d --- /dev/null +++ b/varnish-libvmod-geoip.spec @@ -0,0 +1,89 @@ +%define _varnish varnish +%define _varnishbuildver 3.0.3 + +Name: varnish-libvmod-geoip +Version: 0.4 +Release: 1%{?dist} + +License: BSD +Url: http://github.com/MegaMaddin/%{name} +Group: System Environment/Daemons +Summary: Varnish VMOD for using GeoIP + +Source0: %{name}-%{version}.tar.gz +Source1: http://repo.varnish-cache.org/source/%{_varnish}-%{_varnishbuildver}.tar.gz + +# libvmod-geoip build requirements +BuildRequires: GeoIP-devel GeoIP %{?el5:GeoIP-data} +# Varnish build requirements +BuildRequires: pcre-devel automake libtool pkgconfig ncurses-devel libxslt groff + +Requires: %{_varnish} = %{_varnishbuildver} +Requires: %{_varnish}-libs = %{_varnishbuildver} +Requires: GeoIP %{?el5:GeoIP-data} + +BuildArch: x86_64 +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release} + +%description +This Varnish-Module enhances the varnish caching server to use the +Geo-IP functionality inside VCL-Code. + + +%prep +%setup -n %{name} +# vmods need the compiled varnish sources to build +# so first we have to build varnish +%setup -n %{name} -D -T -a 1 +cd %{_varnish}-%{_varnishbuildver} +%configure && %{__make} %{?_smp_mflags} +cd .. + +%build +./autogen.sh +%{__chmod} +x configure +export VARNISHSRC=%{_builddir}/%{name}/%{_varnish}-%{_varnishbuildver} +export VMODDIR=%{_libdir}/varnish/vmods +%configure +%{__make} %{?_smp_mflags} + +# adopted from varnish spec +%check + +# different place for GeoIP data files +%if 0%{?el6} + %{__rm} src/tests/el5-test01.vtc +%elseif 0%{?el5} + %{__rm} src/tests/el6-test01.vtc +%endif + +%{__make} check %{?el5:abs_top_builddir='$(VARNISHSRC)/$(top_builddir)/'} + +%install +%{__rm} -rf %{buildroot} +%{__make} install DESTDIR=%{buildroot} + +# adopted from varnish.spec +# None of these for fedora +find %{buildroot}/%{_libdir}/ -name '*.la' -exec rm -f {} ';' +find %{buildroot}/%{_libdir}/ -name '*.a' -exec rm -f {} ';' + +%clean +%{__rm} -rf %{buildroot} + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%defattr(-,root,root,-) +%{_libdir}/varnish/vmods/libvmod_geoip* +%{_mandir}/man3/vmod_geoip.3.gz + +%changelog +* Thu May 09 2013 Martin Probst - 0.4-1 +- Changed function-calls from unsupported IP args, to supported STRING args +- added manpage + +* Wed Apr 24 2013 Martin Probst 0.3-1 +- initial rpm release for el5 distribution