Commit Graph

3747 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
47dc8d5dd8 Merge pull request #49325 from akerouanton/fix-45610-v2
libnet/d/bridge: drop connections to lo mappings, and direct remote connections
2025-01-28 16:38:29 +01:00
Sebastiaan van Stijn
beb5fa6acc Merge pull request #49350 from thaJeztah/windows_clean_errors
libnetwork/drivers/windows: remove ErrUnsupportedAddressType
2025-01-28 16:30:49 +01:00
Sebastiaan van Stijn
6bb9f581a5 libnetwork/drivers/windows: remove ErrUnsupportedAddressType
It was only used in a single place, and did not implement an errdef;
the type itself was not used as sentinel error.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 15:14:27 +01:00
Sebastiaan van Stijn
510e6f4f8a libnetwork/options: rewrite tests with gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 12:27:44 +01:00
Sebastiaan van Stijn
5fd7ed2937 Merge pull request #49342 from robmry/debug_flaky_unsol_na
Debug flaky unsolicited Neighbour Advertisements
2025-01-28 12:14:38 +01:00
Albin Kerouanton
ac23dddac0 Merge pull request #49302 from robmry/create_veth_in_container
Create bridge veth in container netns
2025-01-28 11:47:33 +01:00
Albin Kerouanton
d216084185 libnet/d/bridge: drop remote connections to port mapped on lo
Traditionally when Linux receives remote packets with daddr set to a
loopback address, it reject them as 'martians'. However, when a NAT rule
is applied through iptables this doesn't happen. Our current DNAT rule
used to map host ports to containers is applied unconditionally, even
for such 'martian' packets.

This means a neighbor host (ie. a host connected to the same L2
segment) can send packets to a port mapped on a loopback address. The
purpose of publishing on a loopback address is to make ports
inaccessible to remote hosts -- lack of proper filtering defeats that.

This commit adds an iptables rule to the raw-PREROUTING chain to drop
packets with a loopback dest address and coming from any interface other
than lo.

To accomodate WSL2 mirrored mode, another rule is inserted beforehand to
specifically accept packets coming from the loopback0 interface.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-01-27 18:41:20 +01:00
Albin Kerouanton
27adcd596b libnet/d/bridge: port mappings: drop direct-access when gw_mode=nat
When a NAT-based port mapping is created, the daemon adds a DNAT rule in
nat-DOCKER to replace the dest addr with the container IP. However, the
daemon never sets up rules to filter packets destined directly to the
container port. This allows a rogue neighbor (ie. a host that shares a
L2 segment with the host) to send packets directly to the container on
its container-side exposed port.

For instance, if container port 5000 is mapped to host port 6000, a
neighbor could send packets directly to the container on its port 5000.

Since nat-DOCKER mangles the dest addr, and the nat table forbids DROP
rules, this change adds a new rule in the raw-PREROUTING chain to filter
ingress connections targeting the container's IP address.

This filtering is only done when gw_mode=nat. For the unprotected
variant, no filtering is done.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-01-27 18:41:20 +01:00
Albin Kerouanton
a7e6d0a8a3 libnet/d/bridge: releasePortBindings: append directly into 'errs'
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-01-27 18:41:15 +01:00
Rob Murray
aa3a23d4f9 Temporary debug for unsolicited NA
Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-27 14:56:31 +00:00
Sebastiaan van Stijn
49b1ed6d27 libnetwork: remove ErrInvalidName
It was only returned in a few places, and not used any different than
a "invalid parameter" error, so let's use a standard errdefs.ErrInvalidParameter

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-27 14:19:19 +01:00
Sebastiaan van Stijn
a98ecc5f79 libnetwork: remove ErrInvalidID
It was only returned in a few places, and not used any different than
a "invalid parameter" error, so let's use a standard errdefs.ErrInvalidParameter

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-27 14:19:19 +01:00
Sebastiaan van Stijn
548b0b6290 libnetwork: remove ErrNoSuchEndpoint
It was only returned in 1 place, and not used any different than
a "notfound" error, so let's use a standard errdefs.ErrNotFound

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-27 14:19:08 +01:00
Rob Murray
7cc81407aa Add trace/logging in waitForIfUpped
Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-27 11:52:21 +00:00
Sebastiaan van Stijn
cef6fd2fa2 libnetwork: remove Network.EndpointByID as it must not be used
commit 80c44b4b2e removed uses of this
method and added a comment that it should never be used;

> EndpointByID should *never* be called as it's going to create a 2nd instance
> of an Endpoint. The first one lives in the Sandbox the endpoint is attached to.
> Instead, the endpoint should be retrieved by calling [Sandbox.Endpoints()].

