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

Refactor: Use interface to configure libbpf global data when loading bpf programs. #9663

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sridhartigera
Copy link
Member

@sridhartigera sridhartigera commented Dec 31, 2024

Description

We have different set of global data one for Tc programs, one for CTLB and one for conntrack cleanup when loading bpf programs. Configuring each global has a separate API. This PR provides a single API to configure global data for bpf programs.

Related issues/PRs

Todos

  • Tests
  • Documentation
  • Release note

Release Note

TBD

Reminder for the reviewer

Make sure that this PR has the correct labels and milestone set.

Every PR needs one docs-* label.

  • docs-pr-required: This change requires a change to the documentation that has not been completed yet.
  • docs-completed: This change has all necessary documentation completed.
  • docs-not-required: This change has no user-facing impact and requires no docs.

Every PR needs one release-note-* label.

  • release-note-required: This PR has user-facing changes. Most PRs should have this label.
  • release-note-not-required: This PR has no user-facing changes.

Other optional labels:

  • cherry-pick-candidate: This PR should be cherry-picked to an earlier release. For bug fixes only.
  • needs-operator-pr: This PR is related to install and requires a corresponding change to the operator.

@sridhartigera sridhartigera added docs-not-required Docs not required for this change release-note-not-required Change has no user-facing impact labels Dec 31, 2024
@sridhartigera sridhartigera requested a review from a team as a code owner December 31, 2024 21:32
@marvin-tigera marvin-tigera added this to the Calico v3.30.0 milestone Dec 31, 2024
@sridhartigera sridhartigera changed the title Modify configuring libbpf global data Refactor: Use interface to configure libbpf global data when loading bpf programs. Jan 2, 2025
@@ -492,6 +485,20 @@ func XDPSetGlobals(
return err
}

func SetGlobalData(m *Map, data interface{}) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func SetGlobalData(m *Map, data interface{}) error {
func SetGlobalData(m *Map, data any) error {

func SetGlobalData(m *Map, data interface{}) error {
switch v := data.(type) {
case *TcGlobalData:
return tcSetGlobals(m, v)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not to have this function to be a method of each of the globals structs and then define an interface with that method (if need be) and call that method rather than using any and this switch?

@@ -145,17 +145,17 @@ func (s *BPFProgLivenessScanner) ensureBPFExpiryProgram() (*libbpf.Obj, error) {
continue
}

err := libbpf.CTCleanupSetGlobals(
err := libbpf.SetGlobalData(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be?

Suggested change
err := libbpf.SetGlobalData(
err := &libbpf.CTCleanupGlobalData{...}.Set(m)

Copy link
Member Author

Choose a reason for hiding this comment

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

Prefer doing it this way. Will update the PR shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required Docs not required for this change release-note-not-required Change has no user-facing impact
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants