route changes + primary addr on node

This commit is contained in:
0xdcarns
2022-04-19 16:18:03 -04:00
parent 8e976d1f55
commit dc12b1e418
16 changed files with 169 additions and 63 deletions

View File

@@ -7,7 +7,9 @@ import (
"net"
"strings"
"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/netclient/ncutils"
"github.com/seancfoley/ipaddress-go/ipaddr"
)
func setRoute(iface string, addr *net.IPNet, address string) error {
@@ -28,7 +30,14 @@ func deleteRoute(iface string, addr *net.IPNet, address string) error {
}
func setCidr(iface, address string, addr *net.IPNet) {
ncutils.RunCmd("ip -4 route add "+addr.String()+" dev "+iface, false)
cidr := ipaddr.NewIPAddressString(addr.String()).GetAddress()
if cidr.IsIPv4() {
ncutils.RunCmd("ip -4 route add "+addr.String()+" dev "+iface, false)
} else if cidr.IsIPv6() {
ncutils.RunCmd("ip -6 route add "+addr.String()+" dev "+iface, false)
} else {
logger.Log(1, "could not parse address: "+addr.String())
}
}
func removeCidr(iface string, addr *net.IPNet, address string) {