Commit Graph

516 Commits

Author SHA1 Message Date
Patrick Rohr
6b5b7b40d8 Merge changes from topic "bandwidth-limiting"
* changes:
  Add bandwidth limiting to CS
  Add setting that controls network rate limit
2022-02-09 18:00:04 +00:00
Patrick Rohr
2857ac4dd0 Add bandwidth limiting to CS
Adds ingress rate limiting functionality to ConnectivityService. The tc
rate limit is installed before we tell netd about the interface, and
removed after the network is removed from netd. When the setting
changes, the old rate limit needs to be removed before a new one can be
added (unfortunately, we cannot use NLM_F_REPLACE when configuring the
tc-police filter).

Currently, this functionality is always enabled, but may or may not work
based on kernel support.

Bug: 157552970
Test: atest FrameworksNetTests:ConnectivityServiceTest
Change-Id: I4e64b2c40490f061e42b40a1b1b3a6618c3d1a87
2022-02-09 14:46:26 +01:00
Chalard Jean
d490072cd6 Pass the NetworkAgentConfig to NetworkMonitor.
When the network is a VPN, NetworkMonitor needs to know whether
the VPN requests validation, and that information is stored in
NetworkAgentConfig. Pass it.

Test: FrameworksNetTests
Change-Id: I3616f0796b69ce054d92213aafdef43ba7041596
2022-02-09 15:19:38 +09:00
Lorenzo Colitti
96a3f144a7 Revert "Revert "Update the UIDs only after the native network is created""
This reverts commit 13b96bc651.

Reason for revert:
- The reverted CL fixes a bootloop on Fi devices and must be submitted again for droidfood stability purposes.
- It's not clear whether the revert actually fixes the test that prompted it.

Change-Id: I68200501d1c587d1c6b3ad81053175c74961a440
2022-02-08 16:21:01 +00:00
Jordan Demeulenaere
13b96bc651 Revert "Update the UIDs only after the native network is created"
This reverts commit a7d4766d0d.

Reason for revert: DroidMonitor: Potential culprit for Bug 218308105 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.

Change-Id: Ia9953d023c1eb84846834f92d4f38a72fa14bd30
2022-02-08 10:42:11 +00:00
Chalard Jean
a7d4766d0d Update the UIDs only after the native network is created
UIDs can't be sent to netd until the native network is created.
Also, it's possible that the interface disappears at any moment,
so in that case catch the ServiceSpecificException.

Test: FrameworksNetTests
Bug: 218100554
Change-Id: I79285166acf5d89aa34107e00dfff963ccc22d52
2022-02-06 20:06:18 +09:00
Jean Chalard
d262e71965 Merge "Use RECEIVER_NOT_EXPORTED in CarrierPrivilegeAuthenticator." 2022-02-04 16:40:30 +00:00
Patrick Rohr
a46e4b52c3 Remove libbase_headers from libservice-connectivity
libservice-connectivity already links against libbase dynamically.

Test: m
Change-Id: I66da65d6f618799ded21a3f6cdc71f444acd72fd
2022-02-04 08:56:08 +00:00
Lorenzo Colitti
7569d51446 Use RECEIVER_NOT_EXPORTED in CarrierPrivilegeAuthenticator.
Passing one of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED is
required for all code targeting T or above. The correct value
here is RECEIVER_NOT_EXPORTED because the receiver is being
registered in the system server and the broadcast comes from
the system server itself (same UID).

This does not need to be guarded by OS version because
CarrierPrivilegeAuthenticator is only used on T+.

Test: m
Fix: 217642082
Change-Id: I09840b17bd54352896607737b56c6a692ffbd2c2
2022-02-04 15:31:06 +09:00
Patrick Rohr
445dede4eb Merge changes I50417e69,I6892d81c,Id8846844,Ib22da8d4,Iad66f0d4
* changes:
  jni - dynamically link C++ - saves 43 kB
  libservice-connectivity - dynamically link c++ - saves 600 kB
  link libbase & libnetdutils dynamically - save ~17.5 kiB
  remove spurious headers
  libclat only depends on libbase_headers not libbase itself
2022-02-03 19:19:11 +00:00
Robert Horvath
3b20dfbcb7 Merge changes from topic "low-power-standby-impl"
* changes:
  Add Low Power Standby support to TrafficController
  Handle Low Power Standby chain in ConnectivityService
  Implement Low Power Standby packet filtering in BPF program
2022-02-03 16:07:39 +00:00
Maciej Żenczykowski
6a6b071dec jni - dynamically link C++ - saves 43 kB
Since we already ship libc++ in the apex anyway...

Before in /apex/com.android.tethering/lib:
  -rw-r--r-- 1 system system  64560 1969-12-31 16:00 libandroid_net_connectivity_com_android_net_module_util_jni.so
After:
  -rw-r--r-- 1 system system  21460 1969-12-31 16:00 libandroid_net_connectivity_com_android_net_module_util_jni.so

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I50417e69a9a0b03d24212aa3f875bf241e0b0527
2022-02-03 03:51:40 +00:00
Maciej Żenczykowski
167c8607e6 libservice-connectivity - dynamically link c++ - saves 600 kB
Before in /apex/com.android.tethering/lib:
  -rw-r--r-- 1 system system 749980 1969-12-31 16:00 libservice-connectivity.so
After:
  -rw-r--r-- 1 system system 150748 1969-12-31 16:00 libservice-connectivity.so

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6892d81ca597d27cc1a85180f7ffa39f2b3de1be
2022-02-03 03:51:20 +00:00
Maciej Żenczykowski
dcae351663 link libbase & libnetdutils dynamically - save ~17.5 kiB
Before:
  $ adbz root && adbz wait-for-device && adbz shell ls -l /apex/com.android.tethering/{bin/for-system,lib,liv64}
  /apex/com.android.tethering/bin/for-system:
= -rwsr-sr-x 1 clat clat 18412 1969-12-31 16:00 clatd

  /apex/com.android.tethering/lib:
= -rw-r--r-- 1 system system  64560 1969-12-31 16:00 libandroid_net_connectivity_com_android_net_module_util_jni.so
= -rw-r--r-- 1 system system 713636 1969-12-31 16:00 libc++.so
= -rw-r--r-- 1 system system  13596 1969-12-31 16:00 libframework-connectivity-jni.so
d -rw-r--r-- 1 system system 212624 1969-12-31 16:00 libnetd_updatable.so
d -rw-r--r-- 1 system system 948044 1969-12-31 16:00 libservice-connectivity.so

After:
  $ adbz root && adbz wait-for-device && adbz shell ls -l /apex/com.android.
  /apex/com.android.tethering/bin/for-system:
= -rwsr-sr-x 1 clat clat 18412 1969-12-31 16:00 clatd

  /apex/com.android.tethering/lib:
= -rw-r--r-- 1 system system  64560 1969-12-31 16:00 libandroid_net_connectivity_com_android_net_module_util_jni.so
+ -rw-r--r-- 1 system system 251404 1969-12-31 16:00 libbase.so
= -rw-r--r-- 1 system system 713636 1969-12-31 16:00 libc++.so
= -rw-r--r-- 1 system system  13596 1969-12-31 16:00 libframework-connectivity-jni.so
d -rw-r--r-- 1 system system  45584 1969-12-31 16:00 libnetd_updatable.so
+ -rw-r--r-- 1 system system  95872 1969-12-31 16:00 libnetdutils.so
d -rw-r--r-- 1 system system 749980 1969-12-31 16:00 libservice-connectivity.so

Delta: -212624-948044+251404+45584+95872+749980 == -17828

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id88468442c4f3f24d5bca96b75effb69f20038bf
2022-02-02 18:03:23 -08:00
Maciej Żenczykowski
2f7dac1bad remove spurious headers
bpf_connectivity_headers already pulls in bpf_headers,
which already pulls in bpf_syscall_wrappers.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib22da8d433bd3187349f06f41ec064360c38982f
2022-02-02 16:38:36 -08:00
Maciej Żenczykowski
0bbe3d2ce4 libclat only depends on libbase_headers not libbase itself
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iad66f0d4bed4100261e8aa7d135e62336cdd1ae8
2022-02-02 16:38:36 -08:00
Robert Horvath
d945bf0b4f Add Low Power Standby support to TrafficController
Bug: 190822356
Test: atest TrafficControllerTest
Change-Id: I84a95081ab6e6a86543fe2cddf0efdab16c90d72
2022-02-02 22:54:21 +01:00
Robert Horvath
1db49e1c7f Handle Low Power Standby chain in ConnectivityService
Bug: 190822356
Test: atest NetworkManagementServiceTest
Change-Id: If5a07d0ea958d832b00797a9d9a4d5ad4f129b89
2022-02-02 22:54:21 +01:00
Patrick Rohr
8dfcb14be3 Remove libtcutils from dependencies as it is included in lib bpfjni
Test: builds && boots
Change-Id: Iacaed446655a606399188b8e5e4a5e98fefee121
2022-02-02 19:40:12 +00:00
Jean Chalard
2bc73d3b18 Merge changes Ic6a1aa92,I685f924a,I50fab91e
* changes:
  Use packBitList to prevent long-related mistakes
  Introduce ensureListenableCapabilities
  Accept accessUids from telephony when it's the carrier config app
2022-02-02 07:40:06 +00:00
Chalard Jean
dd4219978d Introduce ensureListenableCapabilities
Renamed from ensureValid, this is an easier to understand name.
It is also a lot clearer when requestable capabilities also
have to be listenable.

Also move the 2 functions together.

Test: FrameworksNetTests
Change-Id: I685f924a3720846d740837a4a0fee3d88a26725a
2022-02-02 13:52:26 +09:00
Chalard Jean
ac9ace0bbe Accept accessUids from telephony when it's the carrier config app
Test: FrameworksNetTests, new test in this patch
Change-Id: I50fab91e107c51d33a5e529c73b83db198a88d2c
2022-02-02 13:52:25 +09:00
Patrick Rohr
61e9467fa6 Move netlink_listener_test into TrafficControllerTest
netlink_listener_test tests the socket destroy listener, so it makes
sense to just merge it into the TrafficControllerTest.

Test: atest traffic_controller_unit_test
Change-Id: Ibc0b483203150aa2d7898a761fa4715dce6f4218
2022-02-01 21:13:30 +01:00
Patrick Rohr
83fb6742ac Fix BpfNetMap error logging
Log result code in native_init and fix spelling in log messages.

Test: m
Change-Id: I39b429ba05c6d5ccf50d28b0592fa5241972aa1b
2022-02-01 17:39:11 +01:00
Patrick Rohr
216dfc82f6 Enable TrafficController in apex
Test: atest FrameworksNetTests FrameworksNetIntegrationTests
CtsNetTestCases:android.net.TrafficStatsTest NetworkUsageStatsTest
CtsHostsideNetworkTests

Change-Id: I03f70e3258bf121cbac69a3bb302871ac680c6fb
2022-02-01 17:39:11 +01:00
Patrick Rohr
2b1b2c7206 Revert "Prevent native_init from starting TrafficController"
We are ready to remove traffic controller from netd, so
TrafficController::start() should be called from the system server.

This reverts commit c2984fdca8.

Test: atest FrameworksNetTests FrameworksNetIntegrationTests
CtsNetTestCases:android.net.TrafficStatsTest NetworkUsageStatsTest
CtsHostsideNetworkTests

Change-Id: Ic324ad0c064271977ab35d7f55badee00098e196
2022-02-01 17:38:57 +01:00
Ken Chen
f5f51339af Clean up BpfNetMaps
Cleans up BpfNetMaps.java before enabling mainline code path.

Bug: 202086915
Test: atest FrameworksNetTests
Change-Id: I28e5d63ed4624df540b1ca47b71899cff7321ded
2022-02-01 12:31:03 +01:00
Remi NGUYEN VAN
6a20eeda42 Reorganize connectivity framework dependencies
Allow framework-connectivity to depend on framework-connectivity-t
stubs, and framework-connectivity-t to depend on prebuilt (to avoid
circular dependencies) framework-connectivity stubs to compile its own
stubs, and framework-connectivity.impl to compile its implementation.

Also reorganize jarjar rules so that service and framework jar can use
static libraries in framework-connectivity without packaging their own,
reducing duplicate code.

Bug: 204830222
Test: m
Change-Id: I75c34986e7c479de23cdb2e9b360fa1fede018c9
2022-02-01 13:33:48 +09:00
Remi NGUYEN VAN
a2f7b18680 Link empty nearby library into tethering apex
Nearby will be merged together with the tethering/connectivity APEX, so
that module maintenance efforts can be reduced, and the two codebases
can evolve the interfaces that they expose to each other over time.

This is a cherry-pick from downstream branches, with some differences:
 - nearby/Android.bp is added with empty libraries
 - There is no API change, as no API classes are added
 - proguard is not applied, so no proguard rules change
 - HalfSheetUX APK is not added to the APEX

