diff options
-rw-r--r-- | server/server.go | 26 | ||||
-rw-r--r-- | server/server_test.go | 29 |
2 files changed, 46 insertions, 9 deletions
diff --git a/server/server.go b/server/server.go index f642ece3..2293756d 100644 --- a/server/server.go +++ b/server/server.go @@ -1762,16 +1762,28 @@ func (s *BgpServer) Stop() error { }, true) } +func familiesForSoftreset(peer *Peer, family bgp.RouteFamily) []bgp.RouteFamily { + if family == bgp.RouteFamily(0) { + configured := peer.configuredRFlist() + families := make([]bgp.RouteFamily, 0, len(configured)) + for _, f := range configured { + if f != bgp.RF_RTC_UC { + families = append(families, f) + } + } + return families + } + return []bgp.RouteFamily{family} +} + func (s *BgpServer) softResetIn(addr string, family bgp.RouteFamily) error { peers, err := s.addrToPeers(addr) if err != nil { return err } for _, peer := range peers { - families := []bgp.RouteFamily{family} - if family == bgp.RouteFamily(0) { - families = peer.configuredRFlist() - } + families := familiesForSoftreset(peer, family) + pathList := make([]*table.Path, 0, peer.adjRibIn.Count(families)) for _, path := range peer.adjRibIn.PathList(families, false) { // RFC4271 9.1.2 Phase 2: Route Selection @@ -1807,11 +1819,7 @@ func (s *BgpServer) softResetOut(addr string, family bgp.RouteFamily, deferral b if peer.fsm.state != bgp.BGP_FSM_ESTABLISHED { continue } - - families := []bgp.RouteFamily{family} - if family == bgp.RouteFamily(0) { - families = peer.negotiatedRFList() - } + families := familiesForSoftreset(peer, family) if deferral { _, y := peer.fsm.rfMap[bgp.RF_RTC_UC] diff --git a/server/server_test.go b/server/server_test.go index b7a03490..4a6495e4 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -676,3 +676,32 @@ func TestGracefulRestartTimerExpired(t *testing.T) { } } } + +func TestFamiliesForSoftreset(t *testing.T) { + f := func(f bgp.RouteFamily) config.AfiSafi { + return config.AfiSafi{ + State: config.AfiSafiState{ + Family: f, + }, + } + } + peer := &Peer{ + fsm: &FSM{ + pConf: &config.Neighbor{ + AfiSafis: []config.AfiSafi{f(bgp.RF_RTC_UC), f(bgp.RF_IPv4_UC), f(bgp.RF_IPv6_UC)}, + }, + }, + } + + families := familiesForSoftreset(peer, bgp.RF_IPv4_UC) + assert.Equal(t, len(families), 1) + assert.Equal(t, families[0], bgp.RF_IPv4_UC) + + families = familiesForSoftreset(peer, bgp.RF_RTC_UC) + assert.Equal(t, len(families), 1) + assert.Equal(t, families[0], bgp.RF_RTC_UC) + + families = familiesForSoftreset(peer, bgp.RouteFamily(0)) + assert.Equal(t, len(families), 2) + assert.NotContains(t, families, bgp.RF_RTC_UC) +} |