Commit Graph

1639 Commits

Author SHA1 Message Date
Steven Moreland
f85847c137 Remove toString test.
This is not a stable format.

Bug: 285376559
Bug: 265470635
Test: N/A
Change-Id: I15b58ff7a50f9f1acc3d5e8f86f9272855183870
2023-06-01 21:34:50 +00:00
Treehugger Robot
ae9b229b7e Merge "Add MdnsDiscoveryManager constructor without looper" 2023-05-30 10:24:27 +00:00
Yuyang Huang
243d1a5de4 Add MdnsDiscoveryManager constructor without looper
In some use cases for the MdnsDiscoveryManager, providing looper as an
argument to the MdnsDiscoveryManager constructor is not feasible. Adding
a constructor without looper can help to match those use cases. If
constructor without looper is used. The shutDown() must be called as a
part of cleanup process.

Bug: 283914408
Test: atest FrameworksNetTests
Change-Id: I0ab04d67bae127628c6d67c4b8c109201612a54b
2023-05-30 17:14:54 +09:00
Jean Chalard
5cc9676d4c Merge "Instrument SDK level and change IDs to help testing" 2023-05-30 02:10:05 +00:00
Chalard Jean
df29a85ee7 Instrument SDK level and change IDs to help testing
This patch mocks the SDK level and/or change IDs to help
developing functionality that depends on these without
having to flash a new device every time.

Test: TH
Change-Id: I1011193c99e123a0e5501ed313c9cecbceebdae6
2023-05-29 18:42:31 +09:00
Remi NGUYEN VAN
f4cf2707e7 Merge "Do not process null network packets on all clients" 2023-05-29 03:56:26 +00:00
Remi NGUYEN VAN
5a1c614e42 Merge "Only send to downstream ifaces for null network" 2023-05-29 03:56:20 +00:00
Remi NGUYEN VAN
401ab44c36 Merge "Use the ServiceTypeClient network for queries" 2023-05-29 03:56:12 +00:00
Remi NGUYEN VAN
0ba206cbd1 Do not process null network packets on all clients
Packets received from the "null" networks are packets received from
tethering downstream interfaces. They should not be processed by all
MdnsServiceTypeClients; instead they should be processed by
the MdnsServiceTypeClient for the null network.

Bug: 283708537
Test: atest
Change-Id: Ifef59eca7a24bdfe3650067445d2565869dfa852
2023-05-24 16:37:13 +09:00
Remi NGUYEN VAN
87c374a37a Only send to downstream ifaces for null network
When sendMulticastPacket or sendUnicastPacket is called with the null
network, only send the packets to interfaces indexed with null, instead
of all interfaces.

When using MdnsMultinetworkSocketClient sending packets on the null
network means sending on tethered downstream interfaces. When
MdnsSocketClient is used (not used in the Android tree), sending on the
null network sends on all interfaces as MdnsSocketClient does not
support specific networks. This is clarified by explicitly throwing
when a non-null Network is attempted to be used with MdnsSocketClient
(but MdnsSocketClient is only used for tests in the Android tree).

Bug: 283708537
Test: atest
Change-Id: Ia0186bf8aa2e0fc5878d6071fd23599df8488616
2023-05-24 14:30:14 +09:00
Chiachang Wang
3fabc1b0e0 Merge "Cleanup VpnTest for unused methods/annotations" 2023-05-24 01:41:01 +00:00
Chiachang Wang
b1f3dd9dd1 Merge "Test for not logging meaningless caps changes" 2023-05-24 01:40:34 +00:00
Chalard Jean
74732ba43d Cleanup VpnTest for unused methods/annotations
• Remove unused private methods
• Build files have this test in FrameworksNetTests, which
  by TEST_MAPPING is not run on T and below. It is not in
  the targets that do run on T and below like
  ConnectivityCoverageTest.

Test: VpnTest
Change-Id: I198e5b3571e34e41611f71d351501d3f98f78caa
2023-05-23 18:30:05 +09:00
Chalard Jean
16e41d130c Test for not logging meaningless caps changes
Test: this
Change-Id: Ife6500daae58b7f85a7f4c76cd89ce91def5e78c
2023-05-23 18:30:04 +09:00
Treehugger Robot
7be7f06fc4 Merge "Use "don't actively prefer" timeout when avoiding bad wifi" 2023-05-23 06:47:18 +00:00
Chalard Jean
6f6c353baf Use "don't actively prefer" timeout when avoiding bad wifi
Test: ConnectivityServiceTest
Change-Id: I6e99aff77c55805630d878e472f466bd31bba360
2023-05-23 13:47:15 +09:00
Yuyang Huang
9d778c7fe7 Delete the LinkAddress in cache when RTM_DELADDR is received
The addOrUpdateInterfaceAddress() should be called when RTM_NEWADDR
message is received and the address isPreferred. The
deleteInterfaceAddress() should be called when RTM_DELADDR is called.

Bug: 282592527
Test: atest MdnsSocketProviderTest
Change-Id: I06a5940f53d01552f117309b1cc09256a2a9fae7
2023-05-22 17:17:27 +09:00
Remi NGUYEN VAN
404c1bf787 Use the ServiceTypeClient network for queries
Instead of the network specified in the MdnsSearchOptions, which is
often null to request searching on all networks, use the
MdnsServiceTypeClient Network to build the queries.

When MdnsSearchOptions.network is null, one MdnsServiceTypeClient is
created for each mDNS-compatible Network. Each MdnsServiceTypeClient
schedules queries with a Network selector. If the Network selector is
null, each MdnsServiceTypeClient will post its queries to all networks.
Instead, it should be the Network of the MdnsServiceTypeClient.

There is one remaining problem when a tethered interface is up: in that
case, there will be one MdnsServiceTypeClient for tethered interfaces
with a null network, which will still broadcast its queries to all
networks. This should be addressed in a follow-up by having
MdnsMultinetworkSocketClient only send queries to interfaces that have a
null network, when the network selector is null (and not all
interfaces).

Bug: 283708537
Test: atest
Change-Id: If571d7a59c5e55d809eeb1f3d1c4b58684612cdd
2023-05-22 14:49:59 +09:00
Motomu Utsumi
404636629a Merge "Revert ConnectivityServiceDependencies access modifier" 2023-05-18 05:54:32 +00:00
Motomu Utsumi
d54120344d Revert ConnectivityServiceDependencies access modifier
Address review comment on aosp/2490881

ConnectivityServiceDependencies was made public in aosp/2490881 to
verify destroyLiveTcpSockets call.
This CL reverts that change and updates tests to use mocked
DestroySocketsWrapper to verify destroy sockets call.

Bug: 270298713
Test: atest FrameworksNetTests
Change-Id: I101016399ea29bc5176b7559edf0447f0f7901ce
2023-05-18 12:31:44 +09:00
Motomu Utsumi
ec4511c8aa Merge "Fix agents disconnecting in SUSPENDED state." 2023-05-17 01:59:18 +00:00
Motomu Utsumi
d15b397606 Merge "Check clatd does not stop when suspended network is disconnected" 2023-05-16 08:50:06 +00:00
Paul Hu
d0ebd7023f Merge changes from topic "MdnsDM_running_on_looper_thread"
* changes:
  Pass NsdService thread looper to MdnsDiscoveryManager
  Ensure MdnsDiscoveryManager calls to ServiceTypeClients on looper thread
2023-05-16 08:46:13 +00:00
Yuyang Huang
c61c5788fe Merge "Use case-insensitive matching in discovery/advertising" 2023-05-16 07:56:21 +00:00
wangshengrjxtjcb
fd5d3d90e1 Fix agents disconnecting in SUSPENDED state.
Network state is not changed to disconnected when a networkagent
is disconnected and network state is SUSPENDED.

So the function requiresClat return true. Clat is not stoped.

Bug: 277682237
Test: atest FrameworksNetTests

Change-Id: I5edfcf64aca5d2d34325d722dd29fab41bcf2600
2023-05-16 16:35:03 +09:00
Paul Hu
7f0af78c5e Pass NsdService thread looper to MdnsDiscoveryManager
MdnsDiscoveryManager should use the same thread that create on
NsdService that is used on other mDns components. Thus, pass that
thread loop to MdnsDiscoveryManager.

Bug: 265787401
Test: atest FrameworksNetTests
Change-Id: Icc23994c3ebc99da6043ed2d93540c44f53a150b
2023-05-16 14:39:09 +08:00
Paul Hu
bd4140ea91 Ensure MdnsDiscoveryManager calls to ServiceTypeClients on looper thread
ServiceTypeClients will store/access services on MdnsServiceCache
in subsequent changes. And MdnsServiceCache can be accessed from
looper thread only. So ensure MdnsDiscoveryManager calls to
ServiceTypeClients on the looper thread.

