Commit graph

108,891 commits

Message SHA1
Replace .toList() with .collect()
.toList() was only introduced to android in api level 34, which is newer than
this module's min_sdk_version. Replace it with .collect().

This was found while updating android lint.

Flag: EXEMPT refactor
Bug: 394096385
Test: Presubmits
Change-Id: I472bff7749aebb21bd8681ecf4235ce7a6cfc7de

Cole Faust   commited 2025-02-03 14:18:40 -08:00
725078a6bd
BpfHandler: reduce logging verbosity
most of these are spammy and/or not useful.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iab101ce7de076ef025a046d5e3e9007e091b271f

Maciej Żenczykowski   commited 2025-01-31 12:53:11 -08:00
0bcb13f41c
Merge "Prepare CtsTetheringTestLatestSdk for presubmit by adding it to postsubmit" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-31 02:05:17 -08:00
37bf450778
Merge "Fix some comments around stopTetheringRequest" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-31 01:59:17 -08:00
f09acc7281
Merge "Add basic implementation of stopTetheringRequest" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-31 00:59:58 -08:00
6f57c93e30
Prepare CtsTetheringTestLatestSdk for presubmit by adding it to postsubmit
This commit adds CtsTetheringTestLatestSdk to the postsubmit
configuration. This is a preparatory step towards moving the test to
presubmit, ensuring it runs regularly and catches issues earlier in the
development cycle.

Test: TH
Change-Id: I6932b0b660a675a20102d2683119f689557d8590

Yuyang Huang   commited 2025-01-31 17:51:21 +09:00
1325a02e96
Fix some comments around stopTetheringRequest
Bug: 216524590
Test: atest TetheringManagerTest
Change-Id: Iae0baa8ad7c199770666e2f78813cf0224ea1a9b

Quang Anh Luong   commited 2025-01-31 17:42:39 +09:00
75ac79db56
Add basic implementation of stopTetheringRequest
Add a basic implementation of stopTetheringRequest that simply stops
tethering for that specific type if it is active, or fail with
TETHER_ERROR_UNKNOWN_REQUEST if not. In the future, we will do fuzzy
matching to ensure the correct request is removed.

Bug: 216524590
Test: atest TetheringManagerTest#testStopTetheringRequest
Change-Id: Ib4a660aacdb83e645e39ceb61b7cda45bb24d89d

Quang Anh Luong   commited 2025-01-31 16:23:04 +09:00
696c164c2d
Merge "add kernel version comment for R/S pre-bpf" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2025-01-30 19:14:23 -08:00
cb2125e666
bpf_net_helpers: introduce bpf_get_netns_cookie() helper
Linux Kernel documentation states:

* u64 bpf_get_netns_cookie(void *ctx)
Description
  Retrieve the cookie (generated by the kernel) of the network
  namespace the input *ctx* is associated with. The network
  namespace cookie remains stable for its lifetime and provides
  a global identifier that can be assumed unique. If *ctx* is
  NULL, then the helper returns the cookie for the initial
  network namespace. The cookie itself is very similar to that
  of **bpf_get_socket_cookie**\ () helper, but for network
  namespaces instead of sockets.
Return
  A 8-byte long opaque number.

This was introduced in Linux 5.7, see get_netns_cookie in
  https://elixir.bootlin.com/linux/v5.7/source/net/core/filter.c
vs
  https://elixir.bootlin.com/linux/v5.6/source/net/core/filter.c

But only for sock & sock_addr, while sock_ops & sk_msg were
added later (present in 6.12)

Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Idccb7191552be8048a02fff2358e7d7898123dd9

Maciej Żenczykowski   authored and   Patrick Rohr   commited 2025-01-30 18:48:51 -08:00
259fe7e843
Merge "BpfHandler: add 25Q2+ netd map create and write test" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-30 16:11:15 -08:00
6825d9fa3e
BpfHandler: add 25Q2+ netd map create and write test
Adding this to make sure we have 'unprivileged_bpf_disabled = 0'
This is currently set by NetBpfLoad, but if we remove that things currently work.

However with this change the device then fails to boot:
  $ adbz logcat -s -d *:* | egrep -i -C10 bpf
  I NetdUpdatable: libnetd_updatable_init: Initializing
  I NetdUpdatable: BPF programs are loaded
  I NetdUpdatable: initMaps successfully
  E NetdUpdatable: libnetd_updatable_init: Failed: (1) [Operation not permitted] : map create failed

This is because even though system/netd/server/netd.rc has:
  service netd /system/bin/netd
    class main
    capabilities CHOWN DAC_OVERRIDE DAC_READ_SEARCH FOWNER IPC_LOCK KILL NET_ADMIN NET_BIND_SERVICE NET_RAW SETUID SETGID
    user root
    group root net_admin

