diff options
-rw-r--r-- | internal/pkg/table/adj.go | 7 | ||||
-rw-r--r-- | internal/pkg/table/table_manager.go | 15 | ||||
-rw-r--r-- | pkg/server/peer.go | 4 | ||||
-rw-r--r-- | pkg/server/server.go | 34 |
4 files changed, 14 insertions, 46 deletions
diff --git a/internal/pkg/table/adj.go b/internal/pkg/table/adj.go index 95fbf6af..acb2c07b 100644 --- a/internal/pkg/table/adj.go +++ b/internal/pkg/table/adj.go @@ -106,13 +106,18 @@ func (adj *AdjRib) Accepted(rfList []bgp.RouteFamily) int { return count } -func (adj *AdjRib) Drop(rfList []bgp.RouteFamily) { +func (adj *AdjRib) Drop(rfList []bgp.RouteFamily) []*Path { + l := make([]*Path, 0, adj.Count(rfList)) for _, rf := range rfList { if _, ok := adj.table[rf]; ok { + for _, p := range adj.table[rf] { + l = append(l, p.Clone(true)) + } adj.table[rf] = make(map[string]*Path) adj.accepted[rf] = 0 } } + return l } func (adj *AdjRib) DropStale(rfList []bgp.RouteFamily) []*Path { diff --git a/internal/pkg/table/table_manager.go b/internal/pkg/table/table_manager.go index 57533322..55436369 100644 --- a/internal/pkg/table/table_manager.go +++ b/internal/pkg/table/table_manager.go @@ -190,21 +190,6 @@ func (tm *TableManager) update(newPath *Path) *Update { return u } -func (manager *TableManager) GetPathListByPeer(info *PeerInfo, rf bgp.RouteFamily) []*Path { - if t, ok := manager.Tables[rf]; ok { - pathList := make([]*Path, 0, len(t.destinations)) - for _, dst := range t.destinations { - for _, p := range dst.knownPathList { - if p.GetSource().Equal(info) { - pathList = append(pathList, p) - } - } - } - return pathList - } - return nil -} - func (manager *TableManager) Update(newPath *Path) []*Update { if newPath == nil || newPath.IsEOR() { return nil diff --git a/pkg/server/peer.go b/pkg/server/peer.go index f7b89371..7d85ec52 100644 --- a/pkg/server/peer.go +++ b/pkg/server/peer.go @@ -558,6 +558,6 @@ func (peer *peer) PassConn(conn *net.TCPConn) { } } -func (peer *peer) DropAll(rfList []bgp.RouteFamily) { - peer.adjRibIn.Drop(rfList) +func (peer *peer) DropAll(rfList []bgp.RouteFamily) []*table.Path { + return peer.adjRibIn.Drop(rfList) } diff --git a/pkg/server/server.go b/pkg/server/server.go index 30ccbc37..16b6e869 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -1184,25 +1184,6 @@ func (s *BgpServer) propagateUpdate(peer *peer, pathList []*table.Path) { } } -func (s *BgpServer) dropPeerAllRoutes(peer *peer, families []bgp.RouteFamily) { - peer.fsm.lock.RLock() - peerInfo := peer.fsm.peerInfo - peer.fsm.lock.RUnlock() - - rib := s.globalRib - if peer.isRouteServerClient() { - rib = s.rsRib - } - for _, family := range peer.toGlobalFamilies(families) { - for _, path := range rib.GetPathListByPeer(peerInfo, family) { - p := path.Clone(true) - if dsts := rib.Update(p); len(dsts) > 0 { - s.propagateUpdateToNeighbors(peer, p, dsts, false) - } - } - } -} - func dstsToPaths(id string, as uint32, dsts []*table.Update) ([]*table.Path, []*table.Path, [][]*table.Path) { bestList := make([]*table.Path, 0, len(dsts)) oldList := make([]*table.Path, 0, len(dsts)) @@ -1345,8 +1326,7 @@ func (s *BgpServer) handleFSMMessage(peer *peer, e *fsmMsg) { drop = peer.configuredRFlist() } peer.prefixLimitWarned = make(map[bgp.RouteFamily]bool) - peer.DropAll(drop) - s.dropPeerAllRoutes(peer, drop) + s.propagateUpdate(peer, peer.DropAll(drop)) peer.fsm.lock.Lock() if peer.fsm.pConf.Config.PeerAs == 0 { @@ -1367,8 +1347,7 @@ func (s *BgpServer) handleFSMMessage(peer *peer, e *fsmMsg) { if longLivedEnabled { llgr, no_llgr := peer.llgrFamilies() - peer.DropAll(no_llgr) - s.dropPeerAllRoutes(peer, no_llgr) + s.propagateUpdate(peer, peer.DropAll(no_llgr)) // attach LLGR_STALE community to paths in peer's adj-rib-in // paths with NO_LLGR are deleted @@ -1401,8 +1380,7 @@ func (s *BgpServer) handleFSMMessage(peer *peer, e *fsmMsg) { "Key": peer.ID(), "Family": family, }).Debugf("LLGR restart timer (%d sec) for %s expired", t, family) - peer.DropAll([]bgp.RouteFamily{family}) - s.dropPeerAllRoutes(peer, []bgp.RouteFamily{family}) + s.propagateUpdate(peer, peer.DropAll([]bgp.RouteFamily{family})) // when all llgr restart timer expired, stop PeerRestarting if peer.llgrRestartTimerExpired(family) { @@ -1427,8 +1405,8 @@ func (s *BgpServer) handleFSMMessage(peer *peer, e *fsmMsg) { peer.fsm.lock.Lock() peer.fsm.pConf.GracefulRestart.State.PeerRestarting = false peer.fsm.lock.Unlock() - peer.DropAll(peer.configuredRFlist()) - s.dropPeerAllRoutes(peer, peer.configuredRFlist()) + + s.propagateUpdate(peer, peer.DropAll(peer.configuredRFlist())) if peer.isDynamicNeighbor() { s.deleteDynamicNeighbor(peer, oldState, e) @@ -2908,7 +2886,7 @@ func (s *BgpServer) deleteNeighbor(c *config.Neighbor, code, subcode uint8) erro n.fsm.h.ctxCancel() delete(s.neighborMap, addr) - s.dropPeerAllRoutes(n, n.configuredRFlist()) + s.propagateUpdate(n, n.DropAll(n.configuredRFlist())) return nil } |