41 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Cory Snider
a90adb6dc1 api/types/network: use netip types as appropriate
And generate the ServiceInfo struct from the Swagger spec.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-10-03 21:39:14 +02:00
Cory Snider
46ab36ae46 daemon/internal: move netiputil from libnetwork
These utilities are going to be needed elsewhere in the daemon to handle
netip values from API requests.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-10-03 21:39:13 +02:00
Rob Murray
b26972f9f2 Merge pull request #51033 from robmry/use-libnftables
Use libnftables in dynamically linked binary
2025-10-03 16:53:06 +01:00
Sebastiaan van Stijn
eff4f064a3 daemon/libnetwork/internal/kvstore: remove unused ErrBackendNotSupported
The `ErrBackendNotSupported` error was no longer used since [moby@37cbdeb].

[moby@37cbdeb]: 37cbdeb1f2

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-29 14:53:01 +02:00
Sebastiaan van Stijn
1697aecbd5 daemon/libnetwork/internal/kvstore: remove unused BOLTDB and Backend type
The `BOLTDB` const and related `Backend` type are no longer used since
[moby@ed08486].

[moby@ed08486]: ed08486ec7

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-29 14:45:40 +02:00
Rob Murray
38fb0dd10c Add build tag "no_libnftables"
With this tag, a dynamically linked binary will exec
the nft tool instead of using cgo to call libnftables
directly.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-09-26 13:36:39 +00:00
Rob Murray
6db6de2c20 Use libnftables in dynamically linked binary
Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-09-24 18:27:17 +01:00
Cory Snider
3f86797d3f api,daemon: report IPAM status for network
On API v1.52 and newer, the GET /networks/{id} endpoint returns
statistics about the IPAM state for the subnets assigned to the network.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-09-10 11:06:05 -04:00
Cory Snider
ee8abb845d d/libnetwork: move uint128 to its own package
The uint128 type is very convenient for manipulating 128 bit-wide
quantities, as tends to come up in several contexts when working with
IPv6. Move it into a libnetwork/internal/ package so it can be reused
elsewhere within libnetwork.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-09-10 11:00:35 -04: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
d019451022 Merge pull request #50850 from corhere/addrset-popcnt
d/libn/internal/addrset: add popcount methods
2025-09-04 21:04:22 +02:00
Cory Snider
854ec0a1ad d/libn/internal/addrset: add popcount methods
Add methods to count the number of addresses in the set which have a
particular prefix. The returned counts are 128 bits wide to accommodate
sets containing more than 2**64 addresses.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-08-29 15:17:28 -04:00
Rob Murray
ed78637b9a nftables: iterate over rules
When generating the rules for an nftables chain, rather than collecting
rules into a slice and iterating over that, use an iterator.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-08-29 10:49:14 +01:00
Rob Murray
785ae9a0f9 Rework the interface to libnet/internal/nftables
Add nftables.Modifier, to hold a queue of commands that can be applied
using Modifier.Apply. No updates are made to the underlying Table
until Apply is called, errors in the queue if commands are deferred
until Apply.

This has the advantages that:
- less error handling is needed in code that generates update commands
- it's transactional, without needing explicit transactions

Minor disadvantages are that it's slightly more difficult to debug updates,
as it's no longer possible to step through the call making an update to
the Table manipulation in a debugger - and errors in the command, and
errors like trying to update a nonexistent chain/set/vmap, deleting an
object that doesn't exist or creating a duplicate are not reported
until the updates are applied (but, the file/line where the rule was
added is reported).

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-08-28 19:27:19 +01:00
Albin Kerouanton
1d6c7663c4 d/libnet/i/nftables: move golden files into subdir
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-08-25 10:48:46 +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
Sebastiaan van Stijn
78ccee32b3 update various "doc" links in code
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-05 20:49:57 +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
5b913b3ea0 Move internal/sliceutil to daemon/internal/sliceutil
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-24 12:15:19 -07:00
Cory Snider
c7b93702b9 libn/d/overlay: extract hashable address types
The macAddr and ipmac types are generally useful within libnetwork. Move
them to a dedicated package and overhaul the API to be more like that of
the net/netip package.

Update the overlay driver to utilize these types, adapting to the new
API.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-07-22 11:51:18 -04:00
Albin Kerouanton
289ef96d8b libnet/d/bridge/i/rlkclient: move to libnet/i/rlkclient
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-07-22 12:37:01 +02:00
Rob Murray
8c79486dab Merge pull request #50357 from robmry/firewall_backend_option
Add daemon option --firewall-backend
2025-07-17 19:21:12 +01:00
Rob Murray
39ab393274 Add daemon option --firewall-backend
Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-07-17 15:12:01 +01:00
Sebastiaan van Stijn
2b17ab0ec6 libnet/internal/resolvconf: fix naming of error (errname)
#27 94.97 executor/oci/internal/resolvconf/resolvconf.go:461:6: the error type name `systemErr` should conform to the `xxxError` format (errname)
    #27 94.97 type systemErr struct{ error }
    #27 94.97      ^

Also fix an unhandled error; we don't need a defer() for that one

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-17 13:58:31 +02:00
Sebastiaan van Stijn
aa757e591d libnet/internal/resolvconf: don't use rc.WriteFile in tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-17 13:57:38 +02:00
Sebastiaan van Stijn
8d54d36bce libnet/internal/resolvconf: fix naming of error
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-17 11:43:33 +02:00
Sebastiaan van Stijn
60a3a28a04 libnet/internal/resolvconf: minor optimizations
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-17 11:40:17 +02:00
Sebastiaan van Stijn
f22a3dfdb7 libnet/internal/resolvconf: optimize Generate() without text/template
Rewrite this function to not use text/template, which is ~74× faster,
~25× less memory, and ~56× fewer allocations.

Before/After:

    BenchmarkGenerate-10       42550     27439 ns/op    18083 B/op    394 allocs/op
    BenchmarkGenerate-10     3148328       373 ns/op      712 B/op      7 allocs/op

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-17 11:40:11 +02:00
Sebastiaan van Stijn
0775ab6661 libnet/internal/resolvconf: add benchmark for Generate()
goos: darwin
    goarch: arm64
    pkg: github.com/docker/docker/daemon/libnetwork/internal/resolvconf
    cpu: Apple M1 Pro
    BenchmarkGenerate
    BenchmarkGenerate-10    	   42550	     27439 ns/op	   18083 B/op	     394 allocs/op
    PASS

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-17 11:37:28 +02:00
Sebastiaan van Stijn
fdd9ae3465 libnet/internal/resolvconf: use slices.Clone
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-15 17:28:59 +02:00
Derek McGowan
3b5f7c2a29 Move internal/modprobe to daemon/libnetwork/internal/modprobe
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-14 09:25:55 -07:00
Derek McGowan
7f4713a364 Move internal/maputil to daemon/libnetwork/internal/maputil
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-14 09:25:39 -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