Commit Graph

1238 Commits

Author SHA1 Message Date
Lorenzo Colitti
49e4a98f78 Add a dumpService variant that uses libbinder_ndk.
The one in this file requires libbinder and cannot be used when
libbinder is not present (e.g., when compiling against the NDK).
This allows users of this code not to link against libbinder, and
have the resulting binary not depend on it:

$ m CtsNativeNetPlatformTestCases netd_integration_test
$ objdump -p out/target/product/vsoc_x86_64/testcases/netd_integration_test/x86_64/netd_integration_test64 | grep NEEDED | grep libbinder
  NEEDED               libbinder.so
  NEEDED               libbinder_ndk.so
$ objdump -p out/target/product/vsoc_x86_64/testcases/CtsNativeNetPlatformTestCases/x86_64/CtsNativeNetPlatformTestCases64 | grep NEEDED | grep libbinder
  NEEDED               libbinder_ndk.so
$

Bug: 268440865
Test: see other CL in topic
Merged-In: Icf982675aad4777677a36e357035809fb251d6e9
Change-Id: Icf982675aad4777677a36e357035809fb251d6e9
2023-06-22 19:14:10 +09:00
Chalard Jean
9302d7d7c3 Add constants for clat and v6 fragmentation
Test: manual
Change-Id: Ic18186c1a09c2bb79e7727c70d2d46d511a23075
2023-06-22 17:39:08 +09:00
Xiao Ma
e5e306cd49 Merge "Parse rta_cacheinfo structure in RtNetlinkRouteMessage." 2023-06-22 05:40:53 +00:00
Xiao Ma
b2f61ab77c Merge "Add netlink rta_cacheinfo structure." 2023-06-22 05:39:30 +00:00
Xiao Ma
34ab408ade Parse rta_cacheinfo structure in RtNetlinkRouteMessage.
Bug: 183601771
Test: atest NetworkStaticLibTests
Change-Id: I9ea55ad297f5183853eeaa2e53f2406d79a90a20
2023-06-22 10:37:39 +09:00
Xiao Ma
4cb10fdc28 Add netlink rta_cacheinfo structure.
Bug: 183601771
Test: m
Change-Id: Iaa65425fa875a9dde4d4b7c1b110d9a2a406f444
2023-06-22 10:37:27 +09:00
Maciej Żenczykowski
f1416b5494 enforce bpf ring buffer size is a power of two
While at it enforce a min/max of 4 kiB and 256 MiB.

A bpf ringbuffer must be an integer multiple of page size
(which is at least 4kiB), so 4kB is forced.

256 MiB upper limit is probably higher than it should be,
but it's really only here to avoid the u32/s32 conversion
mess that happens for 2+ GiB.

Test: TreeHugger
Bug: 279819914
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2216d2273b0956a86c4222dd6ecf7293e0bafd41
2023-06-17 11:26:21 +00:00
Maciej Żenczykowski
1e1d7106bc Merge "add macro to disable BTF on user builds" 2023-06-16 02:37:14 +00:00
Maciej Żenczykowski
c6e4122db8 add createOuterMap()
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Icf49cc98daa339b0320b5c18cd055b8a53dcba6c
2023-06-14 09:14:19 +00:00
Maciej Żenczykowski
008f51e585 implement 'int bpfGetFdProgId(const BPF_FD_TYPE prog_fd)'
which fetches the internal kernel identifier of an ebpf program

side note: Linux in include/uapi/linux/bpf.h declares:
  4.14: struct bpf_map_info
  4.14: struct bpf_prog_info
  4.19: struct bpf_btf_info
  5.4: struct bpf_func_info
  5.4: struct bpf_line_info
  5.10: struct bpf_link_info
  5.10: struct bpf_pidns_info

Test: TreeHugger
Bug: 286369326
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8b2fe1a67bdefff521e41b3ff4ef37d29fc90fae
2023-06-14 09:13:09 +00:00
Maciej Żenczykowski
be02054c79 convert ptr_to_u64() macro to an inline function
This allows it to be used from outside this header file,
and provides slightly more type safety.

