History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next

Daniel Borkmann says: ==================== pull-request: bpf-next 2018-03-31 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) Add raw BPF tracepoint API in order to have a BPF program type that can access kernel internal arguments of the tracepoints in their raw form similar to kprobes based BPF programs. This infrastructure also adds a new BPF_RAW_TRACEPOINT_OPEN command to BPF syscall which returns an anon-inode backed fd for the tracepoint object that allows for automatic detach of the BPF program resp. unregistering of the tracepoint probe on fd release, from Alexei. 2) Add new BPF cgroup hooks at bind() and connect() entry in order to allow BPF programs to reject, inspect or modify user space passed struct sockaddr, and as well a hook at post bind time once the port has been allocated. They are used in FB's container management engine for implementing policy, replacing fragile LD_PRELOAD wrapper intercepting bind() and connect() calls that only works in limited scenarios like glibc based apps but not for other runtimes in containerized applications, from Andrey. 3) BPF_F_INGRESS flag support has been added to sockmap programs for their redirect helper call bringing it in line with cls_bpf based programs. Support is added for both variants of sockmap programs, meaning for tx ULP hooks as well as recv skb hooks, from John. 4) Various improvements on BPF side for the nfp driver, besides others this work adds BPF map update and delete helper call support from the datapath, JITing of 32 and 64 bit XADD instructions as well as offload support of bpf_get_prandom_u32() call. Initial implementation of nfp packet cache has been tackled that optimizes memory access (see merge commit for further details), from Jakub and Jiong. 5) Removal of struct bpf_verifier_env argument from the print_bpf_insn() API has been done in order to prepare to use print_bpf_insn() soon out of perf tool directly. This makes the print_bpf_insn() API more generic and pushes the env into private data. bpftool is adjusted as well with the print_bpf_insn() argument removal, from Jiri. 6) Couple of cleanups and prep work for the upcoming BTF (BPF Type Format). The latter will reuse the current BPF verifier log as well, thus bpf_verifier_log() is further generalized, from Martin. 7) For bpf_getsockopt() and bpf_setsockopt() helpers, IPv4 IP_TOS read and write support has been added in similar fashion to existing IPv6 IPV6_TCLASS socket option we already have, from Nikita. 8) Fixes in recent sockmap scatterlist API usage, which did not use sg_init_table() for initialization thus triggering a BUG_ON() in scatterlist API when CONFIG_DEBUG_SG was enabled. This adds and uses a small helper sg_init_marker() to properly handle the affected cases, from Prashant. 9) Let the BPF core follow IDR code convention and therefore use the idr_preload() and idr_preload_end() helpers, which would also help idr_alloc_cyclic() under GFP_ATOMIC to better succeed under memory pressure, from Shaohua. 10) Last but not least, a spelling fix in an error message for the BPF cookie UID helper under BPF sample code, from Colin. ====================

David S. Miller committed 8 years ago

Commit d4069fe2 parents 70ae722 7828f2077 files · +4265 −399Browse files

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

Unified · Split

