Remove ebpf_link_mark_as_legacy_mode #4690
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Resolves: #4675
Modify ebpf_program_atttach* APIs so they can emulate the old libbpf attach (with out links) as well as the new libbpf attach style (with links).
Removed temporary ebpf_link_mark_as_legacy_mode API.
Testing
CI/CD
Documentation
Updated API doxygen.
Installation
No.
This pull request refactors the eBPF user-mode API to simplify program attachment workflows and management of link lifetimes. The main change is to make the output link pointer optional in program attach APIs, and to internalize legacy mode handling so callers no longer need to manually mark links as legacy. Several APIs and internal functions are updated to reflect these changes, and related cleanup is performed in both the API and sample code.
API and Function Signature Changes
struct bpf_link** link) and link file descriptor (fd_t* link) parameters optional in all eBPF program attach APIs (ebpf_program_attach,ebpf_program_attach_by_fd,ebpf_program_attach_by_fds), by changing them to use_Outptr_opt_and_Out_opt_annotations. This allows callers to passnullptrif they do not need the link object or fd. ([[1]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-8b744ef020b2dae7afefac77b8d1d9664fa3d249c683b307cd393362da9f5e8bL446-R447),[[2]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-8b744ef020b2dae7afefac77b8d1d9664fa3d249c683b307cd393362da9f5e8bL470-R472),[[3]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-8b744ef020b2dae7afefac77b8d1d9664fa3d249c683b307cd393362da9f5e8bL486-R488))ebpf_api.cppto handle optional link outputs, including allocation and assignment logic, and to avoid assertions on non-null output pointers. ([[1]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-5838f7744d41bcd6c7dc0e9b88628baa36b2a2645824c76aa15f01955ac9cefeL1610-R1625),[[2]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-5838f7744d41bcd6c7dc0e9b88628baa36b2a2645824c76aa15f01955ac9cefeL1653-R1707),[[3]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-5838f7744d41bcd6c7dc0e9b88628baa36b2a2645824c76aa15f01955ac9cefeL1683-L1686),[[4]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-5838f7744d41bcd6c7dc0e9b88628baa36b2a2645824c76aa15f01955ac9cefeL1710-R1765))Link Legacy Mode Handling
ebpf_link_mark_as_legacy_modeand replaced it with an internal function_ebpf_link_mark_as_legacy_mode. Legacy mode is now set automatically if the caller does not request a link or fd, so callers do not need to manage this explicitly. ([[1]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-2f82d1ff51a61fb435467ba5290591820cb88e359100a25e9b9a8e7913c6577cL132),[[2]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-8b744ef020b2dae7afefac77b8d1d9664fa3d249c683b307cd393362da9f5e8bL909-L920),[[3]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-5838f7744d41bcd6c7dc0e9b88628baa36b2a2645824c76aa15f01955ac9cefeL5226-L5235))[libs/api/ebpf_api.cppL1629-R1663](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-5838f7744d41bcd6c7dc0e9b88628baa36b2a2645824c76aa15f01955ac9cefeL1629-R1663))Cleanup and Refactoring in Sample and Helper Code
bpf_prog_attachand__bpf_set_link_xdp_fd_replaceinlibbpf_program.cpp, and from Netsh sample code inprograms.cpp. This simplifies usage and reduces risk of resource leaks. ([[1]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-780511a42f3cac926001942e228bf075fec98dafebcbef6f1c6f5ce257068839L260-R264),[[2]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-780511a42f3cac926001942e228bf075fec98dafebcbef6f1c6f5ce257068839L274-L281),[[3]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-780511a42f3cac926001942e228bf075fec98dafebcbef6f1c6f5ce257068839L641-R632),[[4]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-9ebbb96ca59e504fcf42e194b161976b696a71ad048cbe73e587a78e084c7a90L266-L283),[[5]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-9ebbb96ca59e504fcf42e194b161976b696a71ad048cbe73e587a78e084c7a90L478-R457))_link_deleterstruct from Netsh sample code, as manual link cleanup is no longer needed. ([libs/ebpfnetsh/programs.cppL112-L122](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-9ebbb96ca59e504fcf42e194b161976b696a71ad048cbe73e587a78e084c7a90L112-L122))Minor Code Formatting
[[1]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-5838f7744d41bcd6c7dc0e9b88628baa36b2a2645824c76aa15f01955ac9cefeL1486-R1492),[[2]](https://github.com/microsoft/ebpf-for-windows/pull/4690/files#diff-5838f7744d41bcd6c7dc0e9b88628baa36b2a2645824c76aa15f01955ac9cefeL2762-R2800))These changes streamline eBPF program attachment by making link management more automatic and reducing the burden on callers, while improving code clarity and safety.