Test: TreeHugger
Bug: 286369326
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I98e5e37a002188813b602e51fd4fcbb9ca4466cc
2023-06-14 02:15:07 +00:00
Treehugger Robot
111f341596 Merge "Make IaPrefixOption constructor public." 2023-06-09 07:00:11 +00:00
Maciej Żenczykowski
8837bf21a5 add macro to disable BTF on user builds
Bug: 286369326
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6a705ae99a12fb8464730dab1119f4ce2ef3f974
2023-06-09 06:06:36 +00:00
Xiao Ma
789baf20d3 Make IaPrefixOption constructor public.
Then we can create an IaPrefixOption instance via constructor in the
NetworkStackIntegration test.

Bug: 260934173
Test: atest NetworkStackIntegrationTests
Change-Id: I05be1dde6ba5bda125631674c5c0f8634eb18924
2023-06-09 11:38:11 +09:00
Maciej Żenczykowski
5bec8b44a9 force map key/value sizes < 1024/65536 bytes to match BpfMap.java
Test: TreeHugger
Bug: 286154283
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I31fb48aa032e22a83e3e9f0ac8d7f2b3253e995e
2023-06-07 06:59:40 +00:00
Xiao Ma
267467ec93 Merge "Add NetworkStackModuleTest annotation." 2023-06-05 01:45:01 +00:00
Treehugger Robot
cae8499e3d Merge "Add a helper function to send RTM_NEWADDR netlink message to kernel." 2023-06-01 08:52:02 +00:00
Mike Yu
eb1fe093ad Merge "Change DnsPacket.DnsRecord.MAXNAMESIZE to public" 2023-06-01 05:45:39 +00:00
Junyu Lai
14a8c7d913 Merge "Fix crash when socket read is interrupted" 2023-06-01 05:39:33 +00:00
Xiao Ma
cff263aa10 Add NetworkStackModuleTest annotation.
This annotation can be used to exclude the testcases which requires the
latest NetworkStack module in the CTS/MTS suite.

Bug: 283200648
Test: atest CtsTetheringTestLatestSdk
Change-Id: Idaffed93af077c2998081142af7b3bfa311dcd90
2023-06-01 13:34:01 +09:00
Xiao Ma
a6fba08f82 Add a helper function to send RTM_NEWADDR netlink message to kernel.
Bug: 260934173
Test: TH
Change-Id: I6e9100e6f04a85550790c90fb0fde8d839e74578
2023-06-01 11:02:05 +09:00
Junyu Lai
ab3fee4246 Fix crash when socket read is interrupted
The exception is thrown in some normal cases e.g. interrupt()
called when Os.read is blocked and waiting for the input.
Ignore such events.

Test: 1. atest NetworkStackCoverageMtsConfigTests on S device
      2. atest com.android.cts.net.HostsideVpnTests
      3. atest NetworkStatsIntegrationTest
Bug: 259632210
Change-Id: Ibff41312d9c7431c2b19f780844ab3a81b48f9e8
2023-05-31 14:14:01 +08:00
Mike Yu
4734d678a5 Change DnsPacket.DnsRecord.MAXNAMESIZE to public
Change this constant to public so that the implementation of other
type of DNS record, such as SVCB record, can reuse this constant
instead of defining a duplicate one.

Bug: 240259333
Test: TreeHugger
Change-Id: Ic5c6ecfba4d16f19adb3794dd50c5fc876d9f82a
2023-05-31 05:27:26 +00:00
Maciej Żenczykowski
2129040ae4 KernelUtils.h - better static assert messages for impossible conditions
per Lorenzo's request during cherrypick to udc-dev on
https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/libs/net/+/23391171

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib19f5b3b63a6978ac5a72b2be08a2f0ba6cdd712
2023-05-25 12:30:52 +00:00
Hansen Kurli
8b39bca655 Merge "Use ThrowingSupplier for visibleOnHandlerThread." 2023-05-24 02:39:07 +00:00
Hansen Kurli
0cd46d480d Use ThrowingSupplier for visibleOnHandlerThread.
In order to return values from functions that are run on the handler
thread, use a ThrowingSupplier instead of a ThrowingRunnable.
Also maintain the case with ThrowingRunnable by overloading.

Test: NetworkStaticLibTests
Change-Id: Ic1b86f9f764997ce5d6848f04185194a961d1106
2023-05-23 06:17:52 +00:00
Motomu Utsumi
a0a78d3ca5 Merge "Add logs for target uids and duration to destroyLiveTcpSockets" 2023-05-23 02:19:24 +00:00
Motomu Utsumi
78cc19e25a Add logs for target uids and duration to destroyLiveTcpSockets
destroyLiveTcpSockets APIs are replacement of socketDestroy in
NetdNativeService which has logging for target uids and duration.
Logging them would be useful in debug.
So adding equivalent logging to destroyLiveTcpSockets APIs.

Test: atest com.android.cts.net.HostsideVpnTests#testSocketClosed
Test: atest ConnectivityManagerTest#testFirewallCloseSocketDenylistChainDeny
Bug: 270298713
Change-Id: I347d010541656c92a64029b1474fae601d6e5659
2023-05-23 02:19:11 +00:00
Motomu Utsumi
4b5cf8ec4a Merge "Add message length check in parseNetlinkErrorMessage" 2023-05-23 02:03:46 +00:00
Maciej Żenczykowski
c8d1e96a34 Merge "KernelUtils.h: explicitly do not support x32" 2023-05-22 19:35:54 +00:00
Treehugger Robot
cc4ccc466c Merge "Correctly test for an object being of the correct type" 2023-05-22 10:41:03 +00:00
Chalard Jean
677b663aaf Correctly test for an object being of the correct type
This `as? T` instruction warns that this is an unchecked cast.
It's unchecked in the literal sense : the compiler actually
doesn't check that the var is of that type. Accordingly, this
will only fail if `it` is null, which never happens.

Concretely what that means is that Java code calling this
method like

  expect(AVAILABLE, network)

...will actually pass for *any* callback matching the network,
because the class is not checked.

Thankfully this code is recent and there doesn't seem to be a
lot of tests that got accepted by this bug when they should
have been rejected.

Test: ConnectivityServiceTest, TH
      new test in this patch that fails before but succeeds after
Change-Id: I2e48dae28ff92045f002cfb2798d383c9c19d5ed
2023-05-22 17:55:11 +09:00
Maciej Żenczykowski
4782ab1b9e KernelUtils.h: explicitly do not support x32
x86 has 2 obvious ABIs:
32-bit registers/pointers/system calls (i386/i486/i586/i686)
64-bit registers/pointers/system calls (amd64 / x86_64)

but there also exists a third:
the memory optimizing hybrid 'x32' which uses 64-bit registers,
with 32-bit pointers, and 64-bit system calls (with minor tweaks).

(there is also technically an aarch64/arm64-ilp32 ABI mirroring x32)

Note: It would probably be trivial to add support if we wanted to.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I82138c5bafbc3bd37cad98eeb79441701d94c386
2023-05-21 02:33:55 +00:00
Maciej Żenczykowski
1c4ba307f4 Merge "bpfloader: ignore_on_(arch) support" 2023-05-20 01:04:21 +00:00
Maciej Żenczykowski
2998627ddd KernelUtils.h - add describeArch()
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0ae4b5fd8cf9baf04b738743d9e52f94a35aaf21
2023-05-20 00:45:27 +00:00
Maciej Żenczykowski
6d3224e286 bpfloader: ignore_on_(arch) support
Test: TreeHugger
Bug: 283523051
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I73768a67b50bb82ebb13e20c6ba6425e1e4236c7
2023-05-19 20:59:40 +00:00
Treehugger Robot
8273756bcc Merge "KernelUtils.h - add arch query helpers" 2023-05-19 07:32:57 +00:00
Patrick Rohr
93312c998e bpf_headers: Make bpf_headers available to libsysutils
So KernelUtils.h can be used in NetlinkEvent.cpp.

Test: builds
Change-Id: If7a6a28e735ee19dc6b7a72330a97a8a01bcecd5
2023-05-18 14:39:14 -07:00
Patrick Rohr
85a86cb908 BpfRingbuf: Clean up memory access
Consumer pos is only written to by userspace (except for
initialization), so reading from it does not require a memory barrier.

