diff --git a/cmd/containerboot/main.go b/cmd/containerboot/main.go index 3676db02c..893495063 100644 --- a/cmd/containerboot/main.go +++ b/cmd/containerboot/main.go @@ -696,6 +696,13 @@ func installEgressForwardingRule(ctx context.Context, dstStr string, tsIPs []net if err := cmdSNAT.Run(); err != nil { return fmt.Errorf("setting up SNAT via iptables failed: %w", err) } + + cmdClamp := exec.CommandContext(ctx, argv0, "-t", "mangle", "-A", "FORWARD", "-o", "tailscale0", "-p", "tcp", "-m", "tcp", "--tcp-flags", "SYN,RST", "SYN", "-j", "TCPMSS", "--clamp-mss-to-pmtu") + cmdClamp.Stdout = os.Stdout + cmdClamp.Stderr = os.Stderr + if err := cmdClamp.Run(); err != nil { + return fmt.Errorf("executing iptables failed: %w", err) + } return nil } @@ -731,6 +738,12 @@ func installIngressForwardingRule(ctx context.Context, dstStr string, tsIPs []ne if err := cmd.Run(); err != nil { return fmt.Errorf("executing iptables failed: %w", err) } + cmdClamp := exec.CommandContext(ctx, argv0, "-t", "mangle", "-A", "FORWARD", "-o", "tailscale0", "-p", "tcp", "-m", "tcp", "--tcp-flags", "SYN,RST", "SYN", "-j", "TCPMSS", "--clamp-mss-to-pmtu") + cmdClamp.Stdout = os.Stdout + cmdClamp.Stderr = os.Stderr + if err := cmdClamp.Run(); err != nil { + return fmt.Errorf("executing iptables failed: %w", err) + } return nil } diff --git a/cmd/containerboot/main_test.go b/cmd/containerboot/main_test.go index e1353a8e6..67f75a4b3 100644 --- a/cmd/containerboot/main_test.go +++ b/cmd/containerboot/main_test.go @@ -330,6 +330,7 @@ func TestContainerBoot(t *testing.T) { WantCmds: []string{ "/usr/bin/tailscale --socket=/tmp/tailscaled.sock set --accept-dns=false", "/usr/bin/iptables -t nat -I PREROUTING 1 -d 100.64.0.1 -j DNAT --to-destination 1.2.3.4", + "/usr/bin/iptables -t mangle -A FORWARD -o tailscale0 -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu", }, }, }, @@ -354,6 +355,7 @@ func TestContainerBoot(t *testing.T) { "/usr/bin/tailscale --socket=/tmp/tailscaled.sock set --accept-dns=false", "/usr/bin/iptables -t nat -I PREROUTING 1 ! -i tailscale0 -j DNAT --to-destination 100.99.99.99", "/usr/bin/iptables -t nat -I POSTROUTING 1 --destination 100.99.99.99 -j SNAT --to-source 100.64.0.1", + "/usr/bin/iptables -t mangle -A FORWARD -o tailscale0 -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu", }, }, },