2 * Copyright (C) 2004, 2005, 2007 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.33 2007/06/19 23:46:59 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 */
69 /*% The nameserver interface structure */
71 unsigned int magic; /*%< Magic number. */
72 ns_interfacemgr_t * mgr; /*%< Interface manager. */
74 int references; /*%< Locked */
75 unsigned int generation; /*%< Generation number. */
76 isc_sockaddr_t addr; /*%< Address and port. */
77 unsigned int flags; /*%< Interface characteristics */
78 char name[32]; /*%< Null terminated. */
79 dns_dispatch_t * udpdispatch; /*%< UDP dispatcher. */
80 isc_socket_t * tcpsocket; /*%< TCP socket. */
81 int ntcptarget; /*%< Desired number of concurrent
83 int ntcpcurrent; /*%< Current ditto, locked */
84 ns_clientmgr_t * clientmgr; /*%< Client manager. */
85 ISC_LINK(ns_interface_t) link;
93 ns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
94 isc_socketmgr_t *socketmgr,
95 dns_dispatchmgr_t *dispatchmgr,
96 ns_interfacemgr_t **mgrp);
98 * Create a new interface manager.
100 * Initially, the new manager will not listen on any interfaces.
101 * Call ns_interfacemgr_setlistenon() and/or ns_interfacemgr_setlistenon6()
102 * to set nonempty listen-on lists.
106 ns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target);
109 ns_interfacemgr_detach(ns_interfacemgr_t **targetp);
112 ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr);
115 ns_interfacemgr_scan(ns_interfacemgr_t *mgr, isc_boolean_t verbose);
117 * Scan the operatings system's list of network interfaces
118 * and create listeners when new interfaces are discovered.
119 * Shut down the sockets for interfaces that go away.
121 * This should be called once on server startup and then
122 * periodically according to the 'interface-interval' option
127 ns_interfacemgr_adjust(ns_interfacemgr_t *mgr, ns_listenlist_t *list,
128 isc_boolean_t verbose);
130 * Similar to ns_interfacemgr_scan(), but this function also tries to see the
131 * need for an explicit listen-on when a list element in 'list' is going to
132 * override an already-listening a wildcard interface.
134 * This function does not update localhost and localnets ACLs.
136 * This should be called once on server startup, after configuring views and
141 ns_interfacemgr_setlistenon4(ns_interfacemgr_t *mgr, ns_listenlist_t *value);
143 * Set the IPv4 "listen-on" list of 'mgr' to 'value'.
144 * The previous IPv4 listen-on list is freed.
148 ns_interfacemgr_setlistenon6(ns_interfacemgr_t *mgr, ns_listenlist_t *value);
150 * Set the IPv6 "listen-on" list of 'mgr' to 'value'.
151 * The previous IPv6 listen-on list is freed.
155 ns_interfacemgr_getaclenv(ns_interfacemgr_t *mgr);
158 ns_interface_attach(ns_interface_t *source, ns_interface_t **target);
161 ns_interface_detach(ns_interface_t **targetp);
164 ns_interface_shutdown(ns_interface_t *ifp);
166 * Stop listening for queries on interface 'ifp'.
167 * May safely be called multiple times.
171 ns_interfacemgr_dumprecursing(FILE *f, ns_interfacemgr_t *mgr);
174 ns_interfacemgr_listeningon(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr);
176 #endif /* NAMED_INTERFACEMGR_H */