Re: [PATCH bpf-next] samples/bpf: Fix sockex3 error: missing BPF prog type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Nov 4, 2022 at 11:48 PM Rong Tao <rtoax@xxxxxxxxxxx> wrote:
>
> From: Rong Tao <rongtao@xxxxxxxx>
>
> since commit 450b167fb9be("libbpf: clean up SEC() handling"),
> sec_def_matches() does not recognize "socket/xxx" as "socket", therefore,
> the BPF program type is not recognized.
>
> Instead of sockex3_user.c parsing section names to get the BPF program fd.
> We use the program array map to assign a static index to each BPF program
> (get inspired by selftests/bpf progs/test_prog_array_init.c).
> Therefore, use SEC("socket") as section name instead of SEC("socket/xxx"),
> so that the BPF program is parsed to SOCKET_FILTER type. The "missing BPF
> prog type" problem is solved.
>
> How to reproduce this error:
> $ cd samples/bpf
> $ sudo ./sockex3
> libbpf: prog 'bpf_func_PARSE_IP': missing BPF prog type, check ELF section name 'socket/3'
> libbpf: prog 'bpf_func_PARSE_IP': failed to load: -22
> libbpf: failed to load object './sockex3_kern.o'
> ERROR: loading BPF object file failed
>
> Signed-off-by: Rong Tao <rongtao@xxxxxxxx>
> ---
>  samples/bpf/sockex3_kern.c | 95 ++++++++++++++++++++++----------------
>  samples/bpf/sockex3_user.c | 23 ++++-----
>  2 files changed, 64 insertions(+), 54 deletions(-)
>
> diff --git a/samples/bpf/sockex3_kern.c b/samples/bpf/sockex3_kern.c
> index b363503357e5..26d916834865 100644
> --- a/samples/bpf/sockex3_kern.c
> +++ b/samples/bpf/sockex3_kern.c
> @@ -17,47 +17,12 @@
>  #define IP_MF          0x2000
>  #define IP_OFFSET      0x1FFF
>
> -#define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F
> -
> -struct {
> -       __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
> -       __uint(key_size, sizeof(u32));
> -       __uint(value_size, sizeof(u32));
> -       __uint(max_entries, 8);
> -} jmp_table SEC(".maps");
> -
>  #define PARSE_VLAN 1
>  #define PARSE_MPLS 2
>  #define PARSE_IP 3
>  #define PARSE_IPV6 4
>
> -/* Protocol dispatch routine. It tail-calls next BPF program depending
> - * on eth proto. Note, we could have used ...
> - *
> - *   bpf_tail_call(skb, &jmp_table, proto);
> - *
> - * ... but it would need large prog_array and cannot be optimised given
> - * the map key is not static.
> - */
> -static inline void parse_eth_proto(struct __sk_buff *skb, u32 proto)
> -{
> -       switch (proto) {
> -       case ETH_P_8021Q:
> -       case ETH_P_8021AD:
> -               bpf_tail_call(skb, &jmp_table, PARSE_VLAN);
> -               break;
> -       case ETH_P_MPLS_UC:
> -       case ETH_P_MPLS_MC:
> -               bpf_tail_call(skb, &jmp_table, PARSE_MPLS);
> -               break;
> -       case ETH_P_IP:
> -               bpf_tail_call(skb, &jmp_table, PARSE_IP);
> -               break;
> -       case ETH_P_IPV6:
> -               bpf_tail_call(skb, &jmp_table, PARSE_IPV6);
> -               break;
> -       }
> -}
> +#define PROG_SOCKET_FILTER     SEC("socket")

I dropped this and made SEC("socket") annotations explicit everywhere.
Applied to bpf-next, thank.

>
>  struct vlan_hdr {
>         __be16 h_vlan_TCI;
> @@ -74,6 +39,8 @@ struct flow_key_record {
>         __u32 ip_proto;
>  };
>

[...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux