diff options
author | Timo Teräs <timo.teras@iki.fi> | 2013-01-14 14:54:35 +0200 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2013-01-14 14:54:35 +0200 |
commit | 417e7ba5f6ca607f94f008a3445a2839bef60a6f (patch) | |
tree | 809fa21050b8e0dd26f0e54f90728cc312e779d3 | |
parent | 7a030c45b097b136f520d36c567f76010bf96d04 (diff) | |
download | alpine_aports-417e7ba5f6ca607f94f008a3445a2839bef60a6f.tar.bz2 alpine_aports-417e7ba5f6ca607f94f008a3445a2839bef60a6f.tar.xz alpine_aports-417e7ba5f6ca607f94f008a3445a2839bef60a6f.zip |
main/gdnsd: add missing patch
-rw-r--r-- | main/gdnsd/geoip-autodc.patch | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/main/gdnsd/geoip-autodc.patch b/main/gdnsd/geoip-autodc.patch new file mode 100644 index 0000000000..ae313ef38e --- /dev/null +++ b/main/gdnsd/geoip-autodc.patch | |||
@@ -0,0 +1,211 @@ | |||
1 | From 8f172f642d4aa3a30f5a356a4611f66227e74681 Mon Sep 17 00:00:00 2001 | ||
2 | From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi> | ||
3 | Date: Tue, 21 Aug 2012 16:45:45 +0300 | ||
4 | Subject: [PATCH] plugin_geoip: allow datacenters to be omitted from | ||
5 | auto_dc_coords | ||
6 | MIME-Version: 1.0 | ||
7 | Content-Type: text/plain; charset=UTF-8 | ||
8 | Content-Transfer-Encoding: 8bit | ||
9 | |||
10 | Those datacenters will be never returned automatically. They are | ||
11 | available only from specific territories (map overrides) or subnets | ||
12 | (net overrides). | ||
13 | |||
14 | Signed-off-by: Timo Teräs <timo.teras@iki.fi> | ||
15 | --- | ||
16 | plugins/meta/libgdmaps/gdmaps.c | 46 +++++++++++++++----------- | ||
17 | plugins/meta/libgdmaps/t/Makefile.am | 3 +- | ||
18 | plugins/meta/libgdmaps/t/t14_missingcoords.c | 42 +++++++++++++++++++++++ | ||
19 | plugins/meta/libgdmaps/t/t14_missingcoords.cfg | 29 ++++++++++++++++ | ||
20 | 4 files changed, 100 insertions(+), 20 deletions(-) | ||
21 | create mode 100644 plugins/meta/libgdmaps/t/t14_missingcoords.c | ||
22 | create mode 100644 plugins/meta/libgdmaps/t/t14_missingcoords.cfg | ||
23 | |||
24 | diff --git a/plugins/meta/libgdmaps/gdmaps.c b/plugins/meta/libgdmaps/gdmaps.c | ||
25 | index be23d9b..b367e6f 100644 | ||
26 | --- a/plugins/meta/libgdmaps/gdmaps.c | ||
27 | +++ b/plugins/meta/libgdmaps/gdmaps.c | ||
28 | @@ -148,6 +148,7 @@ static dcinfo_t* dcinfo_new(const vscf_data_t* dc_cfg, const vscf_data_t* dc_aut | ||
29 | dcinfo_t* info = malloc(sizeof(dcinfo_t)); | ||
30 | |||
31 | const unsigned num_dcs = vscf_array_get_len(dc_cfg); | ||
32 | + unsigned num_auto = 0; | ||
33 | if(!num_dcs) | ||
34 | log_fatal("plugin_geoip: map '%s': 'datacenters' must be an array of one or more strings", map_name); | ||
35 | if(num_dcs > 254) | ||
36 | @@ -164,34 +165,26 @@ static dcinfo_t* dcinfo_new(const vscf_data_t* dc_cfg, const vscf_data_t* dc_aut | ||
37 | log_fatal("plugin_geoip: map '%s': datacenter name 'auto' is illegal", map_name); | ||
38 | } | ||
39 | |||
40 | - if(dc_auto_limit_cfg) { | ||
41 | - unsigned long auto_limit_ul; | ||
42 | - if(!vscf_is_simple(dc_auto_limit_cfg) || !vscf_simple_get_as_ulong(dc_auto_limit_cfg, &auto_limit_ul)) | ||
43 | - log_fatal("plugin_geoip: map '%s': auto_dc_limit must be a single unsigned integer value", map_name); | ||
44 | - if(auto_limit_ul > num_dcs || !auto_limit_ul) | ||
45 | - auto_limit_ul = num_dcs; | ||
46 | - info->auto_limit = auto_limit_ul; | ||
47 | - } | ||
48 | - else { | ||
49 | - info->auto_limit = (num_dcs > 3) ? 3 : num_dcs; | ||
50 | - } | ||
51 | - | ||
52 | if(dc_auto_cfg) { | ||
53 | if(!vscf_is_hash(dc_auto_cfg)) | ||
54 | log_fatal("plugin_geoip: map '%s': auto_dc_coords must be a key-value hash", map_name); | ||
55 | - const unsigned num_auto = vscf_hash_get_len(dc_auto_cfg); | ||
56 | - if(num_auto != num_dcs) | ||
57 | - log_fatal("plugin_geoip: map '%s': auto_dc_coords hash must contain one entry for each datacenter in 'datacenters'", map_name); | ||
58 | - info->coords = malloc(num_auto * 2 * sizeof(double)); | ||
59 | + num_auto = vscf_hash_get_len(dc_auto_cfg); | ||
60 | + if (info->auto_limit > num_auto) | ||
61 | + info->auto_limit = num_auto; | ||
62 | + info->coords = malloc(num_dcs * 2 * sizeof(double)); | ||
63 | + for(unsigned i = 0; i < 2*num_dcs; i++) | ||
64 | + info->coords[i] = NAN; | ||
65 | for(unsigned i = 0; i < num_auto; i++) { | ||
66 | const char* dcname = vscf_hash_get_key_byindex(dc_auto_cfg, i, NULL); | ||
67 | unsigned dcidx; | ||
68 | - for(dcidx = 0; dcidx < info->num_dcs; dcidx++) { | ||
69 | + for(dcidx = 0; dcidx < num_dcs; dcidx++) { | ||
70 | if(!strcmp(dcname, info->names[dcidx])) | ||
71 | break; | ||
72 | } | ||
73 | - if(dcidx == info->num_dcs) | ||
74 | + if(dcidx == num_dcs) | ||
75 | log_fatal("plugin_geoip: map '%s': auto_dc_coords key '%s' not matched from 'datacenters' list", map_name, dcname); | ||
76 | + if(!isnan(info->coords[(dcidx*2)])) | ||
77 | + log_fatal("plugin_geoip: map '%s': auto_dc_coords key '%s' defined twice", map_name, dcname); | ||
78 | const vscf_data_t* coord_cfg = vscf_hash_get_data_byindex(dc_auto_cfg, i); | ||
79 | const vscf_data_t* lat_cfg; | ||
80 | const vscf_data_t* lon_cfg; | ||
81 | @@ -216,6 +209,18 @@ static dcinfo_t* dcinfo_new(const vscf_data_t* dc_cfg, const vscf_data_t* dc_aut | ||
82 | info->coords = NULL; | ||
83 | } | ||
84 | |||
85 | + if(dc_auto_limit_cfg) { | ||
86 | + unsigned long auto_limit_ul; | ||
87 | + if(!vscf_is_simple(dc_auto_limit_cfg) || !vscf_simple_get_as_ulong(dc_auto_limit_cfg, &auto_limit_ul)) | ||
88 | + log_fatal("plugin_geoip: map '%s': auto_dc_limit must be a single unsigned integer value", map_name); | ||
89 | + if(auto_limit_ul > num_auto || !auto_limit_ul) | ||
90 | + auto_limit_ul = num_auto; | ||
91 | + info->auto_limit = auto_limit_ul; | ||
92 | + } | ||
93 | + else { | ||
94 | + info->auto_limit = (num_auto > 3) ? 3 : num_auto; | ||
95 | + } | ||
96 | + | ||
97 | return info; | ||
98 | } | ||
99 | |||
100 | @@ -438,7 +443,10 @@ static unsigned dclists_city_auto_map(dclists_t* lists, const char* map_name, co | ||
101 | double dists[store_len]; | ||
102 | for(unsigned i = 0; i < num_dcs; i++) { | ||
103 | const unsigned c_offs = i * 2; | ||
104 | - dists[i + 1] = haversine(lat_rad, lon_rad, coords[c_offs], coords[c_offs + 1]); | ||
105 | + if (!isnan(coords[c_offs])) | ||
106 | + dists[i + 1] = haversine(lat_rad, lon_rad, coords[c_offs], coords[c_offs + 1]); | ||
107 | + else | ||
108 | + dists[i + 1] = +INFINITY; | ||
109 | } | ||
110 | |||
111 | // Given the relatively small num_dcs of most configs, | ||
112 | diff --git a/plugins/meta/libgdmaps/t/Makefile.am b/plugins/meta/libgdmaps/t/Makefile.am | ||
113 | index f83592f..e9d26ce 100644 | ||
114 | --- a/plugins/meta/libgdmaps/t/Makefile.am | ||
115 | +++ b/plugins/meta/libgdmaps/t/Makefile.am | ||
116 | @@ -41,7 +41,8 @@ TESTLIST = \ | ||
117 | t10_def \ | ||
118 | t11_def2 \ | ||
119 | t12_defnone \ | ||
120 | - t13_castatdef | ||
121 | + t13_castatdef \ | ||
122 | + t14_missingcoords | ||
123 | |||
124 | check_PROGRAMS = $(TESTLIST:=.bin) | ||
125 | |||
126 | diff --git a/plugins/meta/libgdmaps/t/t14_missingcoords.c b/plugins/meta/libgdmaps/t/t14_missingcoords.c | ||
127 | new file mode 100644 | ||
128 | index 0000000..9329ee3 | ||
129 | --- /dev/null | ||
130 | +++ b/plugins/meta/libgdmaps/t/t14_missingcoords.c | ||
131 | @@ -0,0 +1,42 @@ | ||
132 | +/* Copyright © 2012 Brandon L Black <blblack@gmail.com> | ||
133 | + * | ||
134 | + * This file is part of gdnsd-plugin-geoip. | ||
135 | + * | ||
136 | + * gdnsd-plugin-geoip is free software: you can redistribute it and/or modify | ||
137 | + * it under the terms of the GNU General Public License as published by | ||
138 | + * the Free Software Foundation, either version 3 of the License, or | ||
139 | + * (at your option) any later version. | ||
140 | + * | ||
141 | + * gdnsd-plugin-geoip is distributed in the hope that it will be useful, | ||
142 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
143 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
144 | + * GNU General Public License for more details. | ||
145 | + * | ||
146 | + * You should have received a copy of the GNU General Public License | ||
147 | + * along with gdnsd. If not, see <http://www.gnu.org/licenses/>. | ||
148 | + * | ||
149 | + */ | ||
150 | + | ||
151 | +// Unit test for gdmaps | ||
152 | + | ||
153 | +#include "config.h" | ||
154 | +#include <gdnsd-log.h> | ||
155 | +#include "gdmaps_test.h" | ||
156 | + | ||
157 | +int main(int argc, char* argv[]) { | ||
158 | + if(argc != 2) | ||
159 | + log_fatal("root directory must be set on commandline"); | ||
160 | + | ||
161 | + gdmaps_t* gdmaps = gdmaps_test_init(argv[1]); | ||
162 | + unsigned tnum = 0; | ||
163 | + //datacenters => [ us, ie, sg, tr, br ] | ||
164 | + gdmaps_test_lookup_check(tnum++, gdmaps, "my_prod_map", "137.138.144.168", "\2\1\5\3", 16); // Geneva | ||
165 | + gdmaps_test_lookup_check(tnum++, gdmaps, "my_prod_map", "69.58.186.119", "\1\2\5\3", 16); // US East Coast | ||
166 | + gdmaps_test_lookup_check(tnum++, gdmaps, "my_prod_map", "117.53.170.202", "\3\5\1\2", 20); // Australia | ||
167 | + gdmaps_test_lookup_check(tnum++, gdmaps, "my_prod_map", "133.11.114.194", "\2\4", 8); // JP, horrible custom 'map' entry | ||
168 | + gdmaps_test_lookup_check(tnum++, gdmaps, "my_prod_map", "10.0.0.44", "\4\2", 24); // Custom 'nets' entry | ||
169 | + gdmaps_test_lookup_check(tnum++, gdmaps, "my_prod_map", "10.0.1.44", "", 24); // Custom 'nets' entry, empty | ||
170 | + gdmaps_test_lookup_check(tnum++, gdmaps, "my_prod_map", "192.168.1.1", "\1\2\3\4\5", 16); // meta-default, no loc | ||
171 | + gdmaps_destroy(gdmaps); | ||
172 | +} | ||
173 | + | ||
174 | diff --git a/plugins/meta/libgdmaps/t/t14_missingcoords.cfg b/plugins/meta/libgdmaps/t/t14_missingcoords.cfg | ||
175 | new file mode 100644 | ||
176 | index 0000000..8c57cdd | ||
177 | --- /dev/null | ||
178 | +++ b/plugins/meta/libgdmaps/t/t14_missingcoords.cfg | ||
179 | @@ -0,0 +1,29 @@ | ||
180 | +options => { debug => true } | ||
181 | +plugins => { | ||
182 | + geoip => { | ||
183 | + maps => { | ||
184 | + # bringing it all together: city-auto w/ 5 dcs, | ||
185 | + # dual GeoIP inputs, custom maps, custom nets | ||
186 | + # testing with one datacenter not used in auto coords | ||
187 | + my_prod_map => { | ||
188 | + geoip_db => GeoLiteCityv6-20111210.dat, | ||
189 | + geoip_db_v4_overlay => GeoLiteCity-20111210.dat, | ||
190 | + datacenters => [ us, ie, sg, tr, br ] | ||
191 | + auto_dc_limit => 5, | ||
192 | + auto_dc_coords => { | ||
193 | + us = [ 38.9, -77 ] | ||
194 | + ie = [ 53.3, -6.3 ] | ||
195 | + sg = [ 1.3, 103.9 ] | ||
196 | + br = [ -22.9, -43.2 ] | ||
197 | + } | ||
198 | + map => { | ||
199 | + AS => { JP => [ ie, tr ] } | ||
200 | + } | ||
201 | + nets => { | ||
202 | + 10.0.1.0/24 => [ ] | ||
203 | + 10.0.0.0/24 => [ tr, ie ] | ||
204 | + } | ||
205 | + } | ||
206 | + } | ||
207 | + } | ||
208 | +} | ||
209 | -- | ||
210 | 1.7.12 | ||
211 | |||