mac.go 683 B

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