From 68770343435463a93c29106c6e69ac4c18053eef Mon Sep 17 00:00:00 2001 From: KH Shi Date: Thu, 17 Aug 2023 14:34:31 +0000 Subject: [PATCH] Relief unnecessary dependencies of code order The original code requires updating mLastIPv6LinkProperties before calling updateIpv6ForwardingRules because mLastIPv6LinkProperties will be used inside an internal function later. Remove this unnecessary dependency by passing the interface name into the function. Bug: 294025403 Test: atest TetheringTests Change-Id: I5699fba3d7caf3314d102b643b02da2b2797dd66 --- Tethering/src/android/net/ip/IpServer.java | 28 ++++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/Tethering/src/android/net/ip/IpServer.java b/Tethering/src/android/net/ip/IpServer.java index bb09d0de36..eadba58c22 100644 --- a/Tethering/src/android/net/ip/IpServer.java +++ b/Tethering/src/android/net/ip/IpServer.java @@ -283,6 +283,7 @@ public class IpServer extends StateMachine { private List mDhcpLeases = Collections.emptyList(); private int mLastIPv6UpstreamIfindex = 0; + private boolean mUpstreamSupportsBpf = false; private class MyNeighborEventConsumer implements IpNeighborMonitor.NeighborEventConsumer { public void accept(NeighborEvent e) { @@ -779,15 +780,15 @@ public class IpServer extends StateMachine { // If v6only is null, we pass in null to setRaParams(), which handles // deprecation of any existing RA data. - setRaParams(params); - // Be aware that updateIpv6ForwardingRules use mLastIPv6LinkProperties, so this line should - // be eariler than updateIpv6ForwardingRules. - // TODO: avoid this dependencies and move this logic into BpfCoordinator. - mLastIPv6LinkProperties = v6only; - updateIpv6ForwardingRules(mLastIPv6UpstreamIfindex, upstreamIfIndex, null); + // Not support BPF on virtual upstream interface + final boolean upstreamSupportsBpf = upstreamIface != null && !isVcnInterface(upstreamIface); + updateIpv6ForwardingRules( + mLastIPv6UpstreamIfindex, upstreamIfIndex, upstreamSupportsBpf, null); + mLastIPv6LinkProperties = v6only; mLastIPv6UpstreamIfindex = upstreamIfIndex; + mUpstreamSupportsBpf = upstreamSupportsBpf; if (mDadProxy != null) { mDadProxy.setUpstreamIface(upstreamIfaceParams); } @@ -921,20 +922,14 @@ public class IpServer extends StateMachine { mBpfCoordinator.tetherOffloadRuleUpdate(this, newIfindex); } - private boolean isIpv6VcnNetworkInterface() { - if (mLastIPv6LinkProperties == null) return false; - - return isVcnInterface(mLastIPv6LinkProperties.getInterfaceName()); - } - // Handles all updates to IPv6 forwarding rules. These can currently change only if the upstream // changes or if a neighbor event is received. private void updateIpv6ForwardingRules(int prevUpstreamIfindex, int upstreamIfindex, - NeighborEvent e) { - // If no longer have an upstream or it is virtual network, clear forwarding rules and do + boolean upstreamSupportsBpf, NeighborEvent e) { + // If no longer have an upstream or upstream not supports BPF, clear forwarding rules and do // nothing else. // TODO: Rather than always clear rules, ensure whether ipv6 ever enable first. - if (upstreamIfindex == 0 || isIpv6VcnNetworkInterface()) { + if (upstreamIfindex == 0 || !upstreamSupportsBpf) { clearIpv6ForwardingRules(); return; } @@ -995,7 +990,8 @@ public class IpServer extends StateMachine { if (mInterfaceParams != null && mInterfaceParams.index == e.ifindex && mInterfaceParams.hasMacAddress) { - updateIpv6ForwardingRules(mLastIPv6UpstreamIfindex, mLastIPv6UpstreamIfindex, e); + updateIpv6ForwardingRules(mLastIPv6UpstreamIfindex, mLastIPv6UpstreamIfindex, + mUpstreamSupportsBpf, e); updateClientInfoIpv4(e); } }