Commit Graph

91144 Commits

Author SHA1 Message Date
Ken Chen
ec0f7ac36f Add a library for DNS resolver to read bpf maps
The library provides an init function and an API for DNS resolver to
query whether the application is allowed to send DNS query based on BPF
maps settings.

Bug: 288340533
Test: atest dns_helper_unit_test (with test CL)
Change-Id: Ibfb383bfb074da2104a25aa4f04ebc32b22d11da
2023-11-01 06:23:04 +08:00
Sudheer Shanka
3130de88f3 Merge "Use 'set-standby-bucket' instead of 'set-inactive' command." into main 2023-10-31 21:04:49 +00:00
Sudheer Shanka
c6240e9cfd Use 'set-standby-bucket' instead of 'set-inactive' command.
When 'set-inactive' command is used, it is possible for the
test app to get into the NEVER bucket as it wouldn't be
recorded as used by the user in some cases.

Bug: 298816567
Test: atest tests/cts/hostside/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java
Change-Id: If2667a07629b38395d0fed99771488d0900caf18
2023-10-31 19:50:51 +00:00
Yuyang Huang
103e9b6766 Merge "Code cleanup in MdnsInterfaceAdvertiser, MdnsReplySender, MdnsUtils" into main 2023-10-31 13:23:18 +00:00
Motomu Utsumi
d232211291 Merge "Handle v4-mapped v6 address in Struct parsing" into main 2023-10-31 12:02:47 +00:00
Motomu Utsumi
cb62c1b120 Merge "Add util method to generate IPv4-mapped IPv6 address from IPv4 address" into main 2023-10-31 12:02:08 +00:00
Jean Chalard
de33ada087 Merge "Destroyed networks can't hope to beat champions" into main 2023-10-31 10:01:09 +00:00
Jean Chalard
a394bcf24a Merge changes I9109cd9d,Ie7cec6fe,I215e915d into main
* changes:
  Stop MockVpn from extending Vpn class.
  Remove unused method calls of MockVpn
  Create local NetworkCapabilites for MockVpn.
2023-10-31 09:01:50 +00:00
Ken Chen
2337cbf87e Merge "Pass metered information to DNS resolver" into main 2023-10-31 08:53:41 +00:00
Yuyang Huang
f3bef6846a Merge "Increase HandlerUtilsTest timeout to 500ms" into main 2023-10-31 08:39:35 +00:00
Junyu Lai
e003152e2c [BR02] Implement isUidNetworkingBlocked
This is needed for data stall detection mechanism in NetworkStack
to get the information about whether the network is blocked for
a given uid and conditions. Because the API will be called
frequently from NetworkStack to resolve all status for all uids
on the device, the API cannot call into the service which
creates IPC. Instead, the API need to directly access bpf maps
in the user process to retrieve the status. In this case the
user process is the network stack, the access control is provided
by linux file permission and selinux.

Test: atest FrameworksNetTests:android.net.connectivity.android.net.BpfNetMapsReaderTest
Test: atest FrameworksNetTests:android.net.connectivity.android.net.ConnectivityManagerTest
NO_IFTTT=Refactor only change for firewall chains definitions
Bug: 297836825

Change-Id: Iaf983b71ec98cbfe5152dcfade8a3120f938f135
2023-10-31 16:33:41 +08:00
Motomu Utsumi
77b49996d2 Add methods for updating ingressDiscardRule bpf map to BpfNetMaps
Bug 295800201
Test: NetworkStaticLibsTests

Change-Id: I42bc0adc22c3018480029d624053f758d815e526
2023-10-31 17:07:46 +09:00
Motomu Utsumi
e3e34bdf3a Handle v4-mapped v6 address in Struct parsing
testV4MappedV6Address fails without change in Struct.java

Bug: 295800201
Test: atest ConnectivityCoverageTests
Change-Id: I4a40bc47b051860c6420f211491e2ecd34c1d732
2023-10-31 17:01:48 +09:00
Motomu Utsumi
52366e0fb1 Add util method to generate IPv4-mapped IPv6 address from IPv4 address
Bug: 295800201
Test: NetworkStaticLibTests
Change-Id: Ia10e7dd14edfabe0edf5c9e12ceae54a1ff88d13
2023-10-31 17:01:43 +09:00
Ken Chen
5a35cf9086 Pass metered information to DNS resolver
Dns Resolver needs to know whether a network is metered when checking if
DNS requests will be blocked by Data Saver.

