00001 /* 00002 * Copyright (C) 2004, 2005, 2007, 2011, 2013, 2014 Internet Systems Consortium, Inc. ("ISC") 00003 * Copyright (C) 1999-2002 Internet Software Consortium. 00004 * 00005 * Permission to use, copy, modify, and/or distribute this software for any 00006 * purpose with or without fee is hereby granted, provided that the above 00007 * copyright notice and this permission notice appear in all copies. 00008 * 00009 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 00010 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00011 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 00012 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00013 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 00014 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00015 * PERFORMANCE OF THIS SOFTWARE. 00016 */ 00017 00018 /* $Id: interfacemgr.h,v 1.35 2011/07/28 23:47:58 tbox Exp $ */ 00019 00020 #ifndef NAMED_INTERFACEMGR_H 00021 #define NAMED_INTERFACEMGR_H 1 00022 00023 /***** 00024 ***** Module Info 00025 *****/ 00026 00027 /*! \file 00028 * \brief 00029 * The interface manager monitors the operating system's list 00030 * of network interfaces, creating and destroying listeners 00031 * as needed. 00032 * 00033 * Reliability: 00034 *\li No impact expected. 00035 * 00036 * Resources: 00037 * 00038 * Security: 00039 * \li The server will only be able to bind to the DNS port on 00040 * newly discovered interfaces if it is running as root. 00041 * 00042 * Standards: 00043 *\li The API for scanning varies greatly among operating systems. 00044 * This module attempts to hide the differences. 00045 */ 00046 00047 /*** 00048 *** Imports 00049 ***/ 00050 00051 #include <isc/magic.h> 00052 #include <isc/mem.h> 00053 #include <isc/socket.h> 00054 00055 #include <dns/result.h> 00056 00057 #include <named/listenlist.h> 00058 #include <named/types.h> 00059 00060 /*** 00061 *** Types 00062 ***/ 00063 00064 #define IFACE_MAGIC ISC_MAGIC('I',':','-',')') 00065 #define NS_INTERFACE_VALID(t) ISC_MAGIC_VALID(t, IFACE_MAGIC) 00066 00067 #define NS_INTERFACEFLAG_ANYADDR 0x01U /*%< bound to "any" address */ 00068 #define MAX_UDP_DISPATCH 128 /*%< Maximum number of UDP dispatchers 00069 to start per interface */ 00070 /*% The nameserver interface structure */ 00071 struct ns_interface { 00072 unsigned int magic; /*%< Magic number. */ 00073 ns_interfacemgr_t * mgr; /*%< Interface manager. */ 00074 isc_mutex_t lock; 00075 int references; /*%< Locked */ 00076 unsigned int generation; /*%< Generation number. */ 00077 isc_sockaddr_t addr; /*%< Address and port. */ 00078 unsigned int flags; /*%< Interface characteristics */ 00079 char name[32]; /*%< Null terminated. */ 00080 dns_dispatch_t * udpdispatch[MAX_UDP_DISPATCH]; 00081 /*%< UDP dispatchers. */ 00082 isc_socket_t * tcpsocket; /*%< TCP socket. */ 00083 isc_dscp_t dscp; /*%< "listen-on" DSCP value */ 00084 int ntcptarget; /*%< Desired number of concurrent 00085 TCP accepts */ 00086 int ntcpcurrent; /*%< Current ditto, locked */ 00087 int nudpdispatch; /*%< Number of UDP dispatches */ 00088 ns_clientmgr_t * clientmgr; /*%< Client manager. */ 00089 ISC_LINK(ns_interface_t) link; 00090 }; 00091 00092 /*** 00093 *** Functions 00094 ***/ 00095 00096 isc_result_t 00097 ns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, 00098 isc_socketmgr_t *socketmgr, 00099 dns_dispatchmgr_t *dispatchmgr, 00100 isc_task_t *task, ns_interfacemgr_t **mgrp); 00101 /*% 00102 * Create a new interface manager. 00103 * 00104 * Initially, the new manager will not listen on any interfaces. 00105 * Call ns_interfacemgr_setlistenon() and/or ns_interfacemgr_setlistenon6() 00106 * to set nonempty listen-on lists. 00107 */ 00108 00109 void 00110 ns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target); 00111 00112 void 00113 ns_interfacemgr_detach(ns_interfacemgr_t **targetp); 00114 00115 void 00116 ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr); 00117 00118 isc_boolean_t 00119 ns_interfacemgr_islistening(ns_interfacemgr_t *mgr); 00120 /*% 00121 * Return if the manager is listening on any interface. It can be called 00122 * after a scan or adjust. 00123 */ 00124 00125 isc_result_t 00126 ns_interfacemgr_scan(ns_interfacemgr_t *mgr, isc_boolean_t verbose); 00127 /*% 00128 * Scan the operatings system's list of network interfaces 00129 * and create listeners when new interfaces are discovered. 00130 * Shut down the sockets for interfaces that go away. 00131 * 00132 * This should be called once on server startup and then 00133 * periodically according to the 'interface-interval' option 00134 * in named.conf. 00135 */ 00136 00137 isc_result_t 00138 ns_interfacemgr_adjust(ns_interfacemgr_t *mgr, ns_listenlist_t *list, 00139 isc_boolean_t verbose); 00140 /*% 00141 * Similar to ns_interfacemgr_scan(), but this function also tries to see the 00142 * need for an explicit listen-on when a list element in 'list' is going to 00143 * override an already-listening a wildcard interface. 00144 * 00145 * This function does not update localhost and localnets ACLs. 00146 * 00147 * This should be called once on server startup, after configuring views and 00148 * zones. 00149 */ 00150 00151 void 00152 ns_interfacemgr_setlistenon4(ns_interfacemgr_t *mgr, ns_listenlist_t *value); 00153 /*% 00154 * Set the IPv4 "listen-on" list of 'mgr' to 'value'. 00155 * The previous IPv4 listen-on list is freed. 00156 */ 00157 00158 void 00159 ns_interfacemgr_setlistenon6(ns_interfacemgr_t *mgr, ns_listenlist_t *value); 00160 /*% 00161 * Set the IPv6 "listen-on" list of 'mgr' to 'value'. 00162 * The previous IPv6 listen-on list is freed. 00163 */ 00164 00165 dns_aclenv_t * 00166 ns_interfacemgr_getaclenv(ns_interfacemgr_t *mgr); 00167 00168 void 00169 ns_interface_attach(ns_interface_t *source, ns_interface_t **target); 00170 00171 void 00172 ns_interface_detach(ns_interface_t **targetp); 00173 00174 void 00175 ns_interface_shutdown(ns_interface_t *ifp); 00176 /*% 00177 * Stop listening for queries on interface 'ifp'. 00178 * May safely be called multiple times. 00179 */ 00180 00181 void 00182 ns_interfacemgr_dumprecursing(FILE *f, ns_interfacemgr_t *mgr); 00183 00184 isc_boolean_t 00185 ns_interfacemgr_listeningon(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr); 00186 00187 #endif /* NAMED_INTERFACEMGR_H */