forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
95 lines (79 loc) · 3.32 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2016-2017 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"net"
"sync"
"github.com/cilium/cilium/daemon/options"
"github.com/cilium/cilium/pkg/labels"
"github.com/cilium/cilium/pkg/option"
)
const (
// AllowLocalhostAuto defaults to policy except when running in
// Kubernetes where it then defaults to "always"
AllowLocalhostAuto = "auto"
// AllowLocalhostAlways always allows the local stack to reach local
// endpoints
AllowLocalhostAlways = "always"
// AllowLocalhostPolicy requires a policy rule to allow the local stack
// to reach particular endpoints or policy enforcement must be
// disabled.
AllowLocalhostPolicy = "policy"
)
// Config is the configuration used by Daemon.
type Config struct {
BpfDir string // BPF template files directory
LibDir string // Cilium library files directory
RunDir string // Cilium runtime directory
NAT46Prefix *net.IPNet // NAT46 IPv6 Prefix
Device string // Receive device
HostV4Addr net.IP // Host v4 address of the snooping device
HostV6Addr net.IP // Host v6 address of the snooping device
DockerEndpoint string // Docker endpoint
IPv4Disabled bool // Disable IPv4 allocation
K8sEndpoint string // Kubernetes endpoint
K8sCfgPath string // Kubeconfig path
LBInterface string // Set with name of the interface to loadbalance packets from
EnablePolicy string // Whether policy enforcement is enabled.
Tunnel string // Tunnel mode
ValidLabelPrefixesMU sync.RWMutex // Protects the 2 variables below
ValidLabelPrefixes *labels.LabelPrefixCfg // Label prefixes used to filter from all labels
DryMode bool // Do not create BPF maps, devices, ..
RestoreState bool // RestoreState restores the state from previous running daemons.
KeepConfig bool // Keep configuration of existing endpoints when starting up.
KeepTemplates bool // Do not overwrite the template files
// AllowLocalhost defines when to allows the local stack to local endpoints
// values: { auto | always | policy }
AllowLocalhost string
// alwaysAllowLocalhost is set based on the value of AllowLocalhost and
// is either set to true when localhost can always reach local
// endpoints or false when policy should be evaluated
alwaysAllowLocalhost bool
// StateDir is the directory where runtime state of endpoints is stored
StateDir string
// Options changeable at runtime
Opts *option.BoolOptions
}
func NewConfig() *Config {
return &Config{
Opts: option.NewBoolOptions(&options.Library),
}
}
// IsK8sEnabled checks if Cilium is being used in tandem with Kubernetes.
func (c *Config) IsK8sEnabled() bool {
return c.K8sEndpoint != "" || c.K8sCfgPath != ""
}
func (c *Config) IsLBEnabled() bool {
return c.LBInterface != ""
}