Skip to content
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

Allow inserting ranges #23

Closed
UmanShahzad opened this issue Aug 6, 2021 · 7 comments · Fixed by #25
Closed

Allow inserting ranges #23

UmanShahzad opened this issue Aug 6, 2021 · 7 comments · Fixed by #25

Comments

@UmanShahzad
Copy link
Contributor

The Perl writer allows inserting IP ranges as well as IP networks. The Go writer only supports IP networks currently, so users requiring range insertions must convert ranges to networks manually first.

@UmanShahzad
Copy link
Contributor Author

I can possibly contribute this feature.

@UmanShahzad
Copy link
Contributor Author

UmanShahzad commented Aug 17, 2021

@oschwald would you be okay if I had to include a new library for achieving this? I can add the parts needed inline here but then you'd have to be responsible to maintain the difference.

@oschwald
Copy link
Member

That seems fine. Did you have a particular library in mind? github.com/inetaf/netaddr might be a good candidate, although they do make breaking changes from time to time yet. I'd probably prefer if it was not part of the external API so that we could easily replace the underlying implementation if necessary.

@UmanShahzad
Copy link
Contributor Author

netaddr is definitely one, but another one is one that I wrote over at https://github.com/ipinfo/cli/tree/master/lib - it's kind of a collection of many things but I can break out the IPv4/6 range/subnet-related code into a separate package. The particular functions I'd use are:

  • ToIP6Subnets to get all subnets within a range. Can also create a callback-based function so that we don't have to store all subnets in memory at once before writing them out to the tree.
  • Functions to convert net.IP into IP6 so we can use the above function.
  • Functions to convert the return type IP6Subnet into net.IPNet so we can use it in tree.Insert.

I'm fine with whatever you decide; can use either lib. Either way, a library will be needed, since we need to work on 128-bit numbers for calculating ipv6 subnets from ranges efficiently. It's not a lot of code to implement the needed 128-bit adds + bitwise-and/or, but guessing you don't want that in the codebase.

@oschwald
Copy link
Member

I'd prefer netaddr as we are already using it internally. I think you could just use the IPRange type and the Prefixes method to get the networks.

@UmanShahzad
Copy link
Contributor Author

Alright, no problem. Will probably make a PR tomorrow.

UmanShahzad added a commit to UmanShahzad/mmdbwriter that referenced this issue Aug 18, 2021
UmanShahzad added a commit to UmanShahzad/mmdbwriter that referenced this issue Aug 18, 2021
@UmanShahzad
Copy link
Contributor Author

Made #25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants