mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-10 23:24:32 +08:00
Merge pull request #1033 from gravitl/bugfix_v0.13.0_cidr_parsing
Bugfix v0.13.0 cidr parsing
This commit is contained in:
commit
baeae557ce
3 changed files with 19 additions and 37 deletions
|
@ -5,7 +5,6 @@ import (
|
|||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
|
@ -56,7 +55,7 @@ func RegisterWithServer(private *ed25519.PrivateKey, cfg *config.ClientConfig) e
|
|||
CommonName: tls.NewCName(cfg.Node.Name),
|
||||
}
|
||||
url := "https://" + cfg.Server.API + "/api/server/register"
|
||||
log.Println("register at ", url)
|
||||
logger.Log(1, "register at "+url)
|
||||
|
||||
token, err := Authenticate(cfg)
|
||||
if err != nil {
|
||||
|
|
|
@ -147,9 +147,10 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||
// spin up userspace / windows interface + apply the conf file
|
||||
confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
|
||||
var deviceiface = ifacename
|
||||
var mErr error
|
||||
if ncutils.IsMac() { // if node is Mac (Darwin) get the tunnel name first
|
||||
deviceiface, err = local.GetMacIface(node.PrimaryAddress())
|
||||
if err != nil || deviceiface == "" {
|
||||
deviceiface, mErr = local.GetMacIface(node.PrimaryAddress())
|
||||
if mErr != nil || deviceiface == "" {
|
||||
deviceiface = ifacename
|
||||
}
|
||||
}
|
||||
|
@ -162,8 +163,8 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||
ifaceReady := strings.Contains(output, deviceiface)
|
||||
for !ifaceReady && !(time.Now().After(starttime.Add(time.Second << 4))) {
|
||||
if ncutils.IsMac() { // if node is Mac (Darwin) get the tunnel name first
|
||||
deviceiface, err = local.GetMacIface(node.PrimaryAddress())
|
||||
if err != nil || deviceiface == "" {
|
||||
deviceiface, mErr = local.GetMacIface(node.PrimaryAddress())
|
||||
if mErr != nil || deviceiface == "" {
|
||||
deviceiface = ifacename
|
||||
}
|
||||
}
|
||||
|
@ -194,6 +195,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||
if err != nil {
|
||||
logger.Log(1, "error setting peers: ", err.Error())
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
|
@ -215,9 +217,9 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||
} else {
|
||||
logger.Log(1, "could not set cidr route properly: ", cidrErr.Error())
|
||||
}
|
||||
|
||||
local.SetCurrentPeerRoutes(ifacename, node.Address6, peers)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -298,9 +300,17 @@ func ApplyConf(node *models.Node, ifacename string, confPath string) error {
|
|||
var nodeCfg config.ClientConfig
|
||||
nodeCfg.Network = node.Network
|
||||
nodeCfg.ReadConfig()
|
||||
ip, cidr, err := net.ParseCIDR(nodeCfg.NetworkSettings.AddressRange)
|
||||
if err == nil {
|
||||
local.SetCIDRRoute(node.Interface, ip.String(), cidr)
|
||||
if nodeCfg.NetworkSettings.AddressRange != "" {
|
||||
ip, cidr, err := net.ParseCIDR(nodeCfg.NetworkSettings.AddressRange)
|
||||
if err == nil {
|
||||
local.SetCIDRRoute(node.Interface, ip.String(), cidr)
|
||||
}
|
||||
}
|
||||
if nodeCfg.NetworkSettings.AddressRange6 != "" {
|
||||
ip, cidr, err := net.ParseCIDR(nodeCfg.NetworkSettings.AddressRange6)
|
||||
if err == nil {
|
||||
local.SetCIDRRoute(node.Interface, ip.String(), cidr)
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
|
|
|
@ -9,16 +9,6 @@ import (
|
|||
|
||||
// ApplyWindowsConf - applies the WireGuard configuration file on Windows
|
||||
func ApplyWindowsConf(confPath string) error {
|
||||
/*
|
||||
pathStrings := strings.Split(confPath, ncutils.GetWGPathSpecific())
|
||||
if len(pathStrings) == 2 {
|
||||
copyConfPath := fmt.Sprintf("%s\\%s", ncutils.WINDOWS_WG_DPAPI_PATH, pathStrings[1])
|
||||
err := ncutils.Copy(confPath, copyConfPath)
|
||||
if err != nil {
|
||||
logger.Log(err.Error(), 1)
|
||||
}
|
||||
}
|
||||
*/
|
||||
var commandLine = fmt.Sprintf(`wireguard.exe /installtunnelservice "%s"`, confPath)
|
||||
if _, err := ncutils.RunCmdFormatted(commandLine, false); err != nil {
|
||||
return err
|
||||
|
@ -31,22 +21,5 @@ func RemoveWindowsConf(ifacename string, printlog bool) error {
|
|||
if _, err := ncutils.RunCmd("wireguard.exe /uninstalltunnelservice "+ifacename, printlog); err != nil {
|
||||
logger.Log(1, err.Error())
|
||||
}
|
||||
/*
|
||||
dpapipath := fmt.Sprintf("%s\\%s.conf.dpapi", ncutils.WINDOWS_WG_DPAPI_PATH, ifacename)
|
||||
confpath := fmt.Sprintf("%s\\%s.conf", ncutils.WINDOWS_WG_DPAPI_PATH, ifacename)
|
||||
if ncutils.FileExists(confpath) {
|
||||
err := os.Remove(confpath)
|
||||
if err != nil {
|
||||
logger.Log(err.Error(), 1)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Second >> 2)
|
||||
if ncutils.FileExists(dpapipath) {
|
||||
err := os.Remove(dpapipath)
|
||||
if err != nil {
|
||||
logger.Log(err.Error(), 1)
|
||||
}
|
||||
}
|
||||
*/
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue