-
Notifications
You must be signed in to change notification settings - Fork 0
/
es-ctrl.h
66 lines (51 loc) · 1.49 KB
/
es-ctrl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/** es-ctrl.h
*
* Copyright (c) 2021-2024 Leesoo Ahn <lsahn@ooseel.net>
*/
#ifndef __ESBPF_CTRL_H__
#define __ESBPF_CTRL_H__
#include <linux/types.h>
#include <linux/spinlock.h>
#include "es-core.h"
struct esbpf_filter;
enum {
ESBPF_OFF = 0,
ESBPF_ON
};
struct esbpf_ctrl {
atomic_t rx_enable;
struct proc_dir_entry *proc_root;
spinlock_t rcu_lock;
struct esbpf_filter *rx_hooks;
};
static inline void esbpf_ctrl_init(struct esbpf_ctrl *self)
{
self->rx_enable = (atomic_t)ATOMIC_INIT(ESBPF_OFF);
self->proc_root = NULL;
spin_lock_init(&self->rcu_lock);
self->rx_hooks = NULL;
}
static inline struct esbpf_filter *
esbpf_ctrl_replace_hook(struct esbpf_ctrl *self, struct esbpf_filter *new)
{
struct esbpf_filter *old;
spin_lock(&self->rcu_lock);
old = rcu_replace_pointer(self->rx_hooks, new,
lockdep_is_held(&self->rcu_lock));
spin_unlock(&self->rcu_lock);
return old;
}
static inline void esbpf_ctrl_release(struct esbpf_ctrl *self)
{
int new_val = 0, old_val;
struct esbpf_filter *new_filt = NULL, *old_filt;
old_val = atomic_read(&self->rx_enable);
atomic_cmpxchg_acquire(&self->rx_enable, old_val, new_val);
old_filt = esbpf_ctrl_replace_hook(self, new_filt);
if (old_filt)
call_rcu(&old_filt->rcu, esbpf_reclaim_filter);
}
/* -- proc APIs -- */
int esbpf_proc_init(struct esbpf_ctrl *ctrl, const char *proc_name);
void esbpf_proc_release(struct esbpf_ctrl *ctrl);
#endif /* __ESBPF_CTRL_H__ */