bgp: Extend route policy matching with match types#3
bgp: Extend route policy matching with match types#3MitchLewis930 wants to merge 1 commit intopr_043_beforefrom
Conversation
Extends the internal route policy API with 3 specific prefix / neighbor match types (any / all / invert) to support more flexible route policies for future developments. Signed-off-by: Rastislav Szabo <rastislav.szabo@isovalent.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| } | ||
| s.Conditions.PrefixSet = &gobgp.MatchSet{ | ||
| Type: gobgp.MatchSet_ANY, // any of the configured prefixes | ||
| Type: toGoBGPPolicyMatchType(apiStatement.Conditions.MatchNeighbors.Type), |
There was a problem hiding this comment.
Wrong field used for prefix match type conversion
High Severity
When building the GoBGP prefix set condition, the code uses apiStatement.Conditions.MatchNeighbors.Type instead of apiStatement.Conditions.MatchPrefixes.Type. This copy-paste error causes prefix matching to use the wrong match type. It will also cause a nil pointer dereference if MatchNeighbors is nil while MatchPrefixes has values.
| allPeers = true | ||
| } | ||
| addrs = append(addrs, s.Conditions.MatchNeighbors...) | ||
| addrs = append(addrs, s.Conditions.MatchNeighbors.Neighbors...) |
There was a problem hiding this comment.
Nil pointer dereference when accessing neighbor addresses
High Severity
In peerAddressesFromPolicy, after checking if s.Conditions.MatchNeighbors is nil on line 515, the code still unconditionally accesses s.Conditions.MatchNeighbors.Neighbors on line 518. When MatchNeighbors is nil, this causes a nil pointer dereference panic.


PR_043
Note
Medium Risk
Touches core BGP policy representation and conversion paths (API � agent � GoBGP), so mismapped fields or default behaviors could change which routes match; in particular,
toGoBGPPolicyStatementappears to apply the prefix match-set type fromMatchNeighbors.Typeinstead ofMatchPrefixes.Type.Overview
Adds configurable match semantics to BGP route policies. Neighbor and prefix conditions move from simple lists to structured match objects that include a
type(any/all/invert) plus the list of neighbors or prefixes.This updates the Swagger/OpenAPI spec and generated
api/v1/models(newBgpRoutePolicyMatchType,BgpRoutePolicyNeighborMatch,BgpRoutePolicyPrefix, refactoredBgpRoutePolicyPrefixMatch, andBgpRoutePolicyStatementfields), and refactors the agent BGP types/conversions/printers/reconciler code to use the new structures (including updated DeepEqual/sorting/test fixtures).Written by Cursor Bugbot for commit ba9b93c. This will update automatically on new commits. Configure here.