blob: 950c5aaba15e577425f042b328c4a0f8f75e0520 [file] [log] [blame]
Martin KaFai Lau6ac99e82019-04-26 16:39:39 -07001/* 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 Singh4cc9ce4e2020-08-25 20:29:14 +02006#include <linux/types.h>
7#include <linux/spinlock.h>
8
Martin KaFai Lau6ac99e82019-04-26 16:39:39 -07009struct sock;
10
11void bpf_sk_storage_free(struct sock *sk);
12
13extern const struct bpf_func_proto bpf_sk_storage_get_proto;
14extern const struct bpf_func_proto bpf_sk_storage_delete_proto;
15
Martin KaFai Lau1ed4d922020-02-25 15:04:21 -080016struct bpf_sk_storage_diag;
17struct sk_buff;
18struct nlattr;
19struct sock;
20
KP Singh4cc9ce4e2020-08-25 20:29:14 +020021#define BPF_LOCAL_STORAGE_CACHE_SIZE 16
22
23struct 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) \
29static struct bpf_local_storage_cache name = { \
30 .idx_lock = __SPIN_LOCK_UNLOCKED(name.idx_lock), \
31}
32
33u16 bpf_local_storage_cache_idx_get(struct bpf_local_storage_cache *cache);
34void bpf_local_storage_cache_idx_free(struct bpf_local_storage_cache *cache,
35 u16 idx);
36
Stanislav Fomichev8f51dfc2019-08-14 10:37:49 -070037#ifdef CONFIG_BPF_SYSCALL
38int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk);
Martin KaFai Lau1ed4d922020-02-25 15:04:21 -080039struct bpf_sk_storage_diag *
40bpf_sk_storage_diag_alloc(const struct nlattr *nla_stgs);
41void bpf_sk_storage_diag_free(struct bpf_sk_storage_diag *diag);
42int 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 Fomichev8f51dfc2019-08-14 10:37:49 -070046#else
47static inline int bpf_sk_storage_clone(const struct sock *sk,
48 struct sock *newsk)
49{
50 return 0;
51}
Martin KaFai Lau1ed4d922020-02-25 15:04:21 -080052static inline struct bpf_sk_storage_diag *
53bpf_sk_storage_diag_alloc(const struct nlattr *nla)
54{
55 return NULL;
56}
57static inline void bpf_sk_storage_diag_free(struct bpf_sk_storage_diag *diag)
58{
59}
60static 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 Fomichev8f51dfc2019-08-14 10:37:49 -070067#endif
68
Martin KaFai Lau6ac99e82019-04-26 16:39:39 -070069#endif /* _BPF_SK_STORAGE_H */