Commit Graph

1924 Commits

Author SHA1 Message Date
Hansen Kurli
70bc73223e Expect no error for startLegacyVpn with IPv6.
findIPv4DefaultRoute() is removed from Vpn, so
IllegalStateException is no longer thrown for IPv6 only
networks.

The test testStartLegacyVpnIpv6 is now not testing anything new
and so it is removed. Note that other tests that will be calling
startLegacyVpn() ensure coverage is not lost.

Bug: 161776767
Test: atest FrameworksNetTests
Change-Id: I6ac9d7c196b7bc4c44fc2ad32baa25b106640ef4
2023-11-02 21:11:12 +08:00
Hansen Kurli
879655c77b Remove tests related to LegacyVpnRunner.
LegacyVpnRunner is removed, remove the following related tests:
1. testStartRacoonNumericAddress
2. testStartRacoonHostname
3. testStartPptp
4. testStartPptp_NoMppe

Create a new test that asserts UnsupportedOperationException for
the VPN types in those tests.

Bug: 161776767
Test: atest FrameworksNetTests
Change-Id: Id66d09ea54576ca4c641e8f69d104dc26a42c46b
2023-11-02 21:07:06 +08:00
Junyu Lai
31ab762e42 Merge "[BR06] Support check whether network is blocked by data saver" into main 2023-11-02 07:09:50 +00:00
Junyu Lai
2deeef4f5e Merge "Fix NetworkStatsObersers thread leak in the NetworkStatsServiceTest" into main 2023-11-01 10:18:50 +00:00
Junyu Lai
8b5ebfc342 Fix NetworkStatsObersers thread leak in the NetworkStatsServiceTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest
     (with debug code that dump all threads at the end of tests)
Fix: 308544001
Change-Id: I597054633bbb008ffd0edebe34dcf6935958aa5d
2023-11-01 17:11:17 +08:00
Hansen Kurli
8f329c2e97 Merge changes I5fffc137,Ifc076a8d into main
* changes:
  Add Log.wtf when keepalive metrics are unexpected.
  Add dump of KeepaliveStatsTracker
2023-11-01 08:50:39 +00:00
Hansen Kurli
a746c1a4da Add Log.wtf when keepalive metrics are unexpected.
To debug unexpected keepalive metrics values, print the built
metrics in a Log.wtf before writing it to statsd.

Bug: 297292877
Test: atest FrameworksNetTests
Change-Id: I5fffc13721e50e28f24b0da12a961364f3f77e21
2023-11-01 14:41:35 +08:00
Hansen Kurli
723c273be3 Add dump of KeepaliveStatsTracker
To debug unexpected metrics values, print the built metrics into
the connectivity dump.

Sample of the added log dump:
KeepaliveStatsTracker enabled: true
   # android.net.connectivity.com.android.metrics.Dailykeepalive
InfoReported@3293424e
   automatic_keepalive_requests: 2
   distinct_user_count: 1
   duration_per_num_of_keepalive {
     duration_for_num_of_keepalive {
       keepalive_active_durations_msec: 36
       keepalive_registered_durations_msec: 36
       num_of_keepalive: 0
     }
     duration_for_num_of_keepalive {
       keepalive_active_durations_msec: 9
       keepalive_registered_durations_msec: 6
       num_of_keepalive: 1
     }
     duration_for_num_of_keepalive {
       keepalive_active_durations_msec: 7
       keepalive_registered_durations_msec: 10
       num_of_keepalive: 2
     }
   }
   keepalive_lifetime_per_carrier {
     keepalive_lifetime_for_carrier {
       active_lifetime_msec: 23
       carrier_id: -1
       intervals_msec: 10000
       lifetime_msec: 26
       transport_types: 1
     }
   }
   keepalive_requests: 2
   uid: 10097

Bug: 297292877
Test: adb shell dumpsys connectivity
Test: New test testDumpDoesNotCrash()
Change-Id: Ifc076a8dce734e9c175f1b1f28e1c448b9a792e5
2023-11-01 14:41:24 +08:00
Chiachang Wang
006f9d2998 Merge "Quit handler threads at the end of the tests" into main 2023-11-01 06:29:33 +00:00
Junyu Lai
2c8e96d599 Merge "[BR02] Implement isUidNetworkingBlocked" into main 2023-11-01 03:40:05 +00:00
Junyu Lai
c3dc5b6222 [BR06] Support check whether network is blocked by data saver
This change adds a DataSaverStatusTracker, which is a helper
class to continuously track data saver status through NPMS
public API and intents. ConnectivityManager#isUidNetworkingBlocked
would use this cached information along with bpf maps to decide
whether networking of an uid is blocked.

