Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions lighthouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"github.com/slackhq/nebula/header"
"github.com/slackhq/nebula/udp"
"github.com/slackhq/nebula/util"
"github.com/vishvananda/netlink"
)

var ErrHostNotKnown = errors.New("host not known")
Expand Down Expand Up @@ -229,7 +230,7 @@
lh.updateCancel()
}

lh.StartUpdateWorker()
lh.StartUpdateWorkerNetlink()
}
}

Expand Down Expand Up @@ -845,10 +846,65 @@
}()
}

func (lh *LightHouse) StartUpdateWorkerNetlink() {
if lh.amLighthouse {
return
}

addrChan := make(chan netlink.AddrUpdate)

Check failure on line 854 in lighthouse.go

View workflow job for this annotation

GitHub Actions / Build all and test on ubuntu-linux

undefined: netlink.AddrUpdate

Check failure on line 854 in lighthouse.go

View workflow job for this annotation

GitHub Actions / Build and test on macos-latest

undefined: netlink.AddrUpdate
doneChan := make(chan struct{})

err := netlink.AddrSubscribe(addrChan, doneChan)

Check failure on line 857 in lighthouse.go

View workflow job for this annotation

GitHub Actions / Build all and test on ubuntu-linux

undefined: netlink.AddrSubscribe

Check failure on line 857 in lighthouse.go

View workflow job for this annotation

GitHub Actions / Build and test on macos-latest

undefined: netlink.AddrSubscribe
if err != nil {
lh.l.WithError(err).Error("Failed to subscribe to address updates")
return
}

updateCtx, cancel := context.WithCancel(lh.ctx)
lh.updateCancel = cancel

go func() {
defer func() {
x := struct{}{}
doneChan <- x
}()

lh.SendUpdate()

for {
select {
case <-updateCtx.Done():
return
case a := <-addrChan:
addr, ok := netip.AddrFromSlice(a.LinkAddress.IP)
if !ok {
continue
}
ones, _ := a.LinkAddress.Mask.Size()
pfx := netip.PrefixFrom(addr, ones)
lh.l.WithFields(logrus.Fields{
"LinkAddress": pfx,
"LinkIndex": a.LinkIndex,
"Flags": a.Flags,
"Scope": a.Scope,
"NewAddr": a.NewAddr,
"ValidLft": a.ValidLft,
"PreferedLft": a.PreferedLft,
}).Warn("Received address update")

shouldSend := a.PreferedLft != 0 //example criteria
if shouldSend {
lh.SendUpdate()
}
}
}
}()
}

func (lh *LightHouse) SendUpdate() {
var v4 []*V4AddrPort
var v6 []*V6AddrPort

lh.l.Warn("sending lh update!")
for _, e := range lh.GetAdvertiseAddrs() {
if e.Addr().Is4() {
v4 = append(v4, netAddrToProtoV4AddrPort(e.Addr(), e.Port()))
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func Main(c *config.C, configTest bool, buildVersion string, logger *logrus.Logg
sshStart,
statsStart,
dnsStart,
lightHouse.StartUpdateWorker,
lightHouse.StartUpdateWorkerNetlink,
connManager.Start,
}, nil
}
Loading