interfacemgr.h revision 135446
1135446Strhodes/* 2135446Strhodes * Copyright (C) 2004 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 18135446Strhodes/* $Id: interfacemgr.h,v 1.23.24.7 2004/04/29 01:31:22 marka Exp $ */ 19135446Strhodes 20135446Strhodes#ifndef NAMED_INTERFACEMGR_H 21135446Strhodes#define NAMED_INTERFACEMGR_H 1 22135446Strhodes 23135446Strhodes/***** 24135446Strhodes ***** Module Info 25135446Strhodes *****/ 26135446Strhodes 27135446Strhodes/* 28135446Strhodes * Interface manager 29135446Strhodes * 30135446Strhodes * The interface manager monitors the operating system's list 31135446Strhodes * of network interfaces, creating and destroying listeners 32135446Strhodes * as needed. 33135446Strhodes * 34135446Strhodes * Reliability: 35135446Strhodes * No impact expected. 36135446Strhodes * 37135446Strhodes * Resources: 38135446Strhodes * 39135446Strhodes * Security: 40135446Strhodes * The server will only be able to bind to the DNS port on 41135446Strhodes * newly discovered interfaces if it is running as root. 42135446Strhodes * 43135446Strhodes * Standards: 44135446Strhodes * The API for scanning varies greatly among operating systems. 45135446Strhodes * This module attempts to hide the differences. 46135446Strhodes */ 47135446Strhodes 48135446Strhodes/*** 49135446Strhodes *** Imports 50135446Strhodes ***/ 51135446Strhodes 52135446Strhodes#include <isc/magic.h> 53135446Strhodes#include <isc/mem.h> 54135446Strhodes#include <isc/socket.h> 55135446Strhodes 56135446Strhodes#include <dns/result.h> 57135446Strhodes 58135446Strhodes#include <named/listenlist.h> 59135446Strhodes#include <named/types.h> 60135446Strhodes 61135446Strhodes/*** 62135446Strhodes *** Types 63135446Strhodes ***/ 64135446Strhodes 65135446Strhodes#define IFACE_MAGIC ISC_MAGIC('I',':','-',')') 66135446Strhodes#define NS_INTERFACE_VALID(t) ISC_MAGIC_VALID(t, IFACE_MAGIC) 67135446Strhodes 68135446Strhodes#define NS_INTERFACEFLAG_ANYADDR 0x01U /* bound to "any" address */ 69135446Strhodes 70135446Strhodesstruct ns_interface { 71135446Strhodes unsigned int magic; /* Magic number. */ 72135446Strhodes ns_interfacemgr_t * mgr; /* Interface manager. */ 73135446Strhodes isc_mutex_t lock; 74135446Strhodes int references; /* Locked */ 75135446Strhodes unsigned int generation; /* Generation number. */ 76135446Strhodes isc_sockaddr_t addr; /* Address and port. */ 77135446Strhodes unsigned int flags; /* Interface characteristics */ 78135446Strhodes char name[32]; /* Null terminated. */ 79135446Strhodes dns_dispatch_t * udpdispatch; /* UDP dispatcher. */ 80135446Strhodes isc_socket_t * tcpsocket; /* TCP socket. */ 81135446Strhodes int ntcptarget; /* Desired number of concurrent 82135446Strhodes TCP accepts */ 83135446Strhodes int ntcpcurrent; /* Current ditto, locked */ 84135446Strhodes 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); 97135446Strhodes/* 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); 116135446Strhodes/* 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); 129135446Strhodes/* 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); 142135446Strhodes/* 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); 149135446Strhodes/* 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); 165135446Strhodes/* 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 173135446Strhodes#endif /* NAMED_INTERFACEMGR_H */ 174