Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13e817df authored by Paul Jensen's avatar Paul Jensen Committed by Lorenzo Colitti
Browse files

Use NetId instead of interface name when communicating DNS changes to netd.

Change-Id: Ic82b73de6f50d39d56c5e1a32f5b1f3ebb80bb7d
parent e4bde7d4
Loading
Loading
Loading
Loading
+5 −40
Original line number Diff line number Diff line
@@ -320,24 +320,14 @@ interface INetworkManagementService
    void removeIdleTimer(String iface);

    /**
     * Sets the name of the default interface in the DNS resolver.
     * Bind name servers to a network in the DNS resolver.
     */
    void setDefaultInterfaceForDns(String iface);
    void setDnsServersForNetwork(int netId, in String[] servers, String domains);

    /**
     * Bind name servers to an interface in the DNS resolver.
     * Flush the DNS cache associated with the specified network.
     */
    void setDnsServersForInterface(String iface, in String[] servers, String domains);

    /**
     * Flush the DNS cache associated with the default interface.
     */
    void flushDefaultDnsCache();

    /**
     * Flush the DNS cache associated with the specified interface.
     */
    void flushInterfaceDnsCache(String iface);
    void flushNetworkDnsCache(int netId);

    void setFirewallEnabled(boolean enabled);
    boolean isFirewallEnabled();
@@ -350,7 +340,7 @@ interface INetworkManagementService
     * Set all packets from users [uid_start,uid_end] to go through interface iface
     * iface must already be set for marked forwarding by {@link setMarkedForwarding}
     */
    void setUidRangeRoute(String iface, int uid_start, int uid_end);
    void setUidRangeRoute(String iface, int uid_start, int uid_end, boolean forward_dns);

    /**
     * Clears the special routing rules for users [uid_start,uid_end]
@@ -401,31 +391,6 @@ interface INetworkManagementService
     */
    void clearHostExemption(in LinkAddress host);

    /**
     * Set a process (pid) to use the name servers associated with the specified interface.
     */
    void setDnsInterfaceForPid(String iface, int pid);

    /**
     * Clear a process (pid) from being associated with an interface.
     */
    void clearDnsInterfaceForPid(int pid);

    /**
    * Set a range of user ids to use the name servers associated with the specified interface.
    */
    void setDnsInterfaceForUidRange(String iface, int uid_start, int uid_end);

    /**
    * Clear a user range from being associated with an interface.
    */
    void clearDnsInterfaceForUidRange(String iface, int uid_start, int uid_end);

    /**
    * Clear the mappings from pid to Dns interface and from uid range to Dns interface.
    */
    void clearDnsInterfaceMaps();

    /**
     * Start the clatd (464xlat) service
     */
+34 −32
Original line number Diff line number Diff line
@@ -2620,20 +2620,20 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                                }
                            }
                        }
                    } else {
                        loge("Can't reset connection for type "+netType);
                    }
                }
                if (resetDns) {
                    flushVmDnsCache();
                            if (VDBG) log("resetting DNS cache for " + iface);
                    if (VDBG) log("resetting DNS cache for type " + netType);
                    try {
                                mNetd.flushInterfaceDnsCache(iface);
                        mNetd.flushNetworkDnsCache(mNetTrackers[netType].getNetwork().netId);
                    } catch (Exception e) {
                        // never crash - catch them all
                        if (DBG) loge("Exception resetting dns cache: " + e);
                    }
                }
                    } else {
                        loge("Can't reset connection for type "+netType);
                    }
                }
            }
        }

@@ -2834,7 +2834,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                if (p == null) continue;
                if (mNetRequestersPids[i].contains(myPid)) {
                    try {
                        mNetd.setDnsInterfaceForPid(p.getInterfaceName(), pid);
                        // TODO: Reimplement this via local variable in bionic.
                        // mNetd.setDnsNetworkForPid(nt.getNetwork().netId, pid);
                    } catch (Exception e) {
                        Slog.e(TAG, "exception reasseses pid dns: " + e);
                    }
@@ -2844,7 +2845,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        }
        // nothing found - delete
        try {
            mNetd.clearDnsInterfaceForPid(pid);
            // TODO: Reimplement this via local variable in bionic.
            // mNetd.clearDnsNetworkForPid(pid);
        } catch (Exception e) {
            Slog.e(TAG, "exception clear interface from pid: " + e);
        }
