Skip to content

Commit

Permalink
pods in nat-outgoing shoul dnot SNAT to local host
Browse files Browse the repository at this point in the history
When a pod is accessing a local host, it should not get SNATed as the
host when it is in a nat-outgoing ippool. (a) it is unnecessary as the
local node can be accessed and (b) there is no way to return the traffic
as is it would return to the host itself.

refs #7252
  • Loading branch information
tomastigera committed Jan 31, 2024
1 parent 3533227 commit 6051e13
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion felix/bpf-gpl/tc.c
Expand Up @@ -445,7 +445,12 @@ static CALI_BPF_INLINE void calico_tc_process_ct_lookup(struct cali_tc_ctx *ctx)

// Check whether the workload needs outgoing NAT to this address.
if (r->flags & CALI_RT_NAT_OUT) {
if (!(cali_rt_lookup_flags(&ctx->state->post_nat_ip_dst) & CALI_RT_IN_POOL)) {
struct cali_rt *rt = cali_rt_lookup(&ctx->state->post_nat_ip_dst);
enum cali_rt_flags flags = CALI_RT_UNKNOWN;
if (rt) {
flags = rt->flags;
}
if (!(flags & CALI_RT_IN_POOL) && !cali_rt_flags_local_host(flags)) {
CALI_DEBUG("Source is in NAT-outgoing pool "
"but dest is not, need to SNAT.\n");
ctx->state->flags |= CALI_ST_NAT_OUTGOING;
Expand Down
3 changes: 3 additions & 0 deletions felix/fv/bpf_test.go
Expand Up @@ -375,6 +375,8 @@ func describeBPFTests(opts ...bpfTestOpt) bool {
if testOpts.dsr {
options.ExtraEnvVars["FELIX_BPFExternalServiceMode"] = "dsr"
}
// ACCEPT is what is set by our manifests and operator by default.
options.ExtraEnvVars["FELIX_DefaultEndpointToHostAction"] = "ACCEPT"
options.ExternalIPs = true
options.ExtraEnvVars["FELIX_BPFExtToServiceConnmark"] = "0x80"
if !testOpts.ipv6 {
Expand Down Expand Up @@ -1479,6 +1481,7 @@ func describeBPFTests(opts ...bpfTestOpt) bool {
It("should handle NAT outgoing", func() {
By("SNATting outgoing traffic with the flag set")
cc.ExpectSNAT(w[0][0], felixIP(0), hostW[1])
cc.Expect(Some, w[0][0], hostW[0]) // no snat
cc.CheckConnectivity(conntrackChecks(tc.Felixes)...)

if testOpts.tunnel == "none" {
Expand Down

0 comments on commit 6051e13

Please sign in to comment.