Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cert-v2: more lighthousing #1251

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
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
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are reusing the msg struct we need to zero out the v2 fields in v1 and v1 fields in v2.

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
Loading