include/uapi/linux/bpf.h+61−1
@@ -94,6 +94,7 @@ enum bpf_cmd { · 93 unmodified lines
9494 BPF_MAP_GET_FD_BY_ID,
9595 BPF_OBJ_GET_INFO_BY_FD,
9696 BPF_PROG_QUERY,
97+ BPF_RAW_TRACEPOINT_OPEN,
9798 };
9899
99100 enum bpf_map_type {
@@ -134,6 +135,8 @@ enum bpf_prog_type { · 34 unmodified lines
134135 BPF_PROG_TYPE_SK_SKB,
135136 BPF_PROG_TYPE_CGROUP_DEVICE,
136137 BPF_PROG_TYPE_SK_MSG,
138+ BPF_PROG_TYPE_RAW_TRACEPOINT,
139+ BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
137140 };
138141
139142 enum bpf_attach_type {
@@ -145,6 +148,12 @@ enum bpf_attach_type { · 5 unmodified lines
145148 BPF_SK_SKB_STREAM_VERDICT,
146149 BPF_CGROUP_DEVICE,
147150 BPF_SK_MSG_VERDICT,
151+ BPF_CGROUP_INET4_BIND,
152+ BPF_CGROUP_INET6_BIND,
153+ BPF_CGROUP_INET4_CONNECT,
154+ BPF_CGROUP_INET6_CONNECT,
155+ BPF_CGROUP_INET4_POST_BIND,
156+ BPF_CGROUP_INET6_POST_BIND,
148157 __MAX_BPF_ATTACH_TYPE
149158 };
150159
@@ -294,6 +303,11 @@ union bpf_attr { · 143 unmodified lines
294303 __u32 prog_flags;
295304 char prog_name[BPF_OBJ_NAME_LEN];
296305 __u32 prog_ifindex; /* ifindex of netdev to prep for */
306+ /* For some prog types expected attach type must be known at
307+ * load time to verify attach type specific parts of prog
308+ * (context accesses, allowed helpers, etc).
309+ */
310+ __u32 expected_attach_type;
297311 };
298312
299313 struct { /* anonymous struct used by BPF_OBJ_* commands */
@@ -344,6 +358,11 @@ union bpf_attr { · 44 unmodified lines
344358 __aligned_u64 prog_ids;
345359 __u32 prog_cnt;
346360 } query;
361+
362+ struct {
363+ __u64 name;
364+ __u32 prog_fd;
365+ } raw_tracepoint;
347366 } __attribute__((aligned(8)));
348367
349368 /* BPF helper function descriptions:
@@ -729,6 +748,13 @@ union bpf_attr { · 379 unmodified lines
729748 * @flags: reserved for future use
730749 * Return: SK_PASS
731750 *
751+ * int bpf_bind(ctx, addr, addr_len)
752+ * Bind socket to address. Only binding to IP is supported, no port can be
753+ * set in addr.
754+ * @ctx: pointer to context of type bpf_sock_addr
755+ * @addr: pointer to struct sockaddr to bind socket to
756+ * @addr_len: length of sockaddr structure
757+ * Return: 0 on success or negative error code
732758 */
733759 #define __BPF_FUNC_MAPPER(FN) \
734760 FN(unspec), \
@@ -794,7 +820,8 @@ union bpf_attr { · 59 unmodified lines
794820 FN(msg_redirect_map), \
795821 FN(msg_apply_bytes), \
796822 FN(msg_cork_bytes), \
797− FN(msg_pull_data),
823+ FN(msg_pull_data), \
824+ FN(bind),
798825
799826 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
800827 * function eBPF program intends to call
@@ -923,6 +950,15 @@ struct bpf_sock { · 122 unmodified lines
923950 __u32 protocol;
924951 __u32 mark;
925952 __u32 priority;
953+ __u32 src_ip4; /* Allows 1,2,4-byte read.
954+ * Stored in network byte order.
955+ */
956+ __u32 src_ip6[4]; /* Allows 1,2,4-byte read.
957+ * Stored in network byte order.
958+ */
959+ __u32 src_port; /* Allows 4-byte read.
960+ * Stored in host byte order
961+ */
926962 };
927963
928964 #define XDP_PACKET_HEADROOM 256
@@ -998,6 +1034,26 @@ struct bpf_map_info { · 69 unmodified lines
9981034 __u64 netns_ino;
9991035 } __attribute__((aligned(8)));
10001036
1037+/* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
1038+ * by user and intended to be used by socket (e.g. to bind to, depends on
1039+ * attach attach type).
1040+ */
1041+struct bpf_sock_addr {
1042+ __u32 user_family; /* Allows 4-byte read, but no write. */
1043+ __u32 user_ip4; /* Allows 1,2,4-byte read and 4-byte write.
1044+ * Stored in network byte order.
1045+ */
1046+ __u32 user_ip6[4]; /* Allows 1,2,4-byte read an 4-byte write.
1047+ * Stored in network byte order.
1048+ */
1049+ __u32 user_port; /* Allows 4-byte read and write.
1050+ * Stored in network byte order
1051+ */
1052+ __u32 family; /* Allows 4-byte read, but no write */
1053+ __u32 type; /* Allows 4-byte read, but no write */
1054+ __u32 protocol; /* Allows 4-byte read, but no write */
1055+};
1056+
10011057 /* User bpf_sock_ops struct to access socket values and specify request ops
10021058 * and their replies.
10031059 * Some of this fields are in network (bigendian) byte order and may need
@@ -1152,4 +1208,8 @@ struct bpf_cgroup_dev_ctx { · 148 unmodified lines
11521208 __u32 minor;
11531209 };
11541210
1211+struct bpf_raw_tracepoint_args {
1212+ __u64 args[0];
1213+};
1214+
11551215 #endif /* _UAPI__LINUX_BPF_H__ */