The idea here is to help when populating my /etc/pf.losers and similar
files.  I want a simple database that can track previous offenders and
double their penalty time each time there is a repat offense, keep data
from the registry (ARIN, RIPE, LACNIC, APNIC, KRNIC, et. al.), coalesce
adjacent IPv4 address ranges where possible, etc.

Coalescing database entries
---------------------------
If I widen a prefix...

Let's say I have 10.1.1/24 and I want to see if I can widen it to
10.1.1/23.  What I need to do is take the number of addresses in the
widened range, then figure out how many of those addresses are occupied.
I know that half of the addresses are occupied (10.1.1.0 to 10.1.1.255).

Due to overlaps, I can't just decrement a count of addresses.  What I
really need is an IPv4AddressRange class.  And I need a set of them,
since walking the database looking for prefixes contained in the wider
prefix will potentially yield disjoint ranges.  In fact that's my test:
if I wind up with a set of contiguous ranges that span the wider
prefix's range, I can use the wider range.

This is tricky... adding two IP ranges together only yields a single
range if the two ranges are not disjoint.  Otherwise I just have two
ranges.  So perhaps I have two classes: IPv4AddressRange and
IPV4AddressRangeSet.

Of course, I could just look for adjacent networks and see if they can
be added together to bump them up to the next prefix width.  This would
be a bottom-up approach (longest prefix to shortest prefix).

At a minimum, I should delete smaller prefixes when I add a wider entry
that covers those prefixes.  Easy to do.

Aside
-----
I'd still like to have a new type of IPv4 routing table that has a real
iterator.  There's a question of how I get the right ordering.  Explain
by example...

10.0.0.0/8
10.1.0.0/16
10.1.1.0/24

By nature, these are already sorted by their address, without mask.  These
are also ordered, if we add the mask:

10.0.0.0/8
10.0.0.0/16
10.0.0.0/24

Question... if I have a map of 5-byte keys, and also keep track of the
masks that exist in the map, how fast or slow is it?

map<uint32_t,uint32_t>  MaskCounts;  // map of netmasks to count of them in the main map

Keep in mind that my Ipv4Prefix class already has a workable less-than
operator.


