From 806c883a7f3a37cc3a4c649cc1351b008a74ac6f Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sun, 22 Mar 2026 12:29:00 +0100 Subject: [PATCH] Rename geoip_maxmind to geoip_mmdb with a backwards-compatible warn. This is a mmdb backend which supports various GeoIP providers, and we no longer use the maxmind library, so this makes sense. --- Makefile.windows | 6 +- src/modules.c | 20 +++ src/modules/Makefile.in | 8 +- src/modules/geoip_maxmind.c | 299 ------------------------------------ src/modules/geoip_mmdb.c | 299 ++++++++++++++++++++++++++++++++++++ 5 files changed, 326 insertions(+), 306 deletions(-) delete mode 100644 src/modules/geoip_maxmind.c create mode 100644 src/modules/geoip_mmdb.c diff --git a/Makefile.windows b/Makefile.windows index f8b0d59f7..6ffaa2df9 100644 --- a/Makefile.windows +++ b/Makefile.windows @@ -275,7 +275,7 @@ DLL_FILES=\ src/modules/geoip_base.dll \ src/modules/geoip_classic.dll \ src/modules/geoip_csv.dll \ - src/modules/geoip_maxmind.dll \ + src/modules/geoip_mmdb.dll \ src/modules/geoip-tag.dll \ src/modules/globops.dll \ src/modules/help.dll \ @@ -967,8 +967,8 @@ src/modules/geoip_classic.dll: src/modules/geoip_classic.c $(INCLUDES) src/modules/geoip_csv.dll: src/modules/geoip_csv.c $(INCLUDES) $(CC) $(MODCFLAGS) src/modules/geoip_csv.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/geoip_csv.pdb $(MODLFLAGS) -src/modules/geoip_maxmind.dll: src/modules/geoip_maxmind.c $(INCLUDES) - $(CC) $(MODCFLAGS) src/modules/geoip_maxmind.c src/modules/mmdb.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/geoip_maxmind.pdb $(MODLFLAGS) +src/modules/geoip_mmdb.dll: src/modules/geoip_mmdb.c $(INCLUDES) + $(CC) $(MODCFLAGS) src/modules/geoip_mmdb.c src/modules/mmdb.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/geoip_mmdb.pdb $(MODLFLAGS) src/modules/geoip-tag.dll: src/modules/geoip-tag.c $(INCLUDES) $(CC) $(MODCFLAGS) src/modules/geoip-tag.c /Fesrc/modules/ /Fosrc/modules/ /Fdsrc/modules/geoip-tag.pdb $(MODLFLAGS) diff --git a/src/modules.c b/src/modules.c index 9d8261526..f4af81dc7 100644 --- a/src/modules.c +++ b/src/modules.c @@ -275,6 +275,14 @@ int module_already_in_testing(const char *relpath) return 0; } +/** If a module has been renamed, return the new name, otherwise NULL */ +const char *module_renamed(const char *name) +{ + if (!strcmp(name, "geoip_maxmind")) + return "geoip_mmdb"; + return NULL; +} + /** Return an error string if module with 'name' should no longer be used. */ const char *is_module_deprecated(const char *name) { @@ -323,6 +331,18 @@ const char *Module_Create(const char *path_) relpath = Module_GetRelPath(path); + { + const char *newname; + if ((newname = module_renamed(relpath))) + { + config_warn("Module '%s' has been renamed to '%s'. " + "Please update your loadmodule line.", + relpath, newname); + path = Module_TransformPath(newname); + relpath = Module_GetRelPath(path); + } + } + if ((reterr = is_module_deprecated(relpath))) return reterr; diff --git a/src/modules/Makefile.in b/src/modules/Makefile.in index 66c9be0b7..6df58ee9b 100644 --- a/src/modules/Makefile.in +++ b/src/modules/Makefile.in @@ -88,7 +88,7 @@ MODULES= \ no-implicit-names.so maxperip.so utf8functions.so utf8only.so \ isupport.so extended-isupport.so \ $(GEOIP_CLASSIC_OBJECTS) \ - geoip_maxmind.so + geoip_mmdb.so MODULEFLAGS=@MODULEFLAGS@ RM=@RM@ @@ -123,7 +123,7 @@ geoip_classic.so: geoip_classic.c $(INCLUDES) $(CC) $(CFLAGS) $(MODULEFLAGS) $(GEOIP_CLASSIC_CFLAGS) -DDYNAMIC_LINKING \ -o geoip_classic.so geoip_classic.c @LDFLAGS_PRIVATELIBS@ $(GEOIP_CLASSIC_LIBS) -# geoip_maxmind uses shipped mmdb.c -geoip_maxmind.so: geoip_maxmind.c $(INCLUDES) +# geoip_mmdb uses shipped mmdb.c +geoip_mmdb.so: geoip_mmdb.c $(INCLUDES) $(CC) $(CFLAGS) $(MODULEFLAGS) -DDYNAMIC_LINKING \ - -o geoip_maxmind.so geoip_maxmind.c mmdb.c + -o geoip_mmdb.so geoip_mmdb.c mmdb.c diff --git a/src/modules/geoip_maxmind.c b/src/modules/geoip_maxmind.c deleted file mode 100644 index 01d577038..000000000 --- a/src/modules/geoip_maxmind.c +++ /dev/null @@ -1,299 +0,0 @@ -/* GEOIP maxmind module - * (C) Copyright 2021 Bram Matthys and the UnrealIRCd team - * License: GPLv2 or later - */ - -#include "unrealircd.h" -#include "mmdb.h" - -ModuleHeader MOD_HEADER - = { - "geoip_maxmind", - "5.2", - "GEOIP using maxmind databases", - "UnrealIRCd Team", - "unrealircd-6", - }; - -struct geoip_maxmind_config_s { - char *db_file; - char *asn_db_file; -/* for config reading only */ - int have_config; - int have_database; - int have_asn_database; -}; - -/* Variables */ - -struct geoip_maxmind_config_s geoip_maxmind_config; -MMDB_DB mmdb, asn_mmdb; - -/* Forward declarations */ -int geoip_maxmind_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs); -int geoip_maxmind_configposttest(int *errs); -int geoip_maxmind_configrun(ConfigFile *cf, ConfigEntry *ce, int type); -void geoip_maxmind_free(void); -GeoIPResult *geoip_lookup_maxmind(char *ip); - -int geoip_maxmind_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) -{ - ConfigEntry *cep; - int errors = 0; - - if (type != CONFIG_SET) - return 0; - - if (!ce || !ce->name) - return 0; - - if (strcmp(ce->name, "geoip-maxmind")) - return 0; - - geoip_maxmind_config.have_config = 1; - - for (cep = ce->items; cep; cep = cep->next) - { - if (!strcmp(cep->name, "database")) - { - if (geoip_maxmind_config.have_database) - { - config_error("%s:%i: duplicate item set::geoip-maxmind::%s", cep->file->filename, cep->line_number, cep->name); - continue; - } - if (!is_file_readable(cep->value, PERMDATADIR)) - { - config_error("%s:%i: set::geoip-maxmind::%s: cannot open file \"%s/%s\" for reading (%s)", cep->file->filename, cep->line_number, cep->name, PERMDATADIR, cep->value, strerror(errno)); - errors++; - continue; - } - geoip_maxmind_config.have_database = 1; - continue; - } - if (!strcmp(cep->name, "asn-database")) - { - if (geoip_maxmind_config.have_asn_database) - { - config_error("%s:%i: duplicate item set::geoip-maxmind::%s", cep->file->filename, cep->line_number, cep->name); - continue; - } - if (!is_file_readable(cep->value, PERMDATADIR)) - { - config_error("%s:%i: set::geoip-maxmind::%s: cannot open file \"%s/%s\" for reading (%s)", cep->file->filename, cep->line_number, cep->name, PERMDATADIR, cep->value, strerror(errno)); - errors++; - continue; - } - geoip_maxmind_config.have_asn_database = 1; - continue; - } - config_warn("%s:%i: unknown item set::geoip-maxmind::%s", cep->file->filename, cep->line_number, cep->name); - } - - *errs = errors; - return errors ? -1 : 1; -} - -int geoip_maxmind_configposttest(int *errs) -{ - int errors = 0; - if (geoip_maxmind_config.have_config) - { - if (!geoip_maxmind_config.have_database) - { - config_error("geoip_maxmind: no working database file specified! Remove set::geoip-maxmind to use defaults"); - errors++; - } - if (!geoip_maxmind_config.have_asn_database) - safe_free(geoip_maxmind_config.asn_db_file); /* at this point we aren't going to use ASN at all */ - - } else - { - safe_strdup(geoip_maxmind_config.db_file, "GeoLite2-Country.mmdb"); - safe_strdup(geoip_maxmind_config.asn_db_file, "GeoLite2-ASN.mmdb"); - - if (is_file_readable(geoip_maxmind_config.db_file, PERMDATADIR)) - { - geoip_maxmind_config.have_database = 1; - } else - { - config_warn("[geoip_maxmind] cannot open database file \"%s/%s\" for reading (%s)", PERMDATADIR, geoip_maxmind_config.db_file, strerror(errno)); - safe_free(geoip_maxmind_config.db_file); - } - - if (is_file_readable(geoip_maxmind_config.asn_db_file, PERMDATADIR)) - geoip_maxmind_config.have_asn_database = 1; - else - safe_free(geoip_maxmind_config.asn_db_file); - } - - *errs = errors; - return errors ? -1 : 1; -} - -int geoip_maxmind_configrun(ConfigFile *cf, ConfigEntry *ce, int type) -{ - ConfigEntry *cep; - - if (type != CONFIG_SET) - return 0; - - if (!ce || !ce->name) - return 0; - - if (strcmp(ce->name, "geoip-maxmind")) - return 0; - - for (cep = ce->items; cep; cep = cep->next) - { - if (!strcmp(cep->name, "database") && geoip_maxmind_config.have_database) - safe_strdup(geoip_maxmind_config.db_file, cep->value); - if (!strcmp(cep->name, "asn-database") && geoip_maxmind_config.have_asn_database) - safe_strdup(geoip_maxmind_config.asn_db_file, cep->value); - } - return 1; -} - -MOD_TEST() -{ - MARK_AS_OFFICIAL_MODULE(modinfo); - if (!CallbackAddPVoid(modinfo->handle, CALLBACKTYPE_GEOIP_LOOKUP, TO_PVOIDFUNC(geoip_lookup_maxmind))) - { - unreal_log(ULOG_ERROR, "geoip_maxmind", "GEOIP_ADD_CALLBACK_FAILED", NULL, - "geoip_maxmind: Could not install GEOIP_LOOKUP callback. " - "Most likely another geoip module is already loaded. " - "You can only load one!"); - return MOD_FAILED; - } - - geoip_maxmind_config.have_config = 0; - geoip_maxmind_config.have_database = 0; - geoip_maxmind_config.have_asn_database = 0; - HookAdd(modinfo->handle, HOOKTYPE_CONFIGTEST, 0, geoip_maxmind_configtest); - HookAdd(modinfo->handle, HOOKTYPE_CONFIGPOSTTEST, 0, geoip_maxmind_configposttest); - return MOD_SUCCESS; -} - -MOD_INIT() -{ - MARK_AS_OFFICIAL_MODULE(modinfo); - HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN, 0, geoip_maxmind_configrun); - return MOD_SUCCESS; -} - -MOD_LOAD() -{ - int status; - - geoip_maxmind_free(); - - if (geoip_maxmind_config.db_file) - { - convert_to_absolute_path(&geoip_maxmind_config.db_file, PERMDATADIR); - status = mmdb_open(&mmdb, geoip_maxmind_config.db_file); - if (status != MMDB_OK) - { - unreal_log(ULOG_WARNING, "geoip_maxmind", "GEOIP_CANNOT_OPEN_DB", NULL, - "Could not open '$filename' - $mmdb_error", - log_data_string("filename", geoip_maxmind_config.db_file), - log_data_string("mmdb_error", mmdb_strerror(status))); - geoip_maxmind_config.have_database = 0; - } - } - - if (geoip_maxmind_config.asn_db_file) - { - convert_to_absolute_path(&geoip_maxmind_config.asn_db_file, PERMDATADIR); - status = mmdb_open(&asn_mmdb, geoip_maxmind_config.asn_db_file); - if (status != MMDB_OK) - { - unreal_log(ULOG_WARNING, "geoip_maxmind", "GEOIP_CANNOT_OPEN_ASN_DB", NULL, - "Could not open '$filename' - $mmdb_error", - log_data_string("filename", geoip_maxmind_config.asn_db_file), - log_data_string("mmdb_error", mmdb_strerror(status))); - geoip_maxmind_config.have_asn_database = 0; - } - } - - return MOD_SUCCESS; -} - -MOD_UNLOAD() -{ - geoip_maxmind_free(); - safe_free(geoip_maxmind_config.db_file); - safe_free(geoip_maxmind_config.asn_db_file); - return MOD_SUCCESS; -} - -void geoip_maxmind_free(void) -{ - mmdb_close(&mmdb); - mmdb_close(&asn_mmdb); -} - -GeoIPResult *geoip_lookup_maxmind(char *ip) -{ - MMDB_Status status; - MMDB_Result result; - GeoIPResult *r; - - if (!ip) - return NULL; - - if (!geoip_maxmind_config.have_database) - return NULL; - - /* Country database */ - status = mmdb_lookup(&mmdb, ip, &result); - if (status != MMDB_OK) - { - unreal_log(ULOG_DEBUG, "geoip_maxmind", "GEOIP_DB_ERROR", NULL, - "mmdb: lookup error for $ip: $error", - log_data_string("ip", ip), - log_data_string("error", mmdb_strerror(status))); - return NULL; - } - - if (!result.has_data) /* no result */ - return NULL; - - r = safe_alloc(sizeof(GeoIPResult)); - - if (mmdb_get_str(&result, &r->country_code, "country", "iso_code") != MMDB_OK) - { - free_geoip_result(r); - return NULL; - } - - if (mmdb_get_str(&result, &r->country_name, "country", "names", "en") != MMDB_OK) - { - free_geoip_result(r); - return NULL; - } - - /* No ASN database? Then we are done. */ - if (!geoip_maxmind_config.have_asn_database) - return r; - - status = mmdb_lookup(&asn_mmdb, ip, &result); - - if (status != MMDB_OK) - { - unreal_log(ULOG_DEBUG, "geoip_maxmind", "GEOIP_ASN_DB_ERROR", NULL, - "mmdb: lookup error for $ip: $error", - log_data_string("ip", ip), - log_data_string("error", mmdb_strerror(status))); - return r; - } - - if (!result.has_data) - return r; /* no ASN result, we are done. */ - - if (mmdb_get_uint32(&result, &r->asn, "autonomous_system_number") != MMDB_OK) - return r; - - if (mmdb_get_str(&result, &r->asname, "autonomous_system_organization") != MMDB_OK) - return r; - - return r; -} diff --git a/src/modules/geoip_mmdb.c b/src/modules/geoip_mmdb.c new file mode 100644 index 000000000..a6bb2ad88 --- /dev/null +++ b/src/modules/geoip_mmdb.c @@ -0,0 +1,299 @@ +/* GEOIP mmdb module + * (C) Copyright 2021 Bram Matthys and the UnrealIRCd team + * License: GPLv2 or later + */ + +#include "unrealircd.h" +#include "mmdb.h" + +ModuleHeader MOD_HEADER + = { + "geoip_mmdb", + "5.2", + "GEOIP using mmdb databases", + "UnrealIRCd Team", + "unrealircd-6", + }; + +struct geoip_mmdb_config_s { + char *db_file; + char *asn_db_file; +/* for config reading only */ + int have_config; + int have_database; + int have_asn_database; +}; + +/* Variables */ + +struct geoip_mmdb_config_s geoip_mmdb_config; +MMDB_DB mmdb, asn_mmdb; + +/* Forward declarations */ +int geoip_mmdb_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs); +int geoip_mmdb_configposttest(int *errs); +int geoip_mmdb_configrun(ConfigFile *cf, ConfigEntry *ce, int type); +void geoip_mmdb_free(void); +GeoIPResult *geoip_lookup_mmdb(char *ip); + +int geoip_mmdb_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) +{ + ConfigEntry *cep; + int errors = 0; + + if (type != CONFIG_SET) + return 0; + + if (!ce || !ce->name) + return 0; + + if (strcmp(ce->name, "geoip-mmdb") && strcmp(ce->name, "geoip-maxmind")) + return 0; + + geoip_mmdb_config.have_config = 1; + + for (cep = ce->items; cep; cep = cep->next) + { + if (!strcmp(cep->name, "database")) + { + if (geoip_mmdb_config.have_database) + { + config_error("%s:%i: duplicate item set::geoip-mmdb::%s", cep->file->filename, cep->line_number, cep->name); + continue; + } + if (!is_file_readable(cep->value, PERMDATADIR)) + { + config_error("%s:%i: set::geoip-mmdb::%s: cannot open file \"%s/%s\" for reading (%s)", cep->file->filename, cep->line_number, cep->name, PERMDATADIR, cep->value, strerror(errno)); + errors++; + continue; + } + geoip_mmdb_config.have_database = 1; + continue; + } + if (!strcmp(cep->name, "asn-database")) + { + if (geoip_mmdb_config.have_asn_database) + { + config_error("%s:%i: duplicate item set::geoip-mmdb::%s", cep->file->filename, cep->line_number, cep->name); + continue; + } + if (!is_file_readable(cep->value, PERMDATADIR)) + { + config_error("%s:%i: set::geoip-mmdb::%s: cannot open file \"%s/%s\" for reading (%s)", cep->file->filename, cep->line_number, cep->name, PERMDATADIR, cep->value, strerror(errno)); + errors++; + continue; + } + geoip_mmdb_config.have_asn_database = 1; + continue; + } + config_warn("%s:%i: unknown item set::geoip-mmdb::%s", cep->file->filename, cep->line_number, cep->name); + } + + *errs = errors; + return errors ? -1 : 1; +} + +int geoip_mmdb_configposttest(int *errs) +{ + int errors = 0; + if (geoip_mmdb_config.have_config) + { + if (!geoip_mmdb_config.have_database) + { + config_error("geoip_mmdb: no working database file specified! Remove set::geoip-mmdb to use defaults"); + errors++; + } + if (!geoip_mmdb_config.have_asn_database) + safe_free(geoip_mmdb_config.asn_db_file); /* at this point we aren't going to use ASN at all */ + + } else + { + safe_strdup(geoip_mmdb_config.db_file, "GeoLite2-Country.mmdb"); + safe_strdup(geoip_mmdb_config.asn_db_file, "GeoLite2-ASN.mmdb"); + + if (is_file_readable(geoip_mmdb_config.db_file, PERMDATADIR)) + { + geoip_mmdb_config.have_database = 1; + } else + { + config_warn("[geoip_mmdb] cannot open database file \"%s/%s\" for reading (%s)", PERMDATADIR, geoip_mmdb_config.db_file, strerror(errno)); + safe_free(geoip_mmdb_config.db_file); + } + + if (is_file_readable(geoip_mmdb_config.asn_db_file, PERMDATADIR)) + geoip_mmdb_config.have_asn_database = 1; + else + safe_free(geoip_mmdb_config.asn_db_file); + } + + *errs = errors; + return errors ? -1 : 1; +} + +int geoip_mmdb_configrun(ConfigFile *cf, ConfigEntry *ce, int type) +{ + ConfigEntry *cep; + + if (type != CONFIG_SET) + return 0; + + if (!ce || !ce->name) + return 0; + + if (strcmp(ce->name, "geoip-mmdb") && strcmp(ce->name, "geoip-maxmind")) + return 0; + + for (cep = ce->items; cep; cep = cep->next) + { + if (!strcmp(cep->name, "database") && geoip_mmdb_config.have_database) + safe_strdup(geoip_mmdb_config.db_file, cep->value); + if (!strcmp(cep->name, "asn-database") && geoip_mmdb_config.have_asn_database) + safe_strdup(geoip_mmdb_config.asn_db_file, cep->value); + } + return 1; +} + +MOD_TEST() +{ + MARK_AS_OFFICIAL_MODULE(modinfo); + if (!CallbackAddPVoid(modinfo->handle, CALLBACKTYPE_GEOIP_LOOKUP, TO_PVOIDFUNC(geoip_lookup_mmdb))) + { + unreal_log(ULOG_ERROR, "geoip_mmdb", "GEOIP_ADD_CALLBACK_FAILED", NULL, + "geoip_mmdb: Could not install GEOIP_LOOKUP callback. " + "Most likely another geoip module is already loaded. " + "You can only load one!"); + return MOD_FAILED; + } + + geoip_mmdb_config.have_config = 0; + geoip_mmdb_config.have_database = 0; + geoip_mmdb_config.have_asn_database = 0; + HookAdd(modinfo->handle, HOOKTYPE_CONFIGTEST, 0, geoip_mmdb_configtest); + HookAdd(modinfo->handle, HOOKTYPE_CONFIGPOSTTEST, 0, geoip_mmdb_configposttest); + return MOD_SUCCESS; +} + +MOD_INIT() +{ + MARK_AS_OFFICIAL_MODULE(modinfo); + HookAdd(modinfo->handle, HOOKTYPE_CONFIGRUN, 0, geoip_mmdb_configrun); + return MOD_SUCCESS; +} + +MOD_LOAD() +{ + int status; + + geoip_mmdb_free(); + + if (geoip_mmdb_config.db_file) + { + convert_to_absolute_path(&geoip_mmdb_config.db_file, PERMDATADIR); + status = mmdb_open(&mmdb, geoip_mmdb_config.db_file); + if (status != MMDB_OK) + { + unreal_log(ULOG_WARNING, "geoip_mmdb", "GEOIP_CANNOT_OPEN_DB", NULL, + "Could not open '$filename' - $mmdb_error", + log_data_string("filename", geoip_mmdb_config.db_file), + log_data_string("mmdb_error", mmdb_strerror(status))); + geoip_mmdb_config.have_database = 0; + } + } + + if (geoip_mmdb_config.asn_db_file) + { + convert_to_absolute_path(&geoip_mmdb_config.asn_db_file, PERMDATADIR); + status = mmdb_open(&asn_mmdb, geoip_mmdb_config.asn_db_file); + if (status != MMDB_OK) + { + unreal_log(ULOG_WARNING, "geoip_mmdb", "GEOIP_CANNOT_OPEN_ASN_DB", NULL, + "Could not open '$filename' - $mmdb_error", + log_data_string("filename", geoip_mmdb_config.asn_db_file), + log_data_string("mmdb_error", mmdb_strerror(status))); + geoip_mmdb_config.have_asn_database = 0; + } + } + + return MOD_SUCCESS; +} + +MOD_UNLOAD() +{ + geoip_mmdb_free(); + safe_free(geoip_mmdb_config.db_file); + safe_free(geoip_mmdb_config.asn_db_file); + return MOD_SUCCESS; +} + +void geoip_mmdb_free(void) +{ + mmdb_close(&mmdb); + mmdb_close(&asn_mmdb); +} + +GeoIPResult *geoip_lookup_mmdb(char *ip) +{ + MMDB_Status status; + MMDB_Result result; + GeoIPResult *r; + + if (!ip) + return NULL; + + if (!geoip_mmdb_config.have_database) + return NULL; + + /* Country database */ + status = mmdb_lookup(&mmdb, ip, &result); + if (status != MMDB_OK) + { + unreal_log(ULOG_DEBUG, "geoip_mmdb", "GEOIP_DB_ERROR", NULL, + "mmdb: lookup error for $ip: $error", + log_data_string("ip", ip), + log_data_string("error", mmdb_strerror(status))); + return NULL; + } + + if (!result.has_data) /* no result */ + return NULL; + + r = safe_alloc(sizeof(GeoIPResult)); + + if (mmdb_get_str(&result, &r->country_code, "country", "iso_code") != MMDB_OK) + { + free_geoip_result(r); + return NULL; + } + + if (mmdb_get_str(&result, &r->country_name, "country", "names", "en") != MMDB_OK) + { + free_geoip_result(r); + return NULL; + } + + /* No ASN database? Then we are done. */ + if (!geoip_mmdb_config.have_asn_database) + return r; + + status = mmdb_lookup(&asn_mmdb, ip, &result); + + if (status != MMDB_OK) + { + unreal_log(ULOG_DEBUG, "geoip_mmdb", "GEOIP_ASN_DB_ERROR", NULL, + "mmdb: lookup error for $ip: $error", + log_data_string("ip", ip), + log_data_string("error", mmdb_strerror(status))); + return r; + } + + if (!result.has_data) + return r; /* no ASN result, we are done. */ + + if (mmdb_get_uint32(&result, &r->asn, "autonomous_system_number") != MMDB_OK) + return r; + + if (mmdb_get_str(&result, &r->asname, "autonomous_system_organization") != MMDB_OK) + return r; + + return r; +}