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