-
Notifications
You must be signed in to change notification settings - Fork 391
/
Copy pathbpf_cgroup_mkdir.c
63 lines (50 loc) · 1.6 KB
/
bpf_cgroup_mkdir.c
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
// SPDX-License-Identifier: GPL-2.0
/* Copyright Authors of Tetragon */
#include "vmlinux.h"
#include "api.h"
#include "hubble_msg.h"
#include "bpf_cgroup.h"
#include "bpf_events.h"
#include "bpf_cgroup_events.h"
char _license[] __attribute__((section(("license")), used)) = "GPL";
#ifdef VMLINUX_KERNEL_VERSION
int _version __attribute__((section(("version")), used)) =
VMLINUX_KERNEL_VERSION;
#endif
__attribute__((section(("raw_tracepoint/cgroup_mkdir")), used)) int
tg_tp_cgrp_mkdir(struct bpf_raw_tracepoint_args *ctx)
{
uint64_t cgrpid;
int level, hierarchy_id, zero = 0;
struct cgroup *cgrp;
struct cgroup_tracking_value *cgrp_heap;
struct tetragon_conf *config;
config = map_lookup_elem(&tg_conf_map, &zero);
if (!config || config->tg_cgrp_level == 0)
return 0;
cgrp = (struct cgroup *)ctx->args[0];
hierarchy_id = get_cgroup_hierarchy_id(cgrp);
/* Are we operating on the corresponding hierarchy? if no exit */
if (config->tg_cgrp_hierarchy != hierarchy_id)
return 0;
level = get_cgroup_level(cgrp);
/* This should never happen */
if (level == 0)
return 0;
cgrpid = get_cgroup_id(cgrp);
/* This should never happen */
if (cgrpid == 0)
return 0;
if (level <= config->tg_cgrp_level) {
cgrp_heap = __init_cgrp_tracking_val_heap(cgrp, CGROUP_NEW);
if (!cgrp_heap)
return 0;
/* We track only for now cgroups that are at same or above tetragon level */
map_update_elem(&tg_cgrps_tracking_map, &cgrpid, cgrp_heap,
BPF_ANY);
/* Notify events only about cgroup being tracked */
send_cgrp_event(ctx, cgrp_heap, cgrpid, MSG_OP_CGROUP_MKDIR,
EVENT_NOFORCE_SEND);
}
return 0;
}