Commit Graph

3789 Commits

Author SHA1 Message Date
Albin Kerouanton
73f2a5336d libnet/d/bridge: fix compilation on i386
On i386, Linux doesn't provide direct socket syscall but instead
multiplexes them through the socketcall syscall (see `man 2 socketcall`).
This commit fixes compilation for i386 by wrapping the offending syscall
in a new function that uses the socketcall syscall on i386, and
the `setsockopt` syscall on other archs.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-02-23 12:01:59 +01:00
Rob Murray
5719e8edf9 Don't create iptables rules when iptables is disabled
New iptables rules were added by:
- commit 27adcd5 (libnet/d/bridge: port mappings: drop direct-access
  when gw_mode=nat)
- commit d216084 (libnet/d/bridge: drop remote connections to port
  mapped on lo)

But they're added even when iptables=false or ip6tables=false in daemon
config.

So, group those rules with the other per-port rules, behind a config
check.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-02-14 12:55:12 +00:00
Sebastiaan van Stijn
6ee1558852 Merge pull request #49417 from thaJeztah/fix_linting_step1
Fix linting issues to allow enabling more linters
2025-02-13 23:58:24 +01:00
Rob Murray
96dc9cb693 Don't log a warning when an IP address is already in an ipset
It's situation-normal when firewalld is reloaded.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-02-11 11:59:41 +00:00
Rob Murray
b23b8f1567 Restore more iptables rules on firewalld reload
In the bridge network driver, filterPortMappedOnLoopback and
filterDirectAccess each set up some per-port iptables rules - but
they're not called by setPerPortIptables.

