From e62b6121d12b847d625e15f9f8129fc485f71358 Mon Sep 17 00:00:00 2001 From: Patrik Lundin Date: Thu, 26 Dec 2019 11:17:26 +0100 Subject: [PATCH] Only enable IP forwarding if it is disabled Any value other than 0 is considered enabled: https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt Fixes #30 --- server.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index 88c34a7..c811560 100644 --- a/server.go +++ b/server.go @@ -112,9 +112,19 @@ func NewServer() *Server { } func (s *Server) enableIPForward() error { - log.Info("Enabling sys.net.ipv4.ip_forward") p := "/proc/sys/net/ipv4/ip_forward" - return ioutil.WriteFile(p, []byte("1"), 0640) + + content, err := ioutil.ReadFile(p) + if err != nil { + return err + } + + if string(content) == "0\n" { + log.Info("Enabling sys.net.ipv4.ip_forward") + return ioutil.WriteFile(p, []byte("1"), 0640) + } + + return nil } func (s *Server) initInterface() error {