I think the most efficient technique is to make the per-address lookup
table an mmap'd array of pointers to entries in the existing route table.
The existing routing table lookup returns a pointer to an entry
in the routing table or NULL, so none of the program logic needs
major change except the process of loading the routing table itself
would need to update the per-address lookup table too.
And your idea of toggling between two tables is good too, as it
saves all the locking logic. You just update the one that's not
in use, then flip.
That makes it effectively addrtable[2][2**24], right?
That way we can make the per-address lookup VERY fast, and offload
all the table updating to a separate thread. It also allows quick
access to the routes table entry on successful lookups to update its
statistics counters and retrieve its gateway address. One extra
step of indirection is cheap. And I don't have to change much
code (just two major subroutines), which is always a good thing.
I'm going to have to look into this. Thanks for the ideas!
- Brian
On Mon, May 01, 2017 at 08:23:09PM +0200, Rob Janssen wrote:
My estimate of 128MB was based on having 4 bytes per
entry and 2 tables for
convenient updating (update one table then toggle a single indicator or pointer
to make the updated table active).
Of course when you require more bytes per entry the table will expand, but
8-16 bytes per entry should still fit comfortably in a modern machine.