Commit Graph

9261 Commits

Author SHA1 Message Date
Aaron Huang
ece181997c Remove *_WILDCARD constants from NetworkTemplate
NetworkTemplate was moved into mainline module and
provide Builder for external users to build template.
MATCH_MOBILE_WILDCARD and MATCH_WIFI_WILDCARD are not
exposed so currently the usage of these two constants
only in module. This change is to remove the constants.

After removing the constants, two methods matchesWifi
and matchesMobile are changed to adapt the original
matches[Wifi|Mobile]Wildcard behavior.

Bug: 238843364
Test: FrameworksNetTests
Change-Id: I9e156b504ce4eb903b39279e443fad27bc921186
2022-12-28 18:49:37 +08:00
Aaron Huang
ee23c03121 Remove mSubscriberId from NetworkTemplate
Currently NetworkTemplate provides Builder for users to build a
template and it supports multiple subscriber ids. The mSubscriberId
is a local variable in current design so it can be removed from
NetworkTemplate and also can be removed from the parameter of a
constructor as long as the constructor is not annotated with
@UnsupportedAppUsage.

Bug: 238843364
Test: build, FrameworksNetTests
      CtsNetTestCases
Change-Id: Ic6a695e1c1719111bf26ba905a38673952a24736
2022-12-28 12:09:21 +08:00
Aaron Huang
4854d055bb Remove mSubscriberIdMatchRule from NetworkTemplate
Currently, mSubscriberIdMatchRule is only used in NetworkTemplate
and it depends on if mMatchSubscriberIds is empty or not. Thus,
remove it since is not really necessary and replace it with
checking matchSubscriberIds if needed.

Bug: 238843364
Test: build, FrameworksNetTests
      CtsNetTestCases
Change-Id: Ic66d2ff2826846778b004bb15a4718a62fa1f470
2022-12-28 12:09:09 +08:00
Yan Yan
67c7cd81a7 Merge changes I3dd45b29,Ic177015f
* changes:
  Require IPSEC_TUNNEL_MIGRATION feature flag to migrate transforms
  Support IPsec transform migration
2022-12-22 19:22:46 +00:00
Chalard Jean
d8ba034066 Rename isStrictMode to better names
"isStrictMode" is a poor name to set whether the private DNS
probe succeeded.

Test: ConnectivityServiceTest
Change-Id: I5d0d7ebabc5791b4b6cb7c1cce54b515d2e7e9d9
2022-12-22 08:25:16 +00:00
Yan Yan
a48dcd9d1f Require IPSEC_TUNNEL_MIGRATION feature flag to migrate transforms
Bug: 169169973
Test: atest IpSecServiceParameterizedTest (new tests added)
Change-Id: I3dd45b29163cd1e0cdbef08cb8aabdb629cf73bc
2022-12-21 23:12:48 +00:00
Yan Yan
e114b38f07 Support IPsec transform migration
This commit adds methods to support migrating tunnel mode
IpSecTransform to new source/destination addresses.

Bug: 169171001
Test: atest FrameworksNetTests (new tests added)
Change-Id: Ic177015fba5b62d3f73009633118109d3631086f
2022-12-21 23:12:35 +00:00
Lucas Lin
e0e9b0c701 Merge changes from topics "ADD_JVMOVERLOADS", "VPN_NETWORK_PREFERENCE"
* changes:
  Add HostsideVpnTests for testing setVpnDefaultForUids()
  Add CTS for ConnectivityManager#setVpnDefaultForUids()
  Create a new API to make a set of UIDs use only VPN by default
2022-12-21 01:13:47 +00:00
Maciej Żenczykowski
236013b328 Merge "wire bpf_base_test into netd_updatable_unit_test" 2022-12-20 18:36:15 +00:00
Maciej Żenczykowski
986fe9604b Merge "Ensure MTU is set for new interfaces." 2022-12-20 14:51:33 +00:00
Hansen Kurli
0425203152 Ensure MTU is set for new interfaces.
Setting the MTU for an interface should not be skipped when the
interface names are different. This occurs when a VPN network creates
a new interface with identical MTU.

Bug: 246398088
Test: atest ConnectivityServiceTest
Test: Manual test: Connect to VPN network and switch networks
Test: Confirm MTU of interface is set correctly with `adb shell ip addr`
Change-Id: I811a01feca2fb2130c57c6c924145314180434c5
2022-12-20 09:28:36 +00:00
lucaslin
cf52cee443 Add HostsideVpnTests for testing setVpnDefaultForUids()
The test will check if the VPN will be the only default network
for the app after ConnectivityManager#setVpnDefaultForUids() is
called.

