-
Notifications
You must be signed in to change notification settings - Fork 852
Fix header_rewrite MaxMind geo lookups for GeoIP2/GeoLite2 mmdb databases #12948
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bryancall
wants to merge
8
commits into
apache:master
Choose a base branch
from
bryancall:fix-header-rewrite-maxmind-geo
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+393
−44
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cc8fa32
Fix header_rewrite MaxMind geo lookups for standard mmdb databases
bryancall 58588ed
Address Copilot review feedback
bryancall 318b1be
Add MaxMind MMDB path validation test to header_rewrite
bryancall dc1ab5d
Address review feedback: check gai_error and add comments
bryancall fedfd37
Fix misleading comment: initLibrary runs under std::call_once, no retry
bryancall c24e446
Auto-detect MMDB schema: support both flat and nested field layouts
bryancall 64344c8
Move schema detection from runtime to initLibrary
bryancall 340aa8e
Address Copilot review feedback on test infrastructure
bryancall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| #!/usr/bin/env python3 | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """ | ||
| Generate test MMDB files for header_rewrite geo lookup unit tests. | ||
|
|
||
| Two schemas exist in the wild: | ||
|
|
||
| Nested (GeoLite2/GeoIP2/DBIP): country -> iso_code | ||
| Flat (vendor-specific): country_code (top-level) | ||
|
|
||
| This script generates one MMDB file for each schema so the C++ test | ||
| can verify that auto-detection works for both. | ||
|
|
||
| Requires: pip install mmdb-writer netaddr | ||
| """ | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| try: | ||
| from mmdb_writer import MMDBWriter, MmdbU32 | ||
| import netaddr | ||
| except ImportError: | ||
| print("SKIP: mmdb-writer or netaddr not installed (pip install mmdb-writer netaddr)", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def net(cidr): | ||
| return netaddr.IPSet([netaddr.IPNetwork(cidr)]) | ||
|
|
||
|
|
||
| def generate_flat(path): | ||
| """Flat schema: country_code at top level (vendor databases).""" | ||
| w = MMDBWriter(ip_version=4, database_type="Test-Flat-GeoIP") | ||
| w.insert_network( | ||
| net("8.8.8.0/24"), { | ||
| "country_code": "US", | ||
| "autonomous_system_number": MmdbU32(15169), | ||
| "autonomous_system_organization": "GOOGLE", | ||
| }) | ||
| w.insert_network( | ||
| net("1.2.3.0/24"), { | ||
| "country_code": "KR", | ||
| "autonomous_system_number": MmdbU32(9286), | ||
| "autonomous_system_organization": "KINX", | ||
| }) | ||
| w.to_db_file(path) | ||
|
|
||
|
|
||
| def generate_nested(path): | ||
| """Nested schema: country/iso_code (GeoLite2, GeoIP2, DBIP).""" | ||
| w = MMDBWriter(ip_version=4, database_type="Test-Nested-GeoIP2") | ||
bryancall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| w.insert_network( | ||
| net("8.8.8.0/24"), { | ||
| "country": { | ||
| "iso_code": "US", | ||
| "names": { | ||
| "en": "United States" | ||
| } | ||
| }, | ||
| "autonomous_system_number": MmdbU32(15169), | ||
| "autonomous_system_organization": "GOOGLE", | ||
| }) | ||
| w.insert_network( | ||
| net("1.2.3.0/24"), { | ||
| "country": { | ||
| "iso_code": "KR", | ||
| "names": { | ||
| "en": "South Korea" | ||
| } | ||
| }, | ||
| "autonomous_system_number": MmdbU32(9286), | ||
| "autonomous_system_organization": "KINX", | ||
| }) | ||
| w.to_db_file(path) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| outdir = sys.argv[1] if len(sys.argv) > 1 else "." | ||
|
|
||
| flat_path = os.path.join(outdir, "test_flat_geo.mmdb") | ||
| nested_path = os.path.join(outdir, "test_nested_geo.mmdb") | ||
|
|
||
| generate_flat(flat_path) | ||
| generate_nested(nested_path) | ||
|
|
||
| print(f"Generated {flat_path} ({os.path.getsize(flat_path)} bytes)") | ||
| print(f"Generated {nested_path} ({os.path.getsize(nested_path)} bytes)") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.