use of android.net.LinkProperties 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.LinkProperties 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.LinkProperties in project android_frameworks_base by DirtyUnicorns.
the class IpManager method handleLinkPropertiesUpdate.
// Returns false if we have lost provisioning, true otherwise.
private boolean handleLinkPropertiesUpdate(boolean sendCallbacks) {
final LinkProperties newLp = assembleLinkProperties();
if (linkPropertiesUnchanged(newLp)) {
return true;
}
final ProvisioningChange delta = setLinkProperties(newLp);
if (sendCallbacks) {
dispatchCallback(delta, newLp);
}
return (delta != ProvisioningChange.LOST_PROVISIONING);
}
use of android.net.LinkProperties in project android_frameworks_base by DirtyUnicorns.
the class ConnectivityService method updateLinkProperties.
private void updateLinkProperties(NetworkAgentInfo networkAgent, LinkProperties oldLp) {
LinkProperties newLp = networkAgent.linkProperties;
int netId = networkAgent.network.netId;
// we do anything else, make sure its LinkProperties are accurate.
if (networkAgent.clatd != null) {
networkAgent.clatd.fixupLinkProperties(oldLp);
}
updateInterfaces(newLp, oldLp, netId);
updateMtu(newLp, oldLp);
// TODO - figure out what to do for clat
// for (LinkProperties lp : newLp.getStackedLinks()) {
// updateMtu(lp, null);
// }
updateTcpBufferSizes(networkAgent);
updateRoutes(newLp, oldLp, netId);
updateDnses(newLp, oldLp, netId);
updateClat(newLp, oldLp, networkAgent);
if (isDefaultNetwork(networkAgent)) {
handleApplyDefaultProxy(newLp.getHttpProxy());
} else {
updateProxy(newLp, oldLp, networkAgent);
}
// TODO - move this check to cover the whole function
if (!Objects.equals(newLp, oldLp)) {
notifyIfacesChangedForNetworkStats();
notifyNetworkCallbacks(networkAgent, ConnectivityManager.CALLBACK_IP_CHANGED);
}
mKeepaliveTracker.handleCheckKeepalivesStillValid(networkAgent);
}
use of android.net.LinkProperties in project android_frameworks_base by DirtyUnicorns.
the class ConnectivityService method requestRouteToHostAddress.
/**
* Ensure that a network route exists to deliver traffic to the specified
* host via the specified network interface.
* @param networkType the type of the network over which traffic to the
* specified host is to be routed
* @param hostAddress the IP address of the host to which the route is
* desired
* @return {@code true} on success, {@code false} on failure
*/
@Override
public boolean requestRouteToHostAddress(int networkType, byte[] hostAddress) {
enforceChangePermission();
if (mProtectedNetworks.contains(networkType)) {
enforceConnectivityInternalPermission();
}
InetAddress addr;
try {
addr = InetAddress.getByAddress(hostAddress);
} catch (UnknownHostException e) {
if (DBG)
log("requestRouteToHostAddress got " + e.toString());
return false;
}
if (!ConnectivityManager.isNetworkTypeValid(networkType)) {
if (DBG)
log("requestRouteToHostAddress on invalid network: " + networkType);
return false;
}
NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
if (nai == null) {
if (mLegacyTypeTracker.isTypeSupported(networkType) == false) {
if (DBG)
log("requestRouteToHostAddress on unsupported network: " + networkType);
} else {
if (DBG)
log("requestRouteToHostAddress on down network: " + networkType);
}
return false;
}
DetailedState netState;
synchronized (nai) {
netState = nai.networkInfo.getDetailedState();
}
if (netState != DetailedState.CONNECTED && netState != DetailedState.CAPTIVE_PORTAL_CHECK) {
if (VDBG) {
log("requestRouteToHostAddress on down network " + "(" + networkType + ") - dropped" + " netState=" + netState);
}
return false;
}
final int uid = Binder.getCallingUid();
final long token = Binder.clearCallingIdentity();
try {
LinkProperties lp;
int netId;
synchronized (nai) {
lp = nai.linkProperties;
netId = nai.network.netId;
}
boolean ok = addLegacyRouteToHost(lp, addr, netId, uid);
if (DBG)
log("requestRouteToHostAddress ok=" + ok);
return ok;
} finally {
Binder.restoreCallingIdentity(token);
}
}
Aggregations