blob: 3f0df2eae76305e4c3a8607df47ef63954c6f55d [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 Żenczykowski8c7cd342021-01-18 00:02:19 -080017#include <linux/if_ether.h>
18#include <linux/in.h>
19#include <linux/ip.h>
20
Maciej Żenczykowskie9810ff2021-01-14 20:02:08 -080021#include "bpf_helpers.h"
22#include "bpf_net_helpers.h"
Lorenzo Colitti56be03e2021-02-24 00:10:44 +090023#include "bpf_tethering.h"
Maciej Żenczykowskie9810ff2021-01-14 20:02:08 -080024
25// Used only by TetheringPrivilegedTests, not by production code.
Maciej Żenczykowski7dfbcf52021-01-26 16:08:57 -080026DEFINE_BPF_MAP_GRW(tether_downstream6_map, HASH, TetherDownstream6Key, Tether6Value, 16,
Maciej Żenczykowskie9810ff2021-01-14 20:02:08 -080027 AID_NETWORK_STACK)
28
Maciej Żenczykowski5b00fbd2021-01-19 23:37:51 -080029DEFINE_BPF_PROG_KVER("xdp/drop_ipv4_udp_ether", AID_ROOT, AID_NETWORK_STACK,
Maciej Żenczykowski8c7cd342021-01-18 00:02:19 -080030 xdp_test, KVER(5, 9, 0))
31(struct xdp_md *ctx) {
32 void *data = (void *)(long)ctx->data;
33 void *data_end = (void *)(long)ctx->data_end;
34
35 struct ethhdr *eth = data;
36 int hsize = sizeof(*eth);
37
38 struct iphdr *ip = data + hsize;
39 hsize += sizeof(struct iphdr);
40
41 if (data + hsize > data_end) return XDP_PASS;
42 if (eth->h_proto != htons(ETH_P_IP)) return XDP_PASS;
43 if (ip->protocol == IPPROTO_UDP) return XDP_DROP;
44 return XDP_PASS;
45}
46
Maciej Żenczykowskie9810ff2021-01-14 20:02:08 -080047LICENSE("Apache 2.0");