1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#define LOG_TAG "ResolverController" 18#define DBG 0 19 20#include <cutils/log.h> 21 22#include <net/if.h> 23 24// NOTE: <resolv_iface.h> is a private C library header that provides 25// declarations for _resolv_set_default_iface() and others. 26#include <resolv_iface.h> 27 28#include "ResolverController.h" 29 30int ResolverController::setDefaultInterface(const char* iface) { 31 if (DBG) { 32 ALOGD("setDefaultInterface iface = %s\n", iface); 33 } 34 35 _resolv_set_default_iface(iface); 36 37 return 0; 38} 39 40int ResolverController::setInterfaceDnsServers(const char* iface, const char* domains, 41 const char** servers, int numservers) { 42 if (DBG) { 43 ALOGD("setInterfaceDnsServers iface = %s\n", iface); 44 } 45 _resolv_set_nameservers_for_iface(iface, servers, numservers, domains); 46 47 return 0; 48} 49 50int ResolverController::setInterfaceAddress(const char* iface, struct in_addr* addr) { 51 if (DBG) { 52 ALOGD("setInterfaceAddress iface = %s\n", iface); 53 } 54 55 _resolv_set_addr_of_iface(iface, addr); 56 57 return 0; 58} 59 60int ResolverController::flushDefaultDnsCache() { 61 if (DBG) { 62 ALOGD("flushDefaultDnsCache\n"); 63 } 64 65 _resolv_flush_cache_for_default_iface(); 66 67 return 0; 68} 69 70int ResolverController::flushInterfaceDnsCache(const char* iface) { 71 if (DBG) { 72 ALOGD("flushInterfaceDnsCache iface = %s\n", iface); 73 } 74 75 _resolv_flush_cache_for_iface(iface); 76 77 return 0; 78} 79 80int ResolverController::setDnsInterfaceForPid(const char* iface, int pid) { 81 if (DBG) { 82 ALOGD("setDnsIfaceForPid iface = %s, pid = %d\n", iface, pid); 83 } 84 85 _resolv_set_iface_for_pid(iface, pid); 86 87 return 0; 88} 89 90int ResolverController::clearDnsInterfaceForPid(int pid) { 91 if (DBG) { 92 ALOGD("clearDnsIfaceForPid pid = %d\n", pid); 93 } 94 95 _resolv_clear_iface_for_pid(pid); 96 97 return 0; 98} 99 100int ResolverController::setDnsInterfaceForUidRange(const char* iface, int uid_start, int uid_end) { 101 if (DBG) { 102 ALOGD("setDnsIfaceForUidRange iface = %s, range = [%d,%d]\n", iface, uid_start, uid_end); 103 } 104 105 return _resolv_set_iface_for_uid_range(iface, uid_start, uid_end); 106} 107 108int ResolverController::clearDnsInterfaceForUidRange(int uid_start, int uid_end) { 109 if (DBG) { 110 ALOGD("clearDnsIfaceForUidRange range = [%d,%d]\n", uid_start, uid_end); 111 } 112 113 return _resolv_clear_iface_for_uid_range(uid_start, uid_end); 114} 115 116int ResolverController::clearDnsInterfaceMappings() 117{ 118 if (DBG) { 119 ALOGD("clearInterfaceMappings\n"); 120 } 121 _resolv_clear_iface_uid_range_mapping(); 122 _resolv_clear_iface_pid_mapping(); 123 124 return 0; 125} 126