]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/bind9/bin/named/include/named/interfacemgr.h
MFC r363988:
[FreeBSD/stable/9.git] / contrib / bind9 / bin / named / include / named / interfacemgr.h
1 /*
2  * Copyright (C) 2004, 2005, 2007, 2011  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2002  Internet Software Consortium.
4  *
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.
8  *
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.
16  */
17
18 /* $Id: interfacemgr.h,v 1.35 2011/07/28 23:47:58 tbox Exp $ */
19
20 #ifndef NAMED_INTERFACEMGR_H
21 #define NAMED_INTERFACEMGR_H 1
22
23 /*****
24  ***** Module Info
25  *****/
26
27 /*! \file
28  * \brief
29  * The interface manager monitors the operating system's list
30  * of network interfaces, creating and destroying listeners
31  * as needed.
32  *
33  * Reliability:
34  *\li   No impact expected.
35  *
36  * Resources:
37  *
38  * Security:
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.
41  *
42  * Standards:
43  *\li   The API for scanning varies greatly among operating systems.
44  *      This module attempts to hide the differences.
45  */
46
47 /***
48  *** Imports
49  ***/
50
51 #include <isc/magic.h>
52 #include <isc/mem.h>
53 #include <isc/socket.h>
54
55 #include <dns/result.h>
56
57 #include <named/listenlist.h>
58 #include <named/types.h>
59
60 /***
61  *** Types
62  ***/
63
64 #define IFACE_MAGIC             ISC_MAGIC('I',':','-',')')
65 #define NS_INTERFACE_VALID(t)   ISC_MAGIC_VALID(t, IFACE_MAGIC)
66
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 */
71 struct ns_interface {
72         unsigned int            magic;          /*%< Magic number. */
73         ns_interfacemgr_t *     mgr;            /*%< Interface manager. */
74         isc_mutex_t             lock;
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
84                                                      TCP accepts */
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;
89 };
90
91 /***
92  *** Functions
93  ***/
94
95 isc_result_t
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);
100 /*%
101  * Create a new interface manager.
102  *
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.
106  */
107
108 void
109 ns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target);
110
111 void
112 ns_interfacemgr_detach(ns_interfacemgr_t **targetp);
113
114 void
115 ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr);
116
117 void
118 ns_interfacemgr_scan(ns_interfacemgr_t *mgr, isc_boolean_t verbose);
119 /*%
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.
123  *
124  * This should be called once on server startup and then
125  * periodically according to the 'interface-interval' option
126  * in named.conf.
127  */
128
129 void
130 ns_interfacemgr_adjust(ns_interfacemgr_t *mgr, ns_listenlist_t *list,
131                        isc_boolean_t verbose);
132 /*%
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.
136  *
137  * This function does not update localhost and localnets ACLs.
138  *
139  * This should be called once on server startup, after configuring views and
140  * zones.
141  */
142
143 void
144 ns_interfacemgr_setlistenon4(ns_interfacemgr_t *mgr, ns_listenlist_t *value);
145 /*%
146  * Set the IPv4 "listen-on" list of 'mgr' to 'value'.
147  * The previous IPv4 listen-on list is freed.
148  */
149
150 void
151 ns_interfacemgr_setlistenon6(ns_interfacemgr_t *mgr, ns_listenlist_t *value);
152 /*%
153  * Set the IPv6 "listen-on" list of 'mgr' to 'value'.
154  * The previous IPv6 listen-on list is freed.
155  */
156
157 dns_aclenv_t *
158 ns_interfacemgr_getaclenv(ns_interfacemgr_t *mgr);
159
160 void
161 ns_interface_attach(ns_interface_t *source, ns_interface_t **target);
162
163 void
164 ns_interface_detach(ns_interface_t **targetp);
165
166 void
167 ns_interface_shutdown(ns_interface_t *ifp);
168 /*%
169  * Stop listening for queries on interface 'ifp'.
170  * May safely be called multiple times.
171  */
172
173 void
174 ns_interfacemgr_dumprecursing(FILE *f, ns_interfacemgr_t *mgr);
175
176 isc_boolean_t
177 ns_interfacemgr_listeningon(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr);
178
179 #endif /* NAMED_INTERFACEMGR_H */