interfacemgr.h 3.63 KB
Newer Older
1
/*
Bob Halley's avatar
Bob Halley committed
2
 * Copyright (C) 1999, 2000  Internet Software Consortium.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
 * 
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

#ifndef NS_INTERFACEMGR_H
#define NS_INTERFACEMGR_H 1

/*****
 ***** Module Info
 *****/

/*
 * Interface manager
 *
 * The interface manager monitors the operating system's list 
 * of network interfaces, creating and destroying listeners 
 * as needed.
 *
 * Reliability:
 *	No impact expected.
 *
 * Resources:
 *
 * Security:
 * 	The server will only be able to bind to the DNS port on
 *	newly discovered interfaces if it is running as root.
 *
 * Standards:
 *	The API for scanning varies greatly among operating systems.
 *	This module attempts to hide the differences.
 */

/***
 *** Imports
 ***/

Bob Halley's avatar
update  
Bob Halley committed
50
#include <isc/types.h>
51 52
#include <isc/result.h>
#include <isc/mem.h>
Bob Halley's avatar
update  
Bob Halley committed
53
#include <isc/socket.h>
54 55 56

#include <dns/result.h>

57
#include <named/listenlist.h>
58 59
#include <named/types.h>

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
/***
 *** Types
 ***/

#define IFACE_MAGIC		0x493A2D29U	/* I:-). */	
#define NS_INTERFACE_VALID(t)	((t) != NULL && (t)->magic == IFACE_MAGIC)

struct ns_interface {
	unsigned int		magic;		/* Magic number. */
	ns_interfacemgr_t *	mgr;		/* Interface manager. */
	isc_mutex_t		lock;
	int			references;	/* Locked */
	unsigned int		generation;     /* Generation number. */
	isc_sockaddr_t		addr;           /* Address and port. */
	isc_socket_t *		udpsocket; 	/* UDP socket. */
	dns_dispatch_t *	udpdispatch;	/* UDP dispatcher. */
	isc_socket_t *		tcpsocket;	/* TCP socket. */
	isc_task_t *		task;
78 79
	int			ntcptarget;	/* Desired number of concurrent
						   TCP accepts */
80 81 82 83
	int			ntcpcurrent;	/* Current ditto, locked */
	ISC_LINK(ns_interface_t) link;
};

84 85 86 87
/***
 *** Functions
 ***/

88

Bob Halley's avatar
update  
Bob Halley committed
89
isc_result_t
90
ns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
Bob Halley's avatar
update  
Bob Halley committed
91
		       isc_socketmgr_t *socketmgr, ns_clientmgr_t *clientmgr,
92 93
		       ns_interfacemgr_t **mgrp);

94 95 96 97 98 99 100 101 102 103
void
ns_interfacemgr_attach(ns_interfacemgr_t *source,
		       ns_interfacemgr_t **target);

void 
ns_interfacemgr_detach(ns_interfacemgr_t **targetp);

void
ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr);

Bob Halley's avatar
update  
Bob Halley committed
104
void
105 106 107 108 109 110 111 112 113 114 115
ns_interfacemgr_scan(ns_interfacemgr_t *mgr);
/*
 * Scan the operatings system's list of network interfaces
 * and create listeners when new interfaces are discovered.
 * Shut down the sockets for interfaces that go away.
 *
 * This should be called once on server startup and then
 * periodically according to the 'interface-interval' option
 * in named.conf.
 */

116 117 118 119 120 121 122
void
ns_interfacemgr_setlistenon(ns_interfacemgr_t *mgr,
			    ns_listenlist_t *value);
/*
 * Set the "listen-on" list of 'mgr' to 'value'.
 * The previous listen-on list is freed.
 */
123

124 125 126 127 128 129 130 131
isc_result_t
ns_interfacemgr_findudpdispatcher(ns_interfacemgr_t *mgr,
				  isc_sockaddr_t *address,
				  dns_dispatch_t **dispatchp);
/*
 * Find a UDP dispatcher matching 'address', if it exists.
 */

132
void
133 134 135 136 137
ns_interface_attach(ns_interface_t *source,
		    ns_interface_t **target);

void 
ns_interface_detach(ns_interface_t **targetp);
138 139

#endif /* NS_INTERFACEMGR_H */