netmaker/netclient/wireguard/kernel.go

22 lines
515 B
Go
Raw Normal View History

2021-05-26 00:48:04 +08:00
package wireguard
import (
"os/exec"
2021-07-26 02:22:20 +08:00
2021-09-20 02:03:47 +08:00
"github.com/gravitl/netmaker/netclient/ncutils"
2021-05-26 00:48:04 +08:00
//homedir "github.com/mitchellh/go-homedir"
)
2021-07-26 02:22:20 +08:00
2021-09-20 02:03:47 +08:00
func setKernelDevice(ifacename string, address string) error {
ipExec, err := exec.LookPath("ip")
2021-05-26 00:48:04 +08:00
if err != nil {
return err
}
2021-09-20 02:03:47 +08:00
_, _ = ncutils.RunCmd("ip link delete dev "+ifacename, false)
_, _ = ncutils.RunCmd(ipExec+" link add dev "+ifacename+" type wireguard", true)
_, _ = ncutils.RunCmd(ipExec+" address add dev "+ifacename+" "+address+"/24", true)
return nil
2021-07-29 11:08:00 +08:00
}