cidranger
cidranger copied to clipboard
Custom RangerEntry with Overlapping Networks
As posted below, you indicate that there is a way to handle overlapping CIDRs with a custom RangerEntry type. However, it doesn't seem to be possible from what I can tell.
We have a use case where we have multiple subnets that overlap, but are in different VRFs. We want to be able to load all these networks, enriched with the VRF in a custom RangerEntry type, and then retreive this data based on the VRF information.
Please review the code here to see if there is a way to do what we are looking for. - https://play.golang.org/p/9_1PKzEixkr Thanks!
Yes, deduplication were intentional, the idea behind it is that this will any metadata that you would like to attach to a CIDR block could be done through implementing your own custom type that implements the RangerEntry
interface https://github.com/yl2chen/cidranger/blob/928b519e5268fe386d0f7decce320205cc09ca95/cidranger.go#L48
Does that fit your use case?
Originally posted by @yl2chen in https://github.com/yl2chen/cidranger/issues/14#issuecomment-487434204
@yl2chen - Any insight or help you can provide on this?
I am having the same issue, I insert overlapping networks and the expectation is that when I look up an IP address using the ranger.ContainingNetworks(IP) that I would get multiple entries back. I don't get the point of deduplication. This issue cannot be resolved by adding a custom Entry. I have done that, but I still only get the last network that was added.
@yl2chen - Do you have any insight on this? We are really blocked by this issue, we need to know how to have multiple overlapping networks that do not deduplicate, as the data within them is different.
Thanks
try this out
https://play.golang.org/p/tsGYrn8WxLY
Thanks for the idea, but that won't really work for our case. We are trying to differentiate between two networks at two different sites with different vrfs. As you can see below, we only get one site back. We can't do the []int for the vrf b/c that doesn't actually help us to separate it. https://play.golang.org/p/3T42a7D25Wo
WE actually worked around the issue another way by doing a map[int]cidranger.Ranger with the vrf as the int. It works pretty well for our use case for now.
@tagur87 I don't think you get the idea, the idea is you can pass anything in. Instead of just vrf, you can do site and so many other field as well. check this example, and you easily pass what other custom struct you want, which means you won't be limit what a map do
https://play.golang.org/p/L8ohUbgUX2s
No I understand that @ldkingvivi, however what happens if I want to lookup overlapping subnets that exist in two different locations.
SiteA - 172.16.0.0/16 SiteB - 172.16.0.0/16
I enrich this data appropriately with all sorts of custom info(site,vrf,etc). Then I want to retrieve the info for both sites. Since cidranger dedups subnets with the same subnet/cidr, then I can't get the info from both sites, only one. Now extend this to 20+ sites. Still can't get the info I need.
Does that make more sense?
haven't touch github for a while, the idea is you need to aggregate/dedup the data to to per CIDR level first by yourself , like my above example shows, when you insert the cidr to the ranger, you should have that aggregate data ready, then when you search it back, you will have the aggregated data back as well. I do have something else do the aggregate part for me in https://github.com/ldkingvivi/go-aggregate with custom merge functions as well, which give me the flexibility to merge every custom struct.
If you depends on the cidranger to do this dedup for you, then you will have to implement some merge on insert func here as well, I did very basic version of merge on insert to save memory but without the custom merge func, you will have to implement that on top of it
https://github.com/ldkingvivi/cidranger/commit/4811571ec37eb145d638d5829b5317437b5508b1 https://github.com/ldkingvivi/cidranger/commit/38ddb9649d79ae434f2424e6a98add009fa2ce83 https://github.com/ldkingvivi/cidranger/commit/21a84088c634921fb787f2b46daa79c2a8cc5e26