New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
egressgw: optimize policy matching logic #24042
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jibi
added
release-note/misc
This PR makes changes that have no direct user impact.
feature/egress-gateway
Impacts the egress IP gateway feature.
labels
Feb 27, 2023
jibi
force-pushed
the
pr/jibi/improve-egressgw-policy-match-logic
branch
2 times, most recently
from
February 27, 2023 16:02
cdfead8
to
8e6cafd
Compare
Whenever we need to determine if a policy is a match for a given BPF map entry or IP rule, we first select from the policyConfigsBySourceIP cache all the policies that match the entry/rule's source IP, and from there we call the matches or matchesMinusExcludedCIDRs PolicyConfig methods, which iterate again through all the policy's endpoint/source IPs. As this isn't optimal, this commit introduces a couple of new manager's methods, that replace the PolicyConfig ones: * policyMatches * policyMatchesMinusExcludedCIDRs these work like matches and matchesMinusExcludedCIDRs, but iterate through the entire set of policies (instead of on a single one), and are optimized to skip iterating through the endpoint IPs we are not interested in. Signed-off-by: Gilberto Bertin <jibi@cilium.io>
Instead of just storing the endpoint IDs in the PolicyConfig matchedEndpointIDs cache, store also a pointer to the actual endpoint metadata, so that we don't need to rely on the manager's epDataStore every time we need to resolve the endpoint ID to its actual metadata. Also rename the cache to matchedEndpoints. Signed-off-by: Gilberto Bertin <jibi@cilium.io>
Now that the policy configs store a list of matching endpoints, we can replace the following logic, used to determine if a given policy has at least one matching endpoint: for _, endpoint := range manager.epDataStore { if policyConfig.selectsEndpoint(endpoint) { // .. } } with: if len(policyConfig.matchedEndpoints) != 0 { // .. } Signed-off-by: Gilberto Bertin <jibi@cilium.io>
jibi
force-pushed
the
pr/jibi/improve-egressgw-policy-match-logic
branch
from
February 27, 2023 17:36
8e6cafd
to
9973f15
Compare
/test |
schlosna
reviewed
Feb 28, 2023
julianwiedmann
approved these changes
Feb 28, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks Jibi!
jibi
added
the
ready-to-merge
This PR has passed all tests and received consensus from code owners to merge.
label
Feb 28, 2023
jibi
added
affects/v1.12
This issue affects v1.12 branch
affects/v1.13
This issue affects v1.13 branch
labels
Mar 24, 2023
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
affects/v1.12
This issue affects v1.12 branch
affects/v1.13
This issue affects v1.13 branch
feature/egress-gateway
Impacts the egress IP gateway feature.
ready-to-merge
This PR has passed all tests and received consensus from code owners to merge.
release-note/misc
This PR makes changes that have no direct user impact.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Whenever we need to determine if a policy is a match for a given BPF map entry or IP rule, we first select from the policyConfigsBySourceIP cache all the policies that match the entry/rule's source IP, and from there we call the matches or matchesMinusExcludedCIDRs PolicyConfig methods, which iterate again through all the policy's endpoint/source IPs.
As this isn't optimal, this commit introduces a couple of new manager's methods, that replace the PolicyConfig ones:
these work like matches and matchesMinusExcludedCIDRs, but iterate through the entire set of policies (instead of on a single one), and are optimized to skip iterating through the endpoint IPs we are not interested in.