Bug: 231749077
Test: atest CtsHostsideNetworkTests:HostsideVpnTests
Change-Id: I02758ad7d948342797b6a4b00dfec3acdf44775d
2022-12-20 09:02:15 +00:00
lucaslin
220332b9c5 Add CTS for ConnectivityManager#setVpnDefaultForUids()
This test checks
- If the NullPointerException will be thrown or not when the
  given uid ragnes is null.
- If the SecurityException will be thrown or not when the caller
  doesn't have related permission.

Bug: 231749077
Test: atest CtsNetTestCases
      atest CtsNetTestCasesLatestSdk
Change-Id: Ia1e625bc1f791ee9928ba00d76af9979ba52b2db
2022-12-20 06:57:01 +00:00
Maciej Żenczykowski
70d30ec49d wire bpf_base_test into netd_updatable_unit_test
The 3 pre-existing //system/netd tests are:
  TEST_F(BpfBasicTest, TestCgroupMounted)
  TEST_F(BpfBasicTest, TestTagSocket)
  TEST_F(BpfBasicTest, TestCloseSocketWithoutUntag)
which are directly related to BpfHandler.cpp implementation,
as it implements:
  Status BpfHandler::init(const char* cg2_path)
  BpfHandler::tagSocket()
  BpfHandler::untagSocket()

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1c01ae90904faaea54b427495c7a5deab8b1b900
2022-12-20 00:41:05 +00:00
Maciej Żenczykowski
c62bfff71b Merge "bpf_existence_test - add U support" 2022-12-19 19:10:12 +00:00
Treehugger Robot
9aa2315be1 Merge "remove TestTrafficControllerSetUp & TestSocketFilterSetUp" 2022-12-19 18:46:08 +00:00
lucaslin
3ba7cc25c0 Create a new API to make a set of UIDs use only VPN by default
Create a new API - setVpnNetworkPreference() for the caller to
set VPN as the preference network.

VPN will be disconnected when its underlying network is gone.
To prevent packets going through an underlying network when the
underlying network is back but VPN is not connected yet, set VPN
as the only preferred network for specific apps.

Bug: 231749077
Test: 1. atest FrameworksNetTests
      2. Create a test app to register default network and check if
         the VPN is the only default network for the test app.
Change-Id: Iabcd38e2fec2aefedbf78d20e338f222d83a9e7f
2022-12-19 05:35:04 +00:00
Maciej Żenczykowski
3b67343ddb remove TestTrafficControllerSetUp & TestSocketFilterSetUp
This is (as yet) dead code copied over from //system/netd,
but not yet plumbed into any p/m/C Android.bp file/test.

Update the bpf_shared.h include to netd.h now that that has been
renamed, see:
  https://android-review.git.corp.google.com/c/platform/packages/modules/Connectivity/+/2335387

MTS test bpf_existence_test.cpp already does a better job
of testing for bpf program/map existence, see
  MAINLINE_FOR_T_PLUS
  MAINLINE_FOR_T_4_14_PLUS

Test: N/A, this file is not yet compiled
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2ccfd86e352118f6f76e91ec20e10a9285414490
2022-12-18 20:30:32 +00:00
Maciej Żenczykowski
513474c1a7 rename bpf_shared.h to netd.h
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2e1569c8d70e98f9a3fdbab41fd2ba7f7b84dd37
2022-12-18 20:02:52 +00:00
Maciej Żenczykowski
2e4c752084 bpf_existence_test - add U support
The logic about testing API levels was wrong: it simply isn't
meaningful to say it doesn't support and needs to be updated for U+.

This test *always* needs to be kept up to date wrt. any changes
we make to mainline provided bpf programs and maps.

That's why the test is in the same git repo and is MTS not CTS.

Additionally we *can* make (and have made) changes to programs/maps
available on older API levels as well, so it's not even set in stone
for older API levels either.

Getting rid of the api level checks simplifies things.

As does moving the 4.9+ check into the test logic itself.
This has the added benefit of not skipping the test on S
simply because kernel is < 4.9 [not that's valid, but...].

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib0400f4534254b7a35a96d364720a7c800953456
2022-12-18 12:58:36 +00:00
Yan Yan
014d3f1314 Add owners for IPsec CTS
Test: Owners file changes only; no code changes
Bug: 262779843
Change-Id: Iec9fbfcdba4f033884b5f167931c4cfea12b43f8
2022-12-15 23:17:08 +00:00
Maciej Żenczykowski
438e4a8526 copy in bpf_base_test.cpp from system/netd
Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1bf320f838c7cc203dd72bc5b48aee92288bbb81
2022-12-15 22:16:09 +00:00
Treehugger Robot
c12fede943 Merge changes If187d023,I41c557d6
* changes:
  Add MdnsAnnouncer
  Also use other compressed names in DNS compression
2022-12-15 04:31:37 +00:00
chiachangwang
2ed983512c Rename getBypassable to isBypassable
Bug: 262336021
Bug: 256775913
Test: atest FrameworksNetTests
Change-Id: I5ac8f4f9a2a64189fc66d3c14af6da201a35e3e2
2022-12-15 04:22:43 +00:00
Remi NGUYEN VAN
a066e55bc5 Add MdnsAnnouncer
MdnsAnnouncer is a implementations of MdnsPacketRepeater, which sends a
packet at various intervals.

It will be used to send initial advertisements when a service is
registered or there is a network change.

Bug: 241738458
Test: atest
Change-Id: If187d023dd48d9b575431759cc6b67460bc0d33b
2022-12-15 10:56:15 +09:00
Remi NGUYEN VAN
e274170ac6 Also use other compressed names in DNS compression
The previous implementation of writeLabels would not include a
compressed name in the label dictionary, so if a packet had
"something.local", "a.service.local" and "b.service.local",
"service.local" would not be compressed because "a.service.local"
already used compression (for .local).

Fix this and add a test.

Bug: 254166302
Test: atest
Change-Id: I41c557d6debd11acb4c0813735ef7af7323f45d7
2022-12-15 10:49:57 +09:00
Remi NGUYEN VAN
df91219a9b Merge changes I9cd2b861,I4e5f779b
* changes:
  Use compression for mDNS NSEC record data
  Add MdnsProber
2022-12-15 01:41:58 +00:00
Junyu Lai
cccbc497e3 Merge "Ensure default network before testing" 2022-12-14 10:14:53 +00:00
Junyu Lai
52405f7f66 Ensure default network before testing
The testBlockedStatusCallback will get the default network,
and use it to verify upcoming callbacks. However, sometimes
the wifi network will be disconnected by previous executed
tests and becoming connected during the test, and fail the
test.

Thus, ensure wifi is the default network if it is supported
before testing.

Test: atest CtsNetTestCases:android.net.cts.ConnectivityManagerTest#testBlockedStatusCallback \
      --rerun-until-failure 200
Fix: 260560020
Change-Id: Icd79005dbcf5966beb2f2caf271a32b3f772f475
2022-12-14 14:13:14 +08:00
Remi NGUYEN VAN
f1fdca69a5 Use compression for mDNS NSEC record data
Although RFC3845 2.1.1 specifies that NSEC records should not use
compression for the Next DomainName field, RFC6762 18.14 specifies that
compression should also be used for NSEC RDATA. The legacy mDNS
implementation does use compression for that field.

Bug: 241738458
Test: atest
Change-Id: I9cd2b8618b01bb569a7f1d13dc3bfd09a0433300
2022-12-14 11:36:56 +09:00
Remi NGUYEN VAN
3568fddb36 Add MdnsProber
MdnsProber is an implementation of MdnsPacketRepeater that will be used
to send probes for service names before advertising them, to know if
they are already in use.

Bug: 241738458
Test: atest
Change-Id: I4e5f779b891e2c665ba7f752fb5fbd4255070725
2022-12-14 11:36:55 +09:00
Chiachang Wang
9185577397 Merge "Add areLongLivedTcpConnectionsExpensive in VpnTransportInfo" 2022-12-14 00:55:38 +00:00
chiachangwang
a07cef1059 Add areLongLivedTcpConnectionsExpensive in VpnTransportInfo
Add VpnTransportInfo.areLongLivedTcpConnectionsExpensive() in API
surface to allow privileged apps to know whether the long-lived
TCP connections should be expensive in the VPN network.

This is expected to be used combined with getBypassable()
because connections should always go through a VPN that is not
bypassable.

Bug: 259000745
Test: atest FrameworksNetTests
Change-Id: Ic9bcdf43f252f22d12a1136902cc8bbf9cc731f5
2022-12-13 10:15:49 +00:00
Hansen Kurli
edbf34a182 Merge "Add unit tests checking MTU of interfaces are set." 2022-12-13 07:01:19 +00:00
Shubhangi Pawar
c4b72b9583 Merge "Acquire a wakelock before sending KEYCODE_SLEEP" into android13-tests-dev am: 51413173f0
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2300101

Change-Id: I0cde428b1a6a704039b340ccfe9de5008ecf54fa
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-12-13 00:52:52 +00:00
Shubhangi Pawar
51413173f0 Merge "Acquire a wakelock before sending KEYCODE_SLEEP" into android13-tests-dev 2022-12-13 00:16:21 +00:00
Paul Hu
d78cda2ba8 Merge changes Icd842479,I2206a846
* changes:
  Add MdnsInterfaceSocket and MdnsSocketProvider
  Put the Network info in MdnsServiceInfo
2022-12-12 08:16:23 +00:00
Paul Hu
2f1de80315 Add MdnsInterfaceSocket and MdnsSocketProvider
MdnsInterfaceSocket: using for listening the multicast
socket on specific interface.

MdnsSocketProvider: using for creating and managing the
multiple multicast sockets.
- Listen NetworkCallback and TetheringEventCallback to know the
  network connected / disconnected changes. And use the callbacks
  to create / remove the sockets for mdns discovery

Bug: 254166302
Test: atest FrameworksNetTests
Change-Id: Icd8424792e89e71198fa31f9ec92e1ec8172128d
2022-12-12 08:15:38 +00:00
Hansen Kurli
3597deb5e1 Merge "Disconnect network when captive portal returns unwanted." 2022-12-12 06:43:01 +00:00
Paul Hu
9e53b630c5 Put the Network info in MdnsServiceInfo
In Nsd, every request has Network info to assign the specific
network to do the mdns query. But the response MdnsServiceInfo
only has interface index which is not very useful and need to
transfer to a Network every time when using it because most
APIs for apps to use the network are based on Network object.
Thus, put the Network info into MdnsServiceInfo.

Bug: 254166302
Test: atest FrameworksNetTests
Change-Id: I2206a84636981fc7d9aa9deda0f18f60642bc7d7
2022-12-09 14:42:44 +08:00
Hansen Kurli
8d267d8998 Add unit tests checking MTU of interfaces are set.
Unit tests covering the different possible cases of calls to updateMtu.

Bug: 246398088
Test: atest ConnectivityServiceTest
Change-Id: Iced44c00e9dbe944c3a31bbf1da88f8077e4379a
2022-12-08 12:00:35 +00:00
Chris Ye
07718da004 Merge "Add polling for WifiManager#getConnectionInfo" 2022-12-08 07:10:06 +00:00
Lucas Lin
dc824e95de Merge "Verify that the underlying network info will be cleared/sent or not" 2022-12-08 05:30:47 +00:00
Lucas Lin
678113ade7 Merge "Correct the test design for network lost case" 2022-12-08 03:25:05 +00:00
lucaslin
d1938dffce Verify that the underlying network info will be cleared/sent or not
Add some checks to verify that the underlying network info will
only be cleared when the underlying network is lost, or will only
be sent when the category is not CATEGORY_EVENT_DEACTIVATED_BY_USER
and CATEGORY_EVENT_ALWAYS_ON_STATE_CHANGED.

Bug: 237050331
Test: atest FrameworksNetTests:VpnTest
Change-Id: Ifc66658cf59481c4a9804e6933be1048f758b698
2022-12-07 09:47:38 +00:00
lucaslin
0b915e2012 Correct the test design for network lost case
For network lost case, the process should be triggered by calling
onLost() instead of triggering onClosedWithException() directly.

Bug: 237050331
Test: atest FrameworksNetTests:VpnTest
Change-Id: I32781d4ac96ee8212d1fd7ba23009293f72b442e
2022-12-07 09:42:22 +00:00
Leon Li
fe3cd519a3 Acquire a wakelock before sending KEYCODE_SLEEP
To prevent device testing via ADB over ethernet entering standby mode,
acquire a wake lock before sending KEYCODE_SLEEP to device.

We might lose connection when device entering standby mode, end up fail the test.

Test: atest com.android.cts.net.HostsideRestrictBackgroundNetworkTests#testDozeModeNonMetered_whitelisted

Bug: 233154541

Change-Id: I09e0af35d32a8001913d3414c0c41ffbb10ace3d
Merged-In: Icb28d2db6f25bd12ba00f56e5d6e56fa108bdcbd
2022-12-07 08:08:37 +00:00
Paul Hu
3b1703007e Merge "Add onServiceNameDiscovered/onServiceNameRemoved" 2022-12-07 02:00:33 +00:00
Mark Chien
7e60552183 Merge "Increased the timeout from 5 to 30 seconds" 2022-12-06 14:53:44 +00:00
Paul Hu
0ee75422c9 Add onServiceNameDiscovered/onServiceNameRemoved
Add onServiceNameDiscovered method which is used to listen the
discovery callbacks. It would be called once the service is found
even the response is incomplete. This is different from
onServiceFound which needs to receive a complete response.

onServiceNameRemoved is used for service removal if received
response is incomplete.

Bug: 254166302
Test: atest FramworksNetTests
Change-Id: I03313b045d74bb65f7fe6ac93673f02ce3b2c664
2022-12-06 10:29:26 +00:00