This change also moves producer pos to be acquired before anything else
and marks start_ptr as volatile, so it is only read once.

Test: atest BpfRingbufTest
Change-Id: I228578ef4b42c1732646f0ae928b9a0aa2445304
2023-05-18 14:08:37 -07:00
Patrick Rohr
52954ff505 BpfRingbuf: Add support for 32 bit kernels
This change adds support for 32 bit kernels by capping mProducerPos to
4 bytes. mConsumerPos (which is written to by userspace) continues to
use 8 bytes. (This can be done because an entire page is allocated for
mConsumerPos to control access permissions). In a 32 bit kernel, that
means that the top order bits are just ignored. In addition, comparisons
in userspace only use the bottom 4 bytes to be bitness agnostic.

Test: atest BpfRingbufTest
Change-Id: I7fe6d9000a151512785f1aa2a53fa97d31967d19
2023-05-18 14:08:37 -07:00
Maciej Żenczykowski
5b2bcc508a KernelUtils.h - add arch query helpers
see bionic/docs/defines.md:
http://cs/h/android/platform/superproject/+/master:bionic/docs/defines.md?l=57

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I818da16ad4dd1837ef3cdcc552557119eafaf6af
2023-05-18 17:17:29 +00:00
Maciej Żenczykowski
0d6edeef83 Merge "BpfRingbuf: support 32 bit userspace" 2023-05-18 17:08:15 +00:00
Treehugger Robot
2cef16a4de Merge "Disable Play auto-update during tests" 2023-05-18 06:57:29 +00:00
Treehugger Robot
cee4bd691e Merge "bpf_headers: add kernel bitness utility functions to KernelUtils" 2023-05-18 00:28:51 +00:00
Maciej Żenczykowski
7d2b91e7a3 Merge "bpf: Copy comment about bpffs labelling into bpf_helpers.h" 2023-05-17 22:40:57 +00:00
Patrick Rohr
311f8b325e BpfRingbuf: support 32 bit userspace
Both consumer and producer position are wrapped in an std::atomic and
extended to uint64_t to enforce atomic access.

See resulting assembly instructions for aosp_cf_x86_phone-userdebug:

frameworks/libs/net/common/native/bpf_headers/include/bpf/BpfRingbuf.h:212
  2d:   8b 41 18                mov    0x18(%ecx),%eax
external/libcxx/include/atomic:926 (discriminator 4)
  30:   f3 0f 7e 00             movq   (%eax),%xmm0

This will not work on a 32 bit kernel (so we might want to explicitly
check for that in the test).

Test: atest BpfRingbufTest
Change-Id: I7fec435cbe49d392363d05f7e702d82ecacb9e91
2023-05-17 15:39:38 -07:00
Patrick Rohr
2f5c1159cc bpf: Copy comment about bpffs labelling into bpf_helpers.h
I found this comment in aosp/2103424 helpful in figuring out the correct
selinux domain for a newly added map.

Test: documentation only change
Change-Id: I96c06ff33605c8ed3f2ae6e8810bbcdc8e66b51b
2023-05-17 22:38:22 +00:00
Treehugger Robot
677119874e Merge "bpf_headers: rename KernelVersion.h to KernelUtils.h" 2023-05-17 20:41:50 +00:00
Patrick Rohr
432291a334 bpf_headers: add kernel bitness utility functions to KernelUtils
These were copied from
system/core/libsysutils/src/NetlinkEvent.cpp and the following changes
were applied:
- Mark isUserspace64bit as constexpr.
- Added __unused annotations
- Fixed a typo (s/meaningul/meaningful)

Test: TH
Change-Id: Ia0b8e6e02daca7e9b69f337a494d88eb1beffc22
2023-05-17 12:52:56 -07:00
Patrick Rohr
66452f566b bpf_headers: rename KernelVersion.h to KernelUtils.h
Test: TH
Change-Id: Ifacc159c19a8fcb64b571295b945fb9fca82496a
2023-05-17 11:43:02 -07:00