use of android.net.IpPrefix in project android_frameworks_base by DirtyUnicorns.
the class IPv6TetheringInterfaceServices method updateUpstreamIPv6LinkProperties.
// IPv6TetheringCoordinator sends updates with carefully curated IPv6-only
// LinkProperties. These have extraneous data filtered out and only the
// necessary prefixes included (per its prefix distribution policy).
//
// TODO: Evaluate using a data structure than is more directly suited to
// communicating only the relevant information.
public void updateUpstreamIPv6LinkProperties(LinkProperties v6only) {
if (mRaDaemon == null)
return;
// Avoid unnecessary work on spurious updates.
if (Objects.equals(mLastIPv6LinkProperties, v6only)) {
return;
}
RaParams params = null;
if (v6only != null) {
params = new RaParams();
params.mtu = v6only.getMtu();
params.hasDefaultRoute = v6only.hasIPv6DefaultRoute();
for (LinkAddress linkAddr : v6only.getLinkAddresses()) {
if (linkAddr.getPrefixLength() != RFC7421_IP_PREFIX_LENGTH)
continue;
final IpPrefix prefix = new IpPrefix(linkAddr.getAddress(), linkAddr.getPrefixLength());
params.prefixes.add(prefix);
final Inet6Address dnsServer = getLocalDnsIpFor(prefix);
if (dnsServer != null) {
params.dnses.add(dnsServer);
}
}
}
// If v6only is null, we pass in null to setRaParams(), which handles
// deprecation of any existing RA data.
setRaParams(params);
mLastIPv6LinkProperties = v6only;
}
use of android.net.IpPrefix in project android_frameworks_base by AOSPA.
the class StaticIpConfigurationTest method testToLinkProperties.
@SmallTest
public void testToLinkProperties() {
LinkProperties expected = new LinkProperties();
expected.setInterfaceName(IFACE);
StaticIpConfiguration s = new StaticIpConfiguration();
assertEquals(expected, s.toLinkProperties(IFACE));
final RouteInfo connectedRoute = new RouteInfo(new IpPrefix(ADDRSTR), null, IFACE);
s.ipAddress = ADDR;
expected.addLinkAddress(ADDR);
expected.addRoute(connectedRoute);
assertEquals(expected, s.toLinkProperties(IFACE));
s.gateway = GATEWAY;
RouteInfo defaultRoute = new RouteInfo(new IpPrefix("0.0.0.0/0"), GATEWAY, IFACE);
expected.addRoute(defaultRoute);
assertEquals(expected, s.toLinkProperties(IFACE));
s.gateway = OFFLINKGATEWAY;
expected.removeRoute(defaultRoute);
defaultRoute = new RouteInfo(new IpPrefix("0.0.0.0/0"), OFFLINKGATEWAY, IFACE);
expected.addRoute(defaultRoute);
RouteInfo gatewayRoute = new RouteInfo(new IpPrefix("192.0.2.129/32"), null, IFACE);
expected.addRoute(gatewayRoute);
assertEquals(expected, s.toLinkProperties(IFACE));
s.dnsServers.add(DNS1);
expected.addDnsServer(DNS1);
assertEquals(expected, s.toLinkProperties(IFACE));
s.dnsServers.add(DNS2);
s.dnsServers.add(DNS3);
expected.addDnsServer(DNS2);
expected.addDnsServer(DNS3);
assertEquals(expected, s.toLinkProperties(IFACE));
s.domains = "google.com";
expected.setDomains("google.com");
assertEquals(expected, s.toLinkProperties(IFACE));
s.gateway = null;
expected.removeRoute(defaultRoute);
expected.removeRoute(gatewayRoute);
assertEquals(expected, s.toLinkProperties(IFACE));
// Without knowing the IP address, we don't have a directly-connected route, so we can't
// tell if the gateway is off-link or not and we don't add a host route. This isn't a real
// configuration, but we should at least not crash.
s.gateway = OFFLINKGATEWAY;
s.ipAddress = null;
expected.removeLinkAddress(ADDR);
expected.removeRoute(connectedRoute);
expected.addRoute(defaultRoute);
assertEquals(expected, s.toLinkProperties(IFACE));
}
use of android.net.IpPrefix in project android_frameworks_base by AOSPA.
the class IpPrefixTest method testContains.
@SmallTest
public void testContains() {
IpPrefix p = new IpPrefix("2001:db8:f00::ace:d00d/127");
assertTrue(p.contains(Address("2001:db8:f00::ace:d00c")));
assertTrue(p.contains(Address("2001:db8:f00::ace:d00d")));
assertFalse(p.contains(Address("2001:db8:f00::ace:d00e")));
assertFalse(p.contains(Address("2001:db8:f00::bad:d00d")));
assertFalse(p.contains(Address("2001:4868:4860::8888")));
assertFalse(p.contains(null));
assertFalse(p.contains(Address("8.8.8.8")));
p = new IpPrefix("192.0.2.0/23");
assertTrue(p.contains(Address("192.0.2.43")));
assertTrue(p.contains(Address("192.0.3.21")));
assertFalse(p.contains(Address("192.0.0.21")));
assertFalse(p.contains(Address("8.8.8.8")));
assertFalse(p.contains(Address("2001:4868:4860::8888")));
IpPrefix ipv6Default = new IpPrefix("::/0");
assertTrue(ipv6Default.contains(Address("2001:db8::f00")));
assertFalse(ipv6Default.contains(Address("192.0.2.1")));
IpPrefix ipv4Default = new IpPrefix("0.0.0.0/0");
assertTrue(ipv4Default.contains(Address("255.255.255.255")));
assertTrue(ipv4Default.contains(Address("192.0.2.1")));
assertFalse(ipv4Default.contains(Address("2001:db8::f00")));
}
use of android.net.IpPrefix in project android_frameworks_base by AOSPA.
the class IpPrefixTest method testHashCode.
@SmallTest
public void testHashCode() {
IpPrefix p;
int oldCode = -1;
Random random = new Random();
for (int i = 0; i < 100; i++) {
if (random.nextBoolean()) {
// IPv4.
byte[] b = new byte[4];
random.nextBytes(b);
p = new IpPrefix(b, random.nextInt(33));
assertNotEqual(oldCode, p.hashCode());
oldCode = p.hashCode();
} else {
// IPv6.
byte[] b = new byte[16];
random.nextBytes(b);
p = new IpPrefix(b, random.nextInt(129));
assertNotEqual(oldCode, p.hashCode());
oldCode = p.hashCode();
}
}
}
use of android.net.IpPrefix in project android_frameworks_base by AOSPA.
the class IpPrefixTest method testParceling.
public void testParceling() {
IpPrefix p;
p = new IpPrefix("2001:4860:db8::/64");
assertParcelingIsLossless(p);
p = new IpPrefix("192.0.2.0/25");
assertParcelingIsLossless(p);
}
Aggregations