android_packages_modules_Co.../bpf_progs/Android.bp

148 lines
3.1 KiB
Plaintext
Raw Normal View History

//
// Copyright (C) 2020 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.
//
//
// struct definitions shared with JNI
//
package {
default_applicable_licenses: ["Android-Apache-2.0"],
}
cc_library_headers {
name: "bpf_connectivity_headers",
vendor_available: false,
host_supported: false,
header_libs: [
"bpf_headers",
"netd_mainline_headers",
],
export_header_lib_headers: [
"bpf_headers",
"netd_mainline_headers",
],
export_include_dirs: ["."],
cflags: [
"-Wall",
"-Werror",
],
sdk_version: "30",
min_sdk_version: "30",
apex_available: [
"//apex_available:platform",
"com.android.tethering",
],
visibility: [
"//packages/modules/Connectivity/netd",
"//packages/modules/Connectivity/service",
"//packages/modules/Connectivity/service/native/libs/libclat",
"//packages/modules/Connectivity/Tethering",
"//packages/modules/Connectivity/service/native",
"//packages/modules/Connectivity/tests/native",
"//packages/modules/Connectivity/service-t/native/libs/libnetworkstats",
"//packages/modules/Connectivity/tests/unit/jni",
"//system/netd/tests",
],
}
//
// bpf kernel programs
//
bpf {
name: "block.o",
srcs: ["block.c"],
enable btf = true for block/clatd/dscp_policy/netd bpf programs (we avoid offload - for now - due to that being shipped to <T devices) Before: $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/net_shared/*.o -rw-r--r-- 1 system system 2848 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/block.o -rw-r--r-- 1 system system 10240 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/clatd.o -rw-r--r-- 1 system system 16144 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/dscp_policy.o -rw-r--r-- 1 system system 18840 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/netd.o After: $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/net_shared/*.o -rw-r--r-- 1 system system 6192 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/block.o -rw-r--r-- 1 system system 19008 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/clatd.o -rw-r--r-- 1 system system 23960 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/dscp_policy.o -rw-r--r-- 1 system system 27112 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/netd.o So there is a minor increase in .o size, but this allows: $ adbz shell cat /sys/fs/bpf/net_shared/map_netd_iface_index_name_map # WARNING!! The output is for debug purpose only # WARNING!! The output format will change 8: {['e','r','s','p','a','n','0',],} 1: {['l','o',],} 4: {['i','f','b','1',],} 2: {['d','u','m','m','y','0',],} 16: {['e','t','h','1',],} 5: {['t','u','n','l','0',],} 14: {['h','w','s','i','m','0',],} 17: {['w','l','a','n','0',],} 12: {['i','p','6','t','n','l','0',],} 18: {['w','l','a','n','1',],} 13: {['i','p','6','g','r','e','0',],} 3: {['i','f','b','0',],} 15: {['b','u','r','i','e','d','_','e','t','h','0',],} 9: {['i','p','_','v','t','i','0',],} 11: {['s','i','t','0',],} 10: {['i','p','6','_','v','t','i','0',],} 6: {['g','r','e','0',],} 7: {['g','r','e','t','a','p','0',],} This is safe as the net_shared bpf programs are not loaded on pre-T devices, and the T bpfloader is btf enabled. Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I2d480391b6d1a6e2ba99b0445281684d4a51d74b
2022-01-28 19:18:08 +00:00
btf: true,
cflags: [
"-Wall",
"-Werror",
],
sub_dir: "net_shared",
}
bpf {
name: "dscp_policy.o",
srcs: ["dscp_policy.c"],
enable btf = true for block/clatd/dscp_policy/netd bpf programs (we avoid offload - for now - due to that being shipped to <T devices) Before: $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/net_shared/*.o -rw-r--r-- 1 system system 2848 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/block.o -rw-r--r-- 1 system system 10240 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/clatd.o -rw-r--r-- 1 system system 16144 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/dscp_policy.o -rw-r--r-- 1 system system 18840 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/netd.o After: $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/net_shared/*.o -rw-r--r-- 1 system system 6192 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/block.o -rw-r--r-- 1 system system 19008 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/clatd.o -rw-r--r-- 1 system system 23960 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/dscp_policy.o -rw-r--r-- 1 system system 27112 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/netd.o So there is a minor increase in .o size, but this allows: $ adbz shell cat /sys/fs/bpf/net_shared/map_netd_iface_index_name_map # WARNING!! The output is for debug purpose only # WARNING!! The output format will change 8: {['e','r','s','p','a','n','0',],} 1: {['l','o',],} 4: {['i','f','b','1',],} 2: {['d','u','m','m','y','0',],} 16: {['e','t','h','1',],} 5: {['t','u','n','l','0',],} 14: {['h','w','s','i','m','0',],} 17: {['w','l','a','n','0',],} 12: {['i','p','6','t','n','l','0',],} 18: {['w','l','a','n','1',],} 13: {['i','p','6','g','r','e','0',],} 3: {['i','f','b','0',],} 15: {['b','u','r','i','e','d','_','e','t','h','0',],} 9: {['i','p','_','v','t','i','0',],} 11: {['s','i','t','0',],} 10: {['i','p','6','_','v','t','i','0',],} 6: {['g','r','e','0',],} 7: {['g','r','e','t','a','p','0',],} This is safe as the net_shared bpf programs are not loaded on pre-T devices, and the T bpfloader is btf enabled. Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I2d480391b6d1a6e2ba99b0445281684d4a51d74b
2022-01-28 19:18:08 +00:00
btf: true,
cflags: [
"-Wall",
"-Werror",
],
sub_dir: "net_shared",
}
bpf {
name: "offload.o",
srcs: ["offload.c"],
cflags: [
"-Wall",
"-Werror",
],
}
enable btf for offload.o & test.o The objdump -x visible changes between old and new versions of the mainline shipped .o files are really very minimal: just the inclusion of a new .BTF section and changes/removals of some 'l' entries from the symbol table. However, it turns out a change to symbol ordering is incompatible with BpfLoader <v0.10 which doesn't know to skip non-function symbols, and as such enabling btf requires a little bit of gymnastics. After: $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/*.o -rw-r--r-- 1 system system 118352 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/offload.o -rw-r--r-- 1 system system 123424 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/offload@btf.o -rw-r--r-- 1 system system 2232 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/test.o -rw-r--r-- 1 system system 6376 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/test@btf.o $ adbz shell logcat -d | egrep offload.*[.]o 07-15 13:10:43.358 0 0 D LibBpfLoader: Loading critical for tethering ELF object /apex/com.android.tethering/etc/bpf/offload.o with license Apache 2.0 07-15 13:10:43.359 0 0 I LibBpfLoader: BpfLoader version 0x00019 ignoring ELF object /apex/com.android.tethering/etc/bpf/offload.o with max ver 0x00019 07-15 13:10:43.359 0 0 I bpfloader: Loaded object: /apex/com.android.tethering/etc/bpf/offload.o 07-15 13:10:43.374 0 0 D LibBpfLoader: Loading critical for tethering ELF object /apex/com.android.tethering/etc/bpf/offload@btf.o with license Apache 2.0 07-15 13:10:43.375 0 0 I LibBpfLoader: BpfLoader version 0x00019 processing ELF object /apex/com.android.tethering/etc/bpf/offload@btf.o with ver [0x00019,0x10000) 07-15 13:10:43.452 0 0 D LibBpfLoader: map_fd found at 0 is 6 in /apex/com.android.tethering/etc/bpf/offload@btf.o ... Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: Id658818d1d42763358747523615b7918d312588e
2022-04-23 19:33:32 +00:00
bpf {
name: "offload@btf.o",
srcs: ["offload@btf.c"],
btf: true,
cflags: [
"-Wall",
"-Werror",
"-DBTF",
],
}
bpf {
name: "test.o",
srcs: ["test.c"],
cflags: [
"-Wall",
"-Werror",
],
}
enable btf for offload.o & test.o The objdump -x visible changes between old and new versions of the mainline shipped .o files are really very minimal: just the inclusion of a new .BTF section and changes/removals of some 'l' entries from the symbol table. However, it turns out a change to symbol ordering is incompatible with BpfLoader <v0.10 which doesn't know to skip non-function symbols, and as such enabling btf requires a little bit of gymnastics. After: $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/*.o -rw-r--r-- 1 system system 118352 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/offload.o -rw-r--r-- 1 system system 123424 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/offload@btf.o -rw-r--r-- 1 system system 2232 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/test.o -rw-r--r-- 1 system system 6376 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/test@btf.o $ adbz shell logcat -d | egrep offload.*[.]o 07-15 13:10:43.358 0 0 D LibBpfLoader: Loading critical for tethering ELF object /apex/com.android.tethering/etc/bpf/offload.o with license Apache 2.0 07-15 13:10:43.359 0 0 I LibBpfLoader: BpfLoader version 0x00019 ignoring ELF object /apex/com.android.tethering/etc/bpf/offload.o with max ver 0x00019 07-15 13:10:43.359 0 0 I bpfloader: Loaded object: /apex/com.android.tethering/etc/bpf/offload.o 07-15 13:10:43.374 0 0 D LibBpfLoader: Loading critical for tethering ELF object /apex/com.android.tethering/etc/bpf/offload@btf.o with license Apache 2.0 07-15 13:10:43.375 0 0 I LibBpfLoader: BpfLoader version 0x00019 processing ELF object /apex/com.android.tethering/etc/bpf/offload@btf.o with ver [0x00019,0x10000) 07-15 13:10:43.452 0 0 D LibBpfLoader: map_fd found at 0 is 6 in /apex/com.android.tethering/etc/bpf/offload@btf.o ... Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: Id658818d1d42763358747523615b7918d312588e
2022-04-23 19:33:32 +00:00
bpf {
name: "test@btf.o",
srcs: ["test@btf.c"],
btf: true,
cflags: [
"-Wall",
"-Werror",
"-DBTF",
],
}
bpf {
name: "clatd.o",
srcs: ["clatd.c"],
enable btf = true for block/clatd/dscp_policy/netd bpf programs (we avoid offload - for now - due to that being shipped to <T devices) Before: $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/net_shared/*.o -rw-r--r-- 1 system system 2848 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/block.o -rw-r--r-- 1 system system 10240 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/clatd.o -rw-r--r-- 1 system system 16144 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/dscp_policy.o -rw-r--r-- 1 system system 18840 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/netd.o After: $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/net_shared/*.o -rw-r--r-- 1 system system 6192 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/block.o -rw-r--r-- 1 system system 19008 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/clatd.o -rw-r--r-- 1 system system 23960 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/dscp_policy.o -rw-r--r-- 1 system system 27112 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/netd.o So there is a minor increase in .o size, but this allows: $ adbz shell cat /sys/fs/bpf/net_shared/map_netd_iface_index_name_map # WARNING!! The output is for debug purpose only # WARNING!! The output format will change 8: {['e','r','s','p','a','n','0',],} 1: {['l','o',],} 4: {['i','f','b','1',],} 2: {['d','u','m','m','y','0',],} 16: {['e','t','h','1',],} 5: {['t','u','n','l','0',],} 14: {['h','w','s','i','m','0',],} 17: {['w','l','a','n','0',],} 12: {['i','p','6','t','n','l','0',],} 18: {['w','l','a','n','1',],} 13: {['i','p','6','g','r','e','0',],} 3: {['i','f','b','0',],} 15: {['b','u','r','i','e','d','_','e','t','h','0',],} 9: {['i','p','_','v','t','i','0',],} 11: {['s','i','t','0',],} 10: {['i','p','6','_','v','t','i','0',],} 6: {['g','r','e','0',],} 7: {['g','r','e','t','a','p','0',],} This is safe as the net_shared bpf programs are not loaded on pre-T devices, and the T bpfloader is btf enabled. Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I2d480391b6d1a6e2ba99b0445281684d4a51d74b
2022-01-28 19:18:08 +00:00
btf: true,
cflags: [
"-Wall",
"-Werror",
],
sub_dir: "net_shared",
}
bpf {
// WARNING: Android T's non-updatable netd depends on 'netd' string for xt_bpf programs it loads
name: "netd.o",
srcs: ["netd.c"],
enable btf = true for block/clatd/dscp_policy/netd bpf programs (we avoid offload - for now - due to that being shipped to <T devices) Before: $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/net_shared/*.o -rw-r--r-- 1 system system 2848 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/block.o -rw-r--r-- 1 system system 10240 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/clatd.o -rw-r--r-- 1 system system 16144 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/dscp_policy.o -rw-r--r-- 1 system system 18840 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/netd.o After: $ adbz shell ls -l /apex/com.android.tethering/etc/bpf/net_shared/*.o -rw-r--r-- 1 system system 6192 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/block.o -rw-r--r-- 1 system system 19008 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/clatd.o -rw-r--r-- 1 system system 23960 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/dscp_policy.o -rw-r--r-- 1 system system 27112 1969-12-31 16:00 /apex/com.android.tethering/etc/bpf/net_shared/netd.o So there is a minor increase in .o size, but this allows: $ adbz shell cat /sys/fs/bpf/net_shared/map_netd_iface_index_name_map # WARNING!! The output is for debug purpose only # WARNING!! The output format will change 8: {['e','r','s','p','a','n','0',],} 1: {['l','o',],} 4: {['i','f','b','1',],} 2: {['d','u','m','m','y','0',],} 16: {['e','t','h','1',],} 5: {['t','u','n','l','0',],} 14: {['h','w','s','i','m','0',],} 17: {['w','l','a','n','0',],} 12: {['i','p','6','t','n','l','0',],} 18: {['w','l','a','n','1',],} 13: {['i','p','6','g','r','e','0',],} 3: {['i','f','b','0',],} 15: {['b','u','r','i','e','d','_','e','t','h','0',],} 9: {['i','p','_','v','t','i','0',],} 11: {['s','i','t','0',],} 10: {['i','p','6','_','v','t','i','0',],} 6: {['g','r','e','0',],} 7: {['g','r','e','t','a','p','0',],} This is safe as the net_shared bpf programs are not loaded on pre-T devices, and the T bpfloader is btf enabled. Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I2d480391b6d1a6e2ba99b0445281684d4a51d74b
2022-01-28 19:18:08 +00:00
btf: true,
cflags: [
"-Wall",
"-Werror",
],
// WARNING: Android T's non-updatable netd depends on 'netd_shared' string for xt_bpf programs
sub_dir: "netd_shared",
}