Merge "API changes for IPv6 MTU support"
This commit is contained in:
@@ -104,6 +104,11 @@ public final class RouteInfo implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
private final int mType;
|
private final int mType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The maximum transmission unit size for this route.
|
||||||
|
*/
|
||||||
|
private final int mMtu;
|
||||||
|
|
||||||
// Derived data members.
|
// Derived data members.
|
||||||
// TODO: remove these.
|
// TODO: remove these.
|
||||||
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
|
||||||
@@ -132,6 +137,31 @@ public final class RouteInfo implements Parcelable {
|
|||||||
@TestApi
|
@TestApi
|
||||||
public RouteInfo(@Nullable IpPrefix destination, @Nullable InetAddress gateway,
|
public RouteInfo(@Nullable IpPrefix destination, @Nullable InetAddress gateway,
|
||||||
@Nullable String iface, @RouteType int type) {
|
@Nullable String iface, @RouteType int type) {
|
||||||
|
this(destination, gateway, iface, type, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a RouteInfo object.
|
||||||
|
*
|
||||||
|
* If destination is null, then gateway must be specified and the
|
||||||
|
* constructed route is either the IPv4 default route <code>0.0.0.0</code>
|
||||||
|
* if the gateway is an instance of {@link Inet4Address}, or the IPv6 default
|
||||||
|
* route <code>::/0</code> if gateway is an instance of
|
||||||
|
* {@link Inet6Address}.
|
||||||
|
* <p>
|
||||||
|
* destination and gateway may not both be null.
|
||||||
|
*
|
||||||
|
* @param destination the destination prefix
|
||||||
|
* @param gateway the IP address to route packets through
|
||||||
|
* @param iface the interface name to send packets on
|
||||||
|
* @param type the type of this route
|
||||||
|
* @param mtu the maximum transmission unit size for this route
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SystemApi
|
||||||
|
public RouteInfo(@Nullable IpPrefix destination, @Nullable InetAddress gateway,
|
||||||
|
@Nullable String iface, @RouteType int type, int mtu) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case RTN_UNICAST:
|
case RTN_UNICAST:
|
||||||
case RTN_UNREACHABLE:
|
case RTN_UNREACHABLE:
|
||||||
@@ -176,10 +206,10 @@ public final class RouteInfo implements Parcelable {
|
|||||||
}
|
}
|
||||||
mHasGateway = (!gateway.isAnyLocalAddress());
|
mHasGateway = (!gateway.isAnyLocalAddress());
|
||||||
|
|
||||||
if ((destination.getAddress() instanceof Inet4Address &&
|
if ((destination.getAddress() instanceof Inet4Address
|
||||||
(gateway instanceof Inet4Address == false)) ||
|
&& !(gateway instanceof Inet4Address))
|
||||||
(destination.getAddress() instanceof Inet6Address &&
|
|| (destination.getAddress() instanceof Inet6Address
|
||||||
(gateway instanceof Inet6Address == false))) {
|
&& !(gateway instanceof Inet6Address))) {
|
||||||
throw new IllegalArgumentException("address family mismatch in RouteInfo constructor");
|
throw new IllegalArgumentException("address family mismatch in RouteInfo constructor");
|
||||||
}
|
}
|
||||||
mDestination = destination; // IpPrefix objects are immutable.
|
mDestination = destination; // IpPrefix objects are immutable.
|
||||||
@@ -187,6 +217,7 @@ public final class RouteInfo implements Parcelable {
|
|||||||
mInterface = iface; // Strings are immutable.
|
mInterface = iface; // Strings are immutable.
|
||||||
mType = type;
|
mType = type;
|
||||||
mIsHost = isHost();
|
mIsHost = isHost();
|
||||||
|
mMtu = mtu;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -372,6 +403,17 @@ public final class RouteInfo implements Parcelable {
|
|||||||
return mType;
|
return mType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the MTU size for this route.
|
||||||
|
*
|
||||||
|
* @return The MTU size, or 0 if it has not been set.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@SystemApi
|
||||||
|
public int getMtu() {
|
||||||
|
return mMtu;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates if this route is a default route (ie, has no destination specified).
|
* Indicates if this route is a default route (ie, has no destination specified).
|
||||||
*
|
*
|
||||||
@@ -476,6 +518,7 @@ public final class RouteInfo implements Parcelable {
|
|||||||
val += " unknown type " + mType;
|
val += " unknown type " + mType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val += " mtu " + mMtu;
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -493,7 +536,7 @@ public final class RouteInfo implements Parcelable {
|
|||||||
return Objects.equals(mDestination, target.getDestination()) &&
|
return Objects.equals(mDestination, target.getDestination()) &&
|
||||||
Objects.equals(mGateway, target.getGateway()) &&
|
Objects.equals(mGateway, target.getGateway()) &&
|
||||||
Objects.equals(mInterface, target.getInterface()) &&
|
Objects.equals(mInterface, target.getInterface()) &&
|
||||||
mType == target.getType();
|
mType == target.getType() && mMtu == target.getMtu();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -503,7 +546,7 @@ public final class RouteInfo implements Parcelable {
|
|||||||
return (mDestination.hashCode() * 41)
|
return (mDestination.hashCode() * 41)
|
||||||
+ (mGateway == null ? 0 :mGateway.hashCode() * 47)
|
+ (mGateway == null ? 0 :mGateway.hashCode() * 47)
|
||||||
+ (mInterface == null ? 0 :mInterface.hashCode() * 67)
|
+ (mInterface == null ? 0 :mInterface.hashCode() * 67)
|
||||||
+ (mType * 71);
|
+ (mType * 71) + (mMtu * 89);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -522,6 +565,7 @@ public final class RouteInfo implements Parcelable {
|
|||||||
dest.writeByteArray(gatewayBytes);
|
dest.writeByteArray(gatewayBytes);
|
||||||
dest.writeString(mInterface);
|
dest.writeString(mInterface);
|
||||||
dest.writeInt(mType);
|
dest.writeInt(mType);
|
||||||
|
dest.writeInt(mMtu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -540,8 +584,9 @@ public final class RouteInfo implements Parcelable {
|
|||||||
|
|
||||||
String iface = in.readString();
|
String iface = in.readString();
|
||||||
int type = in.readInt();
|
int type = in.readInt();
|
||||||
|
int mtu = in.readInt();
|
||||||
|
|
||||||
return new RouteInfo(dest, gateway, iface, type);
|
return new RouteInfo(dest, gateway, iface, type, mtu);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RouteInfo[] newArray(int size) {
|
public RouteInfo[] newArray(int size) {
|
||||||
|
|||||||
@@ -258,6 +258,16 @@ public class RouteInfoTest extends TestCase {
|
|||||||
assertParcelingIsLossless(r);
|
assertParcelingIsLossless(r);
|
||||||
|
|
||||||
r = new RouteInfo(Prefix("192.0.2.0/24"), null, "wlan0");
|
r = new RouteInfo(Prefix("192.0.2.0/24"), null, "wlan0");
|
||||||
assertParcelSane(r, 6);
|
assertParcelSane(r, 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMtu() {
|
||||||
|
RouteInfo r;
|
||||||
|
r = new RouteInfo(Prefix("0.0.0.0/0"), Address("0.0.0.0"), "wlan0",
|
||||||
|
RouteInfo.RTN_UNICAST, 1500);
|
||||||
|
assertEquals(1500, r.getMtu());
|
||||||
|
|
||||||
|
r = new RouteInfo(Prefix("0.0.0.0/0"), Address("0.0.0.0"), "wlan0");
|
||||||
|
assertEquals(0, r.getMtu());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user