mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-25 13:37:00 +08:00
sync logic working
This commit is contained in:
parent
eb770163f8
commit
56ee112d1b
3 changed files with 11 additions and 22 deletions
|
|
@ -234,7 +234,7 @@ func Pull(network string, manual bool) (*models.Node, error) {
|
|||
}
|
||||
} else {
|
||||
if err = wireguard.SetWGConfig(network, true); err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
if errors.Is(err, os.ErrNotExist) && !ncutils.IsFreeBSD() {
|
||||
return Pull(network, true)
|
||||
} else {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||
}
|
||||
}
|
||||
if syncconf {
|
||||
err = wgclient.ConfigureDevice(deviceiface, conf)
|
||||
err = SyncWGQuickConf(ifacename, confPath)
|
||||
} else {
|
||||
d, _ := wgclient.Device(deviceiface)
|
||||
for d != nil && d.Name == deviceiface {
|
||||
|
|
@ -335,18 +335,3 @@ func ApplyConf(confPath string) error {
|
|||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// ApplyConf - applys a conf on disk to WireGuard interface
|
||||
func SyncConf(confPath string) error {
|
||||
os := runtime.GOOS
|
||||
var err error
|
||||
switch os {
|
||||
/*
|
||||
case "windows":
|
||||
_ = SyncWindowsConf(confPath)
|
||||
*/
|
||||
default:
|
||||
err = SyncWGQuickConf(confPath)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package wireguard
|
|||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"github.com/gravitl/netmaker/models"
|
||||
"github.com/gravitl/netmaker/netclient/config"
|
||||
|
|
@ -56,19 +58,22 @@ func ApplyWGQuickConf(confPath string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// ApplyWGQuickConf - applies wg-quick commands if os supports
|
||||
func SyncWGQuickConf(confPath string) error {
|
||||
// SyncWGQuickConf - formats config file and runs sync command
|
||||
func SyncWGQuickConf(iface string, confPath string) error {
|
||||
var tmpConf = confPath + ".sync.tmp"
|
||||
conf, err := ncutils.RunCmd("wg-quick strip "+confPath, false)
|
||||
confRaw, err := ncutils.RunCmd("wg-quick strip "+confPath, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
regex := regexp.MustCompile(".*Warning.*\n")
|
||||
conf := regex.ReplaceAllString(confRaw, "")
|
||||
err = ioutil.WriteFile(tmpConf, []byte(conf), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = ncutils.RunCmd("wg sync "+confPath, false)
|
||||
_, err = ncutils.RunCmd("wg syncconf "+iface+" "+tmpConf, true)
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
ncutils.Log("error syncing conf, resetting")
|
||||
err = ApplyWGQuickConf(confPath)
|
||||
}
|
||||
|
|
@ -76,7 +81,6 @@ func SyncWGQuickConf(confPath string) error {
|
|||
if errN != nil {
|
||||
ncutils.Log(errN.Error())
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue