Commit Graph

376 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
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
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
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
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
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
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
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
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
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
Wayne Ma
41c2448ff9 Correct some errno values before throw ServiceSpecificException
For those functions which return statusFromErrno() in TrafficController,
it would return positive errno so shouldn't construct with -errno.

Test: m
Change-Id: I94b9294c4e200c43e33f8280469dfad9e9fbf5ea
2022-01-27 11:55:24 +08:00
Nucca Chen
f8ed984e9c Merge changes Ie826477d,I5125a3ac
* changes:
  [CLATJ#26] ClatCoordinator: reword clatd starting failure logging
  [CLATJ#25] ClatCoordinator: stop clatd process gracefully
2022-01-26 14:50:11 +00:00
Hungming Chen
6fb21144b8 [CLATJ#26] ClatCoordinator: reword clatd starting failure logging
Bug: 212345928
Test: build
Change-Id: Ie826477d27db26cc49d113ec8bfacaaa3006e26e
2022-01-26 12:23:45 +00:00
Chiachang Wang
317be96553 Merge "Send exclude local routes value to netd for VPN network" 2022-01-26 02:09:35 +00:00
Hungming Chen
d7b63f8f93 [CLATJ#23] Close the file descriptor manually
ParcelFileDescriptor rely on garbage collection to close handler.
When there is any error during starting clat or quick on/off
IPv6 only network, the file descriptor may not be able to be closed
before next clatStart is called. This may be problematic. For
example, the same v4- tun interface has not closed yet and clatStart
has been called again.

Test: connect/disconnect to IPv6 only network and ping 8.8.8.8
      repeat 10 times
Change-Id: I8e1c66206dc221827a039213ecc86d5cbd777dff
2022-01-25 20:32:11 +08:00
Hungming Chen
9d11ddfd5c [CLATJ#22] ClatCoordinator: stop clatd
provide clatd stop function which stops clatd by pid.

Bug: 212345928
Test: flash and boot
Run "atest ClatCoordinatorTest" in a follow commit.

Change-Id: Icd9c4f9038bf75113fbc5608f213145e58a061d9
2022-01-25 18:44:09 +08:00
Hungming Chen
9625caa8e5 [CLATJ#21] ClatCoordinator: start clatd
launch clatd with the given cli arguments.

Bug: 212345928
Test: flash and boot
- run "atest ClatCoordinatorTest" in a follow commit.
- manual test
  1. Connect to ipv6-only wifi.
  2. Try IPv4 traffic.
     $ ping 8.8.8.8

Change-Id: Ie57a7c7a9d3d77396e91fa9f94c02f1ad05487c1
2022-01-25 18:43:59 +08:00
Maciej Żenczykowski
f807ec7da7 Merge changes from topic "configure_bpf_for_clat"
* changes:
  [CLATJ#20] ClatdCoordinator: stop bpf for clat
  [CLATJ#19] ClatdCoordinator: configure bpf for clat
  [CLATJ#18] libclat: move clat tc and bpf utilis from netd
  [CLATJ#17] bpf_connectivity_headers visible to libclat
2022-01-24 19:14:35 +00:00
Sooraj Sasindran
0311ea0bc6 Merge "Add support for Multiple enterprise slice" 2022-01-24 16:26:03 +00:00
Wayne Ma
790c83e387 [NETD-TC#14] Add traffic controller JNI to tethering module
This CL provides native methods to access BPF maps via a native library.

Bug: 202086915
Test: m; flash; boot;
Change-Id: I2e5d03d0c2e31ba11996d1b28ead9b552397fe29
2022-01-24 00:22:26 +08:00
Sooraj Sasindran
f4a58dcd45 Add support for Multiple enterprise slice
Bug: 194332512
Test: unit test
CTS-Coverage-Bug: 211133973
Change-Id: Ie8be08a7cfa9155168d1da146d02fd1643248bdc
2022-01-22 14:39:40 -08:00
Hungming Chen
fb676b58e0 [CLATJ#20] ClatdCoordinator: stop bpf for clat
Remove eBPF offload at clat stopping if possible.

Bug: 212345928
Test: build only
because need to test with clatd launched

Change-Id: I6ace77694c0e6fe68d16e80e3c8198aa41385fd2
2022-01-22 20:07:30 +08:00
Hungming Chen
b1d3ccbeb6 [CLATJ#19] ClatdCoordinator: configure bpf for clat
Configure eBPF offload at clat starting if possible.

Bug: 212345928
Test: connect to ipv6 only network and check bpf entries
$adb shell dumpsys netd --short | grep Clat -A10
  ClatdController
    Trackers: iif[iface] nat64Prefix v6Addr -> v4Addr v4iif[v4iface] [fwmark]
    BPF ingress map: iif(iface) nat64Prefix v6Addr -> v4Addr oif(iface)
      47(wlan0) 64:ff9b::/96 2a00:79e1:abc:6f02:b7aa:ff3c:9220:595c -> 192.0.0.4 52(v4-wlan0)
    BPF egress map: iif(iface) v4Addr -> v6Addr nat64Prefix oif(iface)
      52(v4-wlan0) 192.0.0.4 -> 2a00:79e1:abc:6f02:b7aa:ff3c:9220:595c 64:ff9b::/96 47(wlan0) ether

Change-Id: I8ff77a2e3e86bfe6dbf43f4181414e444ba0da32
2022-01-22 20:07:24 +08:00
Sooraj Sasindran
499117f279 Ability to specify which all applications fall under enterprise slice.
Bug: 194332512
Test: unit test
Change-Id: I94549a41aaa717add22b0a3e5035beacf6f1b8f2
2022-01-21 01:05:12 -08:00
Wayne Ma
0ea3bdc88b [NETD-TC#10] Create BpfNetMaps class
BpfNetMaps provide interfaces and native methods for
manipulating BPF maps by calling jni library of traffic controller.

DO NOT TOUCH BpfNetMaps before aosp/1945136 and aosp/1948169 get merged.

Bug: 202086915
Test: build and flash
Change-Id: Iaff8ac71100b3f76b444f3b83616556d0ee6eadf
2022-01-21 13:19:29 +08:00
Hungming Chen
050b6529c4 [CLATJ#16] Rename JNI/Dependencies function and improve JNI error handling
- rename JNI functions with prefix native_*
- throw exception while JNI function gets invalid address argument
- throw exception while JNI function returns invalid address

Bug: 212345928
Test: flash and boot
Run "atest ClatCoordinatorTest" in a followup commit

Change-Id: I6745a61525c6f72a61fbde0b21b3f7abcdf2446a
2022-01-20 22:50:13 +08:00
Hungming Chen
847b2ce4f9 [CLATJ#15] ClatCoordinator: add socket filter to packet socket
Update our packet socket filter to reflect the new 464xlat IP address

Bug: 212345928
Test: flash and boot
Run "atest ClatCoordinatorTest" in a followup commit

Change-Id: Ic50dc122731f311ad00ab8bff5472cb3bc41f5f1
2022-01-20 22:50:13 +08:00
Hungming Chen
2c3acb01c9 [CLATJ#14] ClatCoordinator: add anycast to raw socket
Start translating packets to the new prefix.

Bug: 212345928
Test: flash and boot
Run "atest ClatCoordinatorTest" in a followup commit.

Change-Id: I38729c23fce72428919b33ac531ede9593337a0a
2022-01-20 22:50:13 +08:00
Hungming Chen
d292f45e16 [CLATJ#13] ClatCoordinator: open raw socket
Move the raw socket initialization from netd to mainline because
mainline module is going to launch clatd. Need to provide raw
socket for writing local 464xlat IPv6 packets.

Bug: 212345928
Test: flash and boot
Run "atest ClatCoordinatorTest" in a followup commit.

Change-Id: I6d1da4f1b400eeed87771ae8197b0c58ec50804b
2022-01-20 22:50:13 +08:00
Hungming Chen
79d34befb1 [CLATJ#12] ClatCoordinator: open packet socket with a given mark
Move the packet socket initialization from netd to jni because
mainline module is going to launch clatd. Need to provide packet
socket for reading local 464xlat IPv6 packets.

Bug: 212345928
Test: flash and boot
Run "atest ClatCoordinatorTest" in a followup commit.

Change-Id: I1cef6e099403f883d668081fb5e917863f5a3c2a
2022-01-20 22:50:13 +08:00
Hungming Chen
397ca65abb [CLATJ#11] ClatCoordinator: config tun interface and bring up
Apply mtu and selected IPv4 address to tun interface.
Then, bring up the tun interface.

Bug: 212345928
Test: flash and boot
Run "atest ClatCoordinatorTest" in a followup commit.

Change-Id: I24a2a91e2b084be28820a7a63b265c5f56293334
2022-01-20 22:50:13 +08:00
Hungming Chen
7de1c49b74 [CLATJ#10] ClatCoordinator: detect mtu
Detect the available mtu for clat. The native mtu detect function
is moved from netd to libclat which is called by jni. The java
adjust mtu function is moved from netd native code.

Bug: 212345928
Test: flash and boot
Run "atest ClatCoordinatorTest" in a followup commit.

Change-Id: Icf5f57c7e7b947997b76152722e46acdd9d95c1a
2022-01-20 22:50:13 +08:00
Hungming Chen
46bbee1bfe [CLATJ#9] ClatCoordinator: open tun interface
Open the v4-... tun interface for clat. The native function
is moved from netd to jni.

Bug: 212345928
Test: flash and boot
Run "atest ClatCoordinatorTest" in a followup commit.

Change-Id: I3f3c587275125ce3fc7481006947211f17dbb2d4
2022-01-20 22:50:13 +08:00
Hungming Chen
884c0a122c [CLATJ#8] ClatCoordinator: select IPv6 address with checksum-neutral IID
Select a local 464xlat IPv6 address for clatd. The IPv6 address has
checksum-neutral IID. The native function is moved from netd to
libclat. Its test is moved from netd as well.

Bug: 212345928
Test: flash and boot
Run "atest ClatCoordinatorTest" in a followup commit.

Change-Id: I11520e5c086e475999847d829dd6341b14199b39
2022-01-20 22:50:13 +08:00
Hungming Chen
e2cf055590 [CLATJ#7] ClatCoordinator: select IPv4 address for clatd
Introduce ClatCoordinator to replace netd/ClatdController.
This is a startup commit. Starting clatd needs to prepare local
464xlat ipv4 address, local 464xlat ipv6 address, tun interface,
clat read/write sockets. These will be implemented from this
and followup commits. This commit implements that prepare local
464xlat ipv4 address.

Bug: 212345928
Test: flash and boot
Run "atest ClatCoordinatorTest" in a followup commit.

Change-Id: I486db8aef0181ee1aedd7cd7702f95d5a1cef812
2022-01-20 22:50:13 +08:00