261 Commits

Author SHA1 Message Date
Paweł Gronowski
fadd8dc47c daemon/libnetwork: Fix panic in findHNSEp when IP networks are nil
Can happen for `docker run --network none ...`

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2026-01-08 15:01:10 +01:00
Sebastiaan van Stijn
07e2a782c7 libnet/internal/resolvconf: Parse: improve error message
When attempting to read a (malformed) resolv.conf with a very long line,
a obscure error would be produced that didn't provide much context to
identify the problem;

    Handler for POST /v1.51/containers/mariadb11/start returned error: bufio.Scanner: token too long

This patch adds some additional error-handling to detect this situation,
and includes the filename of the resolv.conf to help the user locating
the file that failed to be parsed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-01-06 14:43:51 +01:00
Sebastiaan van Stijn
614d9b966f daemon/libnetwork/options: GenerateFromModel: remove redundant check
This check was added in 14c5cd377d to prevent
passing `nil` as type (`GenerateFromModel[nil](....)`), however, `nil` is not
a type, so trying to do so won't compile. Even if it would, it would be
theoretical at best, so let's just remove it.

fix linting:

    daemon/libnetwork/options/options.go:57:13: SA4023(related information): the lhs of the comparison is the 1st return value of this function call (staticcheck)
        modType := reflect.TypeFor[T]()
                   ^
    daemon/libnetwork/options/options.go:58:5: SA4023: this comparison is never true (staticcheck)
        if modType == nil {
           ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-12-17 14:19:53 +01:00
Paweł Gronowski
0ae3f972ad daemon: Simplify slices.Contains usage
Remove unnecessary intermediate variables and helper functions when
using slices.Contains.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-16 13:31:33 +01:00
Paweł Gronowski
6c5233e109 modernize: Use strings.CutSuffix
Added in Go 1.20

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-15 18:56:34 +01:00
Paweł Gronowski
71fd582aa2 modernize: Use strings.Builder instead of string concatenation
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-15 18:56:34 +01:00
Paweł Gronowski
62ed24a87c modernize: Use slices.Contains
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-15 18:56:34 +01:00
Paweł Gronowski
3df05205f4 modernize: Use range int
Added in Go 1.22

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-15 18:56:34 +01:00
Paweł Gronowski
e548a31d28 modernize: Use min built-in
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-15 18:56:34 +01:00
Paweł Gronowski
39c19d9161 modernize: Use fmt.Appendf
Added in Go 1.19

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-15 18:56:33 +01:00
Paweł Gronowski
cdce8f4f92 modernize: Use maps.Copy instead of for loops
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-15 18:56:33 +01:00
Paweł Gronowski
c9b0a21bb1 modernize: Use b.Loop (introduced in Go 1.24)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-15 18:56:33 +01:00
Sebastiaan van Stijn
99066209a2 libnetwork/options: GenerateFromModel: use generics
Use generics so that the produced output is already in the right
type.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-12-10 01:48:48 +01:00
Sebastiaan van Stijn
14c5cd377d libnetwork/options: GenerateFromModel: reduce reflection
Re-use some of the reflection results where possible.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-12-10 01:48:45 +01:00
kumy
b56d077034 fix: Correct typo in error message
Signed-off-by: kumy <kumy@users.noreply.github.com>
2025-12-03 13:13:46 +01:00
Albin Kerouanton
310aa9241a libnet/pm: log when stopping userland proxy
Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
2025-11-28 19:40:37 +01:00
Albin Kerouanton
52fae09ec0 libnet/pms/nat: don't bind IPv6 ports if not supported by port driver
In rootless mode, the Engine needs to call the rootless port driver to
know which IP address it should bind to inside of its network namespace.

The slirp4netns port drivers doesn't support binding to IPv6 address, so
we need to detect that before listening on the port.

Before commit 201968cc0, this wasn't a problem because the Engine was
binding the port, then calling rootless port driver to learn whether the
proto/IP family was supported, and listen on the port if so.

Starting with that commit, the Engine does bind + listen in one go, and
then calls the port driver — this is too late. Fix the bug by checking
if the port driver supports the PortBindingReq, and only allocate the
port if so.

Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
2025-11-28 19:40:34 +01:00
Albin Kerouanton
56e8e43339 Revert "libnet: populateNetworkResourcesOS: updateDNS only if !needResolver"
This reverts commit 937246a868.

Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
2025-11-28 09:47:07 +01:00
Albin Kerouanton
83f00e9f2b Revert "libnet: rebuildDNS: update the hash file"
This reverts commit eb18b398d4.

Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
2025-11-28 09:47:04 +01:00
Albin Kerouanton
14a955db2f Revert "libnet: setupDNS: don't overwrite user-modified resolv.conf"
This reverts commit 7639e193ff.

Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
2025-11-28 09:47:01 +01:00
Albin Kerouanton
20634eddce Merge pull request #51496 from thaJeztah/discoverapi_cleanups
libnetwork: some minor refactor / cleanups
2025-11-27 12:22:01 +01:00
Rob Murray
baf59d62d6 Merge pull request #51592 from robmry/sbleave_gw_config_error
Suppress errors from gateway re-config when disconnecting a network
2025-11-26 16:07:41 +00:00
Rob Murray
8f2aa3e0f5 Network disconnect: log rather than error on gateway update
During a network disconnect, log rather than returning an error
if it's not possible to set up a new gateway.

This restores the behaviour from before commit 53390f8 ("Put
clearNetworkResources() inline in its only caller"). It's not
ideal, but by the time new gateways are selected the old
endpoint has been disconnected - and nothing puts things back.
Until that's cleaned up, a broken state is inevitable, but
letting endpoint deletion complete means the container can
be restarted or re-connected to the network without a zombie
endpoint causing further issues.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-11-26 14:45:18 +00:00
Rob Murray
18d2a08fcf Merge pull request #51587 from robmry/unmap_ipv6_addr
Unmap() more netip.Addr vars created from slices
2025-11-25 19:30:27 +00:00
Rob Murray
731ae07e65 Endpint.sbLeave: when deleting container, no new gateway
When the endpoint providing a container's default gateway
is removed, there's no need to select a new gateway if the
container is being removed.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-11-25 18:11:07 +00:00
zhangguanzhang
7639e193ff libnet: setupDNS: don't overwrite user-modified resolv.conf
Call resolvconf.UserModified() in sandbox.setupDNS() to check if
resolv.conf was manually modified before regenerating it during
container restart for non-host network modes.

Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
2025-11-25 20:32:40 +08:00
Albin Kerouanton
eb18b398d4 libnet: rebuildDNS: update the hash file
Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
2025-11-25 11:51:27 +01:00
Albin Kerouanton
937246a868 libnet: populateNetworkResourcesOS: updateDNS only if !needResolver
When ep.needResolver() is true, sb.startResolver() calls sb.rebuildDNS()
which doesn't update the resolv.conf hash file.

Subsequent calls to sb.updateDNS() (which is only called by
populateNetworkResourcesOS) won't have any effect since it'll compare
the hash file and consider that the file was manually modified.

Make this explicit by gating the call to updateDNS() on !needResolver().

Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
2025-11-25 11:43:36 +01:00
Rob Murray
a2de9bb334 Unmap more netip.Addr vars created using AddrFromSlice
Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-11-24 16:51:14 +00:00
Rob Murray
ed10b98506 Restore missing nwEndpointsMu.Lock
- introduced by 4f7afb8 (Remove libnet's logic to track a driver's
  port mapping state)

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-11-18 15:38:48 +00:00
Sebastiaan van Stijn
e59d1b4563 libnetwork/drivers/overlay: DiscoverNew: move logic to setKeys, updateKeys
Make the DiscoverNew switch only responsible for asserting the correct
data type, and push the conversion logic into the setKeys and updateKeys
methods.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-16 23:36:04 +01:00
Sebastiaan van Stijn
f40b45ca1f libnetwork/drivers/overlay: use structured logs in some places
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-16 23:36:04 +01:00
Sebastiaan van Stijn
c9f0314f21 libnetwork: controller.handleKeyChange: slight cleanup of logs
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-16 23:36:03 +01:00
Sebastiaan van Stijn
a81d441133 Merge pull request #51534 from robmry/dont-remove-removed-gateway
Don't try to remove a cleared docker_gwbridge endpoint
2025-11-15 00:32:32 +01:00
Rob Murray
1731e9e729 Don't try to remove cleared docker_gwbridge endpoint
If a container is using a docker_gwbridge endpoint as its gateway,
when it's connected to another network that provides a gateway, the
docker_gwbridge endpoint is removed when that endpoint is added (in
a recursive nightmare).

So, the "before" gateway for the container has been removed
before the new gateway is updateExternalConnectivity'd.

Don't pass the old gateway to updateExternalConnectivity in that
case, because the network driver's already forgotten about it.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-11-14 17:41:01 +00:00
Albin Kerouanton
2e41476a5f libnet: create DNS records on sbJoin (if not agent node)
Commit a8b9eff90 removed a call to Network.updateSvcRecord from
Network.createEndpoint on the grounds that:

> all callers of Network.createEndpoint follow up with an Endpoint.Join,
> which also sets up the DNS entry.

However, the original call in Network.createEndpoint was gated by:

```
if !n.getController().isSwarmNode() || n.Scope() != scope.Swarm || !n.driverIsMultihost() {
	n.updateSvcRecord(context.WithoutCancel(ctx), ep, true)
}
```

whereas the call in Endpoint.sbJoin() (invoked by Endpoint.Join()) is
gated by:

```
if !n.getController().isAgent() {
    if !n.getController().isSwarmNode() || n.Scope() != scope.Swarm || !n.driverIsMultihost() {
	    n.updateSvcRecord(context.WithoutCancel(ctx), ep, true)
    }
}
```

As a result, once a node has joined a Swarm cluster, no DNS entries are
created for non swarm-scoped networks.

Change the condition used by `sbJoin` to match the original condition
used in `createEndpoint`.

Signed-off-by: Albin Kerouanton <albin.kerouanton@docker.com>
2025-11-13 17:31:13 +01:00
Sebastiaan van Stijn
81d9fdb838 Merge pull request #51477 from thaJeztah/discovery_enum
libnetwork/discoverapi: use DiscoveryType for enum
2025-11-11 15:01:25 +01:00
Sebastiaan van Stijn
6b8285f965 libnetwork/discoverapi: use DiscoveryType for enum
This type describes the options defined as consts below it, so make
those consts typed. While updating, I also removed the use of iota
to prevent accidentally changing their values (and if this API is
implemented elsewhere)

(but mostly because I'm not a fan of iota ':))

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-11 13:10:17 +01:00
Sebastiaan van Stijn
bb56c4d7e7 daemon: remove some deprecated and unused code
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-11 09:05:41 +01:00
David Negstad
ea0d934ff2 Allow requesting networks with a custom prefix size from the default pools
Signed-off-by: David Negstad <David.Negstad@microsoft.com>
2025-10-22 12:45:55 -07:00
Sebastiaan van Stijn
343185cf1a libnetwork: move Network.resolveDriver to Controller
In this method, the network was controlling the controller, and its
driver-registry. That really felt like two steps too far; let's just
move this method to the controller, so that it can stay, at least
_somewhat_ in control of its own, non-exported, properties.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-21 16:50:33 +02:00
Rob Murray
7989fea6d2 Merge pull request #51241 from thaJeztah/overlay_pass_context
libnetwork/drivers/overlay: pass context for logger
2025-10-21 14:22:12 +01:00
Sebastiaan van Stijn
ee3cab4158 libnetwork/drivers/overlay: pass context for logger
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-21 15:08:03 +02:00
Sebastiaan van Stijn
bdc7474826 Merge pull request #51229 from olljanat/win-overlay-custom-dns
libnetwork: support custom DNS servers in Windows overlay driver
2025-10-21 14:40:07 +02:00
Rob Murray
7066eb3736 Merge pull request #51223 from thaJeztah/cleaner_marshal
libnetwork: EndpointInterface: cleanup marshal/unmarshal
2025-10-21 12:10:36 +01:00
Sebastiaan van Stijn
79f01e4ffc Merge pull request #51217 from thaJeztah/hotel_california
libnetwork/drivers/macvlan, ipvlan: remove some redundant code, and cleanups / fixes
2025-10-21 12:03:01 +02:00
Sebastiaan van Stijn
33fc45e5c5 libnetwork: EndpointInterface: cleanup marshal/unmarshal
Define an intermediate struct for marshaling/unmarshaling; this
struct already uses netip types (in case we want to migrate the
actual struct to use these types as well).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-21 10:37:05 +02:00
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
975e46f726 libnetwork/datastore: small cleanups
- Use an intermediate struct for (un)marshaling dummyObject
- Remove dummyObject.SkipSave as it would always be set to "false"
  (i.e., persisted to disk).
- Minor cleanups in handling locks and some unused vars

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-20 11:49:03 +02:00
Sebastiaan van Stijn
10faa629fe libnetwork/drivers/macvlan, ipvlan: assorted minor cleanups
- Inline some vars and align between drivers
- Remove nested if's where possible
- Use `WithError` for some logs, and use the context if available
- Scope variables locally where only used locally and, the reverse,
  make it clear where a (function-)global variable is used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-20 08:52:09 +02:00