Adding more test cases for stacked link properties for local network.

Addressing feedback from previous change "Adding stacked link addresses
to local_net_access map" and adding more test cases for impact of
stacked link properties on local network prefixes.

Bug: 369815823
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.BpfNetMapsTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.CSLocalNetworkProtectionTest
Change-Id: I4d32d86d3e083a1a14b845583fd80a7a4b18ae5f
This commit is contained in:
Sarup Dalwani 2025-02-20 05:44:56 +00:00
commit e53faa4e84

View file

@ -9805,8 +9805,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
// The both list contain current link properties + stacked links for new and old LP.
List<LinkProperties> newLinkProperties = new ArrayList<>();
List<LinkProperties> oldLinkProperties = new ArrayList<>();
final List<LinkProperties> newLinkProperties = new ArrayList<>();
final List<LinkProperties> oldLinkProperties = new ArrayList<>();
if (newLp != null) {
newLinkProperties.add(newLp);
@ -9819,13 +9819,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
// map contains interface name to list of local network prefixes added because of change
// in link properties
Map<String, List<IpPrefix>> prefixesAddedForInterface = new ArrayMap<>();
final Map<String, List<IpPrefix>> prefixesAddedForInterface = new ArrayMap<>();
final CompareResult<LinkProperties> linkPropertiesDiff = new CompareResult<>(
oldLinkProperties, newLinkProperties);
for (LinkProperties linkProperty : linkPropertiesDiff.added) {
List<IpPrefix> unicastLocalPrefixesToBeAdded = new ArrayList<>();
final List<IpPrefix> unicastLocalPrefixesToBeAdded = new ArrayList<>();
for (LinkAddress linkAddress : linkProperty.getLinkAddresses()) {
unicastLocalPrefixesToBeAdded.addAll(
getLocalNetworkPrefixesForAddress(linkAddress));
@ -9833,7 +9833,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
addLocalAddressesToBpfMap(linkProperty.getInterfaceName(),
unicastLocalPrefixesToBeAdded, linkProperty);
// adding iterface name -> ip prefixes that we added to map
// populating interface name -> ip prefixes which were added to local_net_access map.
if (!prefixesAddedForInterface.containsKey(linkProperty.getInterfaceName())) {
prefixesAddedForInterface.put(linkProperty.getInterfaceName(), new ArrayList<>());
}
@ -9842,9 +9842,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
for (LinkProperties linkProperty : linkPropertiesDiff.removed) {
List<IpPrefix> unicastLocalPrefixesToBeRemoved = new ArrayList<>();
List<IpPrefix> unicastLocalPrefixesAdded = prefixesAddedForInterface.getOrDefault(
linkProperty.getInterfaceName(), new ArrayList<>());
final List<IpPrefix> unicastLocalPrefixesToBeRemoved = new ArrayList<>();
final List<IpPrefix> unicastLocalPrefixesAdded = prefixesAddedForInterface.getOrDefault(
linkProperty.getInterfaceName(), Collections.emptyList());
for (LinkAddress linkAddress : linkProperty.getLinkAddresses()) {
unicastLocalPrefixesToBeRemoved.addAll(
@ -9852,8 +9852,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
}
// This is to ensure if 10.0.10.0/24 was added and 10.0.11.0/24 was removed both will
// still populate the same prefix of 10.0.0.0/8, which mean we should not remove the
// prefix because of removal of 10.0.11.0/24
// still populate the same prefix of 10.0.0.0/8, which mean 10.0.0.0/8 should not be
// removed due to removal of 10.0.11.0/24
unicastLocalPrefixesToBeRemoved.removeAll(unicastLocalPrefixesAdded);
removeLocalAddressesFromBpfMap(linkProperty.getInterfaceName(),