blob: 9671b8afe83a7fef9ea78332f5d7ea745b35c28b [file] [log] [blame]
Chenbo Feng75b410b2018-10-10 15:01:19 -07001/*
2 * Copyright (C) 2017 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
Maciej Żenczykowski23c436f2021-01-21 14:24:15 -080017#pragma once
Chenbo Feng75b410b2018-10-10 15:01:19 -070018
Chenbo Feng75b410b2018-10-10 15:01:19 -070019#include <linux/if_ether.h>
Chenbo Feng75b410b2018-10-10 15:01:19 -070020#include <net/if.h>
21#include <stdlib.h>
22#include <string.h>
23#include <sys/socket.h>
24
Steven Morelande7cd2a72020-01-10 17:49:35 -080025#include <string>
26
Hungming Chena46f2172021-01-13 13:56:38 +080027#include "BpfSyscallWrappers.h"
Chenbo Feng0a1a9a12019-04-09 12:05:04 -070028
Chenbo Feng75b410b2018-10-10 15:01:19 -070029namespace android {
30namespace bpf {
31
Chenbo Feng75b410b2018-10-10 15:01:19 -070032constexpr const int OVERFLOW_COUNTERSET = 2;
33
34constexpr const uint64_t NONEXISTENT_COOKIE = 0;
35
Chenbo Feng75b410b2018-10-10 15:01:19 -070036uint64_t getSocketCookie(int sockFd);
Maciej Żenczykowskic3a640d2020-02-11 15:01:21 -080037int synchronizeKernelRCU();
Chenbo Feng0a1a9a12019-04-09 12:05:04 -070038int setrlimitForTest();
Maciej Żenczykowskidcb52282021-01-17 03:36:34 -080039
Maciej Żenczykowski30af4b52021-02-11 15:58:12 -080040#define KVER(a, b, c) (((a) << 24) + ((b) << 16) + (c))
Maciej Żenczykowskidcb52282021-01-17 03:36:34 -080041
Maciej Żenczykowski07375e22020-02-19 14:23:59 -080042unsigned kernelVersion();
Maciej Żenczykowskidcb52282021-01-17 03:36:34 -080043
44static inline bool isAtLeastKernelVersion(unsigned major, unsigned minor, unsigned sub) {
45 return kernelVersion() >= KVER(major, minor, sub);
46}
Maciej Żenczykowskic3a640d2020-02-11 15:01:21 -080047
Maciej Żenczykowskidcb52282021-01-17 03:36:34 -080048#define SKIP_IF_EXTENDED_BPF_NOT_SUPPORTED \
49 do { \
50 if (!android::bpf::isAtLeastKernelVersion(4, 14, 0)) { \
51 GTEST_LOG_(INFO) << "This test is skipped since extended bpf feature" \
52 << "not supported\n"; \
53 return; \
54 } \
Maciej Żenczykowski672b0e72020-02-12 04:15:20 -080055 } while (0)
56
Maciej Żenczykowskia36bed32021-01-20 15:23:40 -080057#define SKIP_IF_XDP_NOT_SUPPORTED \
58 do { \
59 if (!android::bpf::isAtLeastKernelVersion(5, 9, 0)) { \
60 GTEST_LOG_(INFO) << "This test is skipped since xdp" \
61 << "not supported\n"; \
62 return; \
63 } \
64 } while (0)
65
Chenbo Feng75b410b2018-10-10 15:01:19 -070066} // namespace bpf
67} // namespace android