common.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. package wireguard
  2. import (
  3. "fmt"
  4. "net"
  5. "runtime"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "github.com/gravitl/netmaker/logger"
  10. "github.com/gravitl/netmaker/models"
  11. "github.com/gravitl/netmaker/netclient/config"
  12. "github.com/gravitl/netmaker/netclient/local"
  13. "github.com/gravitl/netmaker/netclient/ncutils"
  14. "golang.zx2c4.com/wireguard/wgctrl"
  15. "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
  16. "gopkg.in/ini.v1"
  17. )
  18. const (
  19. section_interface = "Interface"
  20. section_peers = "Peer"
  21. )
  22. // SetPeers - sets peers on a given WireGuard interface
  23. func SetPeers(iface string, node *models.Node, peers []wgtypes.PeerConfig) error {
  24. var devicePeers []wgtypes.Peer
  25. var keepalive = node.PersistentKeepalive
  26. var oldPeerAllowedIps = make(map[string]bool, len(peers))
  27. var err error
  28. devicePeers, err = GetDevicePeers(iface)
  29. if err != nil {
  30. return err
  31. }
  32. if len(devicePeers) > 1 && len(peers) == 0 {
  33. logger.Log(1, "no peers pulled")
  34. return err
  35. }
  36. for _, peer := range peers {
  37. // make sure peer has AllowedIP's before comparison
  38. hasPeerIP := len(peer.AllowedIPs) > 0
  39. for _, currentPeer := range devicePeers {
  40. // make sure currenPeer has AllowedIP's before comparison
  41. hascurrentPeerIP := len(currentPeer.AllowedIPs) > 0
  42. if hasPeerIP && hascurrentPeerIP &&
  43. currentPeer.AllowedIPs[0].String() == peer.AllowedIPs[0].String() &&
  44. currentPeer.PublicKey.String() != peer.PublicKey.String() {
  45. _, err := ncutils.RunCmd("wg set "+iface+" peer "+currentPeer.PublicKey.String()+" remove", true)
  46. if err != nil {
  47. logger.Log(0, "error removing peer", peer.Endpoint.String())
  48. }
  49. }
  50. }
  51. udpendpoint := peer.Endpoint.String()
  52. var allowedips string
  53. var iparr []string
  54. for _, ipaddr := range peer.AllowedIPs {
  55. if hasPeerIP {
  56. iparr = append(iparr, ipaddr.String())
  57. }
  58. }
  59. if len(iparr) > 0 {
  60. allowedips = strings.Join(iparr, ",")
  61. }
  62. keepAliveString := strconv.Itoa(int(keepalive))
  63. if keepAliveString == "0" {
  64. keepAliveString = "15"
  65. }
  66. if node.IsServer == "yes" || peer.Endpoint == nil {
  67. _, err = ncutils.RunCmd("wg set "+iface+" peer "+peer.PublicKey.String()+
  68. " persistent-keepalive "+keepAliveString+
  69. " allowed-ips "+allowedips, true)
  70. } else {
  71. _, err = ncutils.RunCmd("wg set "+iface+" peer "+peer.PublicKey.String()+
  72. " endpoint "+udpendpoint+
  73. " persistent-keepalive "+keepAliveString+
  74. " allowed-ips "+allowedips, true)
  75. }
  76. if err != nil {
  77. logger.Log(0, "error setting peer", peer.PublicKey.String())
  78. }
  79. }
  80. if len(devicePeers) > 0 {
  81. for _, currentPeer := range devicePeers {
  82. shouldDelete := true
  83. if len(peers) > 0 {
  84. for _, peer := range peers {
  85. if len(peer.AllowedIPs) > 0 && len(currentPeer.AllowedIPs) > 0 &&
  86. peer.AllowedIPs[0].String() == currentPeer.AllowedIPs[0].String() {
  87. shouldDelete = false
  88. }
  89. // re-check this if logic is not working, added in case of allowedips not working
  90. if peer.PublicKey.String() == currentPeer.PublicKey.String() {
  91. shouldDelete = false
  92. }
  93. }
  94. if shouldDelete {
  95. output, err := ncutils.RunCmd("wg set "+iface+" peer "+currentPeer.PublicKey.String()+" remove", true)
  96. if err != nil {
  97. logger.Log(0, output, "error removing peer", currentPeer.PublicKey.String())
  98. }
  99. }
  100. for _, ip := range currentPeer.AllowedIPs {
  101. oldPeerAllowedIps[ip.String()] = true
  102. }
  103. }
  104. }
  105. }
  106. // if routes are wrong, come back to this, but should work...I would think. Or we should get it working.
  107. if len(peers) > 0 {
  108. local.SetPeerRoutes(iface, oldPeerAllowedIps, peers)
  109. }
  110. return nil
  111. }
  112. // Initializes a WireGuard interface
  113. func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig) error {
  114. key, err := wgtypes.ParseKey(privkey)
  115. if err != nil {
  116. return err
  117. }
  118. wgclient, err := wgctrl.New()
  119. if err != nil {
  120. return err
  121. }
  122. defer wgclient.Close()
  123. //nodecfg := modcfg.Node
  124. var ifacename string
  125. if node.Interface != "" {
  126. ifacename = node.Interface
  127. } else {
  128. return fmt.Errorf("no interface to configure")
  129. }
  130. if node.PrimaryAddress() == "" {
  131. return fmt.Errorf("no address to configure")
  132. }
  133. if err := WriteWgConfig(node, key.String(), peers); err != nil {
  134. logger.Log(1, "error writing wg conf file: ", err.Error())
  135. return err
  136. }
  137. // spin up userspace / windows interface + apply the conf file
  138. confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
  139. var deviceiface = ifacename
  140. var mErr error
  141. if ncutils.IsMac() { // if node is Mac (Darwin) get the tunnel name first
  142. deviceiface, mErr = local.GetMacIface(node.PrimaryAddress())
  143. if mErr != nil || deviceiface == "" {
  144. deviceiface = ifacename
  145. }
  146. }
  147. // ensure you clear any existing interface first
  148. RemoveConfGraceful(deviceiface)
  149. ApplyConf(node, ifacename, confPath) // Apply initially
  150. logger.Log(1, "waiting for interface...") // ensure interface is created
  151. output, _ := ncutils.RunCmd("wg", false)
  152. starttime := time.Now()
  153. ifaceReady := strings.Contains(output, deviceiface)
  154. for !ifaceReady && !(time.Now().After(starttime.Add(time.Second << 4))) {
  155. if ncutils.IsMac() { // if node is Mac (Darwin) get the tunnel name first
  156. deviceiface, mErr = local.GetMacIface(node.PrimaryAddress())
  157. if mErr != nil || deviceiface == "" {
  158. deviceiface = ifacename
  159. }
  160. }
  161. output, _ = ncutils.RunCmd("wg", false)
  162. err = ApplyConf(node, node.Interface, confPath)
  163. time.Sleep(time.Second)
  164. ifaceReady = strings.Contains(output, deviceiface)
  165. }
  166. //wgclient does not work well on freebsd
  167. if node.OS == "freebsd" {
  168. if !ifaceReady {
  169. return fmt.Errorf("could not reliably create interface, please check wg installation and retry")
  170. }
  171. } else {
  172. _, devErr := wgclient.Device(deviceiface)
  173. if !ifaceReady || devErr != nil {
  174. fmt.Printf("%v\n", devErr)
  175. return fmt.Errorf("could not reliably create interface, please check wg installation and retry")
  176. }
  177. }
  178. logger.Log(1, "interface ready - netclient.. ENGAGE")
  179. if !ncutils.HasWgQuick() && ncutils.IsLinux() {
  180. err = SetPeers(ifacename, node, peers)
  181. if err != nil {
  182. logger.Log(1, "error setting peers: ", err.Error())
  183. }
  184. time.Sleep(time.Second)
  185. }
  186. //ipv4
  187. if node.Address != "" {
  188. _, cidr, cidrErr := net.ParseCIDR(node.NetworkSettings.AddressRange)
  189. if cidrErr == nil {
  190. local.SetCIDRRoute(ifacename, node.Address, cidr)
  191. } else {
  192. logger.Log(1, "could not set cidr route properly: ", cidrErr.Error())
  193. }
  194. local.SetCurrentPeerRoutes(ifacename, node.Address, peers)
  195. }
  196. if node.Address6 != "" {
  197. //ipv6
  198. _, cidr, cidrErr := net.ParseCIDR(node.NetworkSettings.AddressRange6)
  199. if cidrErr == nil {
  200. local.SetCIDRRoute(ifacename, node.Address6, cidr)
  201. } else {
  202. logger.Log(1, "could not set cidr route properly: ", cidrErr.Error())
  203. }
  204. local.SetCurrentPeerRoutes(ifacename, node.Address6, peers)
  205. }
  206. return err
  207. }
  208. // SetWGConfig - sets the WireGuard Config of a given network and checks if it needs a peer update
  209. func SetWGConfig(network string, peerupdate bool, peers []wgtypes.PeerConfig) error {
  210. cfg, err := config.ReadConfig(network)
  211. if err != nil {
  212. return err
  213. }
  214. privkey, err := RetrievePrivKey(network)
  215. if err != nil {
  216. return err
  217. }
  218. if peerupdate && !ncutils.IsFreeBSD() && !(ncutils.IsLinux() && !ncutils.IsKernel()) {
  219. var iface string
  220. iface = cfg.Node.Interface
  221. if ncutils.IsMac() {
  222. iface, err = local.GetMacIface(cfg.Node.PrimaryAddress())
  223. if err != nil {
  224. return err
  225. }
  226. }
  227. err = SetPeers(iface, &cfg.Node, peers)
  228. } else {
  229. err = InitWireguard(&cfg.Node, privkey, peers)
  230. }
  231. return err
  232. }
  233. // RemoveConf - removes a configuration for a given WireGuard interface
  234. func RemoveConf(iface string, printlog bool) error {
  235. os := runtime.GOOS
  236. if ncutils.IsLinux() && !ncutils.HasWgQuick() {
  237. os = "nowgquick"
  238. }
  239. var err error
  240. switch os {
  241. case "nowgquick":
  242. err = RemoveWithoutWGQuick(iface)
  243. case "windows":
  244. err = RemoveWindowsConf(iface, printlog)
  245. default:
  246. confPath := ncutils.GetNetclientPathSpecific() + iface + ".conf"
  247. err = RemoveWGQuickConf(confPath, printlog)
  248. }
  249. return err
  250. }
  251. // ApplyConf - applys a conf on disk to WireGuard interface
  252. func ApplyConf(node *models.Node, ifacename string, confPath string) error {
  253. os := runtime.GOOS
  254. if ncutils.IsLinux() && !ncutils.HasWgQuick() {
  255. os = "nowgquick"
  256. }
  257. var isConnected = node.Connected != "no"
  258. var err error
  259. switch os {
  260. case "windows":
  261. ApplyWindowsConf(confPath, ifacename, isConnected)
  262. case "nowgquick":
  263. ApplyWithoutWGQuick(node, ifacename, confPath, isConnected)
  264. default:
  265. ApplyWGQuickConf(confPath, ifacename, isConnected)
  266. }
  267. var nodeCfg config.ClientConfig
  268. nodeCfg.Network = node.Network
  269. if !(node.IsServer == "yes") {
  270. nodeCfg.ReadConfig()
  271. if nodeCfg.NetworkSettings.AddressRange != "" {
  272. ip, cidr, err := net.ParseCIDR(nodeCfg.NetworkSettings.AddressRange)
  273. if err == nil {
  274. local.SetCIDRRoute(node.Interface, ip.String(), cidr)
  275. }
  276. }
  277. if nodeCfg.NetworkSettings.AddressRange6 != "" {
  278. ip, cidr, err := net.ParseCIDR(nodeCfg.NetworkSettings.AddressRange6)
  279. if err == nil {
  280. local.SetCIDRRoute(node.Interface, ip.String(), cidr)
  281. }
  282. }
  283. }
  284. return err
  285. }
  286. // WriteWgConfig - creates a wireguard config file
  287. func WriteWgConfig(node *models.Node, privateKey string, peers []wgtypes.PeerConfig) error {
  288. options := ini.LoadOptions{
  289. AllowNonUniqueSections: true,
  290. AllowShadows: true,
  291. }
  292. wireguard := ini.Empty(options)
  293. wireguard.Section(section_interface).Key("PrivateKey").SetValue(privateKey)
  294. if node.ListenPort > 0 && node.UDPHolePunch != "yes" {
  295. wireguard.Section(section_interface).Key("ListenPort").SetValue(strconv.Itoa(int(node.ListenPort)))
  296. }
  297. addrString := node.Address
  298. if node.Address6 != "" {
  299. if addrString != "" {
  300. addrString += ","
  301. }
  302. addrString += node.Address6
  303. }
  304. wireguard.Section(section_interface).Key("Address").SetValue(addrString)
  305. // need to figure out DNS
  306. //if node.DNSOn == "yes" {
  307. // wireguard.Section(section_interface).Key("DNS").SetValue(cfg.Server.CoreDNSAddr)
  308. //}
  309. //need to split postup/postdown because ini lib adds a ` and the ` breaks freebsd
  310. //works fine on others
  311. if node.PostUp != "" {
  312. if node.OS == "freebsd" {
  313. parts := strings.Split(node.PostUp, " ; ")
  314. for i, part := range parts {
  315. if i == 0 {
  316. wireguard.Section(section_interface).Key("PostUp").SetValue(part)
  317. }
  318. wireguard.Section(section_interface).Key("PostUp").AddShadow(part)
  319. }
  320. } else {
  321. wireguard.Section(section_interface).Key("PostUp").SetValue((node.PostUp))
  322. }
  323. }
  324. if node.PostDown != "" {
  325. if node.OS == "freebsd" {
  326. parts := strings.Split(node.PostDown, " ; ")
  327. for i, part := range parts {
  328. if i == 0 {
  329. wireguard.Section(section_interface).Key("PostDown").SetValue(part)
  330. }
  331. wireguard.Section(section_interface).Key("PostDown").AddShadow(part)
  332. }
  333. } else {
  334. wireguard.Section(section_interface).Key("PostDown").SetValue((node.PostDown))
  335. }
  336. }
  337. if node.MTU != 0 {
  338. wireguard.Section(section_interface).Key("MTU").SetValue(strconv.FormatInt(int64(node.MTU), 10))
  339. }
  340. for i, peer := range peers {
  341. wireguard.SectionWithIndex(section_peers, i).Key("PublicKey").SetValue(peer.PublicKey.String())
  342. if peer.PresharedKey != nil {
  343. wireguard.SectionWithIndex(section_peers, i).Key("PreSharedKey").SetValue(peer.PresharedKey.String())
  344. }
  345. if peer.AllowedIPs != nil {
  346. var allowedIPs string
  347. for i, ip := range peer.AllowedIPs {
  348. if i == 0 {
  349. allowedIPs = ip.String()
  350. } else {
  351. allowedIPs = allowedIPs + ", " + ip.String()
  352. }
  353. }
  354. wireguard.SectionWithIndex(section_peers, i).Key("AllowedIps").SetValue(allowedIPs)
  355. }
  356. if peer.Endpoint != nil {
  357. wireguard.SectionWithIndex(section_peers, i).Key("Endpoint").SetValue(peer.Endpoint.String())
  358. }
  359. if peer.PersistentKeepaliveInterval != nil && peer.PersistentKeepaliveInterval.Seconds() > 0 {
  360. wireguard.SectionWithIndex(section_peers, i).Key("PersistentKeepalive").SetValue(strconv.FormatInt((int64)(peer.PersistentKeepaliveInterval.Seconds()), 10))
  361. }
  362. }
  363. if err := wireguard.SaveTo(ncutils.GetNetclientPathSpecific() + node.Interface + ".conf"); err != nil {
  364. return err
  365. }
  366. return nil
  367. }
  368. // UpdateWgPeers - updates the peers of a network
  369. func UpdateWgPeers(file string, peers []wgtypes.PeerConfig) (*net.UDPAddr, error) {
  370. var internetGateway *net.UDPAddr
  371. options := ini.LoadOptions{
  372. AllowNonUniqueSections: true,
  373. AllowShadows: true,
  374. }
  375. wireguard, err := ini.LoadSources(options, file)
  376. if err != nil {
  377. return internetGateway, err
  378. }
  379. //delete the peers sections as they are going to be replaced
  380. wireguard.DeleteSection(section_peers)
  381. for i, peer := range peers {
  382. wireguard.SectionWithIndex(section_peers, i).Key("PublicKey").SetValue(peer.PublicKey.String())
  383. if peer.PresharedKey != nil {
  384. wireguard.SectionWithIndex(section_peers, i).Key("PreSharedKey").SetValue(peer.PresharedKey.String())
  385. }
  386. if peer.AllowedIPs != nil {
  387. var allowedIPs string
  388. for i, ip := range peer.AllowedIPs {
  389. if i == 0 {
  390. allowedIPs = ip.String()
  391. } else {
  392. allowedIPs = allowedIPs + ", " + ip.String()
  393. }
  394. }
  395. wireguard.SectionWithIndex(section_peers, i).Key("AllowedIps").SetValue(allowedIPs)
  396. if strings.Contains(allowedIPs, "0.0.0.0/0") || strings.Contains(allowedIPs, "::/0") {
  397. internetGateway = peer.Endpoint
  398. }
  399. }
  400. if peer.Endpoint != nil {
  401. wireguard.SectionWithIndex(section_peers, i).Key("Endpoint").SetValue(peer.Endpoint.String())
  402. }
  403. if peer.PersistentKeepaliveInterval != nil && peer.PersistentKeepaliveInterval.Seconds() > 0 {
  404. wireguard.SectionWithIndex(section_peers, i).Key("PersistentKeepalive").SetValue(strconv.FormatInt((int64)(peer.PersistentKeepaliveInterval.Seconds()), 10))
  405. }
  406. }
  407. if err := wireguard.SaveTo(file); err != nil {
  408. return internetGateway, err
  409. }
  410. return internetGateway, nil
  411. }
  412. // UpdateWgInterface - updates the interface section of a wireguard config file
  413. func UpdateWgInterface(file, privateKey, nameserver string, node models.Node) error {
  414. options := ini.LoadOptions{
  415. AllowNonUniqueSections: true,
  416. AllowShadows: true,
  417. }
  418. wireguard, err := ini.LoadSources(options, file)
  419. if err != nil {
  420. return err
  421. }
  422. if node.UDPHolePunch == "yes" {
  423. node.ListenPort = 0
  424. }
  425. wireguard.DeleteSection(section_interface)
  426. wireguard.Section(section_interface).Key("PrivateKey").SetValue(privateKey)
  427. wireguard.Section(section_interface).Key("ListenPort").SetValue(strconv.Itoa(int(node.ListenPort)))
  428. addrString := node.Address
  429. if node.Address6 != "" {
  430. if addrString != "" {
  431. addrString += ","
  432. }
  433. addrString += node.Address6
  434. }
  435. wireguard.Section(section_interface).Key("Address").SetValue(addrString)
  436. //if node.DNSOn == "yes" {
  437. // wireguard.Section(section_interface).Key("DNS").SetValue(nameserver)
  438. //}
  439. //need to split postup/postdown because ini lib adds a quotes which breaks freebsd
  440. if node.PostUp != "" {
  441. if node.OS == "freebsd" {
  442. parts := strings.Split(node.PostUp, " ; ")
  443. for i, part := range parts {
  444. if i == 0 {
  445. wireguard.Section(section_interface).Key("PostUp").SetValue(part)
  446. }
  447. wireguard.Section(section_interface).Key("PostUp").AddShadow(part)
  448. }
  449. } else {
  450. wireguard.Section(section_interface).Key("PostUp").SetValue(node.PostUp)
  451. }
  452. }
  453. if node.PostDown != "" {
  454. if node.OS == "freebsd" {
  455. parts := strings.Split(node.PostDown, " ; ")
  456. for i, part := range parts {
  457. if i == 0 {
  458. wireguard.Section(section_interface).Key("PostDown").SetValue(part)
  459. }
  460. wireguard.Section(section_interface).Key("PostDown").AddShadow(part)
  461. }
  462. } else {
  463. wireguard.Section(section_interface).Key("PostDown").SetValue(node.PostDown)
  464. }
  465. }
  466. if node.MTU != 0 {
  467. wireguard.Section(section_interface).Key("MTU").SetValue(strconv.FormatInt(int64(node.MTU), 10))
  468. }
  469. if err := wireguard.SaveTo(file); err != nil {
  470. return err
  471. }
  472. return nil
  473. }
  474. // UpdatePrivateKey - updates the private key of a wireguard config file
  475. func UpdatePrivateKey(file, privateKey string) error {
  476. options := ini.LoadOptions{
  477. AllowNonUniqueSections: true,
  478. AllowShadows: true,
  479. }
  480. wireguard, err := ini.LoadSources(options, file)
  481. if err != nil {
  482. return err
  483. }
  484. wireguard.Section(section_interface).Key("PrivateKey").SetValue(privateKey)
  485. if err := wireguard.SaveTo(file); err != nil {
  486. return err
  487. }
  488. return nil
  489. }
  490. // UpdateKeepAlive - updates the persistentkeepalive of all peers
  491. func UpdateKeepAlive(file string, keepalive int32) error {
  492. options := ini.LoadOptions{
  493. AllowNonUniqueSections: true,
  494. AllowShadows: true,
  495. }
  496. wireguard, err := ini.LoadSources(options, file)
  497. if err != nil {
  498. return err
  499. }
  500. peers, err := wireguard.SectionsByName(section_peers)
  501. if err != nil {
  502. return err
  503. }
  504. newvalue := strconv.Itoa(int(keepalive))
  505. for i := range peers {
  506. wireguard.SectionWithIndex(section_peers, i).Key("PersistentKeepALive").SetValue(newvalue)
  507. }
  508. if err := wireguard.SaveTo(file); err != nil {
  509. return err
  510. }
  511. return nil
  512. }
  513. // RemoveConfGraceful - Run remove conf and wait for it to actually be gone before proceeding
  514. func RemoveConfGraceful(ifacename string) {
  515. // ensure you clear any existing interface first
  516. wgclient, err := wgctrl.New()
  517. if err != nil {
  518. logger.Log(0, "could not create wgclient")
  519. return
  520. }
  521. defer wgclient.Close()
  522. d, _ := wgclient.Device(ifacename)
  523. startTime := time.Now()
  524. for d != nil && d.Name == ifacename {
  525. if err = RemoveConf(ifacename, false); err != nil { // remove interface first
  526. if strings.Contains(err.Error(), "does not exist") {
  527. err = nil
  528. break
  529. }
  530. }
  531. time.Sleep(time.Second >> 2)
  532. d, _ = wgclient.Device(ifacename)
  533. if time.Now().After(startTime.Add(time.Second << 4)) {
  534. break
  535. }
  536. }
  537. time.Sleep(time.Second << 1)
  538. }
  539. // GetDevicePeers - gets the current device's peers
  540. func GetDevicePeers(iface string) ([]wgtypes.Peer, error) {
  541. if ncutils.IsFreeBSD() {
  542. if devicePeers, err := ncutils.GetPeers(iface); err != nil {
  543. return nil, err
  544. } else {
  545. return devicePeers, nil
  546. }
  547. } else {
  548. client, err := wgctrl.New()
  549. if err != nil {
  550. logger.Log(0, "failed to start wgctrl")
  551. return nil, err
  552. }
  553. defer client.Close()
  554. device, err := client.Device(iface)
  555. if err != nil {
  556. logger.Log(0, "failed to parse interface", iface)
  557. return nil, err
  558. }
  559. return device.Peers, nil
  560. }
  561. }