blob: aa6d8dece961c25f710935f8db112ad71d5fc6f4 [file] [log] [blame]
Maciej Żenczykowskie9810ff2021-01-14 20:02:08 -08001/*
2 * Copyright (C) 2021 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 Żenczykowski561fb4a2023-10-24 18:48:54 -070017#ifdef MAINLINE
Maciej Żenczykowski07d30132022-04-23 12:33:32 -070018// BTF is incompatible with bpfloaders < v0.10, hence for S (v0.2) we must
19// ship a different file than for later versions, but we need bpfloader v0.25+
20// for obj@ver.o support
Maciej Żenczykowski4e4f8722024-06-15 06:38:08 -070021#define BPFLOADER_MIN_VER BPFLOADER_MAINLINE_T_VERSION
Maciej Żenczykowski561fb4a2023-10-24 18:48:54 -070022#else /* MAINLINE */
Maciej Żenczykowski4e4f8722024-06-15 06:38:08 -070023// The resulting .o needs to load on the Android S bpfloader
Maciej Żenczykowskif7699522022-05-24 15:56:03 -070024#define BPFLOADER_MIN_VER BPFLOADER_S_VERSION
Maciej Żenczykowski4e4f8722024-06-15 06:38:08 -070025#define BPFLOADER_MAX_VER BPFLOADER_T_VERSION
Maciej Żenczykowski561fb4a2023-10-24 18:48:54 -070026#endif /* MAINLINE */
Maciej Żenczykowskia457bf72021-10-22 21:41:25 -070027
Maciej Żenczykowskic8e40c12022-10-21 00:01:39 +000028// This is non production code, only used for testing
29// Needed because the bitmap array definition is non-kosher for pre-T OS devices.
30#define THIS_BPF_PROGRAM_IS_FOR_TEST_PURPOSES_ONLY
31
Maciej Żenczykowskie9810ff2021-01-14 20:02:08 -080032#include "bpf_net_helpers.h"
Maciej Żenczykowski4e3321e2022-12-08 12:59:23 +000033#include "offload.h"
Maciej Żenczykowskie9810ff2021-01-14 20:02:08 -080034
35// Used only by TetheringPrivilegedTests, not by production code.
Maciej Żenczykowski7dfbcf52021-01-26 16:08:57 -080036DEFINE_BPF_MAP_GRW(tether_downstream6_map, HASH, TetherDownstream6Key, Tether6Value, 16,
Maciej Żenczykowski1edfbf82024-08-16 18:08:09 -070037 AID_NETWORK_STACK)
Maciej Żenczykowski45e93722024-06-15 11:47:26 -070038DEFINE_BPF_MAP_GRW(tether2_downstream6_map, HASH, TetherDownstream6Key, Tether6Value, 16,
Maciej Żenczykowski1edfbf82024-08-16 18:08:09 -070039 AID_NETWORK_STACK)
Maciej Żenczykowski878aae02024-06-15 11:54:36 -070040DEFINE_BPF_MAP_GRW(tether3_downstream6_map, HASH, TetherDownstream6Key, Tether6Value, 16,
Maciej Żenczykowski1edfbf82024-08-16 18:08:09 -070041 AID_NETWORK_STACK)
Tyler Wearc23ffbd2021-12-01 16:25:00 -080042// Used only by BpfBitmapTest, not by production code.
Maciej Żenczykowski1edfbf82024-08-16 18:08:09 -070043DEFINE_BPF_MAP_GRW(bitmap, ARRAY, int, uint64_t, 2, AID_NETWORK_STACK)
Maciej Żenczykowskie9810ff2021-01-14 20:02:08 -080044
Maciej Żenczykowski1edfbf82024-08-16 18:08:09 -070045DEFINE_BPF_PROG_KVER("xdp/drop_ipv4_udp_ether", AID_ROOT, AID_NETWORK_STACK,
Maciej Żenczykowski901c7102023-10-06 15:47:46 -070046 xdp_test, KVER_5_9)
Maciej Żenczykowski8c7cd342021-01-18 00:02:19 -080047(struct xdp_md *ctx) {
48 void *data = (void *)(long)ctx->data;
49 void *data_end = (void *)(long)ctx->data_end;
50
51 struct ethhdr *eth = data;
52 int hsize = sizeof(*eth);
53
54 struct iphdr *ip = data + hsize;
55 hsize += sizeof(struct iphdr);
56
57 if (data + hsize > data_end) return XDP_PASS;
58 if (eth->h_proto != htons(ETH_P_IP)) return XDP_PASS;
59 if (ip->protocol == IPPROTO_UDP) return XDP_DROP;
60 return XDP_PASS;
61}
62
Maciej Żenczykowskie9810ff2021-01-14 20:02:08 -080063LICENSE("Apache 2.0");
Maciej Żenczykowskide1342a2023-06-09 05:45:57 +000064DISABLE_BTF_ON_USER_BUILDS();