From 06afbe9618ce8dcb3da420ebe18dace1ef7a3efc Mon Sep 17 00:00:00 2001 From: Rob Murray Date: Wed, 14 May 2025 10:03:42 +0100 Subject: [PATCH] Check nftables is enabled before applying updates Signed-off-by: Rob Murray --- libnetwork/internal/nftables/nftables_linux.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libnetwork/internal/nftables/nftables_linux.go b/libnetwork/internal/nftables/nftables_linux.go index 884263d748..c78656a128 100644 --- a/libnetwork/internal/nftables/nftables_linux.go +++ b/libnetwork/internal/nftables/nftables_linux.go @@ -259,9 +259,12 @@ table {{$family}} {{$tableName}} { // Apply makes incremental updates to nftables, corresponding to changes to the [TableRef] // since Apply was last called. func (t TableRef) Apply(ctx context.Context) error { - var buf bytes.Buffer + if !Enabled() { + return errors.New("nftables is not enabled") + } // Update nftables. + var buf bytes.Buffer if err := incrementalUpdateTempl.Execute(&buf, t.t); err != nil { return fmt.Errorf("failed to execute template nft ruleset: %w", err) }