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.
Showing the changes to include/uapi (1 of 3 files). Show all
Unified · Split
| @@ -3728,7 +3728,7 @@ struct bpf_sock_addr { · 3727 unmodified lines | ||
| 3728 | 3728 | __u32 user_ip6[4]; /* Allows 1,2,4,8-byte read and 4,8-byte write. |
| 3729 | 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 | 3732 | * Stored in network byte order |
| 3733 | 3733 | */ |
| 3734 | 3734 | __u32 family; /* Allows 4-byte read, but no write */ |