pkg/ip: don't write to /proc/sys if ipforward enabled
This enables setup in a container env like systemd nspawn where /proc/sys is mouted as read only. Signed-off-by: Shengjing Zhu <i@zhsj.me>
This commit is contained in:
@ -15,6 +15,7 @@
|
||||
package ip
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/containernetworking/cni/pkg/types/current"
|
||||
@ -51,5 +52,10 @@ func EnableForward(ips []*current.IPConfig) error {
|
||||
}
|
||||
|
||||
func echo1(f string) error {
|
||||
if content, err := ioutil.ReadFile(f); err == nil {
|
||||
if bytes.Equal(bytes.TrimSpace(content), []byte("1")) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return ioutil.WriteFile(f, []byte("1"), 0644)
|
||||
}
|
||||
|
Reference in New Issue
Block a user