mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 09:22:42 +08:00
remove call to wgctrl.Device for freebsd
This commit is contained in:
@@ -50,7 +50,7 @@ func SetPeerRoutes(iface, currentNodeAddr string, oldPeers map[string][]net.IPNe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetCurrentPeerRoutes - sets all the current peers
|
// SetCurrentPeerRoutes - sets all the current peers
|
||||||
func SetCurrentPeerRoutes(iface, currentAddr string, peers []wgtypes.Peer) {
|
func SetCurrentPeerRoutes(iface, currentAddr string, peers []wgtypes.PeerConfig) {
|
||||||
for _, peer := range peers {
|
for _, peer := range peers {
|
||||||
for _, allowedIP := range peer.AllowedIPs {
|
for _, allowedIP := range peer.AllowedIPs {
|
||||||
setRoute(iface, &allowedIP, currentAddr)
|
setRoute(iface, &allowedIP, currentAddr)
|
||||||
|
@@ -172,8 +172,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||||||
d, _ = wgclient.Device(deviceiface)
|
d, _ = wgclient.Device(deviceiface)
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
||||||
@@ -184,23 +183,29 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
ifaceReady = strings.Contains(output, ifacename)
|
ifaceReady = strings.Contains(output, ifacename)
|
||||||
}
|
}
|
||||||
newDevice, devErr := wgclient.Device(deviceiface)
|
//wgclient does not work well on freebsd
|
||||||
if !ifaceReady || devErr != nil {
|
if node.OS == "freebsd" {
|
||||||
return fmt.Errorf("could not reliably create interface, please check wg installation and retry")
|
if !ifaceReady {
|
||||||
|
return fmt.Errorf("could not reliably create interface, please check wg installation and retry")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_, devErr := wgclient.Device(deviceiface)
|
||||||
|
if !ifaceReady || devErr != nil {
|
||||||
|
return fmt.Errorf("could not reliably create interface, please check wg installation and retry")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ncutils.PrintLog("interface ready - netclient engage", 1)
|
ncutils.PrintLog("interface ready - netclient engage", 1)
|
||||||
|
|
||||||
if syncconf { // should never be called really.
|
if syncconf { // should never be called really.
|
||||||
err = SyncWGQuickConf(ifacename, confPath)
|
err = SyncWGQuickConf(ifacename, confPath)
|
||||||
}
|
}
|
||||||
currentPeers := newDevice.Peers
|
|
||||||
_, cidr, cidrErr := net.ParseCIDR(modcfg.NetworkSettings.AddressRange)
|
_, cidr, cidrErr := net.ParseCIDR(modcfg.NetworkSettings.AddressRange)
|
||||||
if cidrErr == nil {
|
if cidrErr == nil {
|
||||||
local.SetCIDRRoute(ifacename, node.Address, cidr)
|
local.SetCIDRRoute(ifacename, node.Address, cidr)
|
||||||
} else {
|
} else {
|
||||||
ncutils.PrintLog("could not set cidr route properly: "+cidrErr.Error(), 1)
|
ncutils.PrintLog("could not set cidr route properly: "+cidrErr.Error(), 1)
|
||||||
}
|
}
|
||||||
local.SetCurrentPeerRoutes(ifacename, node.Address, currentPeers[:])
|
local.SetCurrentPeerRoutes(ifacename, node.Address, peers)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user