Commit Graph

3500 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
92a05cf414 Merge pull request #48359 from thaJeztah/fix_linting_issues
Fix linting issues in preparation of Go and GolangCI-lint update
2024-08-28 15:48:29 +02:00
Sebastiaan van Stijn
9fca5e7b6f Merge pull request #48368 from thaJeztah/vendor_netlink_1.2.1
vendor: github.com/vishvananda/netlink v1.3.0
2024-08-28 10:26:55 +02:00
Sebastiaan van Stijn
068c1bf3be libnetwork/drivers/bridge: fix non-constant format string in call (govet)
libnetwork/drivers/bridge/setup_ip_tables_linux.go:385:23: printf: non-constant format string in call to fmt.Errorf (govet)
                    return fmt.Errorf(msg)
                                      ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-27 10:23:40 +02:00
Sebastiaan van Stijn
7b60a7047d libnetwork/cnmallocator: fix non-constant format string in call (govet)
libnetwork/cnmallocator/drivers_ipam.go:43:31: printf: non-constant format string in call to (*github.com/docker/docker/vendor/github.com/sirupsen/logrus.Entry).Infof (govet)
            log.G(context.TODO()).Infof("Swarm initialized global default address pool to: " + str.String())
                                        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-27 10:23:39 +02:00
Sebastiaan van Stijn
6008c42ca2 libnetwork: fix non-constant format string in call (govet)
libnetwork/controller.go:1054:32: printf: non-constant format string in call to github.com/docker/docker/libnetwork/types.NotFoundErrorf (govet)
                return types.NotFoundErrorf(err.Error())
                                            ^
    libnetwork/controller.go:1073:32: printf: non-constant format string in call to github.com/docker/docker/libnetwork/types.NotFoundErrorf (govet)
                return types.NotFoundErrorf(err.Error())
                                            ^
    libnetwork/sandbox_externalkey_unix.go:113:21: printf: non-constant format string in call to fmt.Errorf (govet)
            return fmt.Errorf(string(buf[0:n]))
                              ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-27 10:23:39 +02:00
Sebastiaan van Stijn
c7b36f8953 libnetwork: TestDNSOptions: remove redundant skip check
libnetwork/sandbox_dns_unix_test.go:17:13: SA4032: due to the file's build constraints, runtime.GOOS will never equal "windows" (staticcheck)
        skip.If(t, runtime.GOOS == "windows", "test only works on linux")
                   ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-27 09:57:17 +02:00
Sebastiaan van Stijn
6d0a5e31d7 vendor: github.com/vishvananda/netlink v1.2.1
Local changes related to:

- c96b03b4be
- dedb7ec04b

full diff: https://github.com/vishvananda/netlink/compare/v1.2.1-beta.2...v1.2.1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-26 12:32:10 +02:00
Sebastiaan van Stijn
fe307b5dab libnetwork: resolvconf: remove dependency on errdefs
the resolvconf package is imported in BuildKit, and this is the only
location that used the errdefs package outside of the client.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-23 17:54:21 +02:00
Sebastiaan van Stijn
afdfc04e10 libnetwork: resolvconf: remove var that shadowed import
It was only used in a single place, so we can remove the
intermediate variable.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-23 17:54:16 +02:00
Rob Murray
0f341c4cd5 Merge pull request #48322 from robmry/64bit_iprange_fix
Allow 64-bit --ip-range
2024-08-13 15:24:59 +01:00
Rob Murray
496b457ad8 Allow --ip-range ending on a 64-bit boundary
When defaultipam.newPoolData is asked for a pool of 64-bits
or more, it ends up with an overflowed u64 - so, it just
subtracts one to get a nearly-big-enough range (for a 64-bit
subnet).

When defaultipam.getAddress is called with an ipr (sub-pool
range), the range it calls bitmask.SetAnyInRange with is
exclusive of end. So, its end param can't be MaxUint64,
because that's the max value for the top end of the range
and, when checking the range, SetAnyInRange fails.

When fixed-cidr-v6 behaves more like fixed-cidr, it will ask
for a 64-bit range if that's what fixed-cidr-v6 needs. So,
it hits the bug when allocating an address for, for example:

  docker network create --ipv6 --subnet fddd::/64 --ip-range fddd::/64 b46

The additional check for "ipr == base" avoids the issue in
this case, by ignoring the ipr/sub-pool range if ipr is the
same as the pool itself (not really a sub-pool).

But, it still fails when ipr!=base. For example:

  docker network create --ipv6 --subnet fddd::/56 --ip-range fddd::/64 b46

