Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-v3.28] Auto pick #9192: traffic from host should return through host #9199

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions felix/bpf-gpl/tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1319,12 +1319,22 @@ int calico_tc_skb_new_flow_entrypoint(struct __sk_buff *skb)
if (CALI_F_TO_HOST && state->flags & CALI_ST_SKIP_FIB) {
ct_ctx_nat->flags |= CALI_CT_FLAG_SKIP_FIB;
}
/* Packets received at WEP with CALI_CT_FLAG_SKIP_FIB mark signal
* that all traffic on this connection must flow via host namespace as it was
* originally meant for host, but got redirected to a WEP by a 3rd party DNAT rule.
*/
if (CALI_F_TO_WEP && ((ctx->skb->mark & CALI_SKB_MARK_SKIP_FIB) == CALI_SKB_MARK_SKIP_FIB)) {
ct_ctx_nat->flags |= CALI_CT_FLAG_SKIP_FIB;
if (CALI_F_TO_WEP) {
if (!(ctx->skb->mark & CALI_SKB_MARK_SEEN)) {
/* If the packet wasn't seen, must come from host. There is no
* need to do FIB lookup for returning traffic. In fact, it may
* not be always correct, e.g. when some mesh and custom iptables
* rules are used by the host. So don't mess with it.
*/
ct_ctx_nat->flags |= CALI_CT_FLAG_SKIP_FIB;
} else if ((ctx->skb->mark & CALI_SKB_MARK_SKIP_FIB) == CALI_SKB_MARK_SKIP_FIB) {
/* Packets received at WEP with CALI_CT_FLAG_SKIP_FIB mark signal
* that all traffic on this connection must flow via host
* namespace as it was originally meant for host, but got
* redirected to a WEP by a 3rd party DNAT rule.
*/
ct_ctx_nat->flags |= CALI_CT_FLAG_SKIP_FIB;
}
}
if (CALI_F_TO_HOST && CALI_F_NAT_IF) {
ct_ctx_nat->flags |= CALI_CT_FLAG_VIA_NAT_IF;
Expand Down
16 changes: 16 additions & 0 deletions felix/fv/bpf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,22 @@ func describeBPFTests(opts ...bpfTestOpt) bool {
cc.ResetExpectations()
}
})

It("should respond back to host is the original traffic came from the host", func() {
if testOpts.ipv6 {
return
}

By("Setting up istio-like rules that SNAT host as link-local IP")

tc.Felixes[0].Exec("iptables", "-t", "nat", "-A", "POSTROUTING", "-d", w[0].IP, "-j",
"SNAT", "--to-source", "169.254.7.127")

By("Testing connectivity from host to pod")

cc.Expect(Some, hostW, w[0], ExpectWithSrcIPs("169.254.7.127"))
cc.CheckConnectivity()
})
}

if testOpts.nonProtoTests {
Expand Down