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-05-06 01:51:26 -04:00
|
|
|
func setupIPForwarding(config *Configuration) error {
|
2015-03-04 13:11:31 -05:00
|
|
|
// Sanity Check
|
2015-04-15 01:25:42 -04:00
|
|
|
if config.EnableIPForwarding == false {
|
2015-05-14 17:56:15 -04:00
|
|
|
return &ErrIPFwdCfg{}
|
2015-03-04 13:11:31 -05:00
|
|
|
}
|
2015-03-04 14:37:16 -05:00
|
|
|
|
2015-03-04 13:11:31 -05:00
|
|
|
// Enable IPv4 forwarding
|
2015-03-04 16:25:43 -05:00
|
|
|
if err := ioutil.WriteFile(ipv4ForwardConf, []byte{'1', '\n'}, ipv4ForwardConfPerm); err != nil {
|
2015-03-04 14:37:16 -05:00
|
|
|
return fmt.Errorf("Setup IP forwarding failed: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2015-03-04 13:11:31 -05:00
|
|
|
}
|