From 8a8c4bdddd81518db6f561279ca33a078281dd8a Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Thu, 18 May 2023 19:31:54 +0200 Subject: [PATCH] Fix issue 872 (#873) Read and check ip_forward from proc before write --- client/internal/routemanager/systemops_linux.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/internal/routemanager/systemops_linux.go b/client/internal/routemanager/systemops_linux.go index 4f56e8299..67c59be2d 100644 --- a/client/internal/routemanager/systemops_linux.go +++ b/client/internal/routemanager/systemops_linux.go @@ -62,6 +62,16 @@ func removeFromRouteTable(prefix netip.Prefix) error { } func enableIPForwarding() error { - err := os.WriteFile(ipv4ForwardingPath, []byte("1"), 0644) - return err + bytes, err := os.ReadFile(ipv4ForwardingPath) + if err != nil { + return err + } + + // check if it is already enabled + // see more: https://github.com/netbirdio/netbird/issues/872 + if len(bytes) > 0 && bytes[0] == 49 { + return nil + } + + return os.WriteFile(ipv4ForwardingPath, []byte("1"), 0644) }