Skip to content

Commit

Permalink
Fix off-by-one in subnet calculation
Browse files Browse the repository at this point in the history
This was causing problems for people on many networks.

Signed-off-by: Erik Hollensbe <git@hollensbe.org>
  • Loading branch information
erikh committed Apr 9, 2022
1 parent b4db027 commit 3591816
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var networkTemplate string
const (
magicComment = "--- Managed by zerotier-systemd-manager. Do not remove this comment. ---"
networkDir = "/etc/systemd/network"
ipv4bits = net.IPv4len * 8
ipv4bits = 32
)

// parameter list for multiple template operations
Expand Down Expand Up @@ -158,14 +158,15 @@ func main() {
}

used, total := ipnet.Mask.Size()
bits := int(math.Ceil(float64(total) / float64(used)))

octets := make([]byte, bits)
bits := int(math.Trunc(math.Ceil(float64(total) / float64(used))))

octets := make([]byte, bits+1)
if total == ipv4bits {
ip = ip.To4()
}

for i := 0; i < bits; i++ {
for i := 0; i <= bits; i++ {
octets[i] = ip[i]
}

Expand Down

0 comments on commit 3591816

Please sign in to comment.