Skip to content

Comments

bgp: Extend route policy matching with match types#3

Open
MitchLewis930 wants to merge 1 commit intopr_043_beforefrom
pr_043_after
Open

bgp: Extend route policy matching with match types#3
MitchLewis930 wants to merge 1 commit intopr_043_beforefrom
pr_043_after

Conversation

@MitchLewis930
Copy link

PR_043

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>
@MitchLewis930 MitchLewis930 requested a review from Copilot January 31, 2026 01:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends BGP route policy matching capabilities by introducing match types (any, all, invert) for neighbors and prefixes, replacing the previous implicit "any" logic with explicit type-based matching.

Changes:

  • Introduced RoutePolicyMatchType enum with any/all/invert options
  • Refactored RoutePolicyPrefixMatch and introduced RoutePolicyNeighborMatch structs with explicit match types
  • Updated all route policy statement constructions to use the new match structures

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
pkg/bgp/types/bgp.go Introduced match types and restructured neighbor/prefix match structures
pkg/bgp/types/utils.go Updated type names from RoutePolicyPrefixMatch to RoutePolicyPrefix
pkg/bgp/types/zz_generated.deepequal.go Generated DeepEqual methods for new match structures
pkg/bgp/types/bgp_test.go Updated tests to use new match structures and verify match type string representations
pkg/bgp/types/test_fixtures.go Updated test fixtures to use new match structures with explicit types
pkg/bgp/gobgp/conversions.go Updated GoBGP conversions to handle match types and new structures
pkg/bgp/manager/reconciler/*.go Updated reconcilers to create policies with new match structures
pkg/bgp/api/conversions.go Updated API conversions for new match structures
pkg/bgp/api/printers.go Updated table formatting to display match types
api/v1/models/*.go Generated model files for new API structures
api/v1/openapi.yaml Updated OpenAPI schema with new match type definitions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
s.Conditions.PrefixSet = &gobgp.MatchSet{
Type: gobgp.MatchSet_ANY, // any of the configured prefixes
Type: toGoBGPPolicyMatchType(apiStatement.Conditions.MatchNeighbors.Type),
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prefix match set is using the neighbor match type instead of the prefix match type. This should be apiStatement.Conditions.MatchPrefixes.Type to correctly apply the prefix matching logic.

Suggested change
Type: toGoBGPPolicyMatchType(apiStatement.Conditions.MatchNeighbors.Type),
Type: toGoBGPPolicyMatchType(apiStatement.Conditions.MatchPrefixes.Type),

Copilot uses AI. Check for mistakes.
PrefixLenMin: 32,
PrefixLenMax: 32,
MatchNeighbors: &types.RoutePolicyNeighborMatch{
Neighbors: []netip.Addr{netip.MustParseAddr("10.10.10.1")},
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Type field in RoutePolicyNeighborMatch. All other instances in this file explicitly set Type to RoutePolicyMatchAny, but this one omits it, which may lead to inconsistent behavior or use of a zero-value type.

Copilot uses AI. Check for mistakes.
PrefixLenMin: 128,
PrefixLenMax: 128,
MatchNeighbors: &types.RoutePolicyNeighborMatch{
Neighbors: []netip.Addr{netip.MustParseAddr("10.10.10.1")},
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Type field in RoutePolicyNeighborMatch. This instance should include Type: types.RoutePolicyMatchAny for consistency with other neighbor match definitions in this file.

Copilot uses AI. Check for mistakes.
PrefixLenMin: 32,
PrefixLenMax: 32,
MatchNeighbors: &types.RoutePolicyNeighborMatch{
Neighbors: []netip.Addr{netip.MustParseAddr("10.10.10.99")},
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Type field in RoutePolicyNeighborMatch. This should include Type: types.RoutePolicyMatchAny to maintain consistency with other test cases.

Copilot uses AI. Check for mistakes.
PrefixLenMin: 128,
PrefixLenMax: 128,
MatchNeighbors: &types.RoutePolicyNeighborMatch{
Neighbors: []netip.Addr{netip.MustParseAddr("10.10.10.99")},
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Type field in RoutePolicyNeighborMatch. This should include Type: types.RoutePolicyMatchAny for consistency.

Copilot uses AI. Check for mistakes.
return condI.MatchPrefixes.Prefixes[0].PrefixLenMin > condJ.MatchPrefixes.Prefixes[0].PrefixLenMin
}
return true
return false
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sort comparison should return true when there are no prefixes to sort, not false. When one or both statements have no prefixes, the sort should maintain their relative order (return true for stable sort), not force them to the end of the list. This breaks the stable sort behavior.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants