Skip to content

Commit

Permalink
lighthouse updates with v2 tunnels
Browse files Browse the repository at this point in the history
  • Loading branch information
JackDoanRivian committed Oct 11, 2024
1 parent d6f1b51 commit 950e004
Showing 1 changed file with 62 additions and 34 deletions.
96 changes: 62 additions & 34 deletions lighthouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,6 @@ func (lh *LightHouse) SendUpdate() {
}
}

v := lh.ifce.GetCertState().defaultVersion
msg := &NebulaMeta{
Type: NebulaMeta_HostUpdateNotification,
Details: &NebulaMetaDetails{
Expand All @@ -869,47 +868,76 @@ func (lh *LightHouse) SendUpdate() {
},
}

if v == 1 {
var relays []uint32
for _, r := range lh.GetRelaysForMe() {
if !r.Is4() {
continue
}
b := r.As4()
relays = append(relays, binary.BigEndian.Uint32(b[:]))
}
nb := make([]byte, 12, 12)
out := make([]byte, mtu)

msg.Details.OldRelayVpnAddrs = relays
//TODO: assert ipv4
b := lh.myVpnNetworks[0].Addr().As4()
msg.Details.OldVpnAddr = binary.BigEndian.Uint32(b[:])
var v1Update, v2Update []byte
var err error
var v cert.Version
updated := 0
lighthouses := lh.GetLighthouses()

} else if v == 2 {
var relays []*Addr
for _, r := range lh.GetRelaysForMe() {
relays = append(relays, netAddrToProtoAddr(r))
for lhVpnAddr := range lighthouses {
hi := lh.ifce.GetHostInfo(lhVpnAddr)
if hi != nil {
v = hi.ConnectionState.myCert.Version()
} else {
v = lh.ifce.GetCertState().defaultVersion
}
msg.Details.RelayVpnAddrs = relays
msg.Details.VpnAddr = netAddrToProtoAddr(lh.myVpnNetworks[0].Addr())
if v == cert.Version1 {
if v1Update == nil {
var relays []uint32
for _, r := range lh.GetRelaysForMe() {
if !r.Is4() {
continue
}
b := r.As4()
relays = append(relays, binary.BigEndian.Uint32(b[:]))
}

} else {
panic("protocol version not supported")
}
msg.Details.OldRelayVpnAddrs = relays
//TODO: assert ipv4
b := lh.myVpnNetworks[0].Addr().As4()
msg.Details.OldVpnAddr = binary.BigEndian.Uint32(b[:])

lighthouses := lh.GetLighthouses()
lh.metricTx(NebulaMeta_HostUpdateNotification, int64(len(lighthouses)))
nb := make([]byte, 12, 12)
out := make([]byte, mtu)
v1Update, err = msg.Marshal()
if err != nil {
lh.l.WithError(err).WithField("lighthouseAddr", lhVpnAddr).
Error("Error while marshaling for lighthouse v1 update")
continue
}
}

mm, err := msg.Marshal()
if err != nil {
lh.l.WithError(err).Error("Error while marshaling for lighthouse update")
return
}
lh.ifce.SendMessageToVpnIp(header.LightHouse, 0, lhVpnAddr, v1Update, nb, out)
updated++

} else if v == cert.Version2 {
if v2Update == nil {
var relays []*Addr
for _, r := range lh.GetRelaysForMe() {
relays = append(relays, netAddrToProtoAddr(r))
}
msg.Details.RelayVpnAddrs = relays
msg.Details.VpnAddr = netAddrToProtoAddr(lh.myVpnNetworks[0].Addr())

for vpnIp := range lighthouses {
lh.ifce.SendMessageToVpnIp(header.LightHouse, 0, vpnIp, mm, nb, out)
v2Update, err = msg.Marshal()
if err != nil {
lh.l.WithError(err).WithField("lighthouseAddr", lhVpnAddr).
Error("Error while marshaling for lighthouse v2 update")
continue
}
}

lh.ifce.SendMessageToVpnIp(header.LightHouse, 0, lhVpnAddr, v2Update, nb, out)
updated++

} else {
lh.l.Debugf("Can not update lighthouse using unknown protocol version: %v", v)
continue
}
}

lh.metricTx(NebulaMeta_HostUpdateNotification, int64(updated))
}

type LightHouseHandler struct {
Expand Down

0 comments on commit 950e004

Please sign in to comment.