-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
localendpointstore.go
44 lines (34 loc) · 1.36 KB
/
localendpointstore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package envoy
import (
"github.com/cilium/cilium/pkg/lock"
"github.com/cilium/cilium/pkg/proxy/endpoint"
)
// LocalEndpointStore tracks the mapping between a given endpoint IP and the actual local endpoint.
type LocalEndpointStore struct {
// mutex protects accesses to the configuration resources below.
mutex lock.RWMutex
// networkPolicyEndpoints maps endpoint IP to the info on the local endpoint.
// mutex must be held when accessing this.
networkPolicyEndpoints map[string]endpoint.EndpointUpdater
}
// getLocalEndpoint returns the endpoint info for the local endpoint on which
// the network policy of the given name if enforced, or nil if not found.
func (s *LocalEndpointStore) getLocalEndpoint(endpointIP string) endpoint.EndpointUpdater {
s.mutex.RLock()
defer s.mutex.RUnlock()
return s.networkPolicyEndpoints[endpointIP]
}
// setLocalEndpoint maps the given IP to the local endpoint.
func (s *LocalEndpointStore) setLocalEndpoint(endpointIP string, ep endpoint.EndpointUpdater) {
s.mutex.Lock()
defer s.mutex.Unlock()
s.networkPolicyEndpoints[endpointIP] = ep
}
// removeLocalEndpoint delete the mapping for the given endpoint IP
func (s *LocalEndpointStore) removeLocalEndpoint(endpointIP string) {
s.mutex.Lock()
defer s.mutex.Unlock()
delete(s.networkPolicyEndpoints, endpointIP)
}