Loading...
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2022 Google */
3#include <vmlinux.h>
4#include <bpf/bpf_helpers.h>
5#include <bpf/bpf_tracing.h>
6
7char _license[] SEC("license") = "GPL";
8int terminate_early = 0;
9u64 terminal_cgroup = 0;
10
11static inline u64 cgroup_id(struct cgroup *cgrp)
12{
13 return cgrp->kn->id;
14}
15
16SEC("iter/cgroup")
17int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
18{
19 struct seq_file *seq = ctx->meta->seq;
20 struct cgroup *cgrp = ctx->cgroup;
21
22 /* epilogue */
23 if (cgrp == NULL) {
24 BPF_SEQ_PRINTF(seq, "epilogue\n");
25 return 0;
26 }
27
28 /* prologue */
29 if (ctx->meta->seq_num == 0)
30 BPF_SEQ_PRINTF(seq, "prologue\n");
31
32 BPF_SEQ_PRINTF(seq, "%8llu\n", cgroup_id(cgrp));
33
34 if (terminal_cgroup == cgroup_id(cgrp))
35 return 1;
36
37 return terminate_early ? 1 : 0;
38}
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2022 Google */
3
4#include "bpf_iter.h"
5#include <bpf/bpf_helpers.h>
6#include <bpf/bpf_tracing.h>
7
8char _license[] SEC("license") = "GPL";
9int terminate_early = 0;
10u64 terminal_cgroup = 0;
11
12static inline u64 cgroup_id(struct cgroup *cgrp)
13{
14 return cgrp->kn->id;
15}
16
17SEC("iter/cgroup")
18int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
19{
20 struct seq_file *seq = ctx->meta->seq;
21 struct cgroup *cgrp = ctx->cgroup;
22
23 /* epilogue */
24 if (cgrp == NULL) {
25 BPF_SEQ_PRINTF(seq, "epilogue\n");
26 return 0;
27 }
28
29 /* prologue */
30 if (ctx->meta->seq_num == 0)
31 BPF_SEQ_PRINTF(seq, "prologue\n");
32
33 BPF_SEQ_PRINTF(seq, "%8llu\n", cgroup_id(cgrp));
34
35 if (terminal_cgroup == cgroup_id(cgrp))
36 return 1;
37
38 return terminate_early ? 1 : 0;
39}