25 Commits

Author SHA1 Message Date
Olli Janatuinen
48c2d8c458 libnetwork: support custom DNS servers in Windows overlay driver
Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
2025-10-21 07:33:02 +00:00
Sebastiaan van Stijn
8905c3052b daemon/libnetwork: use t.Context() in tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-25 22:53:41 +02:00
Rob Murray
07453abab3 Merge pull request #50929 from robmry/mac_ip_vlan_gateway_config
macvlan, ipvlan-l2: only configure a default route when a gateway address is supplied
2025-09-16 18:09:30 +01:00
Rob Murray
9129094b98 Windows containers: report HNS network name in inspect
After creating a new network, inspect shows that there's no value
for option "com.docker.network.windowsshim.networkname". After
restarting the daemon, it shows up with the docker network name
(not the HNS network name, which defaults to the docker network's
id).

Creating the network with "-o com.docker.network.windowsshim.networkname"
sets the HNS network name, and it shows up in inspect. Until the
daemon is restarted, then it shows the docker network name.

So - set the option value to the HNS network name on creation (the id
if no name is given), and on restore after restart use the name
reported by HNS.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-09-12 16:03:36 +01:00
Rob Murray
468e3521b0 macvlan: do not allocate a gateway address from IPAM
When macvlan is given no '--gateway' option, an address is
allocated from IPAM and a default route is set up via that
gateway. But, the gateway address is not assigned to anything
in the Docker macvlan network - it must be external, and
IPAM shouldn't try to guess it.

When IPv6 auto-configuration is enabled in the network the
macvlan is connected to, the macvlan driver races against it
to set up the gateway. When autoconfig wins, container creation
fails because the default route already exists.

So ...

- disable IPAM gateway address allocation for macvlan
- update the Join code to allow for no configured gateway
- always disable 'docker_gwbridge' connection for macvlan
  networks, so it's not hooked up when there is no gateway
  address.

Libnet assumes an endpoint with no statically configured default
gateway or route does not provide external connectivity. So, it
disables external DNS access, and will not select the endpoint
as gateway for containers. So, where an IPAM allocated gateway
address would have been assigned before, tell libnet to assume
there will be an auto-configured gateway.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-09-12 14:29:15 +01:00
Albin Kerouanton
f835ff6987 Merge pull request #50289 from akerouanton/cleanup-windows-portmapper
libnet/portmapper: clean up windows port mapper
2025-09-08 22:52:45 +02:00
Albin Kerouanton
2f1015482f libnet/d/windows: ReleasePorts: use errors.Join
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-09-08 11:40:09 +02:00
Albin Kerouanton
fc86411353 libnet/d/windows: inline releasePort
releasePort is a one-liner and is called only in one place. Inline it.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-09-08 11:37:08 +02:00
Albin Kerouanton
9efc1cc264 libnet/portmapper: rename, move PortMapper to portallocator
The only viable way to allocate a port is to bind and listen to it. So,
the windows PortMapper was really a PortAllocator in disguise.

Rename it to OSAllocator and move it to the portallocator package.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-09-08 11:32:21 +02:00
Sebastiaan van Stijn
4b230a4909 internal/testutils: merge with internal/testutil
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-08 10:08:35 +02:00
Albin Kerouanton
af677b61a5 libnet/portmapper: clean up windows port mapper
The windows port mapper is needlessly complex while its job is pretty
straightforward: reserve a port through the port allocator, and start a
dummy proxy to allocate it from the OS.

The biggest source of complexity is the use of the `net.Addr` interface
to pass the host IP, port and proto. `MapRange` now has a proto arg, and
returns the allocated port.

`MapRange` is also instantiating a `mapping` struct whose fields are
all unused, except for its `stopUserlandProxy`. Instead, store
`stopProxy` callbacks directly into the `PortMapper`.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-09-08 10:05:29 +02:00
Albin Kerouanton
4d2a293ff3 libnet/drvapi: make NetworkAllocate optional
This method is only used by the cnmallocator to allocate Swarm-scoped
network resources. Its only concrete implementation is in the ovmanager.
Other network drivers are implementing it too to adhere to the
driverapi.Driver interface, but they all return a 'not implemented'
error.

