189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk/*
289c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * Copyright (C) 2011 The Android Open Source Project
389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk *
489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * Licensed under the Apache License, Version 2.0 (the "License");
589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * you may not use this file except in compliance with the License.
689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * You may obtain a copy of the License at
789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk *
889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk *      http://www.apache.org/licenses/LICENSE-2.0
989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk *
1089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * Unless required by applicable law or agreed to in writing, software
1189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * distributed under the License is distributed on an "AS IS" BASIS,
1289c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * See the License for the specific language governing permissions and
1489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk * limitations under the License.
1589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk */
1689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
1789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk#define LOG_TAG "ResolverController"
1889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk#define DBG 0
1989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
2089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk#include <cutils/log.h>
2189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
22970274a61800e047430d81269df977de9dbe45efElliott Hughes#include <net/if.h>
234da10dd08f12002c3821c5d4ceba302daae33e03David 'Digit' Turner
244da10dd08f12002c3821c5d4ceba302daae33e03David 'Digit' Turner// NOTE: <resolv_iface.h> is a private C library header that provides
254da10dd08f12002c3821c5d4ceba302daae33e03David 'Digit' Turner//       declarations for _resolv_set_default_iface() and others.
264da10dd08f12002c3821c5d4ceba302daae33e03David 'Digit' Turner#include <resolv_iface.h>
2789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
2889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk#include "ResolverController.h"
2989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
3089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falkint ResolverController::setDefaultInterface(const char* iface) {
3189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    if (DBG) {
327b984e3f7e724f8a3547a707210319f3d479f261Steve Block        ALOGD("setDefaultInterface iface = %s\n", iface);
3389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    }
3489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
3589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    _resolv_set_default_iface(iface);
3689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
3789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    return 0;
3889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk}
3989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
40dd3e46758b500d5e8c61ed30f7402e8538df7e06Robert Greenwaltint ResolverController::setInterfaceDnsServers(const char* iface, const char* domains,
41dd3e46758b500d5e8c61ed30f7402e8538df7e06Robert Greenwalt        char** servers, int numservers) {
4289c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    if (DBG) {
437b984e3f7e724f8a3547a707210319f3d479f261Steve Block        ALOGD("setInterfaceDnsServers iface = %s\n", iface);
4489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    }
45dd3e46758b500d5e8c61ed30f7402e8538df7e06Robert Greenwalt    _resolv_set_nameservers_for_iface(iface, servers, numservers, domains);
4689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
4789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    return 0;
4889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk}
4989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
5089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falkint ResolverController::setInterfaceAddress(const char* iface, struct in_addr* addr) {
5189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    if (DBG) {
527b984e3f7e724f8a3547a707210319f3d479f261Steve Block        ALOGD("setInterfaceAddress iface = %s\n", iface);
5389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    }
5489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
5589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    _resolv_set_addr_of_iface(iface, addr);
5689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
5789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    return 0;
5889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk}
5989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
6089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falkint ResolverController::flushDefaultDnsCache() {
6189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    if (DBG) {
627b984e3f7e724f8a3547a707210319f3d479f261Steve Block        ALOGD("flushDefaultDnsCache\n");
6389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    }
6489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
6589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    _resolv_flush_cache_for_default_iface();
6689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
6789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    return 0;
6889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk}
6989c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
7089c1e975f0c03997808d35c7be10b244c5309f9fMattias Falkint ResolverController::flushInterfaceDnsCache(const char* iface) {
7189c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    if (DBG) {
727b984e3f7e724f8a3547a707210319f3d479f261Steve Block        ALOGD("flushInterfaceDnsCache iface = %s\n", iface);
7389c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    }
7489c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
7589c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    _resolv_flush_cache_for_iface(iface);
7689c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk
7789c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk    return 0;
7889c1e975f0c03997808d35c7be10b244c5309f9fMattias Falk}
792d4610ec34cc78799a3353638fa05ee53276892aMattias Falk
802d4610ec34cc78799a3353638fa05ee53276892aMattias Falkint ResolverController::setDnsInterfaceForPid(const char* iface, int pid) {
812d4610ec34cc78799a3353638fa05ee53276892aMattias Falk    if (DBG) {
822d4610ec34cc78799a3353638fa05ee53276892aMattias Falk        ALOGD("setDnsIfaceForPid iface = %s, pid = %d\n", iface, pid);
832d4610ec34cc78799a3353638fa05ee53276892aMattias Falk    }
842d4610ec34cc78799a3353638fa05ee53276892aMattias Falk
852d4610ec34cc78799a3353638fa05ee53276892aMattias Falk    _resolv_set_iface_for_pid(iface, pid);
862d4610ec34cc78799a3353638fa05ee53276892aMattias Falk
872d4610ec34cc78799a3353638fa05ee53276892aMattias Falk    return 0;
882d4610ec34cc78799a3353638fa05ee53276892aMattias Falk}
892d4610ec34cc78799a3353638fa05ee53276892aMattias Falk
902d4610ec34cc78799a3353638fa05ee53276892aMattias Falkint ResolverController::clearDnsInterfaceForPid(int pid) {
912d4610ec34cc78799a3353638fa05ee53276892aMattias Falk    if (DBG) {
922d4610ec34cc78799a3353638fa05ee53276892aMattias Falk        ALOGD("clearDnsIfaceForPid pid = %d\n", pid);
932d4610ec34cc78799a3353638fa05ee53276892aMattias Falk    }
942d4610ec34cc78799a3353638fa05ee53276892aMattias Falk
952d4610ec34cc78799a3353638fa05ee53276892aMattias Falk    _resolv_clear_iface_for_pid(pid);
962d4610ec34cc78799a3353638fa05ee53276892aMattias Falk
972d4610ec34cc78799a3353638fa05ee53276892aMattias Falk    return 0;
982d4610ec34cc78799a3353638fa05ee53276892aMattias Falk}
99