Merge from vendor branch FILE:
[dragonfly.git] / contrib / bind-9.3 / bin / named / include / named / interfacemgr.h
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2002  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and 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.23.24.7 2004/04/29 01:31:22 marka Exp $ */
19
20 #ifndef NAMED_INTERFACEMGR_H
21 #define NAMED_INTERFACEMGR_H 1
22
23 /*****
24  ***** Module Info
25  *****/
26
27 /*
28  * Interface manager
29  *
30  * The interface manager monitors the operating system's list
31  * of network interfaces, creating and destroying listeners
32  * as needed.
33  *
34  * Reliability:
35  *      No impact expected.
36  *
37  * Resources:
38  *
39  * Security:
40  *      The server will only be able to bind to the DNS port on
41  *      newly discovered interfaces if it is running as root.
42  *
43  * Standards:
44  *      The API for scanning varies greatly among operating systems.
45  *      This module attempts to hide the differences.
46  */
47
48 /***
49  *** Imports
50  ***/
51
52 #include <isc/magic.h>
53 #include <isc/mem.h>
54 #include <isc/socket.h>
55
56 #include <dns/result.h>
57
58 #include <named/listenlist.h>
59 #include <named/types.h>
60
61 /***
62  *** Types
63  ***/
64
65 #define IFACE_MAGIC             ISC_MAGIC('I',':','-',')')
66 #define NS_INTERFACE_VALID(t)   ISC_MAGIC_VALID(t, IFACE_MAGIC)
67
68 #define NS_INTERFACEFLAG_ANYADDR        0x01U   /* bound to "any" address */
69
70 struct ns_interface {
71         unsigned int            magic;          /* Magic number. */
72         ns_interfacemgr_t *     mgr;            /* Interface manager. */
73         isc_mutex_t             lock;
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
82                                                    TCP accepts */
83         int                     ntcpcurrent;    /* Current ditto, locked */
84         ns_clientmgr_t *        clientmgr;      /* Client manager. */
85         ISC_LINK(ns_interface_t) link;
86 };
87
88 /***
89  *** Functions
90  ***/
91
92 isc_result_t
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);
97 /*
98  * Create a new interface manager.
99  *
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.
103  */
104
105 void
106 ns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target);
107
108 void
109 ns_interfacemgr_detach(ns_interfacemgr_t **targetp);
110
111 void
112 ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr);
113
114 void
115 ns_interfacemgr_scan(ns_interfacemgr_t *mgr, isc_boolean_t verbose);
116 /*
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.
120  *
121  * This should be called once on server startup and then
122  * periodically according to the 'interface-interval' option
123  * in named.conf.
124  */
125
126 void
127 ns_interfacemgr_adjust(ns_interfacemgr_t *mgr, ns_listenlist_t *list,
128                        isc_boolean_t verbose);
129 /*
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.
133  *
134  * This function does not update localhost and localnets ACLs.
135  *
136  * This should be called once on server startup, after configuring views and
137  * zones.
138  */
139
140 void
141 ns_interfacemgr_setlistenon4(ns_interfacemgr_t *mgr, ns_listenlist_t *value);
142 /*
143  * Set the IPv4 "listen-on" list of 'mgr' to 'value'.
144  * The previous IPv4 listen-on list is freed.
145  */
146
147 void
148 ns_interfacemgr_setlistenon6(ns_interfacemgr_t *mgr, ns_listenlist_t *value);
149 /*
150  * Set the IPv6 "listen-on" list of 'mgr' to 'value'.
151  * The previous IPv6 listen-on list is freed.
152  */
153
154 dns_aclenv_t *
155 ns_interfacemgr_getaclenv(ns_interfacemgr_t *mgr);
156
157 void
158 ns_interface_attach(ns_interface_t *source, ns_interface_t **target);
159
160 void
161 ns_interface_detach(ns_interface_t **targetp);
162
163 void
164 ns_interface_shutdown(ns_interface_t *ifp);
165 /*
166  * Stop listening for queries on interface 'ifp'.
167  * May safely be called multiple times.
168  */
169
170 void
171 ns_interfacemgr_dumprecursing(FILE *f, ns_interfacemgr_t *mgr);
172
173 #endif /* NAMED_INTERFACEMGR_H */