|
@@ -63,7 +63,7 @@ func SetPeers(iface, currentNodeAddr string, keepalive int32, peers []wgtypes.Pe
|
|
if !found {
|
|
if !found {
|
|
_, err := ncutils.RunCmd("wg set "+iface+" peer "+currentPeer.PublicKey.String()+" remove", true)
|
|
_, err := ncutils.RunCmd("wg set "+iface+" peer "+currentPeer.PublicKey.String()+" remove", true)
|
|
if err != nil {
|
|
if err != nil {
|
|
- log.Println("error removing peer", currentPeer.Endpoint.String())
|
|
|
|
|
|
+ ncutils.PrintLog("error removing peer: "+currentPeer.Endpoint.String(), 1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -116,7 +116,7 @@ func SetPeers(iface, currentNodeAddr string, keepalive int32, peers []wgtypes.Pe
|
|
" allowed-ips "+allowedips, true)
|
|
" allowed-ips "+allowedips, true)
|
|
}
|
|
}
|
|
if err != nil {
|
|
if err != nil {
|
|
- log.Println("error setting peer", peer.PublicKey.String())
|
|
|
|
|
|
+ ncutils.PrintLog("error setting peer: "+peer.PublicKey.String(), 1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -153,17 +153,16 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Fatalf("failed to open client: %v", err)
|
|
log.Fatalf("failed to open client: %v", err)
|
|
}
|
|
}
|
|
- log.Println("-2")
|
|
|
|
var ifacename string
|
|
var ifacename string
|
|
if nodecfg.Interface != "" {
|
|
if nodecfg.Interface != "" {
|
|
ifacename = nodecfg.Interface
|
|
ifacename = nodecfg.Interface
|
|
} else if node.Interface != "" {
|
|
} else if node.Interface != "" {
|
|
ifacename = node.Interface
|
|
ifacename = node.Interface
|
|
} else {
|
|
} else {
|
|
- log.Fatal("no interface to configure")
|
|
|
|
|
|
+ return fmt.Errorf("no interface to configure")
|
|
}
|
|
}
|
|
if node.Address == "" {
|
|
if node.Address == "" {
|
|
- log.Fatal("no address to configure")
|
|
|
|
|
|
+ return fmt.Errorf("no address to configure")
|
|
}
|
|
}
|
|
if node.UDPHolePunch == "yes" {
|
|
if node.UDPHolePunch == "yes" {
|
|
node.ListenPort = 0
|
|
node.ListenPort = 0
|
|
@@ -172,7 +171,6 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|
ncutils.PrintLog("error writing wg conf file: "+err.Error(), 1)
|
|
ncutils.PrintLog("error writing wg conf file: "+err.Error(), 1)
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- log.Println("-1")
|
|
|
|
// 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
|
|
@@ -182,12 +180,9 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|
deviceiface = ifacename
|
|
deviceiface = ifacename
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- log.Println("0")
|
|
|
|
// ensure you clear any existing interface first
|
|
// ensure you clear any existing interface first
|
|
d, _ := wgclient.Device(deviceiface)
|
|
d, _ := wgclient.Device(deviceiface)
|
|
for d != nil && d.Name == deviceiface {
|
|
for d != nil && d.Name == deviceiface {
|
|
- log.Println("d==", d.Name)
|
|
|
|
- log.Println("deviceiface==", deviceiface)
|
|
|
|
err = RemoveConf(deviceiface, false) // remove interface first
|
|
err = RemoveConf(deviceiface, false) // remove interface first
|
|
if strings.Contains(err.Error(), "does not exist") {
|
|
if strings.Contains(err.Error(), "does not exist") {
|
|
err = nil
|
|
err = nil
|
|
@@ -196,14 +191,12 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|
time.Sleep(time.Second >> 2)
|
|
time.Sleep(time.Second >> 2)
|
|
d, _ = wgclient.Device(deviceiface)
|
|
d, _ = wgclient.Device(deviceiface)
|
|
}
|
|
}
|
|
- log.Println("1")
|
|
|
|
ApplyConf(node, deviceiface, confPath) // Apply initially
|
|
ApplyConf(node, deviceiface, confPath) // Apply initially
|
|
ncutils.PrintLog("waiting for interface...", 1) // ensure interface is created
|
|
ncutils.PrintLog("waiting for interface...", 1) // ensure interface is created
|
|
output, _ := ncutils.RunCmd("wg", false)
|
|
output, _ := ncutils.RunCmd("wg", false)
|
|
starttime := time.Now()
|
|
starttime := time.Now()
|
|
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))) {
|
|
- log.Println("2")
|
|
|
|
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.Address)
|
|
deviceiface, err = local.GetMacIface(node.Address)
|
|
if err != nil || deviceiface == "" {
|
|
if err != nil || deviceiface == "" {
|
|
@@ -215,7 +208,6 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|
time.Sleep(time.Second)
|
|
time.Sleep(time.Second)
|
|
ifaceReady = strings.Contains(output, deviceiface)
|
|
ifaceReady = strings.Contains(output, deviceiface)
|
|
}
|
|
}
|
|
- log.Println("3")
|
|
|
|
//wgclient does not work well on freebsd
|
|
//wgclient does not work well on freebsd
|
|
if node.OS == "freebsd" {
|
|
if node.OS == "freebsd" {
|
|
if !ifaceReady {
|
|
if !ifaceReady {
|