and we thus run as root/root with CAP_NET_ADMIN, but we do *NOT* have CAP_BPF nor CAP_SYS_ADMIN.
This means netd is considered 'unprivileged' from the point of view of that sysctl.

Creating maps from outside the bpfloader (ie. netd/system server/network stack)
is required for map-in-map.

While the sepolicy for netd.te map_create is in V, there is no real
need for this test on V atm, doing this to prevent *future* regressions.
A rollout purely to the not yet existing 25Q2+ is safer.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia39c74cfb1707e88b0aa534ddf42139b1698d5d6

Maciej Żenczykowski   commited 2025-01-30 14:58:07 -08:00
48f244ece4
bpf: define READ_ONCE and WRITE_ONCE
These are convenience macros which do
(const|volatile) cast for atomic operations.

I've run into a case where two 32-bit writes get optimized
by the compiler into a single 64-bit write, which then fails
verification.  WRITE_ONCE() avoids that by virtue of the volatile annotation.

Technically I think the same thing could happen on read,
so add READ_ONCE too.

Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iade089aab3522916bd7b431d4064f89a21bc78b0

Maciej Żenczykowski   commited 2025-01-30 14:43:45 -08:00
645b2d9755
add kernel version comment for R/S pre-bpf
Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ifad1bb0928ad71be6ddacbe62cff4573323db521

Maciej Żenczykowski   commited 2025-01-30 12:36:13 -08:00
0a2340396f
Merge "Skip WiFi test in CtsWifiTestCases and CtsNetTestCases modules if feature not supported" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-30 05:56:27 -08:00
56d6ad9764
Merge changes from topic "log-placeholder-tethering-request" into main
* changes:
  Remove redundant requestedState from IpServer#enable
  Log tethering started with placeholder request
  no-op: Make TetheringRequest @NonNull in enableIpServing

Quang Luong   authored and   Gerrit Code Review   commited 2025-01-30 00:44:35 -08:00
3e0f6b37a2
Remove redundant requestedState from IpServer#enable
IpServer#enable is called with both a non-null TetheringRequest and the
requestedState, but the requestedState is derived from the
TetheringRequest's connectivity scope. Remove this requestedState arg
and simply have IpServer read the connectivity scope itself.

Bug: 216524590
Test: covered by existing tests
Change-Id: I73227f5053da3a2ab35563268fc416b6dd9b1801

Quang Anh Luong   commited 2025-01-30 14:30:51 +09:00
ffb503e86e
Log tethering started with placeholder request
Bug: 216524590
Test: build
Change-Id: I152505f83745f4d1f8148c72f15dcde990b8d7b9

Quang Anh Luong   commited 2025-01-30 14:30:51 +09:00
e1fd3c2daa
no-op: Make TetheringRequest @NonNull in enableIpServing
Currently the enableIpServing->tetherInternal call stack may have a
tethering request alongside a redundant tethering type and requested
state. The redundant arguments were necessary since there may be cases
where the active request is null (e.g. back-to-back start/stop, which
removes the active request before the link layer event enables ip
serving).

This change gets rid of the redundant arguments and makes the call stack
take a non-null TetheringRequest. In case the active request is not
found, we will create a placeholder request with just the type and
connectivity scope (i.e. requested state). This should be equivalent to
the old code of sending a null request (since none of the other fields
in TetheringRequest are used), making this a no-op change.

Bug: 216524590
Test: covered by existing tests
Change-Id: I5ac83c74f5bc4aec2fe85daa9477740749d95c63

Quang Anh Luong   commited 2025-01-30 14:30:49 +09:00
2b8a42d666
Merge "ConnectivityManagerTest#testOpenConnection: skip Cuttlefish" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-29 21:10:13 -08:00
5f18c68810
Skip tests which need an IPv6 address on Cuttlefish.
Avoids:

android.net.cts.DnsTest#testDnsWorks: FAILED (4.993s)

STACKTRACE:
java.lang.AssertionError: Default network did not provide IPv6 connectivity after 5000ms. Please connect to an IPv6-capable network.
lp={InterfaceName: wlan0 LinkAddresses: [ fe80::6c1f:76ff:fe50:2c84/64,192.168.99.115/25 ] DnsAddresses: [ /192.168.99.1 ] Domains: l
an MTU: 0 ServerAddress: /192.168.99.1 TcpBufferSizes: 524288,1048576,2097152,262144,524288,1048576 Routes: [ fe80::/64 -> :: wlan0 m
tu 0,192.168.99.0/25 -> 0.0.0.0 wlan0 mtu 0,0.0.0.0/0 -> 192.168.99.1 wlan0 mtu 0 ]}
  at org.junit.Assert.fail(Assert.java:89)
  at org.junit.Assert.assertTrue(Assert.java:42)
  at android.net.cts.DnsTest.ensureIpv6Connectivity(DnsTest.java:319)
  at android.net.cts.DnsTest.testDnsWorks(DnsTest.java:90)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4b94edae6d196ca02858702dec40ee2bad1db494

