Commit graph

102 commits

Author SHA1 Message Date
Sebastiaan van Stijn
7a5f3f8053
libnetwork: fix empty-lines (revive)
libnetwork/etchosts/etchosts_test.go:167:54: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/osl/route_linux.go:185:74: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/osl/sandbox_linux_test.go:323:36: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/bitseq/sequence.go:412:48: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/datastore/datastore_test.go:67:46: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/datastore/mock_store.go:34:60: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/iptables/firewalld.go:202:44: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/iptables/firewalld_test.go:76:36: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/iptables/iptables.go:256:67: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/iptables/iptables.go:303:128: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/networkdb/cluster.go:183:72: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/ipams/null/null_test.go:44:38: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/drivers/macvlan/macvlan_store.go:45:52: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/ipam/allocator_test.go:1058:39: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/drivers/bridge/port_mapping.go:88:111: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/drivers/bridge/link.go:26:90: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/drivers/bridge/setup_ipv6_test.go:17:34: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/drivers/bridge/setup_ip_tables.go:392:4: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/drivers/bridge/bridge.go:804:50: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/drivers/overlay/ov_serf.go:183:29: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/drivers/overlay/ov_utils.go:81:64: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/drivers/overlay/peerdb.go:172:67: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/drivers/overlay/peerdb.go:209:67: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/drivers/overlay/peerdb.go:344:89: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/drivers/overlay/peerdb.go:436:63: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/drivers/overlay/overlay.go:183:36: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/drivers/overlay/encryption.go:69:28: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/drivers/overlay/ov_network.go:563:81: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/default_gateway.go:32:43: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/errors_test.go:9:40: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/service_common.go:184:64: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/endpoint.go:161:55: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/store.go:320:33: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/store_linux_test.go:11:38: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/sandbox.go:571:36: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/service_common.go:317:246: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/endpoint.go:550:17: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/sandbox_dns_unix.go:213:106: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/controller.go:676:85: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/agent.go:876:60: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/resolver.go:324:69: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/network.go:1153:92: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/network.go:1955:67: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/network.go:2235:9: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/libnetwork_internal_test.go:336:26: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/resolver_test.go:76:35: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/libnetwork_test.go:303:38: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/libnetwork_test.go:985:46: empty-lines: extra empty line at the end of a block (revive)
    libnetwork/ipam/allocator_test.go:1263:37: empty-lines: extra empty line at the start of a block (revive)
    libnetwork/errors_test.go:9:40: empty-lines: extra empty line at the end of a block (revive)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit cd381aea56)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-01-18 21:24:32 +01:00
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
Eng Zer Jun
c55a4ac779
refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated in Go 1.16. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-08-27 14:56:57 +08:00
Sebastiaan van Stijn
427ad30c05
libnetwork: remove unused "testutils" imports
Perhaps the testutils package in the past had an `init()` function to set up
specific things, but it no longer has. so these imports were doing nothing.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-18 14:20:37 +02:00
Brian Goff
4b981436fe Fixup libnetwork lint errors
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2021-06-01 23:48:32 +00:00
Brian Goff
72c4a7b496 Fix issues running libnetwork tests.
libnetwork does different stuff depending on if you are running the
tests in a container or not... without telling it we are in a container
a bunch of the tests actually fail.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2021-06-01 22:14:41 +00:00
Brian Goff
a0a473125b Fix libnetwork imports
After moving libnetwork to this repo, we need to update all the import
paths for libnetwork to point to docker/docker/libnetwork instead of
docker/libnetwork.
This change implements that.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2021-06-01 21:51:23 +00:00
Sebastiaan van Stijn
3e1e9e878c vendor: gotest.tools v3.0.2
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-09-12 03:22:18 +02:00
Yongxin Li
619e3d6706 typo fix about mismatch
Signed-off-by: Yongxin Li <yxli@alauda.io>
2018-09-27 20:43:13 +08:00
rongzhang
36375881f3 Fix some typos
Signed-off-by: rongzhang <rongzhang@alauda.io>
2018-09-08 09:33:24 +08:00
selansen
814f6c1f4b Add getter function for Default Address Pools
ipamutils has two default address pool. Instead of allowing them to
be accessed directly, adding get functions so that other packages
can use get APIs.

Signed-off-by: selansen <elango.siva@docker.com>
2018-08-16 15:48:42 -04:00
selansen
52e85b4b9a Global Default Address Pool support
This change brings global default address pool feature into
libnetwork. Idea is to reuse same code flow and functions that were
implemented for local scope default address pool.
Function InitNetworks carries most of the changes. local scope default
address pool init should always happen only once. But Global scope
default address pool can be initialized multiple times.

