24 Commits

Author SHA1 Message Date
Cory Snider
fb0f15c89a daemon/libnetwork/osl: fix panic on repeated interface removal
Namespace.RemoveInterface closes the Interface's stopCh to stop the
unsolicited ARP/NA sender, but only unregisters the Interface from the
Namespace once the removal has completed. Several failure exits sit in
between, so a removal that fails part-way leaves the Interface
registered with a closed stopCh.

Callers tear interfaces down by iterating over Namespace.Interfaces, so
the same *Interface is handed back to RemoveInterface during a later
teardown, and the second close panics, taking down the API request
being served:

    http: panic serving @: close of closed channel

Seen in CI while disconnecting an endpoint during Sandbox.Refresh:
LinkSetNsFd failed with EBADF after the link had already been renamed
back to its source name, so the following re-join couldn't find the
link, and the rollback in Endpoint.sbJoin removed the same Interface
again.

Close stopCh through a sync.Once, so the ARP/NA sender is still
guaranteed to stop whether or not the netlink teardown succeeds, and
however many times removal is attempted. Keep leaving a failed
Interface registered in the Namespace: the link may still be present
there, and generateIfaceName relies on n.iFaces to avoid handing out
its name again.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Signed-off-by: Cory Snider <csnider@mirantis.com>
2026-07-29 15:03:39 -04:00
Paweł Gronowski
88df5b627e daemon: Adjust file permissions for umask 000
Clearing the daemon umask means creation sites can no longer rely on
umask 0022 to remove group/other-write bits from permissive modes.

Adjust modes for daemon-owned files that previously depended on the old
umask:

- fuse-overlayfs lower file
- goroutine stack dump file
- layer migration tar-data file
- network namespace mount file

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2026-06-17 14:57:17 +02:00
Darafei Praliaskouski
b357912211 daemon/libnetwork/osl: stop draining after LinkSubscribe timeout
The LinkSubscribe cleanup path is documented as bounded, but the timeout case only logged a warning and kept waiting for the update channel to close. If the subscription goroutine does not terminate, the deferred cleanup can still block forever after the warning.

Return from the drain loop after logging the timeout so waitForIfUpped can finish its bounded cleanup path.

Signed-off-by: Darafei Praliaskouski <me@komzpa.net>
2026-05-27 00:42:04 +04:00
Akihiro Suda
84aedb8055 rootless: support detach-netns mode
Now `dockerd-rootless.sh` launches RootlessKit with `--detach-netns`
so as to run the daemon in the host network namespace.

The libnetwork namespaces are allocated inside the "detached" netns
(`$ROOTLESSKIT_STATE_DIR/netns`) that is associated with slirp4netns,
vpnkit, pasta, etc., as the rootless daemon has no `CAP_NET_ADMIN` for
the host network namespace.

This will enable:
- Accelerated (and deflaked) `docker pull`, `docker push`, `docker build`, etc
- Proper support for `docker pull 127.0.0.1:.../...`
- Proper support for `dockern run --net=host`

See also:
- rootless-containers/rootlesskit PR 379
- containerd/nerdctl PR 2723

NOTE: libnetwork contains code generated by Claude Code

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2026-04-10 02:02:51 +09:00
Sebastiaan van Stijn
5378f5427f daemon/libnetwork/ns: remove ParseHandlerInt, add NsHandle
It's more transparent for the caller to handle conversion.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-29 19:51:20 +02:00
Sebastiaan van Stijn
7cfe94a34e daemon/libnetwork/osl: don't chain "WithXXX" for logs
Follow-up to fadc29b86f

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-14 22:26:31 +01:00
Sebastiaan van Stijn
236b2fa7e8 Merge pull request #51988 from psaab/master
libnetwork: send neighbor advertisements on restore
2026-02-14 21:40:39 +01:00
Paul Saab
fadc29b86f libnetwork: send neighbor advertisements on restore
When the Docker daemon restarts with live-restore enabled, containers
retain their network namespaces but neighboring hosts may have stale
ARP/neighbor cache entries. This causes IPv6 connectivity issues because
unlike IPv4, where gratuitous ARP is sent on interface setup, IPv6
relies on Neighbor Discovery Protocol which requires explicit Neighbor
Advertisement messages to update caches.