Bug: 288340533
Test: atest FrameworksNetTests
Change-Id: Ia5822dc522c766c7815680003c7ba275d15ccaff
2023-10-31 07:38:40 +00:00
Ken Chen
792a7cd1a1 Merge "Write Data Saver setting to BPF map" into main 2023-10-31 07:09:47 +00:00
Hansen Kurli
a9b72ba71b Merge "Fill ConnectivityService in testDumpDoesNotCrash()" into main 2023-10-31 05:52:02 +00:00
Yuyang Huang
81877c4153 Code cleanup in MdnsInterfaceAdvertiser, MdnsReplySender, MdnsUtils
* Update getRawOffloadPayload() with @NonNull annotation.
* Log the error object directly instead of logging the error message.
* Use Arrays.copyOfRange() instead of System.arraycopy().
* Remove the unnecessary escape of mPacketCreationBuffer member variable in MdnsReplySender.

Bug: 308079421
Test: TH
Change-Id: I8c805bfe1fc1ae1d9a8abfab498059bda05710ff
2023-10-31 13:02:39 +09:00
Ken Chen
243301748e Write Data Saver setting to BPF map
The information is needed by modules who want to know whether a
specific UID is blocked by Data Saver feature.

1. Add a one-element map data_saver_enabled_map.
2. Update current data saver setting to the map.

Bug: 288340533
Test: atest FrameworksNetTests:android.net.connectivity.com.android.serv
er.BpfNetMapsTest
Test: atest bpf_existence_test

Change-Id: I981da4b569247c33cba2d365cb6f2691f673474e
2023-10-31 01:36:03 +00:00
Chalard Jean
80685f42c3 Destroyed networks can't hope to beat champions
In particular, this fixes a bug where a non-validated destroyed
network can't get disconnected after it's replaced by another
non-validated network because CS thinks it should keep it in
case it validates and beats the replacement network.

Test: new test for this : CSDestroyedNetworkTests
Change-Id: I5d7e413624d6fca28b06484e5369cd17e4a599a4
2023-10-30 23:26:43 +09:00
Ken Chen
6b134f18f4 Pass NetworkCapabilities into DnsManager
1. At present, the transportTypes in NetworkCapabilities have been
passed into DnsManager::updateTransportsForNetwork() as a parameter. In
the following CL, we also need to pass the 'metered' (also in
NetworkCapabilities) as a parameter to the function. Instead of passing
the members of NetworkCapabilities one by one, it is better to pass the
entire NetworkCapabilities.

2. Rename updateTransportsForNetwork() to
updateCapabilitiesForNetwork().

Bug: 288340533
Test: presubmit
Change-Id: I0966124f87b12c1d5a2eaee681885c3d5c7f74dc
2023-10-30 08:29:58 +00:00
Mark Chien
0b8bdb1074 Merge "SyncSM8.2: make IpServer support syncSM" into main 2023-10-30 07:51:54 +00:00
Mark Chien
bdf6178a1a Merge "SyncSM8.1 always call transitionTo under processMessage" into main 2023-10-30 07:51:06 +00:00
Maciej Żenczykowski
e26f93318c Merge "Revert "Add forwarding methods to RoutingCoordinator"" into main 2023-10-28 06:34:26 +00:00
Ken Chen
fe0d0f6e33 Merge "Move is_system_uid utility from netd.c to netd.h" into main 2023-10-28 03:48:45 +00:00
Maciej Żenczykowski
543d0d32e4 Revert "Add forwarding methods to RoutingCoordinator"
This reverts commit 55ccfe19e2.

Reason for revert: this must be introducing some sort of race
it appears to cause
  atest EthernetTetheringTest 'NetdBinderTest#TetherForwardAddRemove'
to no longer reliably pass.

Change-Id: I5281ab3f42c5ce268d97a12db24a6768db3f4354
2023-10-28 02:10:52 +00:00
Maciej Żenczykowski
8bc6ee5b7a Merge "Add java class for Ingress discard bpf map key value" into main 2023-10-27 19:13:52 +00:00
Ken Chen
784696fdb9 Move is_system_uid utility from netd.c to netd.h
1. Move it to header file so that it can be reused by others.
2. Correct the return type from int to bool.
3. Replace __always_inline by inline to avoid -Werror,-Wunused-function.

Bug: 288340533
Test: build
Change-Id: I9062686d9c2f98c2d24e4673f82b1732b180ffc4
2023-10-28 02:46:22 +08:00
Jean Chalard
9fea45db05 Merge "Cleanup modifyRoutes" into main 2023-10-27 13:11:29 +00:00
Paul Hu
77c1118e1c Remove DefaultState in NsdService
The code handling service registration, discovery, and resolution
in DefaultState is never executed because these messages are
always handled in EnabledState. Therefore, the active code in
DefaultState should be moved to EnabledState and DefaultState
should be removed.

Bug: 307209858
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I38a255ddf72148c7ae13d3079dbd3c03f800b9c2
2023-10-27 17:14:05 +08:00
Mark Chien
2c7e2b8448 Merge changes Ibe22b300,I0b0f0bf1 into main
* changes:
  SyncSM08: handle IpServer requestEnableTethering callback in mainSM
  SyncSM07.1: Add a test that shows tethering restarts when disabling
2023-10-27 08:50:04 +00:00
Hansen Kurli
f7a8e9928f Stop MockVpn from extending Vpn class.
Make MockVpn stop extending Vpn in order to stop depending on
Vpn code. This includes:

1. Remove @Override and synchronized for all MockVpn methods.
2. Remove the constructor.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: I9109cd9d3e17717cffa6c89c6a9e4330ed9af3cf
2023-10-27 15:30:46 +08:00
Hansen Kurli
03faec6ea0 Remove unused method calls of MockVpn
The following are removed:
1. mUnderlyingNetworkInfo and the related get and set.
2. Calls to setEnableTeardown() since this has no
   interaction with ConnectivityService.
3. Calls to updateState().
4. Usage of mInterface.
5. Usage of mConfig.
6. Usage of mNetworkAgent.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: Ie7cec6fed25f841de995059deba1c1df67377e70
2023-10-27 15:30:46 +08:00
KH Shi
f92d211c71 Merge "Pass upstream prefixes to bpf tethering offload" into main 2023-10-27 07:23:52 +00:00
Chalard Jean
ac5e4cf025 Cleanup modifyRoutes
This is no longer used out of this file, and should not be.

Test: Build
Change-Id: I531191b4afbda39a5fbaf1f483d13068f86d17f1
Merged-In: Ief0a79883bcc2c5493807c548cb71ef655abed23
2023-10-27 06:53:36 +00:00
Jean Chalard
23376e6fe7 Merge "Add forwarding methods to RoutingCoordinator" into main 2023-10-27 05:12:07 +00:00
Hansen Kurli
20b5a99f88 Create local NetworkCapabilites for MockVpn.
Store the mNetworkCapabilities locally in MockVpn to stop
depending on the Vpn class.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: I215e915dcafb6700950bc8a500bc16f839d0e13e
2023-10-27 10:18:08 +08:00
Patrick Rohr
149868f1b1 Merge "Add public getter for IpPrefix" into main 2023-10-26 18:21:07 +00:00
Mark Chien
a055890412 Merge changes I34903b57,Ic818aa55 into main
* changes:
  SyncSM07: Replace IpServer's state machine with StateMachineShim
  SyncSM06: Add StateMachineShim
2023-10-26 16:44:44 +00:00
Treehugger Robot
aacd7d8d8c Merge "Support NetworkStatsEventLogger" into main 2023-10-26 14:17:21 +00:00
KH Shi
3f738fcd3d Pass upstream prefixes to bpf tethering offload
BPF needs upstream prefixes information to filter spoofing IPv6 source
addresses carried in downstream traffic.

