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
|
---|---|---|---|---|---|---|---|---|---|---|---|
162,500 | cilium/cilium | pkg/clustermesh/clustermesh.go | NodeObserver | func (c *Configuration) NodeObserver() store.Observer {
if c.nodeObserver != nil {
return c.nodeObserver
}
return nodeStore.NewNodeObserver(c.NodeManager)
} | go | func (c *Configuration) NodeObserver() store.Observer {
if c.nodeObserver != nil {
return c.nodeObserver
}
return nodeStore.NewNodeObserver(c.NodeManager)
} | [
"func",
"(",
"c",
"*",
"Configuration",
")",
"NodeObserver",
"(",
")",
"store",
".",
"Observer",
"{",
"if",
"c",
".",
"nodeObserver",
"!=",
"nil",
"{",
"return",
"c",
".",
"nodeObserver",
"\n",
"}",
"\n\n",
"return",
"nodeStore",
".",
"NewNodeObserver",
"(",
"c",
".",
"NodeManager",
")",
"\n",
"}"
] | // NodeObserver returns the node store observer of the configuration | [
"NodeObserver",
"returns",
"the",
"node",
"store",
"observer",
"of",
"the",
"configuration"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/clustermesh/clustermesh.go#L61-L67 |
162,501 | cilium/cilium | pkg/clustermesh/clustermesh.go | NewClusterMesh | func NewClusterMesh(c Configuration) (*ClusterMesh, error) {
cm := &ClusterMesh{
conf: c,
clusters: map[string]*remoteCluster{},
controllers: controller.NewManager(),
globalServices: newGlobalServiceCache(),
}
w, err := createConfigDirectoryWatcher(c.ConfigDirectory, cm)
if err != nil {
return nil, fmt.Errorf("unable to create config directory watcher: %s", err)
}
cm.configWatcher = w
if err := cm.configWatcher.watch(); err != nil {
return nil, err
}
return cm, nil
} | go | func NewClusterMesh(c Configuration) (*ClusterMesh, error) {
cm := &ClusterMesh{
conf: c,
clusters: map[string]*remoteCluster{},
controllers: controller.NewManager(),
globalServices: newGlobalServiceCache(),
}
w, err := createConfigDirectoryWatcher(c.ConfigDirectory, cm)
if err != nil {
return nil, fmt.Errorf("unable to create config directory watcher: %s", err)
}
cm.configWatcher = w
if err := cm.configWatcher.watch(); err != nil {
return nil, err
}
return cm, nil
} | [
"func",
"NewClusterMesh",
"(",
"c",
"Configuration",
")",
"(",
"*",
"ClusterMesh",
",",
"error",
")",
"{",
"cm",
":=",
"&",
"ClusterMesh",
"{",
"conf",
":",
"c",
",",
"clusters",
":",
"map",
"[",
"string",
"]",
"*",
"remoteCluster",
"{",
"}",
",",
"controllers",
":",
"controller",
".",
"NewManager",
"(",
")",
",",
"globalServices",
":",
"newGlobalServiceCache",
"(",
")",
",",
"}",
"\n\n",
"w",
",",
"err",
":=",
"createConfigDirectoryWatcher",
"(",
"c",
".",
"ConfigDirectory",
",",
"cm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"cm",
".",
"configWatcher",
"=",
"w",
"\n\n",
"if",
"err",
":=",
"cm",
".",
"configWatcher",
".",
"watch",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"cm",
",",
"nil",
"\n",
"}"
] | // NewClusterMesh creates a new remote cluster cache based on the
// provided configuration | [
"NewClusterMesh",
"creates",
"a",
"new",
"remote",
"cluster",
"cache",
"based",
"on",
"the",
"provided",
"configuration"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/clustermesh/clustermesh.go#L86-L106 |
162,502 | cilium/cilium | pkg/clustermesh/clustermesh.go | Close | func (cm *ClusterMesh) Close() {
cm.mutex.Lock()
defer cm.mutex.Unlock()
if cm.configWatcher != nil {
cm.configWatcher.close()
}
for name, cluster := range cm.clusters {
cluster.onRemove()
delete(cm.clusters, name)
}
cm.controllers.RemoveAllAndWait()
} | go | func (cm *ClusterMesh) Close() {
cm.mutex.Lock()
defer cm.mutex.Unlock()
if cm.configWatcher != nil {
cm.configWatcher.close()
}
for name, cluster := range cm.clusters {
cluster.onRemove()
delete(cm.clusters, name)
}
cm.controllers.RemoveAllAndWait()
} | [
"func",
"(",
"cm",
"*",
"ClusterMesh",
")",
"Close",
"(",
")",
"{",
"cm",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"cm",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"cm",
".",
"configWatcher",
"!=",
"nil",
"{",
"cm",
".",
"configWatcher",
".",
"close",
"(",
")",
"\n",
"}",
"\n\n",
"for",
"name",
",",
"cluster",
":=",
"range",
"cm",
".",
"clusters",
"{",
"cluster",
".",
"onRemove",
"(",
")",
"\n",
"delete",
"(",
"cm",
".",
"clusters",
",",
"name",
")",
"\n",
"}",
"\n\n",
"cm",
".",
"controllers",
".",
"RemoveAllAndWait",
"(",
")",
"\n",
"}"
] | // Close stops watching for remote cluster configuration files to appear and
// will close all connections to remote clusters | [
"Close",
"stops",
"watching",
"for",
"remote",
"cluster",
"configuration",
"files",
"to",
"appear",
"and",
"will",
"close",
"all",
"connections",
"to",
"remote",
"clusters"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/clustermesh/clustermesh.go#L110-L124 |
162,503 | cilium/cilium | pkg/clustermesh/clustermesh.go | NumReadyClusters | func (cm *ClusterMesh) NumReadyClusters() int {
cm.mutex.RLock()
defer cm.mutex.RUnlock()
nready := 0
for _, cm := range cm.clusters {
if cm.isReady() {
nready++
}
}
return nready
} | go | func (cm *ClusterMesh) NumReadyClusters() int {
cm.mutex.RLock()
defer cm.mutex.RUnlock()
nready := 0
for _, cm := range cm.clusters {
if cm.isReady() {
nready++
}
}
return nready
} | [
"func",
"(",
"cm",
"*",
"ClusterMesh",
")",
"NumReadyClusters",
"(",
")",
"int",
"{",
"cm",
".",
"mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"cm",
".",
"mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"nready",
":=",
"0",
"\n",
"for",
"_",
",",
"cm",
":=",
"range",
"cm",
".",
"clusters",
"{",
"if",
"cm",
".",
"isReady",
"(",
")",
"{",
"nready",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nready",
"\n",
"}"
] | // NumReadyClusters returns the number of remote clusters to which a connection
// has been established | [
"NumReadyClusters",
"returns",
"the",
"number",
"of",
"remote",
"clusters",
"to",
"which",
"a",
"connection",
"has",
"been",
"established"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/clustermesh/clustermesh.go#L177-L189 |
162,504 | cilium/cilium | pkg/loadinfo/loadinfo.go | LogCurrentSystemLoad | func LogCurrentSystemLoad(logFunc LogFunc) {
loadInfo, err := load.Avg()
if err == nil {
logFunc("Load 1-min: %.2f 5-min: %.2f 15min: %.2f",
loadInfo.Load1, loadInfo.Load5, loadInfo.Load15)
}
memInfo, err := mem.VirtualMemory()
if err == nil && memInfo != nil {
logFunc("Memory: Total: %d Used: %d (%.2f%%) Free: %d Buffers: %d Cached: %d",
toMB(memInfo.Total), toMB(memInfo.Used), memInfo.UsedPercent, toMB(memInfo.Free), toMB(memInfo.Buffers), toMB(memInfo.Cached))
}
swapInfo, err := mem.SwapMemory()
if err == nil && swapInfo != nil {
logFunc("Swap: Total: %d Used: %d (%.2f%%) Free: %d",
toMB(swapInfo.Total), toMB(swapInfo.Used), swapInfo.UsedPercent, toMB(swapInfo.Free))
}
procs, err := process.Processes()
if err == nil {
for _, p := range procs {
cpuPercent, _ := p.CPUPercent()
if cpuPercent > cpuWatermark {
name, _ := p.Name()
status, _ := p.Status()
memPercent, _ := p.MemoryPercent()
cmdline, _ := p.Cmdline()
memExt := ""
if memInfo, err := p.MemoryInfo(); memInfo != nil && err == nil {
memExt = fmt.Sprintf("RSS: %d VMS: %d Data: %d Stack: %d Locked: %d Swap: %d",
toMB(memInfo.RSS), toMB(memInfo.VMS), toMB(memInfo.Data),
toMB(memInfo.Stack), toMB(memInfo.Locked), toMB(memInfo.Swap))
}
logFunc("NAME %s STATUS %s PID %d CPU: %.2f%% MEM: %.2f%% CMDLINE: %s MEM-EXT: %s",
name, status, p.Pid, cpuPercent, memPercent, cmdline, memExt)
}
}
}
} | go | func LogCurrentSystemLoad(logFunc LogFunc) {
loadInfo, err := load.Avg()
if err == nil {
logFunc("Load 1-min: %.2f 5-min: %.2f 15min: %.2f",
loadInfo.Load1, loadInfo.Load5, loadInfo.Load15)
}
memInfo, err := mem.VirtualMemory()
if err == nil && memInfo != nil {
logFunc("Memory: Total: %d Used: %d (%.2f%%) Free: %d Buffers: %d Cached: %d",
toMB(memInfo.Total), toMB(memInfo.Used), memInfo.UsedPercent, toMB(memInfo.Free), toMB(memInfo.Buffers), toMB(memInfo.Cached))
}
swapInfo, err := mem.SwapMemory()
if err == nil && swapInfo != nil {
logFunc("Swap: Total: %d Used: %d (%.2f%%) Free: %d",
toMB(swapInfo.Total), toMB(swapInfo.Used), swapInfo.UsedPercent, toMB(swapInfo.Free))
}
procs, err := process.Processes()
if err == nil {
for _, p := range procs {
cpuPercent, _ := p.CPUPercent()
if cpuPercent > cpuWatermark {
name, _ := p.Name()
status, _ := p.Status()
memPercent, _ := p.MemoryPercent()
cmdline, _ := p.Cmdline()
memExt := ""
if memInfo, err := p.MemoryInfo(); memInfo != nil && err == nil {
memExt = fmt.Sprintf("RSS: %d VMS: %d Data: %d Stack: %d Locked: %d Swap: %d",
toMB(memInfo.RSS), toMB(memInfo.VMS), toMB(memInfo.Data),
toMB(memInfo.Stack), toMB(memInfo.Locked), toMB(memInfo.Swap))
}
logFunc("NAME %s STATUS %s PID %d CPU: %.2f%% MEM: %.2f%% CMDLINE: %s MEM-EXT: %s",
name, status, p.Pid, cpuPercent, memPercent, cmdline, memExt)
}
}
}
} | [
"func",
"LogCurrentSystemLoad",
"(",
"logFunc",
"LogFunc",
")",
"{",
"loadInfo",
",",
"err",
":=",
"load",
".",
"Avg",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"logFunc",
"(",
"\"",
"\"",
",",
"loadInfo",
".",
"Load1",
",",
"loadInfo",
".",
"Load5",
",",
"loadInfo",
".",
"Load15",
")",
"\n",
"}",
"\n\n",
"memInfo",
",",
"err",
":=",
"mem",
".",
"VirtualMemory",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"memInfo",
"!=",
"nil",
"{",
"logFunc",
"(",
"\"",
"\"",
",",
"toMB",
"(",
"memInfo",
".",
"Total",
")",
",",
"toMB",
"(",
"memInfo",
".",
"Used",
")",
",",
"memInfo",
".",
"UsedPercent",
",",
"toMB",
"(",
"memInfo",
".",
"Free",
")",
",",
"toMB",
"(",
"memInfo",
".",
"Buffers",
")",
",",
"toMB",
"(",
"memInfo",
".",
"Cached",
")",
")",
"\n",
"}",
"\n\n",
"swapInfo",
",",
"err",
":=",
"mem",
".",
"SwapMemory",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"swapInfo",
"!=",
"nil",
"{",
"logFunc",
"(",
"\"",
"\"",
",",
"toMB",
"(",
"swapInfo",
".",
"Total",
")",
",",
"toMB",
"(",
"swapInfo",
".",
"Used",
")",
",",
"swapInfo",
".",
"UsedPercent",
",",
"toMB",
"(",
"swapInfo",
".",
"Free",
")",
")",
"\n",
"}",
"\n\n",
"procs",
",",
"err",
":=",
"process",
".",
"Processes",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"for",
"_",
",",
"p",
":=",
"range",
"procs",
"{",
"cpuPercent",
",",
"_",
":=",
"p",
".",
"CPUPercent",
"(",
")",
"\n",
"if",
"cpuPercent",
">",
"cpuWatermark",
"{",
"name",
",",
"_",
":=",
"p",
".",
"Name",
"(",
")",
"\n",
"status",
",",
"_",
":=",
"p",
".",
"Status",
"(",
")",
"\n",
"memPercent",
",",
"_",
":=",
"p",
".",
"MemoryPercent",
"(",
")",
"\n",
"cmdline",
",",
"_",
":=",
"p",
".",
"Cmdline",
"(",
")",
"\n\n",
"memExt",
":=",
"\"",
"\"",
"\n",
"if",
"memInfo",
",",
"err",
":=",
"p",
".",
"MemoryInfo",
"(",
")",
";",
"memInfo",
"!=",
"nil",
"&&",
"err",
"==",
"nil",
"{",
"memExt",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"toMB",
"(",
"memInfo",
".",
"RSS",
")",
",",
"toMB",
"(",
"memInfo",
".",
"VMS",
")",
",",
"toMB",
"(",
"memInfo",
".",
"Data",
")",
",",
"toMB",
"(",
"memInfo",
".",
"Stack",
")",
",",
"toMB",
"(",
"memInfo",
".",
"Locked",
")",
",",
"toMB",
"(",
"memInfo",
".",
"Swap",
")",
")",
"\n",
"}",
"\n\n",
"logFunc",
"(",
"\"",
"\"",
",",
"name",
",",
"status",
",",
"p",
".",
"Pid",
",",
"cpuPercent",
",",
"memPercent",
",",
"cmdline",
",",
"memExt",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // LogCurrentSystemLoad logs the current system load and lists all processes
// consuming more than cpuWatermark of the CPU | [
"LogCurrentSystemLoad",
"logs",
"the",
"current",
"system",
"load",
"and",
"lists",
"all",
"processes",
"consuming",
"more",
"than",
"cpuWatermark",
"of",
"the",
"CPU"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/loadinfo/loadinfo.go#L53-L94 |
162,505 | cilium/cilium | pkg/loadinfo/loadinfo.go | LogPeriodicSystemLoad | func LogPeriodicSystemLoad(logFunc LogFunc, interval time.Duration) CloseChan {
closeChan := make(CloseChan)
go func() {
for {
LogCurrentSystemLoad(logFunc)
select {
case <-closeChan:
return
default:
}
time.Sleep(interval)
}
}()
return closeChan
} | go | func LogPeriodicSystemLoad(logFunc LogFunc, interval time.Duration) CloseChan {
closeChan := make(CloseChan)
go func() {
for {
LogCurrentSystemLoad(logFunc)
select {
case <-closeChan:
return
default:
}
time.Sleep(interval)
}
}()
return closeChan
} | [
"func",
"LogPeriodicSystemLoad",
"(",
"logFunc",
"LogFunc",
",",
"interval",
"time",
".",
"Duration",
")",
"CloseChan",
"{",
"closeChan",
":=",
"make",
"(",
"CloseChan",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"{",
"LogCurrentSystemLoad",
"(",
"logFunc",
")",
"\n\n",
"select",
"{",
"case",
"<-",
"closeChan",
":",
"return",
"\n",
"default",
":",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"interval",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"closeChan",
"\n",
"}"
] | // LogPeriodicSystemLoad logs the system load in the interval specified until
// the channel is closed | [
"LogPeriodicSystemLoad",
"logs",
"the",
"system",
"load",
"in",
"the",
"interval",
"specified",
"until",
"the",
"channel",
"is",
"closed"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/loadinfo/loadinfo.go#L98-L115 |
162,506 | cilium/cilium | pkg/kvstore/events.go | ListAndWatch | func ListAndWatch(name, prefix string, chanSize int) *Watcher {
return Client().ListAndWatch(name, prefix, chanSize)
} | go | func ListAndWatch(name, prefix string, chanSize int) *Watcher {
return Client().ListAndWatch(name, prefix, chanSize)
} | [
"func",
"ListAndWatch",
"(",
"name",
",",
"prefix",
"string",
",",
"chanSize",
"int",
")",
"*",
"Watcher",
"{",
"return",
"Client",
"(",
")",
".",
"ListAndWatch",
"(",
"name",
",",
"prefix",
",",
"chanSize",
")",
"\n",
"}"
] | // ListAndWatch creates a new watcher which will watch the specified prefix for
// changes. Before doing this, it will list the current keys matching the
// prefix and report them as new keys. Name can be set to anything and is used
// for logging messages. The Events channel is created with the specified
// sizes. Upon every change observed, a KeyValueEvent will be sent to the
// Events channel
//
// Returns a watcher structure plus a channel that is closed when the initial
// list operation has been completed | [
"ListAndWatch",
"creates",
"a",
"new",
"watcher",
"which",
"will",
"watch",
"the",
"specified",
"prefix",
"for",
"changes",
".",
"Before",
"doing",
"this",
"it",
"will",
"list",
"the",
"current",
"keys",
"matching",
"the",
"prefix",
"and",
"report",
"them",
"as",
"new",
"keys",
".",
"Name",
"can",
"be",
"set",
"to",
"anything",
"and",
"is",
"used",
"for",
"logging",
"messages",
".",
"The",
"Events",
"channel",
"is",
"created",
"with",
"the",
"specified",
"sizes",
".",
"Upon",
"every",
"change",
"observed",
"a",
"KeyValueEvent",
"will",
"be",
"sent",
"to",
"the",
"Events",
"channel",
"Returns",
"a",
"watcher",
"structure",
"plus",
"a",
"channel",
"that",
"is",
"closed",
"when",
"the",
"initial",
"list",
"operation",
"has",
"been",
"completed"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/events.go#L112-L114 |
162,507 | cilium/cilium | pkg/policy/repository.go | NewPolicyRepository | func NewPolicyRepository() *Repository {
repoChangeQueue := eventqueue.NewEventQueueBuffered("repository-change-queue", option.Config.PolicyQueueSize)
ruleReactionQueue := eventqueue.NewEventQueueBuffered("repository-reaction-queue", option.Config.PolicyQueueSize)
repoChangeQueue.Run()
ruleReactionQueue.Run()
return &Repository{
revision: 1,
RepositoryChangeQueue: repoChangeQueue,
RuleReactionQueue: ruleReactionQueue,
}
} | go | func NewPolicyRepository() *Repository {
repoChangeQueue := eventqueue.NewEventQueueBuffered("repository-change-queue", option.Config.PolicyQueueSize)
ruleReactionQueue := eventqueue.NewEventQueueBuffered("repository-reaction-queue", option.Config.PolicyQueueSize)
repoChangeQueue.Run()
ruleReactionQueue.Run()
return &Repository{
revision: 1,
RepositoryChangeQueue: repoChangeQueue,
RuleReactionQueue: ruleReactionQueue,
}
} | [
"func",
"NewPolicyRepository",
"(",
")",
"*",
"Repository",
"{",
"repoChangeQueue",
":=",
"eventqueue",
".",
"NewEventQueueBuffered",
"(",
"\"",
"\"",
",",
"option",
".",
"Config",
".",
"PolicyQueueSize",
")",
"\n",
"ruleReactionQueue",
":=",
"eventqueue",
".",
"NewEventQueueBuffered",
"(",
"\"",
"\"",
",",
"option",
".",
"Config",
".",
"PolicyQueueSize",
")",
"\n",
"repoChangeQueue",
".",
"Run",
"(",
")",
"\n",
"ruleReactionQueue",
".",
"Run",
"(",
")",
"\n",
"return",
"&",
"Repository",
"{",
"revision",
":",
"1",
",",
"RepositoryChangeQueue",
":",
"repoChangeQueue",
",",
"RuleReactionQueue",
":",
"ruleReactionQueue",
",",
"}",
"\n",
"}"
] | // NewPolicyRepository allocates a new policy repository | [
"NewPolicyRepository",
"allocates",
"a",
"new",
"policy",
"repository"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L57-L67 |
162,508 | cilium/cilium | pkg/policy/repository.go | ResolveL4EgressPolicy | func (p *Repository) ResolveL4EgressPolicy(ctx *SearchContext) (*L4PolicyMap, error) {
result, err := p.rules.resolveL4EgressPolicy(ctx, p.GetRevision())
if err != nil {
return nil, err
}
return &result.Egress, nil
} | go | func (p *Repository) ResolveL4EgressPolicy(ctx *SearchContext) (*L4PolicyMap, error) {
result, err := p.rules.resolveL4EgressPolicy(ctx, p.GetRevision())
if err != nil {
return nil, err
}
return &result.Egress, nil
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"ResolveL4EgressPolicy",
"(",
"ctx",
"*",
"SearchContext",
")",
"(",
"*",
"L4PolicyMap",
",",
"error",
")",
"{",
"result",
",",
"err",
":=",
"p",
".",
"rules",
".",
"resolveL4EgressPolicy",
"(",
"ctx",
",",
"p",
".",
"GetRevision",
"(",
")",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"result",
".",
"Egress",
",",
"nil",
"\n",
"}"
] | // ResolveL4EgressPolicy resolves the L4 egress policy for a set of endpoints
// by searching the policy repository for `PortRule` rules that are attached to
// a `Rule` where the EndpointSelector matches `ctx.From`. `ctx.To` takes no effect and
// is ignored in the search. If multiple `PortRule` rules are found, all rules
// are merged together. If rules contains overlapping port definitions, the first
// rule found in the repository takes precedence. | [
"ResolveL4EgressPolicy",
"resolves",
"the",
"L4",
"egress",
"policy",
"for",
"a",
"set",
"of",
"endpoints",
"by",
"searching",
"the",
"policy",
"repository",
"for",
"PortRule",
"rules",
"that",
"are",
"attached",
"to",
"a",
"Rule",
"where",
"the",
"EndpointSelector",
"matches",
"ctx",
".",
"From",
".",
"ctx",
".",
"To",
"takes",
"no",
"effect",
"and",
"is",
"ignored",
"in",
"the",
"search",
".",
"If",
"multiple",
"PortRule",
"rules",
"are",
"found",
"all",
"rules",
"are",
"merged",
"together",
".",
"If",
"rules",
"contains",
"overlapping",
"port",
"definitions",
"the",
"first",
"rule",
"found",
"in",
"the",
"repository",
"takes",
"precedence",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L176-L184 |
162,509 | cilium/cilium | pkg/policy/repository.go | ResolveCIDRPolicy | func (p *Repository) ResolveCIDRPolicy(ctx *SearchContext) *CIDRPolicy {
return p.rules.resolveCIDRPolicy(ctx)
} | go | func (p *Repository) ResolveCIDRPolicy(ctx *SearchContext) *CIDRPolicy {
return p.rules.resolveCIDRPolicy(ctx)
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"ResolveCIDRPolicy",
"(",
"ctx",
"*",
"SearchContext",
")",
"*",
"CIDRPolicy",
"{",
"return",
"p",
".",
"rules",
".",
"resolveCIDRPolicy",
"(",
"ctx",
")",
"\n",
"}"
] | // ResolveCIDRPolicy resolves the L3 policy for a set of endpoints by searching
// the policy repository for `CIDR` rules that are attached to a `Rule`
// where the EndpointSelector matches `ctx.To`. `ctx.From` takes no effect and
// is ignored in the search. | [
"ResolveCIDRPolicy",
"resolves",
"the",
"L3",
"policy",
"for",
"a",
"set",
"of",
"endpoints",
"by",
"searching",
"the",
"policy",
"repository",
"for",
"CIDR",
"rules",
"that",
"are",
"attached",
"to",
"a",
"Rule",
"where",
"the",
"EndpointSelector",
"matches",
"ctx",
".",
"To",
".",
"ctx",
".",
"From",
"takes",
"no",
"effect",
"and",
"is",
"ignored",
"in",
"the",
"search",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L190-L192 |
162,510 | cilium/cilium | pkg/policy/repository.go | AllowsIngressRLocked | func (p *Repository) AllowsIngressRLocked(ctx *SearchContext) api.Decision {
// Lack of DPorts in the SearchContext means L3-only search
if len(ctx.DPorts) == 0 {
newCtx := *ctx
newCtx.DPorts = []*models.Port{{
Port: 0,
Protocol: models.PortProtocolANY,
}}
ctx = &newCtx
}
ctx.PolicyTrace("Tracing %s", ctx.String())
ingressPolicy, err := p.ResolveL4IngressPolicy(ctx)
if err != nil {
log.WithError(err).Warn("Evaluation error while resolving L4 ingress policy")
}
verdict := api.Denied
if err == nil && len(*ingressPolicy) > 0 {
verdict = ingressPolicy.IngressCoversContext(ctx)
}
ctx.PolicyTrace("Ingress verdict: %s", verdict.String())
return verdict
} | go | func (p *Repository) AllowsIngressRLocked(ctx *SearchContext) api.Decision {
// Lack of DPorts in the SearchContext means L3-only search
if len(ctx.DPorts) == 0 {
newCtx := *ctx
newCtx.DPorts = []*models.Port{{
Port: 0,
Protocol: models.PortProtocolANY,
}}
ctx = &newCtx
}
ctx.PolicyTrace("Tracing %s", ctx.String())
ingressPolicy, err := p.ResolveL4IngressPolicy(ctx)
if err != nil {
log.WithError(err).Warn("Evaluation error while resolving L4 ingress policy")
}
verdict := api.Denied
if err == nil && len(*ingressPolicy) > 0 {
verdict = ingressPolicy.IngressCoversContext(ctx)
}
ctx.PolicyTrace("Ingress verdict: %s", verdict.String())
return verdict
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"AllowsIngressRLocked",
"(",
"ctx",
"*",
"SearchContext",
")",
"api",
".",
"Decision",
"{",
"// Lack of DPorts in the SearchContext means L3-only search",
"if",
"len",
"(",
"ctx",
".",
"DPorts",
")",
"==",
"0",
"{",
"newCtx",
":=",
"*",
"ctx",
"\n",
"newCtx",
".",
"DPorts",
"=",
"[",
"]",
"*",
"models",
".",
"Port",
"{",
"{",
"Port",
":",
"0",
",",
"Protocol",
":",
"models",
".",
"PortProtocolANY",
",",
"}",
"}",
"\n",
"ctx",
"=",
"&",
"newCtx",
"\n",
"}",
"\n\n",
"ctx",
".",
"PolicyTrace",
"(",
"\"",
"\"",
",",
"ctx",
".",
"String",
"(",
")",
")",
"\n",
"ingressPolicy",
",",
"err",
":=",
"p",
".",
"ResolveL4IngressPolicy",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithError",
"(",
"err",
")",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"verdict",
":=",
"api",
".",
"Denied",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"len",
"(",
"*",
"ingressPolicy",
")",
">",
"0",
"{",
"verdict",
"=",
"ingressPolicy",
".",
"IngressCoversContext",
"(",
"ctx",
")",
"\n",
"}",
"\n\n",
"ctx",
".",
"PolicyTrace",
"(",
"\"",
"\"",
",",
"verdict",
".",
"String",
"(",
")",
")",
"\n",
"return",
"verdict",
"\n",
"}"
] | // AllowsIngressRLocked evaluates the policy repository for the provided search
// context and returns the verdict for ingress. If no matching policy allows for
// the connection, the request will be denied. The policy repository mutex must
// be held. | [
"AllowsIngressRLocked",
"evaluates",
"the",
"policy",
"repository",
"for",
"the",
"provided",
"search",
"context",
"and",
"returns",
"the",
"verdict",
"for",
"ingress",
".",
"If",
"no",
"matching",
"policy",
"allows",
"for",
"the",
"connection",
"the",
"request",
"will",
"be",
"denied",
".",
"The",
"policy",
"repository",
"mutex",
"must",
"be",
"held",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L198-L222 |
162,511 | cilium/cilium | pkg/policy/repository.go | AllowsEgressRLocked | func (p *Repository) AllowsEgressRLocked(ctx *SearchContext) api.Decision {
// Lack of DPorts in the SearchContext means L3-only search
if len(ctx.DPorts) == 0 {
newCtx := *ctx
newCtx.DPorts = []*models.Port{{
Port: 0,
Protocol: models.PortProtocolANY,
}}
ctx = &newCtx
}
ctx.PolicyTrace("Tracing %s\n", ctx.String())
egressPolicy, err := p.ResolveL4EgressPolicy(ctx)
if err != nil {
log.WithError(err).Warn("Evaluation error while resolving L4 egress policy")
}
verdict := api.Denied
if err == nil && len(*egressPolicy) > 0 {
verdict = egressPolicy.EgressCoversContext(ctx)
}
ctx.PolicyTrace("Egress verdict: %s", verdict.String())
return verdict
} | go | func (p *Repository) AllowsEgressRLocked(ctx *SearchContext) api.Decision {
// Lack of DPorts in the SearchContext means L3-only search
if len(ctx.DPorts) == 0 {
newCtx := *ctx
newCtx.DPorts = []*models.Port{{
Port: 0,
Protocol: models.PortProtocolANY,
}}
ctx = &newCtx
}
ctx.PolicyTrace("Tracing %s\n", ctx.String())
egressPolicy, err := p.ResolveL4EgressPolicy(ctx)
if err != nil {
log.WithError(err).Warn("Evaluation error while resolving L4 egress policy")
}
verdict := api.Denied
if err == nil && len(*egressPolicy) > 0 {
verdict = egressPolicy.EgressCoversContext(ctx)
}
ctx.PolicyTrace("Egress verdict: %s", verdict.String())
return verdict
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"AllowsEgressRLocked",
"(",
"ctx",
"*",
"SearchContext",
")",
"api",
".",
"Decision",
"{",
"// Lack of DPorts in the SearchContext means L3-only search",
"if",
"len",
"(",
"ctx",
".",
"DPorts",
")",
"==",
"0",
"{",
"newCtx",
":=",
"*",
"ctx",
"\n",
"newCtx",
".",
"DPorts",
"=",
"[",
"]",
"*",
"models",
".",
"Port",
"{",
"{",
"Port",
":",
"0",
",",
"Protocol",
":",
"models",
".",
"PortProtocolANY",
",",
"}",
"}",
"\n",
"ctx",
"=",
"&",
"newCtx",
"\n",
"}",
"\n\n",
"ctx",
".",
"PolicyTrace",
"(",
"\"",
"\\n",
"\"",
",",
"ctx",
".",
"String",
"(",
")",
")",
"\n",
"egressPolicy",
",",
"err",
":=",
"p",
".",
"ResolveL4EgressPolicy",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithError",
"(",
"err",
")",
".",
"Warn",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"verdict",
":=",
"api",
".",
"Denied",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"len",
"(",
"*",
"egressPolicy",
")",
">",
"0",
"{",
"verdict",
"=",
"egressPolicy",
".",
"EgressCoversContext",
"(",
"ctx",
")",
"\n",
"}",
"\n\n",
"ctx",
".",
"PolicyTrace",
"(",
"\"",
"\"",
",",
"verdict",
".",
"String",
"(",
")",
")",
"\n",
"return",
"verdict",
"\n",
"}"
] | // AllowsEgressRLocked evaluates the policy repository for the provided search
// context and returns the verdict. If no matching policy allows for the
// connection, the request will be denied. The policy repository mutex must be
// held. | [
"AllowsEgressRLocked",
"evaluates",
"the",
"policy",
"repository",
"for",
"the",
"provided",
"search",
"context",
"and",
"returns",
"the",
"verdict",
".",
"If",
"no",
"matching",
"policy",
"allows",
"for",
"the",
"connection",
"the",
"request",
"will",
"be",
"denied",
".",
"The",
"policy",
"repository",
"mutex",
"must",
"be",
"held",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L228-L251 |
162,512 | cilium/cilium | pkg/policy/repository.go | SearchRLocked | func (p *Repository) SearchRLocked(labels labels.LabelArray) api.Rules {
result := api.Rules{}
for _, r := range p.rules {
if r.Labels.Contains(labels) {
result = append(result, &r.Rule)
}
}
return result
} | go | func (p *Repository) SearchRLocked(labels labels.LabelArray) api.Rules {
result := api.Rules{}
for _, r := range p.rules {
if r.Labels.Contains(labels) {
result = append(result, &r.Rule)
}
}
return result
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"SearchRLocked",
"(",
"labels",
"labels",
".",
"LabelArray",
")",
"api",
".",
"Rules",
"{",
"result",
":=",
"api",
".",
"Rules",
"{",
"}",
"\n\n",
"for",
"_",
",",
"r",
":=",
"range",
"p",
".",
"rules",
"{",
"if",
"r",
".",
"Labels",
".",
"Contains",
"(",
"labels",
")",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"&",
"r",
".",
"Rule",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"result",
"\n",
"}"
] | // SearchRLocked searches the policy repository for rules which match the
// specified labels and will return an array of all rules which matched. | [
"SearchRLocked",
"searches",
"the",
"policy",
"repository",
"for",
"rules",
"which",
"match",
"the",
"specified",
"labels",
"and",
"will",
"return",
"an",
"array",
"of",
"all",
"rules",
"which",
"matched",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L255-L265 |
162,513 | cilium/cilium | pkg/policy/repository.go | AddListLocked | func (p *Repository) AddListLocked(rules api.Rules) (ruleSlice, uint64) {
newList := make(ruleSlice, len(rules))
for i := range rules {
newRule := &rule{
Rule: *rules[i],
metadata: newRuleMetadata(),
}
newList[i] = newRule
}
p.rules = append(p.rules, newList...)
p.BumpRevision()
metrics.PolicyCount.Add(float64(len(newList)))
return newList, p.GetRevision()
} | go | func (p *Repository) AddListLocked(rules api.Rules) (ruleSlice, uint64) {
newList := make(ruleSlice, len(rules))
for i := range rules {
newRule := &rule{
Rule: *rules[i],
metadata: newRuleMetadata(),
}
newList[i] = newRule
}
p.rules = append(p.rules, newList...)
p.BumpRevision()
metrics.PolicyCount.Add(float64(len(newList)))
return newList, p.GetRevision()
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"AddListLocked",
"(",
"rules",
"api",
".",
"Rules",
")",
"(",
"ruleSlice",
",",
"uint64",
")",
"{",
"newList",
":=",
"make",
"(",
"ruleSlice",
",",
"len",
"(",
"rules",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"rules",
"{",
"newRule",
":=",
"&",
"rule",
"{",
"Rule",
":",
"*",
"rules",
"[",
"i",
"]",
",",
"metadata",
":",
"newRuleMetadata",
"(",
")",
",",
"}",
"\n",
"newList",
"[",
"i",
"]",
"=",
"newRule",
"\n",
"}",
"\n\n",
"p",
".",
"rules",
"=",
"append",
"(",
"p",
".",
"rules",
",",
"newList",
"...",
")",
"\n",
"p",
".",
"BumpRevision",
"(",
")",
"\n",
"metrics",
".",
"PolicyCount",
".",
"Add",
"(",
"float64",
"(",
"len",
"(",
"newList",
")",
")",
")",
"\n\n",
"return",
"newList",
",",
"p",
".",
"GetRevision",
"(",
")",
"\n",
"}"
] | // AddListLocked inserts a rule into the policy repository with the repository already locked
// Expects that the entire rule list has already been sanitized. | [
"AddListLocked",
"inserts",
"a",
"rule",
"into",
"the",
"policy",
"repository",
"with",
"the",
"repository",
"already",
"locked",
"Expects",
"that",
"the",
"entire",
"rule",
"list",
"has",
"already",
"been",
"sanitized",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L305-L321 |
162,514 | cilium/cilium | pkg/policy/repository.go | removeIdentityFromRuleCaches | func (p *Repository) removeIdentityFromRuleCaches(identity *identity.Identity) *sync.WaitGroup {
var wg sync.WaitGroup
wg.Add(len(p.rules))
for _, r := range p.rules {
go func(rr *rule, wgg *sync.WaitGroup) {
rr.metadata.delete(identity)
wgg.Done()
}(r, &wg)
}
return &wg
} | go | func (p *Repository) removeIdentityFromRuleCaches(identity *identity.Identity) *sync.WaitGroup {
var wg sync.WaitGroup
wg.Add(len(p.rules))
for _, r := range p.rules {
go func(rr *rule, wgg *sync.WaitGroup) {
rr.metadata.delete(identity)
wgg.Done()
}(r, &wg)
}
return &wg
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"removeIdentityFromRuleCaches",
"(",
"identity",
"*",
"identity",
".",
"Identity",
")",
"*",
"sync",
".",
"WaitGroup",
"{",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"wg",
".",
"Add",
"(",
"len",
"(",
"p",
".",
"rules",
")",
")",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"p",
".",
"rules",
"{",
"go",
"func",
"(",
"rr",
"*",
"rule",
",",
"wgg",
"*",
"sync",
".",
"WaitGroup",
")",
"{",
"rr",
".",
"metadata",
".",
"delete",
"(",
"identity",
")",
"\n",
"wgg",
".",
"Done",
"(",
")",
"\n",
"}",
"(",
"r",
",",
"&",
"wg",
")",
"\n",
"}",
"\n",
"return",
"&",
"wg",
"\n",
"}"
] | // removeIdentityFromRuleCaches removes the identity from the selector cache
// in each rule in the repository.
//
// Returns a sync.WaitGroup that blocks until the policy operation is complete.
// The repository read lock must be held until the waitgroup is complete. | [
"removeIdentityFromRuleCaches",
"removes",
"the",
"identity",
"from",
"the",
"selector",
"cache",
"in",
"each",
"rule",
"in",
"the",
"repository",
".",
"Returns",
"a",
"sync",
".",
"WaitGroup",
"that",
"blocks",
"until",
"the",
"policy",
"operation",
"is",
"complete",
".",
"The",
"repository",
"read",
"lock",
"must",
"be",
"held",
"until",
"the",
"waitgroup",
"is",
"complete",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L328-L338 |
162,515 | cilium/cilium | pkg/policy/repository.go | LocalEndpointIdentityRemoved | func (p *Repository) LocalEndpointIdentityRemoved(identity *identity.Identity) {
go func() {
scopedLog := log.WithField(logfields.Identity, identity)
scopedLog.Debug("Removing identity references from policy cache")
p.Mutex.RLock()
wg := p.removeIdentityFromRuleCaches(identity)
wg.Wait()
p.Mutex.RUnlock()
scopedLog.Debug("Finished cleaning policy cache")
}()
} | go | func (p *Repository) LocalEndpointIdentityRemoved(identity *identity.Identity) {
go func() {
scopedLog := log.WithField(logfields.Identity, identity)
scopedLog.Debug("Removing identity references from policy cache")
p.Mutex.RLock()
wg := p.removeIdentityFromRuleCaches(identity)
wg.Wait()
p.Mutex.RUnlock()
scopedLog.Debug("Finished cleaning policy cache")
}()
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"LocalEndpointIdentityRemoved",
"(",
"identity",
"*",
"identity",
".",
"Identity",
")",
"{",
"go",
"func",
"(",
")",
"{",
"scopedLog",
":=",
"log",
".",
"WithField",
"(",
"logfields",
".",
"Identity",
",",
"identity",
")",
"\n",
"scopedLog",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"p",
".",
"Mutex",
".",
"RLock",
"(",
")",
"\n",
"wg",
":=",
"p",
".",
"removeIdentityFromRuleCaches",
"(",
"identity",
")",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"p",
".",
"Mutex",
".",
"RUnlock",
"(",
")",
"\n",
"scopedLog",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"}",
"(",
")",
"\n",
"}"
] | // LocalEndpointIdentityRemoved handles local identity removal events to
// remove references from rules in the repository to the specified identity. | [
"LocalEndpointIdentityRemoved",
"handles",
"local",
"identity",
"removal",
"events",
"to",
"remove",
"references",
"from",
"rules",
"in",
"the",
"repository",
"to",
"the",
"specified",
"identity",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L347-L357 |
162,516 | cilium/cilium | pkg/policy/repository.go | AddList | func (p *Repository) AddList(rules api.Rules) (ruleSlice, uint64) {
p.Mutex.Lock()
defer p.Mutex.Unlock()
return p.AddListLocked(rules)
} | go | func (p *Repository) AddList(rules api.Rules) (ruleSlice, uint64) {
p.Mutex.Lock()
defer p.Mutex.Unlock()
return p.AddListLocked(rules)
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"AddList",
"(",
"rules",
"api",
".",
"Rules",
")",
"(",
"ruleSlice",
",",
"uint64",
")",
"{",
"p",
".",
"Mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"p",
".",
"AddListLocked",
"(",
"rules",
")",
"\n",
"}"
] | // AddList inserts a rule into the policy repository. It is used for
// unit-testing purposes only. | [
"AddList",
"inserts",
"a",
"rule",
"into",
"the",
"policy",
"repository",
".",
"It",
"is",
"used",
"for",
"unit",
"-",
"testing",
"purposes",
"only",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L361-L365 |
162,517 | cilium/cilium | pkg/policy/repository.go | UpdateRulesEndpointsCaches | func (r ruleSlice) UpdateRulesEndpointsCaches(endpointsToBumpRevision *EndpointSet, endpointsToRegenerate *IDSet, policySelectionWG *sync.WaitGroup) {
// No need to check whether endpoints need to be regenerated here since we
// will unconditionally regenerate all endpoints later.
if !option.Config.SelectiveRegeneration {
return
}
endpointsToBumpRevision.ForEach(policySelectionWG, func(epp Endpoint) {
endpointSelected, err := r.updateEndpointsCaches(epp, endpointsToRegenerate)
// If we could not evaluate the rules against the current endpoint, or
// the endpoint is not selected by the rules, remove it from the set
// of endpoints to bump the revision. If the error is non-nil, the
// endpoint is no longer in either set (endpointsToBumpRevision or
// endpointsToRegenerate, as we could not determine what to do for the
// endpoint). This is usually the case when the endpoint is no longer
// alive (i.e., it has been marked to be deleted).
if endpointSelected || err != nil {
if err != nil {
log.WithError(err).Debug("could not determine whether endpoint was selected by rule")
}
endpointsToBumpRevision.Delete(epp)
}
})
} | go | func (r ruleSlice) UpdateRulesEndpointsCaches(endpointsToBumpRevision *EndpointSet, endpointsToRegenerate *IDSet, policySelectionWG *sync.WaitGroup) {
// No need to check whether endpoints need to be regenerated here since we
// will unconditionally regenerate all endpoints later.
if !option.Config.SelectiveRegeneration {
return
}
endpointsToBumpRevision.ForEach(policySelectionWG, func(epp Endpoint) {
endpointSelected, err := r.updateEndpointsCaches(epp, endpointsToRegenerate)
// If we could not evaluate the rules against the current endpoint, or
// the endpoint is not selected by the rules, remove it from the set
// of endpoints to bump the revision. If the error is non-nil, the
// endpoint is no longer in either set (endpointsToBumpRevision or
// endpointsToRegenerate, as we could not determine what to do for the
// endpoint). This is usually the case when the endpoint is no longer
// alive (i.e., it has been marked to be deleted).
if endpointSelected || err != nil {
if err != nil {
log.WithError(err).Debug("could not determine whether endpoint was selected by rule")
}
endpointsToBumpRevision.Delete(epp)
}
})
} | [
"func",
"(",
"r",
"ruleSlice",
")",
"UpdateRulesEndpointsCaches",
"(",
"endpointsToBumpRevision",
"*",
"EndpointSet",
",",
"endpointsToRegenerate",
"*",
"IDSet",
",",
"policySelectionWG",
"*",
"sync",
".",
"WaitGroup",
")",
"{",
"// No need to check whether endpoints need to be regenerated here since we",
"// will unconditionally regenerate all endpoints later.",
"if",
"!",
"option",
".",
"Config",
".",
"SelectiveRegeneration",
"{",
"return",
"\n",
"}",
"\n\n",
"endpointsToBumpRevision",
".",
"ForEach",
"(",
"policySelectionWG",
",",
"func",
"(",
"epp",
"Endpoint",
")",
"{",
"endpointSelected",
",",
"err",
":=",
"r",
".",
"updateEndpointsCaches",
"(",
"epp",
",",
"endpointsToRegenerate",
")",
"\n\n",
"// If we could not evaluate the rules against the current endpoint, or",
"// the endpoint is not selected by the rules, remove it from the set",
"// of endpoints to bump the revision. If the error is non-nil, the",
"// endpoint is no longer in either set (endpointsToBumpRevision or",
"// endpointsToRegenerate, as we could not determine what to do for the",
"// endpoint). This is usually the case when the endpoint is no longer",
"// alive (i.e., it has been marked to be deleted).",
"if",
"endpointSelected",
"||",
"err",
"!=",
"nil",
"{",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"WithError",
"(",
"err",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"endpointsToBumpRevision",
".",
"Delete",
"(",
"epp",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] | // UpdateRulesEndpointsCaches updates the caches within each rule in r that
// specify whether the rule selects the endpoints in eps. If any rule matches
// the endpoints, it is added to the provided IDSet, and removed from the
// provided EndpointSet. The provided WaitGroup is signaled for a given endpoint
// when it is finished being processed. | [
"UpdateRulesEndpointsCaches",
"updates",
"the",
"caches",
"within",
"each",
"rule",
"in",
"r",
"that",
"specify",
"whether",
"the",
"rule",
"selects",
"the",
"endpoints",
"in",
"eps",
".",
"If",
"any",
"rule",
"matches",
"the",
"endpoints",
"it",
"is",
"added",
"to",
"the",
"provided",
"IDSet",
"and",
"removed",
"from",
"the",
"provided",
"EndpointSet",
".",
"The",
"provided",
"WaitGroup",
"is",
"signaled",
"for",
"a",
"given",
"endpoint",
"when",
"it",
"is",
"finished",
"being",
"processed",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L372-L396 |
162,518 | cilium/cilium | pkg/policy/repository.go | DeleteByLabelsLocked | func (p *Repository) DeleteByLabelsLocked(labels labels.LabelArray) (ruleSlice, uint64, int) {
deleted := 0
new := p.rules[:0]
deletedRules := ruleSlice{}
for _, r := range p.rules {
if !r.Labels.Contains(labels) {
new = append(new, r)
} else {
deletedRules = append(deletedRules, r)
deleted++
}
}
if deleted > 0 {
p.BumpRevision()
p.rules = new
metrics.PolicyCount.Sub(float64(deleted))
}
return deletedRules, p.GetRevision(), deleted
} | go | func (p *Repository) DeleteByLabelsLocked(labels labels.LabelArray) (ruleSlice, uint64, int) {
deleted := 0
new := p.rules[:0]
deletedRules := ruleSlice{}
for _, r := range p.rules {
if !r.Labels.Contains(labels) {
new = append(new, r)
} else {
deletedRules = append(deletedRules, r)
deleted++
}
}
if deleted > 0 {
p.BumpRevision()
p.rules = new
metrics.PolicyCount.Sub(float64(deleted))
}
return deletedRules, p.GetRevision(), deleted
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"DeleteByLabelsLocked",
"(",
"labels",
"labels",
".",
"LabelArray",
")",
"(",
"ruleSlice",
",",
"uint64",
",",
"int",
")",
"{",
"deleted",
":=",
"0",
"\n",
"new",
":=",
"p",
".",
"rules",
"[",
":",
"0",
"]",
"\n",
"deletedRules",
":=",
"ruleSlice",
"{",
"}",
"\n\n",
"for",
"_",
",",
"r",
":=",
"range",
"p",
".",
"rules",
"{",
"if",
"!",
"r",
".",
"Labels",
".",
"Contains",
"(",
"labels",
")",
"{",
"new",
"=",
"append",
"(",
"new",
",",
"r",
")",
"\n",
"}",
"else",
"{",
"deletedRules",
"=",
"append",
"(",
"deletedRules",
",",
"r",
")",
"\n",
"deleted",
"++",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"deleted",
">",
"0",
"{",
"p",
".",
"BumpRevision",
"(",
")",
"\n",
"p",
".",
"rules",
"=",
"new",
"\n",
"metrics",
".",
"PolicyCount",
".",
"Sub",
"(",
"float64",
"(",
"deleted",
")",
")",
"\n",
"}",
"\n\n",
"return",
"deletedRules",
",",
"p",
".",
"GetRevision",
"(",
")",
",",
"deleted",
"\n",
"}"
] | // DeleteByLabelsLocked deletes all rules in the policy repository which
// contain the specified labels. Returns the revision of the policy repository
// after deleting the rules, as well as now many rules were deleted. | [
"DeleteByLabelsLocked",
"deletes",
"all",
"rules",
"in",
"the",
"policy",
"repository",
"which",
"contain",
"the",
"specified",
"labels",
".",
"Returns",
"the",
"revision",
"of",
"the",
"policy",
"repository",
"after",
"deleting",
"the",
"rules",
"as",
"well",
"as",
"now",
"many",
"rules",
"were",
"deleted",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L401-L423 |
162,519 | cilium/cilium | pkg/policy/repository.go | DeleteByLabels | func (p *Repository) DeleteByLabels(labels labels.LabelArray) (uint64, int) {
p.Mutex.Lock()
defer p.Mutex.Unlock()
_, rev, numDeleted := p.DeleteByLabelsLocked(labels)
return rev, numDeleted
} | go | func (p *Repository) DeleteByLabels(labels labels.LabelArray) (uint64, int) {
p.Mutex.Lock()
defer p.Mutex.Unlock()
_, rev, numDeleted := p.DeleteByLabelsLocked(labels)
return rev, numDeleted
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"DeleteByLabels",
"(",
"labels",
"labels",
".",
"LabelArray",
")",
"(",
"uint64",
",",
"int",
")",
"{",
"p",
".",
"Mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Mutex",
".",
"Unlock",
"(",
")",
"\n",
"_",
",",
"rev",
",",
"numDeleted",
":=",
"p",
".",
"DeleteByLabelsLocked",
"(",
"labels",
")",
"\n",
"return",
"rev",
",",
"numDeleted",
"\n",
"}"
] | // DeleteByLabels deletes all rules in the policy repository which contain the
// specified labels | [
"DeleteByLabels",
"deletes",
"all",
"rules",
"in",
"the",
"policy",
"repository",
"which",
"contain",
"the",
"specified",
"labels"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L427-L432 |
162,520 | cilium/cilium | pkg/policy/repository.go | JSONMarshalRules | func JSONMarshalRules(rules api.Rules) string {
b, err := json.MarshalIndent(rules, "", " ")
if err != nil {
return err.Error()
}
return string(b)
} | go | func JSONMarshalRules(rules api.Rules) string {
b, err := json.MarshalIndent(rules, "", " ")
if err != nil {
return err.Error()
}
return string(b)
} | [
"func",
"JSONMarshalRules",
"(",
"rules",
"api",
".",
"Rules",
")",
"string",
"{",
"b",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"rules",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
".",
"Error",
"(",
")",
"\n",
"}",
"\n",
"return",
"string",
"(",
"b",
")",
"\n",
"}"
] | // JSONMarshalRules returns a slice of policy rules as string in JSON
// representation | [
"JSONMarshalRules",
"returns",
"a",
"slice",
"of",
"policy",
"rules",
"as",
"string",
"in",
"JSON",
"representation"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L436-L442 |
162,521 | cilium/cilium | pkg/policy/repository.go | GetJSON | func (p *Repository) GetJSON() string {
p.Mutex.RLock()
defer p.Mutex.RUnlock()
result := api.Rules{}
for _, r := range p.rules {
result = append(result, &r.Rule)
}
return JSONMarshalRules(result)
} | go | func (p *Repository) GetJSON() string {
p.Mutex.RLock()
defer p.Mutex.RUnlock()
result := api.Rules{}
for _, r := range p.rules {
result = append(result, &r.Rule)
}
return JSONMarshalRules(result)
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"GetJSON",
"(",
")",
"string",
"{",
"p",
".",
"Mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"p",
".",
"Mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"result",
":=",
"api",
".",
"Rules",
"{",
"}",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"p",
".",
"rules",
"{",
"result",
"=",
"append",
"(",
"result",
",",
"&",
"r",
".",
"Rule",
")",
"\n",
"}",
"\n\n",
"return",
"JSONMarshalRules",
"(",
"result",
")",
"\n",
"}"
] | // GetJSON returns all rules of the policy repository as string in JSON
// representation | [
"GetJSON",
"returns",
"all",
"rules",
"of",
"the",
"policy",
"repository",
"as",
"string",
"in",
"JSON",
"representation"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L446-L456 |
162,522 | cilium/cilium | pkg/policy/repository.go | GetRulesMatching | func (p *Repository) GetRulesMatching(labels labels.LabelArray) (ingressMatch bool, egressMatch bool) {
ingressMatch = false
egressMatch = false
for _, r := range p.rules {
rulesMatch := r.EndpointSelector.Matches(labels)
if rulesMatch {
if len(r.Ingress) > 0 {
ingressMatch = true
}
if len(r.Egress) > 0 {
egressMatch = true
}
}
if ingressMatch && egressMatch {
return
}
}
return
} | go | func (p *Repository) GetRulesMatching(labels labels.LabelArray) (ingressMatch bool, egressMatch bool) {
ingressMatch = false
egressMatch = false
for _, r := range p.rules {
rulesMatch := r.EndpointSelector.Matches(labels)
if rulesMatch {
if len(r.Ingress) > 0 {
ingressMatch = true
}
if len(r.Egress) > 0 {
egressMatch = true
}
}
if ingressMatch && egressMatch {
return
}
}
return
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"GetRulesMatching",
"(",
"labels",
"labels",
".",
"LabelArray",
")",
"(",
"ingressMatch",
"bool",
",",
"egressMatch",
"bool",
")",
"{",
"ingressMatch",
"=",
"false",
"\n",
"egressMatch",
"=",
"false",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"p",
".",
"rules",
"{",
"rulesMatch",
":=",
"r",
".",
"EndpointSelector",
".",
"Matches",
"(",
"labels",
")",
"\n",
"if",
"rulesMatch",
"{",
"if",
"len",
"(",
"r",
".",
"Ingress",
")",
">",
"0",
"{",
"ingressMatch",
"=",
"true",
"\n",
"}",
"\n",
"if",
"len",
"(",
"r",
".",
"Egress",
")",
">",
"0",
"{",
"egressMatch",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"ingressMatch",
"&&",
"egressMatch",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // GetRulesMatching returns whether any of the rules in a repository contain a
// rule with labels matching the labels in the provided LabelArray.
//
// Must be called with p.Mutex held | [
"GetRulesMatching",
"returns",
"whether",
"any",
"of",
"the",
"rules",
"in",
"a",
"repository",
"contain",
"a",
"rule",
"with",
"labels",
"matching",
"the",
"labels",
"in",
"the",
"provided",
"LabelArray",
".",
"Must",
"be",
"called",
"with",
"p",
".",
"Mutex",
"held"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L462-L481 |
162,523 | cilium/cilium | pkg/policy/repository.go | getMatchingRules | func (p *Repository) getMatchingRules(securityIdentity *identity.Identity) (ingressMatch bool, egressMatch bool, matchingRules ruleSlice) {
matchingRules = []*rule{}
ingressMatch = false
egressMatch = false
for _, r := range p.rules {
if ruleMatches := r.matches(securityIdentity); ruleMatches {
// Don't need to update whether ingressMatch is true if it already
// has been determined to be true - allows us to not have to check
// lenth of slice.
if !ingressMatch && len(r.Ingress) > 0 {
ingressMatch = true
}
if !egressMatch && len(r.Egress) > 0 {
egressMatch = true
}
matchingRules = append(matchingRules, r)
}
}
return
} | go | func (p *Repository) getMatchingRules(securityIdentity *identity.Identity) (ingressMatch bool, egressMatch bool, matchingRules ruleSlice) {
matchingRules = []*rule{}
ingressMatch = false
egressMatch = false
for _, r := range p.rules {
if ruleMatches := r.matches(securityIdentity); ruleMatches {
// Don't need to update whether ingressMatch is true if it already
// has been determined to be true - allows us to not have to check
// lenth of slice.
if !ingressMatch && len(r.Ingress) > 0 {
ingressMatch = true
}
if !egressMatch && len(r.Egress) > 0 {
egressMatch = true
}
matchingRules = append(matchingRules, r)
}
}
return
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"getMatchingRules",
"(",
"securityIdentity",
"*",
"identity",
".",
"Identity",
")",
"(",
"ingressMatch",
"bool",
",",
"egressMatch",
"bool",
",",
"matchingRules",
"ruleSlice",
")",
"{",
"matchingRules",
"=",
"[",
"]",
"*",
"rule",
"{",
"}",
"\n",
"ingressMatch",
"=",
"false",
"\n",
"egressMatch",
"=",
"false",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"p",
".",
"rules",
"{",
"if",
"ruleMatches",
":=",
"r",
".",
"matches",
"(",
"securityIdentity",
")",
";",
"ruleMatches",
"{",
"// Don't need to update whether ingressMatch is true if it already",
"// has been determined to be true - allows us to not have to check",
"// lenth of slice.",
"if",
"!",
"ingressMatch",
"&&",
"len",
"(",
"r",
".",
"Ingress",
")",
">",
"0",
"{",
"ingressMatch",
"=",
"true",
"\n",
"}",
"\n",
"if",
"!",
"egressMatch",
"&&",
"len",
"(",
"r",
".",
"Egress",
")",
">",
"0",
"{",
"egressMatch",
"=",
"true",
"\n",
"}",
"\n",
"matchingRules",
"=",
"append",
"(",
"matchingRules",
",",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // getMatchingRules returns whether any of the rules in a repository contain a
// rule with labels matching the labels in the provided LabelArray, as well as
// a slice of all rules which match.
//
// Must be called with p.Mutex held | [
"getMatchingRules",
"returns",
"whether",
"any",
"of",
"the",
"rules",
"in",
"a",
"repository",
"contain",
"a",
"rule",
"with",
"labels",
"matching",
"the",
"labels",
"in",
"the",
"provided",
"LabelArray",
"as",
"well",
"as",
"a",
"slice",
"of",
"all",
"rules",
"which",
"match",
".",
"Must",
"be",
"called",
"with",
"p",
".",
"Mutex",
"held"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L488-L507 |
162,524 | cilium/cilium | pkg/policy/repository.go | Empty | func (p *Repository) Empty() bool {
p.Mutex.Lock()
defer p.Mutex.Unlock()
return p.NumRules() == 0
} | go | func (p *Repository) Empty() bool {
p.Mutex.Lock()
defer p.Mutex.Unlock()
return p.NumRules() == 0
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"Empty",
"(",
")",
"bool",
"{",
"p",
".",
"Mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Mutex",
".",
"Unlock",
"(",
")",
"\n",
"return",
"p",
".",
"NumRules",
"(",
")",
"==",
"0",
"\n",
"}"
] | // Empty returns 'true' if repository has no rules, 'false' otherwise.
//
// Must be called without p.Mutex held | [
"Empty",
"returns",
"true",
"if",
"repository",
"has",
"no",
"rules",
"false",
"otherwise",
".",
"Must",
"be",
"called",
"without",
"p",
".",
"Mutex",
"held"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L524-L528 |
162,525 | cilium/cilium | pkg/policy/repository.go | TranslateRules | func (p *Repository) TranslateRules(translator Translator) (*TranslationResult, error) {
p.Mutex.Lock()
defer p.Mutex.Unlock()
result := &TranslationResult{}
for ruleIndex := range p.rules {
if err := translator.Translate(&p.rules[ruleIndex].Rule, result); err != nil {
return nil, err
}
}
return result, nil
} | go | func (p *Repository) TranslateRules(translator Translator) (*TranslationResult, error) {
p.Mutex.Lock()
defer p.Mutex.Unlock()
result := &TranslationResult{}
for ruleIndex := range p.rules {
if err := translator.Translate(&p.rules[ruleIndex].Rule, result); err != nil {
return nil, err
}
}
return result, nil
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"TranslateRules",
"(",
"translator",
"Translator",
")",
"(",
"*",
"TranslationResult",
",",
"error",
")",
"{",
"p",
".",
"Mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"p",
".",
"Mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"result",
":=",
"&",
"TranslationResult",
"{",
"}",
"\n\n",
"for",
"ruleIndex",
":=",
"range",
"p",
".",
"rules",
"{",
"if",
"err",
":=",
"translator",
".",
"Translate",
"(",
"&",
"p",
".",
"rules",
"[",
"ruleIndex",
"]",
".",
"Rule",
",",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // TranslateRules traverses rules and applies provided translator to rules | [
"TranslateRules",
"traverses",
"rules",
"and",
"applies",
"provided",
"translator",
"to",
"rules"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L538-L550 |
162,526 | cilium/cilium | pkg/policy/repository.go | BumpRevision | func (p *Repository) BumpRevision() {
metrics.PolicyRevision.Inc()
atomic.AddUint64(&p.revision, 1)
} | go | func (p *Repository) BumpRevision() {
metrics.PolicyRevision.Inc()
atomic.AddUint64(&p.revision, 1)
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"BumpRevision",
"(",
")",
"{",
"metrics",
".",
"PolicyRevision",
".",
"Inc",
"(",
")",
"\n",
"atomic",
".",
"AddUint64",
"(",
"&",
"p",
".",
"revision",
",",
"1",
")",
"\n",
"}"
] | // BumpRevision allows forcing policy regeneration | [
"BumpRevision",
"allows",
"forcing",
"policy",
"regeneration"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L553-L556 |
162,527 | cilium/cilium | pkg/policy/repository.go | GetRulesList | func (p *Repository) GetRulesList() *models.Policy {
p.Mutex.RLock()
defer p.Mutex.RUnlock()
lbls := labels.ParseSelectLabelArrayFromArray([]string{})
ruleList := p.SearchRLocked(lbls)
return &models.Policy{
Revision: int64(p.GetRevision()),
Policy: JSONMarshalRules(ruleList),
}
} | go | func (p *Repository) GetRulesList() *models.Policy {
p.Mutex.RLock()
defer p.Mutex.RUnlock()
lbls := labels.ParseSelectLabelArrayFromArray([]string{})
ruleList := p.SearchRLocked(lbls)
return &models.Policy{
Revision: int64(p.GetRevision()),
Policy: JSONMarshalRules(ruleList),
}
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"GetRulesList",
"(",
")",
"*",
"models",
".",
"Policy",
"{",
"p",
".",
"Mutex",
".",
"RLock",
"(",
")",
"\n",
"defer",
"p",
".",
"Mutex",
".",
"RUnlock",
"(",
")",
"\n\n",
"lbls",
":=",
"labels",
".",
"ParseSelectLabelArrayFromArray",
"(",
"[",
"]",
"string",
"{",
"}",
")",
"\n",
"ruleList",
":=",
"p",
".",
"SearchRLocked",
"(",
"lbls",
")",
"\n\n",
"return",
"&",
"models",
".",
"Policy",
"{",
"Revision",
":",
"int64",
"(",
"p",
".",
"GetRevision",
"(",
")",
")",
",",
"Policy",
":",
"JSONMarshalRules",
"(",
"ruleList",
")",
",",
"}",
"\n",
"}"
] | // GetRulesList returns the current policy | [
"GetRulesList",
"returns",
"the",
"current",
"policy"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L559-L570 |
162,528 | cilium/cilium | pkg/policy/repository.go | ResolvePolicyLocked | func (p *Repository) ResolvePolicyLocked(securityIdentity *identity.Identity) (*SelectorPolicy, error) {
// First obtain whether policy applies in both traffic directions, as well
// as list of rules which actually select this endpoint. This allows us
// to not have to iterate through the entire rule list multiple times and
// perform the matching decision again when computing policy for each
// protocol layer, which is quite costly in terms of performance.
ingressEnabled, egressEnabled, matchingRules := p.computePolicyEnforcementAndRules(securityIdentity)
calculatedPolicy := &SelectorPolicy{
Revision: p.GetRevision(),
L4Policy: NewL4Policy(),
CIDRPolicy: NewCIDRPolicy(),
matchingRules: matchingRules,
IngressPolicyEnabled: ingressEnabled,
EgressPolicyEnabled: egressEnabled,
}
calculatedPolicy.IngressPolicyEnabled = ingressEnabled
calculatedPolicy.EgressPolicyEnabled = egressEnabled
labels := securityIdentity.LabelArray
ingressCtx := SearchContext{
To: labels,
rulesSelect: true,
skipL4RequirementsAggregation: false,
}
egressCtx := SearchContext{
From: labels,
rulesSelect: true,
skipL4RequirementsAggregation: false,
}
if option.Config.TracingEnabled() {
ingressCtx.Trace = TRACE_ENABLED
egressCtx.Trace = TRACE_ENABLED
}
if ingressEnabled {
newL4IngressPolicy, err := matchingRules.resolveL4IngressPolicy(&ingressCtx, p.GetRevision())
if err != nil {
return nil, err
}
newCIDRIngressPolicy := matchingRules.resolveCIDRPolicy(&ingressCtx)
if err := newCIDRIngressPolicy.Validate(); err != nil {
return nil, err
}
calculatedPolicy.CIDRPolicy.Ingress = newCIDRIngressPolicy.Ingress
calculatedPolicy.L4Policy.Ingress = newL4IngressPolicy.Ingress
}
if egressEnabled {
newL4EgressPolicy, err := matchingRules.resolveL4EgressPolicy(&egressCtx, p.GetRevision())
if err != nil {
return nil, err
}
newCIDREgressPolicy := matchingRules.resolveCIDRPolicy(&egressCtx)
if err := newCIDREgressPolicy.Validate(); err != nil {
return nil, err
}
calculatedPolicy.CIDRPolicy.Egress = newCIDREgressPolicy.Egress
calculatedPolicy.L4Policy.Egress = newL4EgressPolicy.Egress
}
return calculatedPolicy, nil
} | go | func (p *Repository) ResolvePolicyLocked(securityIdentity *identity.Identity) (*SelectorPolicy, error) {
// First obtain whether policy applies in both traffic directions, as well
// as list of rules which actually select this endpoint. This allows us
// to not have to iterate through the entire rule list multiple times and
// perform the matching decision again when computing policy for each
// protocol layer, which is quite costly in terms of performance.
ingressEnabled, egressEnabled, matchingRules := p.computePolicyEnforcementAndRules(securityIdentity)
calculatedPolicy := &SelectorPolicy{
Revision: p.GetRevision(),
L4Policy: NewL4Policy(),
CIDRPolicy: NewCIDRPolicy(),
matchingRules: matchingRules,
IngressPolicyEnabled: ingressEnabled,
EgressPolicyEnabled: egressEnabled,
}
calculatedPolicy.IngressPolicyEnabled = ingressEnabled
calculatedPolicy.EgressPolicyEnabled = egressEnabled
labels := securityIdentity.LabelArray
ingressCtx := SearchContext{
To: labels,
rulesSelect: true,
skipL4RequirementsAggregation: false,
}
egressCtx := SearchContext{
From: labels,
rulesSelect: true,
skipL4RequirementsAggregation: false,
}
if option.Config.TracingEnabled() {
ingressCtx.Trace = TRACE_ENABLED
egressCtx.Trace = TRACE_ENABLED
}
if ingressEnabled {
newL4IngressPolicy, err := matchingRules.resolveL4IngressPolicy(&ingressCtx, p.GetRevision())
if err != nil {
return nil, err
}
newCIDRIngressPolicy := matchingRules.resolveCIDRPolicy(&ingressCtx)
if err := newCIDRIngressPolicy.Validate(); err != nil {
return nil, err
}
calculatedPolicy.CIDRPolicy.Ingress = newCIDRIngressPolicy.Ingress
calculatedPolicy.L4Policy.Ingress = newL4IngressPolicy.Ingress
}
if egressEnabled {
newL4EgressPolicy, err := matchingRules.resolveL4EgressPolicy(&egressCtx, p.GetRevision())
if err != nil {
return nil, err
}
newCIDREgressPolicy := matchingRules.resolveCIDRPolicy(&egressCtx)
if err := newCIDREgressPolicy.Validate(); err != nil {
return nil, err
}
calculatedPolicy.CIDRPolicy.Egress = newCIDREgressPolicy.Egress
calculatedPolicy.L4Policy.Egress = newL4EgressPolicy.Egress
}
return calculatedPolicy, nil
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"ResolvePolicyLocked",
"(",
"securityIdentity",
"*",
"identity",
".",
"Identity",
")",
"(",
"*",
"SelectorPolicy",
",",
"error",
")",
"{",
"// First obtain whether policy applies in both traffic directions, as well",
"// as list of rules which actually select this endpoint. This allows us",
"// to not have to iterate through the entire rule list multiple times and",
"// perform the matching decision again when computing policy for each",
"// protocol layer, which is quite costly in terms of performance.",
"ingressEnabled",
",",
"egressEnabled",
",",
"matchingRules",
":=",
"p",
".",
"computePolicyEnforcementAndRules",
"(",
"securityIdentity",
")",
"\n\n",
"calculatedPolicy",
":=",
"&",
"SelectorPolicy",
"{",
"Revision",
":",
"p",
".",
"GetRevision",
"(",
")",
",",
"L4Policy",
":",
"NewL4Policy",
"(",
")",
",",
"CIDRPolicy",
":",
"NewCIDRPolicy",
"(",
")",
",",
"matchingRules",
":",
"matchingRules",
",",
"IngressPolicyEnabled",
":",
"ingressEnabled",
",",
"EgressPolicyEnabled",
":",
"egressEnabled",
",",
"}",
"\n",
"calculatedPolicy",
".",
"IngressPolicyEnabled",
"=",
"ingressEnabled",
"\n",
"calculatedPolicy",
".",
"EgressPolicyEnabled",
"=",
"egressEnabled",
"\n\n",
"labels",
":=",
"securityIdentity",
".",
"LabelArray",
"\n",
"ingressCtx",
":=",
"SearchContext",
"{",
"To",
":",
"labels",
",",
"rulesSelect",
":",
"true",
",",
"skipL4RequirementsAggregation",
":",
"false",
",",
"}",
"\n\n",
"egressCtx",
":=",
"SearchContext",
"{",
"From",
":",
"labels",
",",
"rulesSelect",
":",
"true",
",",
"skipL4RequirementsAggregation",
":",
"false",
",",
"}",
"\n\n",
"if",
"option",
".",
"Config",
".",
"TracingEnabled",
"(",
")",
"{",
"ingressCtx",
".",
"Trace",
"=",
"TRACE_ENABLED",
"\n",
"egressCtx",
".",
"Trace",
"=",
"TRACE_ENABLED",
"\n",
"}",
"\n\n",
"if",
"ingressEnabled",
"{",
"newL4IngressPolicy",
",",
"err",
":=",
"matchingRules",
".",
"resolveL4IngressPolicy",
"(",
"&",
"ingressCtx",
",",
"p",
".",
"GetRevision",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"newCIDRIngressPolicy",
":=",
"matchingRules",
".",
"resolveCIDRPolicy",
"(",
"&",
"ingressCtx",
")",
"\n",
"if",
"err",
":=",
"newCIDRIngressPolicy",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"calculatedPolicy",
".",
"CIDRPolicy",
".",
"Ingress",
"=",
"newCIDRIngressPolicy",
".",
"Ingress",
"\n",
"calculatedPolicy",
".",
"L4Policy",
".",
"Ingress",
"=",
"newL4IngressPolicy",
".",
"Ingress",
"\n",
"}",
"\n\n",
"if",
"egressEnabled",
"{",
"newL4EgressPolicy",
",",
"err",
":=",
"matchingRules",
".",
"resolveL4EgressPolicy",
"(",
"&",
"egressCtx",
",",
"p",
".",
"GetRevision",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"newCIDREgressPolicy",
":=",
"matchingRules",
".",
"resolveCIDRPolicy",
"(",
"&",
"egressCtx",
")",
"\n",
"if",
"err",
":=",
"newCIDREgressPolicy",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"calculatedPolicy",
".",
"CIDRPolicy",
".",
"Egress",
"=",
"newCIDREgressPolicy",
".",
"Egress",
"\n",
"calculatedPolicy",
".",
"L4Policy",
".",
"Egress",
"=",
"newL4EgressPolicy",
".",
"Egress",
"\n",
"}",
"\n\n",
"return",
"calculatedPolicy",
",",
"nil",
"\n",
"}"
] | // ResolvePolicyLocked returns the EndpointPolicy for the provided set of
// labels against the set of rules in the repository, and the provided set of
// identities. If the policy cannot be generated due to conflicts at L4 or L7,
// returns an error.
//
// Must be performed while holding the Repository lock. | [
"ResolvePolicyLocked",
"returns",
"the",
"EndpointPolicy",
"for",
"the",
"provided",
"set",
"of",
"labels",
"against",
"the",
"set",
"of",
"rules",
"in",
"the",
"repository",
"and",
"the",
"provided",
"set",
"of",
"identities",
".",
"If",
"the",
"policy",
"cannot",
"be",
"generated",
"due",
"to",
"conflicts",
"at",
"L4",
"or",
"L7",
"returns",
"an",
"error",
".",
"Must",
"be",
"performed",
"while",
"holding",
"the",
"Repository",
"lock",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L578-L647 |
162,529 | cilium/cilium | pkg/policy/repository.go | computePolicyEnforcementAndRules | func (p *Repository) computePolicyEnforcementAndRules(securityIdentity *identity.Identity) (ingress bool, egress bool, matchingRules ruleSlice) {
lbls := securityIdentity.LabelArray
// Check if policy enforcement should be enabled at the daemon level.
switch GetPolicyEnabled() {
case option.AlwaysEnforce:
_, _, matchingRules = p.getMatchingRules(securityIdentity)
// If policy enforcement is enabled for the daemon, then it has to be
// enabled for the endpoint.
return true, true, matchingRules
case option.DefaultEnforcement:
ingress, egress, matchingRules = p.getMatchingRules(securityIdentity)
// If the endpoint has the reserved:init label, i.e. if it has not yet
// received any labels, always enforce policy (default deny).
if lbls.Has(labels.IDNameInit) {
return true, true, matchingRules
}
// Default mode means that if rules contain labels that match this
// endpoint, then enable policy enforcement for this endpoint.
return ingress, egress, matchingRules
default:
// If policy enforcement isn't enabled, we do not enable policy
// enforcement for the endpoint. We don't care about returning any
// rules that match.
return false, false, nil
}
} | go | func (p *Repository) computePolicyEnforcementAndRules(securityIdentity *identity.Identity) (ingress bool, egress bool, matchingRules ruleSlice) {
lbls := securityIdentity.LabelArray
// Check if policy enforcement should be enabled at the daemon level.
switch GetPolicyEnabled() {
case option.AlwaysEnforce:
_, _, matchingRules = p.getMatchingRules(securityIdentity)
// If policy enforcement is enabled for the daemon, then it has to be
// enabled for the endpoint.
return true, true, matchingRules
case option.DefaultEnforcement:
ingress, egress, matchingRules = p.getMatchingRules(securityIdentity)
// If the endpoint has the reserved:init label, i.e. if it has not yet
// received any labels, always enforce policy (default deny).
if lbls.Has(labels.IDNameInit) {
return true, true, matchingRules
}
// Default mode means that if rules contain labels that match this
// endpoint, then enable policy enforcement for this endpoint.
return ingress, egress, matchingRules
default:
// If policy enforcement isn't enabled, we do not enable policy
// enforcement for the endpoint. We don't care about returning any
// rules that match.
return false, false, nil
}
} | [
"func",
"(",
"p",
"*",
"Repository",
")",
"computePolicyEnforcementAndRules",
"(",
"securityIdentity",
"*",
"identity",
".",
"Identity",
")",
"(",
"ingress",
"bool",
",",
"egress",
"bool",
",",
"matchingRules",
"ruleSlice",
")",
"{",
"lbls",
":=",
"securityIdentity",
".",
"LabelArray",
"\n",
"// Check if policy enforcement should be enabled at the daemon level.",
"switch",
"GetPolicyEnabled",
"(",
")",
"{",
"case",
"option",
".",
"AlwaysEnforce",
":",
"_",
",",
"_",
",",
"matchingRules",
"=",
"p",
".",
"getMatchingRules",
"(",
"securityIdentity",
")",
"\n",
"// If policy enforcement is enabled for the daemon, then it has to be",
"// enabled for the endpoint.",
"return",
"true",
",",
"true",
",",
"matchingRules",
"\n",
"case",
"option",
".",
"DefaultEnforcement",
":",
"ingress",
",",
"egress",
",",
"matchingRules",
"=",
"p",
".",
"getMatchingRules",
"(",
"securityIdentity",
")",
"\n",
"// If the endpoint has the reserved:init label, i.e. if it has not yet",
"// received any labels, always enforce policy (default deny).",
"if",
"lbls",
".",
"Has",
"(",
"labels",
".",
"IDNameInit",
")",
"{",
"return",
"true",
",",
"true",
",",
"matchingRules",
"\n",
"}",
"\n\n",
"// Default mode means that if rules contain labels that match this",
"// endpoint, then enable policy enforcement for this endpoint.",
"return",
"ingress",
",",
"egress",
",",
"matchingRules",
"\n",
"default",
":",
"// If policy enforcement isn't enabled, we do not enable policy",
"// enforcement for the endpoint. We don't care about returning any",
"// rules that match.",
"return",
"false",
",",
"false",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // computePolicyEnforcementAndRules returns whether policy applies at ingress or ingress
// for the given set of labels, as well as a list of any rules which select
// the set of labels.
//
// Must be called with repo mutex held for reading. | [
"computePolicyEnforcementAndRules",
"returns",
"whether",
"policy",
"applies",
"at",
"ingress",
"or",
"ingress",
"for",
"the",
"given",
"set",
"of",
"labels",
"as",
"well",
"as",
"a",
"list",
"of",
"any",
"rules",
"which",
"select",
"the",
"set",
"of",
"labels",
".",
"Must",
"be",
"called",
"with",
"repo",
"mutex",
"held",
"for",
"reading",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/repository.go#L654-L681 |
162,530 | cilium/cilium | api/v1/server/restapi/policy/get_identity_id.go | NewGetIdentityID | func NewGetIdentityID(ctx *middleware.Context, handler GetIdentityIDHandler) *GetIdentityID {
return &GetIdentityID{Context: ctx, Handler: handler}
} | go | func NewGetIdentityID(ctx *middleware.Context, handler GetIdentityIDHandler) *GetIdentityID {
return &GetIdentityID{Context: ctx, Handler: handler}
} | [
"func",
"NewGetIdentityID",
"(",
"ctx",
"*",
"middleware",
".",
"Context",
",",
"handler",
"GetIdentityIDHandler",
")",
"*",
"GetIdentityID",
"{",
"return",
"&",
"GetIdentityID",
"{",
"Context",
":",
"ctx",
",",
"Handler",
":",
"handler",
"}",
"\n",
"}"
] | // NewGetIdentityID creates a new http.Handler for the get identity ID operation | [
"NewGetIdentityID",
"creates",
"a",
"new",
"http",
".",
"Handler",
"for",
"the",
"get",
"identity",
"ID",
"operation"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/policy/get_identity_id.go#L28-L30 |
162,531 | cilium/cilium | pkg/identity/reserved.go | AddReservedIdentity | func AddReservedIdentity(ni NumericIdentity, lbl string) {
identity := NewIdentity(ni, labels.Labels{lbl: labels.NewLabel(lbl, "", labels.LabelSourceReserved)})
// Pre-calculate the SHA256 hash.
identity.GetLabelsSHA256()
ReservedIdentityCache[ni] = identity
} | go | func AddReservedIdentity(ni NumericIdentity, lbl string) {
identity := NewIdentity(ni, labels.Labels{lbl: labels.NewLabel(lbl, "", labels.LabelSourceReserved)})
// Pre-calculate the SHA256 hash.
identity.GetLabelsSHA256()
ReservedIdentityCache[ni] = identity
} | [
"func",
"AddReservedIdentity",
"(",
"ni",
"NumericIdentity",
",",
"lbl",
"string",
")",
"{",
"identity",
":=",
"NewIdentity",
"(",
"ni",
",",
"labels",
".",
"Labels",
"{",
"lbl",
":",
"labels",
".",
"NewLabel",
"(",
"lbl",
",",
"\"",
"\"",
",",
"labels",
".",
"LabelSourceReserved",
")",
"}",
")",
"\n",
"// Pre-calculate the SHA256 hash.",
"identity",
".",
"GetLabelsSHA256",
"(",
")",
"\n",
"ReservedIdentityCache",
"[",
"ni",
"]",
"=",
"identity",
"\n",
"}"
] | // AddReservedIdentity adds the reserved numeric identity with the respective
// label into the map of reserved identity cache. | [
"AddReservedIdentity",
"adds",
"the",
"reserved",
"numeric",
"identity",
"with",
"the",
"respective",
"label",
"into",
"the",
"map",
"of",
"reserved",
"identity",
"cache",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/identity/reserved.go#L27-L32 |
162,532 | cilium/cilium | api/v1/server/restapi/endpoint/put_endpoint_id.go | NewPutEndpointID | func NewPutEndpointID(ctx *middleware.Context, handler PutEndpointIDHandler) *PutEndpointID {
return &PutEndpointID{Context: ctx, Handler: handler}
} | go | func NewPutEndpointID(ctx *middleware.Context, handler PutEndpointIDHandler) *PutEndpointID {
return &PutEndpointID{Context: ctx, Handler: handler}
} | [
"func",
"NewPutEndpointID",
"(",
"ctx",
"*",
"middleware",
".",
"Context",
",",
"handler",
"PutEndpointIDHandler",
")",
"*",
"PutEndpointID",
"{",
"return",
"&",
"PutEndpointID",
"{",
"Context",
":",
"ctx",
",",
"Handler",
":",
"handler",
"}",
"\n",
"}"
] | // NewPutEndpointID creates a new http.Handler for the put endpoint ID operation | [
"NewPutEndpointID",
"creates",
"a",
"new",
"http",
".",
"Handler",
"for",
"the",
"put",
"endpoint",
"ID",
"operation"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/endpoint/put_endpoint_id.go#L28-L30 |
162,533 | cilium/cilium | api/v1/health/server/restapi/cilium_health_api.go | NewCiliumHealthAPI | func NewCiliumHealthAPI(spec *loads.Document) *CiliumHealthAPI {
return &CiliumHealthAPI{
handlers: make(map[string]map[string]http.Handler),
formats: strfmt.Default,
defaultConsumes: "application/json",
defaultProduces: "application/json",
customConsumers: make(map[string]runtime.Consumer),
customProducers: make(map[string]runtime.Producer),
ServerShutdown: func() {},
spec: spec,
ServeError: errors.ServeError,
BasicAuthenticator: security.BasicAuth,
APIKeyAuthenticator: security.APIKeyAuth,
BearerAuthenticator: security.BearerAuth,
JSONConsumer: runtime.JSONConsumer(),
JSONProducer: runtime.JSONProducer(),
GetHealthzHandler: GetHealthzHandlerFunc(func(params GetHealthzParams) middleware.Responder {
return middleware.NotImplemented("operation GetHealthz has not yet been implemented")
}),
GetHelloHandler: GetHelloHandlerFunc(func(params GetHelloParams) middleware.Responder {
return middleware.NotImplemented("operation GetHello has not yet been implemented")
}),
ConnectivityGetStatusHandler: connectivity.GetStatusHandlerFunc(func(params connectivity.GetStatusParams) middleware.Responder {
return middleware.NotImplemented("operation ConnectivityGetStatus has not yet been implemented")
}),
ConnectivityPutStatusProbeHandler: connectivity.PutStatusProbeHandlerFunc(func(params connectivity.PutStatusProbeParams) middleware.Responder {
return middleware.NotImplemented("operation ConnectivityPutStatusProbe has not yet been implemented")
}),
}
} | go | func NewCiliumHealthAPI(spec *loads.Document) *CiliumHealthAPI {
return &CiliumHealthAPI{
handlers: make(map[string]map[string]http.Handler),
formats: strfmt.Default,
defaultConsumes: "application/json",
defaultProduces: "application/json",
customConsumers: make(map[string]runtime.Consumer),
customProducers: make(map[string]runtime.Producer),
ServerShutdown: func() {},
spec: spec,
ServeError: errors.ServeError,
BasicAuthenticator: security.BasicAuth,
APIKeyAuthenticator: security.APIKeyAuth,
BearerAuthenticator: security.BearerAuth,
JSONConsumer: runtime.JSONConsumer(),
JSONProducer: runtime.JSONProducer(),
GetHealthzHandler: GetHealthzHandlerFunc(func(params GetHealthzParams) middleware.Responder {
return middleware.NotImplemented("operation GetHealthz has not yet been implemented")
}),
GetHelloHandler: GetHelloHandlerFunc(func(params GetHelloParams) middleware.Responder {
return middleware.NotImplemented("operation GetHello has not yet been implemented")
}),
ConnectivityGetStatusHandler: connectivity.GetStatusHandlerFunc(func(params connectivity.GetStatusParams) middleware.Responder {
return middleware.NotImplemented("operation ConnectivityGetStatus has not yet been implemented")
}),
ConnectivityPutStatusProbeHandler: connectivity.PutStatusProbeHandlerFunc(func(params connectivity.PutStatusProbeParams) middleware.Responder {
return middleware.NotImplemented("operation ConnectivityPutStatusProbe has not yet been implemented")
}),
}
} | [
"func",
"NewCiliumHealthAPI",
"(",
"spec",
"*",
"loads",
".",
"Document",
")",
"*",
"CiliumHealthAPI",
"{",
"return",
"&",
"CiliumHealthAPI",
"{",
"handlers",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"http",
".",
"Handler",
")",
",",
"formats",
":",
"strfmt",
".",
"Default",
",",
"defaultConsumes",
":",
"\"",
"\"",
",",
"defaultProduces",
":",
"\"",
"\"",
",",
"customConsumers",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"runtime",
".",
"Consumer",
")",
",",
"customProducers",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"runtime",
".",
"Producer",
")",
",",
"ServerShutdown",
":",
"func",
"(",
")",
"{",
"}",
",",
"spec",
":",
"spec",
",",
"ServeError",
":",
"errors",
".",
"ServeError",
",",
"BasicAuthenticator",
":",
"security",
".",
"BasicAuth",
",",
"APIKeyAuthenticator",
":",
"security",
".",
"APIKeyAuth",
",",
"BearerAuthenticator",
":",
"security",
".",
"BearerAuth",
",",
"JSONConsumer",
":",
"runtime",
".",
"JSONConsumer",
"(",
")",
",",
"JSONProducer",
":",
"runtime",
".",
"JSONProducer",
"(",
")",
",",
"GetHealthzHandler",
":",
"GetHealthzHandlerFunc",
"(",
"func",
"(",
"params",
"GetHealthzParams",
")",
"middleware",
".",
"Responder",
"{",
"return",
"middleware",
".",
"NotImplemented",
"(",
"\"",
"\"",
")",
"\n",
"}",
")",
",",
"GetHelloHandler",
":",
"GetHelloHandlerFunc",
"(",
"func",
"(",
"params",
"GetHelloParams",
")",
"middleware",
".",
"Responder",
"{",
"return",
"middleware",
".",
"NotImplemented",
"(",
"\"",
"\"",
")",
"\n",
"}",
")",
",",
"ConnectivityGetStatusHandler",
":",
"connectivity",
".",
"GetStatusHandlerFunc",
"(",
"func",
"(",
"params",
"connectivity",
".",
"GetStatusParams",
")",
"middleware",
".",
"Responder",
"{",
"return",
"middleware",
".",
"NotImplemented",
"(",
"\"",
"\"",
")",
"\n",
"}",
")",
",",
"ConnectivityPutStatusProbeHandler",
":",
"connectivity",
".",
"PutStatusProbeHandlerFunc",
"(",
"func",
"(",
"params",
"connectivity",
".",
"PutStatusProbeParams",
")",
"middleware",
".",
"Responder",
"{",
"return",
"middleware",
".",
"NotImplemented",
"(",
"\"",
"\"",
")",
"\n",
"}",
")",
",",
"}",
"\n",
"}"
] | // NewCiliumHealthAPI creates a new CiliumHealth instance | [
"NewCiliumHealthAPI",
"creates",
"a",
"new",
"CiliumHealth",
"instance"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/health/server/restapi/cilium_health_api.go#L26-L55 |
162,534 | cilium/cilium | api/v1/health/server/restapi/cilium_health_api.go | Validate | func (o *CiliumHealthAPI) Validate() error {
var unregistered []string
if o.JSONConsumer == nil {
unregistered = append(unregistered, "JSONConsumer")
}
if o.JSONProducer == nil {
unregistered = append(unregistered, "JSONProducer")
}
if o.GetHealthzHandler == nil {
unregistered = append(unregistered, "GetHealthzHandler")
}
if o.GetHelloHandler == nil {
unregistered = append(unregistered, "GetHelloHandler")
}
if o.ConnectivityGetStatusHandler == nil {
unregistered = append(unregistered, "connectivity.GetStatusHandler")
}
if o.ConnectivityPutStatusProbeHandler == nil {
unregistered = append(unregistered, "connectivity.PutStatusProbeHandler")
}
if len(unregistered) > 0 {
return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
}
return nil
} | go | func (o *CiliumHealthAPI) Validate() error {
var unregistered []string
if o.JSONConsumer == nil {
unregistered = append(unregistered, "JSONConsumer")
}
if o.JSONProducer == nil {
unregistered = append(unregistered, "JSONProducer")
}
if o.GetHealthzHandler == nil {
unregistered = append(unregistered, "GetHealthzHandler")
}
if o.GetHelloHandler == nil {
unregistered = append(unregistered, "GetHelloHandler")
}
if o.ConnectivityGetStatusHandler == nil {
unregistered = append(unregistered, "connectivity.GetStatusHandler")
}
if o.ConnectivityPutStatusProbeHandler == nil {
unregistered = append(unregistered, "connectivity.PutStatusProbeHandler")
}
if len(unregistered) > 0 {
return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
}
return nil
} | [
"func",
"(",
"o",
"*",
"CiliumHealthAPI",
")",
"Validate",
"(",
")",
"error",
"{",
"var",
"unregistered",
"[",
"]",
"string",
"\n\n",
"if",
"o",
".",
"JSONConsumer",
"==",
"nil",
"{",
"unregistered",
"=",
"append",
"(",
"unregistered",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"JSONProducer",
"==",
"nil",
"{",
"unregistered",
"=",
"append",
"(",
"unregistered",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"GetHealthzHandler",
"==",
"nil",
"{",
"unregistered",
"=",
"append",
"(",
"unregistered",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"GetHelloHandler",
"==",
"nil",
"{",
"unregistered",
"=",
"append",
"(",
"unregistered",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"ConnectivityGetStatusHandler",
"==",
"nil",
"{",
"unregistered",
"=",
"append",
"(",
"unregistered",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"o",
".",
"ConnectivityPutStatusProbeHandler",
"==",
"nil",
"{",
"unregistered",
"=",
"append",
"(",
"unregistered",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"unregistered",
")",
">",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"unregistered",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate validates the registrations in the CiliumHealthAPI | [
"Validate",
"validates",
"the",
"registrations",
"in",
"the",
"CiliumHealthAPI"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/health/server/restapi/cilium_health_api.go#L145-L177 |
162,535 | cilium/cilium | api/v1/health/server/restapi/cilium_health_api.go | Context | func (o *CiliumHealthAPI) Context() *middleware.Context {
if o.context == nil {
o.context = middleware.NewRoutableContext(o.spec, o, nil)
}
return o.context
} | go | func (o *CiliumHealthAPI) Context() *middleware.Context {
if o.context == nil {
o.context = middleware.NewRoutableContext(o.spec, o, nil)
}
return o.context
} | [
"func",
"(",
"o",
"*",
"CiliumHealthAPI",
")",
"Context",
"(",
")",
"*",
"middleware",
".",
"Context",
"{",
"if",
"o",
".",
"context",
"==",
"nil",
"{",
"o",
".",
"context",
"=",
"middleware",
".",
"NewRoutableContext",
"(",
"o",
".",
"spec",
",",
"o",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"return",
"o",
".",
"context",
"\n",
"}"
] | // Context returns the middleware context for the cilium health API | [
"Context",
"returns",
"the",
"middleware",
"context",
"for",
"the",
"cilium",
"health",
"API"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/health/server/restapi/cilium_health_api.go#L255-L261 |
162,536 | cilium/cilium | pkg/maps/ctmap/lookup.go | ToNetwork | func (k *CtKey4) ToNetwork() tuple.TupleKey {
n := *k
n.SourcePort = byteorder.HostToNetwork(n.SourcePort).(uint16)
n.DestPort = byteorder.HostToNetwork(n.DestPort).(uint16)
return &n
} | go | func (k *CtKey4) ToNetwork() tuple.TupleKey {
n := *k
n.SourcePort = byteorder.HostToNetwork(n.SourcePort).(uint16)
n.DestPort = byteorder.HostToNetwork(n.DestPort).(uint16)
return &n
} | [
"func",
"(",
"k",
"*",
"CtKey4",
")",
"ToNetwork",
"(",
")",
"tuple",
".",
"TupleKey",
"{",
"n",
":=",
"*",
"k",
"\n",
"n",
".",
"SourcePort",
"=",
"byteorder",
".",
"HostToNetwork",
"(",
"n",
".",
"SourcePort",
")",
".",
"(",
"uint16",
")",
"\n",
"n",
".",
"DestPort",
"=",
"byteorder",
".",
"HostToNetwork",
"(",
"n",
".",
"DestPort",
")",
".",
"(",
"uint16",
")",
"\n",
"return",
"&",
"n",
"\n",
"}"
] | // ToNetwork converts CtKey4 ports to network byte order. | [
"ToNetwork",
"converts",
"CtKey4",
"ports",
"to",
"network",
"byte",
"order",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/ctmap/lookup.go#L37-L42 |
162,537 | cilium/cilium | pkg/maps/ctmap/lookup.go | Lookup | func Lookup(epname string, remoteAddr, localAddr string, proto u8proto.U8proto, ingress bool) (*CtEntry, error) {
key, err := createTupleKey(remoteAddr, localAddr, proto, ingress)
if err != nil {
return nil, err
}
_, ipv4 := key.(*CtKey4)
mapname := getMapName(epname, ipv4, proto)
m := bpf.GetMap(mapname)
if m == nil {
// Open the map and leave it open
m, err = bpf.OpenMap(mapname)
if err != nil {
return nil, fmt.Errorf("Can not open CT map %s: %s", mapname, err)
}
}
v, err := m.Lookup(key)
if err != nil || v == nil {
return nil, err
}
return v.(*CtEntry), err
} | go | func Lookup(epname string, remoteAddr, localAddr string, proto u8proto.U8proto, ingress bool) (*CtEntry, error) {
key, err := createTupleKey(remoteAddr, localAddr, proto, ingress)
if err != nil {
return nil, err
}
_, ipv4 := key.(*CtKey4)
mapname := getMapName(epname, ipv4, proto)
m := bpf.GetMap(mapname)
if m == nil {
// Open the map and leave it open
m, err = bpf.OpenMap(mapname)
if err != nil {
return nil, fmt.Errorf("Can not open CT map %s: %s", mapname, err)
}
}
v, err := m.Lookup(key)
if err != nil || v == nil {
return nil, err
}
return v.(*CtEntry), err
} | [
"func",
"Lookup",
"(",
"epname",
"string",
",",
"remoteAddr",
",",
"localAddr",
"string",
",",
"proto",
"u8proto",
".",
"U8proto",
",",
"ingress",
"bool",
")",
"(",
"*",
"CtEntry",
",",
"error",
")",
"{",
"key",
",",
"err",
":=",
"createTupleKey",
"(",
"remoteAddr",
",",
"localAddr",
",",
"proto",
",",
"ingress",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"ipv4",
":=",
"key",
".",
"(",
"*",
"CtKey4",
")",
"\n\n",
"mapname",
":=",
"getMapName",
"(",
"epname",
",",
"ipv4",
",",
"proto",
")",
"\n\n",
"m",
":=",
"bpf",
".",
"GetMap",
"(",
"mapname",
")",
"\n",
"if",
"m",
"==",
"nil",
"{",
"// Open the map and leave it open",
"m",
",",
"err",
"=",
"bpf",
".",
"OpenMap",
"(",
"mapname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"mapname",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"v",
",",
"err",
":=",
"m",
".",
"Lookup",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"v",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"v",
".",
"(",
"*",
"CtEntry",
")",
",",
"err",
"\n",
"}"
] | // Lookup opens a conntrack map if necessary, and does a lookup on it with a key constructed from
// the parameters
// 'epname' is a 5-digit represenation of the endpoint ID if local maps
// are to be used, or "global" if global maps should be used. | [
"Lookup",
"opens",
"a",
"conntrack",
"map",
"if",
"necessary",
"and",
"does",
"a",
"lookup",
"on",
"it",
"with",
"a",
"key",
"constructed",
"from",
"the",
"parameters",
"epname",
"is",
"a",
"5",
"-",
"digit",
"represenation",
"of",
"the",
"endpoint",
"ID",
"if",
"local",
"maps",
"are",
"to",
"be",
"used",
"or",
"global",
"if",
"global",
"maps",
"should",
"be",
"used",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/ctmap/lookup.go#L147-L171 |
162,538 | cilium/cilium | pkg/maps/ctmap/lookup.go | CloseLocalMaps | func CloseLocalMaps(mapname string) {
// only close local maps. Global map is kept open as long as cilium-agent is running.
if mapname != "global" {
// close IPv4 maps, if any
if m := getMapWithName(mapname, true, u8proto.TCP); m != nil {
m.Close()
}
if m := getMapWithName(mapname, true, u8proto.UDP); m != nil {
m.Close()
}
// close IPv6 maps, if any
if m := getMapWithName(mapname, false, u8proto.TCP); m != nil {
m.Close()
}
if m := getMapWithName(mapname, false, u8proto.UDP); m != nil {
m.Close()
}
}
} | go | func CloseLocalMaps(mapname string) {
// only close local maps. Global map is kept open as long as cilium-agent is running.
if mapname != "global" {
// close IPv4 maps, if any
if m := getMapWithName(mapname, true, u8proto.TCP); m != nil {
m.Close()
}
if m := getMapWithName(mapname, true, u8proto.UDP); m != nil {
m.Close()
}
// close IPv6 maps, if any
if m := getMapWithName(mapname, false, u8proto.TCP); m != nil {
m.Close()
}
if m := getMapWithName(mapname, false, u8proto.UDP); m != nil {
m.Close()
}
}
} | [
"func",
"CloseLocalMaps",
"(",
"mapname",
"string",
")",
"{",
"// only close local maps. Global map is kept open as long as cilium-agent is running.",
"if",
"mapname",
"!=",
"\"",
"\"",
"{",
"// close IPv4 maps, if any",
"if",
"m",
":=",
"getMapWithName",
"(",
"mapname",
",",
"true",
",",
"u8proto",
".",
"TCP",
")",
";",
"m",
"!=",
"nil",
"{",
"m",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"if",
"m",
":=",
"getMapWithName",
"(",
"mapname",
",",
"true",
",",
"u8proto",
".",
"UDP",
")",
";",
"m",
"!=",
"nil",
"{",
"m",
".",
"Close",
"(",
")",
"\n",
"}",
"\n\n",
"// close IPv6 maps, if any",
"if",
"m",
":=",
"getMapWithName",
"(",
"mapname",
",",
"false",
",",
"u8proto",
".",
"TCP",
")",
";",
"m",
"!=",
"nil",
"{",
"m",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"if",
"m",
":=",
"getMapWithName",
"(",
"mapname",
",",
"false",
",",
"u8proto",
".",
"UDP",
")",
";",
"m",
"!=",
"nil",
"{",
"m",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // CloseLocalMaps closes all local conntrack maps opened previously
// for lookup with the given 'mapname'. | [
"CloseLocalMaps",
"closes",
"all",
"local",
"conntrack",
"maps",
"opened",
"previously",
"for",
"lookup",
"with",
"the",
"given",
"mapname",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/maps/ctmap/lookup.go#L179-L198 |
162,539 | cilium/cilium | pkg/policy/rule.go | rulePortsCoverSearchContext | func rulePortsCoverSearchContext(ports []api.PortProtocol, ctx *SearchContext) bool {
if len(ctx.DPorts) == 0 {
return true
}
for _, p := range ports {
for _, dp := range ctx.DPorts {
tracePort := api.PortProtocol{
Port: fmt.Sprintf("%d", dp.Port),
Protocol: api.L4Proto(dp.Protocol),
}
if p.Covers(tracePort) {
return true
}
}
}
return false
} | go | func rulePortsCoverSearchContext(ports []api.PortProtocol, ctx *SearchContext) bool {
if len(ctx.DPorts) == 0 {
return true
}
for _, p := range ports {
for _, dp := range ctx.DPorts {
tracePort := api.PortProtocol{
Port: fmt.Sprintf("%d", dp.Port),
Protocol: api.L4Proto(dp.Protocol),
}
if p.Covers(tracePort) {
return true
}
}
}
return false
} | [
"func",
"rulePortsCoverSearchContext",
"(",
"ports",
"[",
"]",
"api",
".",
"PortProtocol",
",",
"ctx",
"*",
"SearchContext",
")",
"bool",
"{",
"if",
"len",
"(",
"ctx",
".",
"DPorts",
")",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"ports",
"{",
"for",
"_",
",",
"dp",
":=",
"range",
"ctx",
".",
"DPorts",
"{",
"tracePort",
":=",
"api",
".",
"PortProtocol",
"{",
"Port",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"dp",
".",
"Port",
")",
",",
"Protocol",
":",
"api",
".",
"L4Proto",
"(",
"dp",
".",
"Protocol",
")",
",",
"}",
"\n",
"if",
"p",
".",
"Covers",
"(",
"tracePort",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // portRulesCoverContext determines whether L4 portions of rules cover the
// specified port models.
//
// Returns true if the list of ports is 0, or the rules match the ports. | [
"portRulesCoverContext",
"determines",
"whether",
"L4",
"portions",
"of",
"rules",
"cover",
"the",
"specified",
"port",
"models",
".",
"Returns",
"true",
"if",
"the",
"list",
"of",
"ports",
"is",
"0",
"or",
"the",
"rules",
"match",
"the",
"ports",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/rule.go#L209-L225 |
162,540 | cilium/cilium | pkg/policy/rule.go | resolveCIDRPolicy | func (r *rule) resolveCIDRPolicy(ctx *SearchContext, state *traceState, result *CIDRPolicy) *CIDRPolicy {
// Don't select rule if it doesn't apply to the given context.
if !ctx.rulesSelect {
if !r.EndpointSelector.Matches(ctx.To) {
state.unSelectRule(ctx, ctx.To, r)
return nil
}
}
state.selectRule(ctx, r)
found := 0
for _, ingressRule := range r.Ingress {
// TODO (ianvernon): GH-1658
var allCIDRs []api.CIDR
allCIDRs = append(allCIDRs, ingressRule.FromCIDR...)
allCIDRs = append(allCIDRs, api.ComputeResultantCIDRSet(ingressRule.FromCIDRSet)...)
// CIDR + L4 rules are handled via mergeIngress(),
// skip them here.
if len(allCIDRs) > 0 && len(ingressRule.ToPorts) > 0 {
continue
}
if cnt := mergeCIDR(ctx, "Ingress", allCIDRs, r.Labels, &result.Ingress); cnt > 0 {
found += cnt
}
}
// CIDR egress policy is used for visibility of desired state in
// the API and for determining which prefix lengths are available,
// however it does not determine the actual CIDRs in the BPF maps
// for allowing traffic by CIDR!
for _, egressRule := range r.Egress {
var allCIDRs []api.CIDR
allCIDRs = append(allCIDRs, egressRule.ToCIDR...)
allCIDRs = append(allCIDRs, api.ComputeResultantCIDRSet(egressRule.ToCIDRSet)...)
// Unlike the Ingress policy which only counts L3 policy in
// this function, we count the CIDR+L4 policy in the
// desired egress CIDR policy here as well. This ensures
// proper computation of IPcache prefix lengths.
if cnt := mergeCIDR(ctx, "Egress", allCIDRs, r.Labels, &result.Egress); cnt > 0 {
found += cnt
}
}
if found > 0 {
return result
}
ctx.PolicyTrace(" No L3 rules\n")
return nil
} | go | func (r *rule) resolveCIDRPolicy(ctx *SearchContext, state *traceState, result *CIDRPolicy) *CIDRPolicy {
// Don't select rule if it doesn't apply to the given context.
if !ctx.rulesSelect {
if !r.EndpointSelector.Matches(ctx.To) {
state.unSelectRule(ctx, ctx.To, r)
return nil
}
}
state.selectRule(ctx, r)
found := 0
for _, ingressRule := range r.Ingress {
// TODO (ianvernon): GH-1658
var allCIDRs []api.CIDR
allCIDRs = append(allCIDRs, ingressRule.FromCIDR...)
allCIDRs = append(allCIDRs, api.ComputeResultantCIDRSet(ingressRule.FromCIDRSet)...)
// CIDR + L4 rules are handled via mergeIngress(),
// skip them here.
if len(allCIDRs) > 0 && len(ingressRule.ToPorts) > 0 {
continue
}
if cnt := mergeCIDR(ctx, "Ingress", allCIDRs, r.Labels, &result.Ingress); cnt > 0 {
found += cnt
}
}
// CIDR egress policy is used for visibility of desired state in
// the API and for determining which prefix lengths are available,
// however it does not determine the actual CIDRs in the BPF maps
// for allowing traffic by CIDR!
for _, egressRule := range r.Egress {
var allCIDRs []api.CIDR
allCIDRs = append(allCIDRs, egressRule.ToCIDR...)
allCIDRs = append(allCIDRs, api.ComputeResultantCIDRSet(egressRule.ToCIDRSet)...)
// Unlike the Ingress policy which only counts L3 policy in
// this function, we count the CIDR+L4 policy in the
// desired egress CIDR policy here as well. This ensures
// proper computation of IPcache prefix lengths.
if cnt := mergeCIDR(ctx, "Egress", allCIDRs, r.Labels, &result.Egress); cnt > 0 {
found += cnt
}
}
if found > 0 {
return result
}
ctx.PolicyTrace(" No L3 rules\n")
return nil
} | [
"func",
"(",
"r",
"*",
"rule",
")",
"resolveCIDRPolicy",
"(",
"ctx",
"*",
"SearchContext",
",",
"state",
"*",
"traceState",
",",
"result",
"*",
"CIDRPolicy",
")",
"*",
"CIDRPolicy",
"{",
"// Don't select rule if it doesn't apply to the given context.",
"if",
"!",
"ctx",
".",
"rulesSelect",
"{",
"if",
"!",
"r",
".",
"EndpointSelector",
".",
"Matches",
"(",
"ctx",
".",
"To",
")",
"{",
"state",
".",
"unSelectRule",
"(",
"ctx",
",",
"ctx",
".",
"To",
",",
"r",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"state",
".",
"selectRule",
"(",
"ctx",
",",
"r",
")",
"\n",
"found",
":=",
"0",
"\n\n",
"for",
"_",
",",
"ingressRule",
":=",
"range",
"r",
".",
"Ingress",
"{",
"// TODO (ianvernon): GH-1658",
"var",
"allCIDRs",
"[",
"]",
"api",
".",
"CIDR",
"\n",
"allCIDRs",
"=",
"append",
"(",
"allCIDRs",
",",
"ingressRule",
".",
"FromCIDR",
"...",
")",
"\n",
"allCIDRs",
"=",
"append",
"(",
"allCIDRs",
",",
"api",
".",
"ComputeResultantCIDRSet",
"(",
"ingressRule",
".",
"FromCIDRSet",
")",
"...",
")",
"\n\n",
"// CIDR + L4 rules are handled via mergeIngress(),",
"// skip them here.",
"if",
"len",
"(",
"allCIDRs",
")",
">",
"0",
"&&",
"len",
"(",
"ingressRule",
".",
"ToPorts",
")",
">",
"0",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"cnt",
":=",
"mergeCIDR",
"(",
"ctx",
",",
"\"",
"\"",
",",
"allCIDRs",
",",
"r",
".",
"Labels",
",",
"&",
"result",
".",
"Ingress",
")",
";",
"cnt",
">",
"0",
"{",
"found",
"+=",
"cnt",
"\n",
"}",
"\n",
"}",
"\n\n",
"// CIDR egress policy is used for visibility of desired state in",
"// the API and for determining which prefix lengths are available,",
"// however it does not determine the actual CIDRs in the BPF maps",
"// for allowing traffic by CIDR!",
"for",
"_",
",",
"egressRule",
":=",
"range",
"r",
".",
"Egress",
"{",
"var",
"allCIDRs",
"[",
"]",
"api",
".",
"CIDR",
"\n",
"allCIDRs",
"=",
"append",
"(",
"allCIDRs",
",",
"egressRule",
".",
"ToCIDR",
"...",
")",
"\n",
"allCIDRs",
"=",
"append",
"(",
"allCIDRs",
",",
"api",
".",
"ComputeResultantCIDRSet",
"(",
"egressRule",
".",
"ToCIDRSet",
")",
"...",
")",
"\n\n",
"// Unlike the Ingress policy which only counts L3 policy in",
"// this function, we count the CIDR+L4 policy in the",
"// desired egress CIDR policy here as well. This ensures",
"// proper computation of IPcache prefix lengths.",
"if",
"cnt",
":=",
"mergeCIDR",
"(",
"ctx",
",",
"\"",
"\"",
",",
"allCIDRs",
",",
"r",
".",
"Labels",
",",
"&",
"result",
".",
"Egress",
")",
";",
"cnt",
">",
"0",
"{",
"found",
"+=",
"cnt",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"found",
">",
"0",
"{",
"return",
"result",
"\n",
"}",
"\n\n",
"ctx",
".",
"PolicyTrace",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // resolveCIDRPolicy inserts the CIDRs from the specified rule into result if
// the rule corresponds to the current SearchContext. It returns the resultant
// CIDRPolicy containing the added ingress and egress CIDRs. If no CIDRs are
// added to result, a nil CIDRPolicy is returned. | [
"resolveCIDRPolicy",
"inserts",
"the",
"CIDRs",
"from",
"the",
"specified",
"rule",
"into",
"result",
"if",
"the",
"rule",
"corresponds",
"to",
"the",
"current",
"SearchContext",
".",
"It",
"returns",
"the",
"resultant",
"CIDRPolicy",
"containing",
"the",
"added",
"ingress",
"and",
"egress",
"CIDRs",
".",
"If",
"no",
"CIDRs",
"are",
"added",
"to",
"result",
"a",
"nil",
"CIDRPolicy",
"is",
"returned",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/rule.go#L407-L460 |
162,541 | cilium/cilium | pkg/policy/rule.go | canReachIngress | func (r *rule) canReachIngress(ctx *SearchContext, state *traceState) api.Decision {
if !ctx.rulesSelect {
if !r.EndpointSelector.Matches(ctx.To) {
state.unSelectRule(ctx, ctx.To, r)
return api.Undecided
}
}
state.selectRule(ctx, r)
// If a requirement explicitly denies access, we can return.
if r.meetsRequirementsIngress(ctx, state) == api.Denied {
return api.Denied
}
return r.canReachFromEndpoints(ctx, state)
} | go | func (r *rule) canReachIngress(ctx *SearchContext, state *traceState) api.Decision {
if !ctx.rulesSelect {
if !r.EndpointSelector.Matches(ctx.To) {
state.unSelectRule(ctx, ctx.To, r)
return api.Undecided
}
}
state.selectRule(ctx, r)
// If a requirement explicitly denies access, we can return.
if r.meetsRequirementsIngress(ctx, state) == api.Denied {
return api.Denied
}
return r.canReachFromEndpoints(ctx, state)
} | [
"func",
"(",
"r",
"*",
"rule",
")",
"canReachIngress",
"(",
"ctx",
"*",
"SearchContext",
",",
"state",
"*",
"traceState",
")",
"api",
".",
"Decision",
"{",
"if",
"!",
"ctx",
".",
"rulesSelect",
"{",
"if",
"!",
"r",
".",
"EndpointSelector",
".",
"Matches",
"(",
"ctx",
".",
"To",
")",
"{",
"state",
".",
"unSelectRule",
"(",
"ctx",
",",
"ctx",
".",
"To",
",",
"r",
")",
"\n",
"return",
"api",
".",
"Undecided",
"\n",
"}",
"\n",
"}",
"\n\n",
"state",
".",
"selectRule",
"(",
"ctx",
",",
"r",
")",
"\n\n",
"// If a requirement explicitly denies access, we can return.",
"if",
"r",
".",
"meetsRequirementsIngress",
"(",
"ctx",
",",
"state",
")",
"==",
"api",
".",
"Denied",
"{",
"return",
"api",
".",
"Denied",
"\n",
"}",
"\n\n",
"return",
"r",
".",
"canReachFromEndpoints",
"(",
"ctx",
",",
"state",
")",
"\n",
"}"
] | // canReachIngress returns the decision as to whether the set of labels specified
// in ctx.From match with the label selectors specified in the ingress rules
// contained within r. | [
"canReachIngress",
"returns",
"the",
"decision",
"as",
"to",
"whether",
"the",
"set",
"of",
"labels",
"specified",
"in",
"ctx",
".",
"From",
"match",
"with",
"the",
"label",
"selectors",
"specified",
"in",
"the",
"ingress",
"rules",
"contained",
"within",
"r",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/rule.go#L465-L482 |
162,542 | cilium/cilium | pkg/policy/rule.go | meetsRequirementsIngress | func (r *rule) meetsRequirementsIngress(ctx *SearchContext, state *traceState) api.Decision {
for _, r := range r.Ingress {
for _, sel := range r.FromRequires {
ctx.PolicyTrace(" Requires from labels %+v", sel)
if !sel.Matches(ctx.From) {
ctx.PolicyTrace("- Labels %v not found\n", ctx.From)
state.constrainedRules++
return api.Denied
}
ctx.PolicyTrace("+ Found all required labels\n")
}
}
return api.Undecided
} | go | func (r *rule) meetsRequirementsIngress(ctx *SearchContext, state *traceState) api.Decision {
for _, r := range r.Ingress {
for _, sel := range r.FromRequires {
ctx.PolicyTrace(" Requires from labels %+v", sel)
if !sel.Matches(ctx.From) {
ctx.PolicyTrace("- Labels %v not found\n", ctx.From)
state.constrainedRules++
return api.Denied
}
ctx.PolicyTrace("+ Found all required labels\n")
}
}
return api.Undecided
} | [
"func",
"(",
"r",
"*",
"rule",
")",
"meetsRequirementsIngress",
"(",
"ctx",
"*",
"SearchContext",
",",
"state",
"*",
"traceState",
")",
"api",
".",
"Decision",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"r",
".",
"Ingress",
"{",
"for",
"_",
",",
"sel",
":=",
"range",
"r",
".",
"FromRequires",
"{",
"ctx",
".",
"PolicyTrace",
"(",
"\"",
"\"",
",",
"sel",
")",
"\n",
"if",
"!",
"sel",
".",
"Matches",
"(",
"ctx",
".",
"From",
")",
"{",
"ctx",
".",
"PolicyTrace",
"(",
"\"",
"\\n",
"\"",
",",
"ctx",
".",
"From",
")",
"\n",
"state",
".",
"constrainedRules",
"++",
"\n",
"return",
"api",
".",
"Denied",
"\n",
"}",
"\n",
"ctx",
".",
"PolicyTrace",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"api",
".",
"Undecided",
"\n",
"}"
] | // meetsRequirementsIngress returns whether the labels in ctx.From do not
// meet the requirements in the provided rule. If a rule does meet the
// requirements in the rule, that does not mean that the rule allows traffic
// from the labels in ctx.From, merely that the rule does not deny it. | [
"meetsRequirementsIngress",
"returns",
"whether",
"the",
"labels",
"in",
"ctx",
".",
"From",
"do",
"not",
"meet",
"the",
"requirements",
"in",
"the",
"provided",
"rule",
".",
"If",
"a",
"rule",
"does",
"meet",
"the",
"requirements",
"in",
"the",
"rule",
"that",
"does",
"not",
"mean",
"that",
"the",
"rule",
"allows",
"traffic",
"from",
"the",
"labels",
"in",
"ctx",
".",
"From",
"merely",
"that",
"the",
"rule",
"does",
"not",
"deny",
"it",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/rule.go#L533-L546 |
162,543 | cilium/cilium | pkg/policy/rule.go | meetsRequirementsEgress | func (r *rule) meetsRequirementsEgress(ctx *SearchContext, state *traceState) api.Decision {
for _, r := range r.Egress {
for _, sel := range r.ToRequires {
ctx.PolicyTrace(" Requires from labels %+v", sel)
if !sel.Matches(ctx.To) {
ctx.PolicyTrace("- Labels %v not found\n", ctx.To)
state.constrainedRules++
return api.Denied
}
ctx.PolicyTrace("+ Found all required labels\n")
}
}
return api.Undecided
} | go | func (r *rule) meetsRequirementsEgress(ctx *SearchContext, state *traceState) api.Decision {
for _, r := range r.Egress {
for _, sel := range r.ToRequires {
ctx.PolicyTrace(" Requires from labels %+v", sel)
if !sel.Matches(ctx.To) {
ctx.PolicyTrace("- Labels %v not found\n", ctx.To)
state.constrainedRules++
return api.Denied
}
ctx.PolicyTrace("+ Found all required labels\n")
}
}
return api.Undecided
} | [
"func",
"(",
"r",
"*",
"rule",
")",
"meetsRequirementsEgress",
"(",
"ctx",
"*",
"SearchContext",
",",
"state",
"*",
"traceState",
")",
"api",
".",
"Decision",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"r",
".",
"Egress",
"{",
"for",
"_",
",",
"sel",
":=",
"range",
"r",
".",
"ToRequires",
"{",
"ctx",
".",
"PolicyTrace",
"(",
"\"",
"\"",
",",
"sel",
")",
"\n",
"if",
"!",
"sel",
".",
"Matches",
"(",
"ctx",
".",
"To",
")",
"{",
"ctx",
".",
"PolicyTrace",
"(",
"\"",
"\\n",
"\"",
",",
"ctx",
".",
"To",
")",
"\n",
"state",
".",
"constrainedRules",
"++",
"\n",
"return",
"api",
".",
"Denied",
"\n",
"}",
"\n",
"ctx",
".",
"PolicyTrace",
"(",
"\"",
"\\n",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"api",
".",
"Undecided",
"\n",
"}"
] | // meetsRequirementsEgress returns whether the labels in ctx.To do not
// meet the requirements in the provided rule. If a rule does meet the
// requirements in the rule, that does not mean that the rule allows traffic
// from the labels in ctx.To, merely that the rule does not deny it. | [
"meetsRequirementsEgress",
"returns",
"whether",
"the",
"labels",
"in",
"ctx",
".",
"To",
"do",
"not",
"meet",
"the",
"requirements",
"in",
"the",
"provided",
"rule",
".",
"If",
"a",
"rule",
"does",
"meet",
"the",
"requirements",
"in",
"the",
"rule",
"that",
"does",
"not",
"mean",
"that",
"the",
"rule",
"allows",
"traffic",
"from",
"the",
"labels",
"in",
"ctx",
".",
"To",
"merely",
"that",
"the",
"rule",
"does",
"not",
"deny",
"it",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/rule.go#L594-L607 |
162,544 | cilium/cilium | pkg/policy/api/decision.go | String | func (d Decision) String() string {
if v, exists := decisionToString[d]; exists {
return v
}
return ""
} | go | func (d Decision) String() string {
if v, exists := decisionToString[d]; exists {
return v
}
return ""
} | [
"func",
"(",
"d",
"Decision",
")",
"String",
"(",
")",
"string",
"{",
"if",
"v",
",",
"exists",
":=",
"decisionToString",
"[",
"d",
"]",
";",
"exists",
"{",
"return",
"v",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // String returns the decision in human readable format | [
"String",
"returns",
"the",
"decision",
"in",
"human",
"readable",
"format"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/decision.go#L47-L52 |
162,545 | cilium/cilium | pkg/policy/api/decision.go | UnmarshalJSON | func (d *Decision) UnmarshalJSON(b []byte) error {
if d == nil {
d = new(Decision)
}
if len(b) <= len(`""`) {
return fmt.Errorf("invalid decision '%s'", string(b))
}
if v, exists := stringToDecision[string(b[1:len(b)-1])]; exists {
*d = v
return nil
}
return fmt.Errorf("unknown '%s' decision", string(b))
} | go | func (d *Decision) UnmarshalJSON(b []byte) error {
if d == nil {
d = new(Decision)
}
if len(b) <= len(`""`) {
return fmt.Errorf("invalid decision '%s'", string(b))
}
if v, exists := stringToDecision[string(b[1:len(b)-1])]; exists {
*d = v
return nil
}
return fmt.Errorf("unknown '%s' decision", string(b))
} | [
"func",
"(",
"d",
"*",
"Decision",
")",
"UnmarshalJSON",
"(",
"b",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"d",
"==",
"nil",
"{",
"d",
"=",
"new",
"(",
"Decision",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"b",
")",
"<=",
"len",
"(",
"`\"\"`",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"string",
"(",
"b",
")",
")",
"\n",
"}",
"\n",
"if",
"v",
",",
"exists",
":=",
"stringToDecision",
"[",
"string",
"(",
"b",
"[",
"1",
":",
"len",
"(",
"b",
")",
"-",
"1",
"]",
")",
"]",
";",
"exists",
"{",
"*",
"d",
"=",
"v",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"string",
"(",
"b",
")",
")",
"\n",
"}"
] | // UnmarshalJSON parses a JSON formatted buffer and returns a decision | [
"UnmarshalJSON",
"parses",
"a",
"JSON",
"formatted",
"buffer",
"and",
"returns",
"a",
"decision"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/decision.go#L55-L68 |
162,546 | cilium/cilium | pkg/policy/api/decision.go | MarshalJSON | func (d Decision) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, d)), nil
} | go | func (d Decision) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, d)), nil
} | [
"func",
"(",
"d",
"Decision",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"`\"%s\"`",
",",
"d",
")",
")",
",",
"nil",
"\n",
"}"
] | // MarshalJSON returns the decision as JSON formatted buffer | [
"MarshalJSON",
"returns",
"the",
"decision",
"as",
"JSON",
"formatted",
"buffer"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/api/decision.go#L71-L73 |
162,547 | cilium/cilium | pkg/fqdn/dnsproxy/udp.go | SetSocketOptions | func (f *sessionUDPFactory) SetSocketOptions(conn *net.UDPConn) error {
// Set up the raw socket for sending responses.
// - Must use a raw UDP socket for sending responses so that we can send
// from a specific port without binding to it.
// - The raw UDP socket must be bound to a specific IP address to prevent
// it receiving ALL UDP packets on the host.
// - We use oob data to override the source IP address when sending
// - Must use separate sockets for IPv4/IPv6, as sending to a v6-mapped
// v4 address from a socket bound to "::1" does not work due to kernel
// checking that a route exists from the source address before
// the source address is replaced with the (transparently) changed one
udpOnce.Do(func() {
rawconn4 = bindUDP("127.0.0.1") // raw socket for sending IPv4
rawconn6 = bindUDP("::1") // raw socket for sending IPv6
})
if rawconn4 == nil || rawconn6 == nil {
return fmt.Errorf("Unable to open raw UDP sockets for DNS Proxy")
}
return nil
} | go | func (f *sessionUDPFactory) SetSocketOptions(conn *net.UDPConn) error {
// Set up the raw socket for sending responses.
// - Must use a raw UDP socket for sending responses so that we can send
// from a specific port without binding to it.
// - The raw UDP socket must be bound to a specific IP address to prevent
// it receiving ALL UDP packets on the host.
// - We use oob data to override the source IP address when sending
// - Must use separate sockets for IPv4/IPv6, as sending to a v6-mapped
// v4 address from a socket bound to "::1" does not work due to kernel
// checking that a route exists from the source address before
// the source address is replaced with the (transparently) changed one
udpOnce.Do(func() {
rawconn4 = bindUDP("127.0.0.1") // raw socket for sending IPv4
rawconn6 = bindUDP("::1") // raw socket for sending IPv6
})
if rawconn4 == nil || rawconn6 == nil {
return fmt.Errorf("Unable to open raw UDP sockets for DNS Proxy")
}
return nil
} | [
"func",
"(",
"f",
"*",
"sessionUDPFactory",
")",
"SetSocketOptions",
"(",
"conn",
"*",
"net",
".",
"UDPConn",
")",
"error",
"{",
"// Set up the raw socket for sending responses.",
"// - Must use a raw UDP socket for sending responses so that we can send",
"// from a specific port without binding to it.",
"// - The raw UDP socket must be bound to a specific IP address to prevent",
"// it receiving ALL UDP packets on the host.",
"// - We use oob data to override the source IP address when sending",
"// - Must use separate sockets for IPv4/IPv6, as sending to a v6-mapped",
"// v4 address from a socket bound to \"::1\" does not work due to kernel",
"// checking that a route exists from the source address before",
"// the source address is replaced with the (transparently) changed one",
"udpOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"rawconn4",
"=",
"bindUDP",
"(",
"\"",
"\"",
")",
"// raw socket for sending IPv4",
"\n",
"rawconn6",
"=",
"bindUDP",
"(",
"\"",
"\"",
")",
"// raw socket for sending IPv6",
"\n",
"}",
")",
"\n",
"if",
"rawconn4",
"==",
"nil",
"||",
"rawconn6",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetSocketOptions set's up 'conn' to be used with a SessionUDP. | [
"SetSocketOptions",
"set",
"s",
"up",
"conn",
"to",
"be",
"used",
"with",
"a",
"SessionUDP",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/fqdn/dnsproxy/udp.go#L117-L136 |
162,548 | cilium/cilium | pkg/fqdn/dnsproxy/udp.go | InitPool | func (f *sessionUDPFactory) InitPool(msgSize int) {
f.udpPool.New = func() interface{} {
return &sessionUDP{
f: f,
m: make([]byte, msgSize),
oob: make([]byte, udpOOBSize),
}
}
} | go | func (f *sessionUDPFactory) InitPool(msgSize int) {
f.udpPool.New = func() interface{} {
return &sessionUDP{
f: f,
m: make([]byte, msgSize),
oob: make([]byte, udpOOBSize),
}
}
} | [
"func",
"(",
"f",
"*",
"sessionUDPFactory",
")",
"InitPool",
"(",
"msgSize",
"int",
")",
"{",
"f",
".",
"udpPool",
".",
"New",
"=",
"func",
"(",
")",
"interface",
"{",
"}",
"{",
"return",
"&",
"sessionUDP",
"{",
"f",
":",
"f",
",",
"m",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"msgSize",
")",
",",
"oob",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"udpOOBSize",
")",
",",
"}",
"\n",
"}",
"\n",
"}"
] | // InitPool initializes a pool of buffers to be used with SessionUDP. | [
"InitPool",
"initializes",
"a",
"pool",
"of",
"buffers",
"to",
"be",
"used",
"with",
"SessionUDP",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/fqdn/dnsproxy/udp.go#L139-L147 |
162,549 | cilium/cilium | pkg/fqdn/dnsproxy/udp.go | ReadRequest | func (f *sessionUDPFactory) ReadRequest(conn *net.UDPConn) ([]byte, dns.SessionUDP, error) {
s := f.udpPool.Get().(*sessionUDP)
n, oobn, _, raddr, err := conn.ReadMsgUDP(s.m, s.oob)
if err != nil {
s.Discard()
return nil, nil, err
}
s.conn = conn
s.raddr = raddr
s.m = s.m[:n] // Re-slice to the actual size
s.oob = s.oob[:oobn] // Re-slice to the actual size
s.laddr, err = parseDstFromOOB(s.oob)
if err != nil {
s.Discard()
return nil, nil, err
}
return s.m, s, err
} | go | func (f *sessionUDPFactory) ReadRequest(conn *net.UDPConn) ([]byte, dns.SessionUDP, error) {
s := f.udpPool.Get().(*sessionUDP)
n, oobn, _, raddr, err := conn.ReadMsgUDP(s.m, s.oob)
if err != nil {
s.Discard()
return nil, nil, err
}
s.conn = conn
s.raddr = raddr
s.m = s.m[:n] // Re-slice to the actual size
s.oob = s.oob[:oobn] // Re-slice to the actual size
s.laddr, err = parseDstFromOOB(s.oob)
if err != nil {
s.Discard()
return nil, nil, err
}
return s.m, s, err
} | [
"func",
"(",
"f",
"*",
"sessionUDPFactory",
")",
"ReadRequest",
"(",
"conn",
"*",
"net",
".",
"UDPConn",
")",
"(",
"[",
"]",
"byte",
",",
"dns",
".",
"SessionUDP",
",",
"error",
")",
"{",
"s",
":=",
"f",
".",
"udpPool",
".",
"Get",
"(",
")",
".",
"(",
"*",
"sessionUDP",
")",
"\n",
"n",
",",
"oobn",
",",
"_",
",",
"raddr",
",",
"err",
":=",
"conn",
".",
"ReadMsgUDP",
"(",
"s",
".",
"m",
",",
"s",
".",
"oob",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"s",
".",
"Discard",
"(",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"s",
".",
"conn",
"=",
"conn",
"\n",
"s",
".",
"raddr",
"=",
"raddr",
"\n",
"s",
".",
"m",
"=",
"s",
".",
"m",
"[",
":",
"n",
"]",
"// Re-slice to the actual size",
"\n",
"s",
".",
"oob",
"=",
"s",
".",
"oob",
"[",
":",
"oobn",
"]",
"// Re-slice to the actual size",
"\n",
"s",
".",
"laddr",
",",
"err",
"=",
"parseDstFromOOB",
"(",
"s",
".",
"oob",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"s",
".",
"Discard",
"(",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"s",
".",
"m",
",",
"s",
",",
"err",
"\n",
"}"
] | // ReadRequest reads a single request from 'conn' and returns the request context | [
"ReadRequest",
"reads",
"a",
"single",
"request",
"from",
"conn",
"and",
"returns",
"the",
"request",
"context"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/fqdn/dnsproxy/udp.go#L150-L167 |
162,550 | cilium/cilium | pkg/fqdn/dnsproxy/udp.go | Discard | func (s *sessionUDP) Discard() {
s.conn = nil
s.raddr = nil
s.laddr = nil
s.m = s.m[:cap(s.m)]
s.oob = s.oob[:cap(s.oob)]
s.f.udpPool.Put(s)
} | go | func (s *sessionUDP) Discard() {
s.conn = nil
s.raddr = nil
s.laddr = nil
s.m = s.m[:cap(s.m)]
s.oob = s.oob[:cap(s.oob)]
s.f.udpPool.Put(s)
} | [
"func",
"(",
"s",
"*",
"sessionUDP",
")",
"Discard",
"(",
")",
"{",
"s",
".",
"conn",
"=",
"nil",
"\n",
"s",
".",
"raddr",
"=",
"nil",
"\n",
"s",
".",
"laddr",
"=",
"nil",
"\n",
"s",
".",
"m",
"=",
"s",
".",
"m",
"[",
":",
"cap",
"(",
"s",
".",
"m",
")",
"]",
"\n",
"s",
".",
"oob",
"=",
"s",
".",
"oob",
"[",
":",
"cap",
"(",
"s",
".",
"oob",
")",
"]",
"\n\n",
"s",
".",
"f",
".",
"udpPool",
".",
"Put",
"(",
"s",
")",
"\n",
"}"
] | // Discard returns 's' to the factory pool | [
"Discard",
"returns",
"s",
"to",
"the",
"factory",
"pool"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/fqdn/dnsproxy/udp.go#L170-L178 |
162,551 | cilium/cilium | pkg/fqdn/dnsproxy/udp.go | WriteResponse | func (s *sessionUDP) WriteResponse(b []byte) (int, error) {
// Must give the UDP header to get the source port right.
// Reuse the msg buffer, figure out if golang can do gatter-scather IO
// with raw sockets?
bb := bytes.NewBuffer(s.m[:0])
binary.Write(bb, binary.BigEndian, uint16(s.laddr.Port))
binary.Write(bb, binary.BigEndian, uint16(s.raddr.Port))
binary.Write(bb, binary.BigEndian, uint16(8+len(b)))
binary.Write(bb, binary.BigEndian, uint16(0)) // checksum
bb.Write(b)
buf := bb.Bytes()
var n int
var err error
dst := net.IPAddr{
IP: s.raddr.IP,
}
if s.raddr.IP.To4() == nil {
n, _, err = rawconn6.WriteMsgIP(buf, s.controlMessage(s.laddr), &dst)
} else {
n, _, err = rawconn4.WriteMsgIP(buf, s.controlMessage(s.laddr), &dst)
}
if err != nil {
log.Warningf("WriteMsgIP: %s", err)
} else {
log.Debugf("WriteMsgIP: wrote %d bytes", n)
}
return n, err
} | go | func (s *sessionUDP) WriteResponse(b []byte) (int, error) {
// Must give the UDP header to get the source port right.
// Reuse the msg buffer, figure out if golang can do gatter-scather IO
// with raw sockets?
bb := bytes.NewBuffer(s.m[:0])
binary.Write(bb, binary.BigEndian, uint16(s.laddr.Port))
binary.Write(bb, binary.BigEndian, uint16(s.raddr.Port))
binary.Write(bb, binary.BigEndian, uint16(8+len(b)))
binary.Write(bb, binary.BigEndian, uint16(0)) // checksum
bb.Write(b)
buf := bb.Bytes()
var n int
var err error
dst := net.IPAddr{
IP: s.raddr.IP,
}
if s.raddr.IP.To4() == nil {
n, _, err = rawconn6.WriteMsgIP(buf, s.controlMessage(s.laddr), &dst)
} else {
n, _, err = rawconn4.WriteMsgIP(buf, s.controlMessage(s.laddr), &dst)
}
if err != nil {
log.Warningf("WriteMsgIP: %s", err)
} else {
log.Debugf("WriteMsgIP: wrote %d bytes", n)
}
return n, err
} | [
"func",
"(",
"s",
"*",
"sessionUDP",
")",
"WriteResponse",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"// Must give the UDP header to get the source port right.",
"// Reuse the msg buffer, figure out if golang can do gatter-scather IO",
"// with raw sockets?",
"bb",
":=",
"bytes",
".",
"NewBuffer",
"(",
"s",
".",
"m",
"[",
":",
"0",
"]",
")",
"\n",
"binary",
".",
"Write",
"(",
"bb",
",",
"binary",
".",
"BigEndian",
",",
"uint16",
"(",
"s",
".",
"laddr",
".",
"Port",
")",
")",
"\n",
"binary",
".",
"Write",
"(",
"bb",
",",
"binary",
".",
"BigEndian",
",",
"uint16",
"(",
"s",
".",
"raddr",
".",
"Port",
")",
")",
"\n",
"binary",
".",
"Write",
"(",
"bb",
",",
"binary",
".",
"BigEndian",
",",
"uint16",
"(",
"8",
"+",
"len",
"(",
"b",
")",
")",
")",
"\n",
"binary",
".",
"Write",
"(",
"bb",
",",
"binary",
".",
"BigEndian",
",",
"uint16",
"(",
"0",
")",
")",
"// checksum",
"\n",
"bb",
".",
"Write",
"(",
"b",
")",
"\n",
"buf",
":=",
"bb",
".",
"Bytes",
"(",
")",
"\n\n",
"var",
"n",
"int",
"\n",
"var",
"err",
"error",
"\n",
"dst",
":=",
"net",
".",
"IPAddr",
"{",
"IP",
":",
"s",
".",
"raddr",
".",
"IP",
",",
"}",
"\n",
"if",
"s",
".",
"raddr",
".",
"IP",
".",
"To4",
"(",
")",
"==",
"nil",
"{",
"n",
",",
"_",
",",
"err",
"=",
"rawconn6",
".",
"WriteMsgIP",
"(",
"buf",
",",
"s",
".",
"controlMessage",
"(",
"s",
".",
"laddr",
")",
",",
"&",
"dst",
")",
"\n",
"}",
"else",
"{",
"n",
",",
"_",
",",
"err",
"=",
"rawconn4",
".",
"WriteMsgIP",
"(",
"buf",
",",
"s",
".",
"controlMessage",
"(",
"s",
".",
"laddr",
")",
",",
"&",
"dst",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"n",
")",
"\n",
"}",
"\n",
"return",
"n",
",",
"err",
"\n",
"}"
] | // WriteResponse writes a response to a request received earlier | [
"WriteResponse",
"writes",
"a",
"response",
"to",
"a",
"request",
"received",
"earlier"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/fqdn/dnsproxy/udp.go#L187-L215 |
162,552 | cilium/cilium | pkg/fqdn/dnsproxy/udp.go | parseDstFromOOB | func parseDstFromOOB(oob []byte) (*net.UDPAddr, error) {
msgs, err := syscall.ParseSocketControlMessage(oob)
if err != nil {
return nil, fmt.Errorf("parsing socket control message: %s", err)
}
for _, msg := range msgs {
if msg.Header.Level == unix.SOL_IP && msg.Header.Type == unix.IP_ORIGDSTADDR {
pp := &syscall.RawSockaddrInet4{}
// Address family is in native byte order
family := *(*uint16)(unsafe.Pointer(&msg.Data[unsafe.Offsetof(pp.Family)]))
if family != unix.AF_INET {
return nil, fmt.Errorf("original destination is not IPv4.")
}
// Port is in big-endian byte order
if err = binary.Read(bytes.NewReader(msg.Data), binary.BigEndian, pp); err != nil {
return nil, fmt.Errorf("reading original destination address: %s", err)
}
laddr := &net.UDPAddr{
IP: net.IPv4(pp.Addr[0], pp.Addr[1], pp.Addr[2], pp.Addr[3]),
Port: int(pp.Port),
}
return laddr, nil
}
if msg.Header.Level == unix.SOL_IPV6 && msg.Header.Type == unix.IPV6_ORIGDSTADDR {
pp := &syscall.RawSockaddrInet6{}
// Address family is in native byte order
family := *(*uint16)(unsafe.Pointer(&msg.Data[unsafe.Offsetof(pp.Family)]))
if family != unix.AF_INET6 {
return nil, fmt.Errorf("original destination is not IPv6.")
}
// Scope ID is in native byte order
scopeId := *(*uint32)(unsafe.Pointer(&msg.Data[unsafe.Offsetof(pp.Scope_id)]))
// Rest of the data is big-endian (port)
if err = binary.Read(bytes.NewReader(msg.Data), binary.BigEndian, pp); err != nil {
return nil, fmt.Errorf("reading original destination address: %s", err)
}
laddr := &net.UDPAddr{
IP: net.IP(pp.Addr[:]),
Port: int(pp.Port),
Zone: strconv.Itoa(int(scopeId)),
}
return laddr, nil
}
}
return nil, fmt.Errorf("No original destination found!")
} | go | func parseDstFromOOB(oob []byte) (*net.UDPAddr, error) {
msgs, err := syscall.ParseSocketControlMessage(oob)
if err != nil {
return nil, fmt.Errorf("parsing socket control message: %s", err)
}
for _, msg := range msgs {
if msg.Header.Level == unix.SOL_IP && msg.Header.Type == unix.IP_ORIGDSTADDR {
pp := &syscall.RawSockaddrInet4{}
// Address family is in native byte order
family := *(*uint16)(unsafe.Pointer(&msg.Data[unsafe.Offsetof(pp.Family)]))
if family != unix.AF_INET {
return nil, fmt.Errorf("original destination is not IPv4.")
}
// Port is in big-endian byte order
if err = binary.Read(bytes.NewReader(msg.Data), binary.BigEndian, pp); err != nil {
return nil, fmt.Errorf("reading original destination address: %s", err)
}
laddr := &net.UDPAddr{
IP: net.IPv4(pp.Addr[0], pp.Addr[1], pp.Addr[2], pp.Addr[3]),
Port: int(pp.Port),
}
return laddr, nil
}
if msg.Header.Level == unix.SOL_IPV6 && msg.Header.Type == unix.IPV6_ORIGDSTADDR {
pp := &syscall.RawSockaddrInet6{}
// Address family is in native byte order
family := *(*uint16)(unsafe.Pointer(&msg.Data[unsafe.Offsetof(pp.Family)]))
if family != unix.AF_INET6 {
return nil, fmt.Errorf("original destination is not IPv6.")
}
// Scope ID is in native byte order
scopeId := *(*uint32)(unsafe.Pointer(&msg.Data[unsafe.Offsetof(pp.Scope_id)]))
// Rest of the data is big-endian (port)
if err = binary.Read(bytes.NewReader(msg.Data), binary.BigEndian, pp); err != nil {
return nil, fmt.Errorf("reading original destination address: %s", err)
}
laddr := &net.UDPAddr{
IP: net.IP(pp.Addr[:]),
Port: int(pp.Port),
Zone: strconv.Itoa(int(scopeId)),
}
return laddr, nil
}
}
return nil, fmt.Errorf("No original destination found!")
} | [
"func",
"parseDstFromOOB",
"(",
"oob",
"[",
"]",
"byte",
")",
"(",
"*",
"net",
".",
"UDPAddr",
",",
"error",
")",
"{",
"msgs",
",",
"err",
":=",
"syscall",
".",
"ParseSocketControlMessage",
"(",
"oob",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"msg",
":=",
"range",
"msgs",
"{",
"if",
"msg",
".",
"Header",
".",
"Level",
"==",
"unix",
".",
"SOL_IP",
"&&",
"msg",
".",
"Header",
".",
"Type",
"==",
"unix",
".",
"IP_ORIGDSTADDR",
"{",
"pp",
":=",
"&",
"syscall",
".",
"RawSockaddrInet4",
"{",
"}",
"\n",
"// Address family is in native byte order",
"family",
":=",
"*",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"msg",
".",
"Data",
"[",
"unsafe",
".",
"Offsetof",
"(",
"pp",
".",
"Family",
")",
"]",
")",
")",
"\n",
"if",
"family",
"!=",
"unix",
".",
"AF_INET",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Port is in big-endian byte order",
"if",
"err",
"=",
"binary",
".",
"Read",
"(",
"bytes",
".",
"NewReader",
"(",
"msg",
".",
"Data",
")",
",",
"binary",
".",
"BigEndian",
",",
"pp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"laddr",
":=",
"&",
"net",
".",
"UDPAddr",
"{",
"IP",
":",
"net",
".",
"IPv4",
"(",
"pp",
".",
"Addr",
"[",
"0",
"]",
",",
"pp",
".",
"Addr",
"[",
"1",
"]",
",",
"pp",
".",
"Addr",
"[",
"2",
"]",
",",
"pp",
".",
"Addr",
"[",
"3",
"]",
")",
",",
"Port",
":",
"int",
"(",
"pp",
".",
"Port",
")",
",",
"}",
"\n",
"return",
"laddr",
",",
"nil",
"\n",
"}",
"\n",
"if",
"msg",
".",
"Header",
".",
"Level",
"==",
"unix",
".",
"SOL_IPV6",
"&&",
"msg",
".",
"Header",
".",
"Type",
"==",
"unix",
".",
"IPV6_ORIGDSTADDR",
"{",
"pp",
":=",
"&",
"syscall",
".",
"RawSockaddrInet6",
"{",
"}",
"\n",
"// Address family is in native byte order",
"family",
":=",
"*",
"(",
"*",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"msg",
".",
"Data",
"[",
"unsafe",
".",
"Offsetof",
"(",
"pp",
".",
"Family",
")",
"]",
")",
")",
"\n",
"if",
"family",
"!=",
"unix",
".",
"AF_INET6",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Scope ID is in native byte order",
"scopeId",
":=",
"*",
"(",
"*",
"uint32",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"msg",
".",
"Data",
"[",
"unsafe",
".",
"Offsetof",
"(",
"pp",
".",
"Scope_id",
")",
"]",
")",
")",
"\n",
"// Rest of the data is big-endian (port)",
"if",
"err",
"=",
"binary",
".",
"Read",
"(",
"bytes",
".",
"NewReader",
"(",
"msg",
".",
"Data",
")",
",",
"binary",
".",
"BigEndian",
",",
"pp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"laddr",
":=",
"&",
"net",
".",
"UDPAddr",
"{",
"IP",
":",
"net",
".",
"IP",
"(",
"pp",
".",
"Addr",
"[",
":",
"]",
")",
",",
"Port",
":",
"int",
"(",
"pp",
".",
"Port",
")",
",",
"Zone",
":",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"scopeId",
")",
")",
",",
"}",
"\n",
"return",
"laddr",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // parseDstFromOOB takes oob data and returns the destination IP. | [
"parseDstFromOOB",
"takes",
"oob",
"data",
"and",
"returns",
"the",
"destination",
"IP",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/fqdn/dnsproxy/udp.go#L218-L264 |
162,553 | cilium/cilium | pkg/fqdn/dnsproxy/udp.go | controlMessage | func (s *sessionUDP) controlMessage(src *net.UDPAddr) []byte {
// If the src is definitely an IPv6, then use ipv6's ControlMessage to
// respond otherwise use ipv4's because ipv6's marshal ignores ipv4
// addresses.
if src.IP.To4() == nil {
cm := new(ipv6.ControlMessage)
cm.Src = src.IP
return cm.Marshal()
}
cm := new(ipv4.ControlMessage)
cm.Src = src.IP
return cm.Marshal()
} | go | func (s *sessionUDP) controlMessage(src *net.UDPAddr) []byte {
// If the src is definitely an IPv6, then use ipv6's ControlMessage to
// respond otherwise use ipv4's because ipv6's marshal ignores ipv4
// addresses.
if src.IP.To4() == nil {
cm := new(ipv6.ControlMessage)
cm.Src = src.IP
return cm.Marshal()
}
cm := new(ipv4.ControlMessage)
cm.Src = src.IP
return cm.Marshal()
} | [
"func",
"(",
"s",
"*",
"sessionUDP",
")",
"controlMessage",
"(",
"src",
"*",
"net",
".",
"UDPAddr",
")",
"[",
"]",
"byte",
"{",
"// If the src is definitely an IPv6, then use ipv6's ControlMessage to",
"// respond otherwise use ipv4's because ipv6's marshal ignores ipv4",
"// addresses.",
"if",
"src",
".",
"IP",
".",
"To4",
"(",
")",
"==",
"nil",
"{",
"cm",
":=",
"new",
"(",
"ipv6",
".",
"ControlMessage",
")",
"\n",
"cm",
".",
"Src",
"=",
"src",
".",
"IP",
"\n",
"return",
"cm",
".",
"Marshal",
"(",
")",
"\n",
"}",
"\n",
"cm",
":=",
"new",
"(",
"ipv4",
".",
"ControlMessage",
")",
"\n",
"cm",
".",
"Src",
"=",
"src",
".",
"IP",
"\n",
"return",
"cm",
".",
"Marshal",
"(",
")",
"\n",
"}"
] | // correctSource returns the oob data with the given source address | [
"correctSource",
"returns",
"the",
"oob",
"data",
"with",
"the",
"given",
"source",
"address"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/fqdn/dnsproxy/udp.go#L267-L279 |
162,554 | cilium/cilium | pkg/policy/proxyid.go | ParseProxyID | func ParseProxyID(proxyID string) (endpointID uint16, ingress bool, protocol string, port uint16, err error) {
comps := strings.Split(proxyID, ":")
if len(comps) != 4 {
err = fmt.Errorf("invalid proxy ID structure: %s", proxyID)
return
}
epID, err := strconv.ParseUint(comps[0], 10, 16)
if err != nil {
return
}
endpointID = uint16(epID)
ingress = comps[1] == "ingress"
protocol = comps[2]
l4port, err := strconv.ParseUint(comps[3], 10, 16)
if err != nil {
return
}
port = uint16(l4port)
return
} | go | func ParseProxyID(proxyID string) (endpointID uint16, ingress bool, protocol string, port uint16, err error) {
comps := strings.Split(proxyID, ":")
if len(comps) != 4 {
err = fmt.Errorf("invalid proxy ID structure: %s", proxyID)
return
}
epID, err := strconv.ParseUint(comps[0], 10, 16)
if err != nil {
return
}
endpointID = uint16(epID)
ingress = comps[1] == "ingress"
protocol = comps[2]
l4port, err := strconv.ParseUint(comps[3], 10, 16)
if err != nil {
return
}
port = uint16(l4port)
return
} | [
"func",
"ParseProxyID",
"(",
"proxyID",
"string",
")",
"(",
"endpointID",
"uint16",
",",
"ingress",
"bool",
",",
"protocol",
"string",
",",
"port",
"uint16",
",",
"err",
"error",
")",
"{",
"comps",
":=",
"strings",
".",
"Split",
"(",
"proxyID",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"comps",
")",
"!=",
"4",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"proxyID",
")",
"\n",
"return",
"\n",
"}",
"\n",
"epID",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"comps",
"[",
"0",
"]",
",",
"10",
",",
"16",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"endpointID",
"=",
"uint16",
"(",
"epID",
")",
"\n",
"ingress",
"=",
"comps",
"[",
"1",
"]",
"==",
"\"",
"\"",
"\n",
"protocol",
"=",
"comps",
"[",
"2",
"]",
"\n",
"l4port",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"comps",
"[",
"3",
"]",
",",
"10",
",",
"16",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"port",
"=",
"uint16",
"(",
"l4port",
")",
"\n",
"return",
"\n",
"}"
] | // ParseProxyID parses a proxy ID returned by ProxyID and returns its components. | [
"ParseProxyID",
"parses",
"a",
"proxy",
"ID",
"returned",
"by",
"ProxyID",
"and",
"returns",
"its",
"components",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/policy/proxyid.go#L33-L52 |
162,555 | cilium/cilium | pkg/endpoint/status.go | contains | func (ps componentStatus) contains(s *statusLogMsg) bool {
return ps[s.Status.Type] == s
} | go | func (ps componentStatus) contains(s *statusLogMsg) bool {
return ps[s.Status.Type] == s
} | [
"func",
"(",
"ps",
"componentStatus",
")",
"contains",
"(",
"s",
"*",
"statusLogMsg",
")",
"bool",
"{",
"return",
"ps",
"[",
"s",
".",
"Status",
".",
"Type",
"]",
"==",
"s",
"\n",
"}"
] | // contains checks if the given `s` statusLogMsg is present in the
// priorityStatus. | [
"contains",
"checks",
"if",
"the",
"given",
"s",
"statusLogMsg",
"is",
"present",
"in",
"the",
"priorityStatus",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/status.go#L114-L116 |
162,556 | cilium/cilium | pkg/endpoint/status.go | sortByPriority | func (ps componentStatus) sortByPriority() statusLog {
prs := statusTypeSlice{}
for k := range ps {
prs = append(prs, k)
}
sort.Sort(prs)
slogSorted := statusLog{}
for _, pr := range prs {
slogSorted = append(slogSorted, ps[pr])
}
return slogSorted
} | go | func (ps componentStatus) sortByPriority() statusLog {
prs := statusTypeSlice{}
for k := range ps {
prs = append(prs, k)
}
sort.Sort(prs)
slogSorted := statusLog{}
for _, pr := range prs {
slogSorted = append(slogSorted, ps[pr])
}
return slogSorted
} | [
"func",
"(",
"ps",
"componentStatus",
")",
"sortByPriority",
"(",
")",
"statusLog",
"{",
"prs",
":=",
"statusTypeSlice",
"{",
"}",
"\n",
"for",
"k",
":=",
"range",
"ps",
"{",
"prs",
"=",
"append",
"(",
"prs",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"prs",
")",
"\n",
"slogSorted",
":=",
"statusLog",
"{",
"}",
"\n",
"for",
"_",
",",
"pr",
":=",
"range",
"prs",
"{",
"slogSorted",
"=",
"append",
"(",
"slogSorted",
",",
"ps",
"[",
"pr",
"]",
")",
"\n",
"}",
"\n",
"return",
"slogSorted",
"\n",
"}"
] | // sortByPriority returns a statusLog ordered from highest priority to lowest. | [
"sortByPriority",
"returns",
"a",
"statusLog",
"ordered",
"from",
"highest",
"priority",
"to",
"lowest",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/status.go#L133-L144 |
162,557 | cilium/cilium | pkg/endpoint/status.go | getAndIncIdx | func (e *EndpointStatus) getAndIncIdx() int {
idx := e.Index
e.Index++
if e.Index >= maxLogs {
e.Index = 0
}
// Lets skip the CurrentStatus message from the log to prevent removing
// non-OK status!
if e.Index < len(e.Log) &&
e.CurrentStatuses.contains(e.Log[e.Index]) &&
e.Log[e.Index].Status.Code != OK {
e.Index++
if e.Index >= maxLogs {
e.Index = 0
}
}
return idx
} | go | func (e *EndpointStatus) getAndIncIdx() int {
idx := e.Index
e.Index++
if e.Index >= maxLogs {
e.Index = 0
}
// Lets skip the CurrentStatus message from the log to prevent removing
// non-OK status!
if e.Index < len(e.Log) &&
e.CurrentStatuses.contains(e.Log[e.Index]) &&
e.Log[e.Index].Status.Code != OK {
e.Index++
if e.Index >= maxLogs {
e.Index = 0
}
}
return idx
} | [
"func",
"(",
"e",
"*",
"EndpointStatus",
")",
"getAndIncIdx",
"(",
")",
"int",
"{",
"idx",
":=",
"e",
".",
"Index",
"\n",
"e",
".",
"Index",
"++",
"\n",
"if",
"e",
".",
"Index",
">=",
"maxLogs",
"{",
"e",
".",
"Index",
"=",
"0",
"\n",
"}",
"\n",
"// Lets skip the CurrentStatus message from the log to prevent removing",
"// non-OK status!",
"if",
"e",
".",
"Index",
"<",
"len",
"(",
"e",
".",
"Log",
")",
"&&",
"e",
".",
"CurrentStatuses",
".",
"contains",
"(",
"e",
".",
"Log",
"[",
"e",
".",
"Index",
"]",
")",
"&&",
"e",
".",
"Log",
"[",
"e",
".",
"Index",
"]",
".",
"Status",
".",
"Code",
"!=",
"OK",
"{",
"e",
".",
"Index",
"++",
"\n",
"if",
"e",
".",
"Index",
">=",
"maxLogs",
"{",
"e",
".",
"Index",
"=",
"0",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"idx",
"\n",
"}"
] | // getAndIncIdx returns current free slot index and increments the index to the
// next index that can be overwritten. | [
"getAndIncIdx",
"returns",
"current",
"free",
"slot",
"index",
"and",
"increments",
"the",
"index",
"to",
"the",
"next",
"index",
"that",
"can",
"be",
"overwritten",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/status.go#L176-L193 |
162,558 | cilium/cilium | api/v1/server/restapi/cilium_api.go | Context | func (o *CiliumAPI) Context() *middleware.Context {
if o.context == nil {
o.context = middleware.NewRoutableContext(o.spec, o, nil)
}
return o.context
} | go | func (o *CiliumAPI) Context() *middleware.Context {
if o.context == nil {
o.context = middleware.NewRoutableContext(o.spec, o, nil)
}
return o.context
} | [
"func",
"(",
"o",
"*",
"CiliumAPI",
")",
"Context",
"(",
")",
"*",
"middleware",
".",
"Context",
"{",
"if",
"o",
".",
"context",
"==",
"nil",
"{",
"o",
".",
"context",
"=",
"middleware",
".",
"NewRoutableContext",
"(",
"o",
".",
"spec",
",",
"o",
",",
"nil",
")",
"\n",
"}",
"\n\n",
"return",
"o",
".",
"context",
"\n",
"}"
] | // Context returns the middleware context for the cilium API | [
"Context",
"returns",
"the",
"middleware",
"context",
"for",
"the",
"cilium",
"API"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/cilium_api.go#L558-L564 |
162,559 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | UnmarshalBinary | func (meta *Meta) UnmarshalBinary(data []byte) error {
return meta.ReadBinary(bytes.NewReader(data))
} | go | func (meta *Meta) UnmarshalBinary(data []byte) error {
return meta.ReadBinary(bytes.NewReader(data))
} | [
"func",
"(",
"meta",
"*",
"Meta",
")",
"UnmarshalBinary",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"meta",
".",
"ReadBinary",
"(",
"bytes",
".",
"NewReader",
"(",
"data",
")",
")",
"\n",
"}"
] | // UnmarshalBinary decodes the metadata from its binary representation. | [
"UnmarshalBinary",
"decodes",
"the",
"metadata",
"from",
"its",
"binary",
"representation",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L42-L44 |
162,560 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | MarshalBinary | func (meta *Meta) MarshalBinary() ([]byte, error) {
var buf bytes.Buffer
if err := meta.WriteBinary(&buf); err != nil {
return nil, err
}
return buf.Bytes(), nil
} | go | func (meta *Meta) MarshalBinary() ([]byte, error) {
var buf bytes.Buffer
if err := meta.WriteBinary(&buf); err != nil {
return nil, err
}
return buf.Bytes(), nil
} | [
"func",
"(",
"meta",
"*",
"Meta",
")",
"MarshalBinary",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"if",
"err",
":=",
"meta",
".",
"WriteBinary",
"(",
"&",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] | // MarshalBinary encodes the metadata into its binary representation. | [
"MarshalBinary",
"encodes",
"the",
"metadata",
"into",
"its",
"binary",
"representation",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L47-L53 |
162,561 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | ReadBinary | func (meta *Meta) ReadBinary(r io.Reader) error {
return binary.Read(r, byteorder.Native, meta)
} | go | func (meta *Meta) ReadBinary(r io.Reader) error {
return binary.Read(r, byteorder.Native, meta)
} | [
"func",
"(",
"meta",
"*",
"Meta",
")",
"ReadBinary",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"return",
"binary",
".",
"Read",
"(",
"r",
",",
"byteorder",
".",
"Native",
",",
"meta",
")",
"\n",
"}"
] | // ReadBinary reads the metadata from its binary representation. | [
"ReadBinary",
"reads",
"the",
"metadata",
"from",
"its",
"binary",
"representation",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L56-L58 |
162,562 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | WriteBinary | func (meta *Meta) WriteBinary(w io.Writer) error {
return binary.Write(w, byteorder.Native, meta)
} | go | func (meta *Meta) WriteBinary(w io.Writer) error {
return binary.Write(w, byteorder.Native, meta)
} | [
"func",
"(",
"meta",
"*",
"Meta",
")",
"WriteBinary",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"return",
"binary",
".",
"Write",
"(",
"w",
",",
"byteorder",
".",
"Native",
",",
"meta",
")",
"\n",
"}"
] | // WriteBinary writes the metadata into its binary representation. | [
"WriteBinary",
"writes",
"the",
"metadata",
"into",
"its",
"binary",
"representation",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L61-L63 |
162,563 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | Decode | func (pl *Payload) Decode(data []byte) error {
// Note that this method can't be named UnmarshalBinary, because the gob encoder would call
// this method, resulting in infinite recursion.
return pl.ReadBinary(bytes.NewBuffer(data))
} | go | func (pl *Payload) Decode(data []byte) error {
// Note that this method can't be named UnmarshalBinary, because the gob encoder would call
// this method, resulting in infinite recursion.
return pl.ReadBinary(bytes.NewBuffer(data))
} | [
"func",
"(",
"pl",
"*",
"Payload",
")",
"Decode",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"// Note that this method can't be named UnmarshalBinary, because the gob encoder would call",
"// this method, resulting in infinite recursion.",
"return",
"pl",
".",
"ReadBinary",
"(",
"bytes",
".",
"NewBuffer",
"(",
"data",
")",
")",
"\n",
"}"
] | // Decode decodes the payload from its binary representation. | [
"Decode",
"decodes",
"the",
"payload",
"from",
"its",
"binary",
"representation",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L74-L78 |
162,564 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | Encode | func (pl *Payload) Encode() ([]byte, error) {
// Note that this method can't be named MarshalBinary, because the gob encoder would call
// this method, resulting in infinite recursion.
var buf bytes.Buffer
if err := pl.WriteBinary(&buf); err != nil {
return nil, err
}
return buf.Bytes(), nil
} | go | func (pl *Payload) Encode() ([]byte, error) {
// Note that this method can't be named MarshalBinary, because the gob encoder would call
// this method, resulting in infinite recursion.
var buf bytes.Buffer
if err := pl.WriteBinary(&buf); err != nil {
return nil, err
}
return buf.Bytes(), nil
} | [
"func",
"(",
"pl",
"*",
"Payload",
")",
"Encode",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// Note that this method can't be named MarshalBinary, because the gob encoder would call",
"// this method, resulting in infinite recursion.",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"if",
"err",
":=",
"pl",
".",
"WriteBinary",
"(",
"&",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Encode encodes the payload into its binary representation. | [
"Encode",
"encodes",
"the",
"payload",
"into",
"its",
"binary",
"representation",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L81-L89 |
162,565 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | ReadBinary | func (pl *Payload) ReadBinary(r io.Reader) error {
dec := gob.NewDecoder(r)
return pl.DecodeBinary(dec)
} | go | func (pl *Payload) ReadBinary(r io.Reader) error {
dec := gob.NewDecoder(r)
return pl.DecodeBinary(dec)
} | [
"func",
"(",
"pl",
"*",
"Payload",
")",
"ReadBinary",
"(",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"dec",
":=",
"gob",
".",
"NewDecoder",
"(",
"r",
")",
"\n",
"return",
"pl",
".",
"DecodeBinary",
"(",
"dec",
")",
"\n",
"}"
] | // ReadBinary reads the payload from its binary representation. | [
"ReadBinary",
"reads",
"the",
"payload",
"from",
"its",
"binary",
"representation",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L92-L95 |
162,566 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | WriteBinary | func (pl *Payload) WriteBinary(w io.Writer) error {
enc := gob.NewEncoder(w)
return pl.EncodeBinary(enc)
} | go | func (pl *Payload) WriteBinary(w io.Writer) error {
enc := gob.NewEncoder(w)
return pl.EncodeBinary(enc)
} | [
"func",
"(",
"pl",
"*",
"Payload",
")",
"WriteBinary",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"enc",
":=",
"gob",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"return",
"pl",
".",
"EncodeBinary",
"(",
"enc",
")",
"\n",
"}"
] | // WriteBinary writes the payload into its binary representation. | [
"WriteBinary",
"writes",
"the",
"payload",
"into",
"its",
"binary",
"representation",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L98-L101 |
162,567 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | EncodeBinary | func (pl *Payload) EncodeBinary(enc *gob.Encoder) error {
return enc.Encode(pl)
} | go | func (pl *Payload) EncodeBinary(enc *gob.Encoder) error {
return enc.Encode(pl)
} | [
"func",
"(",
"pl",
"*",
"Payload",
")",
"EncodeBinary",
"(",
"enc",
"*",
"gob",
".",
"Encoder",
")",
"error",
"{",
"return",
"enc",
".",
"Encode",
"(",
"pl",
")",
"\n",
"}"
] | // EncodeBinary writes the payload into its binary representation. | [
"EncodeBinary",
"writes",
"the",
"payload",
"into",
"its",
"binary",
"representation",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L104-L106 |
162,568 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | DecodeBinary | func (pl *Payload) DecodeBinary(dec *gob.Decoder) error {
return dec.Decode(pl)
} | go | func (pl *Payload) DecodeBinary(dec *gob.Decoder) error {
return dec.Decode(pl)
} | [
"func",
"(",
"pl",
"*",
"Payload",
")",
"DecodeBinary",
"(",
"dec",
"*",
"gob",
".",
"Decoder",
")",
"error",
"{",
"return",
"dec",
".",
"Decode",
"(",
"pl",
")",
"\n",
"}"
] | // DecodeBinary reads the payload from its binary representation. | [
"DecodeBinary",
"reads",
"the",
"payload",
"from",
"its",
"binary",
"representation",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L109-L111 |
162,569 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | ReadMetaPayload | func ReadMetaPayload(r io.Reader, meta *Meta, pl *Payload) error {
if err := meta.ReadBinary(r); err != nil {
return err
}
// Meta.Size is not necessary for framing/decoding, but is useful to validate the payload size.
return pl.ReadBinary(io.LimitReader(r, int64(meta.Size)))
} | go | func ReadMetaPayload(r io.Reader, meta *Meta, pl *Payload) error {
if err := meta.ReadBinary(r); err != nil {
return err
}
// Meta.Size is not necessary for framing/decoding, but is useful to validate the payload size.
return pl.ReadBinary(io.LimitReader(r, int64(meta.Size)))
} | [
"func",
"ReadMetaPayload",
"(",
"r",
"io",
".",
"Reader",
",",
"meta",
"*",
"Meta",
",",
"pl",
"*",
"Payload",
")",
"error",
"{",
"if",
"err",
":=",
"meta",
".",
"ReadBinary",
"(",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Meta.Size is not necessary for framing/decoding, but is useful to validate the payload size.",
"return",
"pl",
".",
"ReadBinary",
"(",
"io",
".",
"LimitReader",
"(",
"r",
",",
"int64",
"(",
"meta",
".",
"Size",
")",
")",
")",
"\n",
"}"
] | // ReadMetaPayload reads a Meta and Payload from a Cilium monitor connection. | [
"ReadMetaPayload",
"reads",
"a",
"Meta",
"and",
"Payload",
"from",
"a",
"Cilium",
"monitor",
"connection",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L114-L121 |
162,570 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | WriteMetaPayload | func WriteMetaPayload(w io.Writer, meta *Meta, pl *Payload) error {
payloadBuf, err := pl.Encode()
if err != nil {
return err
}
meta.Size = uint32(len(payloadBuf))
meta.WriteBinary(w)
_, err = w.Write(payloadBuf)
return err
} | go | func WriteMetaPayload(w io.Writer, meta *Meta, pl *Payload) error {
payloadBuf, err := pl.Encode()
if err != nil {
return err
}
meta.Size = uint32(len(payloadBuf))
meta.WriteBinary(w)
_, err = w.Write(payloadBuf)
return err
} | [
"func",
"WriteMetaPayload",
"(",
"w",
"io",
".",
"Writer",
",",
"meta",
"*",
"Meta",
",",
"pl",
"*",
"Payload",
")",
"error",
"{",
"payloadBuf",
",",
"err",
":=",
"pl",
".",
"Encode",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"meta",
".",
"Size",
"=",
"uint32",
"(",
"len",
"(",
"payloadBuf",
")",
")",
"\n",
"meta",
".",
"WriteBinary",
"(",
"w",
")",
"\n",
"_",
",",
"err",
"=",
"w",
".",
"Write",
"(",
"payloadBuf",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // WriteMetaPayload writes a Meta and Payload into a Cilium monitor connection.
// meta.Size is set to the size of the encoded Payload. | [
"WriteMetaPayload",
"writes",
"a",
"Meta",
"and",
"Payload",
"into",
"a",
"Cilium",
"monitor",
"connection",
".",
"meta",
".",
"Size",
"is",
"set",
"to",
"the",
"size",
"of",
"the",
"encoded",
"Payload",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L125-L134 |
162,571 | cilium/cilium | pkg/monitor/payload/monitor_payload.go | BuildMessage | func (pl *Payload) BuildMessage() ([]byte, error) {
plBuf, err := pl.Encode()
if err != nil {
return nil, fmt.Errorf("unable to encode payload: %s", err)
}
meta := &Meta{Size: uint32(len(plBuf))}
metaBuf, err := meta.MarshalBinary()
if err != nil {
return nil, fmt.Errorf("unable to encode metadata: %s", err)
}
return append(metaBuf, plBuf...), nil
} | go | func (pl *Payload) BuildMessage() ([]byte, error) {
plBuf, err := pl.Encode()
if err != nil {
return nil, fmt.Errorf("unable to encode payload: %s", err)
}
meta := &Meta{Size: uint32(len(plBuf))}
metaBuf, err := meta.MarshalBinary()
if err != nil {
return nil, fmt.Errorf("unable to encode metadata: %s", err)
}
return append(metaBuf, plBuf...), nil
} | [
"func",
"(",
"pl",
"*",
"Payload",
")",
"BuildMessage",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"plBuf",
",",
"err",
":=",
"pl",
".",
"Encode",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"meta",
":=",
"&",
"Meta",
"{",
"Size",
":",
"uint32",
"(",
"len",
"(",
"plBuf",
")",
")",
"}",
"\n",
"metaBuf",
",",
"err",
":=",
"meta",
".",
"MarshalBinary",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"append",
"(",
"metaBuf",
",",
"plBuf",
"...",
")",
",",
"nil",
"\n",
"}"
] | // BuildMessage builds the binary message to be sent and returns it | [
"BuildMessage",
"builds",
"the",
"binary",
"message",
"to",
"be",
"sent",
"and",
"returns",
"it"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/monitor/payload/monitor_payload.go#L137-L150 |
162,572 | cilium/cilium | pkg/endpoint/connector/add.go | Endpoint2IfName | func Endpoint2IfName(endpointID string) string {
sum := fmt.Sprintf("%x", sha256.Sum256([]byte(endpointID)))
// returned string length should be < unix.IFNAMSIZ
truncateLength := uint(unix.IFNAMSIZ - len(temporaryInterfacePrefix) - 1)
return hostInterfacePrefix + truncateString(sum, truncateLength)
} | go | func Endpoint2IfName(endpointID string) string {
sum := fmt.Sprintf("%x", sha256.Sum256([]byte(endpointID)))
// returned string length should be < unix.IFNAMSIZ
truncateLength := uint(unix.IFNAMSIZ - len(temporaryInterfacePrefix) - 1)
return hostInterfacePrefix + truncateString(sum, truncateLength)
} | [
"func",
"Endpoint2IfName",
"(",
"endpointID",
"string",
")",
"string",
"{",
"sum",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"sha256",
".",
"Sum256",
"(",
"[",
"]",
"byte",
"(",
"endpointID",
")",
")",
")",
"\n",
"// returned string length should be < unix.IFNAMSIZ",
"truncateLength",
":=",
"uint",
"(",
"unix",
".",
"IFNAMSIZ",
"-",
"len",
"(",
"temporaryInterfacePrefix",
")",
"-",
"1",
")",
"\n",
"return",
"hostInterfacePrefix",
"+",
"truncateString",
"(",
"sum",
",",
"truncateLength",
")",
"\n",
"}"
] | // Endpoint2IfName returns the host interface name for the given endpointID. | [
"Endpoint2IfName",
"returns",
"the",
"host",
"interface",
"name",
"for",
"the",
"given",
"endpointID",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/connector/add.go#L43-L48 |
162,573 | cilium/cilium | pkg/endpoint/connector/add.go | WriteSysConfig | func WriteSysConfig(fileName, value string) error {
f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
return fmt.Errorf("unable to open configuration file: %s", err)
}
_, err = f.WriteString(value)
if err != nil {
f.Close()
return fmt.Errorf("unable to write value: %s", err)
}
err = f.Close()
if err != nil {
return fmt.Errorf("unable to close configuration file: %s", err)
}
return nil
} | go | func WriteSysConfig(fileName, value string) error {
f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
return fmt.Errorf("unable to open configuration file: %s", err)
}
_, err = f.WriteString(value)
if err != nil {
f.Close()
return fmt.Errorf("unable to write value: %s", err)
}
err = f.Close()
if err != nil {
return fmt.Errorf("unable to close configuration file: %s", err)
}
return nil
} | [
"func",
"WriteSysConfig",
"(",
"fileName",
",",
"value",
"string",
")",
"error",
"{",
"f",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"fileName",
",",
"os",
".",
"O_WRONLY",
"|",
"os",
".",
"O_CREATE",
"|",
"os",
".",
"O_TRUNC",
",",
"0666",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"f",
".",
"WriteString",
"(",
"value",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"f",
".",
"Close",
"(",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"err",
"=",
"f",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // WriteSysConfig tries to emulate a sysctl call by writing directly to the
// given fileName the given value. | [
"WriteSysConfig",
"tries",
"to",
"emulate",
"a",
"sysctl",
"call",
"by",
"writing",
"directly",
"to",
"the",
"given",
"fileName",
"the",
"given",
"value",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/connector/add.go#L82-L97 |
162,574 | cilium/cilium | pkg/endpoint/connector/add.go | GetNetInfoFromPID | func GetNetInfoFromPID(pid int) (int, string, net.IP, error) {
netNs, err := ns.GetNS(fmt.Sprintf("/proc/%d/ns/net", pid))
if err != nil {
return 0, "", nil, err
}
defer netNs.Close()
var (
lxcMAC string
parentIndex int
ip net.IP
)
err = netNs.Do(func(_ ns.NetNS) error {
links, err := netlink.LinkList()
if err != nil {
return err
}
for _, l := range links {
addrs, err := netlink.AddrList(l, netlink.FAMILY_V4)
if err != nil {
return err
}
for _, addr := range addrs {
if addr.IP.IsGlobalUnicast() {
ip = addr.IP
lxcMAC = l.Attrs().HardwareAddr.String()
parentIndex = l.Attrs().ParentIndex
log.Debugf("link found: %+v", l.Attrs())
return nil
}
}
}
return nil
})
return parentIndex, lxcMAC, ip, err
} | go | func GetNetInfoFromPID(pid int) (int, string, net.IP, error) {
netNs, err := ns.GetNS(fmt.Sprintf("/proc/%d/ns/net", pid))
if err != nil {
return 0, "", nil, err
}
defer netNs.Close()
var (
lxcMAC string
parentIndex int
ip net.IP
)
err = netNs.Do(func(_ ns.NetNS) error {
links, err := netlink.LinkList()
if err != nil {
return err
}
for _, l := range links {
addrs, err := netlink.AddrList(l, netlink.FAMILY_V4)
if err != nil {
return err
}
for _, addr := range addrs {
if addr.IP.IsGlobalUnicast() {
ip = addr.IP
lxcMAC = l.Attrs().HardwareAddr.String()
parentIndex = l.Attrs().ParentIndex
log.Debugf("link found: %+v", l.Attrs())
return nil
}
}
}
return nil
})
return parentIndex, lxcMAC, ip, err
} | [
"func",
"GetNetInfoFromPID",
"(",
"pid",
"int",
")",
"(",
"int",
",",
"string",
",",
"net",
".",
"IP",
",",
"error",
")",
"{",
"netNs",
",",
"err",
":=",
"ns",
".",
"GetNS",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pid",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"\"",
"\"",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"netNs",
".",
"Close",
"(",
")",
"\n\n",
"var",
"(",
"lxcMAC",
"string",
"\n",
"parentIndex",
"int",
"\n",
"ip",
"net",
".",
"IP",
"\n",
")",
"\n\n",
"err",
"=",
"netNs",
".",
"Do",
"(",
"func",
"(",
"_",
"ns",
".",
"NetNS",
")",
"error",
"{",
"links",
",",
"err",
":=",
"netlink",
".",
"LinkList",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"l",
":=",
"range",
"links",
"{",
"addrs",
",",
"err",
":=",
"netlink",
".",
"AddrList",
"(",
"l",
",",
"netlink",
".",
"FAMILY_V4",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"addr",
":=",
"range",
"addrs",
"{",
"if",
"addr",
".",
"IP",
".",
"IsGlobalUnicast",
"(",
")",
"{",
"ip",
"=",
"addr",
".",
"IP",
"\n",
"lxcMAC",
"=",
"l",
".",
"Attrs",
"(",
")",
".",
"HardwareAddr",
".",
"String",
"(",
")",
"\n",
"parentIndex",
"=",
"l",
".",
"Attrs",
"(",
")",
".",
"ParentIndex",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"l",
".",
"Attrs",
"(",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"return",
"parentIndex",
",",
"lxcMAC",
",",
"ip",
",",
"err",
"\n",
"}"
] | // GetNetInfoFromPID returns the index of the interface parent, the MAC address
// and IP address of the first interface that contains an IP address with global
// scope. | [
"GetNetInfoFromPID",
"returns",
"the",
"index",
"of",
"the",
"interface",
"parent",
"the",
"MAC",
"address",
"and",
"IP",
"address",
"of",
"the",
"first",
"interface",
"that",
"contains",
"an",
"IP",
"address",
"with",
"global",
"scope",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/endpoint/connector/add.go#L102-L138 |
162,575 | cilium/cilium | api/v1/models/debug_info.go | Validate | func (m *DebugInfo) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCiliumStatus(formats); err != nil {
res = append(res, err)
}
if err := m.validateEndpointList(formats); err != nil {
res = append(res, err)
}
if err := m.validatePolicy(formats); err != nil {
res = append(res, err)
}
if err := m.validateServiceList(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | go | func (m *DebugInfo) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCiliumStatus(formats); err != nil {
res = append(res, err)
}
if err := m.validateEndpointList(formats); err != nil {
res = append(res, err)
}
if err := m.validatePolicy(formats); err != nil {
res = append(res, err)
}
if err := m.validateServiceList(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
} | [
"func",
"(",
"m",
"*",
"DebugInfo",
")",
"Validate",
"(",
"formats",
"strfmt",
".",
"Registry",
")",
"error",
"{",
"var",
"res",
"[",
"]",
"error",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateCiliumStatus",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateEndpointList",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validatePolicy",
"(",
"formats",
")",
";",
"err",
"!=",
"nil",
"{",
"res",
"=",
"append",
"(",
"res",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"m",
".",
"validateServiceList",
"(",
"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 debug info | [
"Validate",
"validates",
"this",
"debug",
"info"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/models/debug_info.go#L53-L76 |
162,576 | cilium/cilium | pkg/kvstore/allocator/localkeys.go | allocate | func (lk *localKeys) allocate(key string, val idpool.ID) (idpool.ID, error) {
lk.Lock()
defer lk.Unlock()
if k, ok := lk.keys[key]; ok {
if val != k.val {
return idpool.NoID, fmt.Errorf("local key already allocated with different value (%s != %s)", val, k.val)
}
k.refcnt++
kvstore.Trace("Incremented local key refcnt", nil, logrus.Fields{fieldKey: key, fieldID: val, fieldRefCnt: k.refcnt})
return k.val, nil
}
k := &localKey{key: key, val: val, refcnt: 1}
lk.keys[key] = k
lk.ids[val] = k
kvstore.Trace("New local key", nil, logrus.Fields{fieldKey: key, fieldID: val, fieldRefCnt: 1})
return val, nil
} | go | func (lk *localKeys) allocate(key string, val idpool.ID) (idpool.ID, error) {
lk.Lock()
defer lk.Unlock()
if k, ok := lk.keys[key]; ok {
if val != k.val {
return idpool.NoID, fmt.Errorf("local key already allocated with different value (%s != %s)", val, k.val)
}
k.refcnt++
kvstore.Trace("Incremented local key refcnt", nil, logrus.Fields{fieldKey: key, fieldID: val, fieldRefCnt: k.refcnt})
return k.val, nil
}
k := &localKey{key: key, val: val, refcnt: 1}
lk.keys[key] = k
lk.ids[val] = k
kvstore.Trace("New local key", nil, logrus.Fields{fieldKey: key, fieldID: val, fieldRefCnt: 1})
return val, nil
} | [
"func",
"(",
"lk",
"*",
"localKeys",
")",
"allocate",
"(",
"key",
"string",
",",
"val",
"idpool",
".",
"ID",
")",
"(",
"idpool",
".",
"ID",
",",
"error",
")",
"{",
"lk",
".",
"Lock",
"(",
")",
"\n",
"defer",
"lk",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"k",
",",
"ok",
":=",
"lk",
".",
"keys",
"[",
"key",
"]",
";",
"ok",
"{",
"if",
"val",
"!=",
"k",
".",
"val",
"{",
"return",
"idpool",
".",
"NoID",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"val",
",",
"k",
".",
"val",
")",
"\n",
"}",
"\n\n",
"k",
".",
"refcnt",
"++",
"\n",
"kvstore",
".",
"Trace",
"(",
"\"",
"\"",
",",
"nil",
",",
"logrus",
".",
"Fields",
"{",
"fieldKey",
":",
"key",
",",
"fieldID",
":",
"val",
",",
"fieldRefCnt",
":",
"k",
".",
"refcnt",
"}",
")",
"\n",
"return",
"k",
".",
"val",
",",
"nil",
"\n",
"}",
"\n\n",
"k",
":=",
"&",
"localKey",
"{",
"key",
":",
"key",
",",
"val",
":",
"val",
",",
"refcnt",
":",
"1",
"}",
"\n",
"lk",
".",
"keys",
"[",
"key",
"]",
"=",
"k",
"\n",
"lk",
".",
"ids",
"[",
"val",
"]",
"=",
"k",
"\n",
"kvstore",
".",
"Trace",
"(",
"\"",
"\"",
",",
"nil",
",",
"logrus",
".",
"Fields",
"{",
"fieldKey",
":",
"key",
",",
"fieldID",
":",
"val",
",",
"fieldRefCnt",
":",
"1",
"}",
")",
"\n",
"return",
"val",
",",
"nil",
"\n",
"}"
] | // allocate creates an entry for key in localKeys if needed and increments the
// refcnt. The value associated with the key must match the local cache or an
// error is returned | [
"allocate",
"creates",
"an",
"entry",
"for",
"key",
"in",
"localKeys",
"if",
"needed",
"and",
"increments",
"the",
"refcnt",
".",
"The",
"value",
"associated",
"with",
"the",
"key",
"must",
"match",
"the",
"local",
"cache",
"or",
"an",
"error",
"is",
"returned"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/localkeys.go#L54-L73 |
162,577 | cilium/cilium | pkg/kvstore/allocator/localkeys.go | lookupID | func (lk *localKeys) lookupID(id idpool.ID) string {
lk.RLock()
defer lk.RUnlock()
if k, ok := lk.ids[id]; ok {
return k.key
}
return ""
} | go | func (lk *localKeys) lookupID(id idpool.ID) string {
lk.RLock()
defer lk.RUnlock()
if k, ok := lk.ids[id]; ok {
return k.key
}
return ""
} | [
"func",
"(",
"lk",
"*",
"localKeys",
")",
"lookupID",
"(",
"id",
"idpool",
".",
"ID",
")",
"string",
"{",
"lk",
".",
"RLock",
"(",
")",
"\n",
"defer",
"lk",
".",
"RUnlock",
"(",
")",
"\n\n",
"if",
"k",
",",
"ok",
":=",
"lk",
".",
"ids",
"[",
"id",
"]",
";",
"ok",
"{",
"return",
"k",
".",
"key",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // lookupID returns the key for a given ID or an empty string | [
"lookupID",
"returns",
"the",
"key",
"for",
"a",
"given",
"ID",
"or",
"an",
"empty",
"string"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/localkeys.go#L89-L98 |
162,578 | cilium/cilium | pkg/kvstore/allocator/localkeys.go | use | func (lk *localKeys) use(key string) idpool.ID {
lk.Lock()
defer lk.Unlock()
if k, ok := lk.keys[key]; ok {
// unverified keys behave as if they do not exist
if !k.verified {
return idpool.NoID
}
k.refcnt++
kvstore.Trace("Incremented local key refcnt", nil, logrus.Fields{fieldKey: key, fieldID: k.val, fieldRefCnt: k.refcnt})
return k.val
}
return idpool.NoID
} | go | func (lk *localKeys) use(key string) idpool.ID {
lk.Lock()
defer lk.Unlock()
if k, ok := lk.keys[key]; ok {
// unverified keys behave as if they do not exist
if !k.verified {
return idpool.NoID
}
k.refcnt++
kvstore.Trace("Incremented local key refcnt", nil, logrus.Fields{fieldKey: key, fieldID: k.val, fieldRefCnt: k.refcnt})
return k.val
}
return idpool.NoID
} | [
"func",
"(",
"lk",
"*",
"localKeys",
")",
"use",
"(",
"key",
"string",
")",
"idpool",
".",
"ID",
"{",
"lk",
".",
"Lock",
"(",
")",
"\n",
"defer",
"lk",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"k",
",",
"ok",
":=",
"lk",
".",
"keys",
"[",
"key",
"]",
";",
"ok",
"{",
"// unverified keys behave as if they do not exist",
"if",
"!",
"k",
".",
"verified",
"{",
"return",
"idpool",
".",
"NoID",
"\n",
"}",
"\n\n",
"k",
".",
"refcnt",
"++",
"\n",
"kvstore",
".",
"Trace",
"(",
"\"",
"\"",
",",
"nil",
",",
"logrus",
".",
"Fields",
"{",
"fieldKey",
":",
"key",
",",
"fieldID",
":",
"k",
".",
"val",
",",
"fieldRefCnt",
":",
"k",
".",
"refcnt",
"}",
")",
"\n",
"return",
"k",
".",
"val",
"\n",
"}",
"\n\n",
"return",
"idpool",
".",
"NoID",
"\n",
"}"
] | // use increments the refcnt of the key and returns its value | [
"use",
"increments",
"the",
"refcnt",
"of",
"the",
"key",
"and",
"returns",
"its",
"value"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/localkeys.go#L101-L117 |
162,579 | cilium/cilium | pkg/kvstore/allocator/localkeys.go | release | func (lk *localKeys) release(key string) (lastUse bool, err error) {
lk.Lock()
defer lk.Unlock()
if k, ok := lk.keys[key]; ok {
k.refcnt--
kvstore.Trace("Decremented local key refcnt", nil, logrus.Fields{fieldKey: key, fieldID: k.val, fieldRefCnt: k.refcnt})
if k.refcnt == 0 {
delete(lk.keys, key)
delete(lk.ids, k.val)
return true, nil
}
return false, nil
}
return false, fmt.Errorf("unable to find key in local cache")
} | go | func (lk *localKeys) release(key string) (lastUse bool, err error) {
lk.Lock()
defer lk.Unlock()
if k, ok := lk.keys[key]; ok {
k.refcnt--
kvstore.Trace("Decremented local key refcnt", nil, logrus.Fields{fieldKey: key, fieldID: k.val, fieldRefCnt: k.refcnt})
if k.refcnt == 0 {
delete(lk.keys, key)
delete(lk.ids, k.val)
return true, nil
}
return false, nil
}
return false, fmt.Errorf("unable to find key in local cache")
} | [
"func",
"(",
"lk",
"*",
"localKeys",
")",
"release",
"(",
"key",
"string",
")",
"(",
"lastUse",
"bool",
",",
"err",
"error",
")",
"{",
"lk",
".",
"Lock",
"(",
")",
"\n",
"defer",
"lk",
".",
"Unlock",
"(",
")",
"\n",
"if",
"k",
",",
"ok",
":=",
"lk",
".",
"keys",
"[",
"key",
"]",
";",
"ok",
"{",
"k",
".",
"refcnt",
"--",
"\n",
"kvstore",
".",
"Trace",
"(",
"\"",
"\"",
",",
"nil",
",",
"logrus",
".",
"Fields",
"{",
"fieldKey",
":",
"key",
",",
"fieldID",
":",
"k",
".",
"val",
",",
"fieldRefCnt",
":",
"k",
".",
"refcnt",
"}",
")",
"\n",
"if",
"k",
".",
"refcnt",
"==",
"0",
"{",
"delete",
"(",
"lk",
".",
"keys",
",",
"key",
")",
"\n",
"delete",
"(",
"lk",
".",
"ids",
",",
"k",
".",
"val",
")",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // release releases the refcnt of a key. When the last reference was released,
// the key is deleted and the returned lastUse value is true. | [
"release",
"releases",
"the",
"refcnt",
"of",
"a",
"key",
".",
"When",
"the",
"last",
"reference",
"was",
"released",
"the",
"key",
"is",
"deleted",
"and",
"the",
"returned",
"lastUse",
"value",
"is",
"true",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/kvstore/allocator/localkeys.go#L121-L137 |
162,580 | cilium/cilium | pkg/crypto/sha1/sha1.go | Copy | func (d *digest) Copy() (ResumableHash, error) {
newHash := hash.Hash(sha1.New())
state, err := d.Hash.(encoding.BinaryMarshaler).MarshalBinary()
if err != nil {
return nil, err
}
if err := newHash.(encoding.BinaryUnmarshaler).UnmarshalBinary(state); err != nil {
return nil, err
}
return &digest{
newHash,
}, nil
} | go | func (d *digest) Copy() (ResumableHash, error) {
newHash := hash.Hash(sha1.New())
state, err := d.Hash.(encoding.BinaryMarshaler).MarshalBinary()
if err != nil {
return nil, err
}
if err := newHash.(encoding.BinaryUnmarshaler).UnmarshalBinary(state); err != nil {
return nil, err
}
return &digest{
newHash,
}, nil
} | [
"func",
"(",
"d",
"*",
"digest",
")",
"Copy",
"(",
")",
"(",
"ResumableHash",
",",
"error",
")",
"{",
"newHash",
":=",
"hash",
".",
"Hash",
"(",
"sha1",
".",
"New",
"(",
")",
")",
"\n",
"state",
",",
"err",
":=",
"d",
".",
"Hash",
".",
"(",
"encoding",
".",
"BinaryMarshaler",
")",
".",
"MarshalBinary",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"newHash",
".",
"(",
"encoding",
".",
"BinaryUnmarshaler",
")",
".",
"UnmarshalBinary",
"(",
"state",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"digest",
"{",
"newHash",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Copy duplicates the hash and returns the copy. | [
"Copy",
"duplicates",
"the",
"hash",
"and",
"returns",
"the",
"copy",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/crypto/sha1/sha1.go#L53-L65 |
162,581 | cilium/cilium | api/v1/server/restapi/ipam/post_ip_a_m_responses.go | WithPayload | func (o *PostIPAMCreated) WithPayload(payload *models.IPAMResponse) *PostIPAMCreated {
o.Payload = payload
return o
} | go | func (o *PostIPAMCreated) WithPayload(payload *models.IPAMResponse) *PostIPAMCreated {
o.Payload = payload
return o
} | [
"func",
"(",
"o",
"*",
"PostIPAMCreated",
")",
"WithPayload",
"(",
"payload",
"*",
"models",
".",
"IPAMResponse",
")",
"*",
"PostIPAMCreated",
"{",
"o",
".",
"Payload",
"=",
"payload",
"\n",
"return",
"o",
"\n",
"}"
] | // WithPayload adds the payload to the post Ip a m created response | [
"WithPayload",
"adds",
"the",
"payload",
"to",
"the",
"post",
"Ip",
"a",
"m",
"created",
"response"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/ipam/post_ip_a_m_responses.go#L38-L41 |
162,582 | cilium/cilium | api/v1/server/restapi/ipam/post_ip_a_m_responses.go | WithPayload | func (o *PostIPAMFailure) WithPayload(payload models.Error) *PostIPAMFailure {
o.Payload = payload
return o
} | go | func (o *PostIPAMFailure) WithPayload(payload models.Error) *PostIPAMFailure {
o.Payload = payload
return o
} | [
"func",
"(",
"o",
"*",
"PostIPAMFailure",
")",
"WithPayload",
"(",
"payload",
"models",
".",
"Error",
")",
"*",
"PostIPAMFailure",
"{",
"o",
".",
"Payload",
"=",
"payload",
"\n",
"return",
"o",
"\n",
"}"
] | // WithPayload adds the payload to the post Ip a m failure response | [
"WithPayload",
"adds",
"the",
"payload",
"to",
"the",
"post",
"Ip",
"a",
"m",
"failure",
"response"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/ipam/post_ip_a_m_responses.go#L82-L85 |
162,583 | cilium/cilium | pkg/client/prefilter.go | GetPrefilter | func (c *Client) GetPrefilter() (*models.Prefilter, error) {
resp, err := c.Prefilter.GetPrefilter(nil)
if err != nil {
return nil, Hint(err)
}
return resp.Payload, nil
} | go | func (c *Client) GetPrefilter() (*models.Prefilter, error) {
resp, err := c.Prefilter.GetPrefilter(nil)
if err != nil {
return nil, Hint(err)
}
return resp.Payload, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"GetPrefilter",
"(",
")",
"(",
"*",
"models",
".",
"Prefilter",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"c",
".",
"Prefilter",
".",
"GetPrefilter",
"(",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"Hint",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"resp",
".",
"Payload",
",",
"nil",
"\n",
"}"
] | // GetPrefilter returns a list of all CIDR prefixes | [
"GetPrefilter",
"returns",
"a",
"list",
"of",
"all",
"CIDR",
"prefixes"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/client/prefilter.go#L24-L30 |
162,584 | cilium/cilium | pkg/client/prefilter.go | PatchPrefilter | func (c *Client) PatchPrefilter(spec *models.PrefilterSpec) (*models.Prefilter, error) {
params := prefilter.NewPatchPrefilterParams().WithPrefilterSpec(spec).WithTimeout(api.ClientTimeout)
resp, err := c.Prefilter.PatchPrefilter(params)
if err != nil {
return nil, Hint(err)
}
return resp.Payload, nil
} | go | func (c *Client) PatchPrefilter(spec *models.PrefilterSpec) (*models.Prefilter, error) {
params := prefilter.NewPatchPrefilterParams().WithPrefilterSpec(spec).WithTimeout(api.ClientTimeout)
resp, err := c.Prefilter.PatchPrefilter(params)
if err != nil {
return nil, Hint(err)
}
return resp.Payload, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"PatchPrefilter",
"(",
"spec",
"*",
"models",
".",
"PrefilterSpec",
")",
"(",
"*",
"models",
".",
"Prefilter",
",",
"error",
")",
"{",
"params",
":=",
"prefilter",
".",
"NewPatchPrefilterParams",
"(",
")",
".",
"WithPrefilterSpec",
"(",
"spec",
")",
".",
"WithTimeout",
"(",
"api",
".",
"ClientTimeout",
")",
"\n",
"resp",
",",
"err",
":=",
"c",
".",
"Prefilter",
".",
"PatchPrefilter",
"(",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"Hint",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"resp",
".",
"Payload",
",",
"nil",
"\n",
"}"
] | // PatchPrefilter sets a list of CIDR prefixes | [
"PatchPrefilter",
"sets",
"a",
"list",
"of",
"CIDR",
"prefixes"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/client/prefilter.go#L33-L40 |
162,585 | cilium/cilium | pkg/client/prefilter.go | DeletePrefilter | func (c *Client) DeletePrefilter(spec *models.PrefilterSpec) error {
current, err := c.GetPrefilter()
if err != nil {
return Hint(err)
}
deleteSet := map[string]bool{}
keepList := []string{}
for _, delCIDR := range spec.Deny {
deleteSet[delCIDR] = true
}
if current.Status != nil && current.Status.Realized != nil {
for _, keepCIDR := range current.Status.Realized.Deny {
if !deleteSet[keepCIDR] {
keepList = append(keepList, keepCIDR)
}
}
}
update := current.Status.Realized
update.Deny = keepList
_, err = c.PatchPrefilter(update)
return Hint(err)
} | go | func (c *Client) DeletePrefilter(spec *models.PrefilterSpec) error {
current, err := c.GetPrefilter()
if err != nil {
return Hint(err)
}
deleteSet := map[string]bool{}
keepList := []string{}
for _, delCIDR := range spec.Deny {
deleteSet[delCIDR] = true
}
if current.Status != nil && current.Status.Realized != nil {
for _, keepCIDR := range current.Status.Realized.Deny {
if !deleteSet[keepCIDR] {
keepList = append(keepList, keepCIDR)
}
}
}
update := current.Status.Realized
update.Deny = keepList
_, err = c.PatchPrefilter(update)
return Hint(err)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"DeletePrefilter",
"(",
"spec",
"*",
"models",
".",
"PrefilterSpec",
")",
"error",
"{",
"current",
",",
"err",
":=",
"c",
".",
"GetPrefilter",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"Hint",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"deleteSet",
":=",
"map",
"[",
"string",
"]",
"bool",
"{",
"}",
"\n",
"keepList",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"delCIDR",
":=",
"range",
"spec",
".",
"Deny",
"{",
"deleteSet",
"[",
"delCIDR",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"if",
"current",
".",
"Status",
"!=",
"nil",
"&&",
"current",
".",
"Status",
".",
"Realized",
"!=",
"nil",
"{",
"for",
"_",
",",
"keepCIDR",
":=",
"range",
"current",
".",
"Status",
".",
"Realized",
".",
"Deny",
"{",
"if",
"!",
"deleteSet",
"[",
"keepCIDR",
"]",
"{",
"keepList",
"=",
"append",
"(",
"keepList",
",",
"keepCIDR",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"update",
":=",
"current",
".",
"Status",
".",
"Realized",
"\n",
"update",
".",
"Deny",
"=",
"keepList",
"\n",
"_",
",",
"err",
"=",
"c",
".",
"PatchPrefilter",
"(",
"update",
")",
"\n",
"return",
"Hint",
"(",
"err",
")",
"\n",
"}"
] | // DeletePrefilter deletes a list of CIDR prefixes | [
"DeletePrefilter",
"deletes",
"a",
"list",
"of",
"CIDR",
"prefixes"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/client/prefilter.go#L43-L67 |
162,586 | cilium/cilium | api/v1/client/daemon/get_config_parameters.go | WithTimeout | func (o *GetConfigParams) WithTimeout(timeout time.Duration) *GetConfigParams {
o.SetTimeout(timeout)
return o
} | go | func (o *GetConfigParams) WithTimeout(timeout time.Duration) *GetConfigParams {
o.SetTimeout(timeout)
return o
} | [
"func",
"(",
"o",
"*",
"GetConfigParams",
")",
"WithTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"*",
"GetConfigParams",
"{",
"o",
".",
"SetTimeout",
"(",
"timeout",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithTimeout adds the timeout to the get config params | [
"WithTimeout",
"adds",
"the",
"timeout",
"to",
"the",
"get",
"config",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/daemon/get_config_parameters.go#L69-L72 |
162,587 | cilium/cilium | api/v1/client/daemon/get_config_parameters.go | WithContext | func (o *GetConfigParams) WithContext(ctx context.Context) *GetConfigParams {
o.SetContext(ctx)
return o
} | go | func (o *GetConfigParams) WithContext(ctx context.Context) *GetConfigParams {
o.SetContext(ctx)
return o
} | [
"func",
"(",
"o",
"*",
"GetConfigParams",
")",
"WithContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"*",
"GetConfigParams",
"{",
"o",
".",
"SetContext",
"(",
"ctx",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithContext adds the context to the get config params | [
"WithContext",
"adds",
"the",
"context",
"to",
"the",
"get",
"config",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/daemon/get_config_parameters.go#L80-L83 |
162,588 | cilium/cilium | api/v1/client/daemon/get_config_parameters.go | WithHTTPClient | func (o *GetConfigParams) WithHTTPClient(client *http.Client) *GetConfigParams {
o.SetHTTPClient(client)
return o
} | go | func (o *GetConfigParams) WithHTTPClient(client *http.Client) *GetConfigParams {
o.SetHTTPClient(client)
return o
} | [
"func",
"(",
"o",
"*",
"GetConfigParams",
")",
"WithHTTPClient",
"(",
"client",
"*",
"http",
".",
"Client",
")",
"*",
"GetConfigParams",
"{",
"o",
".",
"SetHTTPClient",
"(",
"client",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithHTTPClient adds the HTTPClient to the get config params | [
"WithHTTPClient",
"adds",
"the",
"HTTPClient",
"to",
"the",
"get",
"config",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/daemon/get_config_parameters.go#L91-L94 |
162,589 | cilium/cilium | api/v1/server/restapi/policy/get_fqdn_cache_id_responses.go | WithPayload | func (o *GetFqdnCacheIDOK) WithPayload(payload []*models.DNSLookup) *GetFqdnCacheIDOK {
o.Payload = payload
return o
} | go | func (o *GetFqdnCacheIDOK) WithPayload(payload []*models.DNSLookup) *GetFqdnCacheIDOK {
o.Payload = payload
return o
} | [
"func",
"(",
"o",
"*",
"GetFqdnCacheIDOK",
")",
"WithPayload",
"(",
"payload",
"[",
"]",
"*",
"models",
".",
"DNSLookup",
")",
"*",
"GetFqdnCacheIDOK",
"{",
"o",
".",
"Payload",
"=",
"payload",
"\n",
"return",
"o",
"\n",
"}"
] | // WithPayload adds the payload to the get fqdn cache Id o k response | [
"WithPayload",
"adds",
"the",
"payload",
"to",
"the",
"get",
"fqdn",
"cache",
"Id",
"o",
"k",
"response"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/policy/get_fqdn_cache_id_responses.go#L38-L41 |
162,590 | cilium/cilium | api/v1/server/restapi/policy/get_fqdn_cache_id_responses.go | WithPayload | func (o *GetFqdnCacheIDBadRequest) WithPayload(payload models.Error) *GetFqdnCacheIDBadRequest {
o.Payload = payload
return o
} | go | func (o *GetFqdnCacheIDBadRequest) WithPayload(payload models.Error) *GetFqdnCacheIDBadRequest {
o.Payload = payload
return o
} | [
"func",
"(",
"o",
"*",
"GetFqdnCacheIDBadRequest",
")",
"WithPayload",
"(",
"payload",
"models",
".",
"Error",
")",
"*",
"GetFqdnCacheIDBadRequest",
"{",
"o",
".",
"Payload",
"=",
"payload",
"\n",
"return",
"o",
"\n",
"}"
] | // WithPayload adds the payload to the get fqdn cache Id bad request response | [
"WithPayload",
"adds",
"the",
"payload",
"to",
"the",
"get",
"fqdn",
"cache",
"Id",
"bad",
"request",
"response"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/server/restapi/policy/get_fqdn_cache_id_responses.go#L85-L88 |
162,591 | cilium/cilium | pkg/fqdn/matchpattern/matchpattern.go | Validate | func Validate(pattern string) (matcher *regexp.Regexp, err error) {
pattern = strings.TrimSpace(pattern)
pattern = strings.ToLower(pattern)
// error check
if strings.ContainsAny(pattern, "[]+{},") {
return nil, errors.New(`Only alphanumeric ASCII characters, the hyphen "-", "." and "*" are allowed in a matchPattern`)
}
return regexp.Compile(ToRegexp(pattern))
} | go | func Validate(pattern string) (matcher *regexp.Regexp, err error) {
pattern = strings.TrimSpace(pattern)
pattern = strings.ToLower(pattern)
// error check
if strings.ContainsAny(pattern, "[]+{},") {
return nil, errors.New(`Only alphanumeric ASCII characters, the hyphen "-", "." and "*" are allowed in a matchPattern`)
}
return regexp.Compile(ToRegexp(pattern))
} | [
"func",
"Validate",
"(",
"pattern",
"string",
")",
"(",
"matcher",
"*",
"regexp",
".",
"Regexp",
",",
"err",
"error",
")",
"{",
"pattern",
"=",
"strings",
".",
"TrimSpace",
"(",
"pattern",
")",
"\n",
"pattern",
"=",
"strings",
".",
"ToLower",
"(",
"pattern",
")",
"\n\n",
"// error check",
"if",
"strings",
".",
"ContainsAny",
"(",
"pattern",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"`Only alphanumeric ASCII characters, the hyphen \"-\", \".\" and \"*\" are allowed in a matchPattern`",
")",
"\n",
"}",
"\n\n",
"return",
"regexp",
".",
"Compile",
"(",
"ToRegexp",
"(",
"pattern",
")",
")",
"\n",
"}"
] | // Validate ensures that pattern is a parseable matchPattern. It returns the
// regexp generated when validating. | [
"Validate",
"ensures",
"that",
"pattern",
"is",
"a",
"parseable",
"matchPattern",
".",
"It",
"returns",
"the",
"regexp",
"generated",
"when",
"validating",
"."
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/fqdn/matchpattern/matchpattern.go#L29-L39 |
162,592 | cilium/cilium | pkg/fqdn/matchpattern/matchpattern.go | Sanitize | func Sanitize(pattern string) string {
if pattern == "*" {
return pattern
}
return strings.ToLower(dns.Fqdn(pattern))
} | go | func Sanitize(pattern string) string {
if pattern == "*" {
return pattern
}
return strings.ToLower(dns.Fqdn(pattern))
} | [
"func",
"Sanitize",
"(",
"pattern",
"string",
")",
"string",
"{",
"if",
"pattern",
"==",
"\"",
"\"",
"{",
"return",
"pattern",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"ToLower",
"(",
"dns",
".",
"Fqdn",
"(",
"pattern",
")",
")",
"\n",
"}"
] | // Sanitize canonicalized the pattern for use by ToRegexp | [
"Sanitize",
"canonicalized",
"the",
"pattern",
"for",
"use",
"by",
"ToRegexp"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/fqdn/matchpattern/matchpattern.go#L42-L48 |
162,593 | cilium/cilium | pkg/cidr/cidr.go | NewCIDR | func NewCIDR(ipnet *net.IPNet) *CIDR {
if ipnet == nil {
return nil
}
return &CIDR{ipnet}
} | go | func NewCIDR(ipnet *net.IPNet) *CIDR {
if ipnet == nil {
return nil
}
return &CIDR{ipnet}
} | [
"func",
"NewCIDR",
"(",
"ipnet",
"*",
"net",
".",
"IPNet",
")",
"*",
"CIDR",
"{",
"if",
"ipnet",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"&",
"CIDR",
"{",
"ipnet",
"}",
"\n",
"}"
] | // NewCIDR returns a new CIDR using a net.IPNet | [
"NewCIDR",
"returns",
"a",
"new",
"CIDR",
"using",
"a",
"net",
".",
"IPNet"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/cidr/cidr.go#L23-L29 |
162,594 | cilium/cilium | pkg/cidr/cidr.go | DeepCopy | func (n *CIDR) DeepCopy() *CIDR {
if n == nil {
return nil
}
out := &CIDR{
&net.IPNet{
IP: make([]byte, len(n.IP)),
Mask: make([]byte, len(n.Mask)),
},
}
copy(out.IP, n.IP)
copy(out.Mask, n.Mask)
return out
} | go | func (n *CIDR) DeepCopy() *CIDR {
if n == nil {
return nil
}
out := &CIDR{
&net.IPNet{
IP: make([]byte, len(n.IP)),
Mask: make([]byte, len(n.Mask)),
},
}
copy(out.IP, n.IP)
copy(out.Mask, n.Mask)
return out
} | [
"func",
"(",
"n",
"*",
"CIDR",
")",
"DeepCopy",
"(",
")",
"*",
"CIDR",
"{",
"if",
"n",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"&",
"CIDR",
"{",
"&",
"net",
".",
"IPNet",
"{",
"IP",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"n",
".",
"IP",
")",
")",
",",
"Mask",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"n",
".",
"Mask",
")",
")",
",",
"}",
",",
"}",
"\n",
"copy",
"(",
"out",
".",
"IP",
",",
"n",
".",
"IP",
")",
"\n",
"copy",
"(",
"out",
".",
"Mask",
",",
"n",
".",
"Mask",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // DeepCopy creates a deep copy of a CIDR | [
"DeepCopy",
"creates",
"a",
"deep",
"copy",
"of",
"a",
"CIDR"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/cidr/cidr.go#L37-L50 |
162,595 | cilium/cilium | pkg/cidr/cidr.go | ParseCIDR | func ParseCIDR(str string) (*CIDR, error) {
_, ipnet, err := net.ParseCIDR(str)
if err != nil {
return nil, err
}
return NewCIDR(ipnet), nil
} | go | func ParseCIDR(str string) (*CIDR, error) {
_, ipnet, err := net.ParseCIDR(str)
if err != nil {
return nil, err
}
return NewCIDR(ipnet), nil
} | [
"func",
"ParseCIDR",
"(",
"str",
"string",
")",
"(",
"*",
"CIDR",
",",
"error",
")",
"{",
"_",
",",
"ipnet",
",",
"err",
":=",
"net",
".",
"ParseCIDR",
"(",
"str",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"NewCIDR",
"(",
"ipnet",
")",
",",
"nil",
"\n",
"}"
] | // ParseCIDR parses the CIDR string using net.ParseCIDR | [
"ParseCIDR",
"parses",
"the",
"CIDR",
"string",
"using",
"net",
".",
"ParseCIDR"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/cidr/cidr.go#L53-L59 |
162,596 | cilium/cilium | pkg/cidr/cidr.go | MustParseCIDR | func MustParseCIDR(str string) *CIDR {
c, err := ParseCIDR(str)
if err != nil {
panic(fmt.Sprintf("Unable to parse CIDR '%s': %s", str, err))
}
return c
} | go | func MustParseCIDR(str string) *CIDR {
c, err := ParseCIDR(str)
if err != nil {
panic(fmt.Sprintf("Unable to parse CIDR '%s': %s", str, err))
}
return c
} | [
"func",
"MustParseCIDR",
"(",
"str",
"string",
")",
"*",
"CIDR",
"{",
"c",
",",
"err",
":=",
"ParseCIDR",
"(",
"str",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"str",
",",
"err",
")",
")",
"\n",
"}",
"\n",
"return",
"c",
"\n",
"}"
] | // MustParseCIDR parses the CIDR string using net.ParseCIDR and panics if the
// CIDR cannot be parsed | [
"MustParseCIDR",
"parses",
"the",
"CIDR",
"string",
"using",
"net",
".",
"ParseCIDR",
"and",
"panics",
"if",
"the",
"CIDR",
"cannot",
"be",
"parsed"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/pkg/cidr/cidr.go#L63-L69 |
162,597 | cilium/cilium | api/v1/client/prefilter/get_prefilter_parameters.go | WithTimeout | func (o *GetPrefilterParams) WithTimeout(timeout time.Duration) *GetPrefilterParams {
o.SetTimeout(timeout)
return o
} | go | func (o *GetPrefilterParams) WithTimeout(timeout time.Duration) *GetPrefilterParams {
o.SetTimeout(timeout)
return o
} | [
"func",
"(",
"o",
"*",
"GetPrefilterParams",
")",
"WithTimeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"*",
"GetPrefilterParams",
"{",
"o",
".",
"SetTimeout",
"(",
"timeout",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithTimeout adds the timeout to the get prefilter params | [
"WithTimeout",
"adds",
"the",
"timeout",
"to",
"the",
"get",
"prefilter",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/prefilter/get_prefilter_parameters.go#L69-L72 |
162,598 | cilium/cilium | api/v1/client/prefilter/get_prefilter_parameters.go | WithContext | func (o *GetPrefilterParams) WithContext(ctx context.Context) *GetPrefilterParams {
o.SetContext(ctx)
return o
} | go | func (o *GetPrefilterParams) WithContext(ctx context.Context) *GetPrefilterParams {
o.SetContext(ctx)
return o
} | [
"func",
"(",
"o",
"*",
"GetPrefilterParams",
")",
"WithContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"*",
"GetPrefilterParams",
"{",
"o",
".",
"SetContext",
"(",
"ctx",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithContext adds the context to the get prefilter params | [
"WithContext",
"adds",
"the",
"context",
"to",
"the",
"get",
"prefilter",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/prefilter/get_prefilter_parameters.go#L80-L83 |
162,599 | cilium/cilium | api/v1/client/prefilter/get_prefilter_parameters.go | WithHTTPClient | func (o *GetPrefilterParams) WithHTTPClient(client *http.Client) *GetPrefilterParams {
o.SetHTTPClient(client)
return o
} | go | func (o *GetPrefilterParams) WithHTTPClient(client *http.Client) *GetPrefilterParams {
o.SetHTTPClient(client)
return o
} | [
"func",
"(",
"o",
"*",
"GetPrefilterParams",
")",
"WithHTTPClient",
"(",
"client",
"*",
"http",
".",
"Client",
")",
"*",
"GetPrefilterParams",
"{",
"o",
".",
"SetHTTPClient",
"(",
"client",
")",
"\n",
"return",
"o",
"\n",
"}"
] | // WithHTTPClient adds the HTTPClient to the get prefilter params | [
"WithHTTPClient",
"adds",
"the",
"HTTPClient",
"to",
"the",
"get",
"prefilter",
"params"
] | 6ecfff82c2314dd9d847645361b57e2646eed64b | https://github.com/cilium/cilium/blob/6ecfff82c2314dd9d847645361b57e2646eed64b/api/v1/client/prefilter/get_prefilter_parameters.go#L91-L94 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.