Given that the only use of this method is in tests, we can remove if altogether.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-27 10:49:40 +01:00
Sebastiaan van Stijn
5c1fe287fc libnetwork: remove UnknownNetworkError
It was only returned in 2 places, and not used any different than
a "notfound" error, so let's use a standard errdefs.NotFound

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:35:22 +01:00
Sebastiaan van Stijn
8f4c98e1eb libnetwork: TestControllerGetSandbox: use errdefs for error asserts
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:35:22 +01:00
Sebastiaan van Stijn
d34ca256b8 libnetwork: TestNetworkConfig: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:35:22 +01:00
Sebastiaan van Stijn
c6f0fe5fc0 libnetwork: parallelTester.Do: use errdefs for error assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:35:22 +01:00
Sebastiaan van Stijn
11a6cb5fac libnetwork: TestEndpointJoin: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:35:21 +01:00
Sebastiaan van Stijn
ea7d17376e libnetwork: TestInvalidRemoteDriver: use gotest.tools for error assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:35:21 +01:00
Sebastiaan van Stijn
01c87cc809 libnetwork: TestContainerInvalidLeave: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:35:21 +01:00
Sebastiaan van Stijn
9472c860de libnetwork: TestEndpointMultipleJoins: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:35:21 +01:00
Sebastiaan van Stijn
ab9d250876 libnetwork: TestEndpointDeleteWithActiveContainer: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:35:21 +01:00
Sebastiaan van Stijn
56debcfc1c libnetwork: TestNetworkQuery: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:35:20 +01:00
Sebastiaan van Stijn
874fb4d2f4 libnetwork: TestControllerQuery: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:35:13 +01:00
Sebastiaan van Stijn
53bf2e8960 libnetwork: TestUnknownEndpoint: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:17:43 +01:00
Sebastiaan van Stijn
895ee1214a libnetwork: TestDuplicateEndpoint: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:17:43 +01:00
Sebastiaan van Stijn
678a8a27f5 libnetwork: TestUnknownNetwork: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:17:42 +01:00
Sebastiaan van Stijn
9304d98757 libnetwork: TestDeleteNetworkWithActiveEndpoints: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:17:42 +01:00
Sebastiaan van Stijn
01b0fe1172 libnetwork: TestNetworkName: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:17:42 +01:00
Sebastiaan van Stijn
24df497674 libnetwork: TestNilRemoteDriver: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:17:42 +01:00
Sebastiaan van Stijn
532d36c251 libnetwork: TestUnknownDriver: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:17:42 +01:00
Sebastiaan van Stijn
400ad04c74 libnetwork: TestNull: use gotest.tools for errdefs assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-26 21:17:39 +01:00
Rob Murray
65120d586b Create bridge veth in container netns
Since commit 933fcc9 (Re-remove the SetKey OCI prestart hook),
the network namespace will be set up before endpoints are
created in most cases, apart from build containers.

So, when possible, create the veth with one end in that netns
to save moving it in later. On my host, that saves about 20ms
for each bridge network a container is connected to.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-24 18:43:51 +00:00
Rob Murray
b3b9e990ee Get netns before calling moveLink
Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-23 14:53:52 +00:00
Rob Murray
357fb9d58d Add trace/logging in waitForIfUpped
Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-23 14:53:52 +00:00
Sebastiaan van Stijn
f2804e04b2 Merge pull request #49329 from thaJeztah/libnetwork_use_errdefs_step2
libnetwork: rewrite some tests to use gotest.tools
2025-01-23 11:30:03 +01:00
Sebastiaan van Stijn
c8a456a5a2 Merge pull request #49327 from thaJeztah/libnetwork_type_conversions
libnetwork: remove some redundant type-conversions
2025-01-23 11:28:18 +01:00
Sebastiaan van Stijn
203d6530d0 libnetwork: use gotest.tools assertions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-22 22:20:43 +01:00
Sebastiaan van Stijn
a39bee9b71 libnetwork: suppress some unhandled errors in tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-22 22:06:40 +01:00
Sebastiaan van Stijn
376ff6add6 libnetwork: use assert.Check in defers
Prefering Check here over NilError so that all defers
wil be executed, instead of potentially failing on the
first one.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-22 22:06:40 +01:00
Sebastiaan van Stijn
71c9a45672 libnetwork: use assert.NilError (step 2)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-22 22:06:38 +01:00
Sebastiaan van Stijn
231012996f libnetwork: use assert.NilError (step 1)
First step; this is just a find and replace

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-22 22:05:58 +01:00
Rob Murray
94444587d4 Merge pull request #48808 from robmry/v6only/gratuitous_arp
IPv6 only: use random MAC addresses
2025-01-22 18:52:21 +00:00
Rob Murray
bc130f367d bridge/macvlan endpoints always use a random MAC address
Now a gratuitous/unsolicted ARP is sent, there's no need to
use an IPv4-based MAC address to preserve arp-cache mappings
between an endpoint's IP addresses and its MAC addresses.

Because a random MAC address is used for the default bridge,
it no longer makes sense to derive container IPv6 addresses
from the MAC address. This "postIPv6" behaviour was needed
before IPv6 addresses could be configured, but not now. So,
IPv6 addresses will now be IPAM-allocated on the default
bridge network, just as they are for user-defined bridges.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-22 16:59:27 +00:00
Cory Snider
a900e0b5bb libn/netutils: put more entropy into random MACs
With randomly-generated MAC addresses going into wider use in the most
commonly used container network drivers, it is imperative to avoid
address collisions. Increase the number of random bits in randomly-
generated MAC addresses from 32 bits to 46 bits.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-01-22 16:59:27 +00:00
Rob Murray
422e056b0f Treat failure to send an initial ARP/NA as an error
If this causes problems, setting nmsgs=0 is a workaround.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-22 16:59:27 +00:00
Rob Murray
522016a842 Configurable count and interval for gratuitous ARP/NA messages
The default is to send 3 messages at 1s intervals.

That can be overridden in "docker network create" using:
  -o com.docker.network.advertise_addr_nmsgs=3
  -o com.docker.network.advertise_addr_ms=1000

Or, in daemon.json for each driver:
  "default-network-opts": {
    "bridge": {
      "com.docker.network.advertise_addr_nmsgs": "3",
      "com.docker.network.advertise_addr_ms": "1000"
    }
  }

The allowed range is 0-3 for the number of messages, and
100-2000ms for the interval. Setting nmsgs to 0 disables the
gratuitous ARP/NA messages.

The default bridge will always use the built-in defaults,
it cannot be configured.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-22 16:59:27 +00:00
Rob Murray
eaa84bc8f4 Send unsolicited ARP/NA requests when bringing up interfaces
Co-authored-by: Cory Snider <csnider@mirantis.com>
Co-authored-by: Rob Murray <rob.murray@docker.com>
Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-22 16:59:27 +00:00