
hulk inclusion category: featrue bugzilla: https://gitee.com/openeuler/kernel/issues/ICS15S -------------------------------- Add bpf_get_ingress_dst kfunc for sock_ops bpf program. It is used to get the receive dst entry of the full sock. Signed-off-by: Pu Lehui <pulehui@huawei.com> --- kernel/bpf/btf.c | 3 +++ net/core/filter.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 68c6e3817ce6..c2059bf7c71d 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -8098,6 +8098,9 @@ static int bpf_prog_type_to_kfunc_hook(enum bpf_prog_type prog_type) case BPF_PROG_TYPE_CGROUP_SOCK_ADDR: case BPF_PROG_TYPE_CGROUP_SOCKOPT: case BPF_PROG_TYPE_CGROUP_SYSCTL: +#ifdef CONFIG_HISOCK + case BPF_PROG_TYPE_SOCK_OPS: +#endif return BTF_KFUNC_HOOK_CGROUP; case BPF_PROG_TYPE_SCHED_ACT: return BTF_KFUNC_HOOK_SCHED_ACT; diff --git a/net/core/filter.c b/net/core/filter.c index 5abdd9a0a2ac..fd717806586c 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -12057,6 +12057,27 @@ __bpf_kfunc int bpf_sock_addr_set_sun_path(struct bpf_sock_addr_kern *sa_kern, return 0; } + +#ifdef CONFIG_HISOCK +__bpf_kfunc struct dst_entry * +bpf_skops_get_ingress_dst(struct bpf_sock_ops *skops_ctx) +{ + struct bpf_sock_ops_kern *skops = (struct bpf_sock_ops_kern *)skops_ctx; + struct sock *sk = skops->sk; + struct dst_entry *dst; + + WARN_ON_ONCE(!rcu_read_lock_held()); + + if (!sk || !sk_fullsock(sk)) + return NULL; + + dst = rcu_dereference(sk->sk_rx_dst); + if (dst) + dst = dst_check(dst, 0); + + return dst; +} +#endif __diag_pop(); int bpf_dynptr_from_skb_rdonly(struct sk_buff *skb, u64 flags, @@ -12085,6 +12106,12 @@ BTF_SET8_START(bpf_kfunc_check_set_sock_addr) BTF_ID_FLAGS(func, bpf_sock_addr_set_sun_path) BTF_SET8_END(bpf_kfunc_check_set_sock_addr) +#ifdef CONFIG_HISOCK +BTF_SET8_START(bpf_kfunc_check_set_sock_ops) +BTF_ID_FLAGS(func, bpf_skops_get_ingress_dst, KF_RET_NULL) +BTF_SET8_END(bpf_kfunc_check_set_sock_ops) +#endif + static const struct btf_kfunc_id_set bpf_kfunc_set_skb = { .owner = THIS_MODULE, .set = &bpf_kfunc_check_set_skb, @@ -12100,6 +12127,13 @@ static const struct btf_kfunc_id_set bpf_kfunc_set_sock_addr = { .set = &bpf_kfunc_check_set_sock_addr, }; +#ifdef CONFIG_HISOCK +static const struct btf_kfunc_id_set bpf_kfunc_set_sock_ops = { + .owner = THIS_MODULE, + .set = &bpf_kfunc_check_set_sock_ops, +}; +#endif + static int __init bpf_kfunc_init(void) { int ret; @@ -12115,6 +12149,9 @@ static int __init bpf_kfunc_init(void) ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_LWT_SEG6LOCAL, &bpf_kfunc_set_skb); ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_NETFILTER, &bpf_kfunc_set_skb); ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_XDP, &bpf_kfunc_set_xdp); +#ifdef CONFIG_HISOCK + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_SOCK_OPS, &bpf_kfunc_set_sock_ops); +#endif return ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCK_ADDR, &bpf_kfunc_set_sock_addr); } -- 2.34.1