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

Reduce the amount of repeating code in CT #25356

Merged
merged 3 commits into from May 17, 2023
Merged

Conversation

gentoo-root
Copy link
Contributor

Pure refactoring, no behavioral change.

@gentoo-root gentoo-root added the release-note/misc This PR makes changes that have no direct user impact. label May 10, 2023
The switch in ct_lookup4 is almost identical to ct_extract_ports4. Reuse
the existing function with a slight modification.

Signed-off-by: Maxim Mikityanskiy <maxim@isovalent.com>
@gentoo-root gentoo-root marked this pull request as ready for review May 10, 2023 17:09
@gentoo-root gentoo-root requested a review from a team as a code owner May 10, 2023 17:09
@qmonnet qmonnet added sig/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. kind/cleanup This includes no functional changes. labels May 10, 2023
Copy link
Member

@qmonnet qmonnet left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

Nit: In 2nd commit, some comment blocks could be re-wrapped now that they have less left-indent.

ICMP_FRAG_NEEDED handling in snat_v4_rev_nat is pretty self-contained,
and three indentation levels can easily be saved by moving this code
into a separate function with just slight modifications.

Signed-off-by: Maxim Mikityanskiy <maxim@isovalent.com>
@gentoo-root
Copy link
Contributor Author

Nit: In 2nd commit, some comment blocks could be re-wrapped now that they have less left-indent.

Done.

Copy link
Member

@julianwiedmann julianwiedmann left a comment

Choose a reason for hiding this comment

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

💯 on the ct_extract_ports4() patch!

I'm less convinced that the ICMP_FRAG_NEEDED patch is truly making it easier to understand things, but not feeling strongly about it either. But should we give the ICMPV6_PKT_TOOBIG part the same treatment then?

Comment on lines +1070 to +1072
struct ipv4_ct_tuple tuple = {};
struct ipv4_nat_entry *state;
struct iphdr iphdr;
Copy link
Member

Choose a reason for hiding this comment

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

Just for context - when initially adding this code (a short while back), there was concern whether we should share the CT tuple (for processing the inner & outer packet), or have it cleanly separated. And how it would impact complexity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I wasn't aware of this context. What was the conclusion of that discussion? Shall I pass a pointer to tuple_buf to this function to reuse the one from the caller? Or there wasn't a clear conclusion?

Copy link
Member

Choose a reason for hiding this comment

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

What was the conclusion of that discussion?

We tried to share it as much as possible - but I don't think there was a final experiment on the latest code whether having it fully split up would trigger the verifier. So if we can do a clean split and still pass the verifier, I think that would be preferable.

Comment on lines +1137 to +1141
/* Switch back to the outer header. */
tuple.nexthdr = IPPROTO_ICMP;

return snat_v4_rewrite_ingress(ctx, &tuple, state, off);
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm slightly concerned that this part (how we NAT the outer headers) will over time drift apart from what we do in the "main" path. How bad would it be to only handle the inner SNAT here, and return to the main function for handling the outer SNAT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean just this function call return snat_v4_rewrite_ingress(ctx, &tuple, state, off);? I don't see what can drift here, rewriting the outer headers is already contained in a separate function, so that it can be reused from two different flows.

I can return 0 from here and goto rewrite_ingress in the caller on non-errors, but that's going to be uglier, and I don't see much point. Please tell me what you think.

Copy link
Member

Choose a reason for hiding this comment

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

You mean just this function call return snat_v4_rewrite_ingress(ctx, &tuple, state, off);? I don't see what can drift here, rewriting the outer headers is already contained in a separate function, so that it can be reused from two different flows.

The bad scenario would be that at some point we only modify the main path, without realizing that there's a second user buried somewhere else.

I can return 0 from here and goto rewrite_ingress in the caller on non-errors, but that's going to be uglier, and I don't see much point. Please tell me what you think.

Then let's not change it and keep your current approach :)

Copy link
Contributor Author

@gentoo-root gentoo-root left a comment

Choose a reason for hiding this comment

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

should we give the ICMPV6_PKT_TOOBIG part the same treatment then?

Good idea, I didn't notice IPv6 had a similar flow, because I mainly worked on IPv4 code for my bugfix. Let me do that too.

BTW, why don't we have ICMPV6_PKT_TOOBIG in snat_v6_nat, but only have it in revNAT?

Comment on lines +1137 to +1141
/* Switch back to the outer header. */
tuple.nexthdr = IPPROTO_ICMP;

return snat_v4_rewrite_ingress(ctx, &tuple, state, off);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean just this function call return snat_v4_rewrite_ingress(ctx, &tuple, state, off);? I don't see what can drift here, rewriting the outer headers is already contained in a separate function, so that it can be reused from two different flows.

I can return 0 from here and goto rewrite_ingress in the caller on non-errors, but that's going to be uglier, and I don't see much point. Please tell me what you think.

Comment on lines +1070 to +1072
struct ipv4_ct_tuple tuple = {};
struct ipv4_nat_entry *state;
struct iphdr iphdr;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I wasn't aware of this context. What was the conclusion of that discussion? Shall I pass a pointer to tuple_buf to this function to reuse the one from the caller? Or there wasn't a clear conclusion?

ICMPV6_PKT_TOOBIG handling in snat_v4_rev_nat is pretty self-contained,
and two indentation levels can easily be saved by moving this code into
a separate function with just slight modifications.

Signed-off-by: Maxim Mikityanskiy <maxim@isovalent.com>
@julianwiedmann
Copy link
Member

should we give the ICMPV6_PKT_TOOBIG part the same treatment then?

Good idea, I didn't notice IPv6 had a similar flow, because I mainly worked on IPv4 code for my bugfix. Let me do that too.

BTW, why don't we have ICMPV6_PKT_TOOBIG in snat_v6_nat, but only have it in revNAT?

Good question, I don't see it being discussed in #25054.

@gentoo-root
Copy link
Contributor 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 17, 2023
@aditighag aditighag merged commit 00429c1 into cilium:main May 17, 2023
57 checks passed
@aditighag
Copy link
Member

Ah! The read-to-merge label was added by mlh. /cc @julianwiedmann Not sure if you all your review comments were addressed (looks that way), please double check.

@julianwiedmann
Copy link
Member

Ah! The read-to-merge label was added by mlh. /cc @julianwiedmann Not sure if you all your review comments were addressed (looks that way), please double check.

All good, thanks! If it's green, merge we must.

@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from main in 1.12.10 May 24, 2023
@maintainer-s-little-helper maintainer-s-little-helper bot removed this from Needs backport from main in 1.12.10 May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup This includes no functional changes. 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

4 participants