Note: due to the release version of the Connectivity/Tethering mainline module being built from sc-mainline-prod, this won't actually take effect until system/bpf bpfloader at version 0.6+ is merged in to that tree. This doesn't really matter, since currently things default to v0.0+. But there is no mainline module updatable pre-v0.2 supported OS anyway. BpfLoader v0.2 is what shipped in Android S Beta 4 through Android S Final. Before S there simply was no bpfloader support for mainline updatable ebpf code, while S Beta 3 and earlier shipped v0.0 which is badly incompatible with even the current version of the mainline module. Additionally v0.0 doesn't even parse this field, while v0.1 which does was very short lived [~3 days] and can thus be utterly ignored. As such this change is effectively a no-op, and even post merge of bpfloader v0.6+ into sc-mainline-prod will still be effectively a no-op. So why do it? I want to explicitly document that these programs are S+, so that I can change the default in the future to be T+. Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I7e5d0124700c7045abe16b1f3b504c9e88054ff2
51 lines
1.6 KiB
C
51 lines
1.6 KiB
C
/*
|
|
* Copyright (C) 2021 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include <linux/if_ether.h>
|
|
#include <linux/in.h>
|
|
#include <linux/ip.h>
|
|
|
|
// The resulting .o needs to load on the Android S bpfloader v0.2
|
|
#define BPFLOADER_MIN_VER 2u
|
|
|
|
#include "bpf_helpers.h"
|
|
#include "bpf_net_helpers.h"
|
|
#include "bpf_tethering.h"
|
|
|
|
// Used only by TetheringPrivilegedTests, not by production code.
|
|
DEFINE_BPF_MAP_GRW(tether_downstream6_map, HASH, TetherDownstream6Key, Tether6Value, 16,
|
|
AID_NETWORK_STACK)
|
|
|
|
DEFINE_BPF_PROG_KVER("xdp/drop_ipv4_udp_ether", AID_ROOT, AID_NETWORK_STACK,
|
|
xdp_test, KVER(5, 9, 0))
|
|
(struct xdp_md *ctx) {
|
|
void *data = (void *)(long)ctx->data;
|
|
void *data_end = (void *)(long)ctx->data_end;
|
|
|
|
struct ethhdr *eth = data;
|
|
int hsize = sizeof(*eth);
|
|
|
|
struct iphdr *ip = data + hsize;
|
|
hsize += sizeof(struct iphdr);
|
|
|
|
if (data + hsize > data_end) return XDP_PASS;
|
|
if (eth->h_proto != htons(ETH_P_IP)) return XDP_PASS;
|
|
if (ip->protocol == IPPROTO_UDP) return XDP_DROP;
|
|
return XDP_PASS;
|
|
}
|
|
|
|
LICENSE("Apache 2.0");
|