Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpf: Allow bpf_get_netns_cookie in BPF_PROG_TYPE_SK_MSG

We'd like to be able to identify netns from sk_msg hooks
to accelerate local process communication form different netns.

Signed-off-by: Xu Liu <liuxu623@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210820071712.52852-2-liuxu623@gmail.com

authored by

Xu Liu and committed by
Alexei Starovoitov
fab60e29 8c0bb89e

+14
+14
net/core/filter.c
··· 4688 4688 .arg1_type = ARG_PTR_TO_CTX_OR_NULL, 4689 4689 }; 4690 4690 4691 + BPF_CALL_1(bpf_get_netns_cookie_sk_msg, struct sk_msg *, ctx) 4692 + { 4693 + return __bpf_get_netns_cookie(ctx ? ctx->sk : NULL); 4694 + } 4695 + 4696 + static const struct bpf_func_proto bpf_get_netns_cookie_sk_msg_proto = { 4697 + .func = bpf_get_netns_cookie_sk_msg, 4698 + .gpl_only = false, 4699 + .ret_type = RET_INTEGER, 4700 + .arg1_type = ARG_PTR_TO_CTX_OR_NULL, 4701 + }; 4702 + 4691 4703 BPF_CALL_1(bpf_get_socket_uid, struct sk_buff *, skb) 4692 4704 { 4693 4705 struct sock *sk = sk_to_full_sk(skb->sk); ··· 7563 7551 return &bpf_sk_storage_get_proto; 7564 7552 case BPF_FUNC_sk_storage_delete: 7565 7553 return &bpf_sk_storage_delete_proto; 7554 + case BPF_FUNC_get_netns_cookie: 7555 + return &bpf_get_netns_cookie_sk_msg_proto; 7566 7556 #ifdef CONFIG_CGROUPS 7567 7557 case BPF_FUNC_get_current_cgroup_id: 7568 7558 return &bpf_get_current_cgroup_id_proto;