mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-11 01:54:34 +08:00
silenced logs
This commit is contained in:
parent
25ea986402
commit
3713d1891a
6 changed files with 57 additions and 24 deletions
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/gravitl/netmaker/netclient/auth"
|
||||
"github.com/gravitl/netmaker/netclient/config"
|
||||
"github.com/gravitl/netmaker/netclient/daemon"
|
||||
"github.com/gravitl/netmaker/netclient/local"
|
||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
||||
"github.com/gravitl/netmaker/netclient/wireguard"
|
||||
"golang.zx2c4.com/wireguard/wgctrl"
|
||||
|
@ -185,17 +186,19 @@ func LeaveNetwork(network string) error {
|
|||
}
|
||||
}
|
||||
}
|
||||
// extra network route setting required for freebsd and windows, TODO mac??
|
||||
if ncutils.IsWindows() {
|
||||
ip, mask, err := ncutils.GetNetworkIPMask(node.NetworkSettings.AddressRange)
|
||||
if err != nil {
|
||||
ncutils.PrintLog(err.Error(), 1)
|
||||
|
||||
wgClient, wgErr := wgctrl.New()
|
||||
if wgErr == nil {
|
||||
dev, devErr := wgClient.Device(cfg.Node.Interface)
|
||||
if devErr == nil {
|
||||
local.FlushPeerRoutes(cfg.Node.Interface, cfg.Node.Address, dev.Peers[:])
|
||||
_, cidr, cidrErr := net.ParseCIDR(cfg.NetworkSettings.AddressRange)
|
||||
if cidrErr == nil {
|
||||
local.RemoveCIDRRoute(cfg.Node.Interface, cfg.Node.Address, cidr)
|
||||
}
|
||||
} else {
|
||||
ncutils.PrintLog("could not flush peer routes when leaving network, "+cfg.Node.Network, 1)
|
||||
}
|
||||
_, _ = ncutils.RunCmd("route delete "+ip+" mask "+mask+" "+node.Address, true)
|
||||
} else if ncutils.IsFreeBSD() {
|
||||
_, _ = ncutils.RunCmd("route del -net "+node.NetworkSettings.AddressRange+" -interface "+node.Interface, true)
|
||||
} else if ncutils.IsLinux() {
|
||||
_, _ = ncutils.RunCmd("ip -4 route del "+node.NetworkSettings.AddressRange+" dev "+node.Interface, false)
|
||||
}
|
||||
|
||||
err = WipeLocal(node.Network)
|
||||
|
|
|
@ -58,7 +58,21 @@ func SetCurrentPeerRoutes(iface, currentAddr string, peers []wgtypes.Peer) {
|
|||
}
|
||||
}
|
||||
|
||||
// FlushPeerRoutes - removes all current peer routes
|
||||
func FlushPeerRoutes(iface, currentAddr string, peers []wgtypes.Peer) {
|
||||
for _, peer := range peers {
|
||||
for _, allowedIP := range peer.AllowedIPs {
|
||||
deleteRoute(iface, &allowedIP, currentAddr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SetCIDRRoute - sets the CIDR route, used on join and restarts
|
||||
func SetCIDRRoute(iface, currentAddr string, cidr *net.IPNet) {
|
||||
setCidr(iface, currentAddr, cidr)
|
||||
}
|
||||
|
||||
// RemoveCIDRRoute - removes a static cidr route
|
||||
func RemoveCIDRRoute(iface, currentAddr string, cidr *net.IPNet) {
|
||||
removeCidr(iface, cidr, currentAddr)
|
||||
}
|
||||
|
|
|
@ -16,22 +16,26 @@ func setRoute(iface string, addr *net.IPNet, address string) error {
|
|||
if strings.Contains(addr.IP.String(), ":") {
|
||||
inetx = "inet6"
|
||||
}
|
||||
out, err = ncutils.RunCmd("route -n get -"+inetx+" "+addr.IP.String(), true)
|
||||
out, err = ncutils.RunCmd("route -n get -"+inetx+" "+addr.IP.String(), false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !(strings.Contains(out, iface)) {
|
||||
_, err = ncutils.RunCmd("route -q -n add -"+inetx+" "+addr.String()+" -interface "+iface, true)
|
||||
_, err = ncutils.RunCmd("route -q -n add -"+inetx+" "+addr.String()+" -interface "+iface, false)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func deleteRoute(iface string, addr *net.IPNet, address string) error {
|
||||
var err error
|
||||
_, err = ncutils.RunCmd("route -q -n delete "+addr.String(), true)
|
||||
_, err = ncutils.RunCmd("route -q -n delete "+addr.String(), false)
|
||||
return err
|
||||
}
|
||||
|
||||
func setCidr(iface, address string, addr *net.IPNet) {
|
||||
ncutils.RunCmd("route -q -n add -net "+addr.String()+" "+address, true)
|
||||
ncutils.RunCmd("route -q -n add -net "+addr.String()+" "+address, false)
|
||||
}
|
||||
|
||||
func removeCidr(iface string, addr *net.IPNet, address string) {
|
||||
ncutils.RunCmd("route -q -n delete "+addr.String()+" -interface "+iface, false)
|
||||
}
|
||||
|
|
|
@ -8,16 +8,20 @@ import (
|
|||
|
||||
func setRoute(iface string, addr *net.IPNet, address string) error {
|
||||
var err error
|
||||
_, _ = ncutils.RunCmd("route add -net "+addr.String()+" -interface "+iface, true)
|
||||
_, _ = ncutils.RunCmd("route add -net "+addr.String()+" -interface "+iface, false)
|
||||
return err
|
||||
}
|
||||
|
||||
func deleteRoute(iface string, addr *net.IPNet, address string) error {
|
||||
var err error
|
||||
_, err = ncutils.RunCmd("route delete -net "+addr.String()+" -interface "+iface, true)
|
||||
_, err = ncutils.RunCmd("route delete -net "+addr.String()+" -interface "+iface, false)
|
||||
return err
|
||||
}
|
||||
|
||||
func setCidr(iface, address string, addr *net.IPNet) {
|
||||
ncutils.RunCmd("route add -net "+addr.String()+" -interface "+iface, true)
|
||||
ncutils.RunCmd("route add -net "+addr.String()+" -interface "+iface, false)
|
||||
}
|
||||
|
||||
func removeCidr(iface string, addr *net.IPNet, address string) {
|
||||
ncutils.RunCmd("route delete -net "+addr.String()+" -interface "+iface, false)
|
||||
}
|
||||
|
|
|
@ -11,16 +11,20 @@ import (
|
|||
|
||||
func setRoute(iface string, addr *net.IPNet, address string) error {
|
||||
var err error
|
||||
_, err = ncutils.RunCmd(fmt.Sprintf("ip route add %s dev %s", addr.String(), iface), true)
|
||||
_, 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
|
||||
_, err = ncutils.RunCmd(fmt.Sprintf("ip route del %s dev %s", addr.String(), iface), true)
|
||||
_, 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)
|
||||
}
|
||||
|
|
|
@ -9,20 +9,24 @@ import (
|
|||
|
||||
func setRoute(iface string, addr *net.IPNet, address string) error {
|
||||
var err error
|
||||
_, err = ncutils.RunCmd("route -p add "+addr.IP.String()+" mask "+addr.Mask.String()+" "+address, true)
|
||||
_, err = ncutils.RunCmd("route -p add "+addr.IP.String()+" mask "+addr.Mask.String()+" "+address, false)
|
||||
time.Sleep(time.Second >> 2)
|
||||
ncutils.RunCmd("route change "+addr.IP.String()+" mask "+addr.Mask.String()+" "+address, true)
|
||||
ncutils.RunCmd("route change "+addr.IP.String()+" mask "+addr.Mask.String()+" "+address, false)
|
||||
return err
|
||||
}
|
||||
|
||||
func deleteRoute(iface string, addr *net.IPNet, address string) error {
|
||||
var err error
|
||||
_, err = ncutils.RunCmd("route delete "+addr.IP.String()+" mask "+addr.Mask.String()+" "+address, true)
|
||||
_, err = ncutils.RunCmd("route delete "+addr.IP.String()+" mask "+addr.Mask.String()+" "+address, false)
|
||||
return err
|
||||
}
|
||||
|
||||
func setCidr(iface, address string, addr *net.IPNet) {
|
||||
ncutils.RunCmd("route -p add "+addr.IP.String()+" mask "+addr.Mask.String()+" "+address, true)
|
||||
ncutils.RunCmd("route -p add "+addr.IP.String()+" mask "+addr.Mask.String()+" "+address, false)
|
||||
time.Sleep(time.Second >> 2)
|
||||
ncutils.RunCmd("route change "+addr.IP.String()+" mask "+addr.Mask.String()+" "+address, true)
|
||||
ncutils.RunCmd("route change "+addr.IP.String()+" mask "+addr.Mask.String()+" "+address, false)
|
||||
}
|
||||
|
||||
func removeCidr(iface, address string, addr *net.IPNet) {
|
||||
ncutils.RunCmd("route delete "+addr.IP.String()+" mask "+addr.Mask.String()+" "+address, false)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue