interfacemgr.h revision 170222
1135446Strhodes/* 2170222Sdougb * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC") 3135446Strhodes * Copyright (C) 1999-2002 Internet Software Consortium. 4135446Strhodes * 5135446Strhodes * Permission to use, copy, modify, and distribute this software for any 6135446Strhodes * purpose with or without fee is hereby granted, provided that the above 7135446Strhodes * copyright notice and this permission notice appear in all copies. 8135446Strhodes * 9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11135446Strhodes * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15135446Strhodes * PERFORMANCE OF THIS SOFTWARE. 16135446Strhodes */ 17135446Strhodes 18170222Sdougb/* $Id: interfacemgr.h,v 1.26.18.4 2005/04/27 05:00:35 sra Exp $ */ 19135446Strhodes 20135446Strhodes#ifndef NAMED_INTERFACEMGR_H 21135446Strhodes#define NAMED_INTERFACEMGR_H 1 22135446Strhodes 23135446Strhodes/***** 24135446Strhodes ***** Module Info 25135446Strhodes *****/ 26135446Strhodes 27170222Sdougb/*! \file 28170222Sdougb * \brief 29135446Strhodes * The interface manager monitors the operating system's list 30135446Strhodes * of network interfaces, creating and destroying listeners 31135446Strhodes * as needed. 32135446Strhodes * 33135446Strhodes * Reliability: 34170222Sdougb *\li No impact expected. 35135446Strhodes * 36135446Strhodes * Resources: 37135446Strhodes * 38135446Strhodes * Security: 39170222Sdougb * \li The server will only be able to bind to the DNS port on 40135446Strhodes * newly discovered interfaces if it is running as root. 41135446Strhodes * 42135446Strhodes * Standards: 43170222Sdougb *\li The API for scanning varies greatly among operating systems. 44135446Strhodes * This module attempts to hide the differences. 45135446Strhodes */ 46135446Strhodes 47135446Strhodes/*** 48135446Strhodes *** Imports 49135446Strhodes ***/ 50135446Strhodes 51135446Strhodes#include <isc/magic.h> 52135446Strhodes#include <isc/mem.h> 53135446Strhodes#include <isc/socket.h> 54135446Strhodes 55135446Strhodes#include <dns/result.h> 56135446Strhodes 57135446Strhodes#include <named/listenlist.h> 58135446Strhodes#include <named/types.h> 59135446Strhodes 60135446Strhodes/*** 61135446Strhodes *** Types 62135446Strhodes ***/ 63135446Strhodes 64135446Strhodes#define IFACE_MAGIC ISC_MAGIC('I',':','-',')') 65135446Strhodes#define NS_INTERFACE_VALID(t) ISC_MAGIC_VALID(t, IFACE_MAGIC) 66135446Strhodes 67170222Sdougb#define NS_INTERFACEFLAG_ANYADDR 0x01U /*%< bound to "any" address */ 68135446Strhodes 69170222Sdougb/*% The nameserver interface structure */ 70135446Strhodesstruct ns_interface { 71170222Sdougb unsigned int magic; /*%< Magic number. */ 72170222Sdougb ns_interfacemgr_t * mgr; /*%< Interface manager. */ 73135446Strhodes isc_mutex_t lock; 74170222Sdougb int references; /*%< Locked */ 75170222Sdougb unsigned int generation; /*%< Generation number. */ 76170222Sdougb isc_sockaddr_t addr; /*%< Address and port. */ 77170222Sdougb unsigned int flags; /*%< Interface characteristics */ 78170222Sdougb char name[32]; /*%< Null terminated. */ 79170222Sdougb dns_dispatch_t * udpdispatch; /*%< UDP dispatcher. */ 80170222Sdougb isc_socket_t * tcpsocket; /*%< TCP socket. */ 81170222Sdougb int ntcptarget; /*%< Desired number of concurrent 82170222Sdougb TCP accepts */ 83170222Sdougb int ntcpcurrent; /*%< Current ditto, locked */ 84170222Sdougb ns_clientmgr_t * clientmgr; /*%< Client manager. */ 85135446Strhodes ISC_LINK(ns_interface_t) link; 86135446Strhodes}; 87135446Strhodes 88135446Strhodes/*** 89135446Strhodes *** Functions 90135446Strhodes ***/ 91135446Strhodes 92135446Strhodesisc_result_t 93135446Strhodesns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, 94135446Strhodes isc_socketmgr_t *socketmgr, 95135446Strhodes dns_dispatchmgr_t *dispatchmgr, 96135446Strhodes ns_interfacemgr_t **mgrp); 97170222Sdougb/*% 98135446Strhodes * Create a new interface manager. 99135446Strhodes * 100135446Strhodes * Initially, the new manager will not listen on any interfaces. 101135446Strhodes * Call ns_interfacemgr_setlistenon() and/or ns_interfacemgr_setlistenon6() 102135446Strhodes * to set nonempty listen-on lists. 103135446Strhodes */ 104135446Strhodes 105135446Strhodesvoid 106135446Strhodesns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target); 107135446Strhodes 108135446Strhodesvoid 109135446Strhodesns_interfacemgr_detach(ns_interfacemgr_t **targetp); 110135446Strhodes 111135446Strhodesvoid 112135446Strhodesns_interfacemgr_shutdown(ns_interfacemgr_t *mgr); 113135446Strhodes 114135446Strhodesvoid 115135446Strhodesns_interfacemgr_scan(ns_interfacemgr_t *mgr, isc_boolean_t verbose); 116170222Sdougb/*% 117135446Strhodes * Scan the operatings system's list of network interfaces 118135446Strhodes * and create listeners when new interfaces are discovered. 119135446Strhodes * Shut down the sockets for interfaces that go away. 120135446Strhodes * 121135446Strhodes * This should be called once on server startup and then 122135446Strhodes * periodically according to the 'interface-interval' option 123135446Strhodes * in named.conf. 124135446Strhodes */ 125135446Strhodes 126135446Strhodesvoid 127135446Strhodesns_interfacemgr_adjust(ns_interfacemgr_t *mgr, ns_listenlist_t *list, 128135446Strhodes isc_boolean_t verbose); 129170222Sdougb/*% 130135446Strhodes * Similar to ns_interfacemgr_scan(), but this function also tries to see the 131135446Strhodes * need for an explicit listen-on when a list element in 'list' is going to 132135446Strhodes * override an already-listening a wildcard interface. 133135446Strhodes * 134135446Strhodes * This function does not update localhost and localnets ACLs. 135135446Strhodes * 136135446Strhodes * This should be called once on server startup, after configuring views and 137135446Strhodes * zones. 138135446Strhodes */ 139135446Strhodes 140135446Strhodesvoid 141135446Strhodesns_interfacemgr_setlistenon4(ns_interfacemgr_t *mgr, ns_listenlist_t *value); 142170222Sdougb/*% 143135446Strhodes * Set the IPv4 "listen-on" list of 'mgr' to 'value'. 144135446Strhodes * The previous IPv4 listen-on list is freed. 145135446Strhodes */ 146135446Strhodes 147135446Strhodesvoid 148135446Strhodesns_interfacemgr_setlistenon6(ns_interfacemgr_t *mgr, ns_listenlist_t *value); 149170222Sdougb/*% 150135446Strhodes * Set the IPv6 "listen-on" list of 'mgr' to 'value'. 151135446Strhodes * The previous IPv6 listen-on list is freed. 152135446Strhodes */ 153135446Strhodes 154135446Strhodesdns_aclenv_t * 155135446Strhodesns_interfacemgr_getaclenv(ns_interfacemgr_t *mgr); 156135446Strhodes 157135446Strhodesvoid 158135446Strhodesns_interface_attach(ns_interface_t *source, ns_interface_t **target); 159135446Strhodes 160135446Strhodesvoid 161135446Strhodesns_interface_detach(ns_interface_t **targetp); 162135446Strhodes 163135446Strhodesvoid 164135446Strhodesns_interface_shutdown(ns_interface_t *ifp); 165170222Sdougb/*% 166135446Strhodes * Stop listening for queries on interface 'ifp'. 167135446Strhodes * May safely be called multiple times. 168135446Strhodes */ 169135446Strhodes 170135446Strhodesvoid 171135446Strhodesns_interfacemgr_dumprecursing(FILE *f, ns_interfacemgr_t *mgr); 172135446Strhodes 173170222Sdougbisc_boolean_t 174170222Sdougbns_interfacemgr_listeningon(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr); 175170222Sdougb 176135446Strhodes#endif /* NAMED_INTERFACEMGR_H */ 177