ptp: add ipv6 support

* Wait for addresses to leave tentative state before setting routes
* Enable forwarding correctly
* Set up masquerading according to the active protocol
This commit is contained in:
Casey Callendrello
2017-06-12 21:12:23 +02:00
parent f8134be6ef
commit 3daee3214d
7 changed files with 258 additions and 25 deletions

View File

@@ -16,6 +16,8 @@ package ip
import (
"io/ioutil"
"github.com/containernetworking/cni/pkg/types/current"
)
func EnableIP4Forward() error {
@@ -26,6 +28,28 @@ func EnableIP6Forward() error {
return echo1("/proc/sys/net/ipv6/conf/all/forwarding")
}
// EnableForward will enable forwarding for all configured
// address families
func EnableForward(ips []*current.IPConfig) error {
v4 := false
v6 := false
for _, ip := range ips {
if ip.Version == "4" && !v4 {
if err := EnableIP4Forward(); err != nil {
return err
}
v4 = true
} else if ip.Version == "6" && !v6 {
if err := EnableIP6Forward(); err != nil {
return err
}
v6 = true
}
}
return nil
}
func echo1(f string) error {
return ioutil.WriteFile(f, []byte("1"), 0644)
}