Bug: 265787401
Test: atest FrameworksNetTests
Change-Id: I05e73140da58c029b49057bb0ccfdb8ed7818dfc
2023-05-16 14:38:36 +08:00
Motomu Utsumi
4a5b06559f Check clatd does not stop when suspended network is disconnected
Currently, clatd is not stopped when suspended network is disconnected
and aosp/2583410 fixes this issue.
This CL adds test for current behavior, aosp/2583410 can update
testDisconnectSuspendedNetworkStopClatd to call verifyClatdStop instead
of verifyNeverClatdStop

Test: atest FrameworksNetTests
Bug: 277682237
Change-Id: I345e097ce8e114800d77c5f44d38d7ae4938935c
2023-05-16 12:32:52 +09:00
Yuyang Huang
73772f325d Use case-insensitive matching in discovery/advertising
mDNS is supposed to be case-insensitive (like DNS). Both advertising and
discovery logic should use case-insensitive matching instead of
case-sensitive matching.

The case sensitive matching can be found by grepping the String.equals()
and Arrays.equals() check across the whole code base. Each occurrence is
analyzed carefully to list up all necessary fixes.

Bug: 272194544
Test: atest FrameworksNetTests
Change-Id: I7c10878129663549c9171c1420b6f399930df2cb
2023-05-16 11:50:07 +09:00
Remi NGUYEN VAN
3d66b0432d Stop MdnsServiceTypeClient send on socket destroy
MdnsServiceTypeClient should stop sending when it is removed due to its
socket being destroyed.

On null networks (downstream interfaces) that may have multiple sockets,
this should only happen once the last socket used by the (null) network
has been destroyed.

Bug: 278635632
Test: atest
Change-Id: Ie1808840bd68678f2af7b71bdd8f3be377c14424
2023-05-16 10:45:36 +09:00
Remi NGUYEN VAN
5fe9bacc63 Do not send socket destroyed on unregistration
When a SocketCallback is unregistered from MdnsSocketProvider, do not
send socket destroyed callbacks. Callers may not expect getting
callbacks after unregistration, and the current callbacks are also
broken when an unrequested socket is still in use by another requester.

MdnsAdvertiser already does not depend on getting this callback, as it
only unregisters the SocketCallback after it is done using the socket.
This change fixes MdnsMultinetworkSocketClient to destroy the socket by
itself when unrequesting.

Bug: 276177548
Test: atest
Change-Id: If95f833e293f3aab91128aab1c9852ebfd41995d
2023-05-15 17:52:22 +09:00
Treehugger Robot
4bcc151bf4 Merge "Do not immediately send new queries on cache hit" 2023-05-12 14:50:09 +00:00
Remi NGUYEN VAN
94a4149a8f Merge changes I09e780af,I21367c66
* changes:
  Implement proper subtype advertising
  Implement proper discovery with subtypes
2023-05-12 13:31:19 +00:00
Motomu Utsumi
179d18b3ad Merge changes from topic "firewall_socket_destroy"
* changes:
  Close sockets from ConnectivityService#setFirewallChainEnabled
  Add test to verify socket close when firewall is enabled
2023-05-12 09:18:40 +00:00
Remi NGUYEN VAN
58bb0a129a Do not immediately send new queries on cache hit
If a listener request is fulfilled immediately from cache, do not
restart queries immediately, but just schedule the next run.

This avoids doubling the number of queries when discovery, then resolve
is requested.

Bug: 281793453
Test: atest
Change-Id: Ibe41ee20427068a1ccdbc1f04525988a89a58899
2023-05-12 16:23:28 +09:00
Remi NGUYEN VAN
ce44beb7aa Implement proper subtype advertising
Implement subtype advertising by advertising an additional PTR record if
subtype advertising was requested.

For an advertiser a subtype is just an additional PTR record, so this
just involves plumbing the subtype down to MdnsRecordRepository, which
includes the additional record in the service registration.

