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

feat: implement checksum #325

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jokestax
Copy link
Contributor

Description

  • Use bpf_l3_csum_replace and bpf_l4_csum_replace instead of bpf_csum_diff.
  • Implement checksum updates for both IP and TCP headers after modifying source IP/port.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 21, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jokestax
Once this PR has been reviewed and has the lgtm label, please assign shaneutt for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 21, 2024
@shaneutt shaneutt linked an issue Jan 6, 2025 that may be closed by this pull request
2 tasks
@shaneutt
Copy link
Member

shaneutt commented Jan 6, 2025

Heya 👋 I noticed this was draft, were you needing some more time for changes before reviews or did you want review while in draft?

@jokestax
Copy link
Contributor Author

jokestax commented Jan 6, 2025

Hello,I’d appreciate a review on this draft to ensure I’m heading in the right direction before proceeding with similar changes for ICMP

Comment on lines -65 to -70
bpf_csum_diff(
mem::MaybeUninit::zeroed().assume_init(),
0,
ip_hdr as *mut u32,
Ipv4Hdr::LEN as u32,
0,
Copy link
Member

Choose a reason for hiding this comment

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

You'll see in the libbpf documentation that the bpf_l4_csum_replace function is intended for use with the bpf_csum_diff function:

https://docs.ebpf.io/linux/helper-function/bpf_l4_csum_replace/

So I'm not sure we want to remove this here. We should probably take a look at other solutions and glean what we can from how they're doing things:

https://github.com/projectcalico/calico/blob/c9931c13faf316703e45ada9b9042439830c082d/felix/bpf-gpl/tc.c#L1580

Copy link
Member

Choose a reason for hiding this comment

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

Just a thought that occurred to me: it would probably be good to take a peek at what Cilium is doing as well and cross reference between this and calico (and maybe others) to glean some insights.

Comment on lines +69 to +74
bpf_l3_csum_replace(
ctx.skb.skb,
4u32,
old_src_addr as u64,
lb_mapping.backend_key.ip.to_be() as u64,
4,
Copy link
Member

Choose a reason for hiding this comment

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

Aya provides helper methods for this that chain all the way up to the TcContext, so you don't have to include these functions directly but could instead do ctx.l3_csum_replace.

Comment on lines +84 to +90
bpf_l4_csum_replace(
ctx.skb.skb,
tcp_header_offset as u32,
old_src_port as u64,
lb_mapping.backend_key.port.to_be() as u64,
2,
)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, you should be able to do ctx.l4_csum_replace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
Status: Review
Development

Successfully merging this pull request may close these issues.

Implement checksums properly in dataplane
3 participants