0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/bpf.h>
0009 #include <linux/version.h>
0010 #include <bpf/bpf_helpers.h>
0011
0012 SEC("cgroup/dev")
0013 int bpf_prog1(struct bpf_cgroup_dev_ctx *ctx)
0014 {
0015 short type = ctx->access_type & 0xFFFF;
0016 #ifdef DEBUG
0017 short access = ctx->access_type >> 16;
0018 char fmt[] = " %d:%d \n";
0019
0020 switch (type) {
0021 case BPF_DEVCG_DEV_BLOCK:
0022 fmt[0] = 'b';
0023 break;
0024 case BPF_DEVCG_DEV_CHAR:
0025 fmt[0] = 'c';
0026 break;
0027 default:
0028 fmt[0] = '?';
0029 break;
0030 }
0031
0032 if (access & BPF_DEVCG_ACC_READ)
0033 fmt[8] = 'r';
0034
0035 if (access & BPF_DEVCG_ACC_WRITE)
0036 fmt[9] = 'w';
0037
0038 if (access & BPF_DEVCG_ACC_MKNOD)
0039 fmt[10] = 'm';
0040
0041 bpf_trace_printk(fmt, sizeof(fmt), ctx->major, ctx->minor);
0042 #endif
0043
0044
0045
0046
0047 if (ctx->major != 1 || type != BPF_DEVCG_DEV_CHAR)
0048 return 0;
0049
0050 switch (ctx->minor) {
0051 case 5:
0052 case 9:
0053 return 1;
0054 }
0055
0056 return 0;
0057 }
0058
0059 char _license[] SEC("license") = "GPL";