So, also subtract one from 'end' if it's going to hit the max
value allowed by the Bitmap.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-12 15:36:32 +01:00
Rob Murray
1d8ff115d8 Merge pull request #48290 from robmry/v6only/dns
IPv6 only: DNS changes
2024-08-12 15:17:53 +01:00
Sebastiaan van Stijn
8d06e70f34 Merge pull request #48132 from robmry/bind_socket_for_docker_proxy
Create docker-proxy TCP/UDP listener sockets in the daemon
2024-08-08 20:30:58 +02:00
Rob Murray
925b484a40 No fallback nameservers for internal resolver
The internal resolver now uses any namesever found in the host's
/etc/resolv.conf as an external nameserver, and it's accessed
from the host's network namespace.

Before this change, when no external nameservers were found (so
the host had no entries in /etc/resolv.conf) Google's DNS servers
were used as fallbacks, always accessed from the container's
network namespace. If a container's initial set of endpoints had
IPv6 enabled, the IPv6 nameservers were included.

Now we have IPv6-only networks, a similar exception would be
needed for Google's IPv4 nameservers... don't include them if
there are no IPv4 endpoints.

However, only the initial set of endpoints was considered. As
networks are connected/disconnected, IPv4 or IPv6 connectivity
may be lost.

Unlike nameservers read from the host's /etc/resolv.conf, there
is no way to tell which fallback nameservers (v4/v6) might work
from the host's namespace. So, using the host's namespace isn't
a good solution.

Since we want to get away from using fallback nameservers anyway,
this change removes them.

If a host has no /etc/resolv.conf entries, but a container does
need to use DNS, it'll need to be configured with servers via
'--dns'.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-06 10:33:05 +01:00
Rob Murray
d29767431c Use host netns for host's ext-dns servers
The internal resolver needs to know whether to make requets
to external DNS servers from the container's network namespace
or the host's.

The original rule was that requests were always made from the
container's namespace, unless the nameserver was on a localhost
address on the host. IPv6 nameservers were left in the container's
/etc/resolv.conf.

Commit 4e8d9a4 modified that so that IPv6 nameservers were also
used as external nameservers. The internal resolver accessed
them from the host namespace if the container's initial set of
endpoints were IPv4-only, or the nameserver address contained
a zone-id, (or the nameserver was on the IPv6 loopback address).

That would break if initial IPv6 endpoints were disconnected from
the container, leaving it with no IPv6 address.

