mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-15 06:05:27 +08:00
36 lines
1 KiB
Go
36 lines
1 KiB
Go
package local
|
|
|
|
import (
|
|
//"github.com/davecgh/go-spew/spew"
|
|
|
|
"fmt"
|
|
"net"
|
|
"strings"
|
|
|
|
"github.com/gravitl/netmaker/netclient/ncutils"
|
|
)
|
|
|
|
func setRoute(iface string, addr *net.IPNet, address string) error {
|
|
out, err := ncutils.RunCmd(fmt.Sprintf("ip route get %s", addr.IP.String()), false)
|
|
if err != nil || !strings.Contains(out, iface) {
|
|
_, err = ncutils.RunCmd(fmt.Sprintf("ip route add %s dev %s", addr.String(), iface), false)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func deleteRoute(iface string, addr *net.IPNet, address string) error {
|
|
var err error
|
|
out, _ := ncutils.RunCmd(fmt.Sprintf("ip route get %s", addr.IP.String()), false)
|
|
if strings.Contains(out, iface) {
|
|
_, err = ncutils.RunCmd(fmt.Sprintf("ip route del %s dev %s", addr.String(), iface), false)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func setCidr(iface, address string, addr *net.IPNet) {
|
|
ncutils.RunCmd("ip -4 route add "+addr.String()+" dev "+iface, false)
|
|
}
|
|
|
|
func removeCidr(iface string, addr *net.IPNet, address string) {
|
|
ncutils.RunCmd("ip route delete "+addr.String()+" dev "+iface, false)
|
|
}
|