[erlang-questions] IP search optimization

Dmitry Kolesnikov dmkolesnikov@REDACTED
Thu Nov 19 17:25:50 CET 2015


Hi,

I’ve did a similar but with persistent storage.

* use aton function to map CIDR into integer space
* use ordered_set ets table with CIDR as key

then you can use ets:next(…) to map IP to CIDR  


Best Regards, 
Dmitry



> On Nov 19, 2015, at 6:17 PM, Sid Muller <sid5@REDACTED> wrote:
> 
> Hi,
> 
> I was wondering if someone knowledgeable in IP/CIDR and bitstrings could give me some advice on how to proceed?
> 
> I'm storing network address in an ets table, for example:
> 77.242.16.0/20
> 31.24.168.0/21
> 
> And then I want to check if an IP (31.24.171.44) belongs to any network address in the ets table (the table can get pretty large).
> The crux of the matter is that I am not sure which of the following routes to pursue because I only get the IP but CIDR is stored in ets with each network:
> 
> 1. Should I store the network/CIDR in ets as tuples:
> {{77, 42, 6, 0}, 20}
> {{31, 24, 168, 0}, 21}
> and search for the IP as a tuple ({31, 24, 171, 44}) byte by byte?
> 
> 2. Should I store the Network as a bitstring:
> <<77,242,1:4>>
> <<31,24,21:5>>
> And then search for the IP as a bitstring match?
> 
> 3. Should I store the network/CIDR as binary:
> <<"77.242.16.0/20">>
> <<"31.24.168.0/21">>
> 
> I think the best solution would be the #2 but this one, just like the others I don't know the CIDR ahead of time to be able to trim the CIDR off the IP and then do a simple key based match from ets.
> 
> Any thoughts?
> 
> Thank you
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list