common.go 18 KB

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