Move upstream interface BPF support check to BpfCoordinator
Removed upstream interface BPF support check from IpServer and moved
it to BpfCoordinator. The support check can be performed directly in
BpfCoordinator using the interface name.
Test: atest TetheringTests
Bug: 294025403
Change-Id: Ia51bc3ab18dd21afdca9db9199fa060aab68f768
diff --git a/Tethering/src/android/net/ip/IpServer.java b/Tethering/src/android/net/ip/IpServer.java
index 35ec51d..8376fa0 100644
--- a/Tethering/src/android/net/ip/IpServer.java
+++ b/Tethering/src/android/net/ip/IpServer.java
@@ -34,7 +34,6 @@
import static com.android.net.module.util.Inet4AddressUtils.intToInet4AddressHTH;
import static com.android.net.module.util.NetworkStackConstants.RFC7421_PREFIX_LENGTH;
import static com.android.networkstack.tethering.TetheringConfiguration.USE_SYNC_SM;
-import static com.android.networkstack.tethering.UpstreamNetworkState.isVcnInterface;
import static com.android.networkstack.tethering.util.PrefixUtils.asIpPrefix;
import static com.android.networkstack.tethering.util.TetheringMessageBase.BASE_IPSERVER;
@@ -289,7 +288,6 @@
private List<TetheredClient> mDhcpLeases = Collections.emptyList();
private int mLastIPv6UpstreamIfindex = 0;
- private boolean mUpstreamSupportsBpf = false;
@NonNull
private Set<IpPrefix> mLastIPv6UpstreamPrefixes = Collections.emptySet();
@@ -800,18 +798,15 @@
setRaParams(params);
// Not support BPF on virtual upstream interface
- final boolean upstreamSupportsBpf = upstreamIface != null && !isVcnInterface(upstreamIface);
final Set<IpPrefix> upstreamPrefixes = params != null ? params.prefixes : Set.of();
// mBpfCoordinator#updateIpv6UpstreamInterface must be called before updating
// mLastIPv6UpstreamIfindex and mLastIPv6UpstreamPrefixes because BpfCoordinator will call
// IpServer#getIpv6UpstreamIfindex and IpServer#getIpv6UpstreamPrefixes to retrieve current
// upstream interface index and prefixes when handling upstream changes.
- mBpfCoordinator.updateIpv6UpstreamInterface(this, upstreamIfIndex, upstreamPrefixes,
- upstreamSupportsBpf);
+ mBpfCoordinator.updateIpv6UpstreamInterface(this, upstreamIfIndex, upstreamPrefixes);
mLastIPv6LinkProperties = v6only;
mLastIPv6UpstreamIfindex = upstreamIfIndex;
mLastIPv6UpstreamPrefixes = upstreamPrefixes;
- mUpstreamSupportsBpf = upstreamSupportsBpf;
if (mDadProxy != null) {
mDadProxy.setUpstreamIface(upstreamIfaceParams);
}
@@ -1309,7 +1304,7 @@
for (String ifname : mUpstreamIfaceSet.ifnames) cleanupUpstreamInterface(ifname);
mUpstreamIfaceSet = null;
mBpfCoordinator.updateIpv6UpstreamInterface(IpServer.this, NO_UPSTREAM,
- Collections.emptySet(), false /* upstreamSupportsBpf */);
+ Collections.emptySet());
}
private void cleanupUpstreamInterface(String upstreamIface) {
diff --git a/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java b/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java
index 60b164b..5c853f4 100644
--- a/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java
+++ b/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java
@@ -902,7 +902,7 @@
* Note that this can be only called on handler thread.
*/
public void updateIpv6UpstreamInterface(@NonNull final IpServer ipServer, int upstreamIfindex,
- @NonNull Set<IpPrefix> upstreamPrefixes, boolean upstreamSupportsBpf) {
+ @NonNull Set<IpPrefix> upstreamPrefixes) {
if (!isUsingBpf()) return;
// If the upstream interface has changed, remove all rules and re-add them with the new
@@ -912,6 +912,7 @@
final Set<IpPrefix> prevUpstreamPrefixes = ipServer.getIpv6UpstreamPrefixes();
if (prevUpstreamIfindex != upstreamIfindex
|| !prevUpstreamPrefixes.equals(upstreamPrefixes)) {
+ final boolean upstreamSupportsBpf = checkUpstreamSupportsBpf(upstreamIfindex);
updateAllIpv6Rules(ipServer, interfaceParams,
getInterfaceIndexForRule(upstreamIfindex, upstreamSupportsBpf),
upstreamPrefixes);
diff --git a/Tethering/tests/unit/src/android/net/ip/IpServerTest.java b/Tethering/tests/unit/src/android/net/ip/IpServerTest.java
index 67af1f4..00eb3b1 100644
--- a/Tethering/tests/unit/src/android/net/ip/IpServerTest.java
+++ b/Tethering/tests/unit/src/android/net/ip/IpServerTest.java
@@ -249,8 +249,8 @@
// when upstream's LinkProperties is updated (updateUpstreamIPv6LinkProperties)
verify(mBpfCoordinator, times(2)).maybeAddUpstreamToLookupTable(
interfaceParams.index, upstreamIface);
- verify(mBpfCoordinator).updateIpv6UpstreamInterface(mIpServer, interfaceParams.index,
- upstreamPrefixes, true /* upstreamSupportsBpf */);
+ verify(mBpfCoordinator).updateIpv6UpstreamInterface(
+ mIpServer, interfaceParams.index, upstreamPrefixes);
}
reset(mNetd, mBpfCoordinator, mCallback, mAddressCoordinator);
when(mAddressCoordinator.requestDownstreamAddress(any(), anyInt(),
@@ -555,7 +555,7 @@
inOrder.verify(mNetd).ipfwdRemoveInterfaceForward(IFACE_NAME, UPSTREAM_IFACE);
inOrder.verify(mNetd).tetherRemoveForward(IFACE_NAME, UPSTREAM_IFACE);
inOrder.verify(mBpfCoordinator).updateIpv6UpstreamInterface(
- mIpServer, NO_UPSTREAM, NO_PREFIXES, false /* upstreamSupportsBpf */);
+ mIpServer, NO_UPSTREAM, NO_PREFIXES);
// When tethering stops, upstream interface is set to zero and thus clearing all upstream
// rules. Downstream rules are needed to be cleared explicitly by calling
// BpfCoordinator#clearAllIpv6Rules in TetheredState#exit.
@@ -763,7 +763,7 @@
lp.setLinkAddresses(UPSTREAM_ADDRESSES);
dispatchTetherConnectionChanged(UPSTREAM_IFACE2, lp, -1);
verify(mBpfCoordinator).updateIpv6UpstreamInterface(
- mIpServer, UPSTREAM_IFINDEX2, UPSTREAM_PREFIXES, true /* upstreamSupportsBpf */);
+ mIpServer, UPSTREAM_IFINDEX2, UPSTREAM_PREFIXES);
reset(mBpfCoordinator);
// Upstream link addresses change result in updating the rules.
@@ -772,7 +772,7 @@
lp2.setLinkAddresses(UPSTREAM_ADDRESSES2);
dispatchTetherConnectionChanged(UPSTREAM_IFACE2, lp2, -1);
verify(mBpfCoordinator).updateIpv6UpstreamInterface(
- mIpServer, UPSTREAM_IFINDEX2, UPSTREAM_PREFIXES2, true /* upstreamSupportsBpf */);
+ mIpServer, UPSTREAM_IFINDEX2, UPSTREAM_PREFIXES2);
reset(mBpfCoordinator);
// When the upstream is lost, rules are removed.
@@ -782,33 +782,33 @@
// - processMessage CMD_IPV6_TETHER_UPDATE for the IPv6 upstream is lost.
// See dispatchTetherConnectionChanged.
verify(mBpfCoordinator, times(2)).updateIpv6UpstreamInterface(
- mIpServer, NO_UPSTREAM, NO_PREFIXES, false /* upstreamSupportsBpf */);
+ mIpServer, NO_UPSTREAM, NO_PREFIXES);
reset(mBpfCoordinator);
// If the upstream is IPv4-only, no rules are added.
dispatchTetherConnectionChanged(UPSTREAM_IFACE);
verify(mBpfCoordinator, never()).updateIpv6UpstreamInterface(
- mIpServer, NO_UPSTREAM, NO_PREFIXES, false /* upstreamSupportsBpf */);
+ mIpServer, NO_UPSTREAM, NO_PREFIXES);
reset(mBpfCoordinator);
// Rules are added again once upstream IPv6 connectivity is available.
lp.setInterfaceName(UPSTREAM_IFACE);
dispatchTetherConnectionChanged(UPSTREAM_IFACE, lp, -1);
verify(mBpfCoordinator).updateIpv6UpstreamInterface(
- mIpServer, UPSTREAM_IFINDEX, UPSTREAM_PREFIXES, true /* upstreamSupportsBpf */);
+ mIpServer, UPSTREAM_IFINDEX, UPSTREAM_PREFIXES);
reset(mBpfCoordinator);
// If upstream IPv6 connectivity is lost, rules are removed.
dispatchTetherConnectionChanged(UPSTREAM_IFACE, null, 0);
verify(mBpfCoordinator).updateIpv6UpstreamInterface(
- mIpServer, NO_UPSTREAM, NO_PREFIXES, false /* upstreamSupportsBpf */);
+ mIpServer, NO_UPSTREAM, NO_PREFIXES);
reset(mBpfCoordinator);
// When upstream IPv6 connectivity comes back, rules are added.
lp.setInterfaceName(UPSTREAM_IFACE);
dispatchTetherConnectionChanged(UPSTREAM_IFACE, lp, -1);
verify(mBpfCoordinator).updateIpv6UpstreamInterface(
- mIpServer, UPSTREAM_IFINDEX, UPSTREAM_PREFIXES, true /* upstreamSupportsBpf */);
+ mIpServer, UPSTREAM_IFINDEX, UPSTREAM_PREFIXES);
reset(mBpfCoordinator);
// When the downstream interface goes down, rules are removed.
@@ -817,7 +817,7 @@
verify(mBpfCoordinator).clearAllIpv6Rules(mIpServer);
verify(mBpfCoordinator).removeIpServer(mIpServer);
verify(mBpfCoordinator).updateIpv6UpstreamInterface(
- mIpServer, NO_UPSTREAM, NO_PREFIXES, false /* upstreamSupportsBpf */);
+ mIpServer, NO_UPSTREAM, NO_PREFIXES);
reset(mBpfCoordinator);
}
diff --git a/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java b/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java
index 4f58c61..224aad7 100644
--- a/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java
+++ b/Tethering/tests/unit/src/com/android/networkstack/tethering/BpfCoordinatorTest.java
@@ -62,7 +62,6 @@
import static com.android.networkstack.tethering.BpfUtils.DOWNSTREAM;
import static com.android.networkstack.tethering.BpfUtils.UPSTREAM;
import static com.android.networkstack.tethering.TetheringConfiguration.DEFAULT_TETHER_OFFLOAD_POLL_INTERVAL_MS;
-import static com.android.networkstack.tethering.UpstreamNetworkState.isVcnInterface;
import static com.android.testutils.MiscAsserts.assertSameElements;
import static org.junit.Assert.assertArrayEquals;
@@ -650,10 +649,8 @@
private void dispatchIpv6UpstreamChanged(BpfCoordinator bpfCoordinator, IpServer ipServer,
int upstreamIfindex, String upstreamIface, Set<IpPrefix> upstreamPrefixes) {
- final boolean upstreamSupportsBpf = upstreamIface != null && !isVcnInterface(upstreamIface);
bpfCoordinator.maybeAddUpstreamToLookupTable(upstreamIfindex, upstreamIface);
- bpfCoordinator.updateIpv6UpstreamInterface(ipServer, upstreamIfindex, upstreamPrefixes,
- upstreamSupportsBpf);
+ bpfCoordinator.updateIpv6UpstreamInterface(ipServer, upstreamIfindex, upstreamPrefixes);
when(ipServer.getIpv6UpstreamIfindex()).thenReturn(upstreamIfindex);
when(ipServer.getIpv6UpstreamPrefixes()).thenReturn(upstreamPrefixes);
}
@@ -1587,7 +1584,7 @@
// The rule can't be updated.
coordinator.updateIpv6UpstreamInterface(mIpServer, rule.upstreamIfindex + 1 /* new */,
- UPSTREAM_PREFIXES, true /* upstreamSupportsBpf */);
+ UPSTREAM_PREFIXES);
verifyNeverRemoveDownstreamRule();
verifyNeverAddDownstreamRule();
rules = coordinator.getIpv6DownstreamRulesForTesting().get(mIpServer);