forked from projectcalico/felix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.go
179 lines (154 loc) · 7.15 KB
/
driver.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// +build !windows
// Copyright (c) 2017-2018 Tigera, Inc. All rights reserved.
//
// 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 dataplane
import (
"math/bits"
"net"
"os/exec"
log "github.com/sirupsen/logrus"
"runtime/debug"
"github.com/projectcalico/felix/config"
"github.com/projectcalico/felix/dataplane/external"
"github.com/projectcalico/felix/dataplane/linux"
"github.com/projectcalico/felix/ifacemonitor"
"github.com/projectcalico/felix/ipsets"
"github.com/projectcalico/felix/logutils"
"github.com/projectcalico/felix/markbits"
"github.com/projectcalico/felix/rules"
"github.com/projectcalico/libcalico-go/lib/health"
)
func StartDataplaneDriver(configParams *config.Config,
healthAggregator *health.HealthAggregator,
configChangedRestartCallback func()) (DataplaneDriver, *exec.Cmd) {
if configParams.UseInternalDataplaneDriver {
log.Info("Using internal (linux) dataplane driver.")
// If kube ipvs interface is present, enable ipvs support.
kubeIPVSSupportEnabled := ifacemonitor.IsInterfacePresent(intdataplane.KubeIPVSInterface)
if kubeIPVSSupportEnabled {
log.Info("Kube-proxy in ipvs mode, enabling felix kube-proxy ipvs support.")
}
if configChangedRestartCallback == nil {
log.Panic("Starting dataplane with nil callback func.")
}
markBitsManager := markbits.NewMarkBitsManager(configParams.IptablesMarkMask, "felix-iptables")
// Dedicated mark bits for accept and pass actions. These are long lived bits
// that we use for communicating between chains.
markAccept, _ := markBitsManager.NextSingleBitMark()
markPass, _ := markBitsManager.NextSingleBitMark()
// Short-lived mark bits for local calculations within a chain.
markScratch0, _ := markBitsManager.NextSingleBitMark()
markScratch1, _ := markBitsManager.NextSingleBitMark()
if markAccept == 0 || markPass == 0 || markScratch0 == 0 || markScratch1 == 0 {
log.WithFields(log.Fields{
"Name": "felix-iptables",
"MarkMask": configParams.IptablesMarkMask,
}).Panic("Not enough mark bits available.")
}
// Mark bits for end point mark. Currently felix takes the rest bits from mask available for use.
markEndpointMark, allocated := markBitsManager.NextBlockBitsMark(markBitsManager.AvailableMarkBitCount())
if kubeIPVSSupportEnabled && allocated == 0 {
log.WithFields(log.Fields{
"Name": "felix-iptables",
"MarkMask": configParams.IptablesMarkMask,
}).Panic("Not enough mark bits available for endpoint mark.")
}
// Take lowest bit position (position 1) from endpoint mark mask reserved for non-calico endpoint.
markEndpointNonCaliEndpoint := uint32(1) << uint(bits.TrailingZeros32(markEndpointMark))
log.WithFields(log.Fields{
"acceptMark": markAccept,
"passMark": markPass,
"scratch0Mark": markScratch0,
"scratch1Mark": markScratch1,
"endpointMark": markEndpointMark,
"endpointMarkNonCali": markEndpointNonCaliEndpoint,
}).Info("Calculated iptables mark bits")
dpConfig := intdataplane.Config{
IfaceMonitorConfig: ifacemonitor.Config{
InterfaceExcludes: configParams.InterfaceExcludes(),
},
RulesConfig: rules.Config{
WorkloadIfacePrefixes: configParams.InterfacePrefixes(),
IPSetConfigV4: ipsets.NewIPVersionConfig(
ipsets.IPFamilyV4,
rules.IPSetNamePrefix,
rules.AllHistoricIPSetNamePrefixes,
rules.LegacyV4IPSetNames,
),
IPSetConfigV6: ipsets.NewIPVersionConfig(
ipsets.IPFamilyV6,
rules.IPSetNamePrefix,
rules.AllHistoricIPSetNamePrefixes,
nil,
),
KubeNodePortRanges: configParams.KubeNodePortRanges,
KubeIPVSSupportEnabled: kubeIPVSSupportEnabled,
OpenStackSpecialCasesEnabled: configParams.OpenstackActive(),
OpenStackMetadataIP: net.ParseIP(configParams.MetadataAddr),
OpenStackMetadataPort: uint16(configParams.MetadataPort),
IptablesMarkAccept: markAccept,
IptablesMarkPass: markPass,
IptablesMarkScratch0: markScratch0,
IptablesMarkScratch1: markScratch1,
IptablesMarkEndpoint: markEndpointMark,
IptablesMarkNonCaliEndpoint: markEndpointNonCaliEndpoint,
IPIPEnabled: configParams.IpInIpEnabled,
IPIPTunnelAddress: configParams.IpInIpTunnelAddr,
IptablesLogPrefix: configParams.LogPrefix,
EndpointToHostAction: configParams.DefaultEndpointToHostAction,
IptablesFilterAllowAction: configParams.IptablesFilterAllowAction,
IptablesMangleAllowAction: configParams.IptablesMangleAllowAction,
FailsafeInboundHostPorts: configParams.FailsafeInboundHostPorts,
FailsafeOutboundHostPorts: configParams.FailsafeOutboundHostPorts,
DisableConntrackInvalid: configParams.DisableConntrackInvalidCheck,
NATPortRange: configParams.NATPortRange,
IptablesNATOutgoingInterfaceFilter: configParams.IptablesNATOutgoingInterfaceFilter,
},
IPIPMTU: configParams.IpInIpMtu,
IptablesRefreshInterval: configParams.IptablesRefreshInterval,
RouteRefreshInterval: configParams.RouteRefreshInterval,
IPSetsRefreshInterval: configParams.IpsetsRefreshInterval,
IptablesPostWriteCheckInterval: configParams.IptablesPostWriteCheckIntervalSecs,
IptablesInsertMode: configParams.ChainInsertMode,
IptablesLockFilePath: configParams.IptablesLockFilePath,
IptablesLockTimeout: configParams.IptablesLockTimeoutSecs,
IptablesLockProbeInterval: configParams.IptablesLockProbeIntervalMillis,
MaxIPSetSize: configParams.MaxIpsetSize,
IgnoreLooseRPF: configParams.IgnoreLooseRPF,
IPv6Enabled: configParams.Ipv6Support,
StatusReportingInterval: configParams.ReportingIntervalSecs,
NetlinkTimeout: configParams.NetlinkTimeoutSecs,
ConfigChangedRestartCallback: configChangedRestartCallback,
PostInSyncCallback: func() {
// The initial resync uses a lot of scratch space so now is
// a good time to force a GC and return any RAM that we can.
debug.FreeOSMemory()
if configParams.DebugMemoryProfilePath == "" {
return
}
logutils.DumpHeapMemoryProfile(configParams.DebugMemoryProfilePath)
},
HealthAggregator: healthAggregator,
DebugSimulateDataplaneHangAfter: configParams.DebugSimulateDataplaneHangAfter,
ExternalNodesCidrs: configParams.ExternalNodesCIDRList,
}
intDP := intdataplane.NewIntDataplaneDriver(dpConfig)
intDP.Start()
return intDP, nil
} else {
log.WithField("driver", configParams.DataplaneDriver).Info(
"Using external dataplane driver.")
return extdataplane.StartExtDataplaneDriver(configParams.DataplaneDriver)
}
}