common.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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 ncutils.IsMac() {
  107. err = SetMacPeerRoutes(iface)
  108. return err
  109. } else if ncutils.IsLinux() {
  110. if len(peers) > 0 {
  111. local.SetPeerRoutes(iface, oldPeerAllowedIps, peers)
  112. }
  113. }
  114. return nil
  115. }
  116. // Initializes a WireGuard interface
  117. func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig) error {
  118. key, err := wgtypes.ParseKey(privkey)
  119. if err != nil {
  120. return err
  121. }
  122. wgclient, err := wgctrl.New()
  123. if err != nil {
  124. return err
  125. }
  126. defer wgclient.Close()
  127. //nodecfg := modcfg.Node
  128. var ifacename string
  129. if node.Interface != "" {
  130. ifacename = node.Interface
  131. } else {
  132. return fmt.Errorf("no interface to configure")
  133. }
  134. if node.PrimaryAddress() == "" {
  135. return fmt.Errorf("no address to configure")
  136. }
  137. if err := WriteWgConfig(node, key.String(), peers); err != nil {
  138. logger.Log(1, "error writing wg conf file: ", err.Error())
  139. return err
  140. }
  141. // spin up userspace / windows interface + apply the conf file
  142. confPath := ncutils.GetNetclientPathSpecific() + ifacename + ".conf"
  143. var deviceiface = ifacename
  144. var mErr error
  145. if ncutils.IsMac() { // if node is Mac (Darwin) get the tunnel name first
  146. deviceiface, mErr = local.GetMacIface(node.PrimaryAddress())
  147. if mErr != nil || deviceiface == "" {
  148. deviceiface = ifacename
  149. }
  150. }
  151. // ensure you clear any existing interface first
  152. RemoveConfGraceful(deviceiface)
  153. ApplyConf(node, ifacename, confPath) // Apply initially
  154. logger.Log(1, "waiting for interface...") // ensure interface is created
  155. output, _ := ncutils.RunCmd("wg", false)
  156. starttime := time.Now()
  157. ifaceReady := strings.Contains(output, deviceiface)
  158. for !ifaceReady && !(time.Now().After(starttime.Add(time.Second << 4))) {
  159. if ncutils.IsMac() { // if node is Mac (Darwin) get the tunnel name first
  160. deviceiface, mErr = local.GetMacIface(node.PrimaryAddress())
  161. if mErr != nil || deviceiface == "" {
  162. deviceiface = ifacename
  163. }
  164. }
  165. output, _ = ncutils.RunCmd("wg", false)
  166. err = ApplyConf(node, node.Interface, confPath)
  167. time.Sleep(time.Second)
  168. ifaceReady = strings.Contains(output, deviceiface)
  169. }
  170. //wgclient does not work well on freebsd
  171. if node.OS == "freebsd" {
  172. if !ifaceReady {
  173. return fmt.Errorf("could not reliably create interface, please check wg installation and retry")
  174. }
  175. } else {
  176. _, devErr := wgclient.Device(deviceiface)
  177. if !ifaceReady || devErr != nil {
  178. fmt.Printf("%v\n", devErr)
  179. return fmt.Errorf("could not reliably create interface, please check wg installation and retry")
  180. }
  181. }
  182. logger.Log(1, "interface ready - netclient.. ENGAGE")
  183. if !ncutils.HasWgQuick() && ncutils.IsLinux() {
  184. err = SetPeers(ifacename, node, peers)
  185. if err != nil {
  186. logger.Log(1, "error setting peers: ", err.Error())
  187. }
  188. time.Sleep(time.Second)
  189. }
  190. //ipv4
  191. if node.Address != "" {
  192. _, cidr, cidrErr := net.ParseCIDR(node.NetworkSettings.AddressRange)
  193. if cidrErr == nil {
  194. local.SetCIDRRoute(ifacename, node.Address, cidr)
  195. } else {
  196. logger.Log(1, "could not set cidr route properly: ", cidrErr.Error())
  197. }
  198. local.SetCurrentPeerRoutes(ifacename, node.Address, peers)
  199. }
  200. if node.Address6 != "" {
  201. //ipv6
  202. _, cidr, cidrErr := net.ParseCIDR(node.NetworkSettings.AddressRange6)
  203. if cidrErr == nil {
  204. local.SetCIDRRoute(ifacename, node.Address6, cidr)
  205. } else {
  206. logger.Log(1, "could not set cidr route properly: ", cidrErr.Error())
  207. }
  208. local.SetCurrentPeerRoutes(ifacename, node.Address6, peers)
  209. }
  210. return err
  211. }
  212. // SetWGConfig - sets the WireGuard Config of a given network and checks if it needs a peer update
  213. func SetWGConfig(network string, peerupdate bool, peers []wgtypes.PeerConfig) error {
  214. cfg, err := config.ReadConfig(network)
  215. if err != nil {
  216. return err
  217. }
  218. privkey, err := RetrievePrivKey(network)
  219. if err != nil {
  220. return err
  221. }
  222. if peerupdate && !ncutils.IsFreeBSD() && !(ncutils.IsLinux() && !ncutils.IsKernel()) {
  223. var iface string
  224. iface = cfg.Node.Interface
  225. if ncutils.IsMac() {
  226. iface, err = local.GetMacIface(cfg.Node.PrimaryAddress())
  227. if err != nil {
  228. return err
  229. }
  230. }
  231. err = SetPeers(iface, &cfg.Node, peers)
  232. } else {
  233. err = InitWireguard(&cfg.Node, privkey, peers)
  234. }
  235. return err
  236. }
  237. // RemoveConf - removes a configuration for a given WireGuard interface
  238. func RemoveConf(iface string, printlog bool) error {
  239. os := runtime.GOOS
  240. if ncutils.IsLinux() && !ncutils.HasWgQuick() {
  241. os = "nowgquick"
  242. }
  243. var err error
  244. switch os {
  245. case "nowgquick":
  246. err = RemoveWithoutWGQuick(iface)
  247. case "windows":
  248. err = RemoveWindowsConf(iface, printlog)
  249. case "darwin":
  250. err = RemoveConfMac(iface)
  251. default:
  252. confPath := ncutils.GetNetclientPathSpecific() + iface + ".conf"
  253. err = RemoveWGQuickConf(confPath, printlog)
  254. }
  255. return err
  256. }
  257. // ApplyConf - applys a conf on disk to WireGuard interface
  258. func ApplyConf(node *models.Node, ifacename string, confPath string) error {
  259. os := runtime.GOOS
  260. if ncutils.IsLinux() && !ncutils.HasWgQuick() {
  261. os = "nowgquick"
  262. }
  263. var isConnected = node.Connected != "no"
  264. var err error
  265. switch os {
  266. case "windows":
  267. ApplyWindowsConf(confPath, isConnected)
  268. case "darwin":
  269. ApplyMacOSConf(node, ifacename, confPath, isConnected)
  270. case "nowgquick":
  271. ApplyWithoutWGQuick(node, ifacename, confPath, isConnected)
  272. default:
  273. ApplyWGQuickConf(confPath, ifacename, isConnected)
  274. }
  275. var nodeCfg config.ClientConfig
  276. nodeCfg.Network = node.Network
  277. if !(node.IsServer == "yes") {
  278. nodeCfg.ReadConfig()
  279. if nodeCfg.NetworkSettings.AddressRange != "" {
  280. ip, cidr, err := net.ParseCIDR(nodeCfg.NetworkSettings.AddressRange)
  281. if err == nil {
  282. local.SetCIDRRoute(node.Interface, ip.String(), cidr)
  283. }
  284. }
  285. if nodeCfg.NetworkSettings.AddressRange6 != "" {
  286. ip, cidr, err := net.ParseCIDR(nodeCfg.NetworkSettings.AddressRange6)
  287. if err == nil {
  288. local.SetCIDRRoute(node.Interface, ip.String(), cidr)
  289. }
  290. }
  291. }
  292. return err
  293. }
  294. // WriteWgConfig - creates a wireguard config file
  295. func WriteWgConfig(node *models.Node, privateKey string, peers []wgtypes.PeerConfig) error {
  296. options := ini.LoadOptions{
  297. AllowNonUniqueSections: true,
  298. AllowShadows: true,
  299. }
  300. wireguard := ini.Empty(options)
  301. wireguard.Section(section_interface).Key("PrivateKey").SetValue(privateKey)
  302. if node.ListenPort > 0 && node.UDPHolePunch != "yes" {
  303. wireguard.Section(section_interface).Key("ListenPort").SetValue(strconv.Itoa(int(node.ListenPort)))
  304. }
  305. addrString := node.Address
  306. if node.Address6 != "" {
  307. if addrString != "" {
  308. addrString += ","
  309. }
  310. addrString += node.Address6
  311. }
  312. wireguard.Section(section_interface).Key("Address").SetValue(addrString)
  313. // need to figure out DNS
  314. //if node.DNSOn == "yes" {
  315. // wireguard.Section(section_interface).Key("DNS").SetValue(cfg.Server.CoreDNSAddr)
  316. //}
  317. //need to split postup/postdown because ini lib adds a ` and the ` breaks freebsd
  318. //works fine on others
  319. if node.PostUp != "" {
  320. if node.OS == "freebsd" {
  321. parts := strings.Split(node.PostUp, " ; ")
  322. for i, part := range parts {
  323. if i == 0 {
  324. wireguard.Section(section_interface).Key("PostUp").SetValue(part)
  325. }
  326. wireguard.Section(section_interface).Key("PostUp").AddShadow(part)
  327. }
  328. } else {
  329. wireguard.Section(section_interface).Key("PostUp").SetValue((node.PostUp))
  330. }
  331. }
  332. if node.PostDown != "" {
  333. if node.OS == "freebsd" {
  334. parts := strings.Split(node.PostDown, " ; ")
  335. for i, part := range parts {
  336. if i == 0 {
  337. wireguard.Section(section_interface).Key("PostDown").SetValue(part)
  338. }
  339. wireguard.Section(section_interface).Key("PostDown").AddShadow(part)
  340. }
  341. } else {
  342. wireguard.Section(section_interface).Key("PostUp").SetValue((node.PostUp))
  343. }
  344. }
  345. if node.MTU != 0 {
  346. wireguard.Section(section_interface).Key("MTU").SetValue(strconv.FormatInt(int64(node.MTU), 10))
  347. }
  348. for i, peer := range peers {
  349. wireguard.SectionWithIndex(section_peers, i).Key("PublicKey").SetValue(peer.PublicKey.String())
  350. if peer.PresharedKey != nil {
  351. wireguard.SectionWithIndex(section_peers, i).Key("PreSharedKey").SetValue(peer.PresharedKey.String())
  352. }
  353. if peer.AllowedIPs != nil {
  354. var allowedIPs string
  355. for i, ip := range peer.AllowedIPs {
  356. if i == 0 {
  357. allowedIPs = ip.String()
  358. } else {
  359. allowedIPs = allowedIPs + ", " + ip.String()
  360. }
  361. }
  362. wireguard.SectionWithIndex(section_peers, i).Key("AllowedIps").SetValue(allowedIPs)
  363. }
  364. if peer.Endpoint != nil {
  365. wireguard.SectionWithIndex(section_peers, i).Key("Endpoint").SetValue(peer.Endpoint.String())
  366. }
  367. if peer.PersistentKeepaliveInterval != nil && peer.PersistentKeepaliveInterval.Seconds() > 0 {
  368. wireguard.SectionWithIndex(section_peers, i).Key("PersistentKeepalive").SetValue(strconv.FormatInt((int64)(peer.PersistentKeepaliveInterval.Seconds()), 10))
  369. }
  370. }
  371. if err := wireguard.SaveTo(ncutils.GetNetclientPathSpecific() + node.Interface + ".conf"); err != nil {
  372. return err
  373. }
  374. return nil
  375. }
  376. // UpdateWgPeers - updates the peers of a network
  377. func UpdateWgPeers(file string, peers []wgtypes.PeerConfig) (*net.UDPAddr, error) {
  378. var internetGateway *net.UDPAddr
  379. options := ini.LoadOptions{
  380. AllowNonUniqueSections: true,
  381. AllowShadows: true,
  382. }
  383. wireguard, err := ini.LoadSources(options, file)
  384. if err != nil {
  385. return internetGateway, err
  386. }
  387. //delete the peers sections as they are going to be replaced
  388. wireguard.DeleteSection(section_peers)
  389. for i, peer := range peers {
  390. wireguard.SectionWithIndex(section_peers, i).Key("PublicKey").SetValue(peer.PublicKey.String())
  391. if peer.PresharedKey != nil {
  392. wireguard.SectionWithIndex(section_peers, i).Key("PreSharedKey").SetValue(peer.PresharedKey.String())
  393. }
  394. if peer.AllowedIPs != nil {
  395. var allowedIPs string
  396. for i, ip := range peer.AllowedIPs {
  397. if i == 0 {
  398. allowedIPs = ip.String()
  399. } else {
  400. allowedIPs = allowedIPs + ", " + ip.String()
  401. }
  402. }
  403. wireguard.SectionWithIndex(section_peers, i).Key("AllowedIps").SetValue(allowedIPs)
  404. if strings.Contains(allowedIPs, "0.0.0.0/0") || strings.Contains(allowedIPs, "::/0") {
  405. internetGateway = peer.Endpoint
  406. }
  407. }
  408. if peer.Endpoint != nil {
  409. wireguard.SectionWithIndex(section_peers, i).Key("Endpoint").SetValue(peer.Endpoint.String())
  410. }
  411. if peer.PersistentKeepaliveInterval != nil && peer.PersistentKeepaliveInterval.Seconds() > 0 {
  412. wireguard.SectionWithIndex(section_peers, i).Key("PersistentKeepalive").SetValue(strconv.FormatInt((int64)(peer.PersistentKeepaliveInterval.Seconds()), 10))
  413. }
  414. }
  415. if err := wireguard.SaveTo(file); err != nil {
  416. return internetGateway, err
  417. }
  418. return internetGateway, nil
  419. }
  420. // UpdateWgInterface - updates the interface section of a wireguard config file
  421. func UpdateWgInterface(file, privateKey, nameserver string, node models.Node) error {
  422. options := ini.LoadOptions{
  423. AllowNonUniqueSections: true,
  424. AllowShadows: true,
  425. }
  426. wireguard, err := ini.LoadSources(options, file)
  427. if err != nil {
  428. return err
  429. }
  430. if node.UDPHolePunch == "yes" {
  431. node.ListenPort = 0
  432. }
  433. wireguard.DeleteSection(section_interface)
  434. wireguard.Section(section_interface).Key("PrivateKey").SetValue(privateKey)
  435. wireguard.Section(section_interface).Key("ListenPort").SetValue(strconv.Itoa(int(node.ListenPort)))
  436. addrString := node.Address
  437. if node.Address6 != "" {
  438. if addrString != "" {
  439. addrString += ","
  440. }
  441. addrString += node.Address6
  442. }
  443. wireguard.Section(section_interface).Key("Address").SetValue(addrString)
  444. //if node.DNSOn == "yes" {
  445. // wireguard.Section(section_interface).Key("DNS").SetValue(nameserver)
  446. //}
  447. //need to split postup/postdown because ini lib adds a quotes which breaks freebsd
  448. if node.PostUp != "" {
  449. parts := strings.Split(node.PostUp, " ; ")
  450. for i, part := range parts {
  451. if i == 0 {
  452. wireguard.Section(section_interface).Key("PostUp").SetValue(part)
  453. }
  454. wireguard.Section(section_interface).Key("PostUp").AddShadow(part)
  455. }
  456. }
  457. if node.PostDown != "" {
  458. parts := strings.Split(node.PostDown, " ; ")
  459. for i, part := range parts {
  460. if i == 0 {
  461. wireguard.Section(section_interface).Key("PostDown").SetValue(part)
  462. }
  463. wireguard.Section(section_interface).Key("PostDown").AddShadow(part)
  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. }