Merge "Add the NAT64 prefix to LinkProperties."

am: 983e77db4a

Change-Id: Ia1e6e1e584db12e57b245fa01651d289337906a3
This commit is contained in:
Lorenzo Colitti
2019-01-14 20:17:53 -08:00
committed by android-build-merger
2 changed files with 92 additions and 6 deletions

View File

@@ -66,6 +66,7 @@ public final class LinkProperties implements Parcelable {
private int mMtu; private int mMtu;
// in the format "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max" // in the format "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max"
private String mTcpBufferSizes; private String mTcpBufferSizes;
private IpPrefix mNat64Prefix;
private static final int MIN_MTU = 68; private static final int MIN_MTU = 68;
private static final int MIN_MTU_V6 = 1280; private static final int MIN_MTU_V6 = 1280;
@@ -759,6 +760,32 @@ public final class LinkProperties implements Parcelable {
return mHttpProxy; return mHttpProxy;
} }
/**
* Returns the NAT64 prefix in use on this link, if any.
*
* @return the NAT64 prefix.
* @hide
*/
public @Nullable IpPrefix getNat64Prefix() {
return mNat64Prefix;
}
/**
* Sets the NAT64 prefix in use on this link.
*
* Currently, only 96-bit prefixes (i.e., where the 32-bit IPv4 address is at the end of the
* 128-bit IPv6 address) are supported.
*
* @param prefix the NAT64 prefix.
* @hide
*/
public void setNat64Prefix(IpPrefix prefix) {
if (prefix != null && prefix.getPrefixLength() != 96) {
throw new IllegalArgumentException("Only 96-bit prefixes are supported: " + prefix);
}
mNat64Prefix = prefix; // IpPrefix objects are immutable.
}
/** /**
* Adds a stacked link. * Adds a stacked link.
* *
@@ -831,6 +858,7 @@ public final class LinkProperties implements Parcelable {
mStackedLinks.clear(); mStackedLinks.clear();
mMtu = 0; mMtu = 0;
mTcpBufferSizes = null; mTcpBufferSizes = null;
mNat64Prefix = null;
} }
/** /**
@@ -908,6 +936,11 @@ public final class LinkProperties implements Parcelable {
resultJoiner.add(mHttpProxy.toString()); resultJoiner.add(mHttpProxy.toString());
} }
if (mNat64Prefix != null) {
resultJoiner.add("Nat64Prefix:");
resultJoiner.add(mNat64Prefix.toString());
}
final Collection<LinkProperties> stackedLinksValues = mStackedLinks.values(); final Collection<LinkProperties> stackedLinksValues = mStackedLinks.values();
if (!stackedLinksValues.isEmpty()) { if (!stackedLinksValues.isEmpty()) {
final StringJoiner stackedLinksJoiner = new StringJoiner(",", "Stacked: [", "]"); final StringJoiner stackedLinksJoiner = new StringJoiner(",", "Stacked: [", "]");
@@ -1294,6 +1327,17 @@ public final class LinkProperties implements Parcelable {
return Objects.equals(mTcpBufferSizes, target.mTcpBufferSizes); return Objects.equals(mTcpBufferSizes, target.mTcpBufferSizes);
} }
/**
* Compares this {@code LinkProperties} NAT64 prefix against the target.
*
* @param target LinkProperties to compare.
* @return {@code true} if both are identical, {@code false} otherwise.
* @hide
*/
public boolean isIdenticalNat64Prefix(LinkProperties target) {
return Objects.equals(mNat64Prefix, target.mNat64Prefix);
}
/** /**
* Compares this {@code LinkProperties} instance against the target * Compares this {@code LinkProperties} instance against the target
* LinkProperties in {@code obj}. Two LinkPropertieses are equal if * LinkProperties in {@code obj}. Two LinkPropertieses are equal if
@@ -1330,7 +1374,8 @@ public final class LinkProperties implements Parcelable {
&& isIdenticalHttpProxy(target) && isIdenticalHttpProxy(target)
&& isIdenticalStackedLinks(target) && isIdenticalStackedLinks(target)
&& isIdenticalMtu(target) && isIdenticalMtu(target)
&& isIdenticalTcpBufferSizes(target); && isIdenticalTcpBufferSizes(target)
&& isIdenticalNat64Prefix(target);
} }
/** /**
@@ -1443,7 +1488,8 @@ public final class LinkProperties implements Parcelable {
+ ((null == mTcpBufferSizes) ? 0 : mTcpBufferSizes.hashCode()) + ((null == mTcpBufferSizes) ? 0 : mTcpBufferSizes.hashCode())
+ (mUsePrivateDns ? 57 : 0) + (mUsePrivateDns ? 57 : 0)
+ mPcscfs.size() * 67 + mPcscfs.size() * 67
+ ((null == mPrivateDnsServerName) ? 0 : mPrivateDnsServerName.hashCode()); + ((null == mPrivateDnsServerName) ? 0 : mPrivateDnsServerName.hashCode())
+ Objects.hash(mNat64Prefix);
} }
/** /**
@@ -1484,6 +1530,8 @@ public final class LinkProperties implements Parcelable {
} else { } else {
dest.writeByte((byte)0); dest.writeByte((byte)0);
} }
dest.writeParcelable(mNat64Prefix, 0);
ArrayList<LinkProperties> stackedLinks = new ArrayList<>(mStackedLinks.values()); ArrayList<LinkProperties> stackedLinks = new ArrayList<>(mStackedLinks.values());
dest.writeList(stackedLinks); dest.writeList(stackedLinks);
} }
@@ -1535,6 +1583,7 @@ public final class LinkProperties implements Parcelable {
if (in.readByte() == 1) { if (in.readByte() == 1) {
netProp.setHttpProxy(in.readParcelable(null)); netProp.setHttpProxy(in.readParcelable(null));
} }
netProp.setNat64Prefix(in.readParcelable(null));
ArrayList<LinkProperties> stackedLinks = new ArrayList<LinkProperties>(); ArrayList<LinkProperties> stackedLinks = new ArrayList<LinkProperties>();
in.readList(stackedLinks, LinkProperties.class.getClassLoader()); in.readList(stackedLinks, LinkProperties.class.getClassLoader());
for (LinkProperties stackedLink: stackedLinks) { for (LinkProperties stackedLink: stackedLinks) {

View File

@@ -18,6 +18,7 @@ package android.net;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@@ -33,6 +34,9 @@ import android.support.test.runner.AndroidJUnit4;
import android.system.OsConstants; import android.system.OsConstants;
import android.util.ArraySet; import android.util.ArraySet;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -41,9 +45,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@SmallTest @SmallTest
public class LinkPropertiesTest { public class LinkPropertiesTest {
@@ -503,6 +504,40 @@ public class LinkPropertiesTest {
assertTrue(lp.equals(lp)); assertTrue(lp.equals(lp));
} }
@Test
public void testNat64Prefix() throws Exception {
LinkProperties lp = new LinkProperties();
lp.addLinkAddress(LINKADDRV4);
lp.addLinkAddress(LINKADDRV6);
assertNull(lp.getNat64Prefix());
IpPrefix p = new IpPrefix("64:ff9b::/96");
lp.setNat64Prefix(p);
assertEquals(p, lp.getNat64Prefix());
p = new IpPrefix("2001:db8:a:b:1:2:3::/96");
lp.setNat64Prefix(p);
assertEquals(p, lp.getNat64Prefix());
p = new IpPrefix("2001:db8:a:b:1:2::/80");
try {
lp.setNat64Prefix(p);
} catch (IllegalArgumentException expected) {
}
p = new IpPrefix("64:ff9b::/64");
try {
lp.setNat64Prefix(p);
} catch (IllegalArgumentException expected) {
}
assertEquals(new IpPrefix("2001:db8:a:b:1:2:3::/96"), lp.getNat64Prefix());
lp.setNat64Prefix(null);
assertNull(lp.getNat64Prefix());
}
@Test @Test
public void testIsProvisioned() { public void testIsProvisioned() {
LinkProperties lp4 = new LinkProperties(); LinkProperties lp4 = new LinkProperties();
@@ -815,7 +850,7 @@ public class LinkPropertiesTest {
} }
@Test @Test
public void testLinkPropertiesParcelable() { public void testLinkPropertiesParcelable() throws Exception {
LinkProperties source = new LinkProperties(); LinkProperties source = new LinkProperties();
source.setInterfaceName(NAME); source.setInterfaceName(NAME);
// set 2 link addresses // set 2 link addresses
@@ -833,6 +868,8 @@ public class LinkPropertiesTest {
source.setMtu(MTU); source.setMtu(MTU);
source.setNat64Prefix(new IpPrefix("2001:db8:1:2:64:64::/96"));
Parcel p = Parcel.obtain(); Parcel p = Parcel.obtain();
source.writeToParcel(p, /* flags */ 0); source.writeToParcel(p, /* flags */ 0);
p.setDataPosition(0); p.setDataPosition(0);