diff mbox series

[bpf-next,1/3] bpf: sk_msg add some generic helpers that may be useful from sk_msg

Message ID 158939783014.17281.11169741455617229373.stgit@john-Precision-5820-Tower
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series bpf: Add sk_msg helpers | expand

Commit Message

John Fastabend May 13, 2020, 7:23 p.m. UTC
Add these generic helpers that may be useful to use from sk_msg programs.
The helpers do not depend on ctx so we can simply add them here,

 BPF_FUNC_perf_event_output
 BPF_FUNC_get_current_uid_gid
 BPF_FUNC_get_current_pid_tgid
 BPF_FUNC_get_current_comm
 BPF_FUNC_get_current_cgroup_id
 BPF_FUNC_get_current_ancestor_cgroup_id
 BPF_FUNC_get_cgroup_classid

Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 net/core/filter.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Yonghong Song May 14, 2020, 6:58 a.m. UTC | #1
On 5/13/20 12:23 PM, John Fastabend wrote:
> Add these generic helpers that may be useful to use from sk_msg programs.
> The helpers do not depend on ctx so we can simply add them here,
> 
>   BPF_FUNC_perf_event_output
>   BPF_FUNC_get_current_uid_gid
>   BPF_FUNC_get_current_pid_tgid
>   BPF_FUNC_get_current_comm
>   BPF_FUNC_get_current_cgroup_id
>   BPF_FUNC_get_current_ancestor_cgroup_id
>   BPF_FUNC_get_cgroup_classid
> 
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>

Acked-by: Yonghong Song <yhs@fb.com>
diff mbox series

Patch

diff --git a/net/core/filter.c b/net/core/filter.c
index da06349..45b4a16 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -6380,6 +6380,22 @@  sk_msg_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 		return &bpf_msg_push_data_proto;
 	case BPF_FUNC_msg_pop_data:
 		return &bpf_msg_pop_data_proto;
+	case BPF_FUNC_perf_event_output:
+		return &bpf_event_output_data_proto;
+	case BPF_FUNC_get_current_uid_gid:
+		return &bpf_get_current_uid_gid_proto;
+	case BPF_FUNC_get_current_pid_tgid:
+		return &bpf_get_current_pid_tgid_proto;
+#ifdef CONFIG_CGROUPS
+	case BPF_FUNC_get_current_cgroup_id:
+		return &bpf_get_current_cgroup_id_proto;
+	case BPF_FUNC_get_current_ancestor_cgroup_id:
+		return &bpf_get_current_ancestor_cgroup_id_proto;
+#endif
+#ifdef CONFIG_CGROUP_NET_CLASSID
+	case BPF_FUNC_get_cgroup_classid:
+		return &bpf_get_cgroup_classid_curr_proto;
+#endif
 	default:
 		return bpf_base_func_proto(func_id);
 	}