use of android.net.LinkAddress in project android_frameworks_base by ParanoidAndroid.
the class Nat464Xlat method interfaceAdded.
@Override
public void interfaceAdded(String iface) {
if (iface.equals(CLAT_INTERFACE_NAME)) {
Slog.i(TAG, "interface " + CLAT_INTERFACE_NAME + " added, mIsRunning = " + mIsRunning + " -> true");
mIsRunning = true;
// it's running on.
try {
InterfaceConfiguration config = mNMService.getInterfaceConfig(iface);
mLP.clear();
mLP.setInterfaceName(iface);
RouteInfo ipv4Default = new RouteInfo(new LinkAddress(Inet4Address.ANY, 0), null, iface);
mLP.addRoute(ipv4Default);
mLP.addLinkAddress(config.getLinkAddress());
mTracker.addStackedLink(mLP);
Slog.i(TAG, "Adding stacked link. tracker LP: " + mTracker.getLinkProperties());
} catch (RemoteException e) {
Slog.e(TAG, "Error getting link properties: " + e);
}
// Inform ConnectivityService that things have changed.
Message msg = mHandler.obtainMessage(NetworkStateTracker.EVENT_CONFIGURATION_CHANGED, mTracker.getNetworkInfo());
Slog.i(TAG, "sending message to ConnectivityService: " + msg);
msg.sendToTarget();
}
}
use of android.net.LinkAddress in project android_frameworks_base by ParanoidAndroid.
the class WifiConfigStore method copyIpSettingsFromConfig.
private LinkProperties copyIpSettingsFromConfig(WifiConfiguration config) {
LinkProperties linkProperties = new LinkProperties();
linkProperties.setInterfaceName(config.linkProperties.getInterfaceName());
for (LinkAddress linkAddr : config.linkProperties.getLinkAddresses()) {
linkProperties.addLinkAddress(linkAddr);
}
for (RouteInfo route : config.linkProperties.getRoutes()) {
linkProperties.addRoute(route);
}
for (InetAddress dns : config.linkProperties.getDnses()) {
linkProperties.addDns(dns);
}
return linkProperties;
}
use of android.net.LinkAddress in project android_frameworks_base by ParanoidAndroid.
the class WifiConfigStore method writeIpAndProxyConfigurationsOnChange.
/* Compare current and new configuration and write to file on change */
private NetworkUpdateResult writeIpAndProxyConfigurationsOnChange(WifiConfiguration currentConfig, WifiConfiguration newConfig) {
boolean ipChanged = false;
boolean proxyChanged = false;
LinkProperties linkProperties = null;
switch(newConfig.ipAssignment) {
case STATIC:
Collection<LinkAddress> currentLinkAddresses = currentConfig.linkProperties.getLinkAddresses();
Collection<LinkAddress> newLinkAddresses = newConfig.linkProperties.getLinkAddresses();
Collection<InetAddress> currentDnses = currentConfig.linkProperties.getDnses();
Collection<InetAddress> newDnses = newConfig.linkProperties.getDnses();
Collection<RouteInfo> currentRoutes = currentConfig.linkProperties.getRoutes();
Collection<RouteInfo> newRoutes = newConfig.linkProperties.getRoutes();
boolean linkAddressesDiffer = (currentLinkAddresses.size() != newLinkAddresses.size()) || !currentLinkAddresses.containsAll(newLinkAddresses);
boolean dnsesDiffer = (currentDnses.size() != newDnses.size()) || !currentDnses.containsAll(newDnses);
boolean routesDiffer = (currentRoutes.size() != newRoutes.size()) || !currentRoutes.containsAll(newRoutes);
if ((currentConfig.ipAssignment != newConfig.ipAssignment) || linkAddressesDiffer || dnsesDiffer || routesDiffer) {
ipChanged = true;
}
break;
case DHCP:
if (currentConfig.ipAssignment != newConfig.ipAssignment) {
ipChanged = true;
}
break;
case UNASSIGNED:
/* Ignore */
break;
default:
loge("Ignore invalid ip assignment during write");
break;
}
switch(newConfig.proxySettings) {
case STATIC:
ProxyProperties newHttpProxy = newConfig.linkProperties.getHttpProxy();
ProxyProperties currentHttpProxy = currentConfig.linkProperties.getHttpProxy();
if (newHttpProxy != null) {
proxyChanged = !newHttpProxy.equals(currentHttpProxy);
} else {
proxyChanged = (currentHttpProxy != null);
}
break;
case NONE:
if (currentConfig.proxySettings != newConfig.proxySettings) {
proxyChanged = true;
}
break;
case UNASSIGNED:
/* Ignore */
break;
default:
loge("Ignore invalid proxy configuration during write");
break;
}
if (!ipChanged) {
linkProperties = copyIpSettingsFromConfig(currentConfig);
} else {
currentConfig.ipAssignment = newConfig.ipAssignment;
linkProperties = copyIpSettingsFromConfig(newConfig);
log("IP config changed SSID = " + currentConfig.SSID + " linkProperties: " + linkProperties.toString());
}
if (!proxyChanged) {
linkProperties.setHttpProxy(currentConfig.linkProperties.getHttpProxy());
} else {
currentConfig.proxySettings = newConfig.proxySettings;
linkProperties.setHttpProxy(newConfig.linkProperties.getHttpProxy());
log("proxy changed SSID = " + currentConfig.SSID);
if (linkProperties.getHttpProxy() != null) {
log(" proxyProperties: " + linkProperties.getHttpProxy().toString());
}
}
if (ipChanged || proxyChanged) {
currentConfig.linkProperties = linkProperties;
writeIpAndProxyConfigurations();
sendConfiguredNetworksChangedBroadcast(currentConfig, WifiManager.CHANGE_REASON_CONFIG_CHANGE);
}
return new NetworkUpdateResult(ipChanged, proxyChanged);
}
use of android.net.LinkAddress in project android_frameworks_base by ParanoidAndroid.
the class WifiStateMachine method stopTethering.
private void stopTethering() {
checkAndSetConnectivityInstance();
/* Clear the interface config to allow dhcp correctly configure new
ip settings */
InterfaceConfiguration ifcg = null;
try {
ifcg = mNwService.getInterfaceConfig(mTetherInterfaceName);
if (ifcg != null) {
ifcg.setLinkAddress(new LinkAddress(NetworkUtils.numericToInetAddress("0.0.0.0"), 0));
mNwService.setInterfaceConfig(mTetherInterfaceName, ifcg);
}
} catch (Exception e) {
loge("Error resetting interface " + mTetherInterfaceName + ", :" + e);
}
if (mCm.untether(mTetherInterfaceName) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
loge("Untether initiate failed!");
}
}
use of android.net.LinkAddress in project platform_frameworks_base by android.
the class NetworkManagementService method getInterfaceConfig.
@Override
public InterfaceConfiguration getInterfaceConfig(String iface) {
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
final NativeDaemonEvent event;
try {
event = mConnector.execute("interface", "getcfg", iface);
} catch (NativeDaemonConnectorException e) {
throw e.rethrowAsParcelableException();
}
event.checkCode(InterfaceGetCfgResult);
// Rsp: 213 xx:xx:xx:xx:xx:xx yyy.yyy.yyy.yyy zzz flag1 flag2 flag3
final StringTokenizer st = new StringTokenizer(event.getMessage());
InterfaceConfiguration cfg;
try {
cfg = new InterfaceConfiguration();
cfg.setHardwareAddress(st.nextToken(" "));
InetAddress addr = null;
int prefixLength = 0;
try {
addr = NetworkUtils.numericToInetAddress(st.nextToken());
} catch (IllegalArgumentException iae) {
Slog.e(TAG, "Failed to parse ipaddr", iae);
}
try {
prefixLength = Integer.parseInt(st.nextToken());
} catch (NumberFormatException nfe) {
Slog.e(TAG, "Failed to parse prefixLength", nfe);
}
cfg.setLinkAddress(new LinkAddress(addr, prefixLength));
while (st.hasMoreTokens()) {
cfg.setFlag(st.nextToken());
}
} catch (NoSuchElementException nsee) {
throw new IllegalStateException("Invalid response from daemon: " + event);
}
return cfg;
}
Aggregations