-
Notifications
You must be signed in to change notification settings - Fork 268
Allow sockops BPF programs to query the WFP flow_id #4763
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: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
| return 0; | ||
| } | ||
|
|
||
| static uint64_t |
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.
why is this needed in addition to the one in netebpfext/net_ebpf_ext_sock_ops.c ?
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.
This is for the mock layer that allows BPF programs to be run in unit_tests.exe, entirely in user mode with out netebpfext.sys.
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.
I see, thanks
Signed-off-by: Alan Jowett <alan.jowett@microsoft.com>
|
|
||
| // Ring buffer event callback context. | ||
| std::unique_ptr<ring_buffer_test_event_context_t> context = std::make_unique<ring_buffer_test_event_context_t>(); | ||
| context->test_event_count = 2; // Expect 2 events for TCP connection (outbound and inbound) |
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.
| context->test_event_count = 2; // Expect 2 events for TCP connection (outbound and inbound) | |
| context->test_event_count = 2; // Expect 2 events for TCP connection (outbound and inbound). |
| local_flow_context->parameters.callout_id = net_ebpf_extension_get_callout_id_for_hook(hook_id); | ||
|
|
||
| // Store the flow_id in the sock_ops context for the helper function. | ||
| local_flow_context->context.flow_id = incoming_metadata_values->flowHandle; |
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.
can we be particularly paranoid and follow WFP runtime checks?
local_flow_context->context.flow_id = 0;
if (FWPS_IS_METADATA_FIELD_PRESENT(incoming_metadata_values, FWPS_METADATA_FIELD_FLOW_HANDLE))
{
local_flow_context->context.flow_id = incoming_metadata_values->flowHandle;
}
Moving this PR to draft until the corresponding issue is in the current milestone
Resolves: #4764
Description
This pull request introduces a new eBPF helper function for SOCK_OPS programs that allows retrieving the WFP flow ID associated with a socket operation context. The changes span the core extension, program info, test infrastructure, and add a new sample and test case to validate the helper. The most significant updates are grouped below.
New SOCK_OPS Helper Function: Flow ID
Added the
bpf_sock_ops_get_flow_idhelper function to the eBPF extension, allowing SOCK_OPS programs to access the WFP flow ID for the current connection via the context (bpf_sock_ops_t). This includes updates to the context struct, helper registration, and implementation. [1] [2] [3] [4] [5] [6]Registered the new helper in the program type-specific helper function tables and prototypes for both the extension and test environments, ensuring it is available to eBPF programs and properly mocked for tests. [1] [2] [3] [4]
Sample Program and Test Coverage
Added a new sample eBPF program (
sockops_flow_id.c) that uses the flow ID helper to audit and store flow IDs in maps for both IPv4 and IPv6 connections, demonstrating usage and providing a basis for validation.Added a comprehensive test case (
sock_ops_flow_id_helper_test) insocket_tests.cppthat attaches the sample program, triggers TCP connections, and verifies that the flow ID helper returns valid (non-zero) values via both ring buffer events and map lookups.Test Infrastructure and Minor Refactoring
These changes collectively add robust support for querying and validating WFP flow IDs in SOCK_OPS programs, improving observability and enabling new use cases for eBPF on Windows.
Testing
CI/CD
Documentation
Doxygen comments.
Installation
No.