mirror of
https://github.com/gravitl/netmaker.git
synced 2024-09-22 08:16:07 +08:00
25 lines
683 B
Go
25 lines
683 B
Go
package wireguard
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/gravitl/netmaker/netclient/ncutils"
|
|
)
|
|
|
|
// GetRealIface - retrieves tun iface based on reference iface name from config file
|
|
func GetRealIface(iface string) (string, error) {
|
|
ncutils.RunCmd("wg show interfaces", false)
|
|
ifacePath := "/var/run/wireguard/" + iface + ".name"
|
|
if !(ncutils.FileExists(ifacePath)) {
|
|
return "", errors.New(ifacePath + " does not exist")
|
|
}
|
|
realIfaceName, err := ncutils.GetFileAsString(ifacePath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if !(ncutils.FileExists("/var/run/wireguard/" + realIfaceName + ".sock")) {
|
|
return "", errors.New("interface file does not exist")
|
|
}
|
|
return realIfaceName, nil
|
|
}
|