mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
5a259d55f0
fixes #405 Signed-off-by: Tomas Kral <tomas.kral@gmail.com>
29 lines
656 B
Go
29 lines
656 B
Go
package bridge
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
)
|
|
|
|
const (
|
|
ipv4ForwardConf = "/proc/sys/net/ipv4/ip_forward"
|
|
ipv4ForwardConfPerm = 0644
|
|
)
|
|
|
|
func setupIPForwarding() error {
|
|
// Get current IPv4 forward setup
|
|
ipv4ForwardData, err := ioutil.ReadFile(ipv4ForwardConf)
|
|
if err != nil {
|
|
return fmt.Errorf("Cannot read IP forwarding setup: %v", err)
|
|
}
|
|
|
|
// Enable IPv4 forwarding only if it is not already enabled
|
|
if ipv4ForwardData[0] != '1' {
|
|
// Enable IPv4 forwarding
|
|
if err := ioutil.WriteFile(ipv4ForwardConf, []byte{'1', '\n'}, ipv4ForwardConfPerm); err != nil {
|
|
return fmt.Errorf("Setup IP forwarding failed: %v", err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|