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(conntrack): bpf code for conntrack + conntrack GC #610

Merged
merged 30 commits into from
Aug 29, 2024

Conversation

nddq
Copy link
Contributor

@nddq nddq commented Aug 15, 2024

Description

Part of #283, broken down for ease of review. Testing results will be added in #624

Related Issue

If this pull request is related to any issue, please mention it here. Additionally, make sure that the issue is assigned to you before submitting this pull request.

Checklist

  • I have read the contributing documentation.
  • I signed and signed-off the commits (git commit -S -s ...). See this documentation on signing commits.
  • I have correctly attributed the author(s) of the code.
  • I have tested the changes locally.
  • I have followed the project's style guidelines.
  • I have updated the documentation, if necessary.
  • I have added tests, if applicable.

Screenshots (if applicable) or Testing Completed

Please add any relevant screenshots or GIFs to showcase the changes made.

Additional Notes

Add any additional notes or context about the pull request here.


Please refer to the CONTRIBUTING.md file for more information on how to contribute to this project.

@nddq nddq added type/enhancement New feature or request lang/go The Go Programming Language area/ebpf priority/0 P0 lang/c The C Programming Language scope/M Change is Medium labels Aug 15, 2024
@nddq nddq self-assigned this Aug 15, 2024
@nddq nddq requested a review from a team as a code owner August 15, 2024 21:03
@nddq nddq requested review from rbtr and matmerr August 15, 2024 21:03
@nddq nddq mentioned this pull request Aug 15, 2024
11 tasks
@nddq nddq removed request for rbtr and matmerr August 20, 2024 22:10
Copy link
Contributor

@anubhabMajumdar anubhabMajumdar left a comment

Choose a reason for hiding this comment

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

Need some detailed Testing Done for this piece of code. I suggest adding a Snapshot function in conntrack_linux.go to test from userspace.

pkg/plugin/conntrack/conntrack_linux.go Show resolved Hide resolved
@nddq nddq mentioned this pull request Aug 29, 2024
@nddq nddq added this pull request to the merge queue Aug 29, 2024
Merged via the queue into main with commit 86fa3bd Aug 29, 2024
22 checks passed
@nddq nddq deleted the nddq/feat/conntrackbpf branch August 29, 2024 20:51
* @arg observation_point The point in the network stack where the packet is observed.
* Returns true if the packet should be report to userspace. False otherwise.
*/
static __always_inline __attribute__((unused)) bool ct_process_packet(struct ct_v4_key key, __u8 flags, __u8 observation_point) {
Copy link
Contributor

Choose a reason for hiding this comment

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

key can be passed as a pointer like you do in other functions to avoid copying

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, my initial plan was to pass in the pointer to the packet into conntrack and then construct the key within ct_process_packet. That way we don't have to do the subsequent function call to get the traffic_direction and is_reply
image
and instead, we can do it within ct_process_packet. However, we will need to relocate the packet struct to conntrack since cycle dependency is not allowed, i think. Curious about your opinion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't understand - why cannot we pass a pointer to they input key here - this function on;y seems to be accessing its values.

Where would we have a cyclical dependency? (Do you mean the eBPF verifier fails on that?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC, and i could be wrong, there was some issue with the verifier when passing the key pointer from packetparser to conntrack, i can test it again to verify.
The cyclical dependency is applied to the statement where i wanted to pass the packet pointer from packetparser to conntrack. Since packetparser is already importing conntrack, conntrack can't import packetparser back to get the packet struct def. The reason why I think we should be passing the packet pointer to conntrack is because so that we don't have to do subsequent map look up for is_reply and traffic_direction, but instead set in immediately in ct_process_packet

Copy link
Contributor

@rectified95 rectified95 left a comment

Choose a reason for hiding this comment

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

Nice job!

github-merge-queue bot pushed a commit that referenced this pull request Sep 6, 2024
# Description

Part 2 of #610
## Related Issue

If this pull request is related to any issue, please mention it here.
Additionally, make sure that the issue is assigned to you before
submitting this pull request.

## Checklist

- [ ] I have read the [contributing
documentation](https://retina.sh/docs/contributing).
- [ ] I signed and signed-off the commits (`git commit -S -s ...`). See
[this
documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
on signing commits.
- [ ] I have correctly attributed the author(s) of the code.
- [ ] I have tested the changes locally.
- [ ] I have followed the project's style guidelines.
- [ ] I have updated the documentation, if necessary.
- [ ] I have added tests, if applicable.

## Screenshots (if applicable) or Testing Completed
Output from debug CLI tool:

![image](https://github.com/user-attachments/assets/4798f877-7931-4d44-8d1f-ca60c4ceda3f)
Hubble flow logs:

![image](https://github.com/user-attachments/assets/10dff07f-24cc-4587-b18f-28f748fa0c33)

## Additional Notes

Add any additional notes or context about the pull request here.

---

Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more
information on how to contribute to this project.

---------

Signed-off-by: Quang Nguyen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ebpf lang/c The C Programming Language lang/go The Go Programming Language priority/0 P0 scope/M Change is Medium type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants