moby--moby/libnetwork/ipam
Mark Feit 3a938df4b5
Make the network allocator handle IPv4 blocks too small for network/broadcast addresses.
This was originally in docker/libnetwork#2624, which has been closed since the
code was moved here.

When creating a new network, IPAM's address allocator attempts to reserve the
network and broadcast addresses on IPv4 networks of all sizes. For RFC 3021
point-to-point networks (IPv4 /31s), this consumes both available addresses and
renders any attempt to allocate an address from the block unsuccessful.

This change prevents those reservations from taking place on IPv4 networks having
two or fewer addresses (i.e., /31s and /32s) while retaining the existing behavior
for larger IPv4 blocks and all IPv6 blocks.

In case you're wondering why anyone would allocate /31s:  I work for a network
service provider.  We use a lot of point-to-point networks.  This cuts our
address space utilization for those by 50%, which makes ARIN happy.

This patch modifies the network allocator to recognize when an network is too
small for network and broadcast addresses and skip those reservations.

There are additional unit tests to make sure the functions involved behave as expected.

Try these out:

 * `docker network create --driver bridge --subnet 10.200.1.0/31 --ip-range 10.200.1.0/31 test-31`
 * `docker network create --driver bridge --subnet 10.200.1.0/32 --ip-range 10.200.1.0/32 test-32`

My installation has been running this patch in production with /31s since March.

Signed-off-by: Mark Feit <mfeit@internet2.edu>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-10-27 13:03:19 +02:00
..
allocator.go Make the network allocator handle IPv4 blocks too small for network/broadcast addresses. 2021-10-27 13:03:19 +02:00
allocator_test.go Make the network allocator handle IPv4 blocks too small for network/broadcast addresses. 2021-10-27 13:03:19 +02:00
parallel_test.go Fixup libnetwork lint errors 2021-06-01 23:48:32 +00:00
store.go Fixup libnetwork lint errors 2021-06-01 23:48:32 +00:00
structures.go Fixup libnetwork lint errors 2021-06-01 23:48:32 +00:00
utils.go Fix libnetwork imports 2021-06-01 21:51:23 +00:00