forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
net/core: Add bpf_get_socket_cookie for sk_msg progs #1
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
christarazi
wants to merge
4
commits into
bpf-next
Choose a base branch
from
sk_msg_md-cookie-helper
base: bpf-next
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
4 commits
Select commit
Hold shift + click to select a range
7bab87e
include/linux: Add macro for BPF atomic loads
christarazi fb45741
net/core: Add socket cookie to bpf_sock
christarazi 5cdde4c
net/core: Add bpf_get_socket_cookie for sk_msg progs
christarazi d60cf2a
selftests: Update test for bpf_get_socket_cookie in sk_msg context
christarazi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4697,6 +4697,18 @@ static const struct bpf_func_proto bpf_get_socket_cookie_sock_ops_proto = { | |
| .arg1_type = ARG_PTR_TO_CTX, | ||
| }; | ||
|
|
||
| BPF_CALL_1(bpf_get_socket_cookie_sk_msg, struct sk_msg *, ctx) | ||
| { | ||
| return ctx->sk ? __sock_gen_cookie(ctx->sk) : 0; | ||
| } | ||
|
|
||
| static const struct bpf_func_proto bpf_get_socket_cookie_sk_msg_proto = { | ||
| .func = bpf_get_socket_cookie_sk_msg, | ||
| .gpl_only = false, | ||
| .ret_type = RET_INTEGER, | ||
| .arg1_type = ARG_PTR_TO_CTX_OR_NULL, | ||
| }; | ||
|
|
||
| static u64 __bpf_get_netns_cookie(struct sock *sk) | ||
| { | ||
| const struct net *net = sk ? sock_net(sk) : &init_net; | ||
|
|
@@ -7633,6 +7645,8 @@ sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) | |
| return &bpf_sk_storage_delete_proto; | ||
| case BPF_FUNC_get_netns_cookie: | ||
| return &bpf_get_netns_cookie_sk_msg_proto; | ||
| case BPF_FUNC_get_socket_cookie: | ||
| return &bpf_get_socket_cookie_sk_msg_proto; | ||
| #ifdef CONFIG_CGROUPS | ||
| case BPF_FUNC_get_current_cgroup_id: | ||
| return &bpf_get_current_cgroup_id_proto; | ||
|
|
@@ -8044,6 +8058,11 @@ bool bpf_sock_is_valid_access(int off, int size, enum bpf_access_type type, | |
| case offsetof(struct bpf_sock, dst_port): | ||
| case offsetof(struct bpf_sock, src_port): | ||
| case offsetof(struct bpf_sock, rx_queue_mapping): | ||
| break; | ||
| case bpf_ctx_range(struct bpf_sock, cookie): | ||
| if (type == BPF_WRITE) | ||
| return false; | ||
| return size == sizeof(__u64); | ||
| case bpf_ctx_range(struct bpf_sock, src_ip4): | ||
| case bpf_ctx_range_till(struct bpf_sock, src_ip6[0], src_ip6[3]): | ||
| case bpf_ctx_range(struct bpf_sock, dst_ip4): | ||
|
|
@@ -9125,6 +9144,7 @@ u32 bpf_sock_convert_ctx_access(enum bpf_access_type type, | |
| skc_state), | ||
| target_size)); | ||
| break; | ||
|
|
||
| case offsetof(struct bpf_sock, rx_queue_mapping): | ||
| #ifdef CONFIG_SOCK_RX_QUEUE_MAPPING | ||
| *insn++ = BPF_LDX_MEM( | ||
|
|
@@ -9142,6 +9162,16 @@ u32 bpf_sock_convert_ctx_access(enum bpf_access_type type, | |
| *target_size = 2; | ||
| #endif | ||
| break; | ||
|
|
||
| case offsetof(struct bpf_sock, cookie): | ||
| *insn++ = BPF_ATOMIC_LOAD_OP( | ||
christarazi marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might make sense to have a macro BPF_ATOMIC_LOAD_XCHG? |
||
| BPF_FIELD_SIZEOF(struct sock_common, skc_cookie), | ||
| BPF_XCHG, si->dst_reg, si->src_reg, | ||
| bpf_target_off(struct sock_common, skc_cookie, | ||
| sizeof_field(struct sock_common, | ||
| skc_cookie), | ||
| target_size)); | ||
| break; | ||
| } | ||
|
|
||
| return insn - insn_buf; | ||
|
|
||
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
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.
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.
remove newline