Netd bpf requires 5.10 at least in 25Q4.
This CL enforces that.
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I76e52b2a2702a2a6ce761a947a0749ea798778b6
Maciej Żenczykowskicommited 2025-05-06 05:28:23 -07:00
Add 25Q3, 25Q4, 26Q1 and 26Q2 SDKs to the bpfloader helpers. The Q3 and
beyond versions are not finalized, so they are not being populated in
BpfUtils.h yet, but at least the logic is in place.
Test: TreeHugger
Flag: EXEMPT test code
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6ea12e347462be2c8258a4fe5bc994b35d4065a5
Maciej Żenczykowskicommited 2025-05-06 02:55:33 -07:00
The lambda was capturing btf by value instead of reference. This meant
that btf__free was never called, because at the time of capture btf was
null.
This changes the lambda to capture btf by reference instead of by value.
Test: TH
Flag: EXEMPT mainline
Bug: 411323352
Change-Id: I6c6637b10f16d48f9ae5b702e44883046b46e252
This code requires
!isArm()
isUserspace32bit()
isAtLeastKernelVersion(6, 7, 0)
which implies
isAtLeastKernelVersion(6, 2, 0)
meaning we match the condition in 1801,
and don't match the isArm() conditions in 1803/1806/1810,
thus we'd have already 'returned 1' in line 1815.
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I234ba91b9bdbfeaf1077eac64248d3ebfe2f2cd2
Maciej Żenczykowskicommited 2025-04-15 13:48:19 -07:00
BTF_KIND_VAR and BTF_KIND_DATASEC were introduced in 5.2.
It should be possible to enable BTF on 4.18 or above since libbpf can
load BTF.
Also, current code should work on 5.4 but this is untested.
For now, this CL enables BTF on 5.10 or above.
Test: boot on 4.9, 4.19, 5.10
Test: adb logcat | grep NetBpfLoad
Change-Id: I3da4970464afcf9a76b1f2645ed79c44750bcd6a
Since btf is declared in inner scope, btf is null in outer scope and BTF
was always disabled.
This CL also makes NetBpfLoad buildable with -Wshadow flag
Test: adb log | grep NetBpfLoad
Change-Id: I511f21a3620ccfdadd797786e087d0d142c816ed
One ALOG to record whether the map is created by btf or not.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5da3af67ba28b01ee4e7b08e61f1fedc24e2840f
Maciej Żenczykowskicommited 2025-03-18 23:01:20 -07:00
BPF_ANNOTATE_KV_PAIR is used to tell the bpf loader about the btf
key_type and value_type of a bpf map.
This CL adds a method to get key value type ids from
BPF_ANNOTATE_KV_PAIR
Bug: 403381101
Test: boot
Change-Id: If308d49b64b38f65991a0a8177e5072d54e2cdf6
Motomu Utsumiauthored and Maciej Żenczykowskicommited 2025-03-18 12:15:39 -07:00
size in btf_type of BTF_KIND_DATASEC is 0 at compilation time.
So bpf loader needs to update to actual size based on ELF's section
size.
Bug: 403381101
Test: boot
Change-Id: I78fb26a5b8eeb120044b5737667f472fac51d79f
Motomu Utsumiauthored and Maciej Żenczykowskicommited 2025-03-18 11:46:16 -07:00
Test: TreeHugger, manually installing tethering apex
(with and without dnsresolver apex) on pixel 6 running S
incl. 'atest bpf_existence_test'
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I63d4b84287e9c98dc0d2a517ac58d3f3ce9d7760
Maciej Żenczykowskicommited 2025-03-05 14:27:59 -08:00
Failure to jit means a buggy in kernel eBPF JIT implementation.
This cannot fail on a 64-bit kernel, because VINTF requires
kernel configuration option CONFIG_BPF_JIT_ALWAYS_ON.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I10cf7ff86bba6d3571ba919300024947446f1bb6
Maciej Żenczykowskicommited 2025-02-14 11:22:13 -08:00
This should always work on 4.14+
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I50fc17ff5b77f279cb741d6ef72e0519733ec881
Maciej Żenczykowskicommited 2025-02-14 11:18:18 -08:00
The function is not available in older kernels.
But when we do call it, fail on error - should not happen.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2695bf01762abcbc087a3bd67f1718e0e326576a
Maciej Żenczykowskicommited 2025-02-13 16:10:48 -08:00
for consistency with 3 other spots
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I726c314cbf70e3a9c09d4f95cf79109db38b59f7
Maciej Żenczykowskicommited 2025-02-13 16:05:07 -08:00
This intentionally does not block 32-bit userspace,
but it does mean existing 32-on-32 devices will need to
upgrade to 32-on-64 to upgrade to 25Q2+. Even Wear/TV.
This will allow us to unconditionally start using 64-bit
cli binaries for network admin tasks and avoid the entire
insanity that is 32-bit kernel net admin ABI of
iptables/netfilter & xfrm/ipsec.
Note: on at least x86 there's already code in netd that is outright incorrect if the kernel is not 64-bit.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9c18f82b38adeb223ffe3c6aebda50f057f3c818
Maciej Żenczykowskicommited 2025-02-10 21:54:34 -08:00
This reverts commit dcb2e7496c.
Reason for revert: will use negative size to imply no prealloc instead.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If1ce59acc592435537bce1d61857ba964bf8b6e6
Maciej Żenczykowskicommited 2025-01-20 12:10:04 -08:00
Note: this effectively (like the 6.6 check) does nothing atm, and is included purely for completeness.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9de5adffa0589cbf19fa4ddcb3cfe491f1600fde
Maciej Żenczykowskicommited 2024-12-11 07:14:12 -08:00
This unblocks building and testing for these devices on V only.
Networking may not work correctly, but at least the device will
boot.
Fix: 374252805
Test: cannot be tested due to lack of devices
Change-Id: I5be400d825bf7486454ff34e17123adac81a4447
Lorenzo Colitticommited 2024-12-04 09:59:33 +00:00
All 6 .c files under bpf/progs are flagged CRITICAL(),
and as such we can simplify this logic.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I884705e1f0fdb20c992499aa2c83d5953a24fd9e
Maciej Żenczykowskicommited 2024-09-18 23:46:16 +00:00
log_buf.size() was always BPF_LOAD_LOG_SZ and thus != 0
After changing ALOGD to ALOGI you now see (for example):
NetBpfLoad: BPF_PROG_LOAD call for /apex/com.android.tethering/etc/bpf/net_shared/block.o (bind4_block_port) returned 'processed 55 insns (limit 1000000) max_states_per_insn 0 total_states 4 peak_states 4 mark_read 1' fd: 6 (ok)
(ALOGV/ALOGD's are effectively silently dropped by the KernelLogger we use)
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4a296976ae3f1e2217c46d81ed48850fdfa95a3c
Maciej Żenczykowskicommited 2024-09-05 22:00:33 +00:00
(since this map relies on percpu access semantics,
and we don't even have userspace helpers to access PERCPU_ maps)
This will also be used by the upcoming satellite egress limiting logic.
See aosp/3235142
With this change we see:
$ adbz shell ls -lZ /sys/fs/bpf/net_shared/*_dscpPolicy_*
-rw-rw---- 1 root system u:object_r:fs_bpf_net_shared:s0 0 2024-09-04 17:01 /sys/fs/bpf/net_shared/map_dscpPolicy_ipv4_dscp_policies_map
-rw-rw---- 1 root system u:object_r:fs_bpf_net_shared:s0 0 2024-09-04 17:01 /sys/fs/bpf/net_shared/map_dscpPolicy_ipv6_dscp_policies_map
---------- 1 root root u:object_r:fs_bpf_loader:s0 0 2024-09-04 17:01 /sys/fs/bpf/net_shared/map_dscpPolicy_socket_policy_cache_map
-r--r----- 1 root system u:object_r:fs_bpf_net_shared:s0 0 2024-09-04 17:01 /sys/fs/bpf/net_shared/prog_dscpPolicy_schedcls_set_dscp_ether
Test: TreeHugger, atest CtsNetTestCases:android.net.cts.DscpPolicyTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I50a12ca4cd5587342f8aaf9df8cb28917f555252
Maciej Żenczykowskicommited 2024-09-04 17:41:47 -07:00
To shorten lines.
Now:
egrep 'base:' NetBpfLoad.cpp
only finds the 'using' statements.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8b125c420c106e4b9c2af0a4fa2e4892a08bb152
Maciej Żenczykowskicommited 2024-09-04 11:43:31 -07:00