BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next 1/2] bpf: add get_netns_cookie helper to tc programs
@ 2024-10-02 16:01 Mahe Tardy
  2024-10-02 16:01 ` [PATCH bpf-next 2/2] selftests/bpf: add tcx netns cookie tests Mahe Tardy
  0 siblings, 1 reply; 9+ messages in thread
From: Mahe Tardy @ 2024-10-02 16:01 UTC (permalink / raw)
  To: bpf; +Cc: martin.lau, daniel, john.fastabend, Mahe Tardy

This is needed in the context of Cilium and Tetragon to retrieve netns
cookie from hostns when traffic leaves Pod, so that we can correlate
skb->sk's netns cookie.

Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
---
 net/core/filter.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/net/core/filter.c b/net/core/filter.c
index cd3524cb326b..6e80991125ba 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5138,6 +5138,17 @@ static u64 __bpf_get_netns_cookie(struct sock *sk)
 	return net->net_cookie;
 }

+BPF_CALL_1(bpf_get_netns_cookie, struct sk_buff *, skb)
+{
+	return __bpf_get_netns_cookie(skb->sk ? skb->sk : NULL);
+}
+
+static const struct bpf_func_proto bpf_get_netns_cookie_proto = {
+	.func           = bpf_get_netns_cookie,
+	.ret_type       = RET_INTEGER,
+	.arg1_type      = ARG_PTR_TO_CTX_OR_NULL,
+};
+
 BPF_CALL_1(bpf_get_netns_cookie_sock, struct sock *, ctx)
 {
 	return __bpf_get_netns_cookie(ctx);
@@ -8209,6 +8220,8 @@ tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
 		return &bpf_skb_under_cgroup_proto;
 	case BPF_FUNC_get_socket_cookie:
 		return &bpf_get_socket_cookie_proto;
+	case BPF_FUNC_get_netns_cookie:
+		return &bpf_get_netns_cookie_proto;
 	case BPF_FUNC_get_socket_uid:
 		return &bpf_get_socket_uid_proto;
 	case BPF_FUNC_fib_lookup:
--
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-10-08 21:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-02 16:01 [PATCH bpf-next 1/2] bpf: add get_netns_cookie helper to tc programs Mahe Tardy
2024-10-02 16:01 ` [PATCH bpf-next 2/2] selftests/bpf: add tcx netns cookie tests Mahe Tardy
2024-10-02 16:42   ` Daniel Borkmann
2024-10-02 17:57     ` [PATCH bpf-next v2 1/2] bpf: add get_netns_cookie helper to tc programs Mahe Tardy
2024-10-02 17:57       ` [PATCH bpf-next v2 2/2] selftests/bpf: add tcx netns cookie tests Mahe Tardy
2024-10-04 12:00       ` [PATCH bpf-next v2 1/2] bpf: add get_netns_cookie helper to tc programs Daniel Borkmann
2024-10-07  9:59         ` [PATCH bpf-next v3 " Mahe Tardy
2024-10-07  9:59           ` [PATCH bpf-next v3 2/2] selftests/bpf: add tcx netns cookie tests Mahe Tardy
2024-10-08 21:40           ` [PATCH bpf-next v3 1/2] bpf: add get_netns_cookie helper to tc programs patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox