Skip to content

Commit 4120a16

Browse files
committed
add felixConfiguration attr: natOutgoingExclusions
1 parent 40b1906 commit 4120a16

21 files changed

+215
-4
lines changed

api/pkg/apis/projectcalico/v3/felixconfig.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ const (
122122
FlowLogsPolicyEvaluationModeContinuous FlowLogsPolicyEvaluationModeType = "Continuous"
123123
)
124124

125+
// +kubebuilder:validation:Enum=IPPoolsOnly;IPPoolsAndHostIPs
126+
type NATOutgoingExclusionsType string
127+
128+
const (
129+
NATOutgoingExclusionsIPPoolsOnly NATOutgoingExclusionsType = "IPPoolsOnly"
130+
NATOutgoingExclusionsIPPoolsAndHostIPs NATOutgoingExclusionsType = "IPPoolsAndHostIPs"
131+
)
132+
125133
// FelixConfigurationSpec contains the values of the Felix configuration.
126134
type FelixConfigurationSpec struct {
127135
// UseInternalDataplaneDriver, if true, Felix will use its internal dataplane programming logic. If false, it
@@ -482,6 +490,13 @@ type FelixConfigurationSpec struct {
482490
// (i.e. it uses the iptables MASQUERADE target).
483491
NATOutgoingAddress string `json:"natOutgoingAddress,omitempty"`
484492

493+
// When a IP pool setting `natOutgoing` is true, packets sent from Calico networked containers in this IP pool to destinations will be masqueraded.
494+
// Configure which type of destinations is excluded from being masqueraded.
495+
// - IPPoolsOnly: destinations outside of this IP pool will be masqueraded.
496+
// - IPPoolsAndHostIPs: destinations outside of this IP pool and all hosts will be masqueraded.
497+
// [Default: IPPoolsOnly]
498+
NATOutgoingExclusions *NATOutgoingExclusionsType `json:"natOutgoingExclusions,omitempty" validate:"omitempty,oneof=IPPoolsOnly IPPoolsAndHostIPs"`
499+
485500
// DeviceRouteSourceAddress IPv4 address to set as the source hint for routes programmed by Felix. When not set
486501
// the source address for local traffic from host to workload will be determined by the kernel.
487502
DeviceRouteSourceAddress string `json:"deviceRouteSourceAddress,omitempty"`

api/pkg/apis/projectcalico/v3/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/pkg/openapi/generated.openapi.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

felix/config/config_params.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,10 @@ type Config struct {
412412
FlowLogsLocalReporter string `config:"oneof(Enabled,Disabled);Disabled"`
413413
FlowLogsPolicyEvaluationMode string `config:"oneof(None,Continuous);Continuous"`
414414

415-
KubeNodePortRanges []numorstring.Port `config:"portrange-list;30000:32767"`
416-
NATPortRange numorstring.Port `config:"portrange;"`
417-
NATOutgoingAddress net.IP `config:"ipv4;"`
415+
KubeNodePortRanges []numorstring.Port `config:"portrange-list;30000:32767"`
416+
NATPortRange numorstring.Port `config:"portrange;"`
417+
NATOutgoingAddress net.IP `config:"ipv4;"`
418+
NATOutgoingExclusions string `config:"oneof(IPPoolsOnly,IPPoolsAndHostIPs);IPPoolsOnly"`
418419

419420
UsageReportingEnabled bool `config:"bool;true"`
420421
UsageReportingInitialDelaySecs time.Duration `config:"seconds;300"`

felix/dataplane/driver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ func StartDataplaneDriver(
288288
NATPortRange: configParams.NATPortRange,
289289
IptablesNATOutgoingInterfaceFilter: configParams.IptablesNATOutgoingInterfaceFilter,
290290
NATOutgoingAddress: configParams.NATOutgoingAddress,
291+
NATOutgoingExclusions: configParams.NATOutgoingExclusions,
291292
BPFEnabled: configParams.BPFEnabled,
292293
BPFForceTrackPacketsFromIfaces: replaceWildcards(configParams.NFTablesMode == "Enabled", configParams.BPFForceTrackPacketsFromIfaces),
293294
ServiceLoopPrevention: configParams.ServiceLoopPrevention,

felix/docs/config-params.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

felix/docs/config-params.md

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

felix/rules/nat.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"sort"
2020
"strings"
2121

22+
apiv3 "github.com/projectcalico/api/pkg/apis/projectcalico/v3"
23+
2224
tcdefs "github.com/projectcalico/calico/felix/bpf/tc/defs"
2325
. "github.com/projectcalico/calico/felix/generictables"
2426
)
@@ -58,6 +60,12 @@ func (r *DefaultRuleRenderer) makeNATOutgoingRuleIPTables(ipVersion uint8, proto
5860
SourceIPSet(masqIPsSetName).
5961
NotDestIPSet(allIPsSetName)
6062

63+
check := apiv3.NATOutgoingExclusionsType(r.Config.NATOutgoingExclusions)
64+
if check == apiv3.NATOutgoingExclusionsIPPoolsAndHostIPs {
65+
allHostsIPsSetName := ipConf.NameForMainIPSet(IPSetIDAllHostNets)
66+
match = match.NotDestIPSet(allHostsIPsSetName)
67+
}
68+
6169
if protocol != "" {
6270
match = match.Protocol(protocol)
6371
}

felix/rules/nat_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@ var _ = Describe("NAT", func() {
6060
},
6161
}))
6262
})
63+
It("should render rules when active with all hosts NAT exclusion", func() {
64+
localConfig := rrConfigNormal
65+
localConfig.NATOutgoingExclusions = "IPPoolsAndHostIPs"
66+
renderer = NewRenderer(localConfig)
67+
68+
Expect(renderer.NATOutgoingChain(true, 4)).To(Equal(&generictables.Chain{
69+
Name: "cali-nat-outgoing",
70+
Rules: []generictables.Rule{
71+
{
72+
Action: MasqAction{},
73+
Match: Match().
74+
SourceIPSet("cali40masq-ipam-pools").
75+
NotDestIPSet("cali40all-ipam-pools").
76+
NotDestIPSet("cali40all-hosts-net"),
77+
},
78+
},
79+
}))
80+
})
6381
It("should render rules when active with an explicit SNAT address", func() {
6482
snatAddress := "192.168.0.1"
6583
localConfig := rrConfigNormal

felix/rules/rule_defs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ type Config struct {
434434
IptablesNATOutgoingInterfaceFilter string
435435

436436
NATOutgoingAddress net.IP
437+
NATOutgoingExclusions string
437438
BPFEnabled bool
438439
BPFForceTrackPacketsFromIfaces []string
439440
ServiceLoopPrevention string

libcalico-go/config/crd/crd.projectcalico.org_felixconfigurations.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libcalico-go/lib/backend/syncersv1/updateprocessors/configurationprocessor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const (
4343
)
4444

4545
const (
46-
numBaseFelixConfigs = 161
46+
numBaseFelixConfigs = 162
4747
)
4848

4949
var _ = Describe("Test the generic configuration update processor and the concrete implementations", func() {

manifests/calico-bpf.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/calico-policy-only.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/calico-typha.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/calico-vxlan.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/calico.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/canal.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/crds.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/flannel-migration/calico.yaml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)