xref: /aosp_15_r20/system/bpf/progs/bpfRingbufProg.c (revision 55039e042b8390f50b0bdd70c11a2419f6d8fd50)
1*55039e04SAndroid Build Coastguard Worker /*
2*55039e04SAndroid Build Coastguard Worker  * Copyright (C) 2022 The Android Open Source Project
3*55039e04SAndroid Build Coastguard Worker  *
4*55039e04SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*55039e04SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*55039e04SAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*55039e04SAndroid Build Coastguard Worker  *
8*55039e04SAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*55039e04SAndroid Build Coastguard Worker  *
10*55039e04SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*55039e04SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*55039e04SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*55039e04SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*55039e04SAndroid Build Coastguard Worker  * limitations under the License.
15*55039e04SAndroid Build Coastguard Worker  */
16*55039e04SAndroid Build Coastguard Worker 
17*55039e04SAndroid Build Coastguard Worker #include "bpf_helpers.h"
18*55039e04SAndroid Build Coastguard Worker 
19*55039e04SAndroid Build Coastguard Worker // This can't be easily changed since the program is loaded on boot and may be
20*55039e04SAndroid Build Coastguard Worker // run against tests at a slightly different version.
21*55039e04SAndroid Build Coastguard Worker #define TEST_RINGBUF_MAGIC_NUM 12345
22*55039e04SAndroid Build Coastguard Worker 
23*55039e04SAndroid Build Coastguard Worker // This ring buffer is for testing purposes only.
24*55039e04SAndroid Build Coastguard Worker DEFINE_BPF_RINGBUF(test_ringbuf, __u64, 4096, AID_ROOT, AID_ROOT, 0660);
25*55039e04SAndroid Build Coastguard Worker 
26*55039e04SAndroid Build Coastguard Worker // This program is for test purposes only - it should never be attached to a
27*55039e04SAndroid Build Coastguard Worker // socket, only executed manually with BPF_PROG_RUN.
28*55039e04SAndroid Build Coastguard Worker DEFINE_BPF_PROG_KVER("skfilter/ringbuf_test", AID_ROOT, AID_ROOT, test_ringbuf_prog, KVER(5, 8, 0))
29*55039e04SAndroid Build Coastguard Worker (void* __unused ctx) {
30*55039e04SAndroid Build Coastguard Worker     __u64* output = bpf_test_ringbuf_reserve();
31*55039e04SAndroid Build Coastguard Worker     if (output == NULL) return 1;
32*55039e04SAndroid Build Coastguard Worker 
33*55039e04SAndroid Build Coastguard Worker     (*output) = TEST_RINGBUF_MAGIC_NUM;
34*55039e04SAndroid Build Coastguard Worker     bpf_test_ringbuf_submit(output);
35*55039e04SAndroid Build Coastguard Worker 
36*55039e04SAndroid Build Coastguard Worker     return 0;
37*55039e04SAndroid Build Coastguard Worker }
38*55039e04SAndroid Build Coastguard Worker 
39*55039e04SAndroid Build Coastguard Worker LICENSE("Apache 2.0");
40*55039e04SAndroid Build Coastguard Worker CRITICAL("BPF Ringbuf test");
41