interfacemgr.h revision 170223
1/*
2 * Copyright (C) 2004, 2005  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.26.18.4 2005/04/27 05:00:35 sra 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
69/*% The nameserver interface structure */
70struct 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
92isc_result_t
93ns_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
105void
106ns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target);
107
108void
109ns_interfacemgr_detach(ns_interfacemgr_t **targetp);
110
111void
112ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr);
113
114void
115ns_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
126void
127ns_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
140void
141ns_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
147void
148ns_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
154dns_aclenv_t *
155ns_interfacemgr_getaclenv(ns_interfacemgr_t *mgr);
156
157void
158ns_interface_attach(ns_interface_t *source, ns_interface_t **target);
159
160void
161ns_interface_detach(ns_interface_t **targetp);
162
163void
164ns_interface_shutdown(ns_interface_t *ifp);
165/*%
166 * Stop listening for queries on interface 'ifp'.
167 * May safely be called multiple times.
168 */
169
170void
171ns_interfacemgr_dumprecursing(FILE *f, ns_interfacemgr_t *mgr);
172
173isc_boolean_t
174ns_interfacemgr_listeningon(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr);
175
176#endif /* NAMED_INTERFACEMGR_H */
177