Re: [PATCH bpf-next] bpf: Add document for 'dst_port' of 'struct bpf_sock'

From: Menglong Dong
Date: Wed Jan 19 2022 - 22:07:45 EST


Hello!

On Thu, Jan 20, 2022 at 6:03 AM Alexei Starovoitov
<alexei.starovoitov@xxxxxxxxx> wrote:
>
[...]
>
> Looks like
> __sk_buff->remote_port
> bpf_sock_ops->remote_port
> sk_msg_md->remote_port
> are doing the right thing,
> but bpf_sock->dst_port is not correct?
>
> I think it's better to fix it,
> but probably need to consolidate it with
> convert_ctx_accesses() that deals with narrow access.
> I suspect reading u8 from three flavors of 'remote_port'
> won't be correct.

What's the meaning of 'narrow access'? Do you mean to
make 'remote_port' u16? Or 'remote_port' should be made
accessible with u8? In fact, '*((u16 *)&skops->remote_port + 1)'
won't work, as it only is accessible with u32.

I can simply make 'dst_port' endianness right with what
'remote_port' do.

Thanks!
Menglong Dong


> 'dst_port' works with a narrow load, but gets endianness wrong.