-
Notifications
You must be signed in to change notification settings - Fork 54
[1/2] Add flavor-specific log codegen callback #486
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
yaakov-stein
wants to merge
5
commits into
facebook:main
Choose a base branch
from
yaakov-stein:extract-log-codegen-callback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
083aa27
lib: cgen: rename log elfstub to pkt_log
yaakov-stein c7e85d2
lib: runtime: restructure bf_log with tagged union
yaakov-stein a7bc7c5
lib: rename bf_pkthdr to bf_log_opt
yaakov-stein 3f33c9f
lib: cgen: move packet codegen out of matcher directory
yaakov-stein 91afd74
lib: cgen: add gen_inline_log flavor callback
yaakov-stein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* SPDX-License-Identifier: GPL-2.0-only */ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
yaakov-stein marked this conversation as resolved.
Show resolved
Hide resolved
yaakov-stein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
|
|
||
| #include <linux/bpf.h> | ||
|
|
||
| #include <bpf/bpf_endian.h> | ||
| #include <bpf/bpf_helpers.h> | ||
| #include <stddef.h> | ||
|
|
||
| #include "cgen/runtime.h" | ||
|
|
||
| __u8 bf_pkt_log(struct bf_runtime *ctx, __u32 rule_id, __u8 headers, | ||
| __u32 verdict, __u32 l3_l4_proto) | ||
| { | ||
| struct bf_log *log; | ||
| __u16 l3_proto = (__u16)(l3_l4_proto >> 16); | ||
| __u8 l4_proto = (__u8)l3_l4_proto; | ||
|
|
||
| log = bpf_ringbuf_reserve(ctx->log_map, sizeof(struct bf_log), 0); | ||
| if (!log) { | ||
| bpf_printk("failed to reserve %d bytes in ringbuf", | ||
| sizeof(struct bf_log)); | ||
| return 1; | ||
| } | ||
|
|
||
| log->ts = bpf_ktime_get_ns(); | ||
| log->rule_id = rule_id; | ||
| log->verdict = verdict; | ||
| log->l3_proto = bpf_ntohs(l3_proto); | ||
| log->l4_proto = l4_proto; | ||
| log->log_type = BF_LOG_TYPE_PACKET; | ||
| log->pkt.pkt_size = ctx->pkt_size; | ||
| log->pkt.req_headers = headers; | ||
| log->pkt.headers = 0; | ||
|
|
||
| if (headers & (1 << BF_LOG_OPT_LINK) && ctx->l2_hdr && | ||
| ctx->l2_size <= BF_L2_SLICE_LEN) { | ||
| bpf_probe_read_kernel(log->pkt.l2hdr, ctx->l2_size, ctx->l2_hdr); | ||
| log->pkt.headers |= (1 << BF_LOG_OPT_LINK); | ||
| } | ||
|
|
||
| if (headers & (1 << BF_LOG_OPT_INTERNET) && ctx->l3_hdr && | ||
| ctx->l3_size <= BF_L3_SLICE_LEN) { | ||
| bpf_probe_read_kernel(log->pkt.l3hdr, ctx->l3_size, ctx->l3_hdr); | ||
| log->pkt.headers |= (1 << BF_LOG_OPT_INTERNET); | ||
| } | ||
|
|
||
| if (headers & (1 << BF_LOG_OPT_TRANSPORT) && ctx->l4_hdr && | ||
| ctx->l4_size <= BF_L4_SLICE_LEN) { | ||
| bpf_probe_read_kernel(log->pkt.l4hdr, ctx->l4_size, ctx->l4_hdr); | ||
| log->pkt.headers |= (1 << BF_LOG_OPT_TRANSPORT); | ||
| } | ||
|
|
||
| bpf_ringbuf_submit(log, 0); | ||
|
|
||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.