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: nodeport: consolidate packet rewrite in RevDNAT path #26852

Merged
merged 4 commits into from
Jul 17, 2023

Conversation

julianwiedmann
Copy link
Member

@julianwiedmann julianwiedmann commented Jul 16, 2023

This adds some smarts to the nodeport helpers, so that it's possible to split up the RevDNAT lookup (what IP/port to use for the RevDNAT) and the actual packet rewrite. This allows us to use the same helper code for the rewrite, regardless whether the reply comes from a local or a DSR backend.

It's a nice simplification on its own, but will also enable a follow-on fix in the RevDNAT path (#26638) that would otherwise be rejected by the verifier. So we'll backport this PR accordingly, once that fix is ready to merged.

@julianwiedmann julianwiedmann added sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. release-note/misc This PR makes changes that have no direct user impact. kind/complexity-issue Relates to BPF complexity or program size issues area/loadbalancing Impacts load-balancing and Kubernetes service implementations labels Jul 16, 2023
@julianwiedmann
Copy link
Member Author

/test

@julianwiedmann
Copy link
Member Author

/test

@julianwiedmann julianwiedmann changed the title 1.15 bpf dsr revdnat bpf: nodeport: consolidate packet rewrite in RevDNAT path Jul 17, 2023
@julianwiedmann
Copy link
Member Author

#26638 needs a few more cycles until it's ready for primetime. But this part is good on its own already, so let's get started on review.

@julianwiedmann julianwiedmann marked this pull request as ready for review July 17, 2023 05:59
@julianwiedmann julianwiedmann requested a review from a team as a code owner July 17, 2023 05:59
return true;
}

if (check_dsr && entry->dsr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just return check_dsr && entry->dsr; ?

if (check_dsr && entry->dsr)
return true;

return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is identical with the v4 case. Maybe you can wrap the error checking and saving the rev_nat_index in an inline function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it 👍 See the pushed diff - two birds, one stone.

@maintainer-s-little-helper maintainer-s-little-helper bot added ready-to-merge This PR has passed all tests and received consensus from code owners to merge. labels Jul 17, 2023
@julianwiedmann
Copy link
Member Author

/test

@julianwiedmann julianwiedmann removed the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jul 17, 2023
In a following patch, we need easy access to the RevDNAT info for replies
by a local backend (from the LB*_REVERSE_NAT_MAP) and by a DSR backend
(from the SNAT_MAPPING_IPV* map).

For this we slightly rework the existing ct_has_nodeport_egress_entry*()
helpers, so that they return the rev_nat_index for non-DSR entries.

Then add a nodeport_rev_dnat_get_info_ipv*() helper that wraps the map
lookups for both cases, and returns the info as lb*_reverse_nat struct.

No functional change intended, the new helpers are not used yet.

Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
Align with lb6_rev_nat() and just pass in the needed parameters from the
ct_state struct. This enables a subsequent patch that wants to call
__lb4_rev_nat() without a ct_state struct.

Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
The RevDNAT path currently uses __lb*_rev_nat() for rewriting replies by
local backends, and snat_v*_rewrite_egress() for rewriting DSR replies.

Both end up doing pretty much the same thing (we currently don't need the
ICMP support in the snat_* version), so switch the DSR path to also use
__lb*_rev_nat(). For this we employ the new nodeport_rev_dnat_get_info_*()
helpers that convert the DSR SNAT entry to lb*_reverse_nat struct.

Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
Now that we have access to the SNAT info which was used to rewrite the
inner packet, we no longer need to peek into the L3 header to obtain the
new source IP.

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 Jul 17, 2023
@julianwiedmann julianwiedmann merged commit e909425 into cilium:main Jul 17, 2023
65 checks passed
@julianwiedmann julianwiedmann deleted the 1.15-bpf-dsr-revdnat branch July 17, 2023 13:24
@sayboras sayboras mentioned this pull request Aug 3, 2023
11 tasks
@julianwiedmann julianwiedmann added the backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. label Aug 9, 2023
@michi-covalent michi-covalent added backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. and removed backport-pending/1.14 The backport for Cilium 1.14.x for this PR is in progress. labels Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/loadbalancing Impacts load-balancing and Kubernetes service implementations backport-done/1.14 The backport for Cilium 1.14.x for this PR is done. kind/complexity-issue Relates to BPF complexity or program size issues ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact. 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

3 participants