Signed-off-by: selansen <elango.siva@docker.com>
2018-08-16 11:28:24 -04:00
Josh Soref
a06f1b2c4e Spelling fixes
* addresses
* assigned
* at least
* attachments
* auxiliary
* available
* cleanup
* communicate
* communications
* configuration
* connection
* connectivity
* destination
* encountered
* endpoint
* example
* existing
* expansion
* expected
* external
* forwarded
* gateway
* implementations
* implemented
* initialize
* internally
* loses
* message
* network
* occurred
* operational
* origin
* overlapping
* reaper
* redirector
* release
* representation
* resolver
* retrieve
* returns
* sanbdox
* sequence
* succesful
* synchronizing
* update
* validates

Signed-off-by: Josh Soref <jsoref@gmail.com>
2018-07-12 12:54:44 -07:00
Vincent Demeester
06d471d186 Migrate to gotest.tools :)
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-07-06 11:01:37 -07:00
Euan Harris
1383aadf59 ipam: Test rejection of overlapping pool requests
TestOverlappingRequests checks that pool requests which are supersets or
subsets of existing allocations, and those which overlap with existing
allocations at the beginning or the end.

Multiple allocation is now tested by TestOverlappingRequests, so
TestDoublePoolRelease only needs to test double releasing.

Signed-off-by: Euan Harris <euan.harris@docker.com>
2018-07-04 09:50:53 +01:00
Euan Harris
6fd25eea33 ipam, types: Expand documentation
Signed-off-by: Euan Harris <euan.harris@docker.com>
2018-07-04 09:50:31 +01:00
Flavio Crisciani
f857b5b8f8 Merge pull request #2166 from idealhack/tests-benchmark
test: update tests to use sub-benchmarks
2018-07-03 14:06:58 -07:00
Abhinandan Prativadi
f5fa40f9aa Fixing the unit test for overlapping subnet
Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
2018-06-18 12:31:48 -07:00
Flavio Crisciani
828a6d788e Merge pull request #2177 from ctelfer/subnet-cursor
Avoid reusing subnets when allocating from pools
2018-06-18 11:23:11 -07:00
Flavio Crisciani
891fb82213 Merge pull request #2148 from abhi/ipam-check
Adding a check for subnet pool overlap
2018-06-18 11:19:41 -07:00
Chris Telfer
e31e906e4e Add pool reuse test to unit tests
Add a test to confirm that the pool allocator will iterate through all
the pools even if some earlier ones were freed before coming back to
previously allocated pools.

Signed-off-by: Chris Telfer <ctelfer@docker.com>
2018-06-08 19:26:10 -04:00
Chris Telfer
cc8b2cac28 Allocate subnets in order rather than restarting
This commit prevents subnets from being reused at least initially,
instead favoring to cycle through them as we do with addresses within a
subnet.

Signed-off-by: Chris Telfer <ctelfer@docker.com>
2018-06-08 19:26:04 -04:00
Yang Li
b0b5e14b77 test: update tests to use sub-benchmarks
Go 1.7 added the subtest feature which can make table-driven tests much easier to run and debug. Some tests are not using this feature.

Signed-off-by: Yang Li <idealhack@gmail.com>
2018-05-31 11:34:15 +08:00
Euan Harris
ebf0054912 ipam/allocator: Fix typos in error message
Signed-off-by: Euan Harris <euan.harris@docker.com>
2018-05-23 11:03:55 +01:00
Euan Harris
35a81f8173 ipam/allocator_test: Test pool double-release behavior
Releasing a pool which has already been released should fail; this
change increases coverage by a fraction by exercising this path.

Signed-off-by: Euan Harris <euan.harris@docker.com>
2018-05-18 17:32:36 +01:00
Abhinandan Prativadi
2f2811dd14 Adding logs for ipam state
Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
2018-05-14 15:44:49 -07:00
Abhinandan Prativadi
dfa303e568 fixing test cases
Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
2018-05-10 14:47:52 -07:00
Abhinandan Prativadi
9fe5cc10b2 Add check for overlapping subnets
Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
2018-05-10 14:47:07 -07:00
Flavio Crisciani
606e28015a Add test for parallel request pool
Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
2018-04-25 16:09:27 -07:00
Sebastiaan van Stijn
a360943a48 Fix golang.org/x/sync canonical import path
The golang.org/x/sync package was vendored using the
github.com/golang/sync URL, but this is not the canonical
URL.