Extract this method into a separate interface, and add a dedicated
RegisterNetworkAllocator to the driver registry. Update the cnmallocator
to load 'network allocators' instead of 'drivers'.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-09-02 21:55:03 +02:00
Cory Snider
a27a2901b1 Merge pull request #50660 from corhere/libn/overlay-eventnotify-nilderef
libn/d/overlay: don't deref nil PeerRecord on error
2025-08-12 11:51:44 -04:00
Sebastiaan van Stijn
561e14ea3f daemon/libnetwork/types: remove TransportPort.GetCopy()
The `GetCopy()` function doesn't de-reference anything, as it's
all a straight copy. We can remove it as it's only making things
more complicated than needed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-12 11:39:56 +02:00
Sebastiaan van Stijn
7d5312ab56 daemon/libnetwork/types: rename PortBinding.GetCopy to Copy and non-pointer
- Rename `PortBinding.GetCopy()` to `PortBinding.Copy()`, which is more
  idiomatic, and aligns with other similar methods.
- Change it to a non-pointer receiver; `Copy` does not mutate state, and
  the type should still be reasonably small.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-12 11:38:09 +02:00
Sebastiaan van Stijn
892ebd2f17 daemon/libnet/drivers/windows: small cleanup in error-handling
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-10 16:43:36 +02:00
Matthieu MOREL
96f8c6395e chore: enable use-any rule from revive
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-08-08 17:07:07 +02:00
Cory Snider
12c6345d3a libn/d/overlay: don't deref nil PeerRecord on error
If unmarshaling the peer record fails, there is no need to check if it's
a record for a local peer. Attempting to do so anyway will result in a
nil-dereference panic. Don't do that.

The Windows overlay driver has a typo: prevPeer is being checked twice
for whether it was a local-peer record. Check prevPeer once and newPeer
once each, as intended.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-08-07 13:25:37 -04:00
Sebastiaan van Stijn
1205a15db1 libnetwork/types: define RouteType type
Define a `RouteType` type, type the related consts, and update the
`JoinInfo.AddStaticRoute` signature in the interface.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-01 22:33:10 +02:00
Derek McGowan
f74e5d48b3 Create github.com/moby/moby/v2 module
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-31 10:13:29 -07:00
Cory Snider
e1a586a9a7 libnetwork/d/overlay: handle coalesced peer updates
The eventually-consistent nature of NetworkDB means we cannot depend on
events being received in the same order that they were sent. Nor can we
depend on receiving events for all intermediate states. It is possible
for a series of entry UPDATEs, or a DELETE followed by a CREATE with the
same key, to get coalesced into a single UPDATE event on the receiving
node. Watchers of NetworkDB tables therefore need to be prepared to
gracefully handle arbitrary UPDATEs of a key, including those where the
new value may have nothing in common with the previous value.

The overlay driver naively handled events for overlay_peer_table
assuming that an endpoint leave followed by a rejoin of the same
endpoint would always be expressed as a DELETE event followed by a
CREATE. It would handle a coalesced UPDATE as a CREATE, inserting a new
entry into peerDB without removing the old one. This would
have various side effects, such as having the "transient state" of
multiple entries in peerDB with the same peer IP never settle.

Update driverapi to pass both the previous and new value of a table
entry into the driver. Modify the overlay driver to handle an UPDATE by
removing the previous peer entry from peerDB then adding the new one.
Modify the Windows overlay driver to match.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-07-22 11:51:18 -04:00
Cory Snider
8340e109de libn/d/win/overlay: dedupe NetworkDB definitions
Windows and Linux overlay driver instances are interoperable, working
from the same NetworkDB table for peer discovery. As both drivers
produce and consume serialized data through the table, they both need to
have a shared understanding of the shape and semantics of that data.
The Windows overlay driver contains a duplicate copy of the protobuf
definitions used for marshaling and unmarshaling the NetworkDB peer
entries for dubious reasons. It gives us the flexibility to have the
definitions diverge, which is only really useful for shooting ourselves
in the foot.

Make daemon/libnetwork/drivers/overlay the source of truth for the peer
record definitions and the name of the NetworkDB table for distributing
peer records.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-07-22 11:51:18 -04:00
Cory Snider
844023f794 libnetwork/driverapi: make EventNotify optional
Overlay is the only driver which makes use of the EventNotify facility,
yet all other driver implementations are forced to provide a stub
implementation. Move the EventNotify and DecodeTableEntry methods into a
new optional TableWatcher interface and remove the stubs from all the
other drivers.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-07-22 11:51:14 -04:00
Derek McGowan
a28f031298 Fix libnetwork proto generation
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-14 10:35:07 -07:00
Derek McGowan
7a720df61f Move libnetwork to daemon/libnetwork
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-14 09:25:23 -07:00