[BOT.5] Move class Ipv6ForwardingRule from IpServer to the coordinator
This is a preparation for moving adding/removing forwarding rules from IpServer to BpfCoordinator. Bug: 150736748 Test: atest IpServerTest Change-Id: I85316ef09ff3c9389ded11dcc384493d699da48e
This commit is contained in:
@@ -33,7 +33,6 @@ import android.net.LinkAddress;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.MacAddress;
|
||||
import android.net.RouteInfo;
|
||||
import android.net.TetherOffloadRuleParcel;
|
||||
import android.net.TetheredClient;
|
||||
import android.net.TetheringManager;
|
||||
import android.net.TetheringRequestParcel;
|
||||
@@ -66,6 +65,7 @@ import com.android.internal.util.MessageUtils;
|
||||
import com.android.internal.util.State;
|
||||
import com.android.internal.util.StateMachine;
|
||||
import com.android.networkstack.tethering.BpfCoordinator;
|
||||
import com.android.networkstack.tethering.BpfCoordinator.Ipv6ForwardingRule;
|
||||
import com.android.networkstack.tethering.PrivateAddressCoordinator;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -272,40 +272,6 @@ public class IpServer extends StateMachine {
|
||||
}
|
||||
}
|
||||
|
||||
static class Ipv6ForwardingRule {
|
||||
public final int upstreamIfindex;
|
||||
public final int downstreamIfindex;
|
||||
public final Inet6Address address;
|
||||
public final MacAddress srcMac;
|
||||
public final MacAddress dstMac;
|
||||
|
||||
Ipv6ForwardingRule(int upstreamIfindex, int downstreamIfIndex, Inet6Address address,
|
||||
MacAddress srcMac, MacAddress dstMac) {
|
||||
this.upstreamIfindex = upstreamIfindex;
|
||||
this.downstreamIfindex = downstreamIfIndex;
|
||||
this.address = address;
|
||||
this.srcMac = srcMac;
|
||||
this.dstMac = dstMac;
|
||||
}
|
||||
|
||||
public Ipv6ForwardingRule onNewUpstream(int newUpstreamIfindex) {
|
||||
return new Ipv6ForwardingRule(newUpstreamIfindex, downstreamIfindex, address, srcMac,
|
||||
dstMac);
|
||||
}
|
||||
|
||||
// Don't manipulate TetherOffloadRuleParcel directly because implementing onNewUpstream()
|
||||
// would be error-prone due to generated stable AIDL classes not having a copy constructor.
|
||||
public TetherOffloadRuleParcel toTetherOffloadRuleParcel() {
|
||||
final TetherOffloadRuleParcel parcel = new TetherOffloadRuleParcel();
|
||||
parcel.inputInterfaceIndex = upstreamIfindex;
|
||||
parcel.outputInterfaceIndex = downstreamIfindex;
|
||||
parcel.destination = address.getAddress();
|
||||
parcel.prefixLength = 128;
|
||||
parcel.srcL2Address = srcMac.toByteArray();
|
||||
parcel.dstL2Address = dstMac.toByteArray();
|
||||
return parcel;
|
||||
}
|
||||
}
|
||||
private final LinkedHashMap<Inet6Address, Ipv6ForwardingRule> mIpv6ForwardingRules =
|
||||
new LinkedHashMap<>();
|
||||
|
||||
|
||||
@@ -26,8 +26,10 @@ import static android.net.NetworkStats.UID_TETHERING;
|
||||
|
||||
import android.app.usage.NetworkStatsManager;
|
||||
import android.net.INetd;
|
||||
import android.net.MacAddress;
|
||||
import android.net.NetworkStats;
|
||||
import android.net.NetworkStats.Entry;
|
||||
import android.net.TetherOffloadRuleParcel;
|
||||
import android.net.TetherStatsParcel;
|
||||
import android.net.netstats.provider.NetworkStatsProvider;
|
||||
import android.net.util.SharedLog;
|
||||
@@ -43,6 +45,8 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
|
||||
import java.net.Inet6Address;
|
||||
|
||||
/**
|
||||
* This coordinator is responsible for providing BPF offload relevant functionality.
|
||||
* - Get tethering stats.
|
||||
@@ -169,6 +173,45 @@ public class BpfCoordinator {
|
||||
}
|
||||
}
|
||||
|
||||
/** IPv6 forwarding rule class. */
|
||||
public static class Ipv6ForwardingRule {
|
||||
public final int upstreamIfindex;
|
||||
public final int downstreamIfindex;
|
||||
public final Inet6Address address;
|
||||
public final MacAddress srcMac;
|
||||
public final MacAddress dstMac;
|
||||
|
||||
public Ipv6ForwardingRule(int upstreamIfindex, int downstreamIfIndex, Inet6Address address,
|
||||
MacAddress srcMac, MacAddress dstMac) {
|
||||
this.upstreamIfindex = upstreamIfindex;
|
||||
this.downstreamIfindex = downstreamIfIndex;
|
||||
this.address = address;
|
||||
this.srcMac = srcMac;
|
||||
this.dstMac = dstMac;
|
||||
}
|
||||
|
||||
/** Return a new rule object which updates with new upstream index. */
|
||||
public Ipv6ForwardingRule onNewUpstream(int newUpstreamIfindex) {
|
||||
return new Ipv6ForwardingRule(newUpstreamIfindex, downstreamIfindex, address, srcMac,
|
||||
dstMac);
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't manipulate TetherOffloadRuleParcel directly because implementing onNewUpstream()
|
||||
* would be error-prone due to generated stable AIDL classes not having a copy constructor.
|
||||
*/
|
||||
public TetherOffloadRuleParcel toTetherOffloadRuleParcel() {
|
||||
final TetherOffloadRuleParcel parcel = new TetherOffloadRuleParcel();
|
||||
parcel.inputInterfaceIndex = upstreamIfindex;
|
||||
parcel.outputInterfaceIndex = downstreamIfindex;
|
||||
parcel.destination = address.getAddress();
|
||||
parcel.prefixLength = 128;
|
||||
parcel.srcL2Address = srcMac.toByteArray();
|
||||
parcel.dstL2Address = dstMac.toByteArray();
|
||||
return parcel;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A BPF tethering stats provider to provide network statistics to the system.
|
||||
* Note that this class's data may only be accessed on the handler thread.
|
||||
|
||||
Reference in New Issue
Block a user