1 /* $NetBSD: interfacemgr.h,v 1.6 2014/12/10 04:37:52 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2004, 2005, 2007, 2011, 2013, 2014 Internet Systems Consortium, Inc. ("ISC") 5 * Copyright (C) 1999-2002 Internet Software Consortium. 6 * 7 * Permission to use, copy, modify, and/or distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /* Id: interfacemgr.h,v 1.35 2011/07/28 23:47:58 tbox Exp */ 21 22 #ifndef NAMED_INTERFACEMGR_H 23 #define NAMED_INTERFACEMGR_H 1 24 25 /***** 26 ***** Module Info 27 *****/ 28 29 /*! \file 30 * \brief 31 * The interface manager monitors the operating system's list 32 * of network interfaces, creating and destroying listeners 33 * as needed. 34 * 35 * Reliability: 36 *\li No impact expected. 37 * 38 * Resources: 39 * 40 * Security: 41 * \li The server will only be able to bind to the DNS port on 42 * newly discovered interfaces if it is running as root. 43 * 44 * Standards: 45 *\li The API for scanning varies greatly among operating systems. 46 * This module attempts to hide the differences. 47 */ 48 49 /*** 50 *** Imports 51 ***/ 52 53 #include <isc/magic.h> 54 #include <isc/mem.h> 55 #include <isc/socket.h> 56 57 #include <dns/result.h> 58 59 #include <named/listenlist.h> 60 #include <named/types.h> 61 62 /*** 63 *** Types 64 ***/ 65 66 #define IFACE_MAGIC ISC_MAGIC('I',':','-',')') 67 #define NS_INTERFACE_VALID(t) ISC_MAGIC_VALID(t, IFACE_MAGIC) 68 69 #define NS_INTERFACEFLAG_ANYADDR 0x01U /*%< bound to "any" address */ 70 #define MAX_UDP_DISPATCH 128 /*%< Maximum number of UDP dispatchers 71 to start per interface */ 72 /*% The nameserver interface structure */ 73 struct ns_interface { 74 unsigned int magic; /*%< Magic number. */ 75 ns_interfacemgr_t * mgr; /*%< Interface manager. */ 76 isc_mutex_t lock; 77 int references; /*%< Locked */ 78 unsigned int generation; /*%< Generation number. */ 79 isc_sockaddr_t addr; /*%< Address and port. */ 80 unsigned int flags; /*%< Interface characteristics */ 81 char name[32]; /*%< Null terminated. */ 82 dns_dispatch_t * udpdispatch[MAX_UDP_DISPATCH]; 83 /*%< UDP dispatchers. */ 84 isc_socket_t * tcpsocket; /*%< TCP socket. */ 85 isc_dscp_t dscp; /*%< "listen-on" DSCP value */ 86 int ntcptarget; /*%< Desired number of concurrent 87 TCP accepts */ 88 int ntcpcurrent; /*%< Current ditto, locked */ 89 int nudpdispatch; /*%< Number of UDP dispatches */ 90 ns_clientmgr_t * clientmgr; /*%< Client manager. */ 91 ISC_LINK(ns_interface_t) link; 92 }; 93 94 /*** 95 *** Functions 96 ***/ 97 98 isc_result_t 99 ns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, 100 isc_socketmgr_t *socketmgr, 101 dns_dispatchmgr_t *dispatchmgr, 102 isc_task_t *task, ns_interfacemgr_t **mgrp); 103 /*% 104 * Create a new interface manager. 105 * 106 * Initially, the new manager will not listen on any interfaces. 107 * Call ns_interfacemgr_setlistenon() and/or ns_interfacemgr_setlistenon6() 108 * to set nonempty listen-on lists. 109 */ 110 111 void 112 ns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target); 113 114 void 115 ns_interfacemgr_detach(ns_interfacemgr_t **targetp); 116 117 void 118 ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr); 119 120 void 121 ns_interfacemgr_scan(ns_interfacemgr_t *mgr, isc_boolean_t verbose); 122 /*% 123 * Scan the operatings system's list of network interfaces 124 * and create listeners when new interfaces are discovered. 125 * Shut down the sockets for interfaces that go away. 126 * 127 * This should be called once on server startup and then 128 * periodically according to the 'interface-interval' option 129 * in named.conf. 130 */ 131 132 void 133 ns_interfacemgr_adjust(ns_interfacemgr_t *mgr, ns_listenlist_t *list, 134 isc_boolean_t verbose); 135 /*% 136 * Similar to ns_interfacemgr_scan(), but this function also tries to see the 137 * need for an explicit listen-on when a list element in 'list' is going to 138 * override an already-listening a wildcard interface. 139 * 140 * This function does not update localhost and localnets ACLs. 141 * 142 * This should be called once on server startup, after configuring views and 143 * zones. 144 */ 145 146 void 147 ns_interfacemgr_setlistenon4(ns_interfacemgr_t *mgr, ns_listenlist_t *value); 148 /*% 149 * Set the IPv4 "listen-on" list of 'mgr' to 'value'. 150 * The previous IPv4 listen-on list is freed. 151 */ 152 153 void 154 ns_interfacemgr_setlistenon6(ns_interfacemgr_t *mgr, ns_listenlist_t *value); 155 /*% 156 * Set the IPv6 "listen-on" list of 'mgr' to 'value'. 157 * The previous IPv6 listen-on list is freed. 158 */ 159 160 dns_aclenv_t * 161 ns_interfacemgr_getaclenv(ns_interfacemgr_t *mgr); 162 163 void 164 ns_interface_attach(ns_interface_t *source, ns_interface_t **target); 165 166 void 167 ns_interface_detach(ns_interface_t **targetp); 168 169 void 170 ns_interface_shutdown(ns_interface_t *ifp); 171 /*% 172 * Stop listening for queries on interface 'ifp'. 173 * May safely be called multiple times. 174 */ 175 176 void 177 ns_interfacemgr_dumprecursing(FILE *f, ns_interfacemgr_t *mgr); 178 179 isc_boolean_t 180 ns_interfacemgr_listeningon(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr); 181 182 #endif /* NAMED_INTERFACEMGR_H */ 183