1135446Strhodes/* 2254897Serwin * Copyright (C) 2004, 2005, 2007, 2011 Internet Systems Consortium, Inc. ("ISC") 3135446Strhodes * Copyright (C) 1999-2002 Internet Software Consortium. 4135446Strhodes * 5193149Sdougb * Permission to use, copy, modify, and/or 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 18254897Serwin/* $Id: interfacemgr.h,v 1.35 2011/07/28 23:47:58 tbox 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 */ 68254897Serwin#define MAX_UDP_DISPATCH 128 /*%< Maximum number of UDP dispatchers 69254897Serwin to start per interface */ 70170222Sdougb/*% The nameserver interface structure */ 71135446Strhodesstruct ns_interface { 72170222Sdougb unsigned int magic; /*%< Magic number. */ 73170222Sdougb ns_interfacemgr_t * mgr; /*%< Interface manager. */ 74135446Strhodes isc_mutex_t lock; 75170222Sdougb int references; /*%< Locked */ 76170222Sdougb unsigned int generation; /*%< Generation number. */ 77170222Sdougb isc_sockaddr_t addr; /*%< Address and port. */ 78170222Sdougb unsigned int flags; /*%< Interface characteristics */ 79170222Sdougb char name[32]; /*%< Null terminated. */ 80254897Serwin dns_dispatch_t * udpdispatch[MAX_UDP_DISPATCH]; 81254897Serwin /*%< UDP dispatchers. */ 82170222Sdougb isc_socket_t * tcpsocket; /*%< TCP socket. */ 83170222Sdougb int ntcptarget; /*%< Desired number of concurrent 84170222Sdougb TCP accepts */ 85170222Sdougb int ntcpcurrent; /*%< Current ditto, locked */ 86254897Serwin int nudpdispatch; /*%< Number of UDP dispatches */ 87170222Sdougb ns_clientmgr_t * clientmgr; /*%< Client manager. */ 88135446Strhodes ISC_LINK(ns_interface_t) link; 89135446Strhodes}; 90135446Strhodes 91135446Strhodes/*** 92135446Strhodes *** Functions 93135446Strhodes ***/ 94135446Strhodes 95135446Strhodesisc_result_t 96135446Strhodesns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, 97135446Strhodes isc_socketmgr_t *socketmgr, 98135446Strhodes dns_dispatchmgr_t *dispatchmgr, 99135446Strhodes ns_interfacemgr_t **mgrp); 100170222Sdougb/*% 101135446Strhodes * Create a new interface manager. 102135446Strhodes * 103135446Strhodes * Initially, the new manager will not listen on any interfaces. 104135446Strhodes * Call ns_interfacemgr_setlistenon() and/or ns_interfacemgr_setlistenon6() 105135446Strhodes * to set nonempty listen-on lists. 106135446Strhodes */ 107135446Strhodes 108135446Strhodesvoid 109135446Strhodesns_interfacemgr_attach(ns_interfacemgr_t *source, ns_interfacemgr_t **target); 110135446Strhodes 111135446Strhodesvoid 112135446Strhodesns_interfacemgr_detach(ns_interfacemgr_t **targetp); 113135446Strhodes 114135446Strhodesvoid 115135446Strhodesns_interfacemgr_shutdown(ns_interfacemgr_t *mgr); 116135446Strhodes 117135446Strhodesvoid 118135446Strhodesns_interfacemgr_scan(ns_interfacemgr_t *mgr, isc_boolean_t verbose); 119170222Sdougb/*% 120135446Strhodes * Scan the operatings system's list of network interfaces 121135446Strhodes * and create listeners when new interfaces are discovered. 122135446Strhodes * Shut down the sockets for interfaces that go away. 123135446Strhodes * 124135446Strhodes * This should be called once on server startup and then 125135446Strhodes * periodically according to the 'interface-interval' option 126135446Strhodes * in named.conf. 127135446Strhodes */ 128135446Strhodes 129135446Strhodesvoid 130135446Strhodesns_interfacemgr_adjust(ns_interfacemgr_t *mgr, ns_listenlist_t *list, 131135446Strhodes isc_boolean_t verbose); 132170222Sdougb/*% 133135446Strhodes * Similar to ns_interfacemgr_scan(), but this function also tries to see the 134135446Strhodes * need for an explicit listen-on when a list element in 'list' is going to 135135446Strhodes * override an already-listening a wildcard interface. 136135446Strhodes * 137135446Strhodes * This function does not update localhost and localnets ACLs. 138135446Strhodes * 139135446Strhodes * This should be called once on server startup, after configuring views and 140135446Strhodes * zones. 141135446Strhodes */ 142135446Strhodes 143135446Strhodesvoid 144135446Strhodesns_interfacemgr_setlistenon4(ns_interfacemgr_t *mgr, ns_listenlist_t *value); 145170222Sdougb/*% 146135446Strhodes * Set the IPv4 "listen-on" list of 'mgr' to 'value'. 147135446Strhodes * The previous IPv4 listen-on list is freed. 148135446Strhodes */ 149135446Strhodes 150135446Strhodesvoid 151135446Strhodesns_interfacemgr_setlistenon6(ns_interfacemgr_t *mgr, ns_listenlist_t *value); 152170222Sdougb/*% 153135446Strhodes * Set the IPv6 "listen-on" list of 'mgr' to 'value'. 154135446Strhodes * The previous IPv6 listen-on list is freed. 155135446Strhodes */ 156135446Strhodes 157135446Strhodesdns_aclenv_t * 158135446Strhodesns_interfacemgr_getaclenv(ns_interfacemgr_t *mgr); 159135446Strhodes 160135446Strhodesvoid 161135446Strhodesns_interface_attach(ns_interface_t *source, ns_interface_t **target); 162135446Strhodes 163135446Strhodesvoid 164135446Strhodesns_interface_detach(ns_interface_t **targetp); 165135446Strhodes 166135446Strhodesvoid 167135446Strhodesns_interface_shutdown(ns_interface_t *ifp); 168170222Sdougb/*% 169135446Strhodes * Stop listening for queries on interface 'ifp'. 170135446Strhodes * May safely be called multiple times. 171135446Strhodes */ 172135446Strhodes 173135446Strhodesvoid 174135446Strhodesns_interfacemgr_dumprecursing(FILE *f, ns_interfacemgr_t *mgr); 175135446Strhodes 176170222Sdougbisc_boolean_t 177170222Sdougbns_interfacemgr_listeningon(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr); 178170222Sdougb 179135446Strhodes#endif /* NAMED_INTERFACEMGR_H */ 180