Fix issue 872 (#873)

Read and check ip_forward from proc before write
This commit is contained in:
Zoltan Papp 2023-05-18 19:31:54 +02:00 committed by GitHub
parent 48a8b52740
commit 8a8c4bdddd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -62,6 +62,16 @@ func removeFromRouteTable(prefix netip.Prefix) error {
}
func enableIPForwarding() error {
err := os.WriteFile(ipv4ForwardingPath, []byte("1"), 0644)
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)
}