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
This commit is contained in:
Patrik Lundin
2019-12-26 11:17:26 +01:00
parent 0bc3c3bc58
commit e62b6121d1
+12 -2
View File
@@ -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 {