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

bpf: lb: deal with stale rev_nat_index after svc lookup in fallback path #24757

Merged

Conversation

julianwiedmann
Copy link
Member

@julianwiedmann julianwiedmann commented Apr 5, 2023

Fix two corner-case bugs in the fallback path for lb_local(), when a previously selected backend is unavailable. In this case we perform a fresh svc lookup, and thus need to handle that the new svc entry is associated with a different rev_nat_index.

@julianwiedmann julianwiedmann added kind/bug This is a bug in the Cilium logic. sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. release-note/bug This PR fixes an issue in a previous release of Cilium. labels Apr 5, 2023
@julianwiedmann
Copy link
Member Author

/test

@julianwiedmann
Copy link
Member Author

Note that https://github.com/julianwiedmann/cilium/blob/03ee82df8229363e0b2966afefcdf2e7984320f9/bpf/lib/lb.h#L1635 is also missing a ct_update_rev_nat_index(). So right now the CT_SERVICE entry would have stale info in such a case as well.

@julianwiedmann
Copy link
Member Author

/test

@julianwiedmann
Copy link
Member Author

/test-1.26-net-next

@julianwiedmann julianwiedmann changed the title bpf: nodeport: fix rev_nat_index check for NAT CT entries bpf: lb: deal with stale rev_nat_index after svc lookup in fallback path May 9, 2023
@julianwiedmann julianwiedmann marked this pull request as ready for review May 10, 2023 06:57
@julianwiedmann julianwiedmann requested a review from a team as a code owner May 10, 2023 06:57
bpf/lib/nodeport.h Show resolved Hide resolved
bpf/lib/lb.h Outdated Show resolved Hide resolved
The caller expects us to reflect back a valid state->rev_nat_index
(that matches svc->rev_nat_index).

- On CT_NEW we already assign this, as part of creating the CT entry.
- On CT_REPLY the obtained state->rev_nat_index will already contain some
  value, and we subsequently check whether it still matches the selected
  svc entry (and update accordingly).

So the additional assignment at the `update_state` label is not required.

Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
lb*_local() has a fallback path for when the previously selected backend
for a svc connection is no longer available. In this case we perform a
fresh svc lookup, and select a new backend.

As this can potentially return a different svc entry, make sure to also
update the rev_nat_index in the CT_SERVICE entry. Otherwise the backend
lookup for the *next* packet will detect a mismatch between svc and
CT entry, and trigger a fresh backend selection.

Also reflect the new rev_nat_index back to the caller in the ct_state
struct.

Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
For non-DSR connections, the nodeport code creates a special CT_EGRESS
entry to maintain its own state (and eg. trigger RevDNAT from it).

This CT entry also tracks the service's rev_nat_index. On a successful
CT lookup, we detect a stale entry by comparing its rev_nat_index to
the currently matched svc's rev_nat_index.

But there's a special case in lb*_lookup() where the backend lookup fails,
and we fall back to a fresh svc lookup. The new svc entry isn't reflected
back to the callers, and consequently they would use the wrong
svc->rev_nat_index to check for staleness of their CT entry.

The actual rev_nat_index *is* reflected back to the caller via the
passed-in ct_state_new struct. So use that for the staleness check instead.

Note that this matches how bpf_lxc determines the current rev_nat_index
in lb*_ctx_store_state().

Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
@julianwiedmann
Copy link
Member Author

/test

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label May 10, 2023
@julianwiedmann julianwiedmann merged commit 322387f into cilium:main May 11, 2023
57 checks passed
@julianwiedmann julianwiedmann deleted the 1.14-nodeport-rev_nat-index branch May 11, 2023 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug This is a bug in the Cilium logic. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/bug This PR fixes an issue in a previous release of Cilium. sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants