aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2013-11-14 16:33:17 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2013-11-14 14:49:14 +0000
commit22934256b731fd05b1ee251e4fc6c7c57d783098 (patch)
tree7a3c269d7edcf3ef5a41b3b60f74320d833ddda2
parent03c9ccc812c60bad951f7b44d26bc5abfabbf001 (diff)
downloadaports-22934256b731fd05b1ee251e4fc6c7c57d783098.tar.bz2
aports-22934256b731fd05b1ee251e4fc6c7c57d783098.tar.xz
main/varnish: make maxminddb plugin always set X-GeoIP-*
to allow consistent headers in case of any error. also adds now X-GeoIP-Error in case of any error. (cherry picked from commit 8d0c891912c6e04a4f68cff0bd2c41f6adb0550e)
-rw-r--r--main/varnish/APKBUILD8
-rw-r--r--main/varnish/maxminddb.vcl37
2 files changed, 24 insertions, 21 deletions
diff --git a/main/varnish/APKBUILD b/main/varnish/APKBUILD
index b5b556898b..5598276c94 100644
--- a/main/varnish/APKBUILD
+++ b/main/varnish/APKBUILD
@@ -3,7 +3,7 @@
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=varnish
pkgver=3.0.4
-pkgrel=2
+pkgrel=3
pkgdesc="High-performance HTTP accelerator"
url="http://www.varnish-cache.org/"
arch="all"
@@ -82,17 +82,17 @@ md5sums="a130ce9c3504b9603a46542635e18701 varnish-3.0.4.tar.gz
d470dd6f893c1848c2d3f08ccb63d0d7 varnishd.initd
df8e6eb5591be4ab916ef4504b3ea05d varnishd.confd
a6cb8a43c9465699cf956dc992998225 varnishd.logrotate
-e0fe20e65072a3c3aca5d5455b65a216 maxminddb.vcl
+2ee926dd6ffa333d38310b9d78a43640 maxminddb.vcl
8c5532869bea7f668e2ce5d4585359f8 varnish-3.0.3-pthread-uclibc.patch"
sha256sums="4e044ccb5c76222bddf89c808f13ea8f66977972675aecb48a920f6800ad0f79 varnish-3.0.4.tar.gz
1f6473f3493a1ce9952218c96614e246445af17059fe06503f6532d5f5d65e3e varnishd.initd
24a9938a1d410579afd86507d645b4a27c36c99b3e73d966cdef15bd7f3c74ed varnishd.confd
017173cb42bb60f853063b7fbc843120c547e501233ce2299e1066b5d81e4d5e varnishd.logrotate
-bdec255d444250c41ec899b21825c8d10785ea4bbc1dbebb5b9b4583a8d36eaa maxminddb.vcl
+a985ddd283be5f22161ff246f237ec1bbb111da62492a109b44bac79816b0a19 maxminddb.vcl
3e39323ff4d741a9a0337e84eee7ce9f8b5419722a3b905f09ccf2486a9ff24f varnish-3.0.3-pthread-uclibc.patch"
sha512sums="d6fa8d320050f659f341af20b24c4401609ffd77207a7889b98e5378c507db04eda310e2b953b5144d748a0b3c08884e87d5c36962f0a38f03014708ff7c78d0 varnish-3.0.4.tar.gz
595b017bf890eaf6ffb9a35eef04983a85a1d90ddbfca835b4a003a7e78e1cf38d9910048fca5bb6a518e3480d6f1e23d1c3be1c1a47e7aafeac9b864c08e7c5 varnishd.initd
fd3d7e6fb8d0849533c0ad1ec0ba1d5221ac03bd2093052b72cd09f2276b16b888a145402507d18f4defd4ec4fd9b198ef5f87347d92e5fca43add30bb91956e varnishd.confd
8fb1cba86ede5eff28a494f6b1da1a651d66383cdeb63922104407f28903dea0c643155b6d7ac8353b8c63d480a6c5b43a70c7252bc51ee73317c33a1844c52c varnishd.logrotate
-166fe752710a62511d277f6c80ad2b7938d1e481cdf62d4af1064804099b9699d9c041135a7fb63f9eb43155348a1403d3dd50b32ef5b1057def6ffe460f9b12 maxminddb.vcl
+d444af35b498914ae761c6b37c1f76f705ece3e9a69c540133abe3d1a6857dd5d2e8737be6c01d97cd91a27066dd48f9fa758906adb8c3922d864707347affcd maxminddb.vcl
c06cd005ba04725ec69a9b5cb138fe2487bbd0b0e0aa4c6a39314b6473b160874d0c8452fca466e4efa907a998752e65940288a65a33b88cc4f206f1180b68d8 varnish-3.0.3-pthread-uclibc.patch"
diff --git a/main/varnish/maxminddb.vcl b/main/varnish/maxminddb.vcl
index b1cd732232..176eeea104 100644
--- a/main/varnish/maxminddb.vcl
+++ b/main/varnish/maxminddb.vcl
@@ -29,43 +29,46 @@ static void __attribute__((destructor)) __geoip_on_unload(void)
MMDB_close(&mmdb);
}
-static inline void __geoip_set_header(struct sess *sp, const char *hdr, MMDB_lookup_result_s *res, char **path)
+static inline void __geoip_set_header(struct sess *sp, const char *hdr, MMDB_lookup_result_s *res, const char * const* path)
{
MMDB_entry_data_s entry;
+ const char *value = "FAIL";
char buf[64];
int s;
+ if (!res->found_entry)
+ goto set_and_exit;
+
s = MMDB_aget_value(&res->entry, &entry, path);
if (s != MMDB_SUCCESS || !entry.has_data)
- return;
-
- if (entry.type != MMDB_DATA_TYPE_UTF8_STRING)
- return;
+ goto set_and_exit;
- if (entry.data_size+1 >= sizeof(buf))
- return;
+ if (entry.type != MMDB_DATA_TYPE_UTF8_STRING || entry.data_size+1 >= sizeof(buf))
+ goto set_and_exit;
memcpy(buf, entry.utf8_string, entry.data_size);
buf[entry.data_size] = 0;
+ value = buf;
- VRT_SetHdr(sp, HDR_REQ, hdr, buf, vrt_magic_string_end);
+set_and_exit:
+ VRT_SetHdr(sp, HDR_REQ, hdr, value, vrt_magic_string_end);
}
static void __geoip_set_headers(struct sess *sp)
{
static const char *continent_path[] = { "continent", "code", NULL };
static const char *country_path[] = { "country", "iso_code", NULL };
- MMDB_lookup_result_s res;
- int mmdb_error;
+ MMDB_lookup_result_s res = {0};
+ int e = MMDB_FILE_OPEN_ERROR;
+
+ if (mmdb.filename != NULL)
+ res = MMDB_lookup_sockaddr(&mmdb, (struct sockaddr*) VRT_r_client_ip(sp), &e);
- if (mmdb.filename == NULL)
- return;
+ if (e != MMDB_SUCCESS)
+ VRT_SetHdr(sp, HDR_REQ, "\016X-GeoIP-Error:", MMDB_strerror(e), vrt_magic_string_end);
- res = MMDB_lookup_sockaddr(&mmdb, (struct sockaddr*) VRT_r_client_ip(sp), &mmdb_error);
- if (mmdb_error == MMDB_SUCCESS) {
- __geoip_set_header(sp, "\022X-GeoIP-Continent:", &res, continent_path);
- __geoip_set_header(sp, "\020X-GeoIP-Country:", &res, country_path);
- }
+ __geoip_set_header(sp, "\022X-GeoIP-Continent:", &res, continent_path);
+ __geoip_set_header(sp, "\020X-GeoIP-Country:", &res, country_path);
}
}C