History

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.

Andrey Ignatov committed 6 years ago

Commit 7aebfa11 parent 6a098153 files · +9 −10Browse files

Showing the changes to include/uapi/linux (1 of 3 files). Show all

Unified · Split

include/uapi/linux/bpf.h+1−1
@@ -3728,7 +3728,7 @@ struct bpf_sock_addr { · 3727 unmodified lines
3728 __u32 user_ip6[4]; /* Allows 1,2,4,8-byte read and 4,8-byte write.3728 __u32 user_ip6[4]; /* Allows 1,2,4,8-byte read and 4,8-byte write.
3729 * Stored in network byte order.3729 * Stored in network byte order.
3730 */3730 */
3731 __u32 user_port; /* Allows 4-byte read and write.3731 __u32 user_port; /* Allows 1,2,4-byte read and 4-byte write.
3732 * Stored in network byte order3732 * Stored in network byte order
3733 */3733 */
3734 __u32 family; /* Allows 4-byte read, but no write */3734 __u32 family; /* Allows 4-byte read, but no write */