Skip to content

Commit

Permalink
policy: Move exported Lookup to EndpointPolicy
Browse files Browse the repository at this point in the history
Move the exported Lookup function to EndpointPolicy, so that it can
actually be used from other packages.

Signed-off-by: Jarno Rajahalme <[email protected]>
  • Loading branch information
jrajahalme committed Dec 24, 2024
1 parent 4680363 commit 4390931
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 0 additions & 11 deletions pkg/policy/mapstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,6 @@ func (ms *mapState) lookup(key Key) (mapStateEntry, bool) {
return mapStateEntry{MapStateEntry: types.DenyEntry()}, false
}

// Lookup finds the policy verdict applicable to the given 'key' using the same precedence logic
// between L3 and L4-only policies as the bpf datapath when both match the given 'key'.
// To be used in testing in place of the bpf datapath when full integration testing is not desired.
// Returns the closest matching covering policy entry, the labels of the rules that contributed to
// that verdict, and 'true' if found.
// 'key' must not have a wildcard identity or port.
func (ms *mapState) Lookup(key Key) (MapStateEntry, labels.LabelArrayList, bool) {
entry, found := ms.lookup(key)
return entry.MapStateEntry, entry.derivedFromRules, found
}

func (ms *mapState) Len() int {
return len(ms.entries)
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/policy/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ func (p *EndpointPolicy) LookupRedirectPort(ingress bool, protocol string, port
return 0, fmt.Errorf("Proxy port for redirect %q not found", proxyID)
}

// Lookup finds the policy verdict applicable to the given 'key' using the same precedence logic
// between L3 and L4-only policies like the bpf datapath when both match the given 'key'.
// To be used in testing in place of the bpf datapath when full integration testing is not desired.
// Returns the closest matching covering policy entry, the labels of the rules that contributed to
// that verdict, and 'true' if found.
// Returns a deny entry when a match is not found, mirroring the datapath default deny behavior.
// 'key' must not have a wildcard identity or port.
func (p *EndpointPolicy) Lookup(key Key) (MapStateEntry, labels.LabelArrayList, bool) {
entry, found := p.policyMapState.lookup(key)
return entry.MapStateEntry, entry.derivedFromRules, found
}

// PolicyOwner is anything which consumes a EndpointPolicy.
type PolicyOwner interface {
GetID() uint64
Expand Down

0 comments on commit 4390931

Please sign in to comment.