2015-03-04 13:11:31 -05:00
|
|
|
package bridge
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-03-04 16:25:43 -05:00
|
|
|
ipv4ForwardConf = "/proc/sys/net/ipv4/ip_forward"
|
|
|
|
ipv4ForwardConfPerm = 0644
|
2015-03-04 13:11:31 -05:00
|
|
|
)
|
|
|
|
|
2015-08-03 18:27:53 -04:00
|
|
|
func setupIPForwarding() error {
|
2015-07-27 07:31:03 -04:00
|
|
|
// 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)
|
|
|
|
}
|
2015-03-04 14:37:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2015-03-04 13:11:31 -05:00
|
|
|
}
|