Test: atest FrameworksNetTests:android.net.connectivity.android.net.BpfNetMapsReaderTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.android.net.ConnectivityManagerTest
Bug: 297836825
Change-Id: I7e13191759430f3ea1f4dec7facc02f16be7146d
2023-11-01 11:10:01 +08:00
Chiachang Wang
2973cf4363 Quit handler threads at the end of the tests
The created handler threads should be quit after the tests to
prevent memory leakage. Also, this commit updates the method
used to close the created HandlerThread to do it correctly.

Bug: 308537727
Test: atest ConnectivityCoverageTests
Change-Id: I3715a73a9142418c05f98bc95e275f97161ab3cd
2023-11-01 01:24:07 +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
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
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
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
Maciej Żenczykowski
e26f93318c Merge "Revert "Add forwarding methods to RoutingCoordinator"" into main 2023-10-28 06:34:26 +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
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
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
Treehugger Robot
aacd7d8d8c Merge "Support NetworkStatsEventLogger" into main 2023-10-26 14:17:21 +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
Maciej Żenczykowski
de9d367ab2 remove dead portions of BpfUtils.java
(mostly to improve code coverage)

We can always revert if it ever turns out this is useful,
but I'd prefer for cgroup attach to be a once-at-boot
thing and handled either from bpfloader or the netd updatable
which are both directly C++ code.

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I79b5ca8a47388cb6b9189234942e74ab6056aab9
2023-10-25 17:40:35 +00:00
Junyu Lai
41b37349f3 Support NetworkStatsEventLogger
The performPoll method in the NetworkStatsService can be called
for many reasons, such as RAT changed events, LinkProperties
changed events, open session method calls, forceUpdate method
calls, etc.
However, the current logging is not sufficient to trace down
the caller of performPoll. This makes it difficult to debug
frequent poll issues or performance problems.

Adding debug log to logcat is not an option, given that
performPoll might run several times per second by system server
callers.

This change adds a reason code to the performPoll method and
a helper class to log performPoll events. This will allow us
to track down the caller of performPoll and better understand
why it is being called frequently or causing performance
problems.

This change also introduces a PollEvent object, which can be
used to put related information in subsequent changes when
logging.

Sample output:
Poll counts per reason:
  DUMPSYS: 0
  FORCE_UPDATE: 6
  GLOBAL_ALERT: 0
  NETWORK_STATUS_CHANGED: 3
  OPEN_SESSION: 0
  PERIODIC: 1
  RAT_CHANGED: 1
  REG_CALLBACK: 3
  REMOVE_UIDS: 0
  UPSTREAM_CHANGED: 1

Recent poll events:
  2023-10-04T02:47:12.937370 - Poll(flags=3, PollEvent{reason=REG_CALLBACK})
  2023-10-04T02:47:13.178559 - Poll(flags=3, PollEvent{reason=FORCE_UPDATE})

Test: manual
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.net.NetworkStatsEventLoggerTest
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.net.NetworkStatsServiceTest
Bug: 301141955
Change-Id: Ic6d0543ccdef12493385f45200199854b841a26b
2023-10-25 19:23:35 +08:00
Junyu Lai
a62eed380c Merge "[BR01.1] Support BpfNetMapsReader" into main 2023-10-24 05:56:33 +00:00
Hansen Kurli
a584159ceb Merge "Mock Vpn.setAlwaysOnPackage()." into main 2023-10-24 03:11:38 +00:00
Junyu Lai
626045a601 [BR01.1] Support BpfNetMapsReader
A helper class to *read* java BpfMaps. This is designed to
provide direct bpf access in the caller process through
ConnectivityManager APIs.

The change also removes any statical link to
net-utils-device-common-struct from service-connectivity.
This is because net-utils-device-common-struct is already
included in framework-connectivity. Including it again in
service-connectivity would create a r8 build fail by circular
dependency.

Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.BpfNetMapsTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.net.module.util.StructTest
Test: atest FrameworksNetTests:android.net.connectivity.android.net.BpfNetMapsReaderTest
Bug: 297836825
Change-Id: I7a6d2eb816d0dc7343167bddd672806b199f44fe
2023-10-23 20:11:02 +08:00
Hansen Kurli
00fd12588f Merge changes Id9f81fdf,I3428e8b3,Ifa895f71,I61cd4751,I47a25e9f into main
* changes:
  Add tests for always on lockdown VPN on system user.
  Remove MockVpn.setAlwaysOnPackage() non-lockdown.
  Mock onUserAdded() and onUserRemoved()
  Refactor helper method to return integer ranges.
  Add tests for onUserAdded and onUserRemoved
