diff options
author | Andrey Ignatov <rdna@fb.com> | 2020-05-13 18:50:27 -0700 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2020-05-14 18:30:57 -0700 |
commit | 7aebfa1b3885b5aa29fcb4a596d0485ac463bbe8 (patch) | |
tree | 63b1598db717838cec551892a04b6245c316539e /tools/include | |
parent | 6a09815428547657f3ffd2f5c31ac2a191e7fdf3 (diff) | |
download | lwn-7aebfa1b3885b5aa29fcb4a596d0485ac463bbe8.tar.gz lwn-7aebfa1b3885b5aa29fcb4a596d0485ac463bbe8.zip |
bpf: Support narrow loads from bpf_sock_addr.user_port
bpf_sock_addr.user_port supports only 4-byte load and it leads to ugly
code in BPF programs, like:
volatile __u32 user_port = ctx->user_port;
__u16 port = bpf_ntohs(user_port);
Since otherwise clang may optimize the load to be 2-byte and it's
rejected by verifier.
Add support for 1- and 2-byte loads same way as it's supported for other
fields in bpf_sock_addr like user_ip4, msg_src_ip4, etc.
Signed-off-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/c1e983f4c17573032601d0b2b1f9d1274f24bc16.1589420814.git.rdna@fb.com
Diffstat (limited to 'tools/include')
-rw-r--r-- | tools/include/uapi/linux/bpf.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index bfb31c1be219..85cfdffde182 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -3728,7 +3728,7 @@ struct bpf_sock_addr { __u32 user_ip6[4]; /* Allows 1,2,4,8-byte read and 4,8-byte write. * Stored in network byte order. */ - __u32 user_port; /* Allows 4-byte read and write. + __u32 user_port; /* Allows 1,2,4-byte read and 4-byte write. * Stored in network byte order */ __u32 family; /* Allows 4-byte read, but no write */ |