Commit Graph

3761 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
bbaa8af8f3 libnetwork/drivers/bridge: un-export errors
These errors implement errdefs interfaces, and are only used internally
for convenience. Un-export their implemetations because the types themselves
are not used as sentinel errors.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:12:42 +01:00
Sebastiaan van Stijn
3f9698e1f6 libnetwork/drivers/bridge: TestLinkDelete: use gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:12:42 +01:00
Sebastiaan van Stijn
74fd2ec0cf libnetwork/drivers/bridge: TestLinkCreateNoEnableIPv6: use gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:12:37 +01:00
Sebastiaan van Stijn
6e9ba725f8 libnetwork/drivers/bridge: TestLinkCreateTwo: use gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:15 +01:00
Sebastiaan van Stijn
bf3323fd40 libnetwork/drivers/bridge: TestLinkCreate: use gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:15 +01:00
Sebastiaan van Stijn
7012e3ce14 libnetwork/drivers/bridge: remove NonDefaultBridgeExistError
It was only used in a single place, and a generic errdefs.ErrInvalid; the
type itself was not used as sentinel error other than for a unit test.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:15 +01:00
Sebastiaan van Stijn
47f6d4e1bc libnetwork/drivers/bridge: internalize ErrInvalidGateway
It's a generic errdefs.ErrInvalidParameter, and the type itself is not
used as sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
3a9f4e0146 libnetwork/drivers/bridge: remove ErrInvalidMtu
It's a generic errdefs.ErrInvalidParameter, and the type itself is not
used as sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
2f42aa0e26 libnetwork/drivers/bridge: remove IPv4AddrNoMatchError
It's a generic error, doesn't implement an errdefs type, and not used as
sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
0c1b660048 libnetwork/drivers/bridge: remove IPv4AddrAddError
It's a generic error, doesn't implement an errdefs type, and not used as
sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
dc52ecb1d0 libnetwork/drivers/bridge: remove ErrNoIPAddr
It's a generic error, doesn't implement an errdefs type, and not used as
sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
77261b5e42 libnetwork/drivers/bridge: remove "InternalError()" method from errors
The `InternalError()` method was added in [moby/libnetwork@50964c9] to
classify the error. However, the same commit defined interfaces for error
types (in the types package). The [InternalError] interface defined did
not match, as it defines a `Internal()` method instead of `InternalError()`.

In short; these errors were never matching any interface, and the actual
error implementations themselves were also never used as a sentinel error,
so we can safely remove these methods.

[moby/libnetwork@50964c9]: 50964c9948
[InternalError]: 50964c9948/types/types.go (L233-L237)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:13 +01:00
Sebastiaan van Stijn
2766298f49 libnetwork/drivers/bridge: remove unused errors
This removes the following errors, which were not used anywhere;

- ErrConfigExists
- ErrInvalidNetworkConfig
- ErrInvalidEndpointConfig
- ErrNetworkExists
- ErrIfaceName
- ErrUnsupportedAddressType
- NonDefaultBridgeNeedsIPError
- IPv6AddrNoMatchError

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:13 +01:00
Sebastiaan van Stijn
59c2d2a4b3 libnetwork/drivers/bridge: remove ErrInvalidDriverConfig
It's a generic error, doesn't implement an errdefs type, is poorly formatted,
and not used as sentinel error anywhere. Let's remove it, and update the error
produced to be slightly more informative (include the invalid type). Worth
noting that there's no need to include the name of the driver in the error,
because the only uses of the error (in `registerNetworkDrivers`) already
decorates it; 5fd7ed2937/libnetwork/drivers_linux.go (L34-L36)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:11 +01:00
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