-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add fallback to load BPF programs without calico_tc_skb_ipv4_frag on failure #11327
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: tomastigera <[email protected]>
Co-authored-by: tomastigera <[email protected]>
Co-authored-by: tomastigera <[email protected]>
…eturn Co-authored-by: tomastigera <[email protected]>
Co-authored-by: tomastigera <[email protected]>
felix/bpf/libbpf/libbpf.go
Outdated
|
|
||
| // SetProgramAutoload sets whether a program should be automatically loaded. | ||
| // When set to false, the program will not be loaded when Load() is called. | ||
| func (o *Obj) SetProgramAutoload(progName string, autoload bool) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot update libbpf_stub.go as well with an empty implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in ad1ca79
Co-authored-by: tomastigera <[email protected]>
There was a problem hiding this 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 adds a fallback mechanism to handle BPF program loading failures on kernels that don't support the calico_tc_skb_ipv4_frag program. When the initial load fails, the system retries without the IP defragmentation program.
- Adds libbpf bindings for controlling program autoload via
bpf_program__set_autoload() - Implements retry logic in
loadObj()to disable and skip the IP defrag program on load failure - Refactors map configuration into a reusable helper function
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| felix/bpf/libbpf/libbpf_api.h | Adds C wrapper bpf_set_program_autoload() to expose libbpf's autoload control function |
| felix/bpf/libbpf/libbpf.go | Implements Go binding SetProgramAutoload() for CGO builds |
| felix/bpf/libbpf/libbpf_stub.go | Adds stub implementation of SetProgramAutoload() for non-CGO builds |
| felix/bpf/hook/map.go | Implements fallback logic and extracts configureMaps() helper to reduce duplication |
| _codeql_detected_source_root | CodeQL configuration file (not a functional change) |
Co-authored-by: Copilot <[email protected]>
felix/bpf/libbpf/libbpf.go
Outdated
|
|
||
| // SetProgramAutoload sets whether a program should be automatically loaded. | ||
| // When set to false, the program will not be loaded when Load() is called. | ||
| func (o *Obj) SetProgramAutoload(progName string, autoload bool) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot This function never returns an error. Amend the stub as well and do not handle the error where this function is called
| func (o *Obj) SetProgramAutoload(progName string, autoload bool) error { | |
| func (o *Obj) SetProgramAutoload(progName string, autoload bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in ccdc113 - changed function signature to not return error in both libbpf.go and libbpf_stub.go, and updated the caller in map.go to not handle the error.
Co-authored-by: tomastigera <[email protected]>
Summary
This PR implements a fallback mechanism for loading BPF programs when the
calico_tc_skb_ipv4_fragprogram causes loading failures on kernels that don't support it.Changes:
bpf_set_program_autoload()C wrapper to expose libbpf'sbpf_program__set_autoload()SetProgramAutoload()Go binding in libbpf package (both CGO and stub implementations)loadObj()to retry without IP defrag program on load failure whenat.hasIPDefrag()is trueallocateLayout()to skip the IP defrag program when explicitly disabledconfigureMaps()helper to reduce code duplicationBehavior:
When
obj.Load()fails at lines 206-208 andat.hasIPDefrag()is true:calico_tc_skb_ipv4_fragusingbpf_program__set_autoload()Tail calls into the disabled program will fail, but this is acceptable as per requirements.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.