mac.go 760 B

123456789101112131415161718192021222324252627
  1. package wireguard
  2. import (
  3. "errors"
  4. "fmt"
  5. "strings"
  6. "github.com/gravitl/netmaker/netclient/ncutils"
  7. )
  8. // GetRealIface - retrieves tun iface based on reference iface name from config file
  9. func GetRealIface(iface string) (string, error) {
  10. ncutils.RunCmd("wg show interfaces", false)
  11. ifacePath := "/var/run/wireguard/" + iface + ".name"
  12. if !(ncutils.FileExists(ifacePath)) {
  13. return "", errors.New(ifacePath + " does not exist")
  14. }
  15. realIfaceName, err := ncutils.GetFileAsString(ifacePath)
  16. if err != nil {
  17. return "", err
  18. }
  19. realIfaceName = strings.TrimSpace(realIfaceName)
  20. if !(ncutils.FileExists(fmt.Sprintf("/var/run/wireguard/%s.sock", realIfaceName))) {
  21. return "", errors.New("interface file does not exist")
  22. }
  23. return realIfaceName, nil
  24. }