2023-10-23 11:58:24 +00:00
Hansen Kurli
2ddfc8ba8c Mock Vpn.setAlwaysOnPackage().
Call setRequireVpnForUids() directly to mock an always on Vpn
being enabled instead of calling the real Vpn method.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: I63d6547104cc6ee984413d4cf6027ceecd301ecc
2023-10-23 17:22:19 +08:00
Hansen Kurli
a09c6f29a6 Add tests for always on lockdown VPN on system user.
Add test coverage for Vpn.setAlwaysOnPackage() where the caller
is system user to ensure uid = 0 is not restricted.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: Id9f81fdf0147597f64f8440b971930b3bd7b55e5
2023-10-23 17:22:10 +08:00
Hansen Kurli
9ae16e4e27 Remove MockVpn.setAlwaysOnPackage() non-lockdown.
Remove calls to MockVpn.setAlwaysOnPackage() where lockdown is
false as this does not cause any changes to occur. Also verify
setRequireVpnForUids() is not called for this case in VpnTest.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: I3428e8b31b02975975be9e943e1f88cf0e80c5ee
2023-10-23 16:03:06 +08:00
Hansen Kurli
cd04062150 Mock onUserAdded() and onUserRemoved()
Replace calls to onUserAdded() and onUserRemoved() to their
equivalent setUids() or setRequireVpnForUids() calls.

Note coverage for the calls to Vpn were added in VpnTest.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: Ifa895f71f78bd3376216fd2759c7a5a33cd3aff1
2023-10-23 15:26:30 +08:00
Hansen Kurli
946cafb87e Refactor helper method to return integer ranges.
Calls to setRequireVpnForUids() for Vpn lockdown actually uses a
List instead of a Set of integer ranges.
Add intRangesExcludingUids() to return the needed List of integer
ranges and replace relevant usages of UidRange.toIntRanges() with
it.

Bug: 230548427
Test: atest FrameworksNetTests
Change-Id: I61cd4751ce2faeb129daa5ad5da7181e3c1df73c
2023-10-23 15:12:21 +08:00
Jean Chalard
e32bf36be8 Merge "Reapply "Add LocalNetworkConfig"" into main 2023-10-20 06:25:14 +00:00
Junyu Lai
eb75416136 Merge "Dump bpf program status in dumpsys" into main 2023-10-19 09:33:27 +00:00
Paul Hu
322a322687 Merge "Add expired services removal flag" into main 2023-10-19 06:19:43 +00:00
Paul Hu
f3fe3333d3 Add expired services removal flag
The TTL check and removal of expired services is currently only
performed when a mDNS query is sent. This can result in expired
services remaining in the cache if no queries are sent. To
address this, the remaining TTL will be checked when retrieving
services from the MdnsServiceCache. Add a new flag to enable
the expired services removal feature. This feature will be
implemented in subsequent changes.

Bug: 265787401
Bug: 304649384
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I30f0eea568ee45d363cc02821de0921d6040f981
2023-10-18 17:48:46 +08:00
Junyu Lai
155760b57b Dump bpf program status in dumpsys
Sample output:
Bpf Program Status:
  CGROUP_INET_INGRESS: 21
  CGROUP_INET_EGRESS: 22
  CGROUP_INET_SOCK_CREATE: 28
  CGROUP_INET4_BIND: 30
  CGROUP_INET6_BIND: 31

Test: adb shell dumpsys connectivity
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.ConnectivityServiceTest#testDumpDoesNotCrash
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest#testDumpDoesNotCrash
Bug: 292156770
Change-Id: I312c90c524af12d093536156d6d5c6febd64305a
2023-10-18 16:05:55 +08:00
Chalard Jean
f9d0e3e94f Reapply "Add LocalNetworkConfig"
This reverts commit 6eea22b18c.

Change-Id: I0a2cef4ee992577674c92ecd384dc6f4361afa02
2023-10-18 15:50:02 +09:00
Jean Chalard
de0f4e5b87 Merge "Reapply "Tell netd about local networks"" into main 2023-10-17 13:00:46 +00:00
Junyu Lai
5606bba1f9 Merge "Move dumpsys to handler thread" into main 2023-10-17 11:08:19 +00:00
Junyu Lai
f8dba342f1 Move dumpsys to handler thread
I0afdda023208c3f8620cb5b89add66448af596d7 added some assertions
to ensure NetworkAgentInfo can only be accessed from the handler
thread. This is good to eliminate any potential concurrent
accessing problem. Howver, dumpsys runs on binder thread, this
change breaks dumpsys functionality.

Thus, this change:
  1. Copy Handler#runWithScissors() and related class
     locally since they are @hide methods.
  2. Run doDump on the handler thread and waits for return.

Test: adb shell dumpsys connectivity
Test: atest FrameworksNetTests:android.net.connectivity.com.android.server.HandlerUtilsTest
Fix: 303348620
Change-Id: Ic3a22f5d370bbf8c18b1972e86d695b6ad61bd0d
2023-10-17 17:16:04 +08:00