Skip to content

Commit

Permalink
Fix broadcast addr calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrownus committed Oct 8, 2024
1 parent e988135 commit 6b05fea
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package nebula

import (
"context"
"encoding/binary"
"errors"
"fmt"
"io"
"net"
"net/netip"
"os"
"runtime"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6b05fea

Please sign in to comment.