Bug: 266167702
Test: atest
Change-Id: I09e780af25149162f16bd75410ddc50f160a0dab
2023-05-12 13:34:27 +09:00
Remi NGUYEN VAN
f2d064112c Implement proper discovery with subtypes
Apps may want to discover a particular subtype, such as
_color._sub._printer._tcp.local, which may return services like
Printer1._printer._tcp.local. The previous code was trying to discover,
and would return service types named _color._sub._printer._tcp.local,
even though the actual service type is still _printer._tcp.local. This
is a regression compared to S/T.

Fix this by passing the subtype to MdnsDiscoveryManager in its options
instead of the service type, and ensure that MdnsDiscoveryManager only
sends callbacks to callers that have requested the given subtype (a
color that asked for _color._sub._printer._tcp.local should not receive
BlackAndWhite._printer._tcp.local).

Bug: 266167702
Test: atest
Change-Id: I21367c66534078667718a9b54dfc858b12ba7103
2023-05-12 13:29:20 +09:00
Remi NGUYEN VAN
2f82fcdd6c Ensure service type ends with a dot in discovery
Historical behavior of onServiceFound is to include a dot at the end of
the service type. To avoid inconsistencies between behavior of new and
older backend, which would be hard to predict/handle for apps, ensure
that the same format is used. This means a dot must be added when using
the new backend.

Implement this by creating the callback service types based on
MdnsServiceInfo obtained from MdnsDiscoveryManager, rather than the
service type that was provided by the calling app. This avoids
inconsistencies as the calling app may or may not include dots
originally, and it may use subtypes ("_sub._type._tcp.local" or even
"_type._tcp.local,_sub"), which would result in callbacks giving invalid
service types, or inconsistent with S/T behavior.

Fixes: 281776253
Test: atest
Change-Id: I677ee885d1ee8e6a09773f21e4dd53e96faee748
2023-05-12 10:35:36 +09:00
Paul Hu
6f47b7d501 Merge "Remove the ServiceTypeClient after socket destroyed" 2023-05-11 11:50:57 +00:00
Paul Hu
f2a51ac5f8 Remove the ServiceTypeClient after socket destroyed
The ServiceTypeClient should be removed after socket destroyed
because it's no longer used by any request. The requests will be
matched to the newly created ServiceTypeClient.

Bug: 278635632
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: Ia917b14d3666f3bfe8e874606a34800a4ce65c5a
2023-05-11 15:17:21 +08:00
Lorenzo Colitti
18cdec34dd Merge "Immediately create native networks when NetworkAgents register." 2023-05-11 03:35:21 +00:00
Motomu Utsumi
d44a33adb9 Close sockets from ConnectivityService#setFirewallChainEnabled
And replace netd.socketDestroy by Java implementation

Bug: 270298713
Test: atest FrameworksNetTests CtsNetTestCases
Change-Id: I0e200247ca010f9649254eeaac02740bd2bfdb21
2023-05-11 12:22:09 +09:00
Paul Hu
3e497c7b1e Merge "Use a single SharedLog for all mdns components" 2023-05-11 00:45:18 +00:00
Mark Fasheh
2d626e5632 Merge "Optionally have ConnectivityService kill sockets for frozen apps" 2023-05-10 23:08:00 +00:00
Mark Fasheh
7c999d8d4c Optionally have ConnectivityService kill sockets for frozen apps
To do this we register a UidFrozenStateChangedCallback with
ActivityManager. The callback then queues up work on the Handler thread
to consume the original callback args and kill appropriate sockets.

Test: atest ConnectivityServiceTests
Bug: 277100090
Change-Id: I93f174811aef726145a18ea90443ddfc1456478e
2023-05-10 21:04:54 +00:00
Lorenzo Colitti
4f87aa3f13 Immediately create native networks when NetworkAgents register.
Currently, native networks for non-VPN networks are created only
when the NetworkAgent goes into the CONNECTED state. This is not
ideal, because until the network is connected:

- Nothing routes to the network, so no IP packets can be sent on
  it (except via packet sockets).
- Many network configuration changes (e.g., routes and DNS
  servers) fail to apply because the network does not exist yet.
  These cause ENONET errors in the logs.

Fix this starting in U by creating the native network as soon as
the agent registers. This should not impact apps because
NetworkCallbacks are not sent until networks are connected.