Bug: 189355156
Test: m
Merged-In: If4b40689a257d2806f895cd2dded97fc699adc5f
Change-Id: I2eb965a0965ffce08388278945160e57e8094339
2022-02-01 12:12:53 +09:00
Maciej Żenczykowski
76709a18e9 Merge changes Ifd6be50a,I857e40c9,I1b9f4fde,Ib3b43cf2
* changes:
  Prevent native_init from starting TrafficController
  Remove libutils dependency from libservice-connectivity
  Merge libtraffic_controller_jni into libservice-connectivity
  [NETD-TC#15] Make ConnectivityService and PermissionMonitor calls BpfNetMaps on T
2022-02-01 03:02:36 +00:00
Patrick Rohr
c2984fdca8 Prevent native_init from starting TrafficController
TrafficController is currently still started by netd, and this should
not happen in two places. Instead, native_init should init (open) the
maps.

Test: atest FrameworksNetTests
Change-Id: Ifd6be50aa5f62e59a5b1c5c0a97550389fd0e7e1
2022-01-31 18:18:21 +01:00
Patrick Rohr
313bc6c2d3 Remove libutils dependency from libservice-connectivity
Remove libutils dependency.

Test: m
Change-Id: I857e40c984bcce2931b5068b3b96d2c9dd69693c
2022-01-31 18:18:21 +01:00
Patrick Rohr
361b859b00 Merge libtraffic_controller_jni into libservice-connectivity
There is not really a point to separate these two as they are all used
in ConnectivityService.
As a future TODO, we might want to rename libservice-connectivity to
libcom_android_server_jni to be more inline with the jarjar'ed jni lib
versions.

Test: atest FrameworksNetTests:ConnectivityServiceTest
Change-Id: I1b9f4fde345038bda6b3ffcf8e3f47cf9262e052
2022-01-31 16:18:51 +01:00
Wayne Ma
2fde98c87b [NETD-TC#15] Make ConnectivityService and PermissionMonitor
calls BpfNetMaps on T

Since TrafficController moves to mainline module for T, so some netd binder
interfaces revelant to BPF are going to deprecated. Provide JNI APIs to
call TrafficController inside mainline module for T.

Bug: 209935649
Test: atest CtsHostsideNetworkTests
Change-Id: Ib3b43cf2840e02806395af9f1e019ca6fccd032e
2022-01-31 09:19:08 +01:00
Chalard Jean
e6c9527554 Send access UIDs to netd
Test: FrameworkNetTests CtsNetTestCases
Change-Id: I8301abaddf5850071fa23d41e8e736ab7071e299
2022-01-31 17:04:58 +09:00
Chalard Jean
9a30acf744 Add accessUids to NetworkCapabilities.
For now, all entry points reject this. Followup changes
will allow the supported use cases.

Test: new unit tests and CTS for this in this patch
Change-Id: I7262811a2e46336d3bb63c80886fc0578a36da94
2022-01-31 17:04:58 +09:00
Chalard Jean
1522857564 Clean up restrictions on network agent capabilities
This is a no-op change.

Test: FrameworkNetTests

Change-Id: I658e579bf49e1baf57a8aeaabc8d07d7d3293c56
2022-01-31 17:04:56 +09:00
Chalard Jean
366c525b15 Sanitize NetworkCapabilities from agent on the handler thread
NetworkAgents send NetworkCapabilities to ConnectivityService but
there are limits to what exactly they can send. Going forward,
some of these checks will have to happen on the handler thread,
which is already the case when an agent updates its capabilities,
but not upon registration.

This patches moves the sanitization on the handler thread, after
the network monitor is created for a network agent.

Before this patch, upon registration of a new agent, the binder
thread would copy and sanitize the capabilities, then store them
in nai.networkCapabilities. It would store the original caps from
the agent in the NAI, mix in what is known from the network info,
process the LinkProperties, and then proceed to create the
network monitor, but not yet store the NAI in the internal
structures because its registration is not finalized, so other
methods should not see it yet. After the monitor is created in
the network stack process, the NAI is stored in the internal
structures which publishes it for all methods to see. After
that is done, the NAI calls to the network monitor to warn it
that it's registered, what its capabilities are, and that it's
time to start validation if applicable.

With this patch, the validation no longer happens on the binder
thread. Instead, the binder thread stores the capabilities and
link properties as is, before sanitization, in the NAI. This is
fine because no other method can access these until the
registration completes upon notification that the monitor has
been created ; this agent is only stored in the network monitor
callbacks in a self-destructing object precisely to make sure
that's the case.
When the monitor is created and CS receives notification of the
same, it will sanitize the capabilities before adding the NAI
to the internal structures, to protect the invariant that the
un-sanitized capabilities inside the NAI can't ever be seen by
any other method. After that's done, it will call to the
monitor to start validation as usual.

Test: FrameworksNetTests CtsNetTestsCases
Change-Id: I7d43ef0e25955e0349903b4801b9dfd8c3c92586
2022-01-31 17:04:46 +09:00
Sooraj Sasindran
e9cd2084e4 Allow Carrier app to request for CBS capability
Test: unit test and CTS
Bug: 194332512
Change-Id: I29680b56d790106ad082f1a398c2bddb030f834a
2022-01-30 12:12:17 -08:00
Lorenzo Colitti
2a947ceb50 Merge changes from topic "dscp_policies"
* changes:
  Don't enable DscpPolicyTracker on pre-T devices.
  Allow service JNI in FrameworksNetIntegrationTests.
  Don't manually load the JNI library in DscpPolicyTracker.
  Process DSCP QoS events for policies
  Allow using BpfMap and TcUtils in unit tests.
2022-01-27 23:25:54 +00:00
Treehugger Robot
3755d9048a Merge "[LSC] Add LOCAL_LICENSE_KINDS to packages/modules/Connectivity" 2022-01-27 23:23:33 +00:00
Bob Badour
e7ebed2849 [LSC] Add LOCAL_LICENSE_KINDS to packages/modules/Connectivity
Added SPDX-license-identifier-Apache-2.0 to:
  service/native/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all
Change-Id: Ibfaed81348fca9e5cf313a4d29fd0b72bc746e06
2022-01-27 10:45:30 -08:00
Chalard Jean
47e778e301 Use the T shims in AOSP
Test: m
Change-Id: I10bbe36ba867aa77ea6f32cc3b8fd37d5b15145e
Merged-In: I0c4e29568eadb6ef85ddadebbb37723adb9f29cd
2022-01-27 16:37:51 +00:00
Lorenzo Colitti
debd9eaffa Don't enable DscpPolicyTracker on pre-T devices.
The code cannot work before T because before T the tethering
module can only load BPF programs/maps into /sys/fs/tethering/bpf
and the system server cannot access that directory.

Additionally, this is causing unit tests to fail on pre-T devices
because on those devices the seccomp filter blocks the bpf
syscall from apps (including Java tests).

Test: revert aosp/1907693 and atest FrameworksNetTests:ConnectivityServiceTest
Change-Id: I6c398031dffb840da1d723b11ea4d0845ad6c6f2
2022-01-27 14:16:49 +00:00
Treehugger Robot
ce0df5a6ed Merge "Correct some errno values before throw ServiceSpecificException" 2022-01-27 11:07:42 +00:00
Patrick Rohr
fff2733066 Merge "Load tcutils in ConnectivityService" 2022-01-27 10:31:02 +00:00
Lorenzo Colitti
f84e2f8e0d Don't manually load the JNI library in DscpPolicyTracker.
This is not necessary because TcUtils already loads its library,
and unlike this code, it correctly loads it using JniUtils so
will succeed even when the code is jarjard in unit tests.

Test: atest ConnectivityServiceTest
Change-Id: I57eb46178d58777769f5497a0ea93cd037d598cb
2022-01-27 10:20:01 +00:00
Tyler Wear
723882126a Process DSCP QoS events for policies
New events to handle adding and removing of DSCP QoS policies.
Async indication sends status back to client if the policy
has been added, failed, or if the policy limit has been
reached.

Bug: 202871011
Change-Id: I7988d22ae625ad0dd415927d2943de4a749e6fb8
2022-01-27 10:19:27 +00:00
Patrick Rohr
e258c5913d Load tcutils in ConnectivityService
Bug: 157552970
Test: TreeHugger
Change-Id: Ic2204260e822b082f58e5f01e5da8dad879ab22f
2022-01-27 09:07:36 +01:00
Jean Chalard
6c24db946d Merge "Use the network stack shims in services connectivity" 2022-01-27 07:36:53 +00:00