History

bpf: Add state, dst_ip4, dst_ip6 and dst_port to bpf_sock

This patch adds "state", "dst_ip4", "dst_ip6" and "dst_port" to the bpf_sock. The userspace has already been using "state", e.g. inet_diag (ss -t) and getsockopt(TCP_INFO). This patch also allows narrow load on the following existing fields: "family", "type", "protocol" and "src_port". Unlike IP address, the load offset is resticted to the first byte for them but it can be relaxed later if there is a use case. This patch also folds __sock_filter_check_size() into bpf_sock_is_valid_access() since it is not called by any where else. All bpf_sock checking is in one place.

Martin KaFai Lau committed 7 years ago

Commit aa65d691 parent 46f8bc92 files · +85 −31Browse files

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

Unified · Split

include/uapi/linux/bpf.h+8−9
@@ -2606,15 +2606,14 @@ struct bpf_sock { · 2605 unmodified lines
26062606 __u32 protocol;
26072607 __u32 mark;
26082608 __u32 priority;
2609− __u32 src_ip4; /* Allows 1,2,4-byte read.
2610− * Stored in network byte order.
2611− */
2612− __u32 src_ip6[4]; /* Allows 1,2,4-byte read.
2613− * Stored in network byte order.
2614− */
2615− __u32 src_port; /* Allows 4-byte read.
2616− * Stored in host byte order
2617− */
2609+ /* IP address also allows 1 and 2 bytes access */
2610+ __u32 src_ip4;
2611+ __u32 src_ip6[4];
2612+ __u32 src_port; /* host byte order */
2613+ __u32 dst_port; /* network byte order */
2614+ __u32 dst_ip4;
2615+ __u32 dst_ip6[4];
2616+ __u32 state;
26182617 };
26192618
26202619 struct bpf_sock_tuple {