Skip to content

Commit

Permalink
NAT routes should not be mirrored back to the original sender
Browse files Browse the repository at this point in the history
Signed-off-by: Guvenc Gulce <guevenc.guelce@sap.com>
  • Loading branch information
guvenc committed Sep 21, 2023
1 parent b667a7e commit 113acdd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
28 changes: 17 additions & 11 deletions metalbond.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,23 @@ func (m *MetalBond) addSubscriber(peer *metalBondPeer, vni VNI) error {
m.log().Infof("Peer %s added Subscription to VNI %d", peer, vni)

// TODO: we're missing a read-lock on routeTable
for dest, hops := range m.routeTable.GetDestinationsByVNI(vni) {
for _, hop := range hops {
err := peer.SendUpdate(msgUpdate{
Action: ADD,
VNI: vni,
Destination: dest,
NextHop: hop,
})
if err != nil {
m.log().Errorf("Could not send UPDATE to peer: %v", err)
peer.Reset()
for dest, hopToPeersMap := range m.routeTable.GetDestinationsByVNIWithPeer(vni) {
for hop, peers := range hopToPeersMap {
for _, peerFromList := range peers {
// Dont send the NAT routes back to the original peer which announced it
if peerFromList == peer && hop.Type == pb.NextHopType_NAT {
continue
}
err := peer.SendUpdate(msgUpdate{
Action: ADD,
VNI: vni,
Destination: dest,
NextHop: hop,
})
if err != nil {
m.log().Errorf("Could not send UPDATE to peer: %v", err)
peer.Reset()
}
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions routetable.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ func (rt *routeTable) GetDestinationsByVNI(vni VNI) map[Destination][]NextHop {
return ret
}

func (rt *routeTable) GetDestinationsByVNIWithPeer(vni VNI) map[Destination]map[NextHop][]*metalBondPeer {
rt.rwmtx.RLock()
defer rt.rwmtx.RUnlock()

ret := make(map[Destination]map[NextHop][]*metalBondPeer)

if _, exists := rt.routes[vni]; !exists {
return ret
}

for dest, nhm := range rt.routes[vni] {
if ret[dest] == nil {
ret[dest] = make(map[NextHop][]*metalBondPeer)
}

for nh, peersMap := range nhm {
peers := []*metalBondPeer{}
for peer := range peersMap {
peers = append(peers, peer)
}
ret[dest][nh] = peers
}
}

return ret
}

func (rt *routeTable) GetNextHopsByDestination(vni VNI, dest Destination) []NextHop {
rt.rwmtx.RLock()
defer rt.rwmtx.RUnlock()
Expand Down

0 comments on commit 113acdd

Please sign in to comment.