Search in sources :

Example 86 with LinkAddress

use of android.net.LinkAddress in project android_frameworks_base by crdroidandroid.

the class ApfFilter method setLinkProperties.

public synchronized void setLinkProperties(LinkProperties lp) {
    // NOTE: Do not keep a copy of LinkProperties as it would further duplicate state.
    final LinkAddress ipv4Address = findIPv4LinkAddress(lp);
    final byte[] addr = (ipv4Address != null) ? ipv4Address.getAddress().getAddress() : null;
    final int prefix = (ipv4Address != null) ? ipv4Address.getPrefixLength() : 0;
    if ((prefix == mIPv4PrefixLength) && Arrays.equals(addr, mIPv4Address)) {
        return;
    }
    mIPv4Address = addr;
    mIPv4PrefixLength = prefix;
    installNewProgramLocked();
}
Also used : LinkAddress(android.net.LinkAddress)

Example 87 with LinkAddress

use of android.net.LinkAddress in project android_frameworks_base by crdroidandroid.

the class IpManager method clearIPv4Address.

private void clearIPv4Address() {
    try {
        final InterfaceConfiguration ifcg = new InterfaceConfiguration();
        ifcg.setLinkAddress(new LinkAddress("0.0.0.0/0"));
        mNwService.setInterfaceConfig(mInterfaceName, ifcg);
    } catch (IllegalStateException | RemoteException e) {
        Log.e(mTag, "ALERT: Failed to clear IPv4 address on interface " + mInterfaceName, e);
    }
}
Also used : LinkAddress(android.net.LinkAddress) RemoteException(android.os.RemoteException) InterfaceConfiguration(android.net.InterfaceConfiguration)

Example 88 with LinkAddress

use of android.net.LinkAddress in project android_frameworks_base by crdroidandroid.

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)

Example 89 with LinkAddress

use of android.net.LinkAddress in project android_frameworks_base by crdroidandroid.

the class NetworkManagementService method setInterfaceConfig.

@Override
public void setInterfaceConfig(String iface, InterfaceConfiguration cfg) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    LinkAddress linkAddr = cfg.getLinkAddress();
    if (linkAddr == null || linkAddr.getAddress() == null) {
        throw new IllegalStateException("Null LinkAddress given");
    }
    final Command cmd = new Command("interface", "setcfg", iface, linkAddr.getAddress().getHostAddress(), linkAddr.getPrefixLength());
    for (String flag : cfg.getFlags()) {
        cmd.appendArg(flag);
    }
    try {
        mConnector.execute(cmd);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : LinkAddress(android.net.LinkAddress) Command(com.android.server.NativeDaemonConnector.Command)

Example 90 with LinkAddress

use of android.net.LinkAddress in project android_frameworks_base by crdroidandroid.

the class NetworkManagementService method addLegacyRouteForNetId.

@Override
public void addLegacyRouteForNetId(int netId, RouteInfo routeInfo, int uid) {
    mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
    final Command cmd = new Command("network", "route", "legacy", uid, "add", netId);
    // create triplet: interface dest-ip-addr/prefixlength gateway-ip-addr
    final LinkAddress la = routeInfo.getDestinationLinkAddress();
    cmd.appendArg(routeInfo.getInterface());
    cmd.appendArg(la.getAddress().getHostAddress() + "/" + la.getPrefixLength());
    if (routeInfo.hasGateway()) {
        cmd.appendArg(routeInfo.getGateway().getHostAddress());
    }
    try {
        mConnector.execute(cmd);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : LinkAddress(android.net.LinkAddress) Command(com.android.server.NativeDaemonConnector.Command)

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