id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
163,500
cilium/cilium
pkg/counter/prefixes.go
NewPrefixLengthCounter
func NewPrefixLengthCounter(maxUniquePrefixes6, maxUniquePrefixes4 int) *PrefixLengthCounter { return &PrefixLengthCounter{ v4: make(IntCounter), v6: make(IntCounter), maxUniquePrefixes4: maxUniquePrefixes4, maxUniquePrefixes6: maxUniquePrefixes6, } }
go
func NewPrefixLengthCounter(maxUniquePrefixes6, maxUniquePrefixes4 int) *PrefixLengthCounter { return &PrefixLengthCounter{ v4: make(IntCounter), v6: make(IntCounter), maxUniquePrefixes4: maxUniquePrefixes4, maxUniquePrefixes6: maxUniquePrefixes6, } }
[ "func", "NewPrefixLengthCounter", "(", "maxUniquePrefixes6", ",", "maxUniquePrefixes4", "int", ")", "*", "PrefixLengthCounter", "{", "return", "&", "PrefixLengthCounter", "{", "v4", ":", "make", "(", "IntCounter", ")", ",", "v6", ":", "make", "(", "IntCounter", ")", ",", "maxUniquePrefixes4", ":", "maxUniquePrefixes4", ",", "maxUniquePrefixes6", ":", "maxUniquePrefixes6", ",", "}", "\n", "}" ]
// NewPrefixLengthCounter returns a new PrefixLengthCounter which limits // insertions to the specified maximum number of unique prefix lengths.
[ "NewPrefixLengthCounter", "returns", "a", "new", "PrefixLengthCounter", "which", "limits", "insertions", "to", "the", "specified", "maximum", "number", "of", "unique", "prefix", "lengths", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/counter/prefixes.go#L39-L46
163,501
cilium/cilium
pkg/counter/prefixes.go
checkLimits
func checkLimits(current, newCount, max int) error { if newCount > max { return fmt.Errorf("Adding specified prefixes would result in too many prefix lengths (current: %d, result: %d, max: %d)", current, newCount, max) } return nil }
go
func checkLimits(current, newCount, max int) error { if newCount > max { return fmt.Errorf("Adding specified prefixes would result in too many prefix lengths (current: %d, result: %d, max: %d)", current, newCount, max) } return nil }
[ "func", "checkLimits", "(", "current", ",", "newCount", ",", "max", "int", ")", "error", "{", "if", "newCount", ">", "max", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "current", ",", "newCount", ",", "max", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// checkLimits checks whether the specified new count of prefixes would exceed // the specified limit on the maximum number of unique keys, and returns an // error if it would exceed the limit.
[ "checkLimits", "checks", "whether", "the", "specified", "new", "count", "of", "prefixes", "would", "exceed", "the", "specified", "limit", "on", "the", "maximum", "number", "of", "unique", "keys", "and", "returns", "an", "error", "if", "it", "would", "exceed", "the", "limit", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/counter/prefixes.go#L51-L57
163,502
cilium/cilium
pkg/counter/prefixes.go
Add
func (p *PrefixLengthCounter) Add(prefixes []*net.IPNet) (bool, error) { p.Lock() defer p.Unlock() // Assemble a map of references that need to be added newV4Counter := p.v4.DeepCopy() newV6Counter := p.v6.DeepCopy() newV4Prefixes := false newV6Prefixes := false for _, prefix := range prefixes { ones, bits := prefix.Mask.Size() switch bits { case net.IPv4len * 8: if newV4Counter.Add(ones) { newV4Prefixes = true } case net.IPv6len * 8: if newV6Counter.Add(ones) { newV6Prefixes = true } default: return false, fmt.Errorf("Unsupported IPAddr bitlength %d", bits) } } // Check if they can be added given the limit in place if newV4Prefixes { if err := checkLimits(len(p.v4), len(newV4Counter), p.maxUniquePrefixes4); err != nil { return false, err } } if newV6Prefixes { if err := checkLimits(len(p.v6), len(newV6Counter), p.maxUniquePrefixes6); err != nil { return false, err } } // Set and return whether anything changed p.v4 = newV4Counter p.v6 = newV6Counter return newV4Prefixes || newV6Prefixes, nil }
go
func (p *PrefixLengthCounter) Add(prefixes []*net.IPNet) (bool, error) { p.Lock() defer p.Unlock() // Assemble a map of references that need to be added newV4Counter := p.v4.DeepCopy() newV6Counter := p.v6.DeepCopy() newV4Prefixes := false newV6Prefixes := false for _, prefix := range prefixes { ones, bits := prefix.Mask.Size() switch bits { case net.IPv4len * 8: if newV4Counter.Add(ones) { newV4Prefixes = true } case net.IPv6len * 8: if newV6Counter.Add(ones) { newV6Prefixes = true } default: return false, fmt.Errorf("Unsupported IPAddr bitlength %d", bits) } } // Check if they can be added given the limit in place if newV4Prefixes { if err := checkLimits(len(p.v4), len(newV4Counter), p.maxUniquePrefixes4); err != nil { return false, err } } if newV6Prefixes { if err := checkLimits(len(p.v6), len(newV6Counter), p.maxUniquePrefixes6); err != nil { return false, err } } // Set and return whether anything changed p.v4 = newV4Counter p.v6 = newV6Counter return newV4Prefixes || newV6Prefixes, nil }
[ "func", "(", "p", "*", "PrefixLengthCounter", ")", "Add", "(", "prefixes", "[", "]", "*", "net", ".", "IPNet", ")", "(", "bool", ",", "error", ")", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "// Assemble a map of references that need to be added", "newV4Counter", ":=", "p", ".", "v4", ".", "DeepCopy", "(", ")", "\n", "newV6Counter", ":=", "p", ".", "v6", ".", "DeepCopy", "(", ")", "\n", "newV4Prefixes", ":=", "false", "\n", "newV6Prefixes", ":=", "false", "\n", "for", "_", ",", "prefix", ":=", "range", "prefixes", "{", "ones", ",", "bits", ":=", "prefix", ".", "Mask", ".", "Size", "(", ")", "\n\n", "switch", "bits", "{", "case", "net", ".", "IPv4len", "*", "8", ":", "if", "newV4Counter", ".", "Add", "(", "ones", ")", "{", "newV4Prefixes", "=", "true", "\n", "}", "\n", "case", "net", ".", "IPv6len", "*", "8", ":", "if", "newV6Counter", ".", "Add", "(", "ones", ")", "{", "newV6Prefixes", "=", "true", "\n", "}", "\n", "default", ":", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "bits", ")", "\n", "}", "\n", "}", "\n\n", "// Check if they can be added given the limit in place", "if", "newV4Prefixes", "{", "if", "err", ":=", "checkLimits", "(", "len", "(", "p", ".", "v4", ")", ",", "len", "(", "newV4Counter", ")", ",", "p", ".", "maxUniquePrefixes4", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "}", "\n", "if", "newV6Prefixes", "{", "if", "err", ":=", "checkLimits", "(", "len", "(", "p", ".", "v6", ")", ",", "len", "(", "newV6Counter", ")", ",", "p", ".", "maxUniquePrefixes6", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "}", "\n\n", "// Set and return whether anything changed", "p", ".", "v4", "=", "newV4Counter", "\n", "p", ".", "v6", "=", "newV6Counter", "\n", "return", "newV4Prefixes", "||", "newV6Prefixes", ",", "nil", "\n", "}" ]
// Add increments references to prefix lengths for the specified IPNets to the // counter. If the maximum number of unique prefix lengths would be exceeded, // returns an error. // // Returns true if adding these prefixes results in an increase in the total // number of unique prefix lengths in the counter.
[ "Add", "increments", "references", "to", "prefix", "lengths", "for", "the", "specified", "IPNets", "to", "the", "counter", ".", "If", "the", "maximum", "number", "of", "unique", "prefix", "lengths", "would", "be", "exceeded", "returns", "an", "error", ".", "Returns", "true", "if", "adding", "these", "prefixes", "results", "in", "an", "increase", "in", "the", "total", "number", "of", "unique", "prefix", "lengths", "in", "the", "counter", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/counter/prefixes.go#L65-L107
163,503
cilium/cilium
pkg/counter/prefixes.go
Delete
func (p *PrefixLengthCounter) Delete(prefixes []*net.IPNet) (changed bool) { p.Lock() defer p.Unlock() for _, prefix := range prefixes { ones, bits := prefix.Mask.Size() switch bits { case net.IPv4len * 8: if p.v4.Delete(ones) { changed = true } case net.IPv6len * 8: if p.v6.Delete(ones) { changed = true } } } return changed }
go
func (p *PrefixLengthCounter) Delete(prefixes []*net.IPNet) (changed bool) { p.Lock() defer p.Unlock() for _, prefix := range prefixes { ones, bits := prefix.Mask.Size() switch bits { case net.IPv4len * 8: if p.v4.Delete(ones) { changed = true } case net.IPv6len * 8: if p.v6.Delete(ones) { changed = true } } } return changed }
[ "func", "(", "p", "*", "PrefixLengthCounter", ")", "Delete", "(", "prefixes", "[", "]", "*", "net", ".", "IPNet", ")", "(", "changed", "bool", ")", "{", "p", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "Unlock", "(", ")", "\n\n", "for", "_", ",", "prefix", ":=", "range", "prefixes", "{", "ones", ",", "bits", ":=", "prefix", ".", "Mask", ".", "Size", "(", ")", "\n", "switch", "bits", "{", "case", "net", ".", "IPv4len", "*", "8", ":", "if", "p", ".", "v4", ".", "Delete", "(", "ones", ")", "{", "changed", "=", "true", "\n", "}", "\n", "case", "net", ".", "IPv6len", "*", "8", ":", "if", "p", ".", "v6", ".", "Delete", "(", "ones", ")", "{", "changed", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "changed", "\n", "}" ]
// Delete reduces references to prefix lengths in the the specified IPNets from // the counter. Returns true if removing references to these prefix lengths // would result in a decrese in the total number of unique prefix lengths in // the counter.
[ "Delete", "reduces", "references", "to", "prefix", "lengths", "in", "the", "the", "specified", "IPNets", "from", "the", "counter", ".", "Returns", "true", "if", "removing", "references", "to", "these", "prefix", "lengths", "would", "result", "in", "a", "decrese", "in", "the", "total", "number", "of", "unique", "prefix", "lengths", "in", "the", "counter", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/counter/prefixes.go#L113-L132
163,504
cilium/cilium
pkg/counter/prefixes.go
ToBPFData
func (p *PrefixLengthCounter) ToBPFData() (s6, s4 []int) { p.RLock() defer p.RUnlock() return p.v6.ToBPFData(), p.v4.ToBPFData() }
go
func (p *PrefixLengthCounter) ToBPFData() (s6, s4 []int) { p.RLock() defer p.RUnlock() return p.v6.ToBPFData(), p.v4.ToBPFData() }
[ "func", "(", "p", "*", "PrefixLengthCounter", ")", "ToBPFData", "(", ")", "(", "s6", ",", "s4", "[", "]", "int", ")", "{", "p", ".", "RLock", "(", ")", "\n", "defer", "p", ".", "RUnlock", "(", ")", "\n\n", "return", "p", ".", "v6", ".", "ToBPFData", "(", ")", ",", "p", ".", "v4", ".", "ToBPFData", "(", ")", "\n", "}" ]
// ToBPFData converts the counter into a set of prefix lengths that the BPF // datapath can use for LPM lookup.
[ "ToBPFData", "converts", "the", "counter", "into", "a", "set", "of", "prefix", "lengths", "that", "the", "BPF", "datapath", "can", "use", "for", "LPM", "lookup", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/counter/prefixes.go#L136-L141
163,505
cilium/cilium
api/v1/client/policy/get_fqdn_cache_id_parameters.go
WithTimeout
func (o *GetFqdnCacheIDParams) WithTimeout(timeout time.Duration) *GetFqdnCacheIDParams { o.SetTimeout(timeout) return o }
go
func (o *GetFqdnCacheIDParams) WithTimeout(timeout time.Duration) *GetFqdnCacheIDParams { o.SetTimeout(timeout) return o }
[ "func", "(", "o", "*", "GetFqdnCacheIDParams", ")", "WithTimeout", "(", "timeout", "time", ".", "Duration", ")", "*", "GetFqdnCacheIDParams", "{", "o", ".", "SetTimeout", "(", "timeout", ")", "\n", "return", "o", "\n", "}" ]
// WithTimeout adds the timeout to the get fqdn cache ID params
[ "WithTimeout", "adds", "the", "timeout", "to", "the", "get", "fqdn", "cache", "ID", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/get_fqdn_cache_id_parameters.go#L98-L101
163,506
cilium/cilium
api/v1/client/policy/get_fqdn_cache_id_parameters.go
WithContext
func (o *GetFqdnCacheIDParams) WithContext(ctx context.Context) *GetFqdnCacheIDParams { o.SetContext(ctx) return o }
go
func (o *GetFqdnCacheIDParams) WithContext(ctx context.Context) *GetFqdnCacheIDParams { o.SetContext(ctx) return o }
[ "func", "(", "o", "*", "GetFqdnCacheIDParams", ")", "WithContext", "(", "ctx", "context", ".", "Context", ")", "*", "GetFqdnCacheIDParams", "{", "o", ".", "SetContext", "(", "ctx", ")", "\n", "return", "o", "\n", "}" ]
// WithContext adds the context to the get fqdn cache ID params
[ "WithContext", "adds", "the", "context", "to", "the", "get", "fqdn", "cache", "ID", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/get_fqdn_cache_id_parameters.go#L109-L112
163,507
cilium/cilium
api/v1/client/policy/get_fqdn_cache_id_parameters.go
WithHTTPClient
func (o *GetFqdnCacheIDParams) WithHTTPClient(client *http.Client) *GetFqdnCacheIDParams { o.SetHTTPClient(client) return o }
go
func (o *GetFqdnCacheIDParams) WithHTTPClient(client *http.Client) *GetFqdnCacheIDParams { o.SetHTTPClient(client) return o }
[ "func", "(", "o", "*", "GetFqdnCacheIDParams", ")", "WithHTTPClient", "(", "client", "*", "http", ".", "Client", ")", "*", "GetFqdnCacheIDParams", "{", "o", ".", "SetHTTPClient", "(", "client", ")", "\n", "return", "o", "\n", "}" ]
// WithHTTPClient adds the HTTPClient to the get fqdn cache ID params
[ "WithHTTPClient", "adds", "the", "HTTPClient", "to", "the", "get", "fqdn", "cache", "ID", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/get_fqdn_cache_id_parameters.go#L120-L123
163,508
cilium/cilium
api/v1/client/policy/get_fqdn_cache_id_parameters.go
WithCidr
func (o *GetFqdnCacheIDParams) WithCidr(cidr *string) *GetFqdnCacheIDParams { o.SetCidr(cidr) return o }
go
func (o *GetFqdnCacheIDParams) WithCidr(cidr *string) *GetFqdnCacheIDParams { o.SetCidr(cidr) return o }
[ "func", "(", "o", "*", "GetFqdnCacheIDParams", ")", "WithCidr", "(", "cidr", "*", "string", ")", "*", "GetFqdnCacheIDParams", "{", "o", ".", "SetCidr", "(", "cidr", ")", "\n", "return", "o", "\n", "}" ]
// WithCidr adds the cidr to the get fqdn cache ID params
[ "WithCidr", "adds", "the", "cidr", "to", "the", "get", "fqdn", "cache", "ID", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/get_fqdn_cache_id_parameters.go#L131-L134
163,509
cilium/cilium
api/v1/client/policy/get_fqdn_cache_id_parameters.go
WithID
func (o *GetFqdnCacheIDParams) WithID(id string) *GetFqdnCacheIDParams { o.SetID(id) return o }
go
func (o *GetFqdnCacheIDParams) WithID(id string) *GetFqdnCacheIDParams { o.SetID(id) return o }
[ "func", "(", "o", "*", "GetFqdnCacheIDParams", ")", "WithID", "(", "id", "string", ")", "*", "GetFqdnCacheIDParams", "{", "o", ".", "SetID", "(", "id", ")", "\n", "return", "o", "\n", "}" ]
// WithID adds the id to the get fqdn cache ID params
[ "WithID", "adds", "the", "id", "to", "the", "get", "fqdn", "cache", "ID", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/get_fqdn_cache_id_parameters.go#L142-L145
163,510
cilium/cilium
api/v1/client/policy/get_fqdn_cache_id_parameters.go
WithMatchpattern
func (o *GetFqdnCacheIDParams) WithMatchpattern(matchpattern *string) *GetFqdnCacheIDParams { o.SetMatchpattern(matchpattern) return o }
go
func (o *GetFqdnCacheIDParams) WithMatchpattern(matchpattern *string) *GetFqdnCacheIDParams { o.SetMatchpattern(matchpattern) return o }
[ "func", "(", "o", "*", "GetFqdnCacheIDParams", ")", "WithMatchpattern", "(", "matchpattern", "*", "string", ")", "*", "GetFqdnCacheIDParams", "{", "o", ".", "SetMatchpattern", "(", "matchpattern", ")", "\n", "return", "o", "\n", "}" ]
// WithMatchpattern adds the matchpattern to the get fqdn cache ID params
[ "WithMatchpattern", "adds", "the", "matchpattern", "to", "the", "get", "fqdn", "cache", "ID", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/policy/get_fqdn_cache_id_parameters.go#L153-L156
163,511
cilium/cilium
pkg/kafka/policy.go
isTopicAPIKey
func isTopicAPIKey(kind int16) bool { switch kind { case api.ProduceKey, api.FetchKey, api.OffsetsKey, api.MetadataKey, api.LeaderAndIsr, api.StopReplica, api.UpdateMetadata, api.OffsetCommitKey, api.OffsetFetchKey, api.CreateTopicsKey, api.DeleteTopicsKey, api.DeleteRecordsKey, api.OffsetForLeaderEpochKey, api.AddPartitionsToTxnKey, api.WriteTxnMarkersKey, api.TxnOffsetCommitKey, api.AlterReplicaLogDirsKey, api.DescribeLogDirsKey, api.CreatePartitionsKey: return true } return false }
go
func isTopicAPIKey(kind int16) bool { switch kind { case api.ProduceKey, api.FetchKey, api.OffsetsKey, api.MetadataKey, api.LeaderAndIsr, api.StopReplica, api.UpdateMetadata, api.OffsetCommitKey, api.OffsetFetchKey, api.CreateTopicsKey, api.DeleteTopicsKey, api.DeleteRecordsKey, api.OffsetForLeaderEpochKey, api.AddPartitionsToTxnKey, api.WriteTxnMarkersKey, api.TxnOffsetCommitKey, api.AlterReplicaLogDirsKey, api.DescribeLogDirsKey, api.CreatePartitionsKey: return true } return false }
[ "func", "isTopicAPIKey", "(", "kind", "int16", ")", "bool", "{", "switch", "kind", "{", "case", "api", ".", "ProduceKey", ",", "api", ".", "FetchKey", ",", "api", ".", "OffsetsKey", ",", "api", ".", "MetadataKey", ",", "api", ".", "LeaderAndIsr", ",", "api", ".", "StopReplica", ",", "api", ".", "UpdateMetadata", ",", "api", ".", "OffsetCommitKey", ",", "api", ".", "OffsetFetchKey", ",", "api", ".", "CreateTopicsKey", ",", "api", ".", "DeleteTopicsKey", ",", "api", ".", "DeleteRecordsKey", ",", "api", ".", "OffsetForLeaderEpochKey", ",", "api", ".", "AddPartitionsToTxnKey", ",", "api", ".", "WriteTxnMarkersKey", ",", "api", ".", "TxnOffsetCommitKey", ",", "api", ".", "AlterReplicaLogDirsKey", ",", "api", ".", "DescribeLogDirsKey", ",", "api", ".", "CreatePartitionsKey", ":", "return", "true", "\n", "}", "\n", "return", "false", "\n", "}" ]
// isTopicAPIKey returns true if kind is apiKey message type which contains a // topic in its request.
[ "isTopicAPIKey", "returns", "true", "if", "kind", "is", "apiKey", "message", "type", "which", "contains", "a", "topic", "in", "its", "request", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kafka/policy.go#L27-L52
163,512
cilium/cilium
pkg/kafka/policy.go
MatchesRule
func (req *RequestMessage) MatchesRule(rules []api.PortRuleKafka) bool { topics := req.GetTopics() // Maintain a map of all topics in the request. // We should allow the request only if all topics are // allowed by the list of rules. reqTopicsMap := make(map[string]bool, len(topics)) for _, topic := range topics { reqTopicsMap[topic] = true } for _, rule := range rules { if rule.Topic == "" || len(topics) == 0 { if req.ruleMatches(rule) { return true } } else if reqTopicsMap[rule.Topic] { if req.ruleMatches(rule) { delete(reqTopicsMap, rule.Topic) if len(reqTopicsMap) == 0 { return true } } } } return false }
go
func (req *RequestMessage) MatchesRule(rules []api.PortRuleKafka) bool { topics := req.GetTopics() // Maintain a map of all topics in the request. // We should allow the request only if all topics are // allowed by the list of rules. reqTopicsMap := make(map[string]bool, len(topics)) for _, topic := range topics { reqTopicsMap[topic] = true } for _, rule := range rules { if rule.Topic == "" || len(topics) == 0 { if req.ruleMatches(rule) { return true } } else if reqTopicsMap[rule.Topic] { if req.ruleMatches(rule) { delete(reqTopicsMap, rule.Topic) if len(reqTopicsMap) == 0 { return true } } } } return false }
[ "func", "(", "req", "*", "RequestMessage", ")", "MatchesRule", "(", "rules", "[", "]", "api", ".", "PortRuleKafka", ")", "bool", "{", "topics", ":=", "req", ".", "GetTopics", "(", ")", "\n", "// Maintain a map of all topics in the request.", "// We should allow the request only if all topics are", "// allowed by the list of rules.", "reqTopicsMap", ":=", "make", "(", "map", "[", "string", "]", "bool", ",", "len", "(", "topics", ")", ")", "\n", "for", "_", ",", "topic", ":=", "range", "topics", "{", "reqTopicsMap", "[", "topic", "]", "=", "true", "\n", "}", "\n\n", "for", "_", ",", "rule", ":=", "range", "rules", "{", "if", "rule", ".", "Topic", "==", "\"", "\"", "||", "len", "(", "topics", ")", "==", "0", "{", "if", "req", ".", "ruleMatches", "(", "rule", ")", "{", "return", "true", "\n", "}", "\n", "}", "else", "if", "reqTopicsMap", "[", "rule", ".", "Topic", "]", "{", "if", "req", ".", "ruleMatches", "(", "rule", ")", "{", "delete", "(", "reqTopicsMap", ",", "rule", ".", "Topic", ")", "\n", "if", "len", "(", "reqTopicsMap", ")", "==", "0", "{", "return", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// MatchesRule validates the Kafka request message against the provided list of // rules. The function will return true if the policy allows the message, // otherwise false is returned.
[ "MatchesRule", "validates", "the", "Kafka", "request", "message", "against", "the", "provided", "list", "of", "rules", ".", "The", "function", "will", "return", "true", "if", "the", "policy", "allows", "the", "message", "otherwise", "false", "is", "returned", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kafka/policy.go#L200-L225
163,513
cilium/cilium
daemon/endpoint.go
EndpointUpdate
func (d *Daemon) EndpointUpdate(id string, cfg *models.EndpointConfigurationSpec) error { ep, err := endpointmanager.Lookup(id) if err != nil { return api.Error(PatchEndpointIDInvalidCode, err) } else if ep == nil { return api.New(PatchEndpointIDConfigNotFoundCode, "endpoint %s not found", id) } else if err = endpoint.APICanModify(ep); err != nil { return api.Error(PatchEndpointIDInvalidCode, err) } if err := ep.Update(d, cfg); err != nil { switch err.(type) { case endpoint.UpdateValidationError: return api.Error(PatchEndpointIDConfigInvalidCode, err) default: return api.Error(PatchEndpointIDConfigFailedCode, err) } } if err := ep.RLockAlive(); err != nil { return api.Error(PatchEndpointIDNotFoundCode, err) } endpointmanager.UpdateReferences(ep) ep.RUnlock() return nil }
go
func (d *Daemon) EndpointUpdate(id string, cfg *models.EndpointConfigurationSpec) error { ep, err := endpointmanager.Lookup(id) if err != nil { return api.Error(PatchEndpointIDInvalidCode, err) } else if ep == nil { return api.New(PatchEndpointIDConfigNotFoundCode, "endpoint %s not found", id) } else if err = endpoint.APICanModify(ep); err != nil { return api.Error(PatchEndpointIDInvalidCode, err) } if err := ep.Update(d, cfg); err != nil { switch err.(type) { case endpoint.UpdateValidationError: return api.Error(PatchEndpointIDConfigInvalidCode, err) default: return api.Error(PatchEndpointIDConfigFailedCode, err) } } if err := ep.RLockAlive(); err != nil { return api.Error(PatchEndpointIDNotFoundCode, err) } endpointmanager.UpdateReferences(ep) ep.RUnlock() return nil }
[ "func", "(", "d", "*", "Daemon", ")", "EndpointUpdate", "(", "id", "string", ",", "cfg", "*", "models", ".", "EndpointConfigurationSpec", ")", "error", "{", "ep", ",", "err", ":=", "endpointmanager", ".", "Lookup", "(", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "api", ".", "Error", "(", "PatchEndpointIDInvalidCode", ",", "err", ")", "\n", "}", "else", "if", "ep", "==", "nil", "{", "return", "api", ".", "New", "(", "PatchEndpointIDConfigNotFoundCode", ",", "\"", "\"", ",", "id", ")", "\n", "}", "else", "if", "err", "=", "endpoint", ".", "APICanModify", "(", "ep", ")", ";", "err", "!=", "nil", "{", "return", "api", ".", "Error", "(", "PatchEndpointIDInvalidCode", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "ep", ".", "Update", "(", "d", ",", "cfg", ")", ";", "err", "!=", "nil", "{", "switch", "err", ".", "(", "type", ")", "{", "case", "endpoint", ".", "UpdateValidationError", ":", "return", "api", ".", "Error", "(", "PatchEndpointIDConfigInvalidCode", ",", "err", ")", "\n", "default", ":", "return", "api", ".", "Error", "(", "PatchEndpointIDConfigFailedCode", ",", "err", ")", "\n", "}", "\n", "}", "\n", "if", "err", ":=", "ep", ".", "RLockAlive", "(", ")", ";", "err", "!=", "nil", "{", "return", "api", ".", "Error", "(", "PatchEndpointIDNotFoundCode", ",", "err", ")", "\n", "}", "\n", "endpointmanager", ".", "UpdateReferences", "(", "ep", ")", "\n", "ep", ".", "RUnlock", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// EndpointUpdate updates the options of the given endpoint and regenerates the endpoint
[ "EndpointUpdate", "updates", "the", "options", "of", "the", "given", "endpoint", "and", "regenerates", "the", "endpoint" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/daemon/endpoint.go#L655-L680
163,514
cilium/cilium
api/v1/server/restapi/endpoint/get_endpoint_id_labels_responses.go
WithPayload
func (o *GetEndpointIDLabelsOK) WithPayload(payload *models.LabelConfiguration) *GetEndpointIDLabelsOK { o.Payload = payload return o }
go
func (o *GetEndpointIDLabelsOK) WithPayload(payload *models.LabelConfiguration) *GetEndpointIDLabelsOK { o.Payload = payload return o }
[ "func", "(", "o", "*", "GetEndpointIDLabelsOK", ")", "WithPayload", "(", "payload", "*", "models", ".", "LabelConfiguration", ")", "*", "GetEndpointIDLabelsOK", "{", "o", ".", "Payload", "=", "payload", "\n", "return", "o", "\n", "}" ]
// WithPayload adds the payload to the get endpoint Id labels o k response
[ "WithPayload", "adds", "the", "payload", "to", "the", "get", "endpoint", "Id", "labels", "o", "k", "response" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/endpoint/get_endpoint_id_labels_responses.go#L38-L41
163,515
cilium/cilium
api/v1/client/endpoint/patch_endpoint_id_labels_parameters.go
WithTimeout
func (o *PatchEndpointIDLabelsParams) WithTimeout(timeout time.Duration) *PatchEndpointIDLabelsParams { o.SetTimeout(timeout) return o }
go
func (o *PatchEndpointIDLabelsParams) WithTimeout(timeout time.Duration) *PatchEndpointIDLabelsParams { o.SetTimeout(timeout) return o }
[ "func", "(", "o", "*", "PatchEndpointIDLabelsParams", ")", "WithTimeout", "(", "timeout", "time", ".", "Duration", ")", "*", "PatchEndpointIDLabelsParams", "{", "o", ".", "SetTimeout", "(", "timeout", ")", "\n", "return", "o", "\n", "}" ]
// WithTimeout adds the timeout to the patch endpoint ID labels params
[ "WithTimeout", "adds", "the", "timeout", "to", "the", "patch", "endpoint", "ID", "labels", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/patch_endpoint_id_labels_parameters.go#L92-L95
163,516
cilium/cilium
api/v1/client/endpoint/patch_endpoint_id_labels_parameters.go
WithContext
func (o *PatchEndpointIDLabelsParams) WithContext(ctx context.Context) *PatchEndpointIDLabelsParams { o.SetContext(ctx) return o }
go
func (o *PatchEndpointIDLabelsParams) WithContext(ctx context.Context) *PatchEndpointIDLabelsParams { o.SetContext(ctx) return o }
[ "func", "(", "o", "*", "PatchEndpointIDLabelsParams", ")", "WithContext", "(", "ctx", "context", ".", "Context", ")", "*", "PatchEndpointIDLabelsParams", "{", "o", ".", "SetContext", "(", "ctx", ")", "\n", "return", "o", "\n", "}" ]
// WithContext adds the context to the patch endpoint ID labels params
[ "WithContext", "adds", "the", "context", "to", "the", "patch", "endpoint", "ID", "labels", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/patch_endpoint_id_labels_parameters.go#L103-L106
163,517
cilium/cilium
api/v1/client/endpoint/patch_endpoint_id_labels_parameters.go
WithHTTPClient
func (o *PatchEndpointIDLabelsParams) WithHTTPClient(client *http.Client) *PatchEndpointIDLabelsParams { o.SetHTTPClient(client) return o }
go
func (o *PatchEndpointIDLabelsParams) WithHTTPClient(client *http.Client) *PatchEndpointIDLabelsParams { o.SetHTTPClient(client) return o }
[ "func", "(", "o", "*", "PatchEndpointIDLabelsParams", ")", "WithHTTPClient", "(", "client", "*", "http", ".", "Client", ")", "*", "PatchEndpointIDLabelsParams", "{", "o", ".", "SetHTTPClient", "(", "client", ")", "\n", "return", "o", "\n", "}" ]
// WithHTTPClient adds the HTTPClient to the patch endpoint ID labels params
[ "WithHTTPClient", "adds", "the", "HTTPClient", "to", "the", "patch", "endpoint", "ID", "labels", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/patch_endpoint_id_labels_parameters.go#L114-L117
163,518
cilium/cilium
api/v1/client/endpoint/patch_endpoint_id_labels_parameters.go
WithConfiguration
func (o *PatchEndpointIDLabelsParams) WithConfiguration(configuration *models.LabelConfigurationSpec) *PatchEndpointIDLabelsParams { o.SetConfiguration(configuration) return o }
go
func (o *PatchEndpointIDLabelsParams) WithConfiguration(configuration *models.LabelConfigurationSpec) *PatchEndpointIDLabelsParams { o.SetConfiguration(configuration) return o }
[ "func", "(", "o", "*", "PatchEndpointIDLabelsParams", ")", "WithConfiguration", "(", "configuration", "*", "models", ".", "LabelConfigurationSpec", ")", "*", "PatchEndpointIDLabelsParams", "{", "o", ".", "SetConfiguration", "(", "configuration", ")", "\n", "return", "o", "\n", "}" ]
// WithConfiguration adds the configuration to the patch endpoint ID labels params
[ "WithConfiguration", "adds", "the", "configuration", "to", "the", "patch", "endpoint", "ID", "labels", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/patch_endpoint_id_labels_parameters.go#L125-L128
163,519
cilium/cilium
api/v1/client/endpoint/patch_endpoint_id_labels_parameters.go
WithID
func (o *PatchEndpointIDLabelsParams) WithID(id string) *PatchEndpointIDLabelsParams { o.SetID(id) return o }
go
func (o *PatchEndpointIDLabelsParams) WithID(id string) *PatchEndpointIDLabelsParams { o.SetID(id) return o }
[ "func", "(", "o", "*", "PatchEndpointIDLabelsParams", ")", "WithID", "(", "id", "string", ")", "*", "PatchEndpointIDLabelsParams", "{", "o", ".", "SetID", "(", "id", ")", "\n", "return", "o", "\n", "}" ]
// WithID adds the id to the patch endpoint ID labels params
[ "WithID", "adds", "the", "id", "to", "the", "patch", "endpoint", "ID", "labels", "params" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/endpoint/patch_endpoint_id_labels_parameters.go#L136-L139
163,520
cilium/cilium
api/v1/models/label_configuration_spec.go
Validate
func (m *LabelConfigurationSpec) Validate(formats strfmt.Registry) error { var res []error if err := m.validateUser(formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
go
func (m *LabelConfigurationSpec) Validate(formats strfmt.Registry) error { var res []error if err := m.validateUser(formats); err != nil { res = append(res, err) } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
[ "func", "(", "m", "*", "LabelConfigurationSpec", ")", "Validate", "(", "formats", "strfmt", ".", "Registry", ")", "error", "{", "var", "res", "[", "]", "error", "\n\n", "if", "err", ":=", "m", ".", "validateUser", "(", "formats", ")", ";", "err", "!=", "nil", "{", "res", "=", "append", "(", "res", ",", "err", ")", "\n", "}", "\n\n", "if", "len", "(", "res", ")", ">", "0", "{", "return", "errors", ".", "CompositeValidationError", "(", "res", "...", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate validates this label configuration spec
[ "Validate", "validates", "this", "label", "configuration", "spec" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/models/label_configuration_spec.go#L24-L35
163,521
cilium/cilium
pkg/policy/trace/yaml.go
GetLabelsFromYaml
func GetLabelsFromYaml(file string) ([][]string, error) { reader, err := os.Open(file) if err != nil { return nil, err } defer reader.Close() byteArr, err := ioutil.ReadAll(reader) if err != nil { return nil, err } splitYamlLabels := [][]string{} yamlDocs := bytes.Split(byteArr, []byte("---")) for _, v := range yamlDocs { yamlLabels := []string{} // Ignore empty documents, e.g., file starting with --- or ---\n if len(v) < 2 { continue } obj, _, err := scheme.Codecs.UniversalDeserializer().Decode(v, nil, nil) if err != nil { return nil, err } switch obj.(type) { case *v1beta1.Deployment: deployment := obj.(*v1beta1.Deployment) var ns string if deployment.Namespace != "" { ns = deployment.Namespace } else { ns = DefaultNamespace } yamlLabels = append(yamlLabels, labels.GenerateK8sLabelString(k8sConst.PodNamespaceLabel, ns)) for k, v := range deployment.Spec.Template.Labels { yamlLabels = append(yamlLabels, labels.GenerateK8sLabelString(k, v)) } case *v1.ReplicationController: controller := obj.(*v1.ReplicationController) var ns string if controller.Namespace != "" { ns = controller.Namespace } else { ns = DefaultNamespace } yamlLabels = append(yamlLabels, labels.GenerateK8sLabelString(k8sConst.PodNamespaceLabel, ns)) for k, v := range controller.Spec.Template.Labels { yamlLabels = append(yamlLabels, labels.GenerateK8sLabelString(k, v)) } case *v1beta1.ReplicaSet: rep := obj.(*v1beta1.ReplicaSet) var ns string if rep.Namespace != "" { ns = rep.Namespace } else { ns = DefaultNamespace } yamlLabels = append(yamlLabels, labels.GenerateK8sLabelString(k8sConst.PodNamespaceLabel, ns)) for k, v := range rep.Spec.Template.Labels { yamlLabels = append(yamlLabels, labels.GenerateK8sLabelString(k, v)) } default: return nil, fmt.Errorf("unsupported type provided in YAML file: %T", obj) } splitYamlLabels = append(splitYamlLabels, yamlLabels) } return splitYamlLabels, nil }
go
func GetLabelsFromYaml(file string) ([][]string, error) { reader, err := os.Open(file) if err != nil { return nil, err } defer reader.Close() byteArr, err := ioutil.ReadAll(reader) if err != nil { return nil, err } splitYamlLabels := [][]string{} yamlDocs := bytes.Split(byteArr, []byte("---")) for _, v := range yamlDocs { yamlLabels := []string{} // Ignore empty documents, e.g., file starting with --- or ---\n if len(v) < 2 { continue } obj, _, err := scheme.Codecs.UniversalDeserializer().Decode(v, nil, nil) if err != nil { return nil, err } switch obj.(type) { case *v1beta1.Deployment: deployment := obj.(*v1beta1.Deployment) var ns string if deployment.Namespace != "" { ns = deployment.Namespace } else { ns = DefaultNamespace } yamlLabels = append(yamlLabels, labels.GenerateK8sLabelString(k8sConst.PodNamespaceLabel, ns)) for k, v := range deployment.Spec.Template.Labels { yamlLabels = append(yamlLabels, labels.GenerateK8sLabelString(k, v)) } case *v1.ReplicationController: controller := obj.(*v1.ReplicationController) var ns string if controller.Namespace != "" { ns = controller.Namespace } else { ns = DefaultNamespace } yamlLabels = append(yamlLabels, labels.GenerateK8sLabelString(k8sConst.PodNamespaceLabel, ns)) for k, v := range controller.Spec.Template.Labels { yamlLabels = append(yamlLabels, labels.GenerateK8sLabelString(k, v)) } case *v1beta1.ReplicaSet: rep := obj.(*v1beta1.ReplicaSet) var ns string if rep.Namespace != "" { ns = rep.Namespace } else { ns = DefaultNamespace } yamlLabels = append(yamlLabels, labels.GenerateK8sLabelString(k8sConst.PodNamespaceLabel, ns)) for k, v := range rep.Spec.Template.Labels { yamlLabels = append(yamlLabels, labels.GenerateK8sLabelString(k, v)) } default: return nil, fmt.Errorf("unsupported type provided in YAML file: %T", obj) } splitYamlLabels = append(splitYamlLabels, yamlLabels) } return splitYamlLabels, nil }
[ "func", "GetLabelsFromYaml", "(", "file", "string", ")", "(", "[", "]", "[", "]", "string", ",", "error", ")", "{", "reader", ",", "err", ":=", "os", ".", "Open", "(", "file", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "reader", ".", "Close", "(", ")", "\n\n", "byteArr", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "reader", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "splitYamlLabels", ":=", "[", "]", "[", "]", "string", "{", "}", "\n", "yamlDocs", ":=", "bytes", ".", "Split", "(", "byteArr", ",", "[", "]", "byte", "(", "\"", "\"", ")", ")", "\n", "for", "_", ",", "v", ":=", "range", "yamlDocs", "{", "yamlLabels", ":=", "[", "]", "string", "{", "}", "\n\n", "// Ignore empty documents, e.g., file starting with --- or ---\\n", "if", "len", "(", "v", ")", "<", "2", "{", "continue", "\n", "}", "\n\n", "obj", ",", "_", ",", "err", ":=", "scheme", ".", "Codecs", ".", "UniversalDeserializer", "(", ")", ".", "Decode", "(", "v", ",", "nil", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "switch", "obj", ".", "(", "type", ")", "{", "case", "*", "v1beta1", ".", "Deployment", ":", "deployment", ":=", "obj", ".", "(", "*", "v1beta1", ".", "Deployment", ")", "\n", "var", "ns", "string", "\n", "if", "deployment", ".", "Namespace", "!=", "\"", "\"", "{", "ns", "=", "deployment", ".", "Namespace", "\n", "}", "else", "{", "ns", "=", "DefaultNamespace", "\n", "}", "\n", "yamlLabels", "=", "append", "(", "yamlLabels", ",", "labels", ".", "GenerateK8sLabelString", "(", "k8sConst", ".", "PodNamespaceLabel", ",", "ns", ")", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "deployment", ".", "Spec", ".", "Template", ".", "Labels", "{", "yamlLabels", "=", "append", "(", "yamlLabels", ",", "labels", ".", "GenerateK8sLabelString", "(", "k", ",", "v", ")", ")", "\n", "}", "\n", "case", "*", "v1", ".", "ReplicationController", ":", "controller", ":=", "obj", ".", "(", "*", "v1", ".", "ReplicationController", ")", "\n", "var", "ns", "string", "\n", "if", "controller", ".", "Namespace", "!=", "\"", "\"", "{", "ns", "=", "controller", ".", "Namespace", "\n", "}", "else", "{", "ns", "=", "DefaultNamespace", "\n", "}", "\n", "yamlLabels", "=", "append", "(", "yamlLabels", ",", "labels", ".", "GenerateK8sLabelString", "(", "k8sConst", ".", "PodNamespaceLabel", ",", "ns", ")", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "controller", ".", "Spec", ".", "Template", ".", "Labels", "{", "yamlLabels", "=", "append", "(", "yamlLabels", ",", "labels", ".", "GenerateK8sLabelString", "(", "k", ",", "v", ")", ")", "\n", "}", "\n", "case", "*", "v1beta1", ".", "ReplicaSet", ":", "rep", ":=", "obj", ".", "(", "*", "v1beta1", ".", "ReplicaSet", ")", "\n", "var", "ns", "string", "\n", "if", "rep", ".", "Namespace", "!=", "\"", "\"", "{", "ns", "=", "rep", ".", "Namespace", "\n", "}", "else", "{", "ns", "=", "DefaultNamespace", "\n", "}", "\n", "yamlLabels", "=", "append", "(", "yamlLabels", ",", "labels", ".", "GenerateK8sLabelString", "(", "k8sConst", ".", "PodNamespaceLabel", ",", "ns", ")", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "rep", ".", "Spec", ".", "Template", ".", "Labels", "{", "yamlLabels", "=", "append", "(", "yamlLabels", ",", "labels", ".", "GenerateK8sLabelString", "(", "k", ",", "v", ")", ")", "\n", "}", "\n", "default", ":", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "obj", ")", "\n", "}", "\n", "splitYamlLabels", "=", "append", "(", "splitYamlLabels", ",", "yamlLabels", ")", "\n", "}", "\n", "return", "splitYamlLabels", ",", "nil", "\n", "}" ]
// GetLabelsFromYaml iterates through the provided YAML file and for each // section in the YAML, returns the labels or an error if the labels could not // be parsed.
[ "GetLabelsFromYaml", "iterates", "through", "the", "provided", "YAML", "file", "and", "for", "each", "section", "in", "the", "YAML", "returns", "the", "labels", "or", "an", "error", "if", "the", "labels", "could", "not", "be", "parsed", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/trace/yaml.go#L39-L112
163,522
cilium/cilium
cilium/cmd/bpf_sha_list.go
getTemplateSHA
func getTemplateSHA(epID string) string { // Get symlink from endpointDir templateSymlink := filepath.Join(stateDir, epID, defaults.TemplatePath) f, err := os.Lstat(templateSymlink) if err != nil { return noSHA } if f.Mode()&os.ModeSymlink == 0 { return brokenSHA } template, err := os.Readlink(templateSymlink) if err != nil { return brokenSHA } if f, err = os.Stat(template); err != nil { return brokenSHA } return filepath.Base(filepath.Dir(template)) }
go
func getTemplateSHA(epID string) string { // Get symlink from endpointDir templateSymlink := filepath.Join(stateDir, epID, defaults.TemplatePath) f, err := os.Lstat(templateSymlink) if err != nil { return noSHA } if f.Mode()&os.ModeSymlink == 0 { return brokenSHA } template, err := os.Readlink(templateSymlink) if err != nil { return brokenSHA } if f, err = os.Stat(template); err != nil { return brokenSHA } return filepath.Base(filepath.Dir(template)) }
[ "func", "getTemplateSHA", "(", "epID", "string", ")", "string", "{", "// Get symlink from endpointDir", "templateSymlink", ":=", "filepath", ".", "Join", "(", "stateDir", ",", "epID", ",", "defaults", ".", "TemplatePath", ")", "\n", "f", ",", "err", ":=", "os", ".", "Lstat", "(", "templateSymlink", ")", "\n", "if", "err", "!=", "nil", "{", "return", "noSHA", "\n", "}", "\n", "if", "f", ".", "Mode", "(", ")", "&", "os", ".", "ModeSymlink", "==", "0", "{", "return", "brokenSHA", "\n", "}", "\n\n", "template", ",", "err", ":=", "os", ".", "Readlink", "(", "templateSymlink", ")", "\n", "if", "err", "!=", "nil", "{", "return", "brokenSHA", "\n", "}", "\n", "if", "f", ",", "err", "=", "os", ".", "Stat", "(", "template", ")", ";", "err", "!=", "nil", "{", "return", "brokenSHA", "\n", "}", "\n", "return", "filepath", ".", "Base", "(", "filepath", ".", "Dir", "(", "template", ")", ")", "\n", "}" ]
// getTemplateSHA returns the SHA that should be reported to the user for // the specified endpoint ID.
[ "getTemplateSHA", "returns", "the", "SHA", "that", "should", "be", "reported", "to", "the", "user", "for", "the", "specified", "endpoint", "ID", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/cilium/cmd/bpf_sha_list.go#L66-L85
163,523
cilium/cilium
pkg/ipam/allocator.go
AllocateIP
func (ipam *IPAM) AllocateIP(ip net.IP, owner string) error { ipam.allocatorMutex.Lock() defer ipam.allocatorMutex.Unlock() family := familyIPv4 if ip.To4() != nil { if ipam.IPv4Allocator == nil { return ErrIPv4Disabled } if err := ipam.IPv4Allocator.Allocate(ip); err != nil { return err } } else { family = familyIPv6 if ipam.IPv6Allocator == nil { return ErrIPv6Disabled } if err := ipam.IPv6Allocator.Allocate(ip); err != nil { return err } } log.WithFields(logrus.Fields{ "ip": ip.String(), "owner": owner, }).Debugf("Allocated specific IP") ipam.owner[ip.String()] = owner metrics.IpamEvent.WithLabelValues(metricAllocate, family).Inc() return nil }
go
func (ipam *IPAM) AllocateIP(ip net.IP, owner string) error { ipam.allocatorMutex.Lock() defer ipam.allocatorMutex.Unlock() family := familyIPv4 if ip.To4() != nil { if ipam.IPv4Allocator == nil { return ErrIPv4Disabled } if err := ipam.IPv4Allocator.Allocate(ip); err != nil { return err } } else { family = familyIPv6 if ipam.IPv6Allocator == nil { return ErrIPv6Disabled } if err := ipam.IPv6Allocator.Allocate(ip); err != nil { return err } } log.WithFields(logrus.Fields{ "ip": ip.String(), "owner": owner, }).Debugf("Allocated specific IP") ipam.owner[ip.String()] = owner metrics.IpamEvent.WithLabelValues(metricAllocate, family).Inc() return nil }
[ "func", "(", "ipam", "*", "IPAM", ")", "AllocateIP", "(", "ip", "net", ".", "IP", ",", "owner", "string", ")", "error", "{", "ipam", ".", "allocatorMutex", ".", "Lock", "(", ")", "\n", "defer", "ipam", ".", "allocatorMutex", ".", "Unlock", "(", ")", "\n", "family", ":=", "familyIPv4", "\n", "if", "ip", ".", "To4", "(", ")", "!=", "nil", "{", "if", "ipam", ".", "IPv4Allocator", "==", "nil", "{", "return", "ErrIPv4Disabled", "\n", "}", "\n\n", "if", "err", ":=", "ipam", ".", "IPv4Allocator", ".", "Allocate", "(", "ip", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "else", "{", "family", "=", "familyIPv6", "\n", "if", "ipam", ".", "IPv6Allocator", "==", "nil", "{", "return", "ErrIPv6Disabled", "\n", "}", "\n\n", "if", "err", ":=", "ipam", ".", "IPv6Allocator", ".", "Allocate", "(", "ip", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "log", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "\"", "\"", ":", "ip", ".", "String", "(", ")", ",", "\"", "\"", ":", "owner", ",", "}", ")", ".", "Debugf", "(", "\"", "\"", ")", "\n\n", "ipam", ".", "owner", "[", "ip", ".", "String", "(", ")", "]", "=", "owner", "\n", "metrics", ".", "IpamEvent", ".", "WithLabelValues", "(", "metricAllocate", ",", "family", ")", ".", "Inc", "(", ")", "\n", "return", "nil", "\n", "}" ]
// AllocateIP allocates a IP address.
[ "AllocateIP", "allocates", "a", "IP", "address", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipam/allocator.go#L49-L80
163,524
cilium/cilium
pkg/ipam/allocator.go
AllocateIPString
func (ipam *IPAM) AllocateIPString(ipAddr, owner string) error { ip := net.ParseIP(ipAddr) if ip == nil { return fmt.Errorf("Invalid IP address: %s", ipAddr) } return ipam.AllocateIP(ip, owner) }
go
func (ipam *IPAM) AllocateIPString(ipAddr, owner string) error { ip := net.ParseIP(ipAddr) if ip == nil { return fmt.Errorf("Invalid IP address: %s", ipAddr) } return ipam.AllocateIP(ip, owner) }
[ "func", "(", "ipam", "*", "IPAM", ")", "AllocateIPString", "(", "ipAddr", ",", "owner", "string", ")", "error", "{", "ip", ":=", "net", ".", "ParseIP", "(", "ipAddr", ")", "\n", "if", "ip", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ipAddr", ")", "\n", "}", "\n\n", "return", "ipam", ".", "AllocateIP", "(", "ip", ",", "owner", ")", "\n", "}" ]
// AllocateIPString is identical to AllocateIP but takes a string
[ "AllocateIPString", "is", "identical", "to", "AllocateIP", "but", "takes", "a", "string" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipam/allocator.go#L83-L90
163,525
cilium/cilium
pkg/ipam/allocator.go
AllocateNextFamily
func (ipam *IPAM) AllocateNextFamily(family Family, owner string) (ip net.IP, err error) { switch family { case IPv6: ip, err = ipam.allocateNextFamily(family, ipam.IPv6Allocator, owner) case IPv4: ip, err = ipam.allocateNextFamily(family, ipam.IPv4Allocator, owner) default: err = fmt.Errorf("unknown address \"%s\" family requested", family) } return }
go
func (ipam *IPAM) AllocateNextFamily(family Family, owner string) (ip net.IP, err error) { switch family { case IPv6: ip, err = ipam.allocateNextFamily(family, ipam.IPv6Allocator, owner) case IPv4: ip, err = ipam.allocateNextFamily(family, ipam.IPv4Allocator, owner) default: err = fmt.Errorf("unknown address \"%s\" family requested", family) } return }
[ "func", "(", "ipam", "*", "IPAM", ")", "AllocateNextFamily", "(", "family", "Family", ",", "owner", "string", ")", "(", "ip", "net", ".", "IP", ",", "err", "error", ")", "{", "switch", "family", "{", "case", "IPv6", ":", "ip", ",", "err", "=", "ipam", ".", "allocateNextFamily", "(", "family", ",", "ipam", ".", "IPv6Allocator", ",", "owner", ")", "\n", "case", "IPv4", ":", "ip", ",", "err", "=", "ipam", ".", "allocateNextFamily", "(", "family", ",", "ipam", ".", "IPv4Allocator", ",", "owner", ")", "\n\n", "default", ":", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\\\"", "\\\"", "\"", ",", "family", ")", "\n", "}", "\n", "return", "\n", "}" ]
// AllocateNextFamily allocates the next IP of the requested address family
[ "AllocateNextFamily", "allocates", "the", "next", "IP", "of", "the", "requested", "address", "family" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipam/allocator.go#L111-L122
163,526
cilium/cilium
pkg/ipam/allocator.go
AllocateNext
func (ipam *IPAM) AllocateNext(family, owner string) (ipv4 net.IP, ipv6 net.IP, err error) { if (family == "ipv6" || family == "") && ipam.IPv6Allocator != nil { ipv6, err = ipam.AllocateNextFamily(IPv6, owner) if err != nil { return } } if (family == "ipv4" || family == "") && ipam.IPv4Allocator != nil { ipv4, err = ipam.AllocateNextFamily(IPv4, owner) if err != nil { if ipv6 != nil { ipam.ReleaseIP(ipv6) } return } } return }
go
func (ipam *IPAM) AllocateNext(family, owner string) (ipv4 net.IP, ipv6 net.IP, err error) { if (family == "ipv6" || family == "") && ipam.IPv6Allocator != nil { ipv6, err = ipam.AllocateNextFamily(IPv6, owner) if err != nil { return } } if (family == "ipv4" || family == "") && ipam.IPv4Allocator != nil { ipv4, err = ipam.AllocateNextFamily(IPv4, owner) if err != nil { if ipv6 != nil { ipam.ReleaseIP(ipv6) } return } } return }
[ "func", "(", "ipam", "*", "IPAM", ")", "AllocateNext", "(", "family", ",", "owner", "string", ")", "(", "ipv4", "net", ".", "IP", ",", "ipv6", "net", ".", "IP", ",", "err", "error", ")", "{", "if", "(", "family", "==", "\"", "\"", "||", "family", "==", "\"", "\"", ")", "&&", "ipam", ".", "IPv6Allocator", "!=", "nil", "{", "ipv6", ",", "err", "=", "ipam", ".", "AllocateNextFamily", "(", "IPv6", ",", "owner", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "}", "\n\n", "if", "(", "family", "==", "\"", "\"", "||", "family", "==", "\"", "\"", ")", "&&", "ipam", ".", "IPv4Allocator", "!=", "nil", "{", "ipv4", ",", "err", "=", "ipam", ".", "AllocateNextFamily", "(", "IPv4", ",", "owner", ")", "\n", "if", "err", "!=", "nil", "{", "if", "ipv6", "!=", "nil", "{", "ipam", ".", "ReleaseIP", "(", "ipv6", ")", "\n", "}", "\n", "return", "\n", "}", "\n", "}", "\n\n", "return", "\n", "}" ]
// AllocateNext allocates the next available IPv4 and IPv6 address out of the // configured address pool. If family is set to "ipv4" or "ipv6", then // allocation is limited to the specified address family. If the pool has been // drained of addresses, an error will be returned.
[ "AllocateNext", "allocates", "the", "next", "available", "IPv4", "and", "IPv6", "address", "out", "of", "the", "configured", "address", "pool", ".", "If", "family", "is", "set", "to", "ipv4", "or", "ipv6", "then", "allocation", "is", "limited", "to", "the", "specified", "address", "family", ".", "If", "the", "pool", "has", "been", "drained", "of", "addresses", "an", "error", "will", "be", "returned", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipam/allocator.go#L128-L148
163,527
cilium/cilium
pkg/ipam/allocator.go
ReleaseIP
func (ipam *IPAM) ReleaseIP(ip net.IP) error { ipam.allocatorMutex.Lock() defer ipam.allocatorMutex.Unlock() family := familyIPv4 if ip.To4() != nil { if ipam.IPv4Allocator == nil { return ErrIPv4Disabled } if err := ipam.IPv4Allocator.Release(ip); err != nil { return err } } else { family = familyIPv6 if ipam.IPv6Allocator == nil { return ErrIPv6Disabled } if err := ipam.IPv6Allocator.Release(ip); err != nil { return err } } owner := ipam.owner[ip.String()] log.WithFields(logrus.Fields{ "ip": ip.String(), "owner": owner, }).Debugf("Released IP") delete(ipam.owner, ip.String()) metrics.IpamEvent.WithLabelValues(metricRelease, family).Inc() return nil }
go
func (ipam *IPAM) ReleaseIP(ip net.IP) error { ipam.allocatorMutex.Lock() defer ipam.allocatorMutex.Unlock() family := familyIPv4 if ip.To4() != nil { if ipam.IPv4Allocator == nil { return ErrIPv4Disabled } if err := ipam.IPv4Allocator.Release(ip); err != nil { return err } } else { family = familyIPv6 if ipam.IPv6Allocator == nil { return ErrIPv6Disabled } if err := ipam.IPv6Allocator.Release(ip); err != nil { return err } } owner := ipam.owner[ip.String()] log.WithFields(logrus.Fields{ "ip": ip.String(), "owner": owner, }).Debugf("Released IP") delete(ipam.owner, ip.String()) metrics.IpamEvent.WithLabelValues(metricRelease, family).Inc() return nil }
[ "func", "(", "ipam", "*", "IPAM", ")", "ReleaseIP", "(", "ip", "net", ".", "IP", ")", "error", "{", "ipam", ".", "allocatorMutex", ".", "Lock", "(", ")", "\n", "defer", "ipam", ".", "allocatorMutex", ".", "Unlock", "(", ")", "\n", "family", ":=", "familyIPv4", "\n", "if", "ip", ".", "To4", "(", ")", "!=", "nil", "{", "if", "ipam", ".", "IPv4Allocator", "==", "nil", "{", "return", "ErrIPv4Disabled", "\n", "}", "\n\n", "if", "err", ":=", "ipam", ".", "IPv4Allocator", ".", "Release", "(", "ip", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "else", "{", "family", "=", "familyIPv6", "\n", "if", "ipam", ".", "IPv6Allocator", "==", "nil", "{", "return", "ErrIPv6Disabled", "\n", "}", "\n\n", "if", "err", ":=", "ipam", ".", "IPv6Allocator", ".", "Release", "(", "ip", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "owner", ":=", "ipam", ".", "owner", "[", "ip", ".", "String", "(", ")", "]", "\n", "log", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "\"", "\"", ":", "ip", ".", "String", "(", ")", ",", "\"", "\"", ":", "owner", ",", "}", ")", ".", "Debugf", "(", "\"", "\"", ")", "\n", "delete", "(", "ipam", ".", "owner", ",", "ip", ".", "String", "(", ")", ")", "\n\n", "metrics", ".", "IpamEvent", ".", "WithLabelValues", "(", "metricRelease", ",", "family", ")", ".", "Inc", "(", ")", "\n", "return", "nil", "\n", "}" ]
// ReleaseIP release a IP address.
[ "ReleaseIP", "release", "a", "IP", "address", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipam/allocator.go#L151-L183
163,528
cilium/cilium
pkg/ipam/allocator.go
ReleaseIPString
func (ipam *IPAM) ReleaseIPString(ipAddr string) error { ip := net.ParseIP(ipAddr) if ip == nil { return fmt.Errorf("Invalid IP address: %s", ipAddr) } return ipam.ReleaseIP(ip) }
go
func (ipam *IPAM) ReleaseIPString(ipAddr string) error { ip := net.ParseIP(ipAddr) if ip == nil { return fmt.Errorf("Invalid IP address: %s", ipAddr) } return ipam.ReleaseIP(ip) }
[ "func", "(", "ipam", "*", "IPAM", ")", "ReleaseIPString", "(", "ipAddr", "string", ")", "error", "{", "ip", ":=", "net", ".", "ParseIP", "(", "ipAddr", ")", "\n", "if", "ip", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ipAddr", ")", "\n", "}", "\n\n", "return", "ipam", ".", "ReleaseIP", "(", "ip", ")", "\n", "}" ]
// ReleaseIPString is identical to ReleaseIP but takes a string
[ "ReleaseIPString", "is", "identical", "to", "ReleaseIP", "but", "takes", "a", "string" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipam/allocator.go#L186-L193
163,529
cilium/cilium
pkg/ipam/allocator.go
Dump
func (ipam *IPAM) Dump() (map[string]string, map[string]string) { ipam.allocatorMutex.RLock() defer ipam.allocatorMutex.RUnlock() allocv4 := map[string]string{} ralv4 := k8sAPI.RangeAllocation{} if ipam.IPv4Allocator != nil { ipam.IPv4Allocator.Snapshot(&ralv4) origIP := big.NewInt(0).SetBytes(ipam.nodeAddressing.IPv4().AllocationCIDR().IP.To4()) v4Bits := big.NewInt(0).SetBytes(ralv4.Data) for i := 0; i < v4Bits.BitLen(); i++ { if v4Bits.Bit(i) != 0 { ip := net.IP(big.NewInt(0).Add(origIP, big.NewInt(int64(uint(i+1)))).Bytes()).String() owner, _ := ipam.owner[ip] // If owner is not available, report IP but leave owner empty allocv4[ip] = owner } } } allocv6 := map[string]string{} ralv6 := k8sAPI.RangeAllocation{} if ipam.IPv6Allocator != nil { ipam.IPv6Allocator.Snapshot(&ralv6) origIP := big.NewInt(0).SetBytes(ipam.nodeAddressing.IPv6().AllocationCIDR().IP) v6Bits := big.NewInt(0).SetBytes(ralv6.Data) for i := 0; i < v6Bits.BitLen(); i++ { if v6Bits.Bit(i) != 0 { ip := net.IP(big.NewInt(0).Add(origIP, big.NewInt(int64(uint(i+1)))).Bytes()).String() owner, _ := ipam.owner[ip] // If owner is not available, report IP but leave owner empty allocv6[ip] = owner } } } return allocv4, allocv6 }
go
func (ipam *IPAM) Dump() (map[string]string, map[string]string) { ipam.allocatorMutex.RLock() defer ipam.allocatorMutex.RUnlock() allocv4 := map[string]string{} ralv4 := k8sAPI.RangeAllocation{} if ipam.IPv4Allocator != nil { ipam.IPv4Allocator.Snapshot(&ralv4) origIP := big.NewInt(0).SetBytes(ipam.nodeAddressing.IPv4().AllocationCIDR().IP.To4()) v4Bits := big.NewInt(0).SetBytes(ralv4.Data) for i := 0; i < v4Bits.BitLen(); i++ { if v4Bits.Bit(i) != 0 { ip := net.IP(big.NewInt(0).Add(origIP, big.NewInt(int64(uint(i+1)))).Bytes()).String() owner, _ := ipam.owner[ip] // If owner is not available, report IP but leave owner empty allocv4[ip] = owner } } } allocv6 := map[string]string{} ralv6 := k8sAPI.RangeAllocation{} if ipam.IPv6Allocator != nil { ipam.IPv6Allocator.Snapshot(&ralv6) origIP := big.NewInt(0).SetBytes(ipam.nodeAddressing.IPv6().AllocationCIDR().IP) v6Bits := big.NewInt(0).SetBytes(ralv6.Data) for i := 0; i < v6Bits.BitLen(); i++ { if v6Bits.Bit(i) != 0 { ip := net.IP(big.NewInt(0).Add(origIP, big.NewInt(int64(uint(i+1)))).Bytes()).String() owner, _ := ipam.owner[ip] // If owner is not available, report IP but leave owner empty allocv6[ip] = owner } } } return allocv4, allocv6 }
[ "func", "(", "ipam", "*", "IPAM", ")", "Dump", "(", ")", "(", "map", "[", "string", "]", "string", ",", "map", "[", "string", "]", "string", ")", "{", "ipam", ".", "allocatorMutex", ".", "RLock", "(", ")", "\n", "defer", "ipam", ".", "allocatorMutex", ".", "RUnlock", "(", ")", "\n\n", "allocv4", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "ralv4", ":=", "k8sAPI", ".", "RangeAllocation", "{", "}", "\n", "if", "ipam", ".", "IPv4Allocator", "!=", "nil", "{", "ipam", ".", "IPv4Allocator", ".", "Snapshot", "(", "&", "ralv4", ")", "\n", "origIP", ":=", "big", ".", "NewInt", "(", "0", ")", ".", "SetBytes", "(", "ipam", ".", "nodeAddressing", ".", "IPv4", "(", ")", ".", "AllocationCIDR", "(", ")", ".", "IP", ".", "To4", "(", ")", ")", "\n", "v4Bits", ":=", "big", ".", "NewInt", "(", "0", ")", ".", "SetBytes", "(", "ralv4", ".", "Data", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "v4Bits", ".", "BitLen", "(", ")", ";", "i", "++", "{", "if", "v4Bits", ".", "Bit", "(", "i", ")", "!=", "0", "{", "ip", ":=", "net", ".", "IP", "(", "big", ".", "NewInt", "(", "0", ")", ".", "Add", "(", "origIP", ",", "big", ".", "NewInt", "(", "int64", "(", "uint", "(", "i", "+", "1", ")", ")", ")", ")", ".", "Bytes", "(", ")", ")", ".", "String", "(", ")", "\n", "owner", ",", "_", ":=", "ipam", ".", "owner", "[", "ip", "]", "\n", "// If owner is not available, report IP but leave owner empty", "allocv4", "[", "ip", "]", "=", "owner", "\n", "}", "\n", "}", "\n", "}", "\n\n", "allocv6", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "ralv6", ":=", "k8sAPI", ".", "RangeAllocation", "{", "}", "\n", "if", "ipam", ".", "IPv6Allocator", "!=", "nil", "{", "ipam", ".", "IPv6Allocator", ".", "Snapshot", "(", "&", "ralv6", ")", "\n", "origIP", ":=", "big", ".", "NewInt", "(", "0", ")", ".", "SetBytes", "(", "ipam", ".", "nodeAddressing", ".", "IPv6", "(", ")", ".", "AllocationCIDR", "(", ")", ".", "IP", ")", "\n", "v6Bits", ":=", "big", ".", "NewInt", "(", "0", ")", ".", "SetBytes", "(", "ralv6", ".", "Data", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "v6Bits", ".", "BitLen", "(", ")", ";", "i", "++", "{", "if", "v6Bits", ".", "Bit", "(", "i", ")", "!=", "0", "{", "ip", ":=", "net", ".", "IP", "(", "big", ".", "NewInt", "(", "0", ")", ".", "Add", "(", "origIP", ",", "big", ".", "NewInt", "(", "int64", "(", "uint", "(", "i", "+", "1", ")", ")", ")", ")", ".", "Bytes", "(", ")", ")", ".", "String", "(", ")", "\n", "owner", ",", "_", ":=", "ipam", ".", "owner", "[", "ip", "]", "\n", "// If owner is not available, report IP but leave owner empty", "allocv6", "[", "ip", "]", "=", "owner", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "allocv4", ",", "allocv6", "\n", "}" ]
// Dump dumps the list of allocated IP addresses
[ "Dump", "dumps", "the", "list", "of", "allocated", "IP", "addresses" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipam/allocator.go#L196-L233
163,530
cilium/cilium
pkg/spanstat/spanstat.go
End
func (s *SpanStat) End(success bool) *SpanStat { if !s.spanStart.IsZero() { d, _ := safetime.TimeSinceSafe(s.spanStart, log) if success { s.successDuration += d } else { s.failureDuration += d } } s.spanStart = time.Time{} return s }
go
func (s *SpanStat) End(success bool) *SpanStat { if !s.spanStart.IsZero() { d, _ := safetime.TimeSinceSafe(s.spanStart, log) if success { s.successDuration += d } else { s.failureDuration += d } } s.spanStart = time.Time{} return s }
[ "func", "(", "s", "*", "SpanStat", ")", "End", "(", "success", "bool", ")", "*", "SpanStat", "{", "if", "!", "s", ".", "spanStart", ".", "IsZero", "(", ")", "{", "d", ",", "_", ":=", "safetime", ".", "TimeSinceSafe", "(", "s", ".", "spanStart", ",", "log", ")", "\n", "if", "success", "{", "s", ".", "successDuration", "+=", "d", "\n", "}", "else", "{", "s", ".", "failureDuration", "+=", "d", "\n", "}", "\n", "}", "\n", "s", ".", "spanStart", "=", "time", ".", "Time", "{", "}", "\n", "return", "s", "\n", "}" ]
// End ends the current span and adds the measured duration to the total // cumulated duration, and to the success or failure cumulated duration // depending on the given success flag
[ "End", "ends", "the", "current", "span", "and", "adds", "the", "measured", "duration", "to", "the", "total", "cumulated", "duration", "and", "to", "the", "success", "or", "failure", "cumulated", "duration", "depending", "on", "the", "given", "success", "flag" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/spanstat/spanstat.go#L58-L69
163,531
cilium/cilium
pkg/k8s/types/zz_generated.deepcopy.go
DeepCopy
func (in *SlimCNP) DeepCopy() *SlimCNP { if in == nil { return nil } out := new(SlimCNP) in.DeepCopyInto(out) return out }
go
func (in *SlimCNP) DeepCopy() *SlimCNP { if in == nil { return nil } out := new(SlimCNP) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "SlimCNP", ")", "DeepCopy", "(", ")", "*", "SlimCNP", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "SlimCNP", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SlimCNP.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "SlimCNP", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/types/zz_generated.deepcopy.go#L240-L247
163,532
cilium/cilium
pkg/k8s/client/informers/externalversions/cilium.io/v2/ciliumnetworkpolicy.go
NewCiliumNetworkPolicyInformer
func NewCiliumNetworkPolicyInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredCiliumNetworkPolicyInformer(client, namespace, resyncPeriod, indexers, nil) }
go
func NewCiliumNetworkPolicyInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { return NewFilteredCiliumNetworkPolicyInformer(client, namespace, resyncPeriod, indexers, nil) }
[ "func", "NewCiliumNetworkPolicyInformer", "(", "client", "versioned", ".", "Interface", ",", "namespace", "string", ",", "resyncPeriod", "time", ".", "Duration", ",", "indexers", "cache", ".", "Indexers", ")", "cache", ".", "SharedIndexInformer", "{", "return", "NewFilteredCiliumNetworkPolicyInformer", "(", "client", ",", "namespace", ",", "resyncPeriod", ",", "indexers", ",", "nil", ")", "\n", "}" ]
// NewCiliumNetworkPolicyInformer constructs a new informer for CiliumNetworkPolicy type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server.
[ "NewCiliumNetworkPolicyInformer", "constructs", "a", "new", "informer", "for", "CiliumNetworkPolicy", "type", ".", "Always", "prefer", "using", "an", "informer", "factory", "to", "get", "a", "shared", "informer", "instead", "of", "getting", "an", "independent", "one", ".", "This", "reduces", "memory", "footprint", "and", "number", "of", "connections", "to", "the", "server", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/informers/externalversions/cilium.io/v2/ciliumnetworkpolicy.go#L48-L50
163,533
cilium/cilium
pkg/k8s/client/informers/externalversions/cilium.io/v2/ciliumnetworkpolicy.go
NewFilteredCiliumNetworkPolicyInformer
func NewFilteredCiliumNetworkPolicyInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } return client.CiliumV2().CiliumNetworkPolicies(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } return client.CiliumV2().CiliumNetworkPolicies(namespace).Watch(options) }, }, &ciliumiov2.CiliumNetworkPolicy{}, resyncPeriod, indexers, ) }
go
func NewFilteredCiliumNetworkPolicyInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { return cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options v1.ListOptions) (runtime.Object, error) { if tweakListOptions != nil { tweakListOptions(&options) } return client.CiliumV2().CiliumNetworkPolicies(namespace).List(options) }, WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { if tweakListOptions != nil { tweakListOptions(&options) } return client.CiliumV2().CiliumNetworkPolicies(namespace).Watch(options) }, }, &ciliumiov2.CiliumNetworkPolicy{}, resyncPeriod, indexers, ) }
[ "func", "NewFilteredCiliumNetworkPolicyInformer", "(", "client", "versioned", ".", "Interface", ",", "namespace", "string", ",", "resyncPeriod", "time", ".", "Duration", ",", "indexers", "cache", ".", "Indexers", ",", "tweakListOptions", "internalinterfaces", ".", "TweakListOptionsFunc", ")", "cache", ".", "SharedIndexInformer", "{", "return", "cache", ".", "NewSharedIndexInformer", "(", "&", "cache", ".", "ListWatch", "{", "ListFunc", ":", "func", "(", "options", "v1", ".", "ListOptions", ")", "(", "runtime", ".", "Object", ",", "error", ")", "{", "if", "tweakListOptions", "!=", "nil", "{", "tweakListOptions", "(", "&", "options", ")", "\n", "}", "\n", "return", "client", ".", "CiliumV2", "(", ")", ".", "CiliumNetworkPolicies", "(", "namespace", ")", ".", "List", "(", "options", ")", "\n", "}", ",", "WatchFunc", ":", "func", "(", "options", "v1", ".", "ListOptions", ")", "(", "watch", ".", "Interface", ",", "error", ")", "{", "if", "tweakListOptions", "!=", "nil", "{", "tweakListOptions", "(", "&", "options", ")", "\n", "}", "\n", "return", "client", ".", "CiliumV2", "(", ")", ".", "CiliumNetworkPolicies", "(", "namespace", ")", ".", "Watch", "(", "options", ")", "\n", "}", ",", "}", ",", "&", "ciliumiov2", ".", "CiliumNetworkPolicy", "{", "}", ",", "resyncPeriod", ",", "indexers", ",", ")", "\n", "}" ]
// NewFilteredCiliumNetworkPolicyInformer constructs a new informer for CiliumNetworkPolicy type. // Always prefer using an informer factory to get a shared informer instead of getting an independent // one. This reduces memory footprint and number of connections to the server.
[ "NewFilteredCiliumNetworkPolicyInformer", "constructs", "a", "new", "informer", "for", "CiliumNetworkPolicy", "type", ".", "Always", "prefer", "using", "an", "informer", "factory", "to", "get", "a", "shared", "informer", "instead", "of", "getting", "an", "independent", "one", ".", "This", "reduces", "memory", "footprint", "and", "number", "of", "connections", "to", "the", "server", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/informers/externalversions/cilium.io/v2/ciliumnetworkpolicy.go#L55-L75
163,534
cilium/cilium
pkg/kvstore/client.go
NewClient
func NewClient(selectedBackend string, opts map[string]string, options *ExtraOptions) (BackendOperations, chan error) { // Channel used to report immediate errors, module.newClient will // create and return a different channel, caller doesn't need to know errChan := make(chan error, 1) defer close(errChan) module := getBackend(selectedBackend) if module == nil { errChan <- fmt.Errorf("unknown key-value store type %q. See cilium.link/err-kvstore for details", selectedBackend) return nil, errChan } if err := module.setConfig(opts); err != nil { errChan <- err return nil, errChan } if err := module.setExtraConfig(options); err != nil { errChan <- err return nil, errChan } return module.newClient(options) }
go
func NewClient(selectedBackend string, opts map[string]string, options *ExtraOptions) (BackendOperations, chan error) { // Channel used to report immediate errors, module.newClient will // create and return a different channel, caller doesn't need to know errChan := make(chan error, 1) defer close(errChan) module := getBackend(selectedBackend) if module == nil { errChan <- fmt.Errorf("unknown key-value store type %q. See cilium.link/err-kvstore for details", selectedBackend) return nil, errChan } if err := module.setConfig(opts); err != nil { errChan <- err return nil, errChan } if err := module.setExtraConfig(options); err != nil { errChan <- err return nil, errChan } return module.newClient(options) }
[ "func", "NewClient", "(", "selectedBackend", "string", ",", "opts", "map", "[", "string", "]", "string", ",", "options", "*", "ExtraOptions", ")", "(", "BackendOperations", ",", "chan", "error", ")", "{", "// Channel used to report immediate errors, module.newClient will", "// create and return a different channel, caller doesn't need to know", "errChan", ":=", "make", "(", "chan", "error", ",", "1", ")", "\n", "defer", "close", "(", "errChan", ")", "\n\n", "module", ":=", "getBackend", "(", "selectedBackend", ")", "\n", "if", "module", "==", "nil", "{", "errChan", "<-", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "selectedBackend", ")", "\n", "return", "nil", ",", "errChan", "\n", "}", "\n\n", "if", "err", ":=", "module", ".", "setConfig", "(", "opts", ")", ";", "err", "!=", "nil", "{", "errChan", "<-", "err", "\n", "return", "nil", ",", "errChan", "\n", "}", "\n\n", "if", "err", ":=", "module", ".", "setExtraConfig", "(", "options", ")", ";", "err", "!=", "nil", "{", "errChan", "<-", "err", "\n", "return", "nil", ",", "errChan", "\n", "}", "\n\n", "return", "module", ".", "newClient", "(", "options", ")", "\n", "}" ]
// NewClient returns a new kvstore client based on the configuration
[ "NewClient", "returns", "a", "new", "kvstore", "client", "based", "on", "the", "configuration" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/client.go#L62-L85
163,535
cilium/cilium
pkg/policy/rules.go
updateEndpointsCaches
func (rules ruleSlice) updateEndpointsCaches(ep Endpoint, epIDSet *IDSet) (bool, error) { if ep == nil { return false, fmt.Errorf("cannot update caches in rules because endpoint is nil") } id := ep.GetID16() if err := ep.RLockAlive(); err != nil { return false, fmt.Errorf("cannnot update caches in rules for endpoint %d because it is being deleted: %s", id, err) } defer ep.RUnlock() securityIdentity := ep.GetSecurityIdentity() if securityIdentity == nil { return false, fmt.Errorf("cannot update caches in rules for endpoint %d because it has a nil identity", id) } for _, r := range rules { if ruleMatches := r.matches(securityIdentity); ruleMatches { epIDSet.Mutex.Lock() epIDSet.IDs[id] = struct{}{} epIDSet.Mutex.Unlock() // If epIDSet is updated, we can exit since updating it again if // another rule selects the Endpoint is a no-op. return true, nil } } return false, nil }
go
func (rules ruleSlice) updateEndpointsCaches(ep Endpoint, epIDSet *IDSet) (bool, error) { if ep == nil { return false, fmt.Errorf("cannot update caches in rules because endpoint is nil") } id := ep.GetID16() if err := ep.RLockAlive(); err != nil { return false, fmt.Errorf("cannnot update caches in rules for endpoint %d because it is being deleted: %s", id, err) } defer ep.RUnlock() securityIdentity := ep.GetSecurityIdentity() if securityIdentity == nil { return false, fmt.Errorf("cannot update caches in rules for endpoint %d because it has a nil identity", id) } for _, r := range rules { if ruleMatches := r.matches(securityIdentity); ruleMatches { epIDSet.Mutex.Lock() epIDSet.IDs[id] = struct{}{} epIDSet.Mutex.Unlock() // If epIDSet is updated, we can exit since updating it again if // another rule selects the Endpoint is a no-op. return true, nil } } return false, nil }
[ "func", "(", "rules", "ruleSlice", ")", "updateEndpointsCaches", "(", "ep", "Endpoint", ",", "epIDSet", "*", "IDSet", ")", "(", "bool", ",", "error", ")", "{", "if", "ep", "==", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "id", ":=", "ep", ".", "GetID16", "(", ")", "\n", "if", "err", ":=", "ep", ".", "RLockAlive", "(", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "id", ",", "err", ")", "\n", "}", "\n", "defer", "ep", ".", "RUnlock", "(", ")", "\n", "securityIdentity", ":=", "ep", ".", "GetSecurityIdentity", "(", ")", "\n\n", "if", "securityIdentity", "==", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "id", ")", "\n", "}", "\n\n", "for", "_", ",", "r", ":=", "range", "rules", "{", "if", "ruleMatches", ":=", "r", ".", "matches", "(", "securityIdentity", ")", ";", "ruleMatches", "{", "epIDSet", ".", "Mutex", ".", "Lock", "(", ")", "\n", "epIDSet", ".", "IDs", "[", "id", "]", "=", "struct", "{", "}", "{", "}", "\n", "epIDSet", ".", "Mutex", ".", "Unlock", "(", ")", "\n\n", "// If epIDSet is updated, we can exit since updating it again if", "// another rule selects the Endpoint is a no-op.", "return", "true", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "false", ",", "nil", "\n", "}" ]
// updateEndpointsCaches iterates over a given list of rules to update the cache // within the rule which determines whether or not the given identity is // selected by that rule. If a rule in the list does select said identity, it is // added to epIDSet. Note that epIDSet can be shared across goroutines! // Returns whether the endpoint was selected by one of the rules, or if the // endpoint is nil.
[ "updateEndpointsCaches", "iterates", "over", "a", "given", "list", "of", "rules", "to", "update", "the", "cache", "within", "the", "rule", "which", "determines", "whether", "or", "not", "the", "given", "identity", "is", "selected", "by", "that", "rule", ".", "If", "a", "rule", "in", "the", "list", "does", "select", "said", "identity", "it", "is", "added", "to", "epIDSet", ".", "Note", "that", "epIDSet", "can", "be", "shared", "across", "goroutines!", "Returns", "whether", "the", "endpoint", "was", "selected", "by", "one", "of", "the", "rules", "or", "if", "the", "endpoint", "is", "nil", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/rules.go#L363-L391
163,536
cilium/cilium
pkg/envoy/grpc.go
startXDSGRPCServer
func startXDSGRPCServer(listener net.Listener, ldsConfig, npdsConfig, nphdsConfig *xds.ResourceTypeConfiguration, resourceAccessTimeout time.Duration) context.CancelFunc { grpcServer := grpc.NewServer() xdsServer := xds.NewServer(map[string]*xds.ResourceTypeConfiguration{ ListenerTypeURL: ldsConfig, NetworkPolicyTypeURL: npdsConfig, NetworkPolicyHostsTypeURL: nphdsConfig, }, resourceAccessTimeout) dsServer := (*xdsGRPCServer)(xdsServer) // TODO: https://github.com/cilium/cilium/issues/5051 // Implement IncrementalAggregatedResources to support Incremental xDS. //envoy_service_discovery_v2.RegisterAggregatedDiscoveryServiceServer(grpcServer, dsServer) envoy_api_v2.RegisterListenerDiscoveryServiceServer(grpcServer, dsServer) cilium.RegisterNetworkPolicyDiscoveryServiceServer(grpcServer, dsServer) cilium.RegisterNetworkPolicyHostsDiscoveryServiceServer(grpcServer, dsServer) reflection.Register(grpcServer) go func() { log.Infof("Envoy: Starting xDS gRPC server listening on %s", listener.Addr()) if err := grpcServer.Serve(listener); err != nil && !strings.Contains(err.Error(), "closed network connection") { log.WithError(err).Fatal("Envoy: Failed to serve xDS gRPC API") } }() return grpcServer.Stop }
go
func startXDSGRPCServer(listener net.Listener, ldsConfig, npdsConfig, nphdsConfig *xds.ResourceTypeConfiguration, resourceAccessTimeout time.Duration) context.CancelFunc { grpcServer := grpc.NewServer() xdsServer := xds.NewServer(map[string]*xds.ResourceTypeConfiguration{ ListenerTypeURL: ldsConfig, NetworkPolicyTypeURL: npdsConfig, NetworkPolicyHostsTypeURL: nphdsConfig, }, resourceAccessTimeout) dsServer := (*xdsGRPCServer)(xdsServer) // TODO: https://github.com/cilium/cilium/issues/5051 // Implement IncrementalAggregatedResources to support Incremental xDS. //envoy_service_discovery_v2.RegisterAggregatedDiscoveryServiceServer(grpcServer, dsServer) envoy_api_v2.RegisterListenerDiscoveryServiceServer(grpcServer, dsServer) cilium.RegisterNetworkPolicyDiscoveryServiceServer(grpcServer, dsServer) cilium.RegisterNetworkPolicyHostsDiscoveryServiceServer(grpcServer, dsServer) reflection.Register(grpcServer) go func() { log.Infof("Envoy: Starting xDS gRPC server listening on %s", listener.Addr()) if err := grpcServer.Serve(listener); err != nil && !strings.Contains(err.Error(), "closed network connection") { log.WithError(err).Fatal("Envoy: Failed to serve xDS gRPC API") } }() return grpcServer.Stop }
[ "func", "startXDSGRPCServer", "(", "listener", "net", ".", "Listener", ",", "ldsConfig", ",", "npdsConfig", ",", "nphdsConfig", "*", "xds", ".", "ResourceTypeConfiguration", ",", "resourceAccessTimeout", "time", ".", "Duration", ")", "context", ".", "CancelFunc", "{", "grpcServer", ":=", "grpc", ".", "NewServer", "(", ")", "\n\n", "xdsServer", ":=", "xds", ".", "NewServer", "(", "map", "[", "string", "]", "*", "xds", ".", "ResourceTypeConfiguration", "{", "ListenerTypeURL", ":", "ldsConfig", ",", "NetworkPolicyTypeURL", ":", "npdsConfig", ",", "NetworkPolicyHostsTypeURL", ":", "nphdsConfig", ",", "}", ",", "resourceAccessTimeout", ")", "\n", "dsServer", ":=", "(", "*", "xdsGRPCServer", ")", "(", "xdsServer", ")", "\n\n", "// TODO: https://github.com/cilium/cilium/issues/5051", "// Implement IncrementalAggregatedResources to support Incremental xDS.", "//envoy_service_discovery_v2.RegisterAggregatedDiscoveryServiceServer(grpcServer, dsServer)", "envoy_api_v2", ".", "RegisterListenerDiscoveryServiceServer", "(", "grpcServer", ",", "dsServer", ")", "\n", "cilium", ".", "RegisterNetworkPolicyDiscoveryServiceServer", "(", "grpcServer", ",", "dsServer", ")", "\n", "cilium", ".", "RegisterNetworkPolicyHostsDiscoveryServiceServer", "(", "grpcServer", ",", "dsServer", ")", "\n\n", "reflection", ".", "Register", "(", "grpcServer", ")", "\n\n", "go", "func", "(", ")", "{", "log", ".", "Infof", "(", "\"", "\"", ",", "listener", ".", "Addr", "(", ")", ")", "\n", "if", "err", ":=", "grpcServer", ".", "Serve", "(", "listener", ")", ";", "err", "!=", "nil", "&&", "!", "strings", ".", "Contains", "(", "err", ".", "Error", "(", ")", ",", "\"", "\"", ")", "{", "log", ".", "WithError", "(", "err", ")", ".", "Fatal", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "grpcServer", ".", "Stop", "\n", "}" ]
// startXDSGRPCServer starts a gRPC server to serve xDS APIs using the given // resource watcher and network listener. // Returns a function that stops the GRPC server when called.
[ "startXDSGRPCServer", "starts", "a", "gRPC", "server", "to", "serve", "xDS", "APIs", "using", "the", "given", "resource", "watcher", "and", "network", "listener", ".", "Returns", "a", "function", "that", "stops", "the", "GRPC", "server", "when", "called", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/envoy/grpc.go#L42-L69
163,537
cilium/cilium
pkg/bpf/bpf_linux.go
DeleteElement
func DeleteElement(fd int, key unsafe.Pointer) error { ret, err := deleteElement(fd, key) if ret != 0 || err != 0 { return fmt.Errorf("Unable to delete element from map with file descriptor %d: %s", fd, err) } return nil }
go
func DeleteElement(fd int, key unsafe.Pointer) error { ret, err := deleteElement(fd, key) if ret != 0 || err != 0 { return fmt.Errorf("Unable to delete element from map with file descriptor %d: %s", fd, err) } return nil }
[ "func", "DeleteElement", "(", "fd", "int", ",", "key", "unsafe", ".", "Pointer", ")", "error", "{", "ret", ",", "err", ":=", "deleteElement", "(", "fd", ",", "key", ")", "\n\n", "if", "ret", "!=", "0", "||", "err", "!=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "fd", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// DeleteElement deletes the map element with the given key.
[ "DeleteElement", "deletes", "the", "map", "element", "with", "the", "given", "key", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/bpf/bpf_linux.go#L165-L173
163,538
cilium/cilium
pkg/bpf/bpf_linux.go
ObjPin
func ObjPin(fd int, pathname string) error { pathStr := C.CString(pathname) defer C.free(unsafe.Pointer(pathStr)) uba := bpfAttrObjOp{ pathname: uint64(uintptr(unsafe.Pointer(pathStr))), fd: uint32(fd), } duration := spanstat.Start() ret, _, err := unix.Syscall( unix.SYS_BPF, BPF_OBJ_PIN, uintptr(unsafe.Pointer(&uba)), unsafe.Sizeof(uba), ) metricSyscallDuration.WithLabelValues(metricOpObjPin, metrics.Errno2Outcome(err)).Observe(duration.End(err == 0).Total().Seconds()) if ret != 0 || err != 0 { return fmt.Errorf("Unable to pin object with file descriptor %d to %s: %s", fd, pathname, err) } return nil }
go
func ObjPin(fd int, pathname string) error { pathStr := C.CString(pathname) defer C.free(unsafe.Pointer(pathStr)) uba := bpfAttrObjOp{ pathname: uint64(uintptr(unsafe.Pointer(pathStr))), fd: uint32(fd), } duration := spanstat.Start() ret, _, err := unix.Syscall( unix.SYS_BPF, BPF_OBJ_PIN, uintptr(unsafe.Pointer(&uba)), unsafe.Sizeof(uba), ) metricSyscallDuration.WithLabelValues(metricOpObjPin, metrics.Errno2Outcome(err)).Observe(duration.End(err == 0).Total().Seconds()) if ret != 0 || err != 0 { return fmt.Errorf("Unable to pin object with file descriptor %d to %s: %s", fd, pathname, err) } return nil }
[ "func", "ObjPin", "(", "fd", "int", ",", "pathname", "string", ")", "error", "{", "pathStr", ":=", "C", ".", "CString", "(", "pathname", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "pathStr", ")", ")", "\n", "uba", ":=", "bpfAttrObjOp", "{", "pathname", ":", "uint64", "(", "uintptr", "(", "unsafe", ".", "Pointer", "(", "pathStr", ")", ")", ")", ",", "fd", ":", "uint32", "(", "fd", ")", ",", "}", "\n\n", "duration", ":=", "spanstat", ".", "Start", "(", ")", "\n", "ret", ",", "_", ",", "err", ":=", "unix", ".", "Syscall", "(", "unix", ".", "SYS_BPF", ",", "BPF_OBJ_PIN", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "&", "uba", ")", ")", ",", "unsafe", ".", "Sizeof", "(", "uba", ")", ",", ")", "\n", "metricSyscallDuration", ".", "WithLabelValues", "(", "metricOpObjPin", ",", "metrics", ".", "Errno2Outcome", "(", "err", ")", ")", ".", "Observe", "(", "duration", ".", "End", "(", "err", "==", "0", ")", ".", "Total", "(", ")", ".", "Seconds", "(", ")", ")", "\n\n", "if", "ret", "!=", "0", "||", "err", "!=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "fd", ",", "pathname", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ObjPin stores the map's fd in pathname.
[ "ObjPin", "stores", "the", "map", "s", "fd", "in", "pathname", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/bpf/bpf_linux.go#L207-L229
163,539
cilium/cilium
pkg/bpf/bpf_linux.go
ObjGet
func ObjGet(pathname string) (int, error) { pathStr := C.CString(pathname) defer C.free(unsafe.Pointer(pathStr)) uba := bpfAttrObjOp{ pathname: uint64(uintptr(unsafe.Pointer(pathStr))), } duration := spanstat.Start() fd, _, err := unix.Syscall( unix.SYS_BPF, BPF_OBJ_GET, uintptr(unsafe.Pointer(&uba)), unsafe.Sizeof(uba), ) metricSyscallDuration.WithLabelValues(metricOpObjGet, metrics.Errno2Outcome(err)).Observe(duration.End(err == 0).Total().Seconds()) if fd == 0 || err != 0 { return 0, &os.PathError{ Op: "Unable to get object", Err: err, Path: pathname, } } return int(fd), nil }
go
func ObjGet(pathname string) (int, error) { pathStr := C.CString(pathname) defer C.free(unsafe.Pointer(pathStr)) uba := bpfAttrObjOp{ pathname: uint64(uintptr(unsafe.Pointer(pathStr))), } duration := spanstat.Start() fd, _, err := unix.Syscall( unix.SYS_BPF, BPF_OBJ_GET, uintptr(unsafe.Pointer(&uba)), unsafe.Sizeof(uba), ) metricSyscallDuration.WithLabelValues(metricOpObjGet, metrics.Errno2Outcome(err)).Observe(duration.End(err == 0).Total().Seconds()) if fd == 0 || err != 0 { return 0, &os.PathError{ Op: "Unable to get object", Err: err, Path: pathname, } } return int(fd), nil }
[ "func", "ObjGet", "(", "pathname", "string", ")", "(", "int", ",", "error", ")", "{", "pathStr", ":=", "C", ".", "CString", "(", "pathname", ")", "\n", "defer", "C", ".", "free", "(", "unsafe", ".", "Pointer", "(", "pathStr", ")", ")", "\n", "uba", ":=", "bpfAttrObjOp", "{", "pathname", ":", "uint64", "(", "uintptr", "(", "unsafe", ".", "Pointer", "(", "pathStr", ")", ")", ")", ",", "}", "\n\n", "duration", ":=", "spanstat", ".", "Start", "(", ")", "\n", "fd", ",", "_", ",", "err", ":=", "unix", ".", "Syscall", "(", "unix", ".", "SYS_BPF", ",", "BPF_OBJ_GET", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "&", "uba", ")", ")", ",", "unsafe", ".", "Sizeof", "(", "uba", ")", ",", ")", "\n", "metricSyscallDuration", ".", "WithLabelValues", "(", "metricOpObjGet", ",", "metrics", ".", "Errno2Outcome", "(", "err", ")", ")", ".", "Observe", "(", "duration", ".", "End", "(", "err", "==", "0", ")", ".", "Total", "(", ")", ".", "Seconds", "(", ")", ")", "\n\n", "if", "fd", "==", "0", "||", "err", "!=", "0", "{", "return", "0", ",", "&", "os", ".", "PathError", "{", "Op", ":", "\"", "\"", ",", "Err", ":", "err", ",", "Path", ":", "pathname", ",", "}", "\n", "}", "\n\n", "return", "int", "(", "fd", ")", ",", "nil", "\n", "}" ]
// ObjGet reads the pathname and returns the map's fd read.
[ "ObjGet", "reads", "the", "pathname", "and", "returns", "the", "map", "s", "fd", "read", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/bpf/bpf_linux.go#L232-L257
163,540
cilium/cilium
pkg/bpf/bpf_linux.go
MapFdFromID
func MapFdFromID(id int) (int, error) { uba := bpfAttrFdFromId{ ID: uint32(id), } duration := spanstat.Start() fd, _, err := unix.Syscall( unix.SYS_BPF, BPF_MAP_GET_FD_BY_ID, uintptr(unsafe.Pointer(&uba)), unsafe.Sizeof(uba), ) metricSyscallDuration.WithLabelValues(metricOpGetFDByID, metrics.Errno2Outcome(err)).Observe(duration.End(err == 0).Total().Seconds()) if fd == 0 || err != 0 { return 0, fmt.Errorf("Unable to get object fd from id %d: %s", id, err) } return int(fd), nil }
go
func MapFdFromID(id int) (int, error) { uba := bpfAttrFdFromId{ ID: uint32(id), } duration := spanstat.Start() fd, _, err := unix.Syscall( unix.SYS_BPF, BPF_MAP_GET_FD_BY_ID, uintptr(unsafe.Pointer(&uba)), unsafe.Sizeof(uba), ) metricSyscallDuration.WithLabelValues(metricOpGetFDByID, metrics.Errno2Outcome(err)).Observe(duration.End(err == 0).Total().Seconds()) if fd == 0 || err != 0 { return 0, fmt.Errorf("Unable to get object fd from id %d: %s", id, err) } return int(fd), nil }
[ "func", "MapFdFromID", "(", "id", "int", ")", "(", "int", ",", "error", ")", "{", "uba", ":=", "bpfAttrFdFromId", "{", "ID", ":", "uint32", "(", "id", ")", ",", "}", "\n\n", "duration", ":=", "spanstat", ".", "Start", "(", ")", "\n", "fd", ",", "_", ",", "err", ":=", "unix", ".", "Syscall", "(", "unix", ".", "SYS_BPF", ",", "BPF_MAP_GET_FD_BY_ID", ",", "uintptr", "(", "unsafe", ".", "Pointer", "(", "&", "uba", ")", ")", ",", "unsafe", ".", "Sizeof", "(", "uba", ")", ",", ")", "\n", "metricSyscallDuration", ".", "WithLabelValues", "(", "metricOpGetFDByID", ",", "metrics", ".", "Errno2Outcome", "(", "err", ")", ")", ".", "Observe", "(", "duration", ".", "End", "(", "err", "==", "0", ")", ".", "Total", "(", ")", ".", "Seconds", "(", ")", ")", "\n\n", "if", "fd", "==", "0", "||", "err", "!=", "0", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "id", ",", "err", ")", "\n", "}", "\n\n", "return", "int", "(", "fd", ")", ",", "nil", "\n", "}" ]
// MapFdFromID retrieves a file descriptor based on a map ID.
[ "MapFdFromID", "retrieves", "a", "file", "descriptor", "based", "on", "a", "map", "ID", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/bpf/bpf_linux.go#L266-L285
163,541
cilium/cilium
api/v1/server/restapi/endpoint/get_endpoint_id_config.go
NewGetEndpointIDConfig
func NewGetEndpointIDConfig(ctx *middleware.Context, handler GetEndpointIDConfigHandler) *GetEndpointIDConfig { return &GetEndpointIDConfig{Context: ctx, Handler: handler} }
go
func NewGetEndpointIDConfig(ctx *middleware.Context, handler GetEndpointIDConfigHandler) *GetEndpointIDConfig { return &GetEndpointIDConfig{Context: ctx, Handler: handler} }
[ "func", "NewGetEndpointIDConfig", "(", "ctx", "*", "middleware", ".", "Context", ",", "handler", "GetEndpointIDConfigHandler", ")", "*", "GetEndpointIDConfig", "{", "return", "&", "GetEndpointIDConfig", "{", "Context", ":", "ctx", ",", "Handler", ":", "handler", "}", "\n", "}" ]
// NewGetEndpointIDConfig creates a new http.Handler for the get endpoint ID config operation
[ "NewGetEndpointIDConfig", "creates", "a", "new", "http", ".", "Handler", "for", "the", "get", "endpoint", "ID", "config", "operation" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/endpoint/get_endpoint_id_config.go#L28-L30
163,542
cilium/cilium
pkg/policy/api/l4.go
Covers
func (p PortProtocol) Covers(other PortProtocol) bool { if p.Port != other.Port { return false } if p.Protocol != other.Protocol { return p.Protocol == "" || p.Protocol == ProtoAny } return true }
go
func (p PortProtocol) Covers(other PortProtocol) bool { if p.Port != other.Port { return false } if p.Protocol != other.Protocol { return p.Protocol == "" || p.Protocol == ProtoAny } return true }
[ "func", "(", "p", "PortProtocol", ")", "Covers", "(", "other", "PortProtocol", ")", "bool", "{", "if", "p", ".", "Port", "!=", "other", ".", "Port", "{", "return", "false", "\n", "}", "\n", "if", "p", ".", "Protocol", "!=", "other", ".", "Protocol", "{", "return", "p", ".", "Protocol", "==", "\"", "\"", "||", "p", ".", "Protocol", "==", "ProtoAny", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Covers returns true if the ports and protocol specified in the received // PortProtocol are equal to or a superset of the ports and protocol in 'other'.
[ "Covers", "returns", "true", "if", "the", "ports", "and", "protocol", "specified", "in", "the", "received", "PortProtocol", "are", "equal", "to", "or", "a", "superset", "of", "the", "ports", "and", "protocol", "in", "other", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/l4.go#L46-L54
163,543
cilium/cilium
pkg/policy/api/l4.go
Len
func (rules *L7Rules) Len() int { if rules == nil { return 0 } return len(rules.HTTP) + len(rules.Kafka) + len(rules.DNS) + len(rules.L7) }
go
func (rules *L7Rules) Len() int { if rules == nil { return 0 } return len(rules.HTTP) + len(rules.Kafka) + len(rules.DNS) + len(rules.L7) }
[ "func", "(", "rules", "*", "L7Rules", ")", "Len", "(", ")", "int", "{", "if", "rules", "==", "nil", "{", "return", "0", "\n", "}", "\n", "return", "len", "(", "rules", ".", "HTTP", ")", "+", "len", "(", "rules", ".", "Kafka", ")", "+", "len", "(", "rules", ".", "DNS", ")", "+", "len", "(", "rules", ".", "L7", ")", "\n", "}" ]
// Len returns the total number of rules inside `L7Rules`. // Returns 0 if nil.
[ "Len", "returns", "the", "total", "number", "of", "rules", "inside", "L7Rules", ".", "Returns", "0", "if", "nil", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/l4.go#L108-L113
163,544
cilium/cilium
pkg/policy/api/l4.go
IsEmpty
func (rules *L7Rules) IsEmpty() bool { return rules == nil || (rules.HTTP == nil && rules.Kafka == nil && rules.DNS == nil && rules.L7 == nil) }
go
func (rules *L7Rules) IsEmpty() bool { return rules == nil || (rules.HTTP == nil && rules.Kafka == nil && rules.DNS == nil && rules.L7 == nil) }
[ "func", "(", "rules", "*", "L7Rules", ")", "IsEmpty", "(", ")", "bool", "{", "return", "rules", "==", "nil", "||", "(", "rules", ".", "HTTP", "==", "nil", "&&", "rules", ".", "Kafka", "==", "nil", "&&", "rules", ".", "DNS", "==", "nil", "&&", "rules", ".", "L7", "==", "nil", ")", "\n", "}" ]
// IsEmpty returns whether the `L7Rules` is nil or contains nil rules.
[ "IsEmpty", "returns", "whether", "the", "L7Rules", "is", "nil", "or", "contains", "nil", "rules", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/l4.go#L116-L118
163,545
cilium/cilium
pkg/policy/resolve.go
computeDesiredL4PolicyMapEntries
func (p *EndpointPolicy) computeDesiredL4PolicyMapEntries(identityCache cache.IdentityCache) { if p.L4Policy == nil { return } p.computeDirectionL4PolicyMapEntries(identityCache, p.L4Policy.Ingress, trafficdirection.Ingress, p.DeniedIngressIdentities) p.computeDirectionL4PolicyMapEntries(identityCache, p.L4Policy.Egress, trafficdirection.Egress, p.DeniedEgressIdentities) return }
go
func (p *EndpointPolicy) computeDesiredL4PolicyMapEntries(identityCache cache.IdentityCache) { if p.L4Policy == nil { return } p.computeDirectionL4PolicyMapEntries(identityCache, p.L4Policy.Ingress, trafficdirection.Ingress, p.DeniedIngressIdentities) p.computeDirectionL4PolicyMapEntries(identityCache, p.L4Policy.Egress, trafficdirection.Egress, p.DeniedEgressIdentities) return }
[ "func", "(", "p", "*", "EndpointPolicy", ")", "computeDesiredL4PolicyMapEntries", "(", "identityCache", "cache", ".", "IdentityCache", ")", "{", "if", "p", ".", "L4Policy", "==", "nil", "{", "return", "\n", "}", "\n", "p", ".", "computeDirectionL4PolicyMapEntries", "(", "identityCache", ",", "p", ".", "L4Policy", ".", "Ingress", ",", "trafficdirection", ".", "Ingress", ",", "p", ".", "DeniedIngressIdentities", ")", "\n", "p", ".", "computeDirectionL4PolicyMapEntries", "(", "identityCache", ",", "p", ".", "L4Policy", ".", "Egress", ",", "trafficdirection", ".", "Egress", ",", "p", ".", "DeniedEgressIdentities", ")", "\n", "return", "\n", "}" ]
// computeDesiredL4PolicyMapEntries transforms the EndpointPolicy.L4Policy into // the datapath-friendly format inside EndpointPolicy.PolicyMapState.
[ "computeDesiredL4PolicyMapEntries", "transforms", "the", "EndpointPolicy", ".", "L4Policy", "into", "the", "datapath", "-", "friendly", "format", "inside", "EndpointPolicy", ".", "PolicyMapState", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/resolve.go#L192-L200
163,546
cilium/cilium
pkg/datapath/linux/route/route_linux.go
getNetlinkRoute
func (r *Route) getNetlinkRoute() netlink.Route { rt := netlink.Route{ Dst: &r.Prefix, Src: r.Local, MTU: r.MTU, Protocol: r.Proto, Table: r.Table, Type: r.Type, } if r.Nexthop != nil { rt.Gw = *r.Nexthop } if r.Scope != netlink.SCOPE_UNIVERSE { rt.Scope = r.Scope } else if r.Scope == netlink.SCOPE_UNIVERSE && r.Type == RTN_LOCAL { rt.Scope = netlink.SCOPE_HOST } return rt }
go
func (r *Route) getNetlinkRoute() netlink.Route { rt := netlink.Route{ Dst: &r.Prefix, Src: r.Local, MTU: r.MTU, Protocol: r.Proto, Table: r.Table, Type: r.Type, } if r.Nexthop != nil { rt.Gw = *r.Nexthop } if r.Scope != netlink.SCOPE_UNIVERSE { rt.Scope = r.Scope } else if r.Scope == netlink.SCOPE_UNIVERSE && r.Type == RTN_LOCAL { rt.Scope = netlink.SCOPE_HOST } return rt }
[ "func", "(", "r", "*", "Route", ")", "getNetlinkRoute", "(", ")", "netlink", ".", "Route", "{", "rt", ":=", "netlink", ".", "Route", "{", "Dst", ":", "&", "r", ".", "Prefix", ",", "Src", ":", "r", ".", "Local", ",", "MTU", ":", "r", ".", "MTU", ",", "Protocol", ":", "r", ".", "Proto", ",", "Table", ":", "r", ".", "Table", ",", "Type", ":", "r", ".", "Type", ",", "}", "\n\n", "if", "r", ".", "Nexthop", "!=", "nil", "{", "rt", ".", "Gw", "=", "*", "r", ".", "Nexthop", "\n", "}", "\n\n", "if", "r", ".", "Scope", "!=", "netlink", ".", "SCOPE_UNIVERSE", "{", "rt", ".", "Scope", "=", "r", ".", "Scope", "\n", "}", "else", "if", "r", ".", "Scope", "==", "netlink", ".", "SCOPE_UNIVERSE", "&&", "r", ".", "Type", "==", "RTN_LOCAL", "{", "rt", ".", "Scope", "=", "netlink", ".", "SCOPE_HOST", "\n", "}", "\n\n", "return", "rt", "\n", "}" ]
// getNetlinkRoute returns the route configuration as netlink.Route
[ "getNetlinkRoute", "returns", "the", "route", "configuration", "as", "netlink", ".", "Route" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/datapath/linux/route/route_linux.go#L46-L67
163,547
cilium/cilium
pkg/datapath/linux/route/route_linux.go
getNexthopAsIPNet
func (r *Route) getNexthopAsIPNet() *net.IPNet { if r.Nexthop == nil { return nil } if r.Nexthop.To4() != nil { return &net.IPNet{IP: *r.Nexthop, Mask: net.CIDRMask(32, 32)} } return &net.IPNet{IP: *r.Nexthop, Mask: net.CIDRMask(128, 128)} }
go
func (r *Route) getNexthopAsIPNet() *net.IPNet { if r.Nexthop == nil { return nil } if r.Nexthop.To4() != nil { return &net.IPNet{IP: *r.Nexthop, Mask: net.CIDRMask(32, 32)} } return &net.IPNet{IP: *r.Nexthop, Mask: net.CIDRMask(128, 128)} }
[ "func", "(", "r", "*", "Route", ")", "getNexthopAsIPNet", "(", ")", "*", "net", ".", "IPNet", "{", "if", "r", ".", "Nexthop", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "r", ".", "Nexthop", ".", "To4", "(", ")", "!=", "nil", "{", "return", "&", "net", ".", "IPNet", "{", "IP", ":", "*", "r", ".", "Nexthop", ",", "Mask", ":", "net", ".", "CIDRMask", "(", "32", ",", "32", ")", "}", "\n", "}", "\n\n", "return", "&", "net", ".", "IPNet", "{", "IP", ":", "*", "r", ".", "Nexthop", ",", "Mask", ":", "net", ".", "CIDRMask", "(", "128", ",", "128", ")", "}", "\n", "}" ]
// getNexthopAsIPNet returns the nexthop of the route as IPNet
[ "getNexthopAsIPNet", "returns", "the", "nexthop", "of", "the", "route", "as", "IPNet" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/datapath/linux/route/route_linux.go#L70-L80
163,548
cilium/cilium
pkg/datapath/linux/route/route_linux.go
Lookup
func Lookup(route Route) (*Route, error) { link, err := netlink.LinkByName(route.Device) if err != nil { return nil, fmt.Errorf("unable to find interface '%s' of route: %s", route.Device, err) } routeSpec := route.getNetlinkRoute() routeSpec.LinkIndex = link.Attrs().Index nlRoute := lookup(&routeSpec) if nlRoute == nil { return nil, nil } result := &Route{ Local: nlRoute.Src, Device: link.Attrs().Name, MTU: nlRoute.MTU, Scope: nlRoute.Scope, Nexthop: &nlRoute.Gw, } if nlRoute.Dst != nil { result.Prefix = *nlRoute.Dst } return result, nil }
go
func Lookup(route Route) (*Route, error) { link, err := netlink.LinkByName(route.Device) if err != nil { return nil, fmt.Errorf("unable to find interface '%s' of route: %s", route.Device, err) } routeSpec := route.getNetlinkRoute() routeSpec.LinkIndex = link.Attrs().Index nlRoute := lookup(&routeSpec) if nlRoute == nil { return nil, nil } result := &Route{ Local: nlRoute.Src, Device: link.Attrs().Name, MTU: nlRoute.MTU, Scope: nlRoute.Scope, Nexthop: &nlRoute.Gw, } if nlRoute.Dst != nil { result.Prefix = *nlRoute.Dst } return result, nil }
[ "func", "Lookup", "(", "route", "Route", ")", "(", "*", "Route", ",", "error", ")", "{", "link", ",", "err", ":=", "netlink", ".", "LinkByName", "(", "route", ".", "Device", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "route", ".", "Device", ",", "err", ")", "\n", "}", "\n\n", "routeSpec", ":=", "route", ".", "getNetlinkRoute", "(", ")", "\n", "routeSpec", ".", "LinkIndex", "=", "link", ".", "Attrs", "(", ")", ".", "Index", "\n\n", "nlRoute", ":=", "lookup", "(", "&", "routeSpec", ")", "\n", "if", "nlRoute", "==", "nil", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "result", ":=", "&", "Route", "{", "Local", ":", "nlRoute", ".", "Src", ",", "Device", ":", "link", ".", "Attrs", "(", ")", ".", "Name", ",", "MTU", ":", "nlRoute", ".", "MTU", ",", "Scope", ":", "nlRoute", ".", "Scope", ",", "Nexthop", ":", "&", "nlRoute", ".", "Gw", ",", "}", "\n\n", "if", "nlRoute", ".", "Dst", "!=", "nil", "{", "result", ".", "Prefix", "=", "*", "nlRoute", ".", "Dst", "\n", "}", "\n\n", "return", "result", ",", "nil", "\n", "}" ]
// Lookup attempts to find the linux route based on the route specification. // If the route exists, the route is returned, otherwise an error is returned.
[ "Lookup", "attempts", "to", "find", "the", "linux", "route", "based", "on", "the", "route", "specification", ".", "If", "the", "route", "exists", "the", "route", "is", "returned", "otherwise", "an", "error", "is", "returned", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/datapath/linux/route/route_linux.go#L92-L119
163,549
cilium/cilium
pkg/datapath/linux/route/route_linux.go
replaceNexthopRoute
func replaceNexthopRoute(link netlink.Link, routerNet *net.IPNet) (bool, error) { route := createNexthopRoute(link, routerNet) if err := netlink.RouteReplace(route); err != nil { return false, fmt.Errorf("unable to add L2 nexthop route: %s", err) } return true, nil }
go
func replaceNexthopRoute(link netlink.Link, routerNet *net.IPNet) (bool, error) { route := createNexthopRoute(link, routerNet) if err := netlink.RouteReplace(route); err != nil { return false, fmt.Errorf("unable to add L2 nexthop route: %s", err) } return true, nil }
[ "func", "replaceNexthopRoute", "(", "link", "netlink", ".", "Link", ",", "routerNet", "*", "net", ".", "IPNet", ")", "(", "bool", ",", "error", ")", "{", "route", ":=", "createNexthopRoute", "(", "link", ",", "routerNet", ")", "\n", "if", "err", ":=", "netlink", ".", "RouteReplace", "(", "route", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "true", ",", "nil", "\n", "}" ]
// replaceNexthopRoute verifies that the L2 route for the router IP which is // used as nexthop for all node routes is properly installed. If unavailable or // incorrect, it will be replaced with the proper L2 route.
[ "replaceNexthopRoute", "verifies", "that", "the", "L2", "route", "for", "the", "router", "IP", "which", "is", "used", "as", "nexthop", "for", "all", "node", "routes", "is", "properly", "installed", ".", "If", "unavailable", "or", "incorrect", "it", "will", "be", "replaced", "with", "the", "proper", "L2", "route", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/datapath/linux/route/route_linux.go#L196-L203
163,550
cilium/cilium
pkg/datapath/linux/route/route_linux.go
Delete
func Delete(route Route) error { link, err := netlink.LinkByName(route.Device) if err != nil { return fmt.Errorf("unable to lookup interface %s: %s", route.Device, err) } // Deletion of routes with Nexthop or Local set fails for IPv6. // Therefore do not use getNetlinkRoute(). routeSpec := netlink.Route{ Dst: &route.Prefix, LinkIndex: link.Attrs().Index, } // Scope can only be specified for IPv4 if route.Prefix.IP.To4() != nil { routeSpec.Scope = route.Scope } if err := netlink.RouteDel(&routeSpec); err != nil { return err } return nil }
go
func Delete(route Route) error { link, err := netlink.LinkByName(route.Device) if err != nil { return fmt.Errorf("unable to lookup interface %s: %s", route.Device, err) } // Deletion of routes with Nexthop or Local set fails for IPv6. // Therefore do not use getNetlinkRoute(). routeSpec := netlink.Route{ Dst: &route.Prefix, LinkIndex: link.Attrs().Index, } // Scope can only be specified for IPv4 if route.Prefix.IP.To4() != nil { routeSpec.Scope = route.Scope } if err := netlink.RouteDel(&routeSpec); err != nil { return err } return nil }
[ "func", "Delete", "(", "route", "Route", ")", "error", "{", "link", ",", "err", ":=", "netlink", ".", "LinkByName", "(", "route", ".", "Device", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "route", ".", "Device", ",", "err", ")", "\n", "}", "\n\n", "// Deletion of routes with Nexthop or Local set fails for IPv6.", "// Therefore do not use getNetlinkRoute().", "routeSpec", ":=", "netlink", ".", "Route", "{", "Dst", ":", "&", "route", ".", "Prefix", ",", "LinkIndex", ":", "link", ".", "Attrs", "(", ")", ".", "Index", ",", "}", "\n\n", "// Scope can only be specified for IPv4", "if", "route", ".", "Prefix", ".", "IP", ".", "To4", "(", ")", "!=", "nil", "{", "routeSpec", ".", "Scope", "=", "route", ".", "Scope", "\n", "}", "\n\n", "if", "err", ":=", "netlink", ".", "RouteDel", "(", "&", "routeSpec", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Delete deletes a Linux route. An error is returned if the route does not // exist or if the route could not be deleted.
[ "Delete", "deletes", "a", "Linux", "route", ".", "An", "error", "is", "returned", "if", "the", "route", "does", "not", "exist", "or", "if", "the", "route", "could", "not", "be", "deleted", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/datapath/linux/route/route_linux.go#L292-L315
163,551
cilium/cilium
pkg/datapath/linux/route/route_linux.go
ReplaceRule
func ReplaceRule(fwmark int, table int) error { exists, err := lookupRule(fwmark, table, netlink.FAMILY_V4) if err != nil { return err } if exists == true { return nil } return replaceRule(fwmark, table, netlink.FAMILY_V4) }
go
func ReplaceRule(fwmark int, table int) error { exists, err := lookupRule(fwmark, table, netlink.FAMILY_V4) if err != nil { return err } if exists == true { return nil } return replaceRule(fwmark, table, netlink.FAMILY_V4) }
[ "func", "ReplaceRule", "(", "fwmark", "int", ",", "table", "int", ")", "error", "{", "exists", ",", "err", ":=", "lookupRule", "(", "fwmark", ",", "table", ",", "netlink", ".", "FAMILY_V4", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "exists", "==", "true", "{", "return", "nil", "\n", "}", "\n", "return", "replaceRule", "(", "fwmark", ",", "table", ",", "netlink", ".", "FAMILY_V4", ")", "\n", "}" ]
// ReplaceRule add or replace rule in the routing table using a mark to indicate // table. Used with BPF datapath to set mark and direct packets to route table.
[ "ReplaceRule", "add", "or", "replace", "rule", "in", "the", "routing", "table", "using", "a", "mark", "to", "indicate", "table", ".", "Used", "with", "BPF", "datapath", "to", "set", "mark", "and", "direct", "packets", "to", "route", "table", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/datapath/linux/route/route_linux.go#L332-L341
163,552
cilium/cilium
pkg/datapath/linux/route/route_linux.go
ReplaceRuleIPv6
func ReplaceRuleIPv6(fwmark, table int) error { exists, err := lookupRule(fwmark, table, netlink.FAMILY_V6) if err != nil { return err } if exists == true { return nil } return replaceRule(fwmark, table, netlink.FAMILY_V6) }
go
func ReplaceRuleIPv6(fwmark, table int) error { exists, err := lookupRule(fwmark, table, netlink.FAMILY_V6) if err != nil { return err } if exists == true { return nil } return replaceRule(fwmark, table, netlink.FAMILY_V6) }
[ "func", "ReplaceRuleIPv6", "(", "fwmark", ",", "table", "int", ")", "error", "{", "exists", ",", "err", ":=", "lookupRule", "(", "fwmark", ",", "table", ",", "netlink", ".", "FAMILY_V6", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "exists", "==", "true", "{", "return", "nil", "\n", "}", "\n", "return", "replaceRule", "(", "fwmark", ",", "table", ",", "netlink", ".", "FAMILY_V6", ")", "\n", "}" ]
// ReplaceRuleIPv6 add or replace IPv6 rule in the routing table using a mark to // indicate table.
[ "ReplaceRuleIPv6", "add", "or", "replace", "IPv6", "rule", "in", "the", "routing", "table", "using", "a", "mark", "to", "indicate", "table", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/datapath/linux/route/route_linux.go#L345-L354
163,553
cilium/cilium
pkg/datapath/linux/route/route_linux.go
DeleteRule
func DeleteRule(fwmark int, table int) error { rule := netlink.NewRule() rule.Mark = fwmark rule.Mask = linux_defaults.RouteMarkMask rule.Table = table rule.Family = netlink.FAMILY_V4 return netlink.RuleDel(rule) }
go
func DeleteRule(fwmark int, table int) error { rule := netlink.NewRule() rule.Mark = fwmark rule.Mask = linux_defaults.RouteMarkMask rule.Table = table rule.Family = netlink.FAMILY_V4 return netlink.RuleDel(rule) }
[ "func", "DeleteRule", "(", "fwmark", "int", ",", "table", "int", ")", "error", "{", "rule", ":=", "netlink", ".", "NewRule", "(", ")", "\n", "rule", ".", "Mark", "=", "fwmark", "\n", "rule", ".", "Mask", "=", "linux_defaults", ".", "RouteMarkMask", "\n", "rule", ".", "Table", "=", "table", "\n", "rule", ".", "Family", "=", "netlink", ".", "FAMILY_V4", "\n", "return", "netlink", ".", "RuleDel", "(", "rule", ")", "\n", "}" ]
// DeleteRule delete a mark based rule from the routing table.
[ "DeleteRule", "delete", "a", "mark", "based", "rule", "from", "the", "routing", "table", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/datapath/linux/route/route_linux.go#L367-L374
163,554
cilium/cilium
pkg/datapath/linux/route/route_linux.go
DeleteRuleIPv6
func DeleteRuleIPv6(fwmark int, table int) error { rule := netlink.NewRule() rule.Mark = fwmark rule.Table = table rule.Family = netlink.FAMILY_V6 return netlink.RuleDel(rule) }
go
func DeleteRuleIPv6(fwmark int, table int) error { rule := netlink.NewRule() rule.Mark = fwmark rule.Table = table rule.Family = netlink.FAMILY_V6 return netlink.RuleDel(rule) }
[ "func", "DeleteRuleIPv6", "(", "fwmark", "int", ",", "table", "int", ")", "error", "{", "rule", ":=", "netlink", ".", "NewRule", "(", ")", "\n", "rule", ".", "Mark", "=", "fwmark", "\n", "rule", ".", "Table", "=", "table", "\n", "rule", ".", "Family", "=", "netlink", ".", "FAMILY_V6", "\n", "return", "netlink", ".", "RuleDel", "(", "rule", ")", "\n", "}" ]
// DeleteRuleIPv6 delete a mark based IPv6 rule from the routing table.
[ "DeleteRuleIPv6", "delete", "a", "mark", "based", "IPv6", "rule", "from", "the", "routing", "table", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/datapath/linux/route/route_linux.go#L377-L383
163,555
cilium/cilium
api/v1/health/server/restapi/connectivity/put_status_probe.go
NewPutStatusProbe
func NewPutStatusProbe(ctx *middleware.Context, handler PutStatusProbeHandler) *PutStatusProbe { return &PutStatusProbe{Context: ctx, Handler: handler} }
go
func NewPutStatusProbe(ctx *middleware.Context, handler PutStatusProbeHandler) *PutStatusProbe { return &PutStatusProbe{Context: ctx, Handler: handler} }
[ "func", "NewPutStatusProbe", "(", "ctx", "*", "middleware", ".", "Context", ",", "handler", "PutStatusProbeHandler", ")", "*", "PutStatusProbe", "{", "return", "&", "PutStatusProbe", "{", "Context", ":", "ctx", ",", "Handler", ":", "handler", "}", "\n", "}" ]
// NewPutStatusProbe creates a new http.Handler for the put status probe operation
[ "NewPutStatusProbe", "creates", "a", "new", "http", ".", "Handler", "for", "the", "put", "status", "probe", "operation" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/health/server/restapi/connectivity/put_status_probe.go#L28-L30
163,556
cilium/cilium
pkg/modules/modules_linux.go
parseModulesFile
func parseModulesFile(r io.Reader) ([]string, error) { var result []string scanner := bufio.NewScanner(r) scanner.Split(bufio.ScanLines) for scanner.Scan() { moduleInfoRaw := scanner.Text() moduleInfoSeparated := strings.Split(moduleInfoRaw, " ") if len(moduleInfoSeparated) < 6 { return nil, fmt.Errorf( "invalid module info - it has %d fields (less than 6): %s", len(moduleInfoSeparated), moduleInfoRaw) } result = append(result, moduleInfoSeparated[0]) } return result, nil }
go
func parseModulesFile(r io.Reader) ([]string, error) { var result []string scanner := bufio.NewScanner(r) scanner.Split(bufio.ScanLines) for scanner.Scan() { moduleInfoRaw := scanner.Text() moduleInfoSeparated := strings.Split(moduleInfoRaw, " ") if len(moduleInfoSeparated) < 6 { return nil, fmt.Errorf( "invalid module info - it has %d fields (less than 6): %s", len(moduleInfoSeparated), moduleInfoRaw) } result = append(result, moduleInfoSeparated[0]) } return result, nil }
[ "func", "parseModulesFile", "(", "r", "io", ".", "Reader", ")", "(", "[", "]", "string", ",", "error", ")", "{", "var", "result", "[", "]", "string", "\n\n", "scanner", ":=", "bufio", ".", "NewScanner", "(", "r", ")", "\n", "scanner", ".", "Split", "(", "bufio", ".", "ScanLines", ")", "\n\n", "for", "scanner", ".", "Scan", "(", ")", "{", "moduleInfoRaw", ":=", "scanner", ".", "Text", "(", ")", "\n", "moduleInfoSeparated", ":=", "strings", ".", "Split", "(", "moduleInfoRaw", ",", "\"", "\"", ")", "\n", "if", "len", "(", "moduleInfoSeparated", ")", "<", "6", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "moduleInfoSeparated", ")", ",", "moduleInfoRaw", ")", "\n", "}", "\n\n", "result", "=", "append", "(", "result", ",", "moduleInfoSeparated", "[", "0", "]", ")", "\n", "}", "\n\n", "return", "result", ",", "nil", "\n", "}" ]
// parseModulesFile returns the list of loaded kernel modules names.
[ "parseModulesFile", "returns", "the", "list", "of", "loaded", "kernel", "modules", "names", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/modules/modules_linux.go#L34-L53
163,557
cilium/cilium
pkg/endpointmanager/conntrack.go
runGC
func runGC(e *endpoint.Endpoint, ipv4, ipv6 bool, filter *ctmap.GCFilter) (mapType bpf.MapType) { var maps []*ctmap.Map if e == nil { maps = ctmap.GlobalMaps(ipv4, ipv6) } else { maps = ctmap.LocalMaps(e, ipv4, ipv6) } for _, m := range maps { path, err := m.Path() if err == nil { err = m.Open() } if err != nil { msg := "Skipping CT garbage collection" scopedLog := log.WithError(err).WithField(logfields.Path, path) if os.IsNotExist(err) { scopedLog.Debug(msg) } else { scopedLog.Warn(msg) } if e != nil { e.LogStatus(endpoint.BPF, endpoint.Warning, fmt.Sprintf("%s: %s", msg, err)) } continue } defer m.Close() mapType = m.MapInfo.MapType deleted := ctmap.GC(m, filter) if deleted > 0 { log.WithFields(logrus.Fields{ logfields.Path: path, "count": deleted, }).Debug("Deleted filtered entries from map") } } return }
go
func runGC(e *endpoint.Endpoint, ipv4, ipv6 bool, filter *ctmap.GCFilter) (mapType bpf.MapType) { var maps []*ctmap.Map if e == nil { maps = ctmap.GlobalMaps(ipv4, ipv6) } else { maps = ctmap.LocalMaps(e, ipv4, ipv6) } for _, m := range maps { path, err := m.Path() if err == nil { err = m.Open() } if err != nil { msg := "Skipping CT garbage collection" scopedLog := log.WithError(err).WithField(logfields.Path, path) if os.IsNotExist(err) { scopedLog.Debug(msg) } else { scopedLog.Warn(msg) } if e != nil { e.LogStatus(endpoint.BPF, endpoint.Warning, fmt.Sprintf("%s: %s", msg, err)) } continue } defer m.Close() mapType = m.MapInfo.MapType deleted := ctmap.GC(m, filter) if deleted > 0 { log.WithFields(logrus.Fields{ logfields.Path: path, "count": deleted, }).Debug("Deleted filtered entries from map") } } return }
[ "func", "runGC", "(", "e", "*", "endpoint", ".", "Endpoint", ",", "ipv4", ",", "ipv6", "bool", ",", "filter", "*", "ctmap", ".", "GCFilter", ")", "(", "mapType", "bpf", ".", "MapType", ")", "{", "var", "maps", "[", "]", "*", "ctmap", ".", "Map", "\n\n", "if", "e", "==", "nil", "{", "maps", "=", "ctmap", ".", "GlobalMaps", "(", "ipv4", ",", "ipv6", ")", "\n", "}", "else", "{", "maps", "=", "ctmap", ".", "LocalMaps", "(", "e", ",", "ipv4", ",", "ipv6", ")", "\n", "}", "\n", "for", "_", ",", "m", ":=", "range", "maps", "{", "path", ",", "err", ":=", "m", ".", "Path", "(", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "m", ".", "Open", "(", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "msg", ":=", "\"", "\"", "\n", "scopedLog", ":=", "log", ".", "WithError", "(", "err", ")", ".", "WithField", "(", "logfields", ".", "Path", ",", "path", ")", "\n", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "scopedLog", ".", "Debug", "(", "msg", ")", "\n", "}", "else", "{", "scopedLog", ".", "Warn", "(", "msg", ")", "\n", "}", "\n", "if", "e", "!=", "nil", "{", "e", ".", "LogStatus", "(", "endpoint", ".", "BPF", ",", "endpoint", ".", "Warning", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "msg", ",", "err", ")", ")", "\n", "}", "\n", "continue", "\n", "}", "\n", "defer", "m", ".", "Close", "(", ")", "\n\n", "mapType", "=", "m", ".", "MapInfo", ".", "MapType", "\n\n", "deleted", ":=", "ctmap", ".", "GC", "(", "m", ",", "filter", ")", "\n\n", "if", "deleted", ">", "0", "{", "log", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "logfields", ".", "Path", ":", "path", ",", "\"", "\"", ":", "deleted", ",", "}", ")", ".", "Debug", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "return", "\n", "}" ]
// runGC run CT's garbage collector for the given endpoint. `isLocal` refers if // the CT map is set to local. If `isIPv6` is set specifies that is the IPv6 // map. `filter` represents the filter type to be used while looping all CT // entries. // // The provided endpoint is optional; if it is provided, then its map will be // garbage collected and any failures will be logged to the endpoint log. // Otherwise it will garbage-collect the global map and use the global log.
[ "runGC", "run", "CT", "s", "garbage", "collector", "for", "the", "given", "endpoint", ".", "isLocal", "refers", "if", "the", "CT", "map", "is", "set", "to", "local", ".", "If", "isIPv6", "is", "set", "specifies", "that", "is", "the", "IPv6", "map", ".", "filter", "represents", "the", "filter", "type", "to", "be", "used", "while", "looping", "all", "CT", "entries", ".", "The", "provided", "endpoint", "is", "optional", ";", "if", "it", "is", "provided", "then", "its", "map", "will", "be", "garbage", "collected", "and", "any", "failures", "will", "be", "logged", "to", "the", "endpoint", "log", ".", "Otherwise", "it", "will", "garbage", "-", "collect", "the", "global", "map", "and", "use", "the", "global", "log", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpointmanager/conntrack.go#L40-L81
163,558
cilium/cilium
pkg/endpointmanager/conntrack.go
EnableConntrackGC
func EnableConntrackGC(ipv4, ipv6 bool, restoredEndpoints []*endpoint.Endpoint) { var ( initialScan = true initialScanComplete = make(chan struct{}) mapType bpf.MapType ) go func() { for { eps := GetEndpoints() if len(eps) > 0 || initialScan { mapType = runGC(nil, ipv4, ipv6, createGCFilter(initialScan, restoredEndpoints)) } for _, e := range eps { if !e.ConntrackLocal() { // Skip because GC was handled above. continue } runGC(e, ipv4, ipv6, &ctmap.GCFilter{RemoveExpired: true}) } if initialScan { close(initialScanComplete) initialScan = false } time.Sleep(calculateInterval(mapType)) } }() select { case <-initialScanComplete: log.Info("Initial scan of connection tracking completed") case <-time.After(30 * time.Second): log.Fatal("Timeout while waiting for initial conntrack scan") } }
go
func EnableConntrackGC(ipv4, ipv6 bool, restoredEndpoints []*endpoint.Endpoint) { var ( initialScan = true initialScanComplete = make(chan struct{}) mapType bpf.MapType ) go func() { for { eps := GetEndpoints() if len(eps) > 0 || initialScan { mapType = runGC(nil, ipv4, ipv6, createGCFilter(initialScan, restoredEndpoints)) } for _, e := range eps { if !e.ConntrackLocal() { // Skip because GC was handled above. continue } runGC(e, ipv4, ipv6, &ctmap.GCFilter{RemoveExpired: true}) } if initialScan { close(initialScanComplete) initialScan = false } time.Sleep(calculateInterval(mapType)) } }() select { case <-initialScanComplete: log.Info("Initial scan of connection tracking completed") case <-time.After(30 * time.Second): log.Fatal("Timeout while waiting for initial conntrack scan") } }
[ "func", "EnableConntrackGC", "(", "ipv4", ",", "ipv6", "bool", ",", "restoredEndpoints", "[", "]", "*", "endpoint", ".", "Endpoint", ")", "{", "var", "(", "initialScan", "=", "true", "\n", "initialScanComplete", "=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "mapType", "bpf", ".", "MapType", "\n", ")", "\n\n", "go", "func", "(", ")", "{", "for", "{", "eps", ":=", "GetEndpoints", "(", ")", "\n", "if", "len", "(", "eps", ")", ">", "0", "||", "initialScan", "{", "mapType", "=", "runGC", "(", "nil", ",", "ipv4", ",", "ipv6", ",", "createGCFilter", "(", "initialScan", ",", "restoredEndpoints", ")", ")", "\n", "}", "\n", "for", "_", ",", "e", ":=", "range", "eps", "{", "if", "!", "e", ".", "ConntrackLocal", "(", ")", "{", "// Skip because GC was handled above.", "continue", "\n", "}", "\n", "runGC", "(", "e", ",", "ipv4", ",", "ipv6", ",", "&", "ctmap", ".", "GCFilter", "{", "RemoveExpired", ":", "true", "}", ")", "\n", "}", "\n\n", "if", "initialScan", "{", "close", "(", "initialScanComplete", ")", "\n", "initialScan", "=", "false", "\n", "}", "\n\n", "time", ".", "Sleep", "(", "calculateInterval", "(", "mapType", ")", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "select", "{", "case", "<-", "initialScanComplete", ":", "log", ".", "Info", "(", "\"", "\"", ")", "\n", "case", "<-", "time", ".", "After", "(", "30", "*", "time", ".", "Second", ")", ":", "log", ".", "Fatal", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// EnableConntrackGC enables the connection tracking garbage collection.
[ "EnableConntrackGC", "enables", "the", "connection", "tracking", "garbage", "collection", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpointmanager/conntrack.go#L116-L152
163,559
cilium/cilium
api/v1/server/restapi/service/get_service_id.go
NewGetServiceID
func NewGetServiceID(ctx *middleware.Context, handler GetServiceIDHandler) *GetServiceID { return &GetServiceID{Context: ctx, Handler: handler} }
go
func NewGetServiceID(ctx *middleware.Context, handler GetServiceIDHandler) *GetServiceID { return &GetServiceID{Context: ctx, Handler: handler} }
[ "func", "NewGetServiceID", "(", "ctx", "*", "middleware", ".", "Context", ",", "handler", "GetServiceIDHandler", ")", "*", "GetServiceID", "{", "return", "&", "GetServiceID", "{", "Context", ":", "ctx", ",", "Handler", ":", "handler", "}", "\n", "}" ]
// NewGetServiceID creates a new http.Handler for the get service ID operation
[ "NewGetServiceID", "creates", "a", "new", "http", ".", "Handler", "for", "the", "get", "service", "ID", "operation" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/service/get_service_id.go#L28-L30
163,560
cilium/cilium
pkg/identity/cache/cache.go
Less
func (s IdentitiesModel) Less(i, j int) bool { return s[i].ID < s[j].ID }
go
func (s IdentitiesModel) Less(i, j int) bool { return s[i].ID < s[j].ID }
[ "func", "(", "s", "IdentitiesModel", ")", "Less", "(", "i", ",", "j", "int", ")", "bool", "{", "return", "s", "[", "i", "]", ".", "ID", "<", "s", "[", "j", "]", ".", "ID", "\n", "}" ]
// Less returns true if the element in index `i` is lower than the element // in index `j`
[ "Less", "returns", "true", "if", "the", "element", "in", "index", "i", "is", "lower", "than", "the", "element", "in", "index", "j" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/cache.go#L44-L46
163,561
cilium/cilium
pkg/identity/cache/cache.go
GetIdentityCache
func GetIdentityCache() IdentityCache { cache := IdentityCache{} if IdentityAllocator != nil { IdentityAllocator.ForeachCache(func(id idpool.ID, val allocator.AllocatorKey) { if val != nil { if gi, ok := val.(globalIdentity); ok { cache[identity.NumericIdentity(id)] = gi.LabelArray } else { log.Warningf("Ignoring unknown identity type '%s': %+v", reflect.TypeOf(val), val) } } }) } for key, identity := range identity.ReservedIdentityCache { cache[key] = identity.Labels.LabelArray() } if localIdentities != nil { for _, identity := range localIdentities.GetIdentities() { cache[identity.ID] = identity.Labels.LabelArray() } } return cache }
go
func GetIdentityCache() IdentityCache { cache := IdentityCache{} if IdentityAllocator != nil { IdentityAllocator.ForeachCache(func(id idpool.ID, val allocator.AllocatorKey) { if val != nil { if gi, ok := val.(globalIdentity); ok { cache[identity.NumericIdentity(id)] = gi.LabelArray } else { log.Warningf("Ignoring unknown identity type '%s': %+v", reflect.TypeOf(val), val) } } }) } for key, identity := range identity.ReservedIdentityCache { cache[key] = identity.Labels.LabelArray() } if localIdentities != nil { for _, identity := range localIdentities.GetIdentities() { cache[identity.ID] = identity.Labels.LabelArray() } } return cache }
[ "func", "GetIdentityCache", "(", ")", "IdentityCache", "{", "cache", ":=", "IdentityCache", "{", "}", "\n\n", "if", "IdentityAllocator", "!=", "nil", "{", "IdentityAllocator", ".", "ForeachCache", "(", "func", "(", "id", "idpool", ".", "ID", ",", "val", "allocator", ".", "AllocatorKey", ")", "{", "if", "val", "!=", "nil", "{", "if", "gi", ",", "ok", ":=", "val", ".", "(", "globalIdentity", ")", ";", "ok", "{", "cache", "[", "identity", ".", "NumericIdentity", "(", "id", ")", "]", "=", "gi", ".", "LabelArray", "\n", "}", "else", "{", "log", ".", "Warningf", "(", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "val", ")", ",", "val", ")", "\n", "}", "\n", "}", "\n", "}", ")", "\n", "}", "\n\n", "for", "key", ",", "identity", ":=", "range", "identity", ".", "ReservedIdentityCache", "{", "cache", "[", "key", "]", "=", "identity", ".", "Labels", ".", "LabelArray", "(", ")", "\n", "}", "\n\n", "if", "localIdentities", "!=", "nil", "{", "for", "_", ",", "identity", ":=", "range", "localIdentities", ".", "GetIdentities", "(", ")", "{", "cache", "[", "identity", ".", "ID", "]", "=", "identity", ".", "Labels", ".", "LabelArray", "(", ")", "\n", "}", "\n", "}", "\n\n", "return", "cache", "\n", "}" ]
// GetIdentityCache returns a cache of all known identities
[ "GetIdentityCache", "returns", "a", "cache", "of", "all", "known", "identities" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/cache.go#L49-L77
163,562
cilium/cilium
pkg/identity/cache/cache.go
GetIdentities
func GetIdentities() IdentitiesModel { identities := IdentitiesModel{} IdentityAllocator.ForeachCache(func(id idpool.ID, val allocator.AllocatorKey) { if gi, ok := val.(globalIdentity); ok { identity := identity.NewIdentityFromLabelArray(identity.NumericIdentity(id), gi.LabelArray) identities = append(identities, identity.GetModel()) } }) // append user reserved identities for _, v := range identity.ReservedIdentityCache { identities = append(identities, v.GetModel()) } for _, v := range localIdentities.GetIdentities() { identities = append(identities, v.GetModel()) } return identities }
go
func GetIdentities() IdentitiesModel { identities := IdentitiesModel{} IdentityAllocator.ForeachCache(func(id idpool.ID, val allocator.AllocatorKey) { if gi, ok := val.(globalIdentity); ok { identity := identity.NewIdentityFromLabelArray(identity.NumericIdentity(id), gi.LabelArray) identities = append(identities, identity.GetModel()) } }) // append user reserved identities for _, v := range identity.ReservedIdentityCache { identities = append(identities, v.GetModel()) } for _, v := range localIdentities.GetIdentities() { identities = append(identities, v.GetModel()) } return identities }
[ "func", "GetIdentities", "(", ")", "IdentitiesModel", "{", "identities", ":=", "IdentitiesModel", "{", "}", "\n\n", "IdentityAllocator", ".", "ForeachCache", "(", "func", "(", "id", "idpool", ".", "ID", ",", "val", "allocator", ".", "AllocatorKey", ")", "{", "if", "gi", ",", "ok", ":=", "val", ".", "(", "globalIdentity", ")", ";", "ok", "{", "identity", ":=", "identity", ".", "NewIdentityFromLabelArray", "(", "identity", ".", "NumericIdentity", "(", "id", ")", ",", "gi", ".", "LabelArray", ")", "\n", "identities", "=", "append", "(", "identities", ",", "identity", ".", "GetModel", "(", ")", ")", "\n", "}", "\n\n", "}", ")", "\n", "// append user reserved identities", "for", "_", ",", "v", ":=", "range", "identity", ".", "ReservedIdentityCache", "{", "identities", "=", "append", "(", "identities", ",", "v", ".", "GetModel", "(", ")", ")", "\n", "}", "\n\n", "for", "_", ",", "v", ":=", "range", "localIdentities", ".", "GetIdentities", "(", ")", "{", "identities", "=", "append", "(", "identities", ",", "v", ".", "GetModel", "(", ")", ")", "\n", "}", "\n\n", "return", "identities", "\n", "}" ]
// GetIdentities returns all known identities
[ "GetIdentities", "returns", "all", "known", "identities" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/cache.go#L80-L100
163,563
cilium/cilium
pkg/identity/cache/cache.go
watch
func (w *identityWatcher) watch(owner IdentityAllocatorOwner, events allocator.AllocatorEventChan) { w.stopChan = make(chan bool) go func() { for { added := IdentityCache{} deleted := IdentityCache{} First: for { // Wait for one identity add or delete or stop select { case event, ok := <-events: if !ok { // 'events' was closed return } // Collect first added and deleted labels switch event.Typ { case kvstore.EventTypeCreate, kvstore.EventTypeDelete: if collectEvent(event, added, deleted) { // First event collected break First } default: // Ignore modify events } case <-w.stopChan: return } } More: for { // see if there is more, but do not wait nor stop select { case event, ok := <-events: if !ok { // 'events' was closed break More } // Collect more added and deleted labels switch event.Typ { case kvstore.EventTypeCreate, kvstore.EventTypeDelete: collectEvent(event, added, deleted) default: // Ignore modify events } default: // No more events available without blocking break More } } // Issue collected updates owner.UpdateIdentities(added, deleted) } }() }
go
func (w *identityWatcher) watch(owner IdentityAllocatorOwner, events allocator.AllocatorEventChan) { w.stopChan = make(chan bool) go func() { for { added := IdentityCache{} deleted := IdentityCache{} First: for { // Wait for one identity add or delete or stop select { case event, ok := <-events: if !ok { // 'events' was closed return } // Collect first added and deleted labels switch event.Typ { case kvstore.EventTypeCreate, kvstore.EventTypeDelete: if collectEvent(event, added, deleted) { // First event collected break First } default: // Ignore modify events } case <-w.stopChan: return } } More: for { // see if there is more, but do not wait nor stop select { case event, ok := <-events: if !ok { // 'events' was closed break More } // Collect more added and deleted labels switch event.Typ { case kvstore.EventTypeCreate, kvstore.EventTypeDelete: collectEvent(event, added, deleted) default: // Ignore modify events } default: // No more events available without blocking break More } } // Issue collected updates owner.UpdateIdentities(added, deleted) } }() }
[ "func", "(", "w", "*", "identityWatcher", ")", "watch", "(", "owner", "IdentityAllocatorOwner", ",", "events", "allocator", ".", "AllocatorEventChan", ")", "{", "w", ".", "stopChan", "=", "make", "(", "chan", "bool", ")", "\n\n", "go", "func", "(", ")", "{", "for", "{", "added", ":=", "IdentityCache", "{", "}", "\n", "deleted", ":=", "IdentityCache", "{", "}", "\n\n", "First", ":", "for", "{", "// Wait for one identity add or delete or stop", "select", "{", "case", "event", ",", "ok", ":=", "<-", "events", ":", "if", "!", "ok", "{", "// 'events' was closed", "return", "\n", "}", "\n", "// Collect first added and deleted labels", "switch", "event", ".", "Typ", "{", "case", "kvstore", ".", "EventTypeCreate", ",", "kvstore", ".", "EventTypeDelete", ":", "if", "collectEvent", "(", "event", ",", "added", ",", "deleted", ")", "{", "// First event collected", "break", "First", "\n", "}", "\n", "default", ":", "// Ignore modify events", "}", "\n", "case", "<-", "w", ".", "stopChan", ":", "return", "\n", "}", "\n", "}", "\n\n", "More", ":", "for", "{", "// see if there is more, but do not wait nor stop", "select", "{", "case", "event", ",", "ok", ":=", "<-", "events", ":", "if", "!", "ok", "{", "// 'events' was closed", "break", "More", "\n", "}", "\n", "// Collect more added and deleted labels", "switch", "event", ".", "Typ", "{", "case", "kvstore", ".", "EventTypeCreate", ",", "kvstore", ".", "EventTypeDelete", ":", "collectEvent", "(", "event", ",", "added", ",", "deleted", ")", "\n", "default", ":", "// Ignore modify events", "}", "\n", "default", ":", "// No more events available without blocking", "break", "More", "\n", "}", "\n", "}", "\n", "// Issue collected updates", "owner", ".", "UpdateIdentities", "(", "added", ",", "deleted", ")", "\n", "}", "\n", "}", "(", ")", "\n", "}" ]
// watch starts the identity watcher
[ "watch", "starts", "the", "identity", "watcher" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/cache.go#L137-L194
163,564
cilium/cilium
pkg/identity/cache/cache.go
LookupIdentity
func LookupIdentity(lbls labels.Labels) *identity.Identity { if reservedIdentity := LookupReservedIdentityByLabels(lbls); reservedIdentity != nil { return reservedIdentity } if identity := localIdentities.lookup(lbls); identity != nil { return identity } if IdentityAllocator == nil { return nil } lblArray := lbls.LabelArray() id, err := IdentityAllocator.Get(context.TODO(), globalIdentity{lblArray}) if err != nil { return nil } if id == idpool.NoID { return nil } return identity.NewIdentityFromLabelArray(identity.NumericIdentity(id), lblArray) }
go
func LookupIdentity(lbls labels.Labels) *identity.Identity { if reservedIdentity := LookupReservedIdentityByLabels(lbls); reservedIdentity != nil { return reservedIdentity } if identity := localIdentities.lookup(lbls); identity != nil { return identity } if IdentityAllocator == nil { return nil } lblArray := lbls.LabelArray() id, err := IdentityAllocator.Get(context.TODO(), globalIdentity{lblArray}) if err != nil { return nil } if id == idpool.NoID { return nil } return identity.NewIdentityFromLabelArray(identity.NumericIdentity(id), lblArray) }
[ "func", "LookupIdentity", "(", "lbls", "labels", ".", "Labels", ")", "*", "identity", ".", "Identity", "{", "if", "reservedIdentity", ":=", "LookupReservedIdentityByLabels", "(", "lbls", ")", ";", "reservedIdentity", "!=", "nil", "{", "return", "reservedIdentity", "\n", "}", "\n\n", "if", "identity", ":=", "localIdentities", ".", "lookup", "(", "lbls", ")", ";", "identity", "!=", "nil", "{", "return", "identity", "\n", "}", "\n\n", "if", "IdentityAllocator", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "lblArray", ":=", "lbls", ".", "LabelArray", "(", ")", "\n", "id", ",", "err", ":=", "IdentityAllocator", ".", "Get", "(", "context", ".", "TODO", "(", ")", ",", "globalIdentity", "{", "lblArray", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "id", "==", "idpool", ".", "NoID", "{", "return", "nil", "\n", "}", "\n\n", "return", "identity", ".", "NewIdentityFromLabelArray", "(", "identity", ".", "NumericIdentity", "(", "id", ")", ",", "lblArray", ")", "\n", "}" ]
// LookupIdentity looks up the identity by its labels but does not create it. // This function will first search through the local cache and fall back to // querying the kvstore.
[ "LookupIdentity", "looks", "up", "the", "identity", "by", "its", "labels", "but", "does", "not", "create", "it", ".", "This", "function", "will", "first", "search", "through", "the", "local", "cache", "and", "fall", "back", "to", "querying", "the", "kvstore", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/cache.go#L204-L228
163,565
cilium/cilium
pkg/identity/cache/cache.go
LookupReservedIdentityByLabels
func LookupReservedIdentityByLabels(lbls labels.Labels) *identity.Identity { if identity := identity.WellKnown.LookupByLabels(lbls); identity != nil { return identity } for _, lbl := range lbls { switch { // If the set of labels contain a fixed identity then and exists in // the map of reserved IDs then return the identity of that reserved ID. case lbl.Key == labels.LabelKeyFixedIdentity: id := identity.GetReservedID(lbl.Value) if id != identity.IdentityUnknown && identity.IsUserReservedIdentity(id) { return identity.LookupReservedIdentity(id) } // If a fixed identity was not found then we return nil to avoid // falling to a reserved identity. return nil // If it doesn't contain a fixed-identity then make sure the set of // labels only contains a single label and that label is of the reserved // type. This is to prevent users from adding cilium-reserved labels // into the workloads. case lbl.Source == labels.LabelSourceReserved: if len(lbls) != 1 { return nil } id := identity.GetReservedID(lbl.Key) if id != identity.IdentityUnknown && !identity.IsUserReservedIdentity(id) { return identity.LookupReservedIdentity(id) } } } return nil }
go
func LookupReservedIdentityByLabels(lbls labels.Labels) *identity.Identity { if identity := identity.WellKnown.LookupByLabels(lbls); identity != nil { return identity } for _, lbl := range lbls { switch { // If the set of labels contain a fixed identity then and exists in // the map of reserved IDs then return the identity of that reserved ID. case lbl.Key == labels.LabelKeyFixedIdentity: id := identity.GetReservedID(lbl.Value) if id != identity.IdentityUnknown && identity.IsUserReservedIdentity(id) { return identity.LookupReservedIdentity(id) } // If a fixed identity was not found then we return nil to avoid // falling to a reserved identity. return nil // If it doesn't contain a fixed-identity then make sure the set of // labels only contains a single label and that label is of the reserved // type. This is to prevent users from adding cilium-reserved labels // into the workloads. case lbl.Source == labels.LabelSourceReserved: if len(lbls) != 1 { return nil } id := identity.GetReservedID(lbl.Key) if id != identity.IdentityUnknown && !identity.IsUserReservedIdentity(id) { return identity.LookupReservedIdentity(id) } } } return nil }
[ "func", "LookupReservedIdentityByLabels", "(", "lbls", "labels", ".", "Labels", ")", "*", "identity", ".", "Identity", "{", "if", "identity", ":=", "identity", ".", "WellKnown", ".", "LookupByLabels", "(", "lbls", ")", ";", "identity", "!=", "nil", "{", "return", "identity", "\n", "}", "\n\n", "for", "_", ",", "lbl", ":=", "range", "lbls", "{", "switch", "{", "// If the set of labels contain a fixed identity then and exists in", "// the map of reserved IDs then return the identity of that reserved ID.", "case", "lbl", ".", "Key", "==", "labels", ".", "LabelKeyFixedIdentity", ":", "id", ":=", "identity", ".", "GetReservedID", "(", "lbl", ".", "Value", ")", "\n", "if", "id", "!=", "identity", ".", "IdentityUnknown", "&&", "identity", ".", "IsUserReservedIdentity", "(", "id", ")", "{", "return", "identity", ".", "LookupReservedIdentity", "(", "id", ")", "\n", "}", "\n", "// If a fixed identity was not found then we return nil to avoid", "// falling to a reserved identity.", "return", "nil", "\n", "// If it doesn't contain a fixed-identity then make sure the set of", "// labels only contains a single label and that label is of the reserved", "// type. This is to prevent users from adding cilium-reserved labels", "// into the workloads.", "case", "lbl", ".", "Source", "==", "labels", ".", "LabelSourceReserved", ":", "if", "len", "(", "lbls", ")", "!=", "1", "{", "return", "nil", "\n", "}", "\n", "id", ":=", "identity", ".", "GetReservedID", "(", "lbl", ".", "Key", ")", "\n", "if", "id", "!=", "identity", ".", "IdentityUnknown", "&&", "!", "identity", ".", "IsUserReservedIdentity", "(", "id", ")", "{", "return", "identity", ".", "LookupReservedIdentity", "(", "id", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// LookupReservedIdentityByLabels looks up a reserved identity by its labels and // returns it if found. Returns nil if not found.
[ "LookupReservedIdentityByLabels", "looks", "up", "a", "reserved", "identity", "by", "its", "labels", "and", "returns", "it", "if", "found", ".", "Returns", "nil", "if", "not", "found", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/cache.go#L232-L264
163,566
cilium/cilium
pkg/identity/cache/cache.go
LookupIdentityByID
func LookupIdentityByID(id identity.NumericIdentity) *identity.Identity { if id == identity.IdentityUnknown { return unknownIdentity } if identity := identity.LookupReservedIdentity(id); identity != nil { return identity } if IdentityAllocator == nil { return nil } if identity := localIdentities.lookupByID(id); identity != nil { return identity } allocatorKey, err := IdentityAllocator.GetByID(idpool.ID(id)) if err != nil { return nil } if gi, ok := allocatorKey.(globalIdentity); ok { return identity.NewIdentityFromLabelArray(id, gi.LabelArray) } return nil }
go
func LookupIdentityByID(id identity.NumericIdentity) *identity.Identity { if id == identity.IdentityUnknown { return unknownIdentity } if identity := identity.LookupReservedIdentity(id); identity != nil { return identity } if IdentityAllocator == nil { return nil } if identity := localIdentities.lookupByID(id); identity != nil { return identity } allocatorKey, err := IdentityAllocator.GetByID(idpool.ID(id)) if err != nil { return nil } if gi, ok := allocatorKey.(globalIdentity); ok { return identity.NewIdentityFromLabelArray(id, gi.LabelArray) } return nil }
[ "func", "LookupIdentityByID", "(", "id", "identity", ".", "NumericIdentity", ")", "*", "identity", ".", "Identity", "{", "if", "id", "==", "identity", ".", "IdentityUnknown", "{", "return", "unknownIdentity", "\n", "}", "\n\n", "if", "identity", ":=", "identity", ".", "LookupReservedIdentity", "(", "id", ")", ";", "identity", "!=", "nil", "{", "return", "identity", "\n", "}", "\n\n", "if", "IdentityAllocator", "==", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "identity", ":=", "localIdentities", ".", "lookupByID", "(", "id", ")", ";", "identity", "!=", "nil", "{", "return", "identity", "\n", "}", "\n\n", "allocatorKey", ",", "err", ":=", "IdentityAllocator", ".", "GetByID", "(", "idpool", ".", "ID", "(", "id", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", "\n", "}", "\n\n", "if", "gi", ",", "ok", ":=", "allocatorKey", ".", "(", "globalIdentity", ")", ";", "ok", "{", "return", "identity", ".", "NewIdentityFromLabelArray", "(", "id", ",", "gi", ".", "LabelArray", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// LookupIdentityByID returns the identity by ID. This function will first // search through the local cache and fall back to querying the kvstore.
[ "LookupIdentityByID", "returns", "the", "identity", "by", "ID", ".", "This", "function", "will", "first", "search", "through", "the", "local", "cache", "and", "fall", "back", "to", "querying", "the", "kvstore", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/cache.go#L270-L297
163,567
cilium/cilium
pkg/identity/cache/cache.go
AddUserDefinedNumericIdentitySet
func AddUserDefinedNumericIdentitySet(m map[string]string) error { // Validate first for k := range m { ni, err := identity.ParseNumericIdentity(k) if err != nil { return err } if !identity.IsUserReservedIdentity(ni) { return identity.ErrNotUserIdentity } } for k, lbl := range m { ni, _ := identity.ParseNumericIdentity(k) identity.AddUserDefinedNumericIdentity(ni, lbl) identity.AddReservedIdentity(ni, lbl) } return nil }
go
func AddUserDefinedNumericIdentitySet(m map[string]string) error { // Validate first for k := range m { ni, err := identity.ParseNumericIdentity(k) if err != nil { return err } if !identity.IsUserReservedIdentity(ni) { return identity.ErrNotUserIdentity } } for k, lbl := range m { ni, _ := identity.ParseNumericIdentity(k) identity.AddUserDefinedNumericIdentity(ni, lbl) identity.AddReservedIdentity(ni, lbl) } return nil }
[ "func", "AddUserDefinedNumericIdentitySet", "(", "m", "map", "[", "string", "]", "string", ")", "error", "{", "// Validate first", "for", "k", ":=", "range", "m", "{", "ni", ",", "err", ":=", "identity", ".", "ParseNumericIdentity", "(", "k", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "!", "identity", ".", "IsUserReservedIdentity", "(", "ni", ")", "{", "return", "identity", ".", "ErrNotUserIdentity", "\n", "}", "\n", "}", "\n", "for", "k", ",", "lbl", ":=", "range", "m", "{", "ni", ",", "_", ":=", "identity", ".", "ParseNumericIdentity", "(", "k", ")", "\n", "identity", ".", "AddUserDefinedNumericIdentity", "(", "ni", ",", "lbl", ")", "\n", "identity", ".", "AddReservedIdentity", "(", "ni", ",", "lbl", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// AddUserDefinedNumericIdentitySet adds all key-value pairs from the given map // to the map of user defined numeric identities and reserved identities. // The key-value pairs should map a numeric identity to a valid label. // Is not safe for concurrent use.
[ "AddUserDefinedNumericIdentitySet", "adds", "all", "key", "-", "value", "pairs", "from", "the", "given", "map", "to", "the", "map", "of", "user", "defined", "numeric", "identities", "and", "reserved", "identities", ".", "The", "key", "-", "value", "pairs", "should", "map", "a", "numeric", "identity", "to", "a", "valid", "label", ".", "Is", "not", "safe", "for", "concurrent", "use", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/cache/cache.go#L303-L320
163,568
cilium/cilium
pkg/k8s/client/clientset/versioned/fake/clientset_generated.go
CiliumV2
func (c *Clientset) CiliumV2() ciliumv2.CiliumV2Interface { return &fakeciliumv2.FakeCiliumV2{Fake: &c.Fake} }
go
func (c *Clientset) CiliumV2() ciliumv2.CiliumV2Interface { return &fakeciliumv2.FakeCiliumV2{Fake: &c.Fake} }
[ "func", "(", "c", "*", "Clientset", ")", "CiliumV2", "(", ")", "ciliumv2", ".", "CiliumV2Interface", "{", "return", "&", "fakeciliumv2", ".", "FakeCiliumV2", "{", "Fake", ":", "&", "c", ".", "Fake", "}", "\n", "}" ]
// CiliumV2 retrieves the CiliumV2Client
[ "CiliumV2", "retrieves", "the", "CiliumV2Client" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/k8s/client/clientset/versioned/fake/clientset_generated.go#L73-L75
163,569
cilium/cilium
pkg/endpoint/connector/ipam.go
IPv6Routes
func IPv6Routes(addr *models.NodeAddressing, linkMTU int) ([]route.Route, error) { ip := net.ParseIP(addr.IPV6.IP) if ip == nil { return []route.Route{}, fmt.Errorf("Invalid IP address: %s", addr.IPV6.IP) } return []route.Route{ { Prefix: net.IPNet{ IP: ip, Mask: defaults.ContainerIPv6Mask, }, }, { Prefix: defaults.IPv6DefaultRoute, Nexthop: &ip, MTU: linkMTU, }, }, nil }
go
func IPv6Routes(addr *models.NodeAddressing, linkMTU int) ([]route.Route, error) { ip := net.ParseIP(addr.IPV6.IP) if ip == nil { return []route.Route{}, fmt.Errorf("Invalid IP address: %s", addr.IPV6.IP) } return []route.Route{ { Prefix: net.IPNet{ IP: ip, Mask: defaults.ContainerIPv6Mask, }, }, { Prefix: defaults.IPv6DefaultRoute, Nexthop: &ip, MTU: linkMTU, }, }, nil }
[ "func", "IPv6Routes", "(", "addr", "*", "models", ".", "NodeAddressing", ",", "linkMTU", "int", ")", "(", "[", "]", "route", ".", "Route", ",", "error", ")", "{", "ip", ":=", "net", ".", "ParseIP", "(", "addr", ".", "IPV6", ".", "IP", ")", "\n", "if", "ip", "==", "nil", "{", "return", "[", "]", "route", ".", "Route", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "addr", ".", "IPV6", ".", "IP", ")", "\n", "}", "\n", "return", "[", "]", "route", ".", "Route", "{", "{", "Prefix", ":", "net", ".", "IPNet", "{", "IP", ":", "ip", ",", "Mask", ":", "defaults", ".", "ContainerIPv6Mask", ",", "}", ",", "}", ",", "{", "Prefix", ":", "defaults", ".", "IPv6DefaultRoute", ",", "Nexthop", ":", "&", "ip", ",", "MTU", ":", "linkMTU", ",", "}", ",", "}", ",", "nil", "\n", "}" ]
// IPv6Routes returns IPv6 routes to be installed in endpoint's networking namespace.
[ "IPv6Routes", "returns", "IPv6", "routes", "to", "be", "installed", "in", "endpoint", "s", "networking", "namespace", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/connector/ipam.go#L39-L57
163,570
cilium/cilium
pkg/endpoint/connector/ipam.go
IPv4Routes
func IPv4Routes(addr *models.NodeAddressing, linkMTU int) ([]route.Route, error) { ip := net.ParseIP(addr.IPV4.IP) if ip == nil { return []route.Route{}, fmt.Errorf("Invalid IP address: %s", addr.IPV4.IP) } return []route.Route{ { Prefix: net.IPNet{ IP: ip, Mask: defaults.ContainerIPv4Mask, }, }, { Prefix: defaults.IPv4DefaultRoute, Nexthop: &ip, MTU: linkMTU, }, }, nil }
go
func IPv4Routes(addr *models.NodeAddressing, linkMTU int) ([]route.Route, error) { ip := net.ParseIP(addr.IPV4.IP) if ip == nil { return []route.Route{}, fmt.Errorf("Invalid IP address: %s", addr.IPV4.IP) } return []route.Route{ { Prefix: net.IPNet{ IP: ip, Mask: defaults.ContainerIPv4Mask, }, }, { Prefix: defaults.IPv4DefaultRoute, Nexthop: &ip, MTU: linkMTU, }, }, nil }
[ "func", "IPv4Routes", "(", "addr", "*", "models", ".", "NodeAddressing", ",", "linkMTU", "int", ")", "(", "[", "]", "route", ".", "Route", ",", "error", ")", "{", "ip", ":=", "net", ".", "ParseIP", "(", "addr", ".", "IPV4", ".", "IP", ")", "\n", "if", "ip", "==", "nil", "{", "return", "[", "]", "route", ".", "Route", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "addr", ".", "IPV4", ".", "IP", ")", "\n", "}", "\n", "return", "[", "]", "route", ".", "Route", "{", "{", "Prefix", ":", "net", ".", "IPNet", "{", "IP", ":", "ip", ",", "Mask", ":", "defaults", ".", "ContainerIPv4Mask", ",", "}", ",", "}", ",", "{", "Prefix", ":", "defaults", ".", "IPv4DefaultRoute", ",", "Nexthop", ":", "&", "ip", ",", "MTU", ":", "linkMTU", ",", "}", ",", "}", ",", "nil", "\n", "}" ]
// IPv4Routes returns IPv4 routes to be installed in endpoint's networking namespace.
[ "IPv4Routes", "returns", "IPv4", "routes", "to", "be", "installed", "in", "endpoint", "s", "networking", "namespace", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/connector/ipam.go#L60-L78
163,571
cilium/cilium
pkg/endpoint/connector/ipam.go
SufficientAddressing
func SufficientAddressing(addr *models.NodeAddressing) error { if addr == nil { return fmt.Errorf("Cilium daemon did not provide addressing information") } if addr.IPV6 != nil && addr.IPV6.IP != "" { return nil } if addr.IPV4 != nil && addr.IPV4.IP != "" { return nil } return fmt.Errorf("Either IPv4 or IPv6 addressing must be provided") }
go
func SufficientAddressing(addr *models.NodeAddressing) error { if addr == nil { return fmt.Errorf("Cilium daemon did not provide addressing information") } if addr.IPV6 != nil && addr.IPV6.IP != "" { return nil } if addr.IPV4 != nil && addr.IPV4.IP != "" { return nil } return fmt.Errorf("Either IPv4 or IPv6 addressing must be provided") }
[ "func", "SufficientAddressing", "(", "addr", "*", "models", ".", "NodeAddressing", ")", "error", "{", "if", "addr", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "if", "addr", ".", "IPV6", "!=", "nil", "&&", "addr", ".", "IPV6", ".", "IP", "!=", "\"", "\"", "{", "return", "nil", "\n", "}", "\n\n", "if", "addr", ".", "IPV4", "!=", "nil", "&&", "addr", ".", "IPV4", ".", "IP", "!=", "\"", "\"", "{", "return", "nil", "\n", "}", "\n\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}" ]
// SufficientAddressing returns an error if the provided NodeAddressing does // not provide sufficient information to derive all IPAM required settings.
[ "SufficientAddressing", "returns", "an", "error", "if", "the", "provided", "NodeAddressing", "does", "not", "provide", "sufficient", "information", "to", "derive", "all", "IPAM", "required", "settings", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/connector/ipam.go#L82-L96
163,572
cilium/cilium
pkg/datapath/loader/metrics.go
GetMap
func (s *SpanStat) GetMap() map[string]*spanstat.SpanStat { return map[string]*spanstat.SpanStat{ "bpfCompilation": &s.bpfCompilation, "bpfWaitForELF": &s.bpfWaitForELF, "bpfWriteELF": &s.bpfWriteELF, "bpfLoadProg": &s.bpfLoadProg, } }
go
func (s *SpanStat) GetMap() map[string]*spanstat.SpanStat { return map[string]*spanstat.SpanStat{ "bpfCompilation": &s.bpfCompilation, "bpfWaitForELF": &s.bpfWaitForELF, "bpfWriteELF": &s.bpfWriteELF, "bpfLoadProg": &s.bpfLoadProg, } }
[ "func", "(", "s", "*", "SpanStat", ")", "GetMap", "(", ")", "map", "[", "string", "]", "*", "spanstat", ".", "SpanStat", "{", "return", "map", "[", "string", "]", "*", "spanstat", ".", "SpanStat", "{", "\"", "\"", ":", "&", "s", ".", "bpfCompilation", ",", "\"", "\"", ":", "&", "s", ".", "bpfWaitForELF", ",", "\"", "\"", ":", "&", "s", ".", "bpfWriteELF", ",", "\"", "\"", ":", "&", "s", ".", "bpfLoadProg", ",", "}", "\n", "}" ]
// GetMap returns a map of statistic names to stats
[ "GetMap", "returns", "a", "map", "of", "statistic", "names", "to", "stats" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/datapath/loader/metrics.go#L31-L38
163,573
cilium/cilium
pkg/ipcache/kvstore.go
release
func (k kvstoreImplementation) release(ctx context.Context, key string) error { return kvstore.Delete(key) }
go
func (k kvstoreImplementation) release(ctx context.Context, key string) error { return kvstore.Delete(key) }
[ "func", "(", "k", "kvstoreImplementation", ")", "release", "(", "ctx", "context", ".", "Context", ",", "key", "string", ")", "error", "{", "return", "kvstore", ".", "Delete", "(", "key", ")", "\n", "}" ]
// release removes the specified key from the kvstore.
[ "release", "removes", "the", "specified", "key", "from", "the", "kvstore", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/kvstore.go#L79-L81
163,574
cilium/cilium
pkg/ipcache/kvstore.go
release
func (r *kvReferenceCounter) release(ctx context.Context, key string) (err error) { r.Lock() defer r.Unlock() refcnt, ok := r.keys[key] // 0 if not found // avoid underflow and report bug if !ok || refcnt == 0 { log.WithField("key", key).Error("BUG: attempt to release ipcache entry while refcnt == 0") return nil } refcnt-- if refcnt == 0 { delete(r.keys, key) delete(r.marshaledIPIDPairs, key) err = r.store.release(ctx, key) } else { r.keys[key] = refcnt } return err }
go
func (r *kvReferenceCounter) release(ctx context.Context, key string) (err error) { r.Lock() defer r.Unlock() refcnt, ok := r.keys[key] // 0 if not found // avoid underflow and report bug if !ok || refcnt == 0 { log.WithField("key", key).Error("BUG: attempt to release ipcache entry while refcnt == 0") return nil } refcnt-- if refcnt == 0 { delete(r.keys, key) delete(r.marshaledIPIDPairs, key) err = r.store.release(ctx, key) } else { r.keys[key] = refcnt } return err }
[ "func", "(", "r", "*", "kvReferenceCounter", ")", "release", "(", "ctx", "context", ".", "Context", ",", "key", "string", ")", "(", "err", "error", ")", "{", "r", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "Unlock", "(", ")", "\n\n", "refcnt", ",", "ok", ":=", "r", ".", "keys", "[", "key", "]", "// 0 if not found", "\n", "// avoid underflow and report bug", "if", "!", "ok", "||", "refcnt", "==", "0", "{", "log", ".", "WithField", "(", "\"", "\"", ",", "key", ")", ".", "Error", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n\n", "refcnt", "--", "\n", "if", "refcnt", "==", "0", "{", "delete", "(", "r", ".", "keys", ",", "key", ")", "\n", "delete", "(", "r", ".", "marshaledIPIDPairs", ",", "key", ")", "\n", "err", "=", "r", ".", "store", ".", "release", "(", "ctx", ",", "key", ")", "\n", "}", "else", "{", "r", ".", "keys", "[", "key", "]", "=", "refcnt", "\n", "}", "\n", "return", "err", "\n", "}" ]
// release removes a reference to the specified key. If the number of // references reaches 0, the key is removed from the underlying kvstore.
[ "release", "removes", "a", "reference", "to", "the", "specified", "key", ".", "If", "the", "number", "of", "references", "reaches", "0", "the", "key", "is", "removed", "from", "the", "underlying", "kvstore", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/kvstore.go#L146-L166
163,575
cilium/cilium
pkg/ipcache/kvstore.go
NewIPIdentityWatcher
func NewIPIdentityWatcher(backend kvstore.BackendOperations) *IPIdentityWatcher { watcher := &IPIdentityWatcher{ backend: backend, stop: make(chan struct{}), synced: make(chan struct{}), } return watcher }
go
func NewIPIdentityWatcher(backend kvstore.BackendOperations) *IPIdentityWatcher { watcher := &IPIdentityWatcher{ backend: backend, stop: make(chan struct{}), synced: make(chan struct{}), } return watcher }
[ "func", "NewIPIdentityWatcher", "(", "backend", "kvstore", ".", "BackendOperations", ")", "*", "IPIdentityWatcher", "{", "watcher", ":=", "&", "IPIdentityWatcher", "{", "backend", ":", "backend", ",", "stop", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "synced", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "}", "\n\n", "return", "watcher", "\n", "}" ]
// NewIPIdentityWatcher creates a new IPIdentityWatcher using the specified // kvstore backend
[ "NewIPIdentityWatcher", "creates", "a", "new", "IPIdentityWatcher", "using", "the", "specified", "kvstore", "backend" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/kvstore.go#L248-L256
163,576
cilium/cilium
pkg/ipcache/kvstore.go
InitIPIdentityWatcher
func InitIPIdentityWatcher() { setupIPIdentityWatcher.Do(func() { globalMap = newKVReferenceCounter(kvstoreImplementation{}) go func() { log.Info("Starting IP identity watcher") watcher = NewIPIdentityWatcher(kvstore.Client()) close(initialized) watcher.Watch() }() }) }
go
func InitIPIdentityWatcher() { setupIPIdentityWatcher.Do(func() { globalMap = newKVReferenceCounter(kvstoreImplementation{}) go func() { log.Info("Starting IP identity watcher") watcher = NewIPIdentityWatcher(kvstore.Client()) close(initialized) watcher.Watch() }() }) }
[ "func", "InitIPIdentityWatcher", "(", ")", "{", "setupIPIdentityWatcher", ".", "Do", "(", "func", "(", ")", "{", "globalMap", "=", "newKVReferenceCounter", "(", "kvstoreImplementation", "{", "}", ")", "\n", "go", "func", "(", ")", "{", "log", ".", "Info", "(", "\"", "\"", ")", "\n", "watcher", "=", "NewIPIdentityWatcher", "(", "kvstore", ".", "Client", "(", ")", ")", "\n", "close", "(", "initialized", ")", "\n", "watcher", ".", "Watch", "(", ")", "\n", "}", "(", ")", "\n", "}", ")", "\n", "}" ]
// InitIPIdentityWatcher initializes the watcher for ip-identity mapping events // in the key-value store.
[ "InitIPIdentityWatcher", "initializes", "the", "watcher", "for", "ip", "-", "identity", "mapping", "events", "in", "the", "key", "-", "value", "store", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/kvstore.go#L386-L396
163,577
cilium/cilium
pkg/ipcache/ipcache.go
SetListeners
func (ipc *IPCache) SetListeners(listeners []IPIdentityMappingListener) { ipc.mutex.Lock() ipc.listeners = listeners ipc.mutex.Unlock() }
go
func (ipc *IPCache) SetListeners(listeners []IPIdentityMappingListener) { ipc.mutex.Lock() ipc.listeners = listeners ipc.mutex.Unlock() }
[ "func", "(", "ipc", "*", "IPCache", ")", "SetListeners", "(", "listeners", "[", "]", "IPIdentityMappingListener", ")", "{", "ipc", ".", "mutex", ".", "Lock", "(", ")", "\n", "ipc", ".", "listeners", "=", "listeners", "\n", "ipc", ".", "mutex", ".", "Unlock", "(", ")", "\n", "}" ]
// SetListeners sets the listeners for this IPCache.
[ "SetListeners", "sets", "the", "listeners", "for", "this", "IPCache", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/ipcache.go#L130-L134
163,578
cilium/cilium
pkg/ipcache/ipcache.go
checkPrefixes
func checkPrefixes(impl Implementation, prefixes []*net.IPNet) (err error) { IPIdentityCache.RLock() defer IPIdentityCache.RUnlock() if err = checkPrefixLengthsAgainstMap(impl, prefixes, IPIdentityCache.v4PrefixLengths, false); err != nil { return } return checkPrefixLengthsAgainstMap(impl, prefixes, IPIdentityCache.v6PrefixLengths, true) }
go
func checkPrefixes(impl Implementation, prefixes []*net.IPNet) (err error) { IPIdentityCache.RLock() defer IPIdentityCache.RUnlock() if err = checkPrefixLengthsAgainstMap(impl, prefixes, IPIdentityCache.v4PrefixLengths, false); err != nil { return } return checkPrefixLengthsAgainstMap(impl, prefixes, IPIdentityCache.v6PrefixLengths, true) }
[ "func", "checkPrefixes", "(", "impl", "Implementation", ",", "prefixes", "[", "]", "*", "net", ".", "IPNet", ")", "(", "err", "error", ")", "{", "IPIdentityCache", ".", "RLock", "(", ")", "\n", "defer", "IPIdentityCache", ".", "RUnlock", "(", ")", "\n\n", "if", "err", "=", "checkPrefixLengthsAgainstMap", "(", "impl", ",", "prefixes", ",", "IPIdentityCache", ".", "v4PrefixLengths", ",", "false", ")", ";", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "return", "checkPrefixLengthsAgainstMap", "(", "impl", ",", "prefixes", ",", "IPIdentityCache", ".", "v6PrefixLengths", ",", "true", ")", "\n", "}" ]
// checkPrefixes ensures that we will reject rules if the import of those // rules would cause the underlying implementation of the ipcache to exceed // the maximum number of supported CIDR prefix lengths.
[ "checkPrefixes", "ensures", "that", "we", "will", "reject", "rules", "if", "the", "import", "of", "those", "rules", "would", "cause", "the", "underlying", "implementation", "of", "the", "ipcache", "to", "exceed", "the", "maximum", "number", "of", "supported", "CIDR", "prefix", "lengths", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/ipcache.go#L164-L172
163,579
cilium/cilium
pkg/ipcache/ipcache.go
refPrefixLength
func refPrefixLength(prefixLengths map[int]int, length int) { if _, ok := prefixLengths[length]; ok { prefixLengths[length]++ } else { prefixLengths[length] = 1 } }
go
func refPrefixLength(prefixLengths map[int]int, length int) { if _, ok := prefixLengths[length]; ok { prefixLengths[length]++ } else { prefixLengths[length] = 1 } }
[ "func", "refPrefixLength", "(", "prefixLengths", "map", "[", "int", "]", "int", ",", "length", "int", ")", "{", "if", "_", ",", "ok", ":=", "prefixLengths", "[", "length", "]", ";", "ok", "{", "prefixLengths", "[", "length", "]", "++", "\n", "}", "else", "{", "prefixLengths", "[", "length", "]", "=", "1", "\n", "}", "\n", "}" ]
// refPrefixLength adds one reference to the prefix length in the map.
[ "refPrefixLength", "adds", "one", "reference", "to", "the", "prefix", "length", "in", "the", "map", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/ipcache.go#L175-L181
163,580
cilium/cilium
pkg/ipcache/ipcache.go
unrefPrefixLength
func unrefPrefixLength(prefixLengths map[int]int, length int) { value, _ := prefixLengths[length] if value <= 1 { delete(prefixLengths, length) } else { prefixLengths[length]-- } }
go
func unrefPrefixLength(prefixLengths map[int]int, length int) { value, _ := prefixLengths[length] if value <= 1 { delete(prefixLengths, length) } else { prefixLengths[length]-- } }
[ "func", "unrefPrefixLength", "(", "prefixLengths", "map", "[", "int", "]", "int", ",", "length", "int", ")", "{", "value", ",", "_", ":=", "prefixLengths", "[", "length", "]", "\n", "if", "value", "<=", "1", "{", "delete", "(", "prefixLengths", ",", "length", ")", "\n", "}", "else", "{", "prefixLengths", "[", "length", "]", "--", "\n", "}", "\n", "}" ]
// refPrefixLength removes one reference from the prefix length in the map.
[ "refPrefixLength", "removes", "one", "reference", "from", "the", "prefix", "length", "in", "the", "map", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/ipcache.go#L184-L191
163,581
cilium/cilium
pkg/ipcache/ipcache.go
endpointIPToCIDR
func endpointIPToCIDR(ip net.IP) *net.IPNet { bits := net.IPv6len * 8 if ip.To4() != nil { bits = net.IPv4len * 8 } return &net.IPNet{ IP: ip, Mask: net.CIDRMask(bits, bits), } }
go
func endpointIPToCIDR(ip net.IP) *net.IPNet { bits := net.IPv6len * 8 if ip.To4() != nil { bits = net.IPv4len * 8 } return &net.IPNet{ IP: ip, Mask: net.CIDRMask(bits, bits), } }
[ "func", "endpointIPToCIDR", "(", "ip", "net", ".", "IP", ")", "*", "net", ".", "IPNet", "{", "bits", ":=", "net", ".", "IPv6len", "*", "8", "\n", "if", "ip", ".", "To4", "(", ")", "!=", "nil", "{", "bits", "=", "net", ".", "IPv4len", "*", "8", "\n", "}", "\n", "return", "&", "net", ".", "IPNet", "{", "IP", ":", "ip", ",", "Mask", ":", "net", ".", "CIDRMask", "(", "bits", ",", "bits", ")", ",", "}", "\n", "}" ]
// endpointIPToCIDR converts the endpoint IP into an equivalent full CIDR.
[ "endpointIPToCIDR", "converts", "the", "endpoint", "IP", "into", "an", "equivalent", "full", "CIDR", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/ipcache.go#L209-L218
163,582
cilium/cilium
pkg/ipcache/ipcache.go
DumpToListenerLocked
func (ipc *IPCache) DumpToListenerLocked(listener IPIdentityMappingListener) { for ip, identity := range ipc.ipToIdentityCache { hostIP, encryptKey := ipc.getHostIPCache(ip) _, cidr, err := net.ParseCIDR(ip) if err != nil { endpointIP := net.ParseIP(ip) cidr = endpointIPToCIDR(endpointIP) } listener.OnIPIdentityCacheChange(Upsert, *cidr, nil, hostIP, nil, identity.ID, encryptKey) } }
go
func (ipc *IPCache) DumpToListenerLocked(listener IPIdentityMappingListener) { for ip, identity := range ipc.ipToIdentityCache { hostIP, encryptKey := ipc.getHostIPCache(ip) _, cidr, err := net.ParseCIDR(ip) if err != nil { endpointIP := net.ParseIP(ip) cidr = endpointIPToCIDR(endpointIP) } listener.OnIPIdentityCacheChange(Upsert, *cidr, nil, hostIP, nil, identity.ID, encryptKey) } }
[ "func", "(", "ipc", "*", "IPCache", ")", "DumpToListenerLocked", "(", "listener", "IPIdentityMappingListener", ")", "{", "for", "ip", ",", "identity", ":=", "range", "ipc", ".", "ipToIdentityCache", "{", "hostIP", ",", "encryptKey", ":=", "ipc", ".", "getHostIPCache", "(", "ip", ")", "\n", "_", ",", "cidr", ",", "err", ":=", "net", ".", "ParseCIDR", "(", "ip", ")", "\n", "if", "err", "!=", "nil", "{", "endpointIP", ":=", "net", ".", "ParseIP", "(", "ip", ")", "\n", "cidr", "=", "endpointIPToCIDR", "(", "endpointIP", ")", "\n", "}", "\n", "listener", ".", "OnIPIdentityCacheChange", "(", "Upsert", ",", "*", "cidr", ",", "nil", ",", "hostIP", ",", "nil", ",", "identity", ".", "ID", ",", "encryptKey", ")", "\n", "}", "\n", "}" ]
// DumpToListenerLocked dumps the entire contents of the IPCache by triggering // the listener's "OnIPIdentityCacheChange" method for each entry in the cache.
[ "DumpToListenerLocked", "dumps", "the", "entire", "contents", "of", "the", "IPCache", "by", "triggering", "the", "listener", "s", "OnIPIdentityCacheChange", "method", "for", "each", "entry", "in", "the", "cache", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/ipcache.go#L345-L355
163,583
cilium/cilium
pkg/ipcache/ipcache.go
deleteLocked
func (ipc *IPCache) deleteLocked(ip string, source Source) { scopedLog := log.WithFields(logrus.Fields{ logfields.IPAddr: ip, }) cachedIdentity, found := ipc.ipToIdentityCache[ip] if !found { scopedLog.Debug("Attempt to remove non-existing IP from ipcache layer") return } if cachedIdentity.Source != source { scopedLog.WithField("source", cachedIdentity.Source). Debugf("Skipping delete of identity from source %s", source) return } var cidr *net.IPNet cacheModification := Delete oldHostIP, encryptKey := ipc.getHostIPCache(ip) var newHostIP net.IP var oldIdentity *identity.NumericIdentity newIdentity := cachedIdentity callbackListeners := true var err error if _, cidr, err = net.ParseCIDR(ip); err == nil { // Remove a reference for the prefix length if this is a CIDR. pl, bits := cidr.Mask.Size() switch bits { case net.IPv6len * 8: unrefPrefixLength(ipc.v6PrefixLengths, pl) case net.IPv4len * 8: unrefPrefixLength(ipc.v4PrefixLengths, pl) } // Check whether the deleted CIDR was shadowed by an endpoint IP. In // this case, skip calling back the listeners since they don't know // about its mapping. if _, endpointIPFound := ipc.ipToIdentityCache[cidr.IP.String()]; endpointIPFound { scopedLog.Debug("Deleting CIDR shadowed by endpoint IP") callbackListeners = false } } else if endpointIP := net.ParseIP(ip); endpointIP != nil { // Endpoint IP. // Convert the endpoint IP into an equivalent full CIDR. bits := net.IPv6len * 8 if endpointIP.To4() != nil { bits = net.IPv4len * 8 } cidr = &net.IPNet{ IP: endpointIP, Mask: net.CIDRMask(bits, bits), } // Check whether the deleted endpoint IP was shadowing that CIDR, and // restore its mapping with the listeners if that was the case. cidrStr := cidr.String() if cidrIdentity, cidrFound := ipc.ipToIdentityCache[cidrStr]; cidrFound { newHostIP, _ = ipc.getHostIPCache(cidrStr) if cidrIdentity.ID != cachedIdentity.ID || bytes.Compare(oldHostIP, newHostIP) != 0 { scopedLog.Debug("Removal of endpoint IP revives shadowed CIDR to identity mapping") cacheModification = Upsert oldIdentity = &cachedIdentity.ID newIdentity = cidrIdentity } else { // The endpoint IP and the CIDR were associated with the same // identity and host IP. Nothing changes for the listeners. callbackListeners = false } } } else { scopedLog.Error("Attempt to delete invalid IP from ipcache layer") return } scopedLog.Debug("Deleting IP from ipcache layer") delete(ipc.ipToIdentityCache, ip) delete(ipc.identityToIPCache[cachedIdentity.ID], ip) if len(ipc.identityToIPCache[cachedIdentity.ID]) == 0 { delete(ipc.identityToIPCache, cachedIdentity.ID) } delete(ipc.ipToHostIPCache, ip) if callbackListeners { for _, listener := range ipc.listeners { listener.OnIPIdentityCacheChange(cacheModification, *cidr, oldHostIP, newHostIP, oldIdentity, newIdentity.ID, encryptKey) } } }
go
func (ipc *IPCache) deleteLocked(ip string, source Source) { scopedLog := log.WithFields(logrus.Fields{ logfields.IPAddr: ip, }) cachedIdentity, found := ipc.ipToIdentityCache[ip] if !found { scopedLog.Debug("Attempt to remove non-existing IP from ipcache layer") return } if cachedIdentity.Source != source { scopedLog.WithField("source", cachedIdentity.Source). Debugf("Skipping delete of identity from source %s", source) return } var cidr *net.IPNet cacheModification := Delete oldHostIP, encryptKey := ipc.getHostIPCache(ip) var newHostIP net.IP var oldIdentity *identity.NumericIdentity newIdentity := cachedIdentity callbackListeners := true var err error if _, cidr, err = net.ParseCIDR(ip); err == nil { // Remove a reference for the prefix length if this is a CIDR. pl, bits := cidr.Mask.Size() switch bits { case net.IPv6len * 8: unrefPrefixLength(ipc.v6PrefixLengths, pl) case net.IPv4len * 8: unrefPrefixLength(ipc.v4PrefixLengths, pl) } // Check whether the deleted CIDR was shadowed by an endpoint IP. In // this case, skip calling back the listeners since they don't know // about its mapping. if _, endpointIPFound := ipc.ipToIdentityCache[cidr.IP.String()]; endpointIPFound { scopedLog.Debug("Deleting CIDR shadowed by endpoint IP") callbackListeners = false } } else if endpointIP := net.ParseIP(ip); endpointIP != nil { // Endpoint IP. // Convert the endpoint IP into an equivalent full CIDR. bits := net.IPv6len * 8 if endpointIP.To4() != nil { bits = net.IPv4len * 8 } cidr = &net.IPNet{ IP: endpointIP, Mask: net.CIDRMask(bits, bits), } // Check whether the deleted endpoint IP was shadowing that CIDR, and // restore its mapping with the listeners if that was the case. cidrStr := cidr.String() if cidrIdentity, cidrFound := ipc.ipToIdentityCache[cidrStr]; cidrFound { newHostIP, _ = ipc.getHostIPCache(cidrStr) if cidrIdentity.ID != cachedIdentity.ID || bytes.Compare(oldHostIP, newHostIP) != 0 { scopedLog.Debug("Removal of endpoint IP revives shadowed CIDR to identity mapping") cacheModification = Upsert oldIdentity = &cachedIdentity.ID newIdentity = cidrIdentity } else { // The endpoint IP and the CIDR were associated with the same // identity and host IP. Nothing changes for the listeners. callbackListeners = false } } } else { scopedLog.Error("Attempt to delete invalid IP from ipcache layer") return } scopedLog.Debug("Deleting IP from ipcache layer") delete(ipc.ipToIdentityCache, ip) delete(ipc.identityToIPCache[cachedIdentity.ID], ip) if len(ipc.identityToIPCache[cachedIdentity.ID]) == 0 { delete(ipc.identityToIPCache, cachedIdentity.ID) } delete(ipc.ipToHostIPCache, ip) if callbackListeners { for _, listener := range ipc.listeners { listener.OnIPIdentityCacheChange(cacheModification, *cidr, oldHostIP, newHostIP, oldIdentity, newIdentity.ID, encryptKey) } } }
[ "func", "(", "ipc", "*", "IPCache", ")", "deleteLocked", "(", "ip", "string", ",", "source", "Source", ")", "{", "scopedLog", ":=", "log", ".", "WithFields", "(", "logrus", ".", "Fields", "{", "logfields", ".", "IPAddr", ":", "ip", ",", "}", ")", "\n\n", "cachedIdentity", ",", "found", ":=", "ipc", ".", "ipToIdentityCache", "[", "ip", "]", "\n", "if", "!", "found", "{", "scopedLog", ".", "Debug", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "if", "cachedIdentity", ".", "Source", "!=", "source", "{", "scopedLog", ".", "WithField", "(", "\"", "\"", ",", "cachedIdentity", ".", "Source", ")", ".", "Debugf", "(", "\"", "\"", ",", "source", ")", "\n", "return", "\n", "}", "\n\n", "var", "cidr", "*", "net", ".", "IPNet", "\n", "cacheModification", ":=", "Delete", "\n", "oldHostIP", ",", "encryptKey", ":=", "ipc", ".", "getHostIPCache", "(", "ip", ")", "\n", "var", "newHostIP", "net", ".", "IP", "\n", "var", "oldIdentity", "*", "identity", ".", "NumericIdentity", "\n", "newIdentity", ":=", "cachedIdentity", "\n", "callbackListeners", ":=", "true", "\n\n", "var", "err", "error", "\n", "if", "_", ",", "cidr", ",", "err", "=", "net", ".", "ParseCIDR", "(", "ip", ")", ";", "err", "==", "nil", "{", "// Remove a reference for the prefix length if this is a CIDR.", "pl", ",", "bits", ":=", "cidr", ".", "Mask", ".", "Size", "(", ")", "\n", "switch", "bits", "{", "case", "net", ".", "IPv6len", "*", "8", ":", "unrefPrefixLength", "(", "ipc", ".", "v6PrefixLengths", ",", "pl", ")", "\n", "case", "net", ".", "IPv4len", "*", "8", ":", "unrefPrefixLength", "(", "ipc", ".", "v4PrefixLengths", ",", "pl", ")", "\n", "}", "\n\n", "// Check whether the deleted CIDR was shadowed by an endpoint IP. In", "// this case, skip calling back the listeners since they don't know", "// about its mapping.", "if", "_", ",", "endpointIPFound", ":=", "ipc", ".", "ipToIdentityCache", "[", "cidr", ".", "IP", ".", "String", "(", ")", "]", ";", "endpointIPFound", "{", "scopedLog", ".", "Debug", "(", "\"", "\"", ")", "\n", "callbackListeners", "=", "false", "\n", "}", "\n", "}", "else", "if", "endpointIP", ":=", "net", ".", "ParseIP", "(", "ip", ")", ";", "endpointIP", "!=", "nil", "{", "// Endpoint IP.", "// Convert the endpoint IP into an equivalent full CIDR.", "bits", ":=", "net", ".", "IPv6len", "*", "8", "\n", "if", "endpointIP", ".", "To4", "(", ")", "!=", "nil", "{", "bits", "=", "net", ".", "IPv4len", "*", "8", "\n", "}", "\n", "cidr", "=", "&", "net", ".", "IPNet", "{", "IP", ":", "endpointIP", ",", "Mask", ":", "net", ".", "CIDRMask", "(", "bits", ",", "bits", ")", ",", "}", "\n\n", "// Check whether the deleted endpoint IP was shadowing that CIDR, and", "// restore its mapping with the listeners if that was the case.", "cidrStr", ":=", "cidr", ".", "String", "(", ")", "\n", "if", "cidrIdentity", ",", "cidrFound", ":=", "ipc", ".", "ipToIdentityCache", "[", "cidrStr", "]", ";", "cidrFound", "{", "newHostIP", ",", "_", "=", "ipc", ".", "getHostIPCache", "(", "cidrStr", ")", "\n", "if", "cidrIdentity", ".", "ID", "!=", "cachedIdentity", ".", "ID", "||", "bytes", ".", "Compare", "(", "oldHostIP", ",", "newHostIP", ")", "!=", "0", "{", "scopedLog", ".", "Debug", "(", "\"", "\"", ")", "\n", "cacheModification", "=", "Upsert", "\n", "oldIdentity", "=", "&", "cachedIdentity", ".", "ID", "\n", "newIdentity", "=", "cidrIdentity", "\n", "}", "else", "{", "// The endpoint IP and the CIDR were associated with the same", "// identity and host IP. Nothing changes for the listeners.", "callbackListeners", "=", "false", "\n", "}", "\n", "}", "\n", "}", "else", "{", "scopedLog", ".", "Error", "(", "\"", "\"", ")", "\n", "return", "\n", "}", "\n\n", "scopedLog", ".", "Debug", "(", "\"", "\"", ")", "\n\n", "delete", "(", "ipc", ".", "ipToIdentityCache", ",", "ip", ")", "\n", "delete", "(", "ipc", ".", "identityToIPCache", "[", "cachedIdentity", ".", "ID", "]", ",", "ip", ")", "\n", "if", "len", "(", "ipc", ".", "identityToIPCache", "[", "cachedIdentity", ".", "ID", "]", ")", "==", "0", "{", "delete", "(", "ipc", ".", "identityToIPCache", ",", "cachedIdentity", ".", "ID", ")", "\n", "}", "\n", "delete", "(", "ipc", ".", "ipToHostIPCache", ",", "ip", ")", "\n\n", "if", "callbackListeners", "{", "for", "_", ",", "listener", ":=", "range", "ipc", ".", "listeners", "{", "listener", ".", "OnIPIdentityCacheChange", "(", "cacheModification", ",", "*", "cidr", ",", "oldHostIP", ",", "newHostIP", ",", "oldIdentity", ",", "newIdentity", ".", "ID", ",", "encryptKey", ")", "\n", "}", "\n", "}", "\n", "}" ]
// deleteLocked removes removes the provided IP-to-security-identity mapping // from ipc with the assumption that the IPCache's mutex is held.
[ "deleteLocked", "removes", "removes", "the", "provided", "IP", "-", "to", "-", "security", "-", "identity", "mapping", "from", "ipc", "with", "the", "assumption", "that", "the", "IPCache", "s", "mutex", "is", "held", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/ipcache.go#L359-L449
163,584
cilium/cilium
pkg/ipcache/ipcache.go
Delete
func (ipc *IPCache) Delete(IP string, source Source) { ipc.mutex.Lock() defer ipc.mutex.Unlock() ipc.deleteLocked(IP, source) }
go
func (ipc *IPCache) Delete(IP string, source Source) { ipc.mutex.Lock() defer ipc.mutex.Unlock() ipc.deleteLocked(IP, source) }
[ "func", "(", "ipc", "*", "IPCache", ")", "Delete", "(", "IP", "string", ",", "source", "Source", ")", "{", "ipc", ".", "mutex", ".", "Lock", "(", ")", "\n", "defer", "ipc", ".", "mutex", ".", "Unlock", "(", ")", "\n", "ipc", ".", "deleteLocked", "(", "IP", ",", "source", ")", "\n", "}" ]
// Delete removes the provided IP-to-security-identity mapping from the IPCache.
[ "Delete", "removes", "the", "provided", "IP", "-", "to", "-", "security", "-", "identity", "mapping", "from", "the", "IPCache", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/ipcache.go#L452-L456
163,585
cilium/cilium
pkg/ipcache/ipcache.go
LookupByIP
func (ipc *IPCache) LookupByIP(IP string) (Identity, bool) { ipc.mutex.RLock() defer ipc.mutex.RUnlock() return ipc.LookupByIPRLocked(IP) }
go
func (ipc *IPCache) LookupByIP(IP string) (Identity, bool) { ipc.mutex.RLock() defer ipc.mutex.RUnlock() return ipc.LookupByIPRLocked(IP) }
[ "func", "(", "ipc", "*", "IPCache", ")", "LookupByIP", "(", "IP", "string", ")", "(", "Identity", ",", "bool", ")", "{", "ipc", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "ipc", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "ipc", ".", "LookupByIPRLocked", "(", "IP", ")", "\n", "}" ]
// LookupByIP returns the corresponding security identity that endpoint IP maps // to within the provided IPCache, as well as if the corresponding entry exists // in the IPCache.
[ "LookupByIP", "returns", "the", "corresponding", "security", "identity", "that", "endpoint", "IP", "maps", "to", "within", "the", "provided", "IPCache", "as", "well", "as", "if", "the", "corresponding", "entry", "exists", "in", "the", "IPCache", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/ipcache.go#L461-L465
163,586
cilium/cilium
pkg/ipcache/ipcache.go
LookupByIPRLocked
func (ipc *IPCache) LookupByIPRLocked(IP string) (Identity, bool) { identity, exists := ipc.ipToIdentityCache[IP] return identity, exists }
go
func (ipc *IPCache) LookupByIPRLocked(IP string) (Identity, bool) { identity, exists := ipc.ipToIdentityCache[IP] return identity, exists }
[ "func", "(", "ipc", "*", "IPCache", ")", "LookupByIPRLocked", "(", "IP", "string", ")", "(", "Identity", ",", "bool", ")", "{", "identity", ",", "exists", ":=", "ipc", ".", "ipToIdentityCache", "[", "IP", "]", "\n", "return", "identity", ",", "exists", "\n", "}" ]
// LookupByIPRLocked returns the corresponding security identity that endpoint IP maps // to within the provided IPCache, as well as if the corresponding entry exists // in the IPCache.
[ "LookupByIPRLocked", "returns", "the", "corresponding", "security", "identity", "that", "endpoint", "IP", "maps", "to", "within", "the", "provided", "IPCache", "as", "well", "as", "if", "the", "corresponding", "entry", "exists", "in", "the", "IPCache", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/ipcache.go#L470-L474
163,587
cilium/cilium
pkg/ipcache/ipcache.go
LookupByPrefix
func (ipc *IPCache) LookupByPrefix(IP string) (Identity, bool) { ipc.mutex.RLock() defer ipc.mutex.RUnlock() return ipc.LookupByPrefixRLocked(IP) }
go
func (ipc *IPCache) LookupByPrefix(IP string) (Identity, bool) { ipc.mutex.RLock() defer ipc.mutex.RUnlock() return ipc.LookupByPrefixRLocked(IP) }
[ "func", "(", "ipc", "*", "IPCache", ")", "LookupByPrefix", "(", "IP", "string", ")", "(", "Identity", ",", "bool", ")", "{", "ipc", ".", "mutex", ".", "RLock", "(", ")", "\n", "defer", "ipc", ".", "mutex", ".", "RUnlock", "(", ")", "\n", "return", "ipc", ".", "LookupByPrefixRLocked", "(", "IP", ")", "\n", "}" ]
// LookupByPrefix returns the corresponding security identity that endpoint IP // maps to within the provided IPCache, as well as if the corresponding entry // exists in the IPCache.
[ "LookupByPrefix", "returns", "the", "corresponding", "security", "identity", "that", "endpoint", "IP", "maps", "to", "within", "the", "provided", "IPCache", "as", "well", "as", "if", "the", "corresponding", "entry", "exists", "in", "the", "IPCache", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/ipcache/ipcache.go#L498-L502
163,588
cilium/cilium
pkg/node/node_address_linux.go
firstGlobalV6Addr
func firstGlobalV6Addr(intf string, preferredIP net.IP) (net.IP, error) { return firstGlobalAddr(intf, preferredIP, netlink.FAMILY_V6) }
go
func firstGlobalV6Addr(intf string, preferredIP net.IP) (net.IP, error) { return firstGlobalAddr(intf, preferredIP, netlink.FAMILY_V6) }
[ "func", "firstGlobalV6Addr", "(", "intf", "string", ",", "preferredIP", "net", ".", "IP", ")", "(", "net", ".", "IP", ",", "error", ")", "{", "return", "firstGlobalAddr", "(", "intf", ",", "preferredIP", ",", "netlink", ".", "FAMILY_V6", ")", "\n", "}" ]
// firstGlobalV6Addr returns first IPv6 global IP of an interface, see // firstGlobalV4Addr for more details.
[ "firstGlobalV6Addr", "returns", "first", "IPv6", "global", "IP", "of", "an", "interface", "see", "firstGlobalV4Addr", "for", "more", "details", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/node/node_address_linux.go#L155-L157
163,589
cilium/cilium
pkg/node/node_address_linux.go
SetInternalIPv4From
func SetInternalIPv4From(ifaceName string) error { l, err := netlink.LinkByName(ifaceName) if err != nil { return errors.New("unable to retrieve interface attributes") } v4Addrs, err := netlink.AddrList(l, netlink.FAMILY_V4) if err != nil { return errors.New("unable to retrieve interface IPv4 address") } for _, ip := range v4Addrs { if netlink.Scope(ip.Scope) == netlink.SCOPE_UNIVERSE { SetInternalIPv4(ip.IP) return nil } } return errors.New("unable to find IP addresses with scope global") }
go
func SetInternalIPv4From(ifaceName string) error { l, err := netlink.LinkByName(ifaceName) if err != nil { return errors.New("unable to retrieve interface attributes") } v4Addrs, err := netlink.AddrList(l, netlink.FAMILY_V4) if err != nil { return errors.New("unable to retrieve interface IPv4 address") } for _, ip := range v4Addrs { if netlink.Scope(ip.Scope) == netlink.SCOPE_UNIVERSE { SetInternalIPv4(ip.IP) return nil } } return errors.New("unable to find IP addresses with scope global") }
[ "func", "SetInternalIPv4From", "(", "ifaceName", "string", ")", "error", "{", "l", ",", "err", ":=", "netlink", ".", "LinkByName", "(", "ifaceName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "v4Addrs", ",", "err", ":=", "netlink", ".", "AddrList", "(", "l", ",", "netlink", ".", "FAMILY_V4", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "for", "_", ",", "ip", ":=", "range", "v4Addrs", "{", "if", "netlink", ".", "Scope", "(", "ip", ".", "Scope", ")", "==", "netlink", ".", "SCOPE_UNIVERSE", "{", "SetInternalIPv4", "(", "ip", ".", "IP", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}" ]
// SetInternalIPv4From sets the internal IPv4 with the first global address // found in that interface.
[ "SetInternalIPv4From", "sets", "the", "internal", "IPv4", "with", "the", "first", "global", "address", "found", "in", "that", "interface", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/node/node_address_linux.go#L186-L202
163,590
cilium/cilium
api/v1/models/endpoint_policy_enabled.go
Validate
func (m EndpointPolicyEnabled) Validate(formats strfmt.Registry) error { var res []error // value enum if err := m.validateEndpointPolicyEnabledEnum("", "body", m); err != nil { return err } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
go
func (m EndpointPolicyEnabled) Validate(formats strfmt.Registry) error { var res []error // value enum if err := m.validateEndpointPolicyEnabledEnum("", "body", m); err != nil { return err } if len(res) > 0 { return errors.CompositeValidationError(res...) } return nil }
[ "func", "(", "m", "EndpointPolicyEnabled", ")", "Validate", "(", "formats", "strfmt", ".", "Registry", ")", "error", "{", "var", "res", "[", "]", "error", "\n\n", "// value enum", "if", "err", ":=", "m", ".", "validateEndpointPolicyEnabledEnum", "(", "\"", "\"", ",", "\"", "\"", ",", "m", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "len", "(", "res", ")", ">", "0", "{", "return", "errors", ".", "CompositeValidationError", "(", "res", "...", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate validates this endpoint policy enabled
[ "Validate", "validates", "this", "endpoint", "policy", "enabled" ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/models/endpoint_policy_enabled.go#L57-L69
163,591
cilium/cilium
pkg/service/id_local.go
NewIDAllocator
func NewIDAllocator(nextID uint32, maxID uint32) *IDAllocator { return &IDAllocator{ entitiesID: map[uint32]*loadbalancer.L3n4AddrID{}, entities: map[string]uint32{}, nextID: nextID, maxID: maxID, initNextID: nextID, initMaxID: maxID, } }
go
func NewIDAllocator(nextID uint32, maxID uint32) *IDAllocator { return &IDAllocator{ entitiesID: map[uint32]*loadbalancer.L3n4AddrID{}, entities: map[string]uint32{}, nextID: nextID, maxID: maxID, initNextID: nextID, initMaxID: maxID, } }
[ "func", "NewIDAllocator", "(", "nextID", "uint32", ",", "maxID", "uint32", ")", "*", "IDAllocator", "{", "return", "&", "IDAllocator", "{", "entitiesID", ":", "map", "[", "uint32", "]", "*", "loadbalancer", ".", "L3n4AddrID", "{", "}", ",", "entities", ":", "map", "[", "string", "]", "uint32", "{", "}", ",", "nextID", ":", "nextID", ",", "maxID", ":", "maxID", ",", "initNextID", ":", "nextID", ",", "initMaxID", ":", "maxID", ",", "}", "\n", "}" ]
// NewIDAllocator creates a new ID allocator instance.
[ "NewIDAllocator", "creates", "a", "new", "ID", "allocator", "instance", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/service/id_local.go#L54-L63
163,592
cilium/cilium
pkg/policy/api/zz_generated.deepcopy.go
DeepCopy
func (in *AWSGroup) DeepCopy() *AWSGroup { if in == nil { return nil } out := new(AWSGroup) in.DeepCopyInto(out) return out }
go
func (in *AWSGroup) DeepCopy() *AWSGroup { if in == nil { return nil } out := new(AWSGroup) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "AWSGroup", ")", "DeepCopy", "(", ")", "*", "AWSGroup", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "AWSGroup", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSGroup.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "AWSGroup", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/zz_generated.deepcopy.go#L50-L57
163,593
cilium/cilium
pkg/policy/api/zz_generated.deepcopy.go
DeepCopy
func (in *CIDRRule) DeepCopy() *CIDRRule { if in == nil { return nil } out := new(CIDRRule) in.DeepCopyInto(out) return out }
go
func (in *CIDRRule) DeepCopy() *CIDRRule { if in == nil { return nil } out := new(CIDRRule) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "CIDRRule", ")", "DeepCopy", "(", ")", "*", "CIDRRule", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "CIDRRule", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CIDRRule.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "CIDRRule", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/zz_generated.deepcopy.go#L71-L78
163,594
cilium/cilium
pkg/policy/api/zz_generated.deepcopy.go
DeepCopy
func (in CIDRRuleSlice) DeepCopy() CIDRRuleSlice { if in == nil { return nil } out := new(CIDRRuleSlice) in.DeepCopyInto(out) return *out }
go
func (in CIDRRuleSlice) DeepCopy() CIDRRuleSlice { if in == nil { return nil } out := new(CIDRRuleSlice) in.DeepCopyInto(out) return *out }
[ "func", "(", "in", "CIDRRuleSlice", ")", "DeepCopy", "(", ")", "CIDRRuleSlice", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "CIDRRuleSlice", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "*", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CIDRRuleSlice.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "CIDRRuleSlice", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/zz_generated.deepcopy.go#L93-L100
163,595
cilium/cilium
pkg/policy/api/zz_generated.deepcopy.go
DeepCopy
func (in CIDRSlice) DeepCopy() CIDRSlice { if in == nil { return nil } out := new(CIDRSlice) in.DeepCopyInto(out) return *out }
go
func (in CIDRSlice) DeepCopy() CIDRSlice { if in == nil { return nil } out := new(CIDRSlice) in.DeepCopyInto(out) return *out }
[ "func", "(", "in", "CIDRSlice", ")", "DeepCopy", "(", ")", "CIDRSlice", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "CIDRSlice", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "*", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CIDRSlice.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "CIDRSlice", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/zz_generated.deepcopy.go#L113-L120
163,596
cilium/cilium
pkg/policy/api/zz_generated.deepcopy.go
DeepCopy
func (in *EgressRule) DeepCopy() *EgressRule { if in == nil { return nil } out := new(EgressRule) in.DeepCopyInto(out) return out }
go
func (in *EgressRule) DeepCopy() *EgressRule { if in == nil { return nil } out := new(EgressRule) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "EgressRule", ")", "DeepCopy", "(", ")", "*", "EgressRule", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "EgressRule", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EgressRule.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "EgressRule", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/zz_generated.deepcopy.go#L193-L200
163,597
cilium/cilium
pkg/policy/api/zz_generated.deepcopy.go
DeepCopy
func (in *EndpointSelector) DeepCopy() *EndpointSelector { if in == nil { return nil } out := new(EndpointSelector) in.DeepCopyInto(out) return out }
go
func (in *EndpointSelector) DeepCopy() *EndpointSelector { if in == nil { return nil } out := new(EndpointSelector) in.DeepCopyInto(out) return out }
[ "func", "(", "in", "*", "EndpointSelector", ")", "DeepCopy", "(", ")", "*", "EndpointSelector", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "EndpointSelector", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EndpointSelector.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "EndpointSelector", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/zz_generated.deepcopy.go#L225-L232
163,598
cilium/cilium
pkg/policy/api/zz_generated.deepcopy.go
DeepCopy
func (in EndpointSelectorSlice) DeepCopy() EndpointSelectorSlice { if in == nil { return nil } out := new(EndpointSelectorSlice) in.DeepCopyInto(out) return *out }
go
func (in EndpointSelectorSlice) DeepCopy() EndpointSelectorSlice { if in == nil { return nil } out := new(EndpointSelectorSlice) in.DeepCopyInto(out) return *out }
[ "func", "(", "in", "EndpointSelectorSlice", ")", "DeepCopy", "(", ")", "EndpointSelectorSlice", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "EndpointSelectorSlice", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "*", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EndpointSelectorSlice.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "EndpointSelectorSlice", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/zz_generated.deepcopy.go#L247-L254
163,599
cilium/cilium
pkg/policy/api/zz_generated.deepcopy.go
DeepCopy
func (in EntitySlice) DeepCopy() EntitySlice { if in == nil { return nil } out := new(EntitySlice) in.DeepCopyInto(out) return *out }
go
func (in EntitySlice) DeepCopy() EntitySlice { if in == nil { return nil } out := new(EntitySlice) in.DeepCopyInto(out) return *out }
[ "func", "(", "in", "EntitySlice", ")", "DeepCopy", "(", ")", "EntitySlice", "{", "if", "in", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "out", ":=", "new", "(", "EntitySlice", ")", "\n", "in", ".", "DeepCopyInto", "(", "out", ")", "\n", "return", "*", "out", "\n", "}" ]
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EntitySlice.
[ "DeepCopy", "is", "an", "autogenerated", "deepcopy", "function", "copying", "the", "receiver", "creating", "a", "new", "EntitySlice", "." ]
6ecfff82c2314dd9d847645361b57e2646eed64b
https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/zz_generated.deepcopy.go#L267-L274