xref: /linux/tools/testing/selftests/bpf/bpf_kfuncs.h (revision a7ddedc84c59a645ef970b992f7cda5bffc70cc0)
1 #ifndef __BPF_KFUNCS__
2 #define __BPF_KFUNCS__
3 
4 struct bpf_sock_addr_kern;
5 
6 /* Description
7  *  Initializes an skb-type dynptr
8  * Returns
9  *  Error code
10  */
11 extern int bpf_dynptr_from_skb(struct __sk_buff *skb, __u64 flags,
12     struct bpf_dynptr *ptr__uninit) __ksym __weak;
13 
14 /* Description
15  *  Initializes an xdp-type dynptr
16  * Returns
17  *  Error code
18  */
19 extern int bpf_dynptr_from_xdp(struct xdp_md *xdp, __u64 flags,
20 			       struct bpf_dynptr *ptr__uninit) __ksym __weak;
21 
22 extern int bpf_dynptr_from_skb_meta(struct __sk_buff *skb, __u64 flags,
23 				    struct bpf_dynptr *ptr__uninit) __ksym __weak;
24 
25 /* Description
26  *  Obtain a read-only pointer to the dynptr's data
27  * Returns
28  *  Either a direct pointer to the dynptr data or a pointer to the user-provided
29  *  buffer if unable to obtain a direct pointer
30  */
31 extern void *bpf_dynptr_slice(const struct bpf_dynptr *ptr, __u32 offset,
32 			      void *buffer, __u32 buffer__szk) __ksym __weak;
33 
34 /* Description
35  *  Obtain a read-write pointer to the dynptr's data
36  * Returns
37  *  Either a direct pointer to the dynptr data or a pointer to the user-provided
38  *  buffer if unable to obtain a direct pointer
39  */
40 extern void *bpf_dynptr_slice_rdwr(const struct bpf_dynptr *ptr, __u32 offset,
41 			      void *buffer, __u32 buffer__szk) __ksym __weak;
42 
43 extern int bpf_dynptr_adjust(const struct bpf_dynptr *ptr, __u32 start, __u32 end) __ksym __weak;
44 extern bool bpf_dynptr_is_null(const struct bpf_dynptr *ptr) __ksym __weak;
45 extern bool bpf_dynptr_is_rdonly(const struct bpf_dynptr *ptr) __ksym __weak;
46 extern __u32 bpf_dynptr_size(const struct bpf_dynptr *ptr) __ksym __weak;
47 extern int bpf_dynptr_clone(const struct bpf_dynptr *ptr, struct bpf_dynptr *clone__init) __ksym __weak;
48 
49 /* Description
50  *  Modify the address of a AF_UNIX sockaddr.
51  * Returns
52  *  -EINVAL if the address size is too big or, 0 if the sockaddr was successfully modified.
53  */
54 extern int bpf_sock_addr_set_sun_path(struct bpf_sock_addr_kern *sa_kern,
55 				      const __u8 *sun_path, __u32 sun_path__sz) __ksym;
56 
57 /* Description
58  *  Allocate and configure a reqsk and link it with a listener and skb.
59  * Returns
60  *  Error code
61  */
62 struct sock;
63 struct bpf_tcp_req_attrs;
64 extern int bpf_sk_assign_tcp_reqsk(struct __sk_buff *skb, struct sock *sk,
65 				   struct bpf_tcp_req_attrs *attrs, int attrs__sz) __ksym;
66 
67 void *bpf_cast_to_kern_ctx(void *) __ksym;
68 
69 extern void *bpf_rdonly_cast(const void *obj, __u32 btf_id) __ksym __weak;
70 
71 extern int bpf_get_file_xattr(struct file *file, const char *name,
72 			      struct bpf_dynptr *value_ptr) __ksym;
73 extern int bpf_get_fsverity_digest(struct file *file, struct bpf_dynptr *digest_ptr) __ksym;
74 
75 extern struct bpf_key *bpf_lookup_user_key(__s32 serial, __u64 flags) __ksym;
76 extern struct bpf_key *bpf_lookup_system_key(__u64 id) __ksym;
77 extern void bpf_key_put(struct bpf_key *key) __ksym;
78 extern int bpf_verify_pkcs7_signature(struct bpf_dynptr *data_ptr,
79 				      struct bpf_dynptr *sig_ptr,
80 				      struct bpf_key *trusted_keyring) __ksym;
81 
82 extern bool bpf_session_is_return(void) __ksym __weak;
83 extern __u64 *bpf_session_cookie(void) __ksym __weak;
84 
85 struct dentry;
86 /* Description
87  *  Returns xattr of a dentry
88  * Returns
89  *  Error code
90  */
91 extern int bpf_get_dentry_xattr(struct dentry *dentry, const char *name,
92 			      struct bpf_dynptr *value_ptr) __ksym __weak;
93 
94 extern int bpf_set_dentry_xattr(struct dentry *dentry, const char *name__str,
95 				const struct bpf_dynptr *value_p, int flags) __ksym __weak;
96 extern int bpf_remove_dentry_xattr(struct dentry *dentry, const char *name__str) __ksym __weak;
97 
98 #endif
99