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