Re: Typo in the man7 bpf-helpers page

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

 



2023-01-31 22:36 UTC+0800 ~ Zexuan Luo <spacewanderlzx@xxxxxxxxx>
> My bad!
> 
>> No, I don't think there is anything wrong with that. I suppose you mean
> bpf_get_socket_cookie_sock_(ad
> dr|ops) (the functions you mentioned don't
> exist), but the four variants of the helper just have the same name, and
> take different objects for their context.
> 
> Yes! I made a mistake in the function names in the first email. Thank
> you for pointing that out.
> 
> I am an eBPF newbie and I am learning it currently. AFAIK, language C
> doesn't support function overriding via different parameters.
> So how do these four functions co-exist?

User space header file knows only about a single
bpf_get_socket_cookie(), which takes a "void *". See:
https://github.com/libbpf/libbpf/blob/v1.1.0/src/bpf_helper_defs.h#L1154

It compiles into the eBPF insruction "call 46", where 46 is the number
associated to these helpers. When your program loads, the verifier finds
out, depending on program type, what function should be called for that
number (see e.g. tc_cls_act_func_proto() in net/core/filter.c, where
BPF_FUNC_get_socket_cookie (46) returns &bpf_get_socket_cookie_proto,
whereas sock_addr_func_proto(), applied to programs of different types,
will return &bpf_get_socket_cookie_sock_addr_proto instead).

> 
> Some naive search in the kernel code leads me to:
> https://elixir.bootlin.com/linux/v6.2-rc6/source/net/core/filter.c#L4919
> ```
> static const struct bpf_func_proto bpf_get_socket_cookie_sock_addr_proto = {
>     .func        = bpf_get_socket_cookie_sock_addr,
>     .gpl_only    = false,
>     .ret_type    = RET_INTEGER,
>     .arg1_type    = ARG_PTR_TO_CTX,
> };
> ```
> 
> https://elixir.bootlin.com/linux/v6.2-rc6/source/net/core/filter.c#L4955
> ```
> static const struct bpf_func_proto bpf_get_socket_cookie_sock_ops_proto = {
>         .func           = bpf_get_socket_cookie_sock_ops,
>         .gpl_only       = false,
>         .ret_type       = RET_INTEGER,
>         .arg1_type      = ARG_PTR_TO_CTX,
> };
> ```
> 
> It seems that the function definitions are quite real...

Yes, but "bpf_get_socket_cookie_addr" (from your message) !=
"bpf_get_socket_cookie_sock_addr".

Quentin



[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