bryancall opened a new pull request, #12948:
URL: https://github.com/apache/trafficserver/pull/12948
The header_rewrite plugin's MaxMind geo lookup code used incorrect MMDB
field paths that don't match the structure of standard GeoLite2 and DBIP
databases, causing all geo lookups to return `(unknown)` or `-1`.
## Problem
The original code was written for a flat MMDB structure that doesn't
exist in standard MaxMind/DBIP databases. For example, `GEO_QUAL_COUNTRY`
queried a top-level `"country_code"` field, but GeoLite2 and DBIP databases
use a nested structure: `country -> names -> en`. Additionally,
`GEO_QUAL_COUNTRY_ISO` was completely missing from `get_geo_string()`,
and a null-after-delete bug in `initLibrary` could prevent the database
from being opened on retry.
* **Fix country name lookup** -- change `GEO_QUAL_COUNTRY` from flat
`"country_code"` to nested `"country", "names", "en"` path, matching
the standard GeoLite2/DBIP database structure
* **Add country ISO code lookup** -- add missing `GEO_QUAL_COUNTRY_ISO`
case using `"country", "iso_code"` path
* **Fix null-after-delete bug** -- set `gMaxMindDB = nullptr` after
`delete` on `MMDB_open` failure so subsequent `initLibrary` calls
can retry instead of seeing a dangling pointer
* **Add data validation** -- check `entry_data.has_data` and
`entry_data.type` before accessing entry values to avoid reading
uninitialized data
* **Fix memory leaks** -- ensure `MMDB_free_entry_data_list` is called
on all return paths in both `get_geo_string` and `get_geo_int`
The corrected field paths match what the `maxmind_acl` plugin already
uses successfully (see `plugins/experimental/maxmind_acl/mmdb.cc` line 566).
Verified with a standalone test program against DBIP Country Lite and
ASN Lite databases:
```
$ ./test_mmdb dbip-country-lite.mmdb 1.201.194.27
COUNTRY: South Korea
COUNTRY-ISO: KR
$ ./test_mmdb dbip-asn-lite.mmdb 1.201.194.27
ASN-NAME: KINX
ASN: 9286
```
Fixes: #11812
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]