Maciej Żenczykowski   commited 2025-01-29 19:56:31 -08:00
7355ca14e5
ConnectivityManagerTest#testOpenConnection: skip Cuttlefish
due to:

android.net.cts.ConnectivityManagerTest#testOpenConnection: FAILED (277ms)

STACKTRACE:
java.lang.AssertionError: Same address '104.135.180.196' on two different networks (153, 143)
  at org.junit.Assert.fail(Assert.java:89)
  at org.junit.Assert.assertTrue(Assert.java:42)
  at org.junit.Assert.assertFalse(Assert.java:65)
  at android.net.cts.ConnectivityManagerTest.testOpenConnection(ConnectivityManagerTest.java:934)

This would possibly be fixed by cuttlefish having IPv6 connectivity, but it doesn't atm.

@RequiresDevice doesn't work right with atest.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5bd4189ed6297a2491dc0ab7b251ffd19d1ecb5d

Maciej Żenczykowski   commited 2025-01-29 19:54:48 -08:00
5d9885da86
Merge "Make it clear that legacyTether always uses IpServer.STATE_TETHERED." into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-29 17:30:57 -08:00
36e7969920
Merge "Add coverage for StopTetheringCallback methods" into main
Quang Luong   authored and   Gerrit Code Review   commited 2025-01-29 15:24:53 -08:00
6bbe256bb7
Merge changes Ib0c4a52e,Iff7d2981,Ie8af8b71,I7884faf8 into main
* changes:
  Rename mActiveTetheringRequests to mPendingTetheringRequests
  Give the two variants of ensureIpServerStarted different names.
  Move the TetheringRequest further up the stack.
  Un-nest legacyTether by moving lambda contents to new method.

Quang Luong   authored and   Gerrit Code Review   commited 2025-01-29 13:48:17 -08:00
343429d013
Stop tracking left-over test interfaces
When setIncludeTestInterfaces(false) is called, any RTM_DELLINK
callback for a testtap interface is ignored, since the interface is no
longer considered to be a valid ethernet interface.

Change setIncludeTestInterfaces to go through all interfaces, and stop
tracking the ones which are no longer valid. Otherwise, they will
stick around forever (and break subsequent tests).

Bug: 390722214
Test: TH
Change-Id: Ied73e86c0452831f4d6b00f67908c51201af8bbd

Patrick Rohr   commited 2025-01-29 07:34:27 -08:00
d16138eeea
Add coverage for StopTetheringCallback methods
Bug: 385014495
Bug: 385278741
Test: atest TetheringManagerTest
Change-Id: I176e3339a80a1efe5410092589f459fd7e94728a

Quang Anh Luong   commited 2025-01-29 17:42:00 +09:00
b16b6e6d2c
Make it clear that legacyTether always uses IpServer.STATE_TETHERED.
This is a no-op refactor

Bug: 216524590
Test: covered by existing tests
Change-Id: I2a3eb4a64cc9527793136b7ae6fb83d32923debd

Lorenzo Colitti   commited 2025-01-29 17:38:18 +09:00
dca881697c
Rename mActiveTetheringRequests to mPendingTetheringRequests
mActiveTetheringRequests is a misnomer because the requests aren't
actually active yet. Rename this to mPendingTetheringRequests since
they're pending a link layer event that the iface is ready to start IP
serving.

Bug: 216524590
Test: covered by existing tests
Change-Id: Ib0c4a52e0aa72fc27b67bce25187124b20082c05

Quang Anh Luong   authored and   Lorenzo Colitti   commited 2025-01-29 17:15:53 +09:00
caae4e7916
Give the two variants of ensureIpServerStarted different names.
The fact that the two overloads have the same name is confusing
because one of them fetches the type and one of them has it
passed in. This means it's not obvious whether they behave
identically or not.

This is a no-op refactor.

Bug: 216524590
Test: covered by existing tests
Change-Id: Iff7d2981cb5835831f00117166035d48b44a61a4

