Search in sources :

Example 6 with LinkAddress

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();
    }
}
Also used : LinkAddress(android.net.LinkAddress) Message(android.os.Message) RouteInfo(android.net.RouteInfo) RemoteException(android.os.RemoteException) InterfaceConfiguration(android.net.InterfaceConfiguration)

Example 7 with LinkAddress

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;
}
Also used : LinkAddress(android.net.LinkAddress) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Example 8 with LinkAddress

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);
}
Also used : LinkAddress(android.net.LinkAddress) ProxyProperties(android.net.ProxyProperties) NetworkUpdateResult(android.net.wifi.NetworkUpdateResult) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Example 9 with LinkAddress

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!");
    }
}
Also used : LinkAddress(android.net.LinkAddress) InterfaceConfiguration(android.net.InterfaceConfiguration) RemoteException(android.os.RemoteException)

Example 10 with LinkAddress

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;
}
Also used : LinkAddress(android.net.LinkAddress) StringTokenizer(java.util.StringTokenizer) InterfaceConfiguration(android.net.InterfaceConfiguration) InetAddress(java.net.InetAddress) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

LinkAddress (android.net.LinkAddress)210 LinkProperties (android.net.LinkProperties)70 InetAddress (java.net.InetAddress)70 RouteInfo (android.net.RouteInfo)52 SmallTest (android.test.suitebuilder.annotation.SmallTest)29 RemoteException (android.os.RemoteException)27 Inet4Address (java.net.Inet4Address)24 InterfaceConfiguration (android.net.InterfaceConfiguration)22 Inet6Address (java.net.Inet6Address)21 IpPrefix (android.net.IpPrefix)20 StaticIpConfiguration (android.net.StaticIpConfiguration)20 IOException (java.io.IOException)15 ApfFilter (android.net.apf.ApfFilter)12 ByteBuffer (java.nio.ByteBuffer)12 ProxyInfo (android.net.ProxyInfo)10 VpnConfig (com.android.internal.net.VpnConfig)10 DhcpResults (android.net.DhcpResults)9 LargeTest (android.test.suitebuilder.annotation.LargeTest)9 Command (com.android.server.NativeDaemonConnector.Command)9 EOFException (java.io.EOFException)6