diff --git a/mmdb_writer/ipmmdb b/mmdb_writer/ipmmdb index 34e5415..22841da 100755 Binary files a/mmdb_writer/ipmmdb and b/mmdb_writer/ipmmdb differ diff --git a/mmdb_writer/mmdb_writer.go b/mmdb_writer/mmdb_writer.go index 3bf8f74..d03c5d1 100644 --- a/mmdb_writer/mmdb_writer.go +++ b/mmdb_writer/mmdb_writer.go @@ -8,6 +8,7 @@ import ( "os" "github.com/maxmind/mmdbwriter" + "github.com/maxmind/mmdbwriter/inserter" "github.com/maxmind/mmdbwriter/mmdbtype" ) @@ -27,6 +28,9 @@ func run() error { // "1.1.1.1": { // "is_proxy": true, // "score": 42 + // }, + // "1.0.0.0/8": { + // "is_hosting": true // } // } var input map[string]any @@ -52,9 +56,9 @@ func run() error { // Valid values are 24, 28, and 32. RecordSize: 28, - + IncludeReservedNetworks: true, - + DisableIPv4Aliasing: true, }) if err != nil { @@ -62,6 +66,20 @@ func run() error { } // Insert every IP/CIDR. + // + // Use TopLevelMergeWith instead of the normal Insert method. + // + // This is important when ranges overlap. For example: + // + // 1.2.0.0/16 -> {"is_proxy": true} + // 1.2.3.0/24 -> {"is_hosting": true} + // + // An address inside 1.2.3.0/24 will retain both fields: + // + // { + // "is_proxy": true, + // "is_hosting": true + // } for address, rawRecord := range input { network, err := parseNetwork(address) if err != nil { @@ -73,7 +91,10 @@ func run() error { return fmt.Errorf("invalid record for %q: %w", address, err) } - if err := tree.Insert(network, record); err != nil { + if err := tree.InsertFunc( + network, + inserter.TopLevelMergeWith(record), + ); err != nil { return fmt.Errorf("inserting %q: %w", address, err) } }