Lorenzo Colitti   commited 2025-01-29 17:11:37 +09:00
ac046ba684
Move the TetheringRequest further up the stack.
Currently, the active TetheringRequest (if any) is fetched at the
very bottom of the stack, just before enabling the IpServer.
Have the callers pass it in instead.

This CL is a no-op refactor. In particular, it ignores the fact
that the TetheringRequest can be null, and that the connectivity
scope in the request might not match the requested state, etc. -
it just documents the current behaviour (bugs included) and
leaves it unchanged. It exists only to make future changes
easier.

Bug: 216524590
Test: covered by existing tests
Change-Id: Ie8af8b718a9de1f1d5adde0ac589060dce112a27

Lorenzo Colitti   commited 2025-01-29 17:11:37 +09:00
7e43a1adfa
Un-nest legacyTether by moving lambda contents to new method.
This is a no-op refactor.

Bug: 216524590
Test: covered by existing tests
Change-Id: I7884faf8e0f187bb840ec80b8d6d86e3e4323553

Lorenzo Colitti   commited 2025-01-29 17:11:32 +09:00
6887c8d925
Merge changes from topic "serializablelambda" into main
* changes:
  Revert "Force CtsNetTestCases to compile with Kotlin 1.9"
  Annotate lambdas capturing newer-framework classes

Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2025-01-28 12:42:43 -08:00
544df81acf
Add missing null check to prevent system server crash
This bug was introduced in aosp/3342195 and can occur when calling
setEthernetEnabled() while ethernet tethering is enabled and the
tethering interface has disappeared.

Bug: 392912047
Test: TH
Change-Id: I4c4c2144558ad9057195ddcf30c055227f3fc62a

Patrick Rohr   commited 2025-01-28 11:06:41 -08:00
ec2cd8f872
Revert "Force CtsNetTestCases to compile with Kotlin 1.9"
With b/391766151 fixed by the previous patch, this can now
be reverted.

This reverts commit 4f59de2f85.

Test: atest NetworkAgentTest on an S device
Change-Id: Ie2cb2ca5653a134c0eaa1cac5b0c4b4221f1c0ac

Chalard Jean   commited 2025-01-28 13:24:12 +09:00
cd36064ad4
Annotate lambdas capturing newer-framework classes
b/391766151 is caused by the combination of three things :
• Newer compilers, such as the Kotlin K2 compiler, will use the
  `invokedynamic` instruction introduced in Java 7.
  → Before then, lambdas had to be wrapped in synthetic classes,
    which would be generated by the compiler. The compiler would
    then generate code that instantiates the synthetic class and
    pass it to the callee as the lambda.
  → After then, there is no need for synthetic classes. Instead, the
    compiler synthesizes a static method that corresponds to the
    lambda and emits an invokedynamic opcode at that call site.
    The JVM will then lookup the class dynamically and create a
    MethodHandle object from which it can substitute an immediate
    method call at runtime.
  → The new way means a much smaller footprint (because
    there are less classes in bytecode) and typically much better
    call performance after the initial resolution, at the cost of linking
    the method at the first execution of the lambda. For most
    modern apps, the trade-off is very advantageous.
  → In this case, the methods that accept the lambda are of the
    `runAsShell` family.
  → Because there are captured local variables of the *WaiterCallback
    types, the generated static methods take instances of these types.
• JUnit uses reflection to enumerate the methods of test classes.
  It does not take care to only enumerate public methods, and as
  such will try to resolve all private methods including the types of
  their arguments.
  → Note that the `Class` class has a way to retrieve all methods
    of public visibility including inherited methods, a way to
    retrieve all non-inherited methods including all visibilities, but
    not a way to retrieve only public locally-declared methods, so
    JUnit's implementation is understandable.
  → In this case, this means JUnit has code that will try to resolve
    the *WaiterCallback classes.
• The test code is compiled against newer SDKs but run with the
  JUnit test harness on older SDKs which don't have the base classes
  for the *WaiterCallback classes.

The net result is that as JUnit enumerates methods, it finds the
private synthetic methods emitted by the newer compilers, which
causes the JVM to try and resolve the type of the arguments, which
in turn is not possible on older frameworks. The test run promptly
crashes with ClassNotFoundException before it can run any test
method.

Note that this would also happen with newer Java compilers.

This patch solves this method by annotating the relevant
lambdas with @JvmSerializableLambda, which causes the
Kotlin compiler to use the old behavior on just those lambdas.

The drawback of this patch is that the @JvmSerializableLambda
feature is pretty obscure and it needs to be managed per-lambda.

Bug: 391766151
Test: revert aosp/3464183 on top of this, then atest NetworkAgentTest
      on an S device, then atest CtsNetTestCases to test whether there
      are other instances of this issue
