2 * Copyright (C) 2004, 2005, 2007, 2011 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2002 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: interfacemgr.h,v 1.35 2011/07/28 23:47:58 tbox Exp $ */
20 #ifndef NAMED_INTERFACEMGR_H
21 #define NAMED_INTERFACEMGR_H 1
29 * The interface manager monitors the operating system's list
30 * of network interfaces, creating and destroying listeners
34 *\li No impact expected.
39 * \li The server will only be able to bind to the DNS port on
40 * newly discovered interfaces if it is running as root.
43 *\li The API for scanning varies greatly among operating systems.
44 * This module attempts to hide the differences.
51 #include <isc/magic.h>
53 #include <isc/socket.h>
55 #include <dns/result.h>
57 #include <named/listenlist.h>
58 #include <named/types.h>
64 #define IFACE_MAGIC ISC_MAGIC('I',':','-',')')
65 #define NS_INTERFACE_VALID(t) ISC_MAGIC_VALID(t, IFACE_MAGIC)
67 #define NS_INTERFACEFLAG_ANYADDR 0x01U /*%< bound to "any" address */
68 #define MAX_UDP_DISPATCH 128 /*%< Maximum number of UDP dispatchers
69 to start per interface */
70 /*% The nameserver interface structure */
72 unsigned int magic; /*%< Magic number. */
73 ns_interfacemgr_t * mgr; /*%< Interface manager. */
75 int references; /*%< Locked */
76 unsigned int generation; /*%< Generation number. */
77 isc_sockaddr_t addr; /*%< Address and port. */
78 unsigned int flags; /*%< Interface characteristics */
79 char name[32]; /*%< Null terminated. */
80 dns_dispatch_t * udpdispatch[MAX_UDP_DISPATCH];
81 /*%< UDP dispatchers. */
82 isc_socket_t * tcpsocket; /*%< TCP socket. */
83 int ntcptarget; /*%< Desired number of concurrent
85 int ntcpcurrent; /*%< Current ditto, locked */
86 int nudpdispatch; /*%< Number of UDP dispatches */
87 ns_clientmgr_t * clientmgr; /*%< Client manager. */
88 ISC_LINK(ns_interface_t) link;
96 ns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
97 isc_socketmgr_t *socketmgr,
98 dns_dispatchmgr_t *dispatchmgr,
99 ns_interfacemgr_t **mgrp);
101 * Create a new interface manager.
103 * Initially, the new manager will not listen on any interfaces.
104 * Call ns_interfacemgr_setlistenon() and/or ns_interfacemgr_setlistenon6()
105 * to set nonempty listen-on lists.
109 ns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target);
112 ns_interfacemgr_detach(ns_interfacemgr_t **targetp);
115 ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr);
118 ns_interfacemgr_scan(ns_interfacemgr_t *mgr, isc_boolean_t verbose);
120 * Scan the operatings system's list of network interfaces
121 * and create listeners when new interfaces are discovered.
122 * Shut down the sockets for interfaces that go away.
124 * This should be called once on server startup and then
125 * periodically according to the 'interface-interval' option
130 ns_interfacemgr_adjust(ns_interfacemgr_t *mgr, ns_listenlist_t *list,
131 isc_boolean_t verbose);
133 * Similar to ns_interfacemgr_scan(), but this function also tries to see the
134 * need for an explicit listen-on when a list element in 'list' is going to
135 * override an already-listening a wildcard interface.
137 * This function does not update localhost and localnets ACLs.
139 * This should be called once on server startup, after configuring views and
144 ns_interfacemgr_setlistenon4(ns_interfacemgr_t *mgr, ns_listenlist_t *value);
146 * Set the IPv4 "listen-on" list of 'mgr' to 'value'.
147 * The previous IPv4 listen-on list is freed.
151 ns_interfacemgr_setlistenon6(ns_interfacemgr_t *mgr, ns_listenlist_t *value);
153 * Set the IPv6 "listen-on" list of 'mgr' to 'value'.
154 * The previous IPv6 listen-on list is freed.
158 ns_interfacemgr_getaclenv(ns_interfacemgr_t *mgr);
161 ns_interface_attach(ns_interface_t *source, ns_interface_t **target);
164 ns_interface_detach(ns_interface_t **targetp);
167 ns_interface_shutdown(ns_interface_t *ifp);
169 * Stop listening for queries on interface 'ifp'.
170 * May safely be called multiple times.
174 ns_interfacemgr_dumprecursing(FILE *f, ns_interfacemgr_t *mgr);
177 ns_interfacemgr_listeningon(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr);
179 #endif /* NAMED_INTERFACEMGR_H */