Skip to content

Commit

Permalink
add felixConfiguration attr: DisableHostSubnetNATExclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
wayne-cheng committed Oct 8, 2024
1 parent b3cc67c commit bae1508
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 6 deletions.
4 changes: 4 additions & 0 deletions api/pkg/apis/projectcalico/v3/felixconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ type FelixConfigurationSpec struct {
// (ie it uses the iptables MASQUERADE target)
NATOutgoingAddress string `json:"natOutgoingAddress,omitempty"`

// When set to true and ip pool setting `natOutgoing` is true, packets sent from Calico networked containers in this pool
// to cluster host subnet will not be excluded from being masqueraded. [Default: false]
DisableHostSubnetNATExclusion bool `json:"disableHostSubnetNATExclusion,omitempty"`

// This is the IPv4 source address to use on programmed device routes. By default the source address is left blank,
// leaving the kernel to choose the source address used.
DeviceRouteSourceAddress string `json:"deviceRouteSourceAddress,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions api/pkg/openapi/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions felix/config/config_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,10 @@ type Config struct {
FailsafeInboundHostPorts []ProtoPort `config:"port-list;tcp:22,udp:68,tcp:179,tcp:2379,tcp:2380,tcp:5473,tcp:6443,tcp:6666,tcp:6667;die-on-fail"`
FailsafeOutboundHostPorts []ProtoPort `config:"port-list;udp:53,udp:67,tcp:179,tcp:2379,tcp:2380,tcp:5473,tcp:6443,tcp:6666,tcp:6667;die-on-fail"`

KubeNodePortRanges []numorstring.Port `config:"portrange-list;30000:32767"`
NATPortRange numorstring.Port `config:"portrange;"`
NATOutgoingAddress net.IP `config:"ipv4;"`
KubeNodePortRanges []numorstring.Port `config:"portrange-list;30000:32767"`
NATPortRange numorstring.Port `config:"portrange;"`
NATOutgoingAddress net.IP `config:"ipv4;"`
DisableHostSubnetNATExclusion bool `config:"bool;false"`

UsageReportingEnabled bool `config:"bool;true"`
UsageReportingInitialDelaySecs time.Duration `config:"seconds;300"`
Expand Down
1 change: 1 addition & 0 deletions felix/dataplane/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func StartDataplaneDriver(configParams *config.Config,
NATPortRange: configParams.NATPortRange,
IptablesNATOutgoingInterfaceFilter: configParams.IptablesNATOutgoingInterfaceFilter,
NATOutgoingAddress: configParams.NATOutgoingAddress,
DisableHostSubnetNATExclusion: configParams.DisableHostSubnetNATExclusion,
BPFEnabled: configParams.BPFEnabled,
BPFForceTrackPacketsFromIfaces: replaceWildcards(configParams.NFTablesMode == "Enabled", configParams.BPFForceTrackPacketsFromIfaces),
ServiceLoopPrevention: configParams.ServiceLoopPrevention,
Expand Down
9 changes: 6 additions & 3 deletions felix/rules/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ func (r *DefaultRuleRenderer) makeNATOutgoingRuleBPF(version uint8, protocol str
func (r *DefaultRuleRenderer) makeNATOutgoingRuleIPTables(ipVersion uint8, protocol string, action Action) Rule {
ipConf := r.ipSetConfig(ipVersion)
allIPsSetName := ipConf.NameForMainIPSet(IPSetIDNATOutgoingAllPools)
allHostsIPsSetName := ipConf.NameForMainIPSet(IPSetIDAllHostNets)
masqIPsSetName := ipConf.NameForMainIPSet(IPSetIDNATOutgoingMasqPools)

match := r.NewMatch().
SourceIPSet(masqIPsSetName).
NotDestIPSet(allIPsSetName).
NotDestIPSet(allHostsIPsSetName)
NotDestIPSet(allIPsSetName)

if !r.Config.DisableHostSubnetNATExclusion {
allHostsIPsSetName := ipConf.NameForMainIPSet(IPSetIDAllHostNets)
match = match.NotDestIPSet(allHostsIPsSetName)
}

if protocol != "" {
match = match.Protocol(protocol)
Expand Down
1 change: 1 addition & 0 deletions felix/rules/rule_defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ type Config struct {
IptablesNATOutgoingInterfaceFilter string

NATOutgoingAddress net.IP
DisableHostSubnetNATExclusion bool
BPFEnabled bool
BPFForceTrackPacketsFromIfaces []string
ServiceLoopPrevention string
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/calico-bpf.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/calico-policy-only.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/calico-typha.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/calico-vxlan.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/calico.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/canal.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/crds.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/flannel-migration/calico.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/ocp/crd.projectcalico.org_felixconfigurations.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/operator-crds.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions manifests/tigera-operator.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bae1508

Please sign in to comment.