Skip to content

Commit 00a4fd1

Browse files
bpf: add get_netns_cookie helper to tc programs
JIRA: https://issues.redhat.com/browse/RHEL-110279 commit eb62f49 Author: Mahe Tardy <mahe.tardy@gmail.com> Date: Mon Oct 7 09:59:57 2024 +0000 bpf: add get_netns_cookie helper to tc programs 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> Link: https://lore.kernel.org/r/20241007095958.97442-1-mahe.tardy@gmail.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
1 parent 653d33f commit 00a4fd1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

net/core/filter.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5103,6 +5103,17 @@ static u64 __bpf_get_netns_cookie(struct sock *sk)
51035103
return net->net_cookie;
51045104
}
51055105

5106+
BPF_CALL_1(bpf_get_netns_cookie, struct sk_buff *, skb)
5107+
{
5108+
return __bpf_get_netns_cookie(skb && skb->sk ? skb->sk : NULL);
5109+
}
5110+
5111+
static const struct bpf_func_proto bpf_get_netns_cookie_proto = {
5112+
.func = bpf_get_netns_cookie,
5113+
.ret_type = RET_INTEGER,
5114+
.arg1_type = ARG_PTR_TO_CTX_OR_NULL,
5115+
};
5116+
51065117
BPF_CALL_1(bpf_get_netns_cookie_sock, struct sock *, ctx)
51075118
{
51085119
return __bpf_get_netns_cookie(ctx);
@@ -8116,6 +8127,8 @@ tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
81168127
return &bpf_skb_under_cgroup_proto;
81178128
case BPF_FUNC_get_socket_cookie:
81188129
return &bpf_get_socket_cookie_proto;
8130+
case BPF_FUNC_get_netns_cookie:
8131+
return &bpf_get_netns_cookie_proto;
81198132
case BPF_FUNC_get_socket_uid:
81208133
return &bpf_get_socket_uid_proto;
81218134
case BPF_FUNC_fib_lookup:

0 commit comments

Comments
 (0)