Commit Graph

1675 Commits

Author SHA1 Message Date
Chiachang Wang
c42f1adfd5 Merge "[DK1]Add TCP polling mechanism" 2023-01-17 13:04:04 +00:00
chiachangwang
6a9f0db983 [DK1]Add TCP polling mechanism
Add TCP polling mechanism in KeepaliveTracker to understand if
there are any TCP sockets in the target network. This is a
preparation commit for dynamically control keepalive based on
the existence of TCP sockets. This is non-functional now since
there is no caller to retrieve the information now.

Bug: 259000745
Test: atest FrameworksNetTests
Test: Manually test by creating TCP sockets on the target network
      in device and check if deisgn works.
Change-Id: I355ac340cad2fac618bb9d65fb1b1539ea644959
2023-01-17 07:24:48 +00:00
Paul Hu
03a51d5674 Move mDNS code to service-connectivity-t
Instead of using a separate service-mdns library, move the code to
service-connectivity-t.

service-connectivity-t is chosen because it has access to hidden API of
classes that were made updatable in T, such as NsdServiceInfo and
NsdManager. mdns code can be there as it is only loaded on T+.

Bug: 241738458
Test: atest
Change-Id: I7eb6c9ab8bf0e0a614ea2994c6ed80a1a780241f
2023-01-13 16:42:48 +08:00
Remi NGUYEN VAN
73990178e5 Merge "Add unit tests for probing" 2023-01-13 04:05:46 +00:00
Paul Hu
6ea0c1d05b Merge "Add MdnsMultinetworkSocketClient" 2023-01-13 03:58:19 +00:00
Remi NGUYEN VAN
1373b36bf7 Merge "Implement service add, remove, and probing" 2023-01-13 01:51:16 +00:00
Remi NGUYEN VAN
65df28291a Merge "Remove PacketRepeater destinationsSupplier logic" 2023-01-13 01:51:07 +00:00
Remi NGUYEN VAN
5e5393ffde Add unit tests for probing
Add tests for MdnsRecordRepository and MdnsInterfaceAdvertiser
implementations of probing.

Bug: 241738458
Test: atest
Change-Id: If41a387f14e805e81b6d0d8217d081ca053e340f
2023-01-12 19:36:43 +09:00
Remi NGUYEN VAN
42282ecc8b Implement service add, remove, and probing
Add MdnsRecordRepository to hold ServiceRegistration records. When a
service is added, the repository generates its records, and can generate
the ProbingInfo to use to send initial probes.

Implement MdnsInterfaceAdvertiser addService/removeService based on that
logic.

Bug: 241738458
Test: atest
Change-Id: Idcc3ee8b9781a20eda57cd656252acab5e822f83
2023-01-12 19:36:41 +09:00
Jean Chalard
526df99b53 Merge "Apply "most-recent" delivery policy to CONNECTIVITY_ACTION." 2023-01-12 06:37:26 +00:00
Paul Hu
637d9833f8 Add MdnsMultinetworkSocketClient
Add MdnsMultinetworkSocketClient which is using for managing
multinetwork for discovery and resolution. If the requests are
specified the network to do the discovery or resolution, it
should send the queries and receive the responses on the active
networks only. This can save the resource by reducing unnecessary
queries and align the behavior with mdnsresponder.

Bug: 254166302
Test: atest FramworksNetTests
Change-Id: I9f49ac11e70cb945f9a90efc5eb684be87801286
2023-01-12 00:47:46 +08:00
Remi NGUYEN VAN
49ae3f0d51 Remove PacketRepeater destinationsSupplier logic
PacketRepeater can just try to send to both v4 and v6 multicast
addresses, and rely on MdnsReplySender to check whether the sockets have
(automatically) joined the v4 or v6 groups, so there is no need to use
this unusual lambda setup anymore.

Bug: 264947218
Test: atest MdnsProberTest MdnsAnnouncerTest
Change-Id: I09e0fa4bf14e1f31f2d2508f17e23adf1415feb7
2023-01-11 18:47:35 +09:00
Junyu Lai
73bf06f6b5 Merge "Enterprise slicing for profile blocking default" 2023-01-11 07:23:58 +00:00
Remi NGUYEN VAN
125ff06cba Merge "Add MdnsAdvertiser" 2023-01-11 05:45:32 +00:00
Junyu Lai
35665cc887 Enterprise slicing for profile blocking default
Test: atest ConnectivityServiceTest#testProfileNetworkPreferenceBlocking_networkChanges \
      ConnectivityServiceTest#testProfileNetworkPreferenceBlocking_changePreference \
      --rerun-until-failure 100
Bug: 263219497

Change-Id: Idbda582542bcabf0156e2bab9f8bea42fc908cae
2023-01-11 10:47:00 +08:00
Remi NGUYEN VAN
314db00b3f Add MdnsAdvertiser
MdnsAdvertiser takes requests to advertise services on given Networks,
and relays them to internal maps of MdnsInterfaceAdvertisers.
SocketProvider is used to create the sockets for the requested networks.

It also ensures that added services do not have name conflicts, as
registration of one service should use the same name on all interfaces,
so any conflict means that every MdnsInterfaceAdvertiser needs to use a
different name. Names are automatically updated with a number suffix
(like "service (2)", "service (3)"), similarly to the legacy
mdnsresponder implementation.

The implementatio of MdnsInterfaceAdvertiser will be added in a
different change.

Bug: 241738458
Test: atest

Change-Id: I21aa93c681dd179b9d6ec425bc0f247a10ba5b0b
2023-01-10 22:04:05 +09:00
Sudheer Shanka
2453a3ada2 Apply "most-recent" delivery policy to CONNECTIVITY_ACTION.
This allows us to skip any older CONNECTIVITY_ACTION broadcasts
waiting to be delivered when a new broadcast is dispatched.

Bug: 255545931
Test: TH
Change-Id: Iac5da2f727e295d1775bfe91358900f316258be4
2023-01-09 03:21:44 +00:00
Maciej Żenczykowski
e7ebb15424 check for U+ before checking device feature flags
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I12e147e61febd96324cdbb6642e0894e5c399526
2022-12-27 10:57:59 +00:00
Maciej Żenczykowski
bdf970240e switch DscpPolicyTracker from U32 to S32
In practice these are tiny indexes into a small array, see:
  packages/modules/Connectivity/bpf_progs/dscpPolicy.h
  #define MAX_POLICIES 16
So there is no need to complicate things...

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iac3ddd3fc726b1643b1aad42e40f97ea12cebf29
2022-12-22 00:17:21 +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
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
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
Igor Chernyshev
483a8a8aeb Merge "Ignore incorrect NewApi Lint warning for CDM getAllAssociations()" 2022-12-19 02:26:19 +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
Igor Chernyshev
fd05937f52 Ignore incorrect NewApi Lint warning for CDM getAllAssociations()
CDM.getAllAssociations() is made public (was SystemApi)
and linter will wrongly flag it as [NewApi] so we have to
update the RequireApi and add a SuppressLint.

Bug: 245972418
Bug: 193460475

Tag: #feature

Test: presubmit
Change-Id: Ia0f3f13f648fd3744df0296eb4dead0bbedf46f9
2022-12-16 16:44:27 -08:00
Igor Chernyshev
9dac660bf0 Add CDM dependency in Tethering
This change introduces a limited library for dependencies on
framework-connectivity from Tethering,
connectivity-internal-api-util, where all classes are annotated with
@RequiresApi(S) to ensure proper API checks are done before usage.

Bug: 245972418

Change-Id: I82bafd9063341adc71d07f0858e6d68283d081f0
2022-12-16 17:55:53 +00:00
Treehugger Robot
a2f9fe6b21 Merge "Make ProfileNetworkPreferenceList generic" 2022-12-15 08:59:52 +00:00
Chalard Jean
0606fc83a6 Make ProfileNetworkPreferenceList generic
This will be useful for VPN profile preferences.

Change-Id: Id3b7d57d29d32ff9e1fcd410f55148b3c85b1a7c
Test: FrameworksNetTests
      CtsNetTestCases
      FrameworksNetIntegrationTests
      NetworkStackTests
      NetworkStaticLibTests
      TetheringTests
      MtsTetheringTestLatestSdk
      TetheringIntegrationTests
