From 832f1028c736c9e876cbf9a41edec42af2a39e44 Mon Sep 17 00:00:00 2001 From: Ross Zurowski Date: Tue, 27 Jun 2023 15:00:42 -0400 Subject: [PATCH] net/netutil: parse IP forwarding val as int, not bool (#8455) This commit updates our IP forwarding parsing logic to allow the less common but still valid value of `2` to be parsed as `true`, which fixes an error some users encountered. Fixes #8375 Signed-off-by: Ross Zurowski --- net/netutil/ip_forward.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/netutil/ip_forward.go b/net/netutil/ip_forward.go index f8c6a90fc..9b015c754 100644 --- a/net/netutil/ip_forward.go +++ b/net/netutil/ip_forward.go @@ -212,9 +212,16 @@ func ipForwardingEnabledLinux(p protocol, iface string) (bool, error) { } return false, err } - on, err := strconv.ParseBool(string(bytes.TrimSpace(bs))) + + val, err := strconv.ParseInt(string(bytes.TrimSpace(bs)), 10, 32) if err != nil { return false, fmt.Errorf("couldn't parse %s: %w", k, err) } + // 0 = disabled, 1 = enabled, 2 = enabled (but uncommon) + // https://github.com/tailscale/tailscale/issues/8375 + if val < 0 || val > 2 { + return false, fmt.Errorf("unexpected value %d for %s", val, k) + } + on := val == 1 || val == 2 return on, nil }