We retrieve prefixes from upstream interface's LinkProperties and pass
it to the BpfCoordinator. Forwarding rules will also be updated when
upstream interface's IPv6 link addresses change.

Test: atest TetheringTests
Bug: 261923493
Change-Id: If8cfc3b191e520ca838654d1b5211ab9e9ec021d
2023-10-26 13:13:38 +00:00
Chalard Jean
55ccfe19e2 Add forwarding methods to RoutingCoordinator
Test: RoutingCoordinatorServiceTest
      TetheringTest
Change-Id: Ic3b36ddc236e8615e7d931b6e526556bbd2dac17
2023-10-26 20:18:48 +09:00
Hansen Kurli
49f7ab9eeb Fill ConnectivityService in testDumpDoesNotCrash()
testDumpDoesNotCrash does not dump enough objects to have full
coverage. e.g. In b/303348620, it did not detect the crash since
there is no NetworkAgentInfo stored in ConnectivityService.

This change ensures ConnectivityService is filled with more
objects that will be dumped:
1. NetworkProvider
2. NetworkAgentInfo
3. NetworkOffer
4. Network preferences

Bug: 303348620
Test: atest FrameworksNetTests
Change-Id: I7e2f1954c91409f3bf0daf01300e34ce73e311cb
2023-10-26 18:35:33 +08:00
Mark
be99f86ad9 SyncSM8.2: make IpServer support syncSM
After this change, IpServer could switch to use syncSM.

Test: atest TetheringTests
Change-Id: I2d7fa47cd020f3e76e7a8beaefb98852e93545f8
2023-10-26 09:34:23 +00:00
Mark
50eef8316c SyncSM8.1 always call transitionTo under processMessage
As state transitions always occur after a message has been processed,
calling transitionTo only under processMessage makes the flow easier
to understand and less error-prone.

The risk of this change is very minimal since it is only about
handling the error, but tethering will stop regardless.

Test: atest TetheringTests

Change-Id: I56c6cf6cc989464ee84a8333ac131afc808a3d95
2023-10-26 09:31:18 +00:00
Mark
5cc386bdef SyncSM08: handle IpServer requestEnableTethering callback in mainSM
This can make it easier to adopt SM shim replacement in follow up change,
as both SyncSM and AsyncSM will process the same message without any
difference.

This change also fix a problem that bring up downstream before it's
IpServer completely disabled.

Previous:
CMD_NOTIFY_PREFIX_CONFLICT -> requestEnableTethering(false) ->
requestEnableTethering(true) -> IpServer stopped ->
reportTetherStateChanged(downstream inactive) -> IpServer started
-> reportTetherStateChanged(downstream active)
New:
CMD_NOTIFY_PREFIX_CONFLICT -> requestEnableTethering(false) ->
IpServer stopped -> reportTetherStateChanged(downstream inactive)
-> requestEnableTethering(true) -> IpServer started
-> reportTetherStateChanged(downstream active)

Test: atest MtsTetheringTestLatestSdk
Change-Id: Ibe22b300c56125359f4fa452bd01a0a2381fda23
2023-10-26 09:28:22 +00:00
Mark
d81f6ef4db SyncSM07.1: Add a test that shows tethering restarts when disabling
When tethering restarts due to an IP conflict, it starts to
bring up downstream before its IpServer is completely disabled.

Test: atest TetheringTests
Change-Id: I0b0f0bf1bb9ac8421c05fe512d5082d095fa7180
2023-10-26 09:26:37 +00:00
Mark
2150296476 SyncSM07: Replace IpServer's state machine with StateMachineShim
A simple replacement without changing any behavior.

Test: atest TetheringTests
Change-Id: I34903b57df68081e974163edec82a851ee4ccc98
2023-10-26 09:26:15 +00:00
Mark
2ec1595d0b SyncSM06: Add StateMachineShim
Test: atest StateMachineShimTest

Change-Id: Ic818aa55e7e0fd7a62dfce50a6ad719e6e1c44ec
2023-10-26 09:24:55 +00:00
Krzysztof Kosiński
93196302b1 Merge "Clean up obsolete aliases for Truth." into main 2023-10-26 09:07:59 +00:00