Merge "Add config_p2p_leases_subnet_prefix_length configuration"

This commit is contained in:
Mark Chien
2022-04-06 09:14:19 +00:00
committed by Gerrit Code Review
7 changed files with 95 additions and 1 deletions

View File

@@ -185,6 +185,16 @@ public class DhcpServingParamsParcelExt extends DhcpServingParamsParcel {
return this;
}
/** Set leases subnet prefix length. If the value is smaller than server address prefix length,
* this configuration will be ignored.
*
* <p>If not set, the default value is zero.
*/
public DhcpServingParamsParcelExt setLeasesSubnetPrefixLength(int prefixLength) {
this.leasesSubnetPrefixLength = prefixLength;
return this;
}
private static int[] toIntArray(@NonNull Collection<Inet4Address> addrs) {
int[] res = new int[addrs.size()];
int i = 0;

View File

@@ -241,6 +241,7 @@ public class IpServer extends StateMachine {
private final LinkProperties mLinkProperties;
private final boolean mUsingLegacyDhcp;
private final boolean mUsingBpfOffload;
private final int mP2pLeasesSubnetPrefixLength;
private final Dependencies mDeps;
@@ -299,6 +300,7 @@ public class IpServer extends StateMachine {
mLinkProperties = new LinkProperties();
mUsingLegacyDhcp = config.useLegacyDhcpServer();
mUsingBpfOffload = config.isBpfOffloadEnabled();
mP2pLeasesSubnetPrefixLength = config.getP2pLeasesSubnetPrefixLength();
mPrivateAddressCoordinator = addressCoordinator;
mDeps = deps;
resetLinkProperties();
@@ -527,6 +529,9 @@ public class IpServer extends StateMachine {
@Nullable Inet4Address clientAddr) {
final boolean changePrefixOnDecline =
(mInterfaceType == TetheringManager.TETHERING_NCM && clientAddr == null);
final int subnetPrefixLength = mInterfaceType == TetheringManager.TETHERING_WIFI_P2P
? mP2pLeasesSubnetPrefixLength : 0 /* default value */;
return new DhcpServingParamsParcelExt()
.setDefaultRouters(defaultRouter)
.setDhcpLeaseTimeSecs(DHCP_LEASE_TIME_SECS)
@@ -534,7 +539,8 @@ public class IpServer extends StateMachine {
.setServerAddr(serverAddr)
.setMetered(true)
.setSingleClientAddr(clientAddr)
.setChangePrefixOnDecline(changePrefixOnDecline);
.setChangePrefixOnDecline(changePrefixOnDecline)
.setLeasesSubnetPrefixLength(subnetPrefixLength);
// TODO: also advertise link MTU
}

View File

@@ -149,6 +149,7 @@ public class TetheringConfiguration {
// TODO: Add to TetheringConfigurationParcel if required.
private final boolean mEnableBpfOffload;
private final boolean mEnableWifiP2pDedicatedIp;
private final int mP2pLeasesSubnetPrefixLength;
private final int mUsbTetheringFunction;
protected final ContentResolver mContentResolver;
@@ -214,9 +215,27 @@ public class TetheringConfiguration {
R.bool.config_tether_enable_legacy_wifi_p2p_dedicated_ip,
false /* defaultValue */);
mP2pLeasesSubnetPrefixLength = getP2pLeasesSubnetPrefixLengthFromRes(res, configLog);
configLog.log(toString());
}
private int getP2pLeasesSubnetPrefixLengthFromRes(final Resources res, final SharedLog log) {
if (!mEnableWifiP2pDedicatedIp) return 0;
int prefixLength = getResourceInteger(res,
R.integer.config_p2p_leases_subnet_prefix_length, 0 /* default value */);
// DhcpLeaseRepository ignores the first and last addresses of the range so the max prefix
// length is 30.
if (prefixLength < 0 || prefixLength > 30) {
log.e("Invalid p2p leases subnet prefix length configuration: " + prefixLength);
return 0;
}
return prefixLength;
}
/** Check whether using legacy dhcp server. */
public boolean useLegacyDhcpServer() {
return mEnableLegacyDhcpServer;
@@ -272,6 +291,15 @@ public class TetheringConfiguration {
return mEnableWifiP2pDedicatedIp;
}
/**
* Get subnet prefix length of dhcp leases for wifi p2p.
* This feature only support when wifi p2p use dedicated address. If
* #shouldEnableWifiP2pDedicatedIp is false, this method would always return 0.
*/
public int getP2pLeasesSubnetPrefixLength() {
return mP2pLeasesSubnetPrefixLength;
}
/** Does the dumping.*/
public void dump(PrintWriter pw) {
pw.print("activeDataSubId: ");
@@ -310,6 +338,9 @@ public class TetheringConfiguration {
pw.print("enableWifiP2pDedicatedIp: ");
pw.println(mEnableWifiP2pDedicatedIp);
pw.print("p2pLeasesSubnetPrefixLength: ");
pw.println(mP2pLeasesSubnetPrefixLength);
pw.print("mUsbTetheringFunction: ");
pw.println(isUsingNcm() ? "NCM" : "RNDIS");
}