From a529b28a00fc7536ecbd3941c2bcb406803f6fd4 Mon Sep 17 00:00:00 2001 From: "Matthew R. Kasun" Date: Mon, 7 Feb 2022 05:45:24 -0500 Subject: [PATCH] remove call to wgctrl.Device for freebsd --- netclient/local/routes.go | 2 +- netclient/wireguard/common.go | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/netclient/local/routes.go b/netclient/local/routes.go index 0dab135a..2957ecf3 100644 --- a/netclient/local/routes.go +++ b/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) diff --git a/netclient/wireguard/common.go b/netclient/wireguard/common.go index 4defd201..c72f8772 100644 --- a/netclient/wireguard/common.go +++ b/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 }