Once IPv6-only networks are allowed, another exception would need
to be made for IPv4 nameservers (they'd need to be accessed from
the host's namespace).

Instead of doing that ... this change simplifies things, if a
nameserver address is read from the host's /etc/resolv.conf, it'll
work in the host's namespace. So, the rule is now simply that
nameservers read from the host's resolv.conf are accessed from the
host's namespace. DNS servers added as overrides ('--dns') are
accessed from the container's namespace (as before).

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-06 10:33:04 +01:00
Rob Murray
344039b9ae Populate DNS records for IPv6-only endpoints
Also, return IPv6 records from Network.getSvcRecords()
so that /etc/hosts entries are deleted when an IPv6-only
endpoint is removed.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-06 10:33:04 +01:00
Rob Murray
ea914a66a2 Use retErr in Network.ipamAllocate
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-05 15:45:05 +01:00
Rob Murray
cdea750966 Tell RootlessKit about port mappings when --userland-proxy=false
The daemon was modified to tell RootlessKit about host port
mappings directly, rather than by running rootlesskit-docker-proxy
to make those updates.

DNAT rules created in rootless mode referred to the host IP address,
rather than the address seen as host address in the rootless network
namespace.

With these changes, port mappings work in rootless mode when
--userland-proxy=false - so, don't gate the RootlessKit API calls
on starting docker-proxy.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-05 14:04:05 +01:00
Rob Murray
b3fabedecc Create docker-proxy TCP/UDP listener sockets in the daemon
Before commit 4f09af6, when allocating host ports for a new
port mapping, iptables rules were set up then docker-proxy was
started. If the host port was already in-use, docker-proxy exited
with an error, and the iptables rules were removed. That could
potentially interfere with a non-docker service that was already
using the host port for something unrelated.

Commit 4f09af6 swapped that problem for a different one... in
order to check that a port was available before creating iptables
rules, it attempted to start docker-proxy first. If it failed, it
could then try a different host port, without interfering with
any other service. The problem with that is docker-proxy would
start listening before the iptables rules were in place, so it
could accept connections then become unusable because new NAT
rules diverted packets directly to the container. This would leave
the client with a broken connection, causing at-least a delay
while it figured that out and reconnected.

This change creates and binds the socket in the daemon, before
creating iptables rules. If the bind fails, it may try a different
port. When or if the bind succeeds, iptables rules are created,
then the daemon calls listen on the socket. If docker-proxy is
needed, the socket is handed over to it at that point.

In rootless mode, the ports have to be bound to an address in the
rootless network namespace (where dockerd is running). DNAT rules
now use the same address.

If docker-proxy is not needed ("--userland-proxy=false"), the daemon
still listens on TCP sockets as the old dummyProxy would have done.
This makes the socket show up in "netstat" output.

The dummyProxy is no longer needed on Linux. Its job was to bind the
host ports if docker-proxy was disabled, but that's now already
handled by binding the sockets early.

This change doesn't affect SCTP, because it's not currently possible
for docker-proxy to convert the file descriptor into an SCTPListener.
So, docker-proxy is still started early, and the window for lost
connections remains.

If the user has an old docker-proxy in their path and it's given a
listener docker with '-use-listen-fd', it'll fail because of the
unknown option. In this case, the daemon's error message suggests
checking $PATH.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-05 14:04:05 +01:00
Rob Murray
f1e0746c08 Tell RootlessKit about docker-proxy port mappings
Before this change, when running rootless, instead of running
docker-proxy the daemon would run rootlesskit-docker-proxy.

The job of rootlesskit-docker-proxy was to tell RootlessKit
about mapped host ports before starting docker-proxy, and then
to remove the mapping when it was stopped.

So, rootlesskit-docker-proxy would need to be kept in-step
with changes to docker-proxy (particuarly the upcoming change
to bind TCP/UDP ports in the daemon and pass them to the proxy,
but also possible-future changes like running proxy per-container
rather than per-port-mapping).

This change runs the docker-proxy in rootless mode, instead of
rootlesskit-docker-proxy, and the daemon itself tells RootlessKit
about changes in host port mappings.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-05 14:04:05 +01:00
Rob Murray
384ca56d90 Fix error type used for ProgramExternalConnectivity
Get rid of "FIXME: Got an API for which error does not match
any expected type!!!  error="driver failed programming external
connectivity on endpoint..." from debug logs.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-05 14:04:05 +01:00
Rob Murray
3b1341972b Only assign an IPv4 address if required
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-01 16:21:26 +01:00
Rob Murray
15e5f6868a Don't auto-allocate IPv4 IPAM if !enableIPv4
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-01 16:21:20 +01:00
Rob Murray
c0a6145f6d Enable IPv4 in the unit tests that will need it.
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-01 16:14:55 +01:00
Rob Murray
b42f4b96aa Check for an IPv6 gateway before connecting to docker_gwbridge
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-01 16:01:02 +01:00
Rob Murray
034a5a8986 Reject swarm n/w creation with IPv4 disabled.
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-01 14:20:27 +01:00
Rob Murray
c91dc7e6dc Reject Windows network creation with IPv4 disabled.
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-01 14:20:27 +01:00
Rob Murray
a43ed47441 Merge pull request #48271 from robmry/v6only/add_option_enable_ipv4
IPv6 only: add API option enable/disable IPv4
2024-07-31 19:21:42 +01:00
Rob Murray
1f542d5d6c Set EnableIPv4 for predefined networks
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-07-31 18:38:43 +01:00
Rob Murray
903daa4dc4 Add flag 'enableIPv4' to libnetwork.Network
Similar to EnableIPv6:
- Set it if EnableIPv4 is specified in a create request.
- Otherwise, set it if included in `default-network-opts`.
  - Apart from in a config-from network, so that it doesn't look
    like the API request set the field.
- Include the new field in  Network marshalling/unmarshalling test.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-07-31 18:38:43 +01:00
Sebastiaan van Stijn
376a699830 Merge pull request #48157 from thaJeztah/libnetwork_immutable_radix_v2
libnetwork/networkdb: switch to go-immutable-radix v2
2024-07-31 15:33:16 +02:00
Sebastiaan van Stijn
2847c4b7fe libnetwork/networkdb: switch to go-immutable-radix v2
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-26 23:11:53 +02:00
Rob Murray
ef8e2fe282 Use retErr in Endpoint.sbJoin
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-07-26 16:26:34 +01:00
Rob Murray
58808e7748 Remove code to update Network.enableIPv6 if false
Commit 4b9dc647 (from 2016) added this in response to a
review comment, but I don't think it can ever have worked
because n.enableIPv6 = netMap["enableIPv6"].(bool), added
in 2015, would already have panic'd if the field wasn't
stored.

In any case, it's no longer needed.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-07-26 16:26:34 +01:00
Rob Murray
8f1989556a Trivial tidy-up of Endpoint.assignAddress()
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-07-26 16:26:34 +01:00
Rob Murray
6fe26e0629 Add IPv6 to the null IPAM driver
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-07-26 16:26:34 +01:00
Sebastiaan van Stijn
20a0102c5f Merge pull request #48139 from corhere/go119atomics
all: switch to Go 1.19 atomics
2024-07-15 18:03:41 +02:00
Rob Murray
8be292a7bb By-default, don't create an iptables rule to checksum SCTP
For SCTP port mappings, an iptables mangle rule was create to fix
the checksum. The code comment says it was done to fix a problem
caused by the veth driver reporting NETIF_F_SCTP_CRC since kernel
4.9, when used with NICs that do not support NETIF_F_SCTP_CRC.

But the checksum rule fills in the checksum in the IP header,
not an SCTP checksum, so it doesn't seem related. And, quoting
from the github issue, "since kernel v4.19, the xt_CHECKSUM.c
explicitly states it should only be used for UDP and only in the
OUTPUT chain - while docker is using it for SCTP in the PREROUTING
chain".

Furthermore, the rule is reported to be causing errors for SCTP
between containers.

Because we don't entirely understand why the rule exists, it
is now only added if the daemon's env has
DOCKER_IPTABLES_SCTP_CHECKSUM=1. If no problems are reported, that
escape-hatch and the code to add the rule will be removed in a
future release.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-07-10 18:53:54 +01:00
Cory Snider
1c102140f8 libnetwork: switch to Go 1.19 atomics
Signed-off-by: Cory Snider <csnider@mirantis.com>
2024-07-08 11:09:56 -04:00
Cory Snider
46133bdb8e libnetwork/diagnostic: drop unsound use of atomics
It was unnecessary; access to the variable was synchronized through a
mutex in all cases but one, where synchonizing through the mutex would
work just fine without any chance of deadlocks.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2024-07-08 11:09:56 -04:00
Albin Kerouanton
1bf2e03636 Merge pull request #48135 from robmry/remove_ipv6_bridge_route_add
Remove IPv6 bridge RouteAdd() that always fails
2024-07-05 14:58:20 +02:00
Rob Murray
4776e6dd60 Remove IPv6 bridge RouteAdd() that always fails
The netlink.RouteAdd in setupBridgeIPv6 always failed, because
the bridge is always 'down' when it's called.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-07-04 18:28:37 +01:00
Sebastiaan van Stijn
c0dd5c18f6 Merge pull request #48081 from thaJeztah/gofumpt
do another run of gofumpt
2024-07-01 16:17:54 +02:00
Sebastiaan van Stijn
c94586d8ee Merge pull request #48088 from robmry/48067_fix_specific_ipv6_portmap_proxy_to_ipv4
Fix incorrect validation of port mapping
2024-06-28 21:05:26 +02:00
Rob Murray
dfbcddb9f5 Fix incorrect validation of port mapping
Regression introduced in 01eecb6.

A port mapping from a specific IPv6 host address can be used
by a container on an IPv4-only network, docker-proxy makes the
connection.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-28 17:32:15 +01:00
Rob Murray
4de54ee14c Fix duplicate subnet allocations
Keep allocated subnets in-order, so that they're not mistakenly
reallocated due to a gap in the list where misplaced subnets should
have been.

Introduced in 9d288b5.

The iterator over allocated subnets was incremented too early, this
change moves it past three clauses in addrSpace.allocatePredefinedPool().
The three new unit tests correspond to a separate failure caused by
incrementing before each of them.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-06-28 13:34:35 +01:00
Sebastiaan van Stijn
84e43da752 libnetwork: gofumpt
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-27 23:18:48 +02:00
Sebastiaan van Stijn
59b119f94e Merge pull request #47994 from thaJeztah/simplify_getDummyName
libnetwork: ipvlan, macvlan: cleanup getDummyName utility
2024-06-18 21:25:55 +02:00
Albin Kerouanton
3e85c9d517 Merge pull request #48025 from robmry/fix_port_mapped_hairpin
Fix hairpin between networks with mapped port
2024-06-18 19:46:16 +02:00
Sebastiaan van Stijn
f741ca857c libnetwork/drivers/macvlan: getDummyName don't use stringid.TruncateID
The stringid.TruncateID utility is used to provide a consistent length
for "short IDs" (containers, networks). While the dummy interfaces need
a short identifier, they use their own format and don't have to follow
the same length as is used for "short IDs" elsewhere.

In addition, stringid.TruncateID has an additional check for the given
ID to contain colons (":"), which won't be the case for network-IDs that
are passed to it, so this check is redundant.

This patch moves the truncating local to the getDummyName function, so
that it can define its own semantics, independent of changes elsewhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-18 19:40:15 +02:00