So, make sure they're called when firewalld is reloaded.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-02-11 11:59:41 +00:00
Sebastiaan van Stijn
6929a3fd22 libnetwork/networkdb: make switches exhaustive (exhaustive)
Adding a `default` statement so that disabling the "default-signifies-exhaustive"
linter option will  make it show up.

    libnetwork/networkdb/delegate.go:49:2: missing cases in switch of type networkdb.NodeEvent_Type: networkdb.NodeEventTypeInvalid (exhaustive)
        switch nEvent.Type {
        ^
    libnetwork/networkdb/delegate.go:223:2: missing cases in switch of type networkdb.TableEvent_Type: networkdb.TableEventTypeInvalid (exhaustive)
        switch tEvent.Type {
        ^
    libnetwork/networkdb/nodemgmt.go:51:2: missing cases in switch of type networkdb.nodeState: networkdb.nodeNotFound (exhaustive)
        switch newState {
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:51 +01:00
Sebastiaan van Stijn
1a047bbe8b libnetwork: ignore unchecked json (Un)Marshal errors (errchkjson)
These need revisiting, similar to similar code in libnetwork/drivers/bridge.
There was already a TODO in place for this, so ignoring these for now.

    libnetwork/endpoint.go:148:11: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
        ib, _ := json.Marshal(epMap["ep_iface"])
                 ^
    libnetwork/endpoint.go:151:11: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
        jb, _ := json.Marshal(epMap["joinInfo"])
                 ^
    libnetwork/endpoint.go:154:11: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
        tb, _ := json.Marshal(epMap["exposed_ports"])
                 ^
    libnetwork/endpoint.go:159:11: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
        cb, _ := json.Marshal(epMap["sandbox"])
                 ^
    libnetwork/endpoint.go:237:12: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
        sal, _ := json.Marshal(epMap["svcAliases"])
                  ^
    libnetwork/endpoint.go:242:11: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
        pc, _ := json.Marshal(epMap["ingressPorts"])
                 ^
    libnetwork/endpoint.go:247:11: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
        ma, _ := json.Marshal(epMap["myAliases"])
                 ^
    libnetwork/endpoint.go:252:11: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
        dn, _ := json.Marshal(epMap["dnsNames"])
                 ^
    libnetwork/endpoint_info.go:123:11: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
        rb, _ := json.Marshal(epMap["routes"])
                 ^
    libnetwork/endpoint_info.go:490:12: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
            tb, _ := json.Marshal(v)
                     ^
    libnetwork/network.go:161:11: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
            b, _ := json.Marshal(v)
                    ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:50 +01:00
Sebastiaan van Stijn
63deb55263 libnetwork/drivers/bridge: bridgeEndpoint.UnmarshalJSON: fix unhandled errors (errchkjson)
Log errors, but continue, to keep the existing behavior, but add a TODO
to revisit the logic.

    libnetwork/drivers/bridge/bridge_store.go:316:10: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
        d, _ := json.Marshal(epMap["ContainerConfig"])
                ^
    libnetwork/drivers/bridge/bridge_store.go:320:9: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
        d, _ = json.Marshal(epMap["ExternalConnConfig"])
               ^
    libnetwork/drivers/bridge/bridge_store.go:324:9: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
        d, _ = json.Marshal(epMap["PortMapping"])
               ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:50 +01:00
Sebastiaan van Stijn
26d30159f7 libnetwork/driverapi: ignore unchecked error (for now) (errchkjson)
libnetwork/driverapi/ipamdata.go:52:11: Error return value of `encoding/json.Marshal` is not checked: unsafe type `interface{}` found (errchkjson)
            b, _ := json.Marshal(v)
                    ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:49 +01:00
Sebastiaan van Stijn
b87c9fb3f4 libnetwork/diagnostic: ignore unchecked error (errchkjson)
libnetwork/diagnostic/server.go:234:19: Error return value of `encoding/json.MarshalIndent` is not checked: unsafe type `github.com/docker/docker/libnetwork/diagnostic.StringInterface` found (errchkjson)
                    response, _ = json.MarshalIndent(FailCommand(err), "", "  ")
                                  ^
    libnetwork/diagnostic/server.go:239:19: Error return value of `encoding/json.Marshal` is not checked: unsafe type `github.com/docker/docker/libnetwork/diagnostic.StringInterface` found (errchkjson)
                    response, _ = json.Marshal(FailCommand(err))
                                  ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:49 +01:00
Sebastiaan van Stijn
17f32e8822 libnetwork/internal/resolvconf: avoid allocations with bytes.NewBufferString (mirror)
libnetwork/internal/resolvconf/resolvconf_test.go:63:21: avoid allocations with bytes.NewBufferString (mirror)
                rc, err := Parse(bytes.NewBuffer([]byte("options "+tc.options)), "")
                                 ^
    libnetwork/internal/resolvconf/resolvconf_test.go:106:19: avoid allocations with bytes.NewBufferString (mirror)
        rc, err := Parse(bytes.NewBuffer([]byte("nameserver 1.2.3.4")), "")
                         ^
    libnetwork/internal/resolvconf/resolvconf_test.go:214:21: avoid allocations with bytes.NewBufferString (mirror)
                rc, err := Parse(bytes.NewBuffer([]byte(input)), "")
                                 ^
    libnetwork/internal/resolvconf/resolvconf_test.go:311:21: avoid allocations with bytes.NewBufferString (mirror)
                rc, err := Parse(bytes.NewBuffer([]byte(tc.input)), "/etc/resolv.conf")
                                 ^
    libnetwork/internal/resolvconf/resolvconf_test.go:418:21: avoid allocations with bytes.NewBufferString (mirror)
                rc, err := Parse(bytes.NewBuffer([]byte(tc.input)), "/etc/resolv.conf")
                                 ^
    libnetwork/internal/resolvconf/resolvconf_test.go:492:21: avoid allocations with bytes.NewBufferString (mirror)
                rc, err := Parse(bytes.NewBuffer([]byte(content)), "/etc/resolv.conf")
                                 ^
    libnetwork/internal/resolvconf/resolvconf_test.go:535:19: avoid allocations with bytes.NewBufferString (mirror)
        rc, err := Parse(bytes.NewBuffer([]byte("nameserver 1.2.3.4.5")), "")
                         ^
    libnetwork/internal/resolvconf/resolvconf_test.go:548:19: avoid allocations with bytes.NewBufferString (mirror)
        rc, err := Parse(bytes.NewBuffer([]byte("nameserver 127.0.0.53")), "/etc/resolv.conf")
                         ^
    libnetwork/internal/resolvconf/resolvconf_test.go:569:19: avoid allocations with bytes.NewBufferString (mirror)
        rc, err := Parse(bytes.NewBuffer([]byte(input)), "/etc/resolv.conf")
                         ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:46 +01:00
Sebastiaan van Stijn
0c8d086ed3 libnetwork: avoid allocations with regexp.Match (mirror)
libnetwork/drivers/bridge/bridge_linux_test.go:978:17: avoid allocations with regexp.Match (mirror)
            matched, _ := regexp.MatchString(regex, string(out[:]))
                          ^
    libnetwork/drivers/bridge/bridge_linux_test.go:1004:17: avoid allocations with regexp.Match (mirror)
            matched, _ := regexp.MatchString(regex, string(out[:]))
                          ^
    libnetwork/drivers/bridge/bridge_linux_test.go:1032:18: avoid allocations with regexp.Match (mirror)
                matched, _ := regexp.MatchString(regex, string(out[:]))
                              ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:46 +01:00
Sebastiaan van Stijn
dd8ee9eeb1 libnetwork/cnmallocator: fix append to non-zero initialized length (makezero)
libnetwork/cnmallocator/networkallocator.go:876:17: append to slice `ipamConfigs` with non-zero initialized length (makezero)
            ipamConfigs = append(ipamConfigs, &api.IPAMConfig{Family: api.IPAMConfig_IPV4})
                          ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:45 +01:00
Sebastiaan van Stijn
8e9fce7970 libnetwork/bitmap: fix append to non-zero initialized length (makezero)
Changing to use binary.LittleEndian.AppendUint64, which does not require
the slice to have an initial size, and makes the code slightly more
straightforward.

    libnetwork/bitmap/sequence.go:296:7: append to slice `ba` with non-zero initialized length (makezero)
        ba = append(ba, bm...)
             ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:45 +01:00
Sebastiaan van Stijn
f9890d97d1 libnet: kvstore/boltdb: fix append to non-zero initialized length (makezero)
Changing to use binary.LittleEndian.AppendUint64, which does not require
the slice to have an initial size, and makes the code slightly more
straightforward.

    libnetwork/internal/kvstore/boltdb/boltdb.go:79:11: append to slice `dbval` with non-zero initialized length (makezero)
            dbval = append(dbval, value...)
                    ^
    libnetwork/internal/kvstore/boltdb/boltdb.go:228:11: append to slice `dbval` with non-zero initialized length (makezero)
            dbval = append(dbval, value...)
                    ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-09 13:22:45 +01:00
Paweł Gronowski
6c3797923d Merge pull request #49155 from akerouanton/custom-ifname
libnet: add support for custom interface names
2025-02-06 18:09:49 +00:00
Paweł Gronowski
9e77d05967 add //go:build directives to prevent downgrading to go1.16 language
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-02-06 18:16:59 +01:00
Albin Kerouanton
5a703c2eda libnet/osl: scan ns ifaces to generate ifname
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-02-06 17:01:15 +01:00
Albin Kerouanton
78b0475605 libnet/osl: AddInterface: un-alias props into local vars
At first glance, it seemed like the Namespace lock was held to make
local copies of Namespace properties, but all those properties all safe
to access concurrently. So, un-alias those props and reduce the scope
of the mutex lock.

This helps understanding where locking is really needed.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-02-06 17:01:12 +01:00
Albin Kerouanton
56a7817b2d libnet: add support for custom interface names
To support this, a new netlabel is added: `com.docker.network.endpoint.ifname`.

It gives the ability to specify the interface name to be set by
netdrivers when the interface is added / moved into the container's
network namespace.

All builtin netdrivers support it.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-02-06 17:00:29 +01:00
Albin Kerouanton
6a8360012c libnet/osl: distinguish dstName & dstPrefix
Before this commit, `Interface.dstName` was used to store the dest
ifname prefix, and then the final ifname.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-02-06 17:00:29 +01:00
Paweł Gronowski
f353b56f49 Merge pull request #49392 from robmry/wait_for_mcast_route
Wait for a route to ff02::1 before sending NAs
2025-02-06 15:47:53 +00:00
Rob Murray
997a6e167e Merge pull request #49372 from robmry/remote_driver_skip_gw_alloc
Implement GwAllocChecker for the remote network driver
2025-02-05 11:30:33 +00:00
Rob Murray
d4fa252cd3 Wait for a route to ff02::1 before sending NAs
Commit aa3a23d (Temporary debug for unsolicited NA) added code to
check for a route from ::1 to ff02::1 if a neighbour advertisement
send failed ... hoping to show that the route appeared fairly quickly
after the first attempt.

The failure didn't happen in CI, perhaps other changes in that PR
changed the timing enough for it not to be an issue. Or, perhaps the
change in commit 9a6e96f (Before sending ARPs/NAs, check the bridge is
ready) was enough to solve the issue.

But, in case it's a timing issue we're just no longer seeing on the CI
hosts - check the route exists before trying to send an NA, and wait
for a short time if not.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-02-05 10:56:49 +00:00
Paweł Gronowski
6ee81dc3eb Merge pull request #49262 from robmry/gw_mode_isolated
Add gateway mode "isolated"
2025-02-05 09:29:20 +00:00
Rob Murray
634951457d Implement GwAllocChecker for the remote network driver
Commit 38e76eb (Ask network drivers if they'll use a gateway
address) added an optional driver interface "GwAllocChecker"
to give the driver a chance to say whether, given network
config options, it would use a gateway address if one was
reserved for it in IPAM.

So, implement support for that in the remote network driver.
The driver itself implements the interface, but only tries
to make an HTTP request to the driver plugin if the plugin
has reported support for it in response to an initial
capabilities request.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-02-04 19:35:20 +00:00
Rob Murray
9a6e96fd9c Before sending ARPs/NAs, check the bridge is ready
We don't enable STP on bridges belonging to bridge networks,
but bridge ports still need to transition from "disabled" to
"forwarding", after the veth device comes "up". Until then,
the bridge will just drop packets.

So, if a container's network is a veth device, and its other
end is slaved to a bridge - wait for the bridge port to
be "forwarding".

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-30 20:40:01 +00:00
Rob Murray
9fdcde7618 Add bridge gateway mode "isolated"
It can only be set on a "--internal" network, and the only difference is
that no address is assigned to the bridge. So, there's no route to a
host address.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-29 10:28:55 +00:00
Sebastiaan van Stijn
bbaa8af8f3 libnetwork/drivers/bridge: un-export errors
These errors implement errdefs interfaces, and are only used internally
for convenience. Un-export their implemetations because the types themselves
are not used as sentinel errors.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:12:42 +01:00
Sebastiaan van Stijn
3f9698e1f6 libnetwork/drivers/bridge: TestLinkDelete: use gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:12:42 +01:00
Sebastiaan van Stijn
74fd2ec0cf libnetwork/drivers/bridge: TestLinkCreateNoEnableIPv6: use gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:12:37 +01:00
Sebastiaan van Stijn
6e9ba725f8 libnetwork/drivers/bridge: TestLinkCreateTwo: use gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:15 +01:00
Sebastiaan van Stijn
bf3323fd40 libnetwork/drivers/bridge: TestLinkCreate: use gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:15 +01:00
Sebastiaan van Stijn
7012e3ce14 libnetwork/drivers/bridge: remove NonDefaultBridgeExistError
It was only used in a single place, and a generic errdefs.ErrInvalid; the
type itself was not used as sentinel error other than for a unit test.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:15 +01:00
Sebastiaan van Stijn
47f6d4e1bc libnetwork/drivers/bridge: internalize ErrInvalidGateway
It's a generic errdefs.ErrInvalidParameter, and the type itself is not
used as sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
3a9f4e0146 libnetwork/drivers/bridge: remove ErrInvalidMtu
It's a generic errdefs.ErrInvalidParameter, and the type itself is not
used as sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
2f42aa0e26 libnetwork/drivers/bridge: remove IPv4AddrNoMatchError
It's a generic error, doesn't implement an errdefs type, and not used as
sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
0c1b660048 libnetwork/drivers/bridge: remove IPv4AddrAddError
It's a generic error, doesn't implement an errdefs type, and not used as
sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
dc52ecb1d0 libnetwork/drivers/bridge: remove ErrNoIPAddr
It's a generic error, doesn't implement an errdefs type, and not used as
sentinel error anywhere.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:14 +01:00
Sebastiaan van Stijn
77261b5e42 libnetwork/drivers/bridge: remove "InternalError()" method from errors
The `InternalError()` method was added in [moby/libnetwork@50964c9] to
classify the error. However, the same commit defined interfaces for error
types (in the types package). The [InternalError] interface defined did
not match, as it defines a `Internal()` method instead of `InternalError()`.

In short; these errors were never matching any interface, and the actual
error implementations themselves were also never used as a sentinel error,
so we can safely remove these methods.

[moby/libnetwork@50964c9]: 50964c9948
[InternalError]: 50964c9948/types/types.go (L233-L237)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:13 +01:00
Sebastiaan van Stijn
2766298f49 libnetwork/drivers/bridge: remove unused errors
This removes the following errors, which were not used anywhere;

- ErrConfigExists
- ErrInvalidNetworkConfig
- ErrInvalidEndpointConfig
- ErrNetworkExists
- ErrIfaceName
- ErrUnsupportedAddressType
- NonDefaultBridgeNeedsIPError
- IPv6AddrNoMatchError

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:13 +01:00
Sebastiaan van Stijn
59c2d2a4b3 libnetwork/drivers/bridge: remove ErrInvalidDriverConfig
It's a generic error, doesn't implement an errdefs type, is poorly formatted,
and not used as sentinel error anywhere. Let's remove it, and update the error
produced to be slightly more informative (include the invalid type). Worth
noting that there's no need to include the name of the driver in the error,
because the only uses of the error (in `registerNetworkDrivers`) already
decorates it; 5fd7ed2937/libnetwork/drivers_linux.go (L34-L36)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 19:10:11 +01:00
Sebastiaan van Stijn
47dc8d5dd8 Merge pull request #49325 from akerouanton/fix-45610-v2
libnet/d/bridge: drop connections to lo mappings, and direct remote connections
2025-01-28 16:38:29 +01:00
Sebastiaan van Stijn
beb5fa6acc Merge pull request #49350 from thaJeztah/windows_clean_errors
libnetwork/drivers/windows: remove ErrUnsupportedAddressType
2025-01-28 16:30:49 +01:00
Sebastiaan van Stijn
6bb9f581a5 libnetwork/drivers/windows: remove ErrUnsupportedAddressType
It was only used in a single place, and did not implement an errdef;
the type itself was not used as sentinel error.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 15:14:27 +01:00
Sebastiaan van Stijn
510e6f4f8a libnetwork/options: rewrite tests with gotest.tools
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-28 12:27:44 +01:00
Sebastiaan van Stijn
5fd7ed2937 Merge pull request #49342 from robmry/debug_flaky_unsol_na
Debug flaky unsolicited Neighbour Advertisements
2025-01-28 12:14:38 +01:00
Albin Kerouanton
ac23dddac0 Merge pull request #49302 from robmry/create_veth_in_container
Create bridge veth in container netns
2025-01-28 11:47:33 +01:00
Albin Kerouanton
d216084185 libnet/d/bridge: drop remote connections to port mapped on lo
Traditionally when Linux receives remote packets with daddr set to a
loopback address, it reject them as 'martians'. However, when a NAT rule
is applied through iptables this doesn't happen. Our current DNAT rule
used to map host ports to containers is applied unconditionally, even
for such 'martian' packets.

This means a neighbor host (ie. a host connected to the same L2
segment) can send packets to a port mapped on a loopback address. The
purpose of publishing on a loopback address is to make ports
inaccessible to remote hosts -- lack of proper filtering defeats that.

This commit adds an iptables rule to the raw-PREROUTING chain to drop
packets with a loopback dest address and coming from any interface other
than lo.

To accomodate WSL2 mirrored mode, another rule is inserted beforehand to
specifically accept packets coming from the loopback0 interface.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-01-27 18:41:20 +01:00
Albin Kerouanton
27adcd596b libnet/d/bridge: port mappings: drop direct-access when gw_mode=nat
When a NAT-based port mapping is created, the daemon adds a DNAT rule in
nat-DOCKER to replace the dest addr with the container IP. However, the
daemon never sets up rules to filter packets destined directly to the
container port. This allows a rogue neighbor (ie. a host that shares a
L2 segment with the host) to send packets directly to the container on
its container-side exposed port.

For instance, if container port 5000 is mapped to host port 6000, a
neighbor could send packets directly to the container on its port 5000.

Since nat-DOCKER mangles the dest addr, and the nat table forbids DROP
rules, this change adds a new rule in the raw-PREROUTING chain to filter
ingress connections targeting the container's IP address.

This filtering is only done when gw_mode=nat. For the unprotected
variant, no filtering is done.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-01-27 18:41:20 +01:00