mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-20 00:31:17 -08:00
util/linuxfw: run without IPv6 rules when ip6tables fails to initialize (#22362)
newIPTablesRunner returned the error from the IPv6 go-iptables constructor, which made tailscaled exit at startup. The nft flavor of ip6tables exits 1 from "--version" on kernels without nf_tables even though the binary is present. Treat that like a missing ip6tables and disable tunneled IPv6. Fixes #20348 Signed-off-by: Brendan Creane <[email protected]>
This commit is contained in:
1 parent
d0512a9ef7
commit
92f396d8e9
2 files changed
+64
-5
No files matched your search
@@ -102,14 +102,18 @@ func newIPTablesRunner(logf logger.Logf) (*iptablesRunner, error) {
|
||||
case ip6terr != nil:
|
||||
logf("disabling tunneled IPv6 due to missing ip6tables: %v", ip6terr)
|
||||
default:
|
||||
supportsV6 = true
|
||||
ipt6, err = iptables.NewWithProtocol(iptables.ProtocolIPv6)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// ip6tables is present but "ip6tables --version" failed,
|
||||
// as the nft flavor does on kernels without nf_tables.
|
||||
// Run without IPv6 rules instead of failing. (#20348)
|
||||
logf("disabling tunneled IPv6 due to ip6tables init failure: %v", err)
|
||||
} else {
|
||||
supportsV6 = true
|
||||
supportsV6Filter = checkSupportsV6Filter(ipt6, logf)
|
||||
supportsV6NAT = checkSupportsV6NAT(ipt6, logf)
|
||||
logf("netfilter running in iptables mode v6 = %v, v6filter = %v, v6nat = %v", supportsV6, supportsV6Filter, supportsV6NAT)
|
||||
}
|
||||
supportsV6Filter = checkSupportsV6Filter(ipt6, logf)
|
||||
supportsV6NAT = checkSupportsV6NAT(ipt6, logf)
|
||||
logf("netfilter running in iptables mode v6 = %v, v6filter = %v, v6nat = %v", supportsV6, supportsV6Filter, supportsV6NAT)
|
||||
}
|
||||
return &iptablesRunner{
|
||||
ipt4: ipt4,
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
// Copyright (c) Tailscale Inc & contributors
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build linux && !ts_omit_iptables
|
||||
|
||||
package linuxfw
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/tstest"
|
||||
"tailscale.com/types/logger"
|
||||
)
|
||||
|
||||
// TestNewIPTablesRunnerIP6TablesInitFailure checks that a present but
|
||||
// non-functional ip6tables disables IPv6 instead of failing runner creation.
|
||||
// The nft flavor of ip6tables exits 1 from "--version" on kernels without
|
||||
// nf_tables, which used to make tailscaled exit at startup (#20348).
|
||||
func TestNewIPTablesRunnerIP6TablesInitFailure(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
writeScript := func(name, body string) {
|
||||
t.Helper()
|
||||
if err := os.WriteFile(filepath.Join(dir, name), []byte("#!/bin/sh\n"+body), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
writeScript("iptables", "echo 'iptables v1.8.10 (legacy)'\n")
|
||||
writeScript("ip6tables", "echo 'ip6tables/1.8.10 Failed to initialize nft: Protocol not supported' >&2\nexit 1\n")
|
||||
t.Setenv("PATH", dir)
|
||||
|
||||
// Make the system IPv6 probe pass so the test reaches the ip6tables
|
||||
// constructor regardless of the host's IPv6 configuration.
|
||||
tstest.Replace(t, &checkIPv6ForTest, func(logger.Logf) error { return nil })
|
||||
|
||||
var logs strings.Builder
|
||||
r, err := newIPTablesRunner(func(format string, args ...any) {
|
||||
fmt.Fprintf(&logs, format+"\n", args...)
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("newIPTablesRunner: %v", err)
|
||||
}
|
||||
if r.HasIPV6() {
|
||||
t.Error("HasIPV6() = true; want false when ip6tables fails to initialize")
|
||||
}
|
||||
if r.HasIPV6Filter() || r.HasIPV6NAT() {
|
||||
t.Error("IPv6 filter/NAT reported available; want neither")
|
||||
}
|
||||
if !strings.Contains(logs.String(), "disabling tunneled IPv6 due to ip6tables init failure") {
|
||||
t.Errorf("log missing ip6tables init failure line; got:\n%s", logs.String())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user