Skip to content

Commit

Permalink
prePolicyFilterpath: respect max routes config
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Peim committed Mar 15, 2024
1 parent 9d05544 commit 48e3262
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
21 changes: 21 additions & 0 deletions pkg/server/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type peer struct {
policy *table.RoutingPolicy
localRib *table.TableManager
prefixLimitWarned map[bgp.RouteFamily]bool
dstRoutesCount map[bgp.RouteFamily]map[string]uint8
llgrEndChs []chan struct{}
}

Expand All @@ -113,6 +114,7 @@ func newPeer(g *oc.Global, conf *oc.Neighbor, loc *table.TableManager, policy *t
policy: policy,
fsm: newFSM(g, conf, logger),
prefixLimitWarned: make(map[bgp.RouteFamily]bool),
dstRoutesCount: make(map[bgp.RouteFamily]map[string]uint8),
}
if peer.isRouteServerClient() {
peer.tableId = conf.State.NeighborAddress
Expand All @@ -121,6 +123,11 @@ func newPeer(g *oc.Global, conf *oc.Neighbor, loc *table.TableManager, policy *t
}
rfs, _ := oc.AfiSafis(conf.AfiSafis).ToRfList()
peer.adjRibIn = table.NewAdjRib(peer.fsm.logger, rfs)
for _, f := range rfs {
if peer.isAddPathSendEnabled(f) {
peer.dstRoutesCount[f] = make(map[string]uint8)
}
}
return peer
}

Expand Down Expand Up @@ -200,6 +207,20 @@ func (peer *peer) isAddPathSendEnabled(family bgp.RouteFamily) bool {
return (peer.getAddPathMode(family) & bgp.BGP_ADD_PATH_SEND) > 0
}

func (peer *peer) getAddPathSendMax(family bgp.RouteFamily) uint8 {
peer.fsm.lock.RLock()
defer peer.fsm.lock.RUnlock()
if !peer.isAddPathSendEnabled(family) {
return 0
}
for _, a := range peer.fsm.pConf.AfiSafis {
if a.State.Family == family {
return a.AddPaths.Config.SendMax
}
}
return 0
}

func (peer *peer) isDynamicNeighbor() bool {
peer.fsm.lock.RLock()
defer peer.fsm.lock.RUnlock()
Expand Down
35 changes: 34 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,39 @@ func (s *BgpServer) prePolicyFilterpath(peer *peer, path, old *table.Path) (*tab
}
}

if path != nil {
family := path.GetRouteFamily()
f := func() bgp.RouteFamily {
if peerVrf != "" {
switch family {
case bgp.RF_IPv4_VPN:
return bgp.RF_IPv4_UC
case bgp.RF_IPv6_VPN:
return bgp.RF_IPv6_UC
case bgp.RF_FS_IPv4_VPN:
return bgp.RF_FS_IPv4_UC
case bgp.RF_FS_IPv6_VPN:
return bgp.RF_FS_IPv6_UC
}
}
return family
}()

sendMax := peer.getAddPathSendMax(f)
if sendMax > 0 {
dstPrefix := path.GetNlri().String()
dstRouteCount := peer.dstRoutesCount[f][dstPrefix]
if dstRouteCount > 0 && path.IsWithdraw {
dstRouteCount--
} else if dstRouteCount < sendMax && !path.IsWithdraw {
dstRouteCount++
} else if dstRouteCount >= sendMax {
return nil, nil, true
}
peer.dstRoutesCount[f][dstPrefix] = dstRouteCount
}
}

// replace-peer-as handling
peer.fsm.lock.RLock()
if path != nil && !path.IsWithdraw && peer.fsm.pConf.AsPathOptions.State.ReplacePeerAs {
Expand Down Expand Up @@ -760,6 +793,7 @@ func (s *BgpServer) postFilterpath(peer *peer, path *table.Path) *table.Path {
if path != nil && !peer.isIBGPPeer() && !peer.isRouteServerClient() {
path.RemoveLocalPref()
}

return path
}

Expand Down Expand Up @@ -1132,7 +1166,6 @@ func (s *BgpServer) processOutgoingPaths(peer *peer, paths, olds []*table.Path)
}

outgoing := make([]*table.Path, 0, len(paths))

for idx, path := range paths {
var old *table.Path
if olds != nil {
Expand Down

0 comments on commit 48e3262

Please sign in to comment.