Commit f8082454 authored by kwb0523's avatar kwb0523
Browse files

bpf: Allow bpf_get_netns_cookie in BPF_PROG_TYPE_SOCK_OPS

mainline inclusion
from mainline-v6.5-rc3
commit 6cf1770d
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I7NL40
CVE: NA

Reference: https://github.com/torvalds/linux/commit/6cf1770d63dd2d0d0d4048e7b3ee360336c072d9



----------------------------------------------------------------------

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

Signed-off-by: default avatarXu Liu <liuxu623@gmail.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarSong Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20210818105820.91894-2-liuxu623@gmail.com


Signed-off-by: default avatarJofDiamonds <kwb0523@163.com>
Reviewed-by: default avatarwuchangye <wuchangye@huawei.com>
parent c5633a85
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -4677,6 +4677,18 @@ static const struct bpf_func_proto bpf_get_netns_cookie_sock_addr_proto = {
	.arg1_type	= ARG_PTR_TO_CTX_OR_NULL,
};

BPF_CALL_1(bpf_get_netns_cookie_sock_ops, struct bpf_sock_ops_kern *, ctx)
{
	return __bpf_get_netns_cookie(ctx ? ctx->sk : NULL);
}

static const struct bpf_func_proto bpf_get_netns_cookie_sock_ops_proto = {
	.func		= bpf_get_netns_cookie_sock_ops,
	.gpl_only	= false,
	.ret_type	= RET_INTEGER,
	.arg1_type	= ARG_PTR_TO_CTX_OR_NULL,
};

BPF_CALL_1(bpf_get_socket_uid, struct sk_buff *, skb)
{
	struct sock *sk = sk_to_full_sk(skb->sk);
@@ -7391,6 +7403,8 @@ sock_ops_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
		return &bpf_sk_storage_get_proto;
	case BPF_FUNC_sk_storage_delete:
		return &bpf_sk_storage_delete_proto;
	case BPF_FUNC_get_netns_cookie:
		return &bpf_get_netns_cookie_sock_ops_proto;
	case BPF_FUNC_get_sockops_uid_gid:
		return &bpf_get_sockops_uid_gid_proto;
	case BPF_FUNC_sk_original_addr: