trie value for except should not inherite if [overlaps between except and allow CIDR] or [except is larger than allow CIDR] ; trie value for except should inherite if except is smaller than allow cidr #347
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.
Issue #, if available:
Now there is an overlap between allow ip cidrs and except, here is the case:
Here, the ebpf egress map is :
Description of changes:
trie key
10.0.0.0/24
should not haveTCP 8081
, which belongs to 10.0.0.0/16 but except 10.0.0.0/24.We should first collect all the L4Info for nonHostCIDR, and then handle the exceptions. This is because when the eBPF program receives a packet, it matches against the smallest CIDR. If an exception is contained within a certain CIDR, then this exception should inherit the L4Info of that CIDR.
Therefore, after processing all the L4Info associated with the CIDRs, we will handle the exceptions:
For a specific exception (let's call it exceptA), we need to iterate through all the CIDRs and their L4Info. If:
Finally, we will process all the CIDRs and exceptions, using these as keys to write into the eBPF map's trie, and determine the corresponding L4Info. If the length of the L4Info is 0, we will write a RESERVE. If it is not 0, we will write the values according to the StartPort, EndPort, and Protocol of the L4Info.
after change,the ebpf egress map is:
port 8081
for10.0.0.0/16
but except10.0.0.24
has been removedFor another case , which e :
after change , we can get :
except
10.0.0.0/25
is in allow cidr10.0.0.0/24
, so L4Info should gather10.0.0.0/24
'sport 8080
and10.0.0.0/16
'sport 8081
.and the last case:
after change , we can get :
we should block any packet that in
10.0.0.0/23
but not in10.0.0.0/25
, and if packet that in10.0.0.0/24
, it matches10.0.0.0/24
, allowing port 8080.therefore, for an except cidr, if no other allow cidr (for except's parent allow cidr, L4Info should not inherit) contains it , we should deny all ports.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.