diff --git a/Tethering/apex/Android.bp b/Tethering/apex/Android.bp index c99121cae7..7970944329 100644 --- a/Tethering/apex/Android.bp +++ b/Tethering/apex/Android.bp @@ -27,7 +27,10 @@ apex { jni_libs: [ "libservice-connectivity", ], - bpfs: ["offload.o"], + bpfs: [ + "offload.o", + "test.o", + ], apps: ["Tethering"], manifest: "manifest.json", key: "com.android.tethering.key", diff --git a/Tethering/bpf_progs/Android.bp b/Tethering/bpf_progs/Android.bp index d54f861486..d62e9a1b4c 100644 --- a/Tethering/bpf_progs/Android.bp +++ b/Tethering/bpf_progs/Android.bp @@ -31,3 +31,18 @@ bpf { "system/netd/libnetdutils/include", // for UidConstants.h ], } + +bpf { + name: "test.o", + srcs: ["test.c"], + cflags: [ + "-Wall", + "-Werror", + ], + include_dirs: [ + // TODO: get rid of system/netd. + "system/netd/bpf_progs", // for bpf_net_helpers.h + "system/netd/libnetdbpf/include", // for bpf_shared.h + "system/netd/libnetdutils/include", // for UidConstants.h + ], +} diff --git a/Tethering/bpf_progs/offload.c b/Tethering/bpf_progs/offload.c index d8dc60dc1a..cc5af3127b 100644 --- a/Tethering/bpf_progs/offload.c +++ b/Tethering/bpf_progs/offload.c @@ -34,10 +34,6 @@ DEFINE_BPF_MAP_GRW(tether_stats_map, HASH, uint32_t, TetherStatsValue, 16, AID_N // (tethering allowed when stats[iif].rxBytes + stats[iif].txBytes < limit[iif]) DEFINE_BPF_MAP_GRW(tether_limit_map, HASH, uint32_t, uint64_t, 16, AID_NETWORK_STACK) -// Used only by TetheringPrivilegedTests, not by production code. -DEFINE_BPF_MAP_GRW(tether_ingress_map_TEST, HASH, TetherIngressKey, TetherIngressValue, 16, - AID_NETWORK_STACK) - static inline __always_inline int do_forward(struct __sk_buff* skb, bool is_ethernet) { int l2_header_size = is_ethernet ? sizeof(struct ethhdr) : 0; void* data = (void*)(long)skb->data; diff --git a/Tethering/bpf_progs/test.c b/Tethering/bpf_progs/test.c new file mode 100644 index 0000000000..b5be33f459 --- /dev/null +++ b/Tethering/bpf_progs/test.c @@ -0,0 +1,25 @@ +/* + * 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 "bpf_helpers.h" +#include "bpf_net_helpers.h" +#include "netdbpf/bpf_shared.h" + +// Used only by TetheringPrivilegedTests, not by production code. +DEFINE_BPF_MAP_GRW(tether_ingress_map, HASH, TetherIngressKey, TetherIngressValue, 16, + AID_NETWORK_STACK) + +LICENSE("Apache 2.0"); diff --git a/Tethering/tests/privileged/src/com/android/networkstack/tethering/BpfMapTest.java b/Tethering/tests/privileged/src/com/android/networkstack/tethering/BpfMapTest.java index 1ddbaa9a20..04c1f00064 100644 --- a/Tethering/tests/privileged/src/com/android/networkstack/tethering/BpfMapTest.java +++ b/Tethering/tests/privileged/src/com/android/networkstack/tethering/BpfMapTest.java @@ -52,7 +52,7 @@ public final class BpfMapTest { // Sync from packages/modules/Connectivity/Tethering/bpf_progs/offload.c. private static final int TEST_MAP_SIZE = 16; private static final String TETHER_INGRESS_FS_PATH = - "/sys/fs/bpf/map_offload_tether_ingress_map_TEST"; + "/sys/fs/bpf/map_test_tether_ingress_map"; private ArrayMap mTestData;