Change-Id: Iacaadddb597c4a5dfdd8c497e6ebc1243ae1e923

Chalard Jean   commited 2025-01-28 12:00:11 +09:00
6b7e0b3078
Use NLM_F_REQUEST_ACK in createSetFlagsMessage()
This rtnl message is used with sendOneShotKernelMessage() which expects
that kernel returns an ACK. We need to set NLM_F_ACK explicitly for
that.

Bug: 390722214
Bug: 392491075
Test: Manually run the affected test, no more exception with EAGAIN.
Change-Id: I7ef9497461a8e89e9f7f7fe399562b2d8ede14a9

Jie Jiang   commited 2025-01-27 22:10:31 +09:00
b61913bbb6
Merge changes Ide254542,Id3ad2c75 into main
* changes:
  Rename the CTLogger APIs to reflect the atom name change
  Remove the threshold logic for logging log list update failures

Bessie Jiang   authored and   Gerrit Code Review   commited 2025-01-24 09:42:09 -08:00
66b2627d1e
Rename the CTLogger APIs to reflect the atom name change
The atom no longer just represents log list update failures, and will
instead be representing the entire log list update result regardless of
success or failure.

Flag: com.android.net.ct.flags.certificate_transparency_service
Bug: 378626065
Test: atest NetworkSecurityUnitTests
Change-Id: Ide254542aeb9c9657e79a154e53f651478bb1a54

Bessie Jiang   commited 2025-01-24 15:40:51 +00:00
c9cefdbe1c
Remove the threshold logic for logging log list update failures
Previously, we would only log to statsd if a default threshold of 10 had
been met to avoid noise in the logs. Because we will instead be logging
every time a log list update happens (success or failure), we are
removing this threshold logic.

Flag: com.android.net.ct.flags.certificate_transparency_service
Bug: 378626065
Test: atest NetworkSecurityUnitTests
Change-Id: Id3ad2c75fcceb3c15add70d4263f6c443f145348

Bessie Jiang   commited 2025-01-24 12:18:48 +00:00
e48e790e32
Merge "Revert^2 "Fix flakes due to tests resetting CarrierConfig"" into main
Yuyang Huang   authored and   Gerrit Code Review   commited 2025-01-24 03:29:10 -08:00
0e2102069e
Merge "Add jimictw@ to core networking OWNERS." into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-24 01:57:02 -08:00
cf70026227
Add jimictw@ to core networking OWNERS.
Change-Id: I8c3b23ab091f843c07f3709a971866033ef912e0

Lorenzo Colitti   commited 2025-01-24 01:06:33 -08:00
912516c2ca
Force CtsNetTestCases to compile with Kotlin 1.9
The change to use Kotlin 2 by default causes NetworkAgentTest to
crash on S, possibly due to the compiler emitting synthetic methods that access API classes that don't exist on S. Force it to compile with Kotlin 1.9 until we can fix it.

Change-Id: Ief9b34c8d1eb1469ea33408736d9ca250019dbe9
Fix: 391766151
Test: Test-only change

Lorenzo Colitti   commited 2025-01-24 00:38:41 -08:00
4f59de2f85
Revert^2 "Fix flakes due to tests resetting CarrierConfig"
This reverts commit 19a936d3ab.

Reason for revert: revert^2 to verify if this CL really break TH.

Change-Id: I8600883785881d857b7e79cf16459e33080fa82b

Yuyang Huang   authored and   Gerrit Code Review   commited 2025-01-23 18:56:11 -08:00
6f99275476
Merge "Revert "Fix flakes due to tests resetting CarrierConfig"" into main
Yuyang Huang   authored and   Gerrit Code Review   commited 2025-01-23 18:55:18 -08:00
55105df5ee
Revert "Fix flakes due to tests resetting CarrierConfig"
This reverts commit c7ed1a195a.

Reason for revert: possibly fails on S

Bug: 391766151
Change-Id: I24c72b48e037c2e2b7852bcc8300de777a391557

Maciej Żenczykowski   commited 2025-01-23 15:38:01 -08:00
19a936d3ab
Merge "Update CT log list update logging to reflect atom changes" into main
Bessie Jiang   authored and   Gerrit Code Review   commited 2025-01-23 09:37:57 -08:00
46ac499e60
Merge "Add NetSecConfigCertificateTransparencySctNoLogListTestCases to networksecurity TEST_MAPPING" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-23 02:41:15 -08:00
c9a4bf16f3
Merge "Remove unused libprocessgroup dependency" into main
Treehugger Robot   authored and   Gerrit Code Review   commited 2025-01-23 01:42:31 -08:00
5edc8a815d