Bug: 143158421
Test: new coverage in NetworkAgentTest
Change-Id: I26bfa8630c085422175558645c47a6c64be96ae6
2023-05-10 20:01:07 +09:00
Junyu Lai
598ca1e284 Merge "Fix template for test network needs fine location permission" 2023-05-10 02:22:18 +00:00
Paul Hu
14667deefa Use a single SharedLog for all mdns components
Use a single SharedLog in NsdService, and making subcomponents
for DiscoveryManager/Advertiser/SocketProvider. Because each
logger has 500 maxRecords, so 2000 records in total, which take
too much memory.

Also address leftover comments in previous logging changes.

Before:
  2023-04-17T15:05:27.409895 - [Client10082-1] Register a DiscoveryListener 3 for service type:_nmt274981618._tcp.local
  2023-04-17T15:05:26.408015 - [Client10082-1] New client. useJavaBackend=true

Advertiser:
  2023-04-17T15:05:27.213023 - [testtap0] Probing finished for service 2
  2023-04-17T15:05:26.409607 - Adding service name: ^Nsd.Test|Non-#AsCiI\Characters&\ufffe テスト 測試, type: _nmt274981618._tcp, hostAddresses: , port: 12345, network: null, txtRecord:  with ID 2

DiscoveryManager:
  2023-04-17T15:05:28.227786 - [_nmt274981618._tcp.local-102] onServiceNameDiscovered: ^Nsd.Test|Non-#AsCiI\Characters&\ufffe テスト 測試
  2023-04-17T15:05:27.409104 - createServiceTypeClient for serviceType:_nmt274981618._tcp.local network:102
  2023-04-17T15:05:27.398075 - Registering listener for serviceType: _nmt274981618._tcp.local

SocketProvider:
  2023-04-17T15:05:28.292106 - Remove socket on net:102
  2023-04-17T15:05:26.441517 - Create socket on net:NetworkAsKey{ network=102 }, ifName:testtap0
  2023-04-17T15:05:26.409005 - Start monitoring sockets.

After:
Logs:
  2023-04-17T20:51:42.931769 - [MdnsDiscoveryManager._nmt682015268._tcp.local-101] onServiceNameDiscovered: Name: ^Nsd.Test|Non-#AsCiI\Characters&\ufffe テスト 測試, type: _nmt682015268._tcp.local, subtypes: , ip: [100.70.162.138], ipv6: [fe80::9c0e:d0ff:fe7d:e5aa, 2a00:79e1:abc:6f04:9c0e:d0ff:fe7d:e5aa, 2a00:79e1:abc:6f04:eb56:8e39:5e1f:1102], port: 12345, interfaceIndex: 47, network: 101, textStrings: [], textEntries: []
  2023-04-17T20:51:42.032465 - [NsdService.Client10082-1] Register a DiscoveryListener 3 for service type:_nmt682015268._tcp.local
  2023-04-17T20:51:42.026645 - [MdnsDiscoveryManager] createServiceTypeClient for type:_nmt682015268._tcp.local, net:101
  2023-04-17T20:51:41.091555 - [MdnsAdvertiser] Adding service name: ^Nsd.Test|Non-#AsCiI\Characters&\ufffe テスト 測試, type: _nmt682015268._tcp, hostAddresses: , port: 12345, network: null, txtRecord:  with ID 2
  2023-04-17T20:51:41.091037 - [MdnsSocketProvider] Start monitoring sockets.
  2023-04-17T20:51:41.089951 - [NsdService.Client10082-1] New client. useJavaBackend=true

Bug: 275004614
Test: atest FrameworksNetTests android.net.cts.NsdManagerTest
Change-Id: I1c9b7697cc95748f7fe4e6beecea217d39c56fb1
2023-05-10 02:18:43 +00:00
Paul Hu
49078d7b0f Merge "Process all responses if the network is null in MdnsServiceTypeClient" 2023-05-09 10:23:24 +00:00
Paul Hu
bdf82a2aa0 Process all responses if the network is null in MdnsServiceTypeClient
If the network is null in MdnsServiceTypeClient, it should use
MdnsSocketClient for single socket only. So it's expected to
process any response from only the socket (network).

Move the stopDiscovery outside the listener check loop.
Because the stop should only be called once.

Add a test to verify the response processing with a non-null
network MdnsServiceTypeClient

Bug: 265787401
Test: atest FrameworksNetTests
Change-Id: I76965302037f050e0ac3b2cfdbaa5a855e2283c7
2023-05-09 15:19:29 +08:00