diff --git a/modules/mmgeoip/README b/modules/mmgeoip/README index 9ef9066b4ca..11d6abcd764 100644 --- a/modules/mmgeoip/README +++ b/modules/mmgeoip/README @@ -26,6 +26,7 @@ Kobi Eshun 1.3. Exported Parameters 1.3.1. mmgeoip_city_db_path (string) + 1.3.2. cache_type (string) 1.4. Exported Functions @@ -36,7 +37,8 @@ Kobi Eshun List of Examples 1.1. Set “mmgeoip_city_db_path” parameter - 1.2. mmg_lookup usage + 1.2. Set “cache_type” parameter + 1.3. mmg_lookup usage Chapter 1. Admin Guide @@ -79,6 +81,27 @@ modparam("mmgeoip", "mmgeoip_city_db_path", "/usr/share/GeoIP/GeoLiteCity.dat") ... +1.3.2. cache_type (string) + + Databse memory caching options. The following options are + available: + * STANDARD - Read database from file system; least memory + used; + * MMAP_CACHE - Load database into mmap allocated memory; + WARNING: this option will cause a segmentation fault if + database file is changed at runtime! + * MEM_CACHE_CHECK - Load database into memory; this mode + checks for database updates; if database was modified, the + file will be reloaded after 60 seconds; it will be slower + than MMAP_CACHE but it will allow reloads; + + Default value for this parameter is MMAP_CACHE. + + Example 1.2. Set “cache_type” parameter +... +modparam("mmgeoip", "cache_type","MEM_CACHE_CHECK") +... + 1.4. Exported Functions 1.4.1. mmg_lookup([fields,]src,dst) @@ -104,7 +127,7 @@ modparam("mmgeoip", "mmgeoip_city_db_path", This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE,ERROR_ROUTE, and LOCAL_ROUTE. - Example 1.2. mmg_lookup usage + Example 1.3. mmg_lookup usage ... if(mmg_lookup("lon:lat","$si","$avp(lat_lon)")) { xlog("L_INFO","Source IP latitude:$(avp(lat_lon)[0])\n"); diff --git a/modules/mmgeoip/doc/mmgeoip_admin.xml b/modules/mmgeoip/doc/mmgeoip_admin.xml index 74001f888f1..ba0cb804518 100644 --- a/modules/mmgeoip/doc/mmgeoip_admin.xml +++ b/modules/mmgeoip/doc/mmgeoip_admin.xml @@ -1,9 +1,9 @@ - + &adminguide; - +
Overview @@ -18,7 +18,7 @@ by the script. Visit the MaxMind - website for more information on the location + website for more information on the location databases.
@@ -55,6 +55,7 @@
Exported Parameters +
<varname>mmgeoip_city_db_path</varname> (string) @@ -75,6 +76,53 @@ modparam("mmgeoip", "mmgeoip_city_db_path",
+ +
+ <varname>cache_type</varname> (string) + + Databse memory caching options. The following options are available: + + + + + STANDARD - Read database from file system; + least memory used; + + + + + + MMAP_CACHE - Load database into mmap allocated + memory; + WARNING: this option will cause a segmentation + fault if database file is changed at runtime! + + + + + + MEM_CACHE_CHECK - Load database into memory; + this mode checks for database updates; if database was modified, + the file will be reloaded after 60 seconds; it will be slower than + MMAP_CACHE but it will allow reloads; + + + + + + + Default value for this parameter is MMAP_CACHE. + + + Set <quote>cache_type</quote> parameter + +... +modparam("mmgeoip", "cache_type","MEM_CACHE_CHECK") +... + + +
+
Exported Functions @@ -107,7 +155,7 @@ modparam("mmgeoip", "mmgeoip_city_db_path", ac Area Code TZ Time Zone - + This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE,ERROR_ROUTE, and LOCAL_ROUTE. diff --git a/modules/mmgeoip/mmgeoip.c b/modules/mmgeoip/mmgeoip.c index 57eac3a3a24..fdd7dc3954c 100644 --- a/modules/mmgeoip/mmgeoip.c +++ b/modules/mmgeoip/mmgeoip.c @@ -33,6 +33,7 @@ #include "../../str.h" #include "../../usr_avp.h" #include "../../mod_fix.h" +#include "../../ut.h" #include "GeoIP.h" #include "GeoIPCity.h" @@ -41,6 +42,38 @@ static str MMG_city_db_path = {NULL, 0}; static GeoIP *MMG_gi = NULL; +static int geoip_cache_option = GEOIP_MMAP_CACHE; + + +int parse_mem_option( unsigned int type, void *val) +{ + str opt_s; + + static const str opt_STANDARD = str_init("STANDARD"); + static const str opt_MMAP = str_init("MMAP_CACHE"); + static const str opt_MEM_CHECK = str_init("MEM_CACHE_CHECK"); + + opt_s.s = (char *) val; + opt_s.len = strlen(opt_s.s); + + + if (opt_s.len == opt_STANDARD.len && + !strncasecmp(opt_s.s, opt_STANDARD.s, opt_s.len)) { + geoip_cache_option = GEOIP_STANDARD; + } else if (opt_s.len == opt_MMAP.len && + !strncasecmp(opt_s.s, opt_MMAP.s, opt_s.len)) { + geoip_cache_option = GEOIP_MMAP_CACHE; + } else if (opt_s.len == opt_MEM_CHECK.len && + !strncasecmp(opt_s.s, opt_MEM_CHECK.s, opt_s.len)) { + geoip_cache_option = GEOIP_MEMORY_CACHE|GEOIP_CHECK_CACHE; + } else { + LM_ERR("Invalid cache option!\n"); + return -1; + } + + return 0; +} + static int mod_init(void) { @@ -52,7 +85,8 @@ mod_init(void) } MMG_city_db_path.len=strlen(MMG_city_db_path.s); - if(0==(MMG_gi = GeoIP_open(MMG_city_db_path.s, GEOIP_MMAP_CACHE))){ + if(0==(MMG_gi = GeoIP_open(MMG_city_db_path.s, + geoip_cache_option))){ LM_ERR("Unable to open City DB at path '%.*s'.\n", MMG_city_db_path.len,MMG_city_db_path.s); return -1; @@ -234,6 +268,7 @@ w_lookup_cmd2(struct sip_msg *m, char *ipaddr, char *dst) */ static param_export_t mod_params[]={ {"mmgeoip_city_db_path", STR_PARAM, &MMG_city_db_path.s}, + {"cache_type", STR_PARAM|USE_FUNC_PARAM, parse_mem_option}, { 0,0,0 } };