[PATCH 08/13] bpf, sk_msg: Add some generic helpers that may be useful from sk_msg

Khalid Elmously khalid.elmously at canonical.com
Thu Jul 16 02:36:14 UTC 2020


From: John Fastabend <john.fastabend at gmail.com>

BugLink: https://bugs.launchpad.net/bugs/1887740

[ upstream commit abe3cac8706bffeda3ebc06e4a9fa6e9cadacf26 ]

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_cgroup_id
 BPF_FUNC_get_current_ancestor_cgroup_id
 BPF_FUNC_get_cgroup_classid

Signed-off-by: John Fastabend <john.fastabend at gmail.com>
Signed-off-by: Daniel Borkmann <daniel at iogearbox.net>
Acked-by: Yonghong Song <yhs at fb.com>
Link: https://lore.kernel.org/bpf/159033903373.12355.15489763099696629346.stgit@john-Precision-5820-Tower
[ Backport note: Taken out get_current_{,ancestor_}cgroup_id() due to
  a cgroup v2 patch dependency. ]
Signed-off-by: Daniel Borkmann <daniel at iogearbox.net>
Signed-off-by: Khalid Elmously <khalid.elmously at canonical.com>
---
 net/core/filter.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/net/core/filter.c b/net/core/filter.c
index a4526beb6cc1..d1373a8ce6ed 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -6406,6 +6406,16 @@ 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_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);
 	}
-- 
2.17.1




More information about the kernel-team mailing list