mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 17:48:25 +08:00
removed hard coded netmask
This commit is contained in:
parent
2374e60c0b
commit
e39138c184
1 changed files with 5 additions and 3 deletions
|
@ -94,7 +94,9 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||
|
||||
if ncutils.IsKernel() {
|
||||
logger.Log(2, "setting kernel device", ifacename)
|
||||
setKernelDevice(ifacename, node.Address)
|
||||
network := strings.Split(node.NetworkSettings.AddressRange, "/")
|
||||
mask := network[len(network)-1]
|
||||
setKernelDevice(ifacename, node.Address, mask)
|
||||
}
|
||||
|
||||
nodeport := int(node.ListenPort)
|
||||
|
@ -184,7 +186,7 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
|||
return err
|
||||
}
|
||||
|
||||
func setKernelDevice(ifacename string, address string) error {
|
||||
func setKernelDevice(ifacename, address, mask string) error {
|
||||
ipExec, err := exec.LookPath("ip")
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -193,7 +195,7 @@ func setKernelDevice(ifacename string, address string) error {
|
|||
// == best effort ==
|
||||
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) // this is a bug waiting to happen
|
||||
ncutils.RunCmd(ipExec+" address add dev "+ifacename+" "+address+"/"+mask, true) // this was a bug waiting to happen
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue