blob: c189e6c896d1446b2d425f79fd075bebf675aaa5 [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.
Maciej Żenczykowski4038b8f2023-10-06 14:42:38 -070024DEFINE_BPF_RINGBUF_EXT(test_ringbuf, __u64, 4096, AID_ROOT, AID_ROOT, 0660, "", "", PRIVATE,
25 BPFLOADER_MIN_VER, BPFLOADER_MAX_VER,
26 LOAD_ON_ENG, LOAD_ON_USER, LOAD_ON_USERDEBUG);
Ryan Zuklie65748202022-12-07 18:22:21 -080027
28// This program is for test purposes only - it should never be attached to a
29// socket, only executed manually with BPF_PROG_RUN.
30DEFINE_BPF_PROG_KVER("skfilter/ringbuf_test", AID_ROOT, AID_ROOT, test_ringbuf_prog, KVER(5, 8, 0))
Neill Kapron8ebb2232024-07-25 00:54:04 +000031(void* __unused ctx) {
Ryan Zuklie65748202022-12-07 18:22:21 -080032 __u64* output = bpf_test_ringbuf_reserve();
33 if (output == NULL) return 1;
34
35 (*output) = TEST_RINGBUF_MAGIC_NUM;
36 bpf_test_ringbuf_submit(output);
37
38 return 0;
39}
40
41LICENSE("Apache 2.0");
42CRITICAL("BPF Ringbuf test");