From 6b05fea13909c432bf3fd07d2eec529dfb171987 Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Mon, 7 Oct 2024 22:29:21 -0500 Subject: [PATCH] Fix broadcast addr calculation --- interface.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/interface.go b/interface.go index 9308aae84..5d41a8714 100644 --- a/interface.go +++ b/interface.go @@ -2,9 +2,11 @@ package nebula import ( "context" + "encoding/binary" "errors" "fmt" "io" + "net" "net/netip" "os" "runtime" @@ -189,10 +191,11 @@ func NewInterface(ctx context.Context, c *InterfaceConfig) (*Interface, error) { } if ifce.myVpnNet.Addr().Is4() { - //TODO: - //addr := myVpnNet.Masked().Addr().As4() - //binary.BigEndian.PutUint32(addr[:], binary.BigEndian.Uint32(addr[:])|^binary.BigEndian.Uint32(certificate.Details.Ips[0].Mask)) - //ifce.myBroadcastAddr = netip.AddrFrom4(addr) + maskedAddr := certificate.Networks()[0].Masked() + addr := maskedAddr.Addr().As4() + mask := net.CIDRMask(maskedAddr.Bits(), maskedAddr.Addr().BitLen()) + binary.BigEndian.PutUint32(addr[:], binary.BigEndian.Uint32(addr[:])|^binary.BigEndian.Uint32(mask)) + ifce.myBroadcastAddr = netip.AddrFrom4(addr) } ifce.tryPromoteEvery.Store(c.tryPromoteEvery)