mmgeoip Module


Table of Contents

1. Admin Guide
1.1. Overview
1.2. Dependencies
1.2.1. OpenSIPS Modules
1.2.2. External Libraries or Applications
1.3. Exported Parameters
1.3.1. mmgeoip_city_db_path (string)
1.3.2. cache_type (string)
1.4. Exported Functions
1.4.1. mmg_lookup([fields,]src,dst)
1.5. Known Issues
2. Contributors
2.1. By Commit Statistics
2.2. By Commit Activity
3. Documentation
3.1. Contributors

List of Tables

2.1. Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)
2.2. Most recently active contributors(1) to this module

List of Examples

1.1. Set mmgeoip_city_db_path parameter
1.2. Set cache_type parameter
1.3. mmg_lookup usage

Chapter 1. Admin Guide

1.1. Overview

This module is a lightweight wrapper for the MaxMind GeoIP API. It adds IP address-to-location lookup capability to OpenSIPS scripts.

Lookups are executed against the freely-available GeoLite City database; and the non-free GeoIP City database is drop-in compatible. All lookup fields provided by the API are accessible by the script. Visit the MaxMind website for more information on the location databases.

The module is compatible with both legacy GeoIP and the newer GeoIP2 APIs and databases.

1.2. Dependencies

1.2.1. OpenSIPS Modules

The following modules must be loaded before this module:

  • No dependencies on other OpenSIPS modules.

1.2.2. External Libraries or Applications

The following libraries or applications must be installed before running OpenSIPS with this module loaded:

  • libGeoIP - for the legacy GeoIP API and database;

  • libmaxminddb - for the GeoIP2 API and database.

You can select which GeoIP library to use by setting the GEOIP environment variable, before compiling the module, to one of the following values:

  • GEOIPLEGACY *** libGeoIP library shall be used

  • GEOIP2 *** libmaxminddb library shall be used;

IMPORTANT: If the selected library is not installed the module won't compile.

NOTE: If GEOIP env is not set, the module will try to find which GeoIP library is installed, prioritizing libmaxminddb.

1.3. Exported Parameters

1.3.1. mmgeoip_city_db_path (string)

Path to either a GeoLite or GeoIP City database file.

Mandatory parameter.

Example 1.1. Set mmgeoip_city_db_path parameter

...
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.

NOTE: If libmaxminddb is used, this parameter will be ignored as the library only supports loading the database into mmap allocated memory.

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)

Looks up information specified by field associated with the IP address src. The resulting data is loaded in reverse order into the dst AVP.

Parameters:

  • fields (string, optional) - a list of elements delimited by one of these separators: ':', '|', ',', '/' or ' '(space). Accepts the following tokens:

    • lat - Latitude

    • lon - Longitude

    • cont - Continent

    • cc - Country Code

    • reg - Region

    • city - City

    • pc - Postal Code

    • dma - DMA Code

    • ac - Area Code, only available in the legacy GeoIP database

    • tz - Time Zone

  • src (string) - IP address

  • dst (var) - AVP to return the information associated with the IP in.

When using the GeoIP2 library, each token from the list given in the fields parameter can be provided as a path to a specific key in the data structure associated with an IP. Thus, the token format is 'key_name.key_name[.key_name]*'. If a key's value is an array, instead of a subkey name, an index should be provided in order to select the appropriate value.

Example tokens: 'country.names.en', 'continent.names.en ', 'subdivisions.0.iso_code'. For more details about the available fields in the database and the key names that should be used to retrieve them, check the MaxMind GeoIP2 documentation.

This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE,ERROR_ROUTE, and LOCAL_ROUTE.

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");
  xlog("L_INFO","Source IP longitude:$(avp(lat_lon)[1])\n");
};
...
# fields format only supported for GeoIP2
if(mmg_lookup("continent.names.en:country.iso_code,",$si,$avp(geodata))) {
  xlog("L_INFO","Source IP country code:$(avp(geodata)[0])\n");
  xlog("L_INFO","Source IP continent:$(avp(geodata)[1])\n");
};
...
		

1.5. Known Issues

It is not currently possible to load an updated location database without first stalling the server.

Chapter 2. Contributors

2.1. By Commit Statistics

Table 2.1. Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)

 NameDevScoreCommitsLines ++Lines --
1. Vlad Patrascu (@rvlad-patrascu)155653238
2. Bogdan-Andrei Iancu (@bogdan-iancu)1083224
3. Razvan Crainea (@razvancrainea)108189
4. Liviu Chircu (@liviuchircu)1081638
5. Kobi Eshun (@ekobi)834804
6. Maksym Sobolyev (@sobomax)6466
7. Sergio Gutierrez4253
8. Ionut Ionita (@ionutrazvanionita)31841
9. Anca Vamanu3162
10. Peter Lemenkov (@lemenkov)3111

(1) DevScore = author_commits + author_lines_added / (project_lines_added / project_commits) + author_lines_deleted / (project_lines_deleted / project_commits)

(2) including any documentation-related commits, excluding merge commits. Regarding imported patches/code, we do our best to count the work on behalf of the proper owner, as per the "fix_authors" and "mod_renames" arrays in opensips/doc/build-contrib.sh. If you identify any patches/commits which do not get properly attributed to you, please submit a pull request which extends "fix_authors" and/or "mod_renames".

(3) ignoring whitespace edits, renamed files and auto-generated files

2.2. By Commit Activity

Table 2.2. Most recently active contributors(1) to this module

 NameCommit Activity
1. Maksym Sobolyev (@sobomax)Oct 2022 - Feb 2023
2. Razvan Crainea (@razvancrainea)Jun 2011 - Apr 2021
3. Liviu Chircu (@liviuchircu)Mar 2014 - Jan 2021
4. Vlad Patrascu (@rvlad-patrascu)May 2017 - Apr 2019
5. Bogdan-Andrei Iancu (@bogdan-iancu)Jul 2009 - Apr 2019
6. Peter Lemenkov (@lemenkov)Jun 2018 - Jun 2018
7. Ionut Ionita (@ionutrazvanionita)May 2016 - May 2016
8. Kobi Eshun (@ekobi)Nov 2008 - Dec 2009
9. Anca VamanuSep 2009 - Sep 2009
10. Sergio GutierrezNov 2008 - Nov 2008

(1) including any documentation-related commits, excluding merge commits

Chapter 3. Documentation

3.1. Contributors

Last edited by: Vlad Patrascu (@rvlad-patrascu), Peter Lemenkov (@lemenkov), Liviu Chircu (@liviuchircu), Ionut Ionita (@ionutrazvanionita), Bogdan-Andrei Iancu (@bogdan-iancu), Kobi Eshun (@ekobi).

Documentation Copyrights:

Copyright © 2008 SightSpeed, Inc.