Bug: 262482087
2022-12-15 06:08:03 +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
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
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
Frank Li
fee29c5c09 Merge "Revert "Remove the stats protos from ConnectivityService until tests are added"" 2022-12-08 07:09:41 +00:00
Motomu Utsumi
ae4431aadc Merge "Enable java bpf map always in U devices" 2022-12-07 07:29:54 +00:00
Paul Hu
3b1703007e Merge "Add onServiceNameDiscovered/onServiceNameRemoved" 2022-12-07 02:00:33 +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
Motomu Utsumi
0e9c379c3e Enable java bpf map always in U devices
Having SdkLevel.isAtLeastU() as a default value of
DeviceConfigUtils.isFeatureEnabled could result confusing behavior.
For example, when flag value is pushed to only the T device and the T
device with the flag is ugraded to U, this device could disable java bpf
map while the device keeps the flag value.
This CL prevents above confusing behavior.

Bug: 246218229
Test: atest BpfNetMaps
Change-Id: I615603c337bb94101dccac77ea0e6fa857041259
2022-12-06 15:03:20 +09:00
Paul Hu
ed3e683407 Merge "Fix empty value problem in the TextEntry" 2022-12-06 05:31:39 +00:00
Paul Hu
536cc4d102 Fix empty value problem in the TextEntry
Now, the value in TextEntry would be a zero length byte array if
the text record response doesn't contain the value. The problem
is that the value could either be an empty string ("key="), or
there can be no value ("key"), as per rfc6763 6.4 "If there is
no '=' in a DNS-SD TXT record string, then it is a boolean
attribute, simply identified as being present, with no value.".

Bug: 254166302
Test: atest FramworksNetTests
Change-Id: I4eaa5e593ce9ddaa6b6cb2f069c1aef977910796
2022-12-05 02:18:34 +00:00
Chiachang Wang
2217cd03f4 Merge "Ensure calling package and UID synchronized while calling dump()" 2022-12-05 00:48:25 +00:00
Bill Yi
c80ab04c22 Import translations. DO NOT MERGE ANYWHERE
Auto-generated-cl: translation import
Change-Id: Iac76895633eb6af61834b84b75c2312c857dfefa
2022-12-03 13:48:54 -08:00
Treehugger Robot
841b1f33d5 Merge "Revert consider TEMPORARILY_NOT_METERED as unmetered in data usage" 2022-12-02 11:27:27 +00:00
Aaron Huang
c5a05d1d8f Revert consider TEMPORARILY_NOT_METERED as unmetered in data usage
Currently, NET_CAPABILITY_TEMPORARILY_NOT_METERED traffic is
counted as unmetered data usage, and "mobile data usage"
settings screen shows metered data usage which means it doesn't
include TEMPORARILY_NOT_METERED traffic. However, some carriers
show TEMPORARILY_NOT_METERED data usage in customer's bill which
would be confusing if the data usage in the device shows different
results. Thus, revert the change to avoid confusing.

Bug: 183776809
Test: FrameworksNetTests
Change-Id: I4ef25095462adf30b1ecf82134996739f167930d
2022-12-02 16:04:55 +08:00
Paul Hu
79e239eacb Merge "Send MdnsServiceInfo on onServiceRemoved callback" 2022-12-02 01:33:40 +00:00
chiachangwang
18a6e8cf2f Ensure calling package and UID synchronized while calling dump()
This commit clear the calling identity before accessing the
DeviceConfig in ConnectivityService#dump().

The calling package of DeviceConfig.getProperties() comes from
ActivityThread.currentApplication(). In ConnectivityService#dump(),
the caller is ConnectivityService. It's OK to access DeviceConfig
from ConnectivityService. The same scenario applies to an app with
proper permission accessing DeviceConfig from its own context.

However, if cts would like to verify design by calling
ConnectivityService#dump(), the calling uid will comes from the
binder but package name will stay as ConnectivityService which
is 'android'. This will result in a SecurityException says that
the package does not match the uid and failed the test.

Bug: 255231779
Test: atest CtsNetTestCases FrameworksNetTests
Change-Id: I257e246b1cbf3b8a93bee2c326055ced9dfde588
2022-12-01 00:22:34 +00:00