* changes:
Store socket cookie to sk storage in inet_create hook on 5.10+ kernel
Declare map with BPF_MAP_TYPE_SK_STORAGE
Add macro to declare a sk storage and related accessor functions
Maciej Żenczykowskiauthored and Gerrit Code Reviewcommited 2025-03-26 15:36:06 -07:00
to avoid waking up clat daemon needlessly
(it just drops these anyway)
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8485f01635d5c6dd168d89279a3b390200f78c63
Maciej Żenczykowskicommited 2025-03-25 13:57:21 -07:00
This is a *critical* fix for http://go/aog/3514294
'Drop egress multicast on clat interface'
Bug: 404457155
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If14ef730f78c7e991842a678260dd20df607b1ec
Maciej Żenczykowskicommited 2025-03-21 12:55:32 -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
On at least some kernel versions sufficient memlock
is needed for some [types? larger? preallocated?]
bpf map creation requests to succeed.
(the kernel's bpf subsys ignores CAP_IPC_LOCK)
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia6975e854e6398ee9c56ce836b278b570e17a0f9
Maciej Żenczykowskicommited 2025-03-20 11:54:00 -07:00
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
Possible since inet_sock_release hook is now enabled on T+ 5.10+
and that will perform map cleanup for us without reliance on
netlink notifications (which aren't available for other types).
Test: atest netd_updatable_unit_test TagSocketTest, adbz_cookies
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I141b1f98ae8e4ce80813194a66a26755925b6683
Maciej Żenczykowskicommited 2025-03-05 14:19:48 -08:00
This reverts commit 0e9b0e05c6.
Reason for revert: needs a .31rc specific version instead.
Will merge the required changes into the followup commit.
Change-Id: I01e9dfee4aaabc3ddab39da7519b7d9963b84124
Maciej Żenczykowskicommited 2025-03-04 21:54:09 -08:00
By itself this change is a no-op, as we don't actually *yet* start mdnsd_netbpfload.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic7665b3dd5716bd3bbdc96450a42e9b0c26441c9
Maciej Żenczykowskicommited 2025-03-04 14:21:46 -08:00
This is a *partial* NOOP revert of:
'bpf: support BPF_F_NO_PREALLOC in bpf_map_def.h'
https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/3457780
The comment is simply wrong, the negativeness is hidden
by the map declaration macros and thus never makes it
into the max_entries field of bpf_map_def struct.
A negative value passed to the map creation macros will store
the absolute value in max_entries, and set the BPF_F_NO_PREALLOC
flag in map_flags.
A negative / excessively large max_entries field will (presumably)
fail during map creation due to lack of ram.
Bug: 399549732
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I86951605cb1397c512c484c84e9d67a85b992b07
Maciej Żenczykowskicommited 2025-02-27 14:26:52 -08:00
Multicast packets on the clat interface are not supported,
so drop them in both clatd and its associated bpf offload.
This is required because NsdManager will start sending mDNS
packets on the clat interface as the check for
IFF_POINTOPOINT was removed.
Ingress multicast packets are already dropped elsewhere.
Test: TH
Change-Id: Icd22ca7f263ea5ff5244c17276ebb1002f72e842
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
Available in Linux Kernel 4.14+
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I3e5a43ceece5826fc6019bd11df2bc5315fe405c
Maciej Żenczykowskicommited 2025-02-14 11:12:31 -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