hulk inclusion category: featrue bugzilla: https://atomgit.com/openeuler/kernel/issues/8480 -------------------------------- Add bpf_get_skb_ethhdr kfunc to fetch the ether header of the ingress skb. Signed-off-by: Pu Lehui <pulehui@huawei.com> --- kernel/bpf/verifier.c | 6 +++++- net/core/filter.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index f028f5650323..4e0d6c2cb3ed 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -10815,6 +10815,7 @@ enum special_kfunc_type { KF_bpf_set_ingress_dst, KF_bpf_set_ingress_dev, KF_bpf_set_egress_dev, + KF_bpf_get_skb_ethhdr, #endif }; @@ -10840,6 +10841,7 @@ BTF_ID(func, bpf_dynptr_clone) BTF_ID(func, bpf_set_ingress_dst) BTF_ID(func, bpf_set_ingress_dev) BTF_ID(func, bpf_set_egress_dev) +BTF_ID(func, bpf_get_skb_ethhdr) #endif BTF_SET_END(special_kfunc_set) @@ -10867,6 +10869,7 @@ BTF_ID(func, bpf_dynptr_clone) BTF_ID(func, bpf_set_ingress_dst) BTF_ID(func, bpf_set_ingress_dev) BTF_ID(func, bpf_set_egress_dev) +BTF_ID(func, bpf_get_skb_ethhdr) #endif static bool is_kfunc_ret_null(struct bpf_kfunc_call_arg_meta *meta) @@ -11848,7 +11851,8 @@ static int check_atype_kfunc_compatibility(struct bpf_verifier_env *env, u32 fun { #ifdef CONFIG_HISOCK if ((func_id == special_kfunc_list[KF_bpf_set_ingress_dst] || - func_id == special_kfunc_list[KF_bpf_set_ingress_dev]) && + func_id == special_kfunc_list[KF_bpf_set_ingress_dev] || + func_id == special_kfunc_list[KF_bpf_get_skb_ethhdr]) && env->prog->expected_attach_type != BPF_HISOCK_INGRESS) return -EACCES; diff --git a/net/core/filter.c b/net/core/filter.c index 442025f7841f..3530e5bde7bd 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -12243,6 +12243,19 @@ __bpf_kfunc int bpf_skb_change_dev(struct __sk_buff *skb_ctx, u32 ifindex) return 0; } +__bpf_kfunc int +bpf_get_skb_ethhdr(struct __sk_buff *skb_ctx, struct ethhdr *peth, int size__sz) +{ + struct sk_buff *skb = (struct sk_buff *)skb_ctx; + struct ethhdr *eth = eth_hdr(skb); + + if (size__sz != sizeof(struct ethhdr)) + return -EINVAL; + + memcpy(peth, eth, size__sz); + return 0; +} + __bpf_kfunc int bpf_set_ingress_dev(struct __sk_buff *skb_ctx, unsigned long _dev) { @@ -12310,6 +12323,7 @@ BTF_SET8_END(bpf_kfunc_check_set_sock_ops) BTF_SET8_START(bpf_kfunc_check_set_hisock) BTF_ID_FLAGS(func, bpf_set_ingress_dst) +BTF_ID_FLAGS(func, bpf_get_skb_ethhdr) BTF_ID_FLAGS(func, bpf_set_ingress_dev) BTF_ID_FLAGS(func, bpf_set_egress_dev) BTF_ID_FLAGS(func, bpf_skb_change_dev) -- 2.34.1