mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 16:57:51 +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:
@@ -5,7 +5,6 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -56,7 +55,7 @@ func RegisterWithServer(private *ed25519.PrivateKey, cfg *config.ClientConfig) e
|
|||||||
CommonName: tls.NewCName(cfg.Node.Name),
|
CommonName: tls.NewCName(cfg.Node.Name),
|
||||||
}
|
}
|
||||||
url := "https://" + cfg.Server.API + "/api/server/register"
|
url := "https://" + cfg.Server.API + "/api/server/register"
|
||||||
log.Println("register at ", url)
|
logger.Log(1, "register at "+url)
|
||||||
|
|
||||||
token, err := Authenticate(cfg)
|
token, err := Authenticate(cfg)
|
||||||
if err != nil {
|
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
|
// spin up userspace / windows interface + apply the conf file
|
||||||
confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
|
confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
|
||||||
var deviceiface = ifacename
|
var deviceiface = ifacename
|
||||||
|
var mErr error
|
||||||
if ncutils.IsMac() { // if node is Mac (Darwin) get the tunnel name first
|
if ncutils.IsMac() { // if node is Mac (Darwin) get the tunnel name first
|
||||||
deviceiface, err = local.GetMacIface(node.PrimaryAddress())
|
deviceiface, mErr = local.GetMacIface(node.PrimaryAddress())
|
||||||
if err != nil || deviceiface == "" {
|
if mErr != nil || deviceiface == "" {
|
||||||
deviceiface = ifacename
|
deviceiface = ifacename
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,8 +163,8 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||||||
ifaceReady := strings.Contains(output, deviceiface)
|
ifaceReady := strings.Contains(output, deviceiface)
|
||||||
for !ifaceReady && !(time.Now().After(starttime.Add(time.Second << 4))) {
|
for !ifaceReady && !(time.Now().After(starttime.Add(time.Second << 4))) {
|
||||||
if ncutils.IsMac() { // if node is Mac (Darwin) get the tunnel name first
|
if ncutils.IsMac() { // if node is Mac (Darwin) get the tunnel name first
|
||||||
deviceiface, err = local.GetMacIface(node.PrimaryAddress())
|
deviceiface, mErr = local.GetMacIface(node.PrimaryAddress())
|
||||||
if err != nil || deviceiface == "" {
|
if mErr != nil || deviceiface == "" {
|
||||||
deviceiface = ifacename
|
deviceiface = ifacename
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,6 +195,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Log(1, "error setting peers: ", err.Error())
|
logger.Log(1, "error setting peers: ", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,9 +217,9 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||||||
} else {
|
} else {
|
||||||
logger.Log(1, "could not set cidr route properly: ", cidrErr.Error())
|
logger.Log(1, "could not set cidr route properly: ", cidrErr.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
local.SetCurrentPeerRoutes(ifacename, node.Address6, peers)
|
local.SetCurrentPeerRoutes(ifacename, node.Address6, peers)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,10 +300,18 @@ func ApplyConf(node *models.Node, ifacename string, confPath string) error {
|
|||||||
var nodeCfg config.ClientConfig
|
var nodeCfg config.ClientConfig
|
||||||
nodeCfg.Network = node.Network
|
nodeCfg.Network = node.Network
|
||||||
nodeCfg.ReadConfig()
|
nodeCfg.ReadConfig()
|
||||||
|
if nodeCfg.NetworkSettings.AddressRange != "" {
|
||||||
ip, cidr, err := net.ParseCIDR(nodeCfg.NetworkSettings.AddressRange)
|
ip, cidr, err := net.ParseCIDR(nodeCfg.NetworkSettings.AddressRange)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
local.SetCIDRRoute(node.Interface, ip.String(), cidr)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -9,16 +9,6 @@ import (
|
|||||||
|
|
||||||
// ApplyWindowsConf - applies the WireGuard configuration file on Windows
|
// ApplyWindowsConf - applies the WireGuard configuration file on Windows
|
||||||
func ApplyWindowsConf(confPath string) error {
|
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)
|
var commandLine = fmt.Sprintf(`wireguard.exe /installtunnelservice "%s"`, confPath)
|
||||||
if _, err := ncutils.RunCmdFormatted(commandLine, false); err != nil {
|
if _, err := ncutils.RunCmdFormatted(commandLine, false); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -31,22 +21,5 @@ func RemoveWindowsConf(ifacename string, printlog bool) error {
|
|||||||
if _, err := ncutils.RunCmd("wireguard.exe /uninstalltunnelservice "+ifacename, printlog); err != nil {
|
if _, err := ncutils.RunCmd("wireguard.exe /uninstalltunnelservice "+ifacename, printlog); err != nil {
|
||||||
logger.Log(1, err.Error())
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user