Skip to content

Commit 0e2cc22

Browse files
authored
Merge pull request moby#50049 from robmry/nftables_env_var_enable
nftables: enable using env var
2 parents e37efd4 + 21a165d commit 0e2cc22

File tree

7 files changed

+28
-1
lines changed

7 files changed

+28
-1
lines changed

hack/make/.integration-test-helpers

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ test_env() {
201201
DOCKER_REMAP_ROOT="$DOCKER_REMAP_ROOT" \
202202
DOCKER_REMOTE_DAEMON="$DOCKER_REMOTE_DAEMON" \
203203
DOCKER_ROOTLESS="$DOCKER_ROOTLESS" \
204+
DOCKER_FIREWALL_BACKEND="$DOCKER_FIREWALL_BACKEND" \
204205
GITHUB_ACTIONS="$GITHUB_ACTIONS" \
205206
GO111MODULE="$GO111MODULE" \
206207
GOCACHE="$GOCACHE" \

libnetwork/controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ func New(ctx context.Context, cfgOptions ...config.Option) (_ *Controller, retEr
168168
diagnosticServer: diagnostic.New(),
169169
}
170170

171+
c.selectFirewallBackend()
171172
c.drvRegistry.Notify = c
172173

173174
// External plugins don't need config passed through daemon. They can

libnetwork/controller_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/containerd/log"
1010
"github.com/docker/docker/api/types/system"
11+
"github.com/docker/docker/libnetwork/internal/nftables"
1112
"github.com/docker/docker/libnetwork/iptables"
1213
"github.com/docker/docker/libnetwork/netlabel"
1314
"github.com/docker/docker/libnetwork/options"
@@ -16,6 +17,9 @@ import (
1617

1718
// FirewallBackend returns the name of the firewall backend for "docker info".
1819
func (c *Controller) FirewallBackend() *system.FirewallInfo {
20+
if nftables.Enabled() {
21+
return &system.FirewallInfo{Driver: "nftables"}
22+
}
1923
usingFirewalld, err := iptables.UsingFirewalld()
2024
if err != nil {
2125
return nil

libnetwork/drivers/bridge/bridge_linux.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,6 @@ func (d *driver) configure(option map[string]interface{}) error {
519519
if err != nil {
520520
return err
521521
}
522-
iptables.OnReloaded(d.handleFirewalldReload)
523522

524523
var pdc portDriverClient
525524
if config.Rootless {
@@ -535,6 +534,12 @@ func (d *driver) configure(option map[string]interface{}) error {
535534
d.config = config
536535
d.Unlock()
537536

537+
// Register for an event when firewalld is reloaded, but take the config lock so
538+
// that events won't be processed until the initial load from Store is complete.
539+
d.configNetwork.Lock()
540+
defer d.configNetwork.Unlock()
541+
iptables.OnReloaded(d.handleFirewalldReload)
542+
538543
return d.initStore()
539544
}
540545

libnetwork/firewall_linux.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"os"
78

89
"github.com/containerd/log"
10+
"github.com/docker/docker/libnetwork/internal/nftables"
911
"github.com/docker/docker/libnetwork/iptables"
1012
)
1113

1214
const userChain = "DOCKER-USER"
1315

16+
func (c *Controller) selectFirewallBackend() {
17+
// Only try to use nftables if explicitly enabled by env-var.
18+
// TODO(robmry) - command line options?
19+
if os.Getenv("DOCKER_FIREWALL_BACKEND") == "nftables" {
20+
_ = nftables.Enable()
21+
}
22+
}
23+
1424
// Sets up the DOCKER-USER chain for each iptables version (IPv4, IPv6) that's
1525
// enabled in the controller's configuration.
1626
func (c *Controller) setupUserChains() {

libnetwork/firewall_others.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
package libnetwork
44

5+
func (c *Controller) selectFirewallBackend() {}
6+
57
func (c *Controller) setupUserChains() {}

testutil/daemon/daemon.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ func New(t testing.TB, ops ...Option) *Daemon {
234234
}
235235
ops = append(ops, WithOOMScoreAdjust(-500))
236236

237+
if val, ok := os.LookupEnv("DOCKER_FIREWALL_BACKEND"); ok {
238+
ops = append(ops, WithEnvVars("DOCKER_FIREWALL_BACKEND="+val))
239+
}
240+
237241
d, err := NewDaemon(dest, ops...)
238242
assert.NilError(t, err, "could not create daemon at %q", dest)
239243
if d.rootlessUser != nil && d.dockerdBinary != defaultDockerdBinary {

0 commit comments

Comments
 (0)