aboutsummaryrefslogtreecommitdiffstats
path: root/main/gdnsd/geoip-autodc.patch
blob: ec88491a1547ae0c128840ab903588bb75494b97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From: Timo TerÃs <timo.teras@iki.fi>

plugin_geoip: allow datacenters to be omitted from auto_dc_coords
    
sometimes we might need a datacenter to be accessible only via
overrides of map (via specific territory) or via nets (only
specific nets). this makes those datacenters to be sorted always
last.

http://code.google.com/p/gdnsd/issues/detail?id=17

diff --git a/plugins/meta/libgdmaps/gdmaps.c b/plugins/meta/libgdmaps/gdmaps.c
index b49bfa5..9d20351 100644
--- a/plugins/meta/libgdmaps/gdmaps.c
+++ b/plugins/meta/libgdmaps/gdmaps.c
@@ -180,13 +180,13 @@ static dcinfo_t* dcinfo_new(const vscf_data_t* dc_cfg, const vscf_data_t* dc_aut
         if(!vscf_is_hash(dc_auto_cfg))
             log_fatal("plugin_geoip: map '%s': auto_dc_coords must be a key-value hash", map_name);
         const unsigned num_auto = vscf_hash_get_len(dc_auto_cfg);
-        if(num_auto != num_dcs)
-            log_fatal("plugin_geoip: map '%s': auto_dc_coords hash must contain one entry for each datacenter in 'datacenters'", map_name);
-        info->coords = malloc(num_auto * 2 * sizeof(double));
+        info->coords = malloc(num_dcs * 2 * sizeof(double));
+        for(unsigned i = 0; i < 2*num_dcs; i++)
+            info->coords[i] = NAN;
         for(unsigned i = 0; i < num_auto; i++) {
             const char* dcname = vscf_hash_get_key_byindex(dc_auto_cfg, i, NULL);
             unsigned dcidx;
-            for(dcidx = 0; dcidx < info->num_dcs; dcidx++) {
+            for(dcidx = 0; dcidx < num_dcs; dcidx++) {
                 if(!strcmp(dcname, info->names[dcidx]))
                     break;
             }
@@ -438,7 +438,10 @@ static unsigned dclists_city_auto_map(dclists_t* lists, const char* map_name, co
     double dists[store_len];
     for(unsigned i = 0; i < num_dcs; i++) {
         const unsigned c_offs = i * 2;
-        dists[i + 1] = haversine(lat_rad, lon_rad, coords[c_offs], coords[c_offs + 1]);
+        if (coords[c_offs] != NAN)
+            dists[i + 1] = haversine(lat_rad, lon_rad, coords[c_offs], coords[c_offs + 1]);
+        else
+            dists[i + 1] = +INFINITY;
     }
 
     // Given the relatively small num_dcs of most configs,