use of android.net.RouteInfo in project android_frameworks_base by DirtyUnicorns.
the class IpManager method assembleLinkProperties.
private LinkProperties assembleLinkProperties() {
// [1] Create a new LinkProperties object to populate.
LinkProperties newLp = new LinkProperties();
newLp.setInterfaceName(mInterfaceName);
// [2] Pull in data from netlink:
// - IPv4 addresses
// - IPv6 addresses
// - IPv6 routes
// - IPv6 DNS servers
//
// N.B.: this is fundamentally race-prone and should be fixed by
// changing NetlinkTracker from a hybrid edge/level model to an
// edge-only model, or by giving IpManager its own netlink socket(s)
// so as to track all required information directly.
LinkProperties netlinkLinkProperties = mNetlinkTracker.getLinkProperties();
newLp.setLinkAddresses(netlinkLinkProperties.getLinkAddresses());
for (RouteInfo route : netlinkLinkProperties.getRoutes()) {
newLp.addRoute(route);
}
addAllReachableDnsServers(newLp, netlinkLinkProperties.getDnsServers());
// to worry about concurrent modification.
if (mDhcpResults != null) {
for (RouteInfo route : mDhcpResults.getRoutes(mInterfaceName)) {
newLp.addRoute(route);
}
addAllReachableDnsServers(newLp, mDhcpResults.dnsServers);
newLp.setDomains(mDhcpResults.domains);
if (mDhcpResults.mtu != 0) {
newLp.setMtu(mDhcpResults.mtu);
}
}
// [4] Add in TCP buffer sizes and HTTP Proxy config, if available.
if (!TextUtils.isEmpty(mTcpBufferSizes)) {
newLp.setTcpBufferSizes(mTcpBufferSizes);
}
if (mHttpProxy != null) {
newLp.setHttpProxy(mHttpProxy);
}
if (VDBG) {
Log.d(mTag, "newLp{" + newLp + "}");
}
return newLp;
}
use of android.net.RouteInfo in project android_frameworks_base by DirtyUnicorns.
the class IpReachabilityMonitor method updateLinkProperties.
public void updateLinkProperties(LinkProperties lp) {
if (!mInterfaceName.equals(lp.getInterfaceName())) {
// TODO: figure out whether / how to cope with interface changes.
Log.wtf(TAG, "requested LinkProperties interface '" + lp.getInterfaceName() + "' does not match: " + mInterfaceName);
return;
}
synchronized (mLock) {
mLinkProperties = new LinkProperties(lp);
Map<InetAddress, Short> newIpWatchList = new HashMap<>();
final List<RouteInfo> routes = mLinkProperties.getRoutes();
for (RouteInfo route : routes) {
if (route.hasGateway()) {
InetAddress gw = route.getGateway();
if (isOnLink(routes, gw)) {
newIpWatchList.put(gw, getNeighborStateLocked(gw));
}
}
}
for (InetAddress nameserver : lp.getDnsServers()) {
if (isOnLink(routes, nameserver)) {
newIpWatchList.put(nameserver, getNeighborStateLocked(nameserver));
}
}
mIpWatchList = newIpWatchList;
mIpWatchListVersion++;
}
if (DBG) {
Log.d(TAG, "watch: " + describeWatchList());
}
}
use of android.net.RouteInfo in project android_frameworks_base by DirtyUnicorns.
the class IpReachabilityMonitor method handleNeighborLost.
private void handleNeighborLost(String msg) {
InetAddress ip = null;
final ProvisioningChange delta;
synchronized (mLock) {
LinkProperties whatIfLp = new LinkProperties(mLinkProperties);
for (Map.Entry<InetAddress, Short> entry : mIpWatchList.entrySet()) {
if (entry.getValue() != StructNdMsg.NUD_FAILED) {
continue;
}
ip = entry.getKey();
for (RouteInfo route : mLinkProperties.getRoutes()) {
if (ip.equals(route.getGateway())) {
whatIfLp.removeRoute(route);
}
}
if (avoidingBadLinks() || !(ip instanceof Inet6Address)) {
// We should do this unconditionally, but alas we cannot: b/31827713.
whatIfLp.removeDnsServer(ip);
}
}
delta = LinkProperties.compareProvisioning(mLinkProperties, whatIfLp);
}
if (delta == ProvisioningChange.LOST_PROVISIONING) {
final String logMsg = "FAILURE: LOST_PROVISIONING, " + msg;
Log.w(TAG, logMsg);
if (mCallback != null) {
// TODO: remove |ip| when the callback signature no longer has
// an InetAddress argument.
mCallback.notifyLost(ip, logMsg);
}
}
logNudFailed(delta);
}
use of android.net.RouteInfo in project android_frameworks_base by DirtyUnicorns.
the class LinkPropertiesTest method testIsProvisioned.
@SmallTest
public void testIsProvisioned() {
LinkProperties lp4 = new LinkProperties();
assertFalse("v4only:empty", lp4.isProvisioned());
lp4.addLinkAddress(LINKADDRV4);
assertFalse("v4only:addr-only", lp4.isProvisioned());
lp4.addDnsServer(DNS1);
assertFalse("v4only:addr+dns", lp4.isProvisioned());
lp4.addRoute(new RouteInfo(GATEWAY1));
assertTrue("v4only:addr+dns+route", lp4.isProvisioned());
assertTrue("v4only:addr+dns+route", lp4.isIPv4Provisioned());
assertFalse("v4only:addr+dns+route", lp4.isIPv6Provisioned());
LinkProperties lp6 = new LinkProperties();
assertFalse("v6only:empty", lp6.isProvisioned());
lp6.addLinkAddress(LINKADDRV6LINKLOCAL);
assertFalse("v6only:fe80-only", lp6.isProvisioned());
lp6.addDnsServer(DNS6);
assertFalse("v6only:fe80+dns", lp6.isProvisioned());
lp6.addRoute(new RouteInfo(GATEWAY61));
assertFalse("v6only:fe80+dns+route", lp6.isProvisioned());
lp6.addLinkAddress(LINKADDRV6);
assertTrue("v6only:fe80+global+dns+route", lp6.isIPv6Provisioned());
assertTrue("v6only:fe80+global+dns+route", lp6.isProvisioned());
lp6.removeLinkAddress(LINKADDRV6LINKLOCAL);
assertFalse("v6only:global+dns+route", lp6.isIPv4Provisioned());
assertTrue("v6only:global+dns+route", lp6.isIPv6Provisioned());
assertTrue("v6only:global+dns+route", lp6.isProvisioned());
LinkProperties lp46 = new LinkProperties();
lp46.addLinkAddress(LINKADDRV4);
lp46.addLinkAddress(LINKADDRV6);
lp46.addDnsServer(DNS1);
lp46.addDnsServer(DNS6);
assertFalse("dualstack:missing-routes", lp46.isProvisioned());
lp46.addRoute(new RouteInfo(GATEWAY1));
assertTrue("dualstack:v4-provisioned", lp46.isIPv4Provisioned());
assertFalse("dualstack:v4-provisioned", lp46.isIPv6Provisioned());
assertTrue("dualstack:v4-provisioned", lp46.isProvisioned());
lp46.addRoute(new RouteInfo(GATEWAY61));
assertTrue("dualstack:both-provisioned", lp46.isIPv4Provisioned());
assertTrue("dualstack:both-provisioned", lp46.isIPv6Provisioned());
assertTrue("dualstack:both-provisioned", lp46.isProvisioned());
// A link with an IPv6 address and default route, but IPv4 DNS server.
LinkProperties mixed = new LinkProperties();
mixed.addLinkAddress(LINKADDRV6);
mixed.addDnsServer(DNS1);
mixed.addRoute(new RouteInfo(GATEWAY61));
assertFalse("mixed:addr6+route6+dns4", mixed.isIPv4Provisioned());
assertFalse("mixed:addr6+route6+dns4", mixed.isIPv6Provisioned());
assertFalse("mixed:addr6+route6+dns4", mixed.isProvisioned());
}
use of android.net.RouteInfo in project android_frameworks_base by DirtyUnicorns.
the class LinkPropertiesTest method testCompareProvisioning.
@SmallTest
public void testCompareProvisioning() {
LinkProperties v4lp = new LinkProperties();
v4lp.addLinkAddress(LINKADDRV4);
v4lp.addRoute(new RouteInfo(GATEWAY1));
v4lp.addDnsServer(DNS1);
assertTrue(v4lp.isProvisioned());
LinkProperties v4r = new LinkProperties(v4lp);
v4r.removeDnsServer(DNS1);
assertFalse(v4r.isProvisioned());
assertEquals(ProvisioningChange.STILL_NOT_PROVISIONED, LinkProperties.compareProvisioning(v4r, v4r));
assertEquals(ProvisioningChange.LOST_PROVISIONING, LinkProperties.compareProvisioning(v4lp, v4r));
assertEquals(ProvisioningChange.GAINED_PROVISIONING, LinkProperties.compareProvisioning(v4r, v4lp));
assertEquals(ProvisioningChange.STILL_PROVISIONED, LinkProperties.compareProvisioning(v4lp, v4lp));
// Check that losing IPv4 provisioning on a dualstack network is
// seen as a total loss of provisioning.
LinkProperties v6lp = new LinkProperties();
v6lp.addLinkAddress(LINKADDRV6);
v6lp.addRoute(new RouteInfo(GATEWAY61));
v6lp.addDnsServer(DNS6);
assertFalse(v6lp.isIPv4Provisioned());
assertTrue(v6lp.isIPv6Provisioned());
assertTrue(v6lp.isProvisioned());
LinkProperties v46lp = new LinkProperties(v6lp);
v46lp.addLinkAddress(LINKADDRV4);
v46lp.addRoute(new RouteInfo(GATEWAY1));
v46lp.addDnsServer(DNS1);
assertTrue(v46lp.isIPv4Provisioned());
assertTrue(v46lp.isIPv6Provisioned());
assertTrue(v46lp.isProvisioned());
assertEquals(ProvisioningChange.STILL_PROVISIONED, LinkProperties.compareProvisioning(v4lp, v46lp));
assertEquals(ProvisioningChange.STILL_PROVISIONED, LinkProperties.compareProvisioning(v6lp, v46lp));
assertEquals(ProvisioningChange.LOST_PROVISIONING, LinkProperties.compareProvisioning(v46lp, v6lp));
assertEquals(ProvisioningChange.LOST_PROVISIONING, LinkProperties.compareProvisioning(v46lp, v4lp));
// Check that losing and gaining a secondary router does not change
// the provisioning status.
LinkProperties v6lp2 = new LinkProperties(v6lp);
v6lp2.addRoute(new RouteInfo(GATEWAY62));
assertTrue(v6lp2.isProvisioned());
assertEquals(ProvisioningChange.STILL_PROVISIONED, LinkProperties.compareProvisioning(v6lp2, v6lp));
assertEquals(ProvisioningChange.STILL_PROVISIONED, LinkProperties.compareProvisioning(v6lp, v6lp2));
}
Aggregations