removed hard coded netmask

This commit is contained in:
Matthew R. Kasun 2022-02-09 14:41:13 -05:00
parent 2374e60c0b
commit e39138c184

View file

@ -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
}