Skip to content

Optimize ebpf programs #387

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Pavani-Panakanti
Copy link
Contributor

Issue #, if available:
Updating bpf program files to follow best practices

Description of changes:

  • functions should be always inline
  • number of arguments to a func should be less than 5
  • arguments should be passed as pointers than values

Testing
Cyclonus tests passed for both v4 and v6 with standard and strict mode

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Pavani-Panakanti Pavani-Panakanti requested a review from a team as a code owner April 14, 2025 19:36
@jayanthvn jayanthvn requested a review from Copilot May 31, 2025 18:19
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes the eBPF programs by updating function signatures and argument usage to follow best practices. Key changes include:

  • Changing functions from static inline to static __always_inline.
  • Reducing function arguments by removing the ip and l4_dst_port parameters.
  • Updating protocol and port comparisons to use flow_key values.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/ebpf/c/tc.v6ingress.bpf.c Updated evaluateByLookUp: changed signature and replaced ip/l4_dst_port usage with flow_key values.
pkg/ebpf/c/tc.v6egress.bpf.c Updated evaluateByLookUp: changed signature and replaced ip/l4_dst_port usage with flow_key values.
pkg/ebpf/c/tc.v4ingress.bpf.c Updated evaluateByLookUp: changed signature and replaced ip/l4_dst_port usage with flow_key values.
pkg/ebpf/c/tc.v4egress.bpf.c Updated evaluateByLookUp: changed signature and replaced ip/l4_dst_port usage with flow_key values.
Comments suppressed due to low confidence (4)

pkg/ebpf/c/tc.v6ingress.bpf.c:101

  • The update to remove the ip and l4_dst_port parameters aligns with reducing function complexity; please verify that flow_key provides all the needed protocol and port information in every use case.
static __always_inline int evaluateByLookUp(struct keystruct trie_key, struct conntrack_key flow_key, struct pod_state *pst, struct data_t evt) {

pkg/ebpf/c/tc.v6egress.bpf.c:99

  • The removal of the ip and l4_dst_port parameters simplifies the function interface; please ensure that replacing these with flow_key values consistently meets the logic requirements.
static __always_inline int evaluateByLookUp(struct keystruct trie_key, struct conntrack_key flow_key, struct pod_state *pst, struct data_t evt) {

pkg/ebpf/c/tc.v4ingress.bpf.c:98

  • The updated signature removes unused parameters, which is a good improvement; please confirm that the flow_key fully substitutes the protocol and port values originally provided by ip and l4_dst_port.
static __always_inline int evaluateByLookUp(struct keystruct trie_key, struct conntrack_key flow_key, struct pod_state *pst, struct data_t evt) {

pkg/ebpf/c/tc.v4egress.bpf.c:98

  • Removing the ip and l4_dst_port parameters adheres to the best practice of limiting function arguments; please ensure that using flow_key for protocol and destination port comparison is adequate for all intended packet handling scenarios.
static __always_inline int evaluateByLookUp(struct keystruct trie_key, struct conntrack_key flow_key, struct pod_state *pst, struct data_t evt) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants