Skip to content

Commit

Permalink
Fix wrong impl failing IPv4-in-IPv6 when IPv4-mapped IPv6 is missing
Browse files Browse the repository at this point in the history
---
Fix wrong root in MMDB tree parser, which failed IPv4 lookups in IPv6
databases that don't include IPv4-mapped IPv6 addresses.

A bug that was part of locus since forever but didn't show up in MaxMind
databases since those appear to always include the IPv4-mapped IPv6
addresses node.

Thanks to https://github.com/nickjacob who left me the clues I needed in
an earlier closed PR:
* #39
  • Loading branch information
g-andrade committed May 4, 2024
1 parent b83d0cc commit 75e38f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- wrong root in MMDB tree parser, failing IPv4 lookups in IPv6 databases that
don't include IPv4-mapped IPv6 addresses [wrong since 1.0.0]

## [2.3.7] - 2024-03-16

### Added
Expand Down
8 changes: 6 additions & 2 deletions src/locus_mmdb_tree.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@
%% Macro Definitions
%% ------------------------------------------------------------------

% https://en.wikipedia.org/wiki/IPv6#IPv4-mapped_IPv6_addresses
-define(IPV4_IPV6_PREFIX, <<0:80, 16#FFFF:16>>).
% "When storing IPv4 addresses in an IPv6 tree, they are stored as-is, so they
% occupy the first 32-bits of the address space (from 0 to 2**32 - 1)."
%
% * https://maxmind.github.io/MaxMind-DB/#ipv4-addresses-in-an-ipv6-tree
%
-define(IPV4_IPV6_PREFIX, <<0:96>>).

%% ------------------------------------------------------------------
%% API Record and Type Definitions
Expand Down

0 comments on commit 75e38f3

Please sign in to comment.