Search in sources :

Example 1 with LinkAddress

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

the class RouteInfoTest method testMatches.

public void testMatches() {
    class PatchedRouteInfo extends RouteInfo {

        public PatchedRouteInfo(LinkAddress destination, InetAddress gateway, String iface) {
            super(destination, gateway, iface);
        }

        public boolean matches(InetAddress destination) {
            return super.matches(destination);
        }
    }
    RouteInfo r;
    r = new PatchedRouteInfo(Prefix("2001:db8:f00::ace:d00d/127"), null, "rmnet0");
    assertTrue(r.matches(Address("2001:db8:f00::ace:d00c")));
    assertTrue(r.matches(Address("2001:db8:f00::ace:d00d")));
    assertFalse(r.matches(Address("2001:db8:f00::ace:d00e")));
    assertFalse(r.matches(Address("2001:db8:f00::bad:d00d")));
    assertFalse(r.matches(Address("2001:4868:4860::8888")));
    r = new PatchedRouteInfo(Prefix("192.0.2.0/23"), null, "wlan0");
    assertTrue(r.matches(Address("192.0.2.43")));
    assertTrue(r.matches(Address("192.0.3.21")));
    assertFalse(r.matches(Address("192.0.0.21")));
    assertFalse(r.matches(Address("8.8.8.8")));
    RouteInfo ipv6Default = new PatchedRouteInfo(Prefix("::/0"), null, "rmnet0");
    assertTrue(ipv6Default.matches(Address("2001:db8::f00")));
    assertFalse(ipv6Default.matches(Address("192.0.2.1")));
    RouteInfo ipv4Default = new PatchedRouteInfo(Prefix("0.0.0.0/0"), null, "rmnet0");
    assertTrue(ipv4Default.matches(Address("255.255.255.255")));
    assertTrue(ipv4Default.matches(Address("192.0.2.1")));
    assertFalse(ipv4Default.matches(Address("2001:db8::f00")));
}
Also used : LinkAddress(android.net.LinkAddress) RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress)

Example 2 with LinkAddress

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

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 3 with LinkAddress

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

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.getNetworkPrefixLength());
    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 4 with LinkAddress

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

the class NetworkManagementService method modifyRoute.

private void modifyRoute(String interfaceName, String action, RouteInfo route, String type) {
    final Command cmd = new Command("interface", "route", action, interfaceName, type);
    // create triplet: dest-ip-addr prefixlength gateway-ip-addr
    final LinkAddress la = route.getDestination();
    cmd.appendArg(la.getAddress().getHostAddress());
    cmd.appendArg(la.getNetworkPrefixLength());
    if (route.getGateway() == null) {
        if (la.getAddress() instanceof Inet4Address) {
            cmd.appendArg("0.0.0.0");
        } else {
            cmd.appendArg("::0");
        }
    } else {
        cmd.appendArg(route.getGateway().getHostAddress());
    }
    try {
        mConnector.execute(cmd);
    } catch (NativeDaemonConnectorException e) {
        throw e.rethrowAsParcelableException();
    }
}
Also used : LinkAddress(android.net.LinkAddress) Inet4Address(java.net.Inet4Address) Command(com.android.server.NativeDaemonConnector.Command)

Example 5 with LinkAddress

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

the class Tethering method configureUsbIface.

// configured when we start tethering and unconfig'd on error or conclusion
private boolean configureUsbIface(boolean enabled) {
    if (VDBG)
        Log.d(TAG, "configureUsbIface(" + enabled + ")");
    // toggle the USB interfaces
    String[] ifaces = new String[0];
    try {
        ifaces = mNMService.listInterfaces();
    } catch (Exception e) {
        Log.e(TAG, "Error listing Interfaces", e);
        return false;
    }
    for (String iface : ifaces) {
        if (isUsb(iface)) {
            InterfaceConfiguration ifcg = null;
            try {
                ifcg = mNMService.getInterfaceConfig(iface);
                if (ifcg != null) {
                    InetAddress addr = NetworkUtils.numericToInetAddress(USB_NEAR_IFACE_ADDR);
                    ifcg.setLinkAddress(new LinkAddress(addr, USB_PREFIX_LENGTH));
                    if (enabled) {
                        ifcg.setInterfaceUp();
                    } else {
                        ifcg.setInterfaceDown();
                    }
                    ifcg.clearFlag("running");
                    mNMService.setInterfaceConfig(iface, ifcg);
                }
            } catch (Exception e) {
                Log.e(TAG, "Error configuring interface " + iface, e);
                return false;
            }
        }
    }
    return true;
}
Also used : LinkAddress(android.net.LinkAddress) InterfaceConfiguration(android.net.InterfaceConfiguration) InetAddress(java.net.InetAddress) RemoteException(android.os.RemoteException)

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