This change adds unsolicited ARP (for IPv4) and Neighbor Advertisement
(for IPv6) messages when restoring interfaces after a daemon restart,
mirroring the behavior that already exists in AddInterface for new
containers.

The fix also handles network drivers (such as SR-IOV and macvlan) that
don't store the MAC address in the endpoint configuration by fetching
it from the actual link when needed.

Signed-off-by: Paul Saab <ps@mu.org>
2026-02-14 07:51:29 -08:00
Sebastiaan van Stijn
21d383fca5 modernize: waitgroup
Update some remaining waitgroups;

    go install golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest
    modernize -waitgroup -fix ./...

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-13 18:49:51 +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
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
Sebastiaan van Stijn
a65293c036 libnetwork/osl/kernel: ApplyOSTweaks: don't log errors if not found
I noticed these errors logged inside the dev-container;

    ERRO[2025-10-14T16:15:46.603781797Z] error reading the kernel parameter net.ipv4.neigh.default.gc_thresh1  error="open /proc/sys/net/ipv4/neigh/default/gc_thresh1: no such file or directory"
    ERRO[2025-10-14T16:15:46.603808089Z] error reading the kernel parameter net.ipv4.neigh.default.gc_thresh2  error="open /proc/sys/net/ipv4/neigh/default/gc_thresh2: no such file or directory"
    ERRO[2025-10-14T16:15:46.603819922Z] error reading the kernel parameter net.ipv4.neigh.default.gc_thresh3  error="open /proc/sys/net/ipv4/neigh/default/gc_thresh3: no such file or directory"

Given that these happen during an initial check, we can probably ignore them
if there's nothing to tweak.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-15 02:26:25 +02:00
Cory Snider
d5c838dc5e internal: move sliceutil from daemon/internal
These utilities are very handy to use in integration tests, too. Move
the package so it can be imported by them.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-10-03 21:39:14 +02: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
2bb0443ae9 Release IPv6 address if unused due to sysctl setting
When running:
  docker network create --ipv6 b46
  docker run --rm -ti \
    --network name=b46,driver-opt=com.docker.network.endpoint.sysctls=net.ipv6.conf.IFNAME.disable_ipv6=1 \
     busybox

IPv6 is enabled in the container and the network, so an IPv6 address
will be allocated for the endpoint.

But, when the sysctl is applied, the IPv6 address will be removed
from the interface ... so, no unsolicited neighbour advertisement
should be (or can be) sent and, the endpoint should not be treated
as dual-stack when selecting a gateway endpoint and, if it is
selected as the gateway endpoint, setting up an IPv6 route via the
network will fail.

So, if the IPv6 address disappears after sysctls have been applied,
release the address and remove it from the endpoint's config.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-09-15 10:39:08 +01: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
Sebastiaan van Stijn
6505e8d605 daemon/libnetwork/types: rename StaticRoute.GetCopy to Copy
Just for consistency; it was the last `GetCopy` remaining.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-12 11:48:24 +02:00
Sebastiaan van Stijn
115b801a3b daemon/libnetwork/types: remove GetMacCopy; use slices.Clone
We can replace this utility with slices.Clone, which provides the
same functionality.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-12 11:38:09 +02:00
Sebastiaan van Stijn
cf15d5bbc6 remove obsolete //go:build tags
These are no longer needed as these are now part of a module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-01 00:49:22 +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
Derek McGowan
14eb2770b9 Move internal/unshare to daemon/internal/unshare
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-24 12:15:50 -07:00
Derek McGowan
5b913b3ea0 Move internal/sliceutil to daemon/internal/sliceutil
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-24 12:15:19 -07:00
Derek McGowan
713d7f5ed1 Move internal/nlwrap to daemon/libnetwork/nlwrap
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-24 12:13:58 -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