blob: cbf91049d0ea3838923293c7e7d6fd8217da587a [file] [log] [blame]
Ryan Zuklie65748202022-12-07 18:22:21 -08001/*
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.
Ryan Zuklieb41a3cf2023-01-04 18:01:28 -080024DEFINE_BPF_RINGBUF_EXT(test_ringbuf, __u64, 4096, AID_ROOT, AID_ROOT, 0660, "", "", false,
25 BPFLOADER_MIN_VER, BPFLOADER_MAX_VER, false, false, false);
Ryan Zuklie65748202022-12-07 18:22:21 -080026
27// This program is for test purposes only - it should never be attached to a
28// socket, only executed manually with BPF_PROG_RUN.
29DEFINE_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
40LICENSE("Apache 2.0");
41CRITICAL("BPF Ringbuf test");