mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 09:22:42 +08:00
route changes + primary addr on node
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user