Because of this, vendoring failed in Moby, as it detects
these to be a duplicate import:

    vndr github.com/golang/sync
    2018/03/14 11:54:37 Collecting initial packages
    2018/03/14 11:55:00 Download dependencies
    2018/03/14 11:55:00 Failed to parse config: invalid config format: // FIXME this should be golang.org/x/sync, which is already vendored above

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-03-14 13:11:08 +01:00
Flavio Crisciani
4c8d751400 IPAM tests
Added tests for swarm mode and also some new parallel tests

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
2018-03-09 11:07:36 -08:00
Abhinandan Prativadi
a0085a47fd IPAM and Bitseq test cases
This commit contains test cases to verify the changes and to
solidify the library.

Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
2018-03-09 09:24:10 -08:00
Abhinandan Prativadi
fe629b6eba Fixing concurrent map access
This commit fixes panic due to concurrent map access

Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
2018-03-08 11:19:45 -08:00
selansen
4484ea17c3 Allow user to specify default address pools for docker networks
This is new feature that allows  user to specify which subnetwork
 Docker contrainer should choose from when it creates bridge network.

 This libnetwork commit is to address moby PR 36054
Signed-off-by: selansen <elango.siva@docker.com>
2018-02-22 12:14:59 -05:00
Abhinandan Prativadi
3d44975995 Adding a unit case to verify rollover
Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
2017-10-03 12:15:34 -07:00
Abhinandan Prativadi
813a24a51c Minor unit test change
Since bit allocation is no longer first available from
the start some verfications are removed/modified to
the change allocation model

Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
2017-09-29 11:33:26 -07:00
Flavio Crisciani
38382fb29b Merge pull request #1752 from aaronlehmann/sprintfs
all: Avoid trivial uses of Sprintf
2017-08-23 15:49:46 -07:00
Derek McGowan
710e0664c4 Update logrus to v1.0.1
Fix case sensitivity issue
Update docker and runc vendors

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-08-07 11:20:47 -07:00
Flavio Crisciani
65860255c6 Fixed code issues
Fixed issues highlighted by the new checks

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
2017-06-12 11:31:35 -07:00
Aaron Lehmann
cc0b7e6aad all: Avoid trivial uses of Sprintf
Use the string concatenation operator instead of using Sprintf for
simple string concatenation. This is usually easier to read, and allows
the compiler to detect problems with the type or number of operands,
which would be runtime errors with Sprintf.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-05-09 16:07:09 -07:00
Alessandro Boch
595246bdfb Merge pull request #1568 from likel/refactor
Remove unnecessary string formats
2016-12-29 12:18:06 -08:00
Madhu Venugopal
1b28c5e01d Internal interface to differentiate built-in drivers from remote
Signed-off-by: Madhu Venugopal <madhu@docker.com>
2016-12-19 05:17:42 -08:00
Ke Li
23ac56fdd0 Remove unnecessary string formats
Signed-off-by: Ke Li <kel@splunk.com>
2016-11-22 09:29:53 +08:00
Alessandro Boch
83dd2c193a Respect auto allocation for --ipv6
Signed-off-by: Alessandro Boch <aboch@docker.com>
2016-11-08 19:05:51 -08:00
Daehyeok Mun
7f473c779a Refactoring logrus import and formatting
This fix tries to fix logrus formatting by removing `f` from
`logrus.[Error|Warn|Debug|Fatal|Panic|Info]f` when formatting string
is not present.
Also fix import name to use original project name 'logrus' instead of
'log'

Signed-off-by: Daehyeok Mun <daehyeok@gmail.com>
2016-11-08 12:42:41 -07:00
Alessandro Boch
5889b279fb Separate pool parsing from pool auto-allocation
- In default ipam driver. Also improve error message
  in case no good pool is found

Signed-off-by: Alessandro Boch <aboch@docker.com>
2016-05-25 15:02:44 -07:00
Alessandro Boch
a9c9765b33 IPAM allocator to not accept a datastore update if already present
- Restoring the above behavior which got recently broken

Signed-off-by: Alessandro Boch <aboch@docker.com>
2016-05-12 16:43:51 -07:00
Alessandro Boch
04f5343139 Make o/p of ipam DumpDatabase() consistent
Signed-off-by: Alessandro Boch <aboch@docker.com>
2016-04-15 17:34:48 -07:00
Jana Radhakrishnan
716af1c1ee Need boltdb Register only in tests
Fixing an earlier commit which needlessly registered
boltdb in allocator.go while it is needed only for tests.

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
2016-04-15 16:34:09 -07:00
Alessandro Boch
216def1e1b Merge pull request #1120 from mrjana/store
Remove kvstore backend deps from datastore package
2016-04-15 15:50:46 -07:00