Browse Source

remove call to wgctrl.Device for freebsd

Matthew R. Kasun 3 years ago
parent
commit
a529b28a00
2 changed files with 14 additions and 9 deletions
  1. 1 1
      netclient/local/routes.go
  2. 13 8
      netclient/wireguard/common.go

+ 1 - 1
netclient/local/routes.go

@@ -50,7 +50,7 @@ func SetPeerRoutes(iface, currentNodeAddr string, oldPeers map[string][]net.IPNe
 }
 
 // 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 _, allowedIP := range peer.AllowedIPs {
 			setRoute(iface, &allowedIP, currentAddr)

+ 13 - 8
netclient/wireguard/common.go

@@ -172,8 +172,7 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
 		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
 	output, _ := ncutils.RunCmd("wg", false)
 	starttime := time.Now()
@@ -184,23 +183,29 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
 		time.Sleep(time.Second)
 		ifaceReady = strings.Contains(output, ifacename)
 	}
-	newDevice, devErr := wgclient.Device(deviceiface)
-	if !ifaceReady || devErr != nil {
-		return fmt.Errorf("could not reliably create interface, please check wg installation and retry")
+	//wgclient does not work well on freebsd
+	if node.OS == "freebsd" {
+		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)
-
 	if syncconf { // should never be called really.
 		err = SyncWGQuickConf(ifacename, confPath)
 	}
-	currentPeers := newDevice.Peers
+
 	_, cidr, cidrErr := net.ParseCIDR(modcfg.NetworkSettings.AddressRange)
 	if cidrErr == nil {
 		local.SetCIDRRoute(ifacename, node.Address, cidr)
 	} else {
 		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
 }