summaryrefslogtreecommitdiffstats
path: root/include/linux/bpf.h
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2018-10-12 20:45:58 -0400
committerAlexei Starovoitov <ast@kernel.org>2018-10-15 15:23:19 -0400
commit604326b41a6fb9b4a78b6179335decee0365cd8c (patch)
tree95d439c3739f0b3ed5022780cd3f6925f1a4f94d /include/linux/bpf.h
parent1243a51f6c05ecbb2c5c9e02fdcc1e7a06f76f26 (diff)
bpf, sockmap: convert to generic sk_msg interface
Add a generic sk_msg layer, and convert current sockmap and later kTLS over to make use of it. While sk_buff handles network packet representation from netdevice up to socket, sk_msg handles data representation from application to socket layer. This means that sk_msg framework spans across ULP users in the kernel, and enables features such as introspection or filtering of data with the help of BPF programs that operate on this data structure. Latter becomes in particular useful for kTLS where data encryption is deferred into the kernel, and as such enabling the kernel to perform L7 introspection and policy based on BPF for TLS connections where the record is being encrypted after BPF has run and came to a verdict. In order to get there, first step is to transform open coding of scatter-gather list handling into a common core framework that subsystems can use. The code itself has been split and refactored into three bigger pieces: i) the generic sk_msg API which deals with managing the scatter gather ring, providing helpers for walking and mangling, transferring application data from user space into it, and preparing it for BPF pre/post-processing, ii) the plain sock map itself where sockets can be attached to or detached from; these bits are independent of i) which can now be used also without sock map, and iii) the integration with plain TCP as one protocol to be used for processing L7 application data (later this could e.g. also be extended to other protocols like UDP). The semantics are the same with the old sock map code and therefore no change of user facing behavior or APIs. While pursuing this work it also helped finding a number of bugs in the old sockmap code that we've fixed already in earlier commits. The test_sockmap kselftest suite passes through fine as well. Joint work with John. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'include/linux/bpf.h')
-rw-r--r--include/linux/bpf.h33
1 files changed, 11 insertions, 22 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 9b558713447f..e60fff48288b 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -737,33 +737,18 @@ static inline void bpf_map_offload_map_free(struct bpf_map *map)
737} 737}
738#endif /* CONFIG_NET && CONFIG_BPF_SYSCALL */ 738#endif /* CONFIG_NET && CONFIG_BPF_SYSCALL */
739 739
740#if defined(CONFIG_STREAM_PARSER) && defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_INET) 740#if defined(CONFIG_BPF_STREAM_PARSER)
741struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key); 741int sock_map_prog_update(struct bpf_map *map, struct bpf_prog *prog, u32 which);
742struct sock *__sock_hash_lookup_elem(struct bpf_map *map, void *key); 742int sock_map_get_from_fd(const union bpf_attr *attr, struct bpf_prog *prog);
743int sock_map_prog(struct bpf_map *map, struct bpf_prog *prog, u32 type);
744int sockmap_get_from_fd(const union bpf_attr *attr, int type,
745 struct bpf_prog *prog);
746#else 743#else
747static inline struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key) 744static inline int sock_map_prog_update(struct bpf_map *map,
748{ 745 struct bpf_prog *prog, u32 which)
749 return NULL;
750}
751
752static inline struct sock *__sock_hash_lookup_elem(struct bpf_map *map,
753 void *key)
754{
755 return NULL;
756}
757
758static inline int sock_map_prog(struct bpf_map *map,
759 struct bpf_prog *prog,
760 u32 type)
761{ 746{
762 return -EOPNOTSUPP; 747 return -EOPNOTSUPP;
763} 748}
764 749
765static inline int sockmap_get_from_fd(const union bpf_attr *attr, int type, 750static inline int sock_map_get_from_fd(const union bpf_attr *attr,
766 struct bpf_prog *prog) 751 struct bpf_prog *prog)
767{ 752{
768 return -EINVAL; 753 return -EINVAL;
769} 754}
@@ -839,6 +824,10 @@ extern const struct bpf_func_proto bpf_get_stack_proto;
839extern const struct bpf_func_proto bpf_sock_map_update_proto; 824extern const struct bpf_func_proto bpf_sock_map_update_proto;
840extern const struct bpf_func_proto bpf_sock_hash_update_proto; 825extern const struct bpf_func_proto bpf_sock_hash_update_proto;
841extern const struct bpf_func_proto bpf_get_current_cgroup_id_proto; 826extern const struct bpf_func_proto bpf_get_current_cgroup_id_proto;
827extern const struct bpf_func_proto bpf_msg_redirect_hash_proto;
828extern const struct bpf_func_proto bpf_msg_redirect_map_proto;
829extern const struct bpf_func_proto bpf_sk_redirect_hash_proto;
830extern const struct bpf_func_proto bpf_sk_redirect_map_proto;
842 831
843extern const struct bpf_func_proto bpf_get_local_storage_proto; 832extern const struct bpf_func_proto bpf_get_local_storage_proto;
844 833