Martin KaFai Lau | 6ac99e8 | 2019-04-26 16:39:39 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* Copyright (c) 2019 Facebook */ |
| 3 | #ifndef _BPF_SK_STORAGE_H |
| 4 | #define _BPF_SK_STORAGE_H |
| 5 | |
KP Singh | 4cc9ce4e | 2020-08-25 20:29:14 +0200 | [diff] [blame^] | 6 | #include <linux/types.h> |
| 7 | #include <linux/spinlock.h> |
| 8 | |
Martin KaFai Lau | 6ac99e8 | 2019-04-26 16:39:39 -0700 | [diff] [blame] | 9 | struct sock; |
| 10 | |
| 11 | void bpf_sk_storage_free(struct sock *sk); |
| 12 | |
| 13 | extern const struct bpf_func_proto bpf_sk_storage_get_proto; |
| 14 | extern const struct bpf_func_proto bpf_sk_storage_delete_proto; |
| 15 | |
Martin KaFai Lau | 1ed4d92 | 2020-02-25 15:04:21 -0800 | [diff] [blame] | 16 | struct bpf_sk_storage_diag; |
| 17 | struct sk_buff; |
| 18 | struct nlattr; |
| 19 | struct sock; |
| 20 | |
KP Singh | 4cc9ce4e | 2020-08-25 20:29:14 +0200 | [diff] [blame^] | 21 | #define BPF_LOCAL_STORAGE_CACHE_SIZE 16 |
| 22 | |
| 23 | struct bpf_local_storage_cache { |
| 24 | spinlock_t idx_lock; |
| 25 | u64 idx_usage_counts[BPF_LOCAL_STORAGE_CACHE_SIZE]; |
| 26 | }; |
| 27 | |
| 28 | #define DEFINE_BPF_STORAGE_CACHE(name) \ |
| 29 | static struct bpf_local_storage_cache name = { \ |
| 30 | .idx_lock = __SPIN_LOCK_UNLOCKED(name.idx_lock), \ |
| 31 | } |
| 32 | |
| 33 | u16 bpf_local_storage_cache_idx_get(struct bpf_local_storage_cache *cache); |
| 34 | void bpf_local_storage_cache_idx_free(struct bpf_local_storage_cache *cache, |
| 35 | u16 idx); |
| 36 | |
Stanislav Fomichev | 8f51dfc | 2019-08-14 10:37:49 -0700 | [diff] [blame] | 37 | #ifdef CONFIG_BPF_SYSCALL |
| 38 | int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk); |
Martin KaFai Lau | 1ed4d92 | 2020-02-25 15:04:21 -0800 | [diff] [blame] | 39 | struct bpf_sk_storage_diag * |
| 40 | bpf_sk_storage_diag_alloc(const struct nlattr *nla_stgs); |
| 41 | void bpf_sk_storage_diag_free(struct bpf_sk_storage_diag *diag); |
| 42 | int bpf_sk_storage_diag_put(struct bpf_sk_storage_diag *diag, |
| 43 | struct sock *sk, struct sk_buff *skb, |
| 44 | int stg_array_type, |
| 45 | unsigned int *res_diag_size); |
Stanislav Fomichev | 8f51dfc | 2019-08-14 10:37:49 -0700 | [diff] [blame] | 46 | #else |
| 47 | static inline int bpf_sk_storage_clone(const struct sock *sk, |
| 48 | struct sock *newsk) |
| 49 | { |
| 50 | return 0; |
| 51 | } |
Martin KaFai Lau | 1ed4d92 | 2020-02-25 15:04:21 -0800 | [diff] [blame] | 52 | static inline struct bpf_sk_storage_diag * |
| 53 | bpf_sk_storage_diag_alloc(const struct nlattr *nla) |
| 54 | { |
| 55 | return NULL; |
| 56 | } |
| 57 | static inline void bpf_sk_storage_diag_free(struct bpf_sk_storage_diag *diag) |
| 58 | { |
| 59 | } |
| 60 | static inline int bpf_sk_storage_diag_put(struct bpf_sk_storage_diag *diag, |
| 61 | struct sock *sk, struct sk_buff *skb, |
| 62 | int stg_array_type, |
| 63 | unsigned int *res_diag_size) |
| 64 | { |
| 65 | return 0; |
| 66 | } |
Stanislav Fomichev | 8f51dfc | 2019-08-14 10:37:49 -0700 | [diff] [blame] | 67 | #endif |
| 68 | |
Martin KaFai Lau | 6ac99e8 | 2019-04-26 16:39:39 -0700 | [diff] [blame] | 69 | #endif /* _BPF_SK_STORAGE_H */ |