maxmind / mmdbwriter

Go library for writing MaxMind DB (mmdb) files
Apache License 2.0
116 stars 28 forks source link

reserved network Error while using mmdb writer code #16

Closed juanmalaver closed 3 years ago

juanmalaver commented 3 years ago

I am using the sample code as a reference to add specific ipv4 address to my mmdb file. For every ip i am using i keep getting a similar error to the following one

2021/03/26 06:33:41 attempt to insert ::a00:0/106, which is in a reserved network

sonmething particular about this error is that is showing an ipv6 format in the error

`package main

import ( "log" "net" "os"

"github.com/maxmind/mmdbwriter"
"github.com/maxmind/mmdbwriter/inserter"
"github.com/maxmind/mmdbwriter/mmdbtype"

)

func main() { // Load the database we wish to enrich. writer, err := mmdbwriter.Load("GeoIP2-Country.mmdb", mmdbwriter.Options{}) if err != nil { log.Fatal(err) }

// Define and insert the new data.
_, sreNet, err := net.ParseCIDR("10.0.0.0/10")
if err != nil {
    log.Fatal(err)
}
sreData := mmdbtype.Map{
    "AcmeCorp.DeptName": mmdbtype.String("SRE"),
    "AcmeCorp.Environments": mmdbtype.Slice{
        mmdbtype.String("development"),
        mmdbtype.String("staging"),
        mmdbtype.String("production"),
    },
}
if err := writer.InsertFunc(sreNet, inserter.TopLevelMergeWith(sreData)); err != nil {
    log.Fatal(err)
}

`

this is also happening with other ip address like 172.16.0.0 and so on

nchelluri commented 3 years ago

Hi, can you try the following?

Change writer, err := mmdbwriter.Load("GeoIP2-Country.mmdb", mmdbwriter.Options{}) to writer, err := mmdbwriter.Load("GeoIP2-Country.mmdb", mmdbwriter.Options{IncludeReservedNetworks: true})?

See https://pkg.go.dev/github.com/maxmind/mmdbwriter#Options:~:text=%2F%2F%20IncludeReservedNetworks%20will%20allow%20reserved%20networks,IncludeReservedNetworks%20bool for why I think this may work for you.

juanmalaver commented 3 years ago

It work perfectly, thanks for the link !!