@@ -2869,8 +2871,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
    }

    // Caller must grab mDnsLock.
    private void updateDnsLocked(String network, String iface,
            Collection<InetAddress> dnses, String domains, boolean defaultDns) {
    private void updateDnsLocked(String network, int netId,
            Collection<InetAddress> dnses, String domains) {
        int last = 0;
        if (dnses.size() == 0 && mDefaultDns != null) {
            dnses = new ArrayList();
@@ -2881,10 +2883,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        }

        try {
            mNetd.setDnsServersForInterface(iface, NetworkUtils.makeStrings(dnses), domains);
            if (defaultDns) {
                mNetd.setDefaultInterfaceForDns(iface);
            }
            mNetd.setDnsServersForNetwork(netId, NetworkUtils.makeStrings(dnses), domains);

            for (InetAddress dns : dnses) {
                ++last;
@@ -2909,14 +2908,15 @@ public class ConnectivityService extends IConnectivityManager.Stub {
            LinkProperties p = nt.getLinkProperties();
            if (p == null) return;
            Collection<InetAddress> dnses = p.getDnses();
            int netId = nt.getNetwork().netId;
            if (mNetConfigs[netType].isDefault()) {
                String network = nt.getNetworkInfo().getTypeName();
                synchronized (mDnsLock) {
                    updateDnsLocked(network, p.getInterfaceName(), dnses, p.getDomains(), true);
                    updateDnsLocked(network, netId, dnses, p.getDomains());
                }
            } else {
                try {
                    mNetd.setDnsServersForInterface(p.getInterfaceName(),
                    mNetd.setDnsServersForNetwork(netId,
                            NetworkUtils.makeStrings(dnses), p.getDomains());
                } catch (Exception e) {
                    if (DBG) loge("exception setting dns servers: " + e);
@@ -2925,7 +2925,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                List<Integer> pids = mNetRequestersPids[netType];
                for (Integer pid : pids) {
                    try {
                        mNetd.setDnsInterfaceForPid(p.getInterfaceName(), pid);
                        // TODO: Reimplement this via local variable in bionic.
                        // mNetd.setDnsNetworkForPid(netId, pid);
                    } catch (Exception e) {
                        Slog.e(TAG, "exception setting interface for pid: " + e);
                    }
@@ -3878,7 +3879,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {

            // Apply DNS changes.
            synchronized (mDnsLock) {
                updateDnsLocked("VPN", iface, addresses, domains, false);
                // TODO: Re-enable this when the netId of the VPN is known.
                // updateDnsLocked("VPN", netId, addresses, domains);
            }

            // Temporarily disable the default proxy (not global).
@@ -3946,21 +3948,21 @@ public class ConnectivityService extends IConnectivityManager.Stub {

        public void addUidForwarding(String interfaze, int uidStart, int uidEnd,
                boolean forwardDns) {
            try {
                mNetd.setUidRangeRoute(interfaze,uidStart, uidEnd);
                if (forwardDns) mNetd.setDnsInterfaceForUidRange(interfaze, uidStart, uidEnd);
            } catch (RemoteException e) {
            }
            // TODO: Re-enable this when the netId of the VPN is known.
            // try {
            //     mNetd.setUidRangeRoute(netId, uidStart, uidEnd, forwardDns);
            // } catch (RemoteException e) {
            // }

        }

        public void clearUidForwarding(String interfaze, int uidStart, int uidEnd,
                boolean forwardDns) {
            try {
                mNetd.clearUidRangeRoute(interfaze, uidStart, uidEnd);
                if (forwardDns) mNetd.clearDnsInterfaceForUidRange(interfaze, uidStart, uidEnd);
            } catch (RemoteException e) {
            }
            // TODO: Re-enable this when the netId of the VPN is known.
            // try {
            //     mNetd.clearUidRangeRoute(interfaze, uidStart, uidEnd);
            // } catch (RemoteException e) {
            // }

        }
    }
+7 −80
Original line number Diff line number Diff line
@@ -1616,20 +1616,10 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    }

    @Override
    public void setDefaultInterfaceForDns(String iface) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        try {
            mConnector.execute("resolver", "setdefaultif", iface);
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
    }

    @Override
    public void setDnsServersForInterface(String iface, String[] servers, String domains) {
    public void setDnsServersForNetwork(int netId, String[] servers, String domains) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);

        final Command cmd = new Command("resolver", "setifdns", iface,
        final Command cmd = new Command("resolver", "setnetdns", netId,
                (domains == null ? "" : domains));

        for (String s : servers) {
@@ -1647,11 +1637,11 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    }

    @Override
    public void setUidRangeRoute(String iface, int uid_start, int uid_end) {
    public void setUidRangeRoute(String iface, int uid_start, int uid_end, boolean forward_dns) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        try {
            mConnector.execute("interface", "fwmark",
                    "uid", "add", iface, uid_start, uid_end);
                    "uid", "add", iface, uid_start, uid_end, forward_dns ? 1 : 0);
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
@@ -1662,7 +1652,7 @@ public class NetworkManagementService extends INetworkManagementService.Stub
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        try {
            mConnector.execute("interface", "fwmark",
                    "uid", "remove", iface, uid_start, uid_end);
                    "uid", "remove", iface, uid_start, uid_end, 0);
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
@@ -1759,51 +1749,10 @@ public class NetworkManagementService extends INetworkManagementService.Stub
    }

    @Override
    public void setDnsInterfaceForUidRange(String iface, int uid_start, int uid_end) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        try {
            mConnector.execute("resolver", "setifaceforuidrange", iface, uid_start, uid_end);
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
    }

    @Override
    public void clearDnsInterfaceForUidRange(String iface, int uid_start, int uid_end) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        try {
            mConnector.execute("resolver", "clearifaceforuidrange", iface, uid_start, uid_end);
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
    }

    @Override
    public void clearDnsInterfaceMaps() {
    public void flushNetworkDnsCache(int netId) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        try {
            mConnector.execute("resolver", "clearifacemapping");
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
    }


    @Override
    public void flushDefaultDnsCache() {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        try {
            mConnector.execute("resolver", "flushdefaultif");
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
    }

    @Override
    public void flushInterfaceDnsCache(String iface) {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        try {
            mConnector.execute("resolver", "flushif", iface);
            mConnector.execute("resolver", "flushnet", netId);
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
@@ -1881,28 +1830,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub
        }
    }

    @Override
    public void setDnsInterfaceForPid(String iface, int pid) throws IllegalStateException {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        try {
            mConnector.execute("resolver", "setifaceforpid", iface, pid);
        } catch (NativeDaemonConnectorException e) {
            throw new IllegalStateException(
                    "Error communicating with native deamon to set interface for pid" + iface, e);
        }
    }

    @Override
    public void clearDnsInterfaceForPid(int pid) throws IllegalStateException {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
        try {
            mConnector.execute("resolver", "clearifaceforpid", pid);
        } catch (NativeDaemonConnectorException e) {
            throw new IllegalStateException(
                    "Error communicating with native deamon to clear interface for pid " + pid, e);
        }
    }

    @Override
    public void startClatd(String interfaceName) throws IllegalStateException {
        mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);