interfacemgr.c 16.1 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
 * 
 * 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.
 */

#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

#include <isc/assertions.h>
#include <isc/error.h>
#include <isc/mem.h>
#include <isc/result.h>
#include <isc/socket.h>
#include <isc/types.h>
Bob Halley's avatar
Bob Halley committed
32
#include <isc/net.h>
33
#include <isc/interfaceiter.h>
34
#include <isc/util.h>
35

36
#include <dns/acl.h>
37 38 39 40
#include <dns/dispatch.h>

#include <named/client.h>
#include <named/globals.h>
41
#include <named/listenlist.h>
42
#include <named/log.h>
43
#include <named/interfacemgr.h>
44 45

#define IFMGR_MAGIC		0x49464D47U	/* IFMG. */	
46
#define NS_INTERFACEMGR_VALID(t) ((t) != NULL && (t)->magic == IFMGR_MAGIC)
47

48 49 50
#define IFMGR_COMMON_LOGARGS \
	ns_g_lctx, NS_LOGCATEGORY_NETWORK, NS_LOGMODULE_INTERFACEMGR

51 52
struct ns_interfacemgr {
	unsigned int		magic;		/* Magic number. */
53 54
	int			references;
	isc_mutex_t		lock;
55 56 57
	isc_mem_t *		mctx;		/* Memory context. */
	isc_taskmgr_t *		taskmgr;	/* Task manager. */
	isc_socketmgr_t *	socketmgr;	/* Socket manager. */
58
	ns_clientmgr_t *	clientmgr;	/* Client manager. */
59
	unsigned int		generation;	/* Current generation no. */
60
	ns_listenlist_t *	listenon;
61 62 63
	ISC_LIST(ns_interface_t) interfaces;	/* List of interfaces. */
};

64
static void purge_old_interfaces(ns_interfacemgr_t *mgr);
65

66
isc_result_t
67
ns_interfacemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
68
		       isc_socketmgr_t *socketmgr, ns_clientmgr_t *clientmgr,
69 70
		       ns_interfacemgr_t **mgrp)
{
71
	isc_result_t result;
72
	ns_interfacemgr_t *mgr;
73

74 75 76 77 78 79 80 81
	REQUIRE(mctx != NULL);
	REQUIRE(mgrp != NULL);
	REQUIRE(*mgrp == NULL);
	
	mgr = isc_mem_get(mctx, sizeof(*mgr));
	if (mgr == NULL)
		return (DNS_R_NOMEMORY);

82
	result = isc_mutex_init(&mgr->lock);
83 84
	if (result != ISC_R_SUCCESS)
		goto cleanup;
85

86 87 88
	mgr->mctx = mctx;
	mgr->taskmgr = taskmgr;
	mgr->socketmgr = socketmgr;
89
	mgr->clientmgr = clientmgr;
90
	mgr->generation = 1;
91
	mgr->listenon = NULL;
92 93
	ISC_LIST_INIT(mgr->interfaces);

94 95 96 97 98
	result = ns_listenlist_default(mctx, ns_g_port,
				       &mgr->listenon);
	if (result != DNS_R_SUCCESS)
		goto cleanup;
	
99
	mgr->references = 1;
100 101 102
	mgr->magic = IFMGR_MAGIC;
	*mgrp = mgr;
	return (DNS_R_SUCCESS);
103 104 105 106

 cleanup:
	isc_mem_put(mctx, mgr, sizeof(*mgr));
	return (result);
107 108
}

109 110 111 112
static void
ns_interfacemgr_destroy(ns_interfacemgr_t *mgr)
{
	REQUIRE(NS_INTERFACEMGR_VALID(mgr));
113
	ns_listenlist_detach(&mgr->listenon);
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
	isc_mutex_destroy(&mgr->lock);
	mgr->magic = 0;
	isc_mem_put(mgr->mctx, mgr, sizeof *mgr);
}

void
ns_interfacemgr_attach(ns_interfacemgr_t *source,
		       ns_interfacemgr_t **target)
{
	REQUIRE(NS_INTERFACEMGR_VALID(source));
	LOCK(&source->lock);
	INSIST(source->references > 0);
	source->references++;
	UNLOCK(&source->lock);
	*target = source;
}

void 
ns_interfacemgr_detach(ns_interfacemgr_t **targetp)
{
	isc_result_t need_destroy = ISC_FALSE;
	ns_interfacemgr_t *target = *targetp;
	REQUIRE(target != NULL);
	REQUIRE(NS_INTERFACEMGR_VALID(target));
	LOCK(&target->lock);
	REQUIRE(target->references > 0);
	target->references--;
	if (target->references == 0)
		need_destroy = ISC_TRUE;
	UNLOCK(&target->lock);
	if (need_destroy)
		ns_interfacemgr_destroy(target);
	*targetp = NULL;
}

void
ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr)
{
	REQUIRE(NS_INTERFACEMGR_VALID(mgr));

	LOCK(&mgr->lock);
	/*
	 * Shut down and detach all interfaces.
	 * By incrementing the generation count, we make purge_old_interfaces()
	 * consider all interfaces "old".
	 */
	mgr->generation++;
	purge_old_interfaces(mgr);
	INSIST(ISC_LIST_EMPTY(mgr->interfaces));
	UNLOCK(&mgr->lock);	
}


167
static isc_result_t
168
ns_interface_create(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr,
169 170
		    ns_interface_t **ifpret)
{
171
        ns_interface_t *ifp;
172
	isc_result_t result;
173
	
174
	REQUIRE(NS_INTERFACEMGR_VALID(mgr));
175 176 177
	ifp = isc_mem_get(mgr->mctx, sizeof(*ifp));
	if (ifp == NULL)
		return (DNS_R_NOMEMORY);
178
	ifp->mgr = NULL;
179 180 181
	ifp->generation = mgr->generation;
	ifp->addr = *addr;

182 183 184 185
	result = isc_mutex_init(&ifp->lock);
	if (result != ISC_R_SUCCESS)
		goto lock_create_failure;

186 187 188 189 190 191
	/*
	 * Create a task.
	 */
	ifp->task = NULL;
	result = isc_task_create(mgr->taskmgr, mgr->mctx, 0, &ifp->task);
	if (result != ISC_R_SUCCESS) {
192
		isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
193 194 195 196
				 "isc_task_create() failed: %s",
				 isc_result_totext(result));
		goto task_create_failure;
	}
Bob Halley's avatar
Bob Halley committed
197
	isc_task_setname(ifp->task, "ifp", ifp);
198

199 200 201 202
	ifp->udpsocket = NULL;
	ifp->udpdispatch = NULL;
	
	ifp->tcpsocket = NULL;
203 204 205 206 207 208 209
	/*
	 * Create a single TCP client object.  It will replace itself
	 * with a new one as soon as it gets a connection, so the actual
	 * connections will be handled in parallel even though there is
	 * only one client initially.
	 */
	ifp->ntcptarget = 1;
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
	ifp->ntcpcurrent = 0;

	ns_interfacemgr_attach(mgr, &ifp->mgr);	
	ISC_LIST_APPEND(mgr->interfaces, ifp, link);

	ifp->references = 1;
	ifp->magic = IFACE_MAGIC;
	*ifpret = ifp;

	return (DNS_R_SUCCESS);

 task_create_failure:
	isc_mutex_destroy(&ifp->lock);
 lock_create_failure:
	ifp->magic = 0;
	isc_mem_put(mgr->mctx, ifp, sizeof(*ifp));

	return (DNS_R_UNEXPECTED);
}

static isc_result_t
ns_interface_listenudp(ns_interface_t *ifp) {
	isc_result_t result;
	
234 235 236
	/*
	 * Open a UDP socket.
	 */
237 238
	result = isc_socket_create(ifp->mgr->socketmgr,
				   isc_sockaddr_pf(&ifp->addr),
239 240 241
				   isc_sockettype_udp,
				   &ifp->udpsocket);
	if (result != ISC_R_SUCCESS) {
242
		isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
243 244
				 "creating UDP socket: %s",
				 isc_result_totext(result));
245 246
		goto udp_socket_failure;
	}
247 248
	result = isc_socket_bind(ifp->udpsocket, &ifp->addr);
	if (result != ISC_R_SUCCESS) {
249
		isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
250 251
				 "binding UDP socket: %s",
				 isc_result_totext(result));
252 253
		goto udp_bind_failure;
	}
254
	result = dns_dispatch_create(ifp->mgr->mctx, ifp->udpsocket, ifp->task,
255
				     4096, 1000, 32768, 8219, 8237, NULL,
256
				     &ifp->udpdispatch);
257 258 259 260 261 262
	if (result != ISC_R_SUCCESS) {
		UNEXPECTED_ERROR(__FILE__, __LINE__,
				 "UDP dns_dispatch_create(): %s",
				 isc_result_totext(result));
		goto udp_dispatch_failure;
	}
263

264 265
	result = ns_clientmgr_createclients(ifp->mgr->clientmgr, ns_g_cpus,
					    ifp, ISC_FALSE);
266 267
	if (result != ISC_R_SUCCESS) {
		UNEXPECTED_ERROR(__FILE__, __LINE__,
268
				 "UDP ns_clientmgr_createclients(): %s",
269 270 271
				 isc_result_totext(result));
		goto addtodispatch_failure;
	}
272
	return (ISC_R_SUCCESS);
273

274 275 276 277 278 279 280 281
 addtodispatch_failure:
	dns_dispatch_detach(&ifp->udpdispatch);
 udp_dispatch_failure:
 udp_bind_failure:
	isc_socket_detach(&ifp->udpsocket);
 udp_socket_failure:
	return (result);
}
282

283 284 285 286 287 288 289 290 291 292 293 294
static isc_result_t
ns_interface_accepttcp(ns_interface_t *ifp) {
	isc_result_t result;
	
	/*
	 * Open a TCP socket.
	 */
	result = isc_socket_create(ifp->mgr->socketmgr,
				   isc_sockaddr_pf(&ifp->addr),
				   isc_sockettype_tcp,
				   &ifp->tcpsocket);
	if (result != ISC_R_SUCCESS) {
295
		isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
296 297 298 299 300 301
				 "creating TCP socket: %s",
				 isc_result_totext(result));
		goto tcp_socket_failure;
	}
	result = isc_socket_bind(ifp->tcpsocket, &ifp->addr);
	if (result != ISC_R_SUCCESS) {
302
		isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
303 304 305 306 307 308
				 "binding TCP socket: %s",
				 isc_result_totext(result));
		goto tcp_bind_failure;
	}
	result = isc_socket_listen(ifp->tcpsocket, 0);
	if (result != ISC_R_SUCCESS) {
309 310
		isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR,
				 "listening on TCP socket: %s",
311 312 313
				 isc_result_totext(result));
		goto tcp_listen_failure;
	}
314 315 316 317

	result = ns_clientmgr_createclients(ifp->mgr->clientmgr,
					    ifp->ntcptarget, ifp,
					    ISC_TRUE);
318 319
	if (result != ISC_R_SUCCESS) {
		UNEXPECTED_ERROR(__FILE__, __LINE__,
320
				 "TCP ns_clientmgr_createclients(): %s",
321 322 323 324
				 isc_result_totext(result));
		goto accepttcp_failure;
	}
	return (ISC_R_SUCCESS);
325

Bob Halley's avatar
Bob Halley committed
326 327 328 329 330 331
 accepttcp_failure:
 tcp_listen_failure:
 tcp_bind_failure:
	isc_socket_detach(&ifp->tcpsocket);
 tcp_socket_failure:
	return (DNS_R_SUCCESS);
332 333
}

334
static isc_result_t
335 336 337 338 339 340 341 342 343 344
ns_interface_setup(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr,
		   ns_interface_t **ifpret)
{
	isc_result_t result;
	ns_interface_t *ifp = NULL;
	REQUIRE(ifpret != NULL && *ifpret == NULL);
	
	result = ns_interface_create(mgr, addr, &ifp);
	if (result != DNS_R_SUCCESS)
		return (result);
345

346 347 348
	result = ns_interface_listenudp(ifp);
	if (result != DNS_R_SUCCESS)
		goto cleanup_interface;
349

350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
	result = ns_interface_accepttcp(ifp);
	if (result != DNS_R_SUCCESS) {
		/*
		 * XXXRTH  We don't currently have a way to easily stop dispatch
		 * service, so we return currently return DNS_R_SUCCESS (the UDP
		 * stuff will work even if TCP creation failed).  This will be fixed
		 * later.
		 */
		result = ISC_R_SUCCESS;
	}
	*ifpret = ifp;
	return (ISC_R_SUCCESS);
	
 cleanup_interface:
	ISC_LIST_UNLINK(ifp->mgr->interfaces, ifp, link);	
	ns_interface_detach(&ifp);
	return (result);
}
368

369 370 371 372 373 374 375 376 377 378 379
static void
ns_interface_destroy(ns_interface_t *ifp) {
	isc_mem_t *mctx = ifp->mgr->mctx;
	REQUIRE(NS_INTERFACE_VALID(ifp));

	if (ifp->udpdispatch != NULL)
		dns_dispatch_detach(&ifp->udpdispatch);
	if (ifp->udpsocket != NULL) {
		isc_socket_cancel(ifp->udpsocket, NULL, ISC_SOCKCANCEL_ALL);
		isc_socket_detach(&ifp->udpsocket);
	}
380 381 382 383
	if (ifp->tcpsocket != NULL) {
		isc_socket_cancel(ifp->tcpsocket, NULL, ISC_SOCKCANCEL_ALL);
		isc_socket_detach(&ifp->tcpsocket);
	}
384

385
	isc_task_detach(&ifp->task);
386 387 388
	isc_mutex_destroy(&ifp->lock);

	ns_interfacemgr_detach(&ifp->mgr);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
389 390
	
	ifp->magic = 0;
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
	isc_mem_put(mctx, ifp, sizeof(*ifp));
}

void
ns_interface_attach(ns_interface_t *source,
		    ns_interface_t **target)
{
	REQUIRE(NS_INTERFACE_VALID(source));
	LOCK(&source->lock);
	INSIST(source->references > 0);
	source->references++;
	UNLOCK(&source->lock);
	*target = source;
}

void 
ns_interface_detach(ns_interface_t **targetp)
{
	isc_result_t need_destroy = ISC_FALSE;
	ns_interface_t *target = *targetp;
	REQUIRE(target != NULL);
	REQUIRE(NS_INTERFACE_VALID(target));
	LOCK(&target->lock);
	REQUIRE(target->references > 0);
	target->references--;
	if (target->references == 0)
		need_destroy = ISC_TRUE;
	UNLOCK(&target->lock);
	if (need_destroy)
		ns_interface_destroy(target);
	*targetp = NULL;
422 423 424 425 426 427 428 429 430 431 432
}

/*
 * Search the interface list for an interface whose address and port
 * both match those of 'addr'.  Return a pointer to it, or NULL if not found.
 */
static ns_interface_t *
find_matching_interface(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr) {
        ns_interface_t *ifp;
        for (ifp = ISC_LIST_HEAD(mgr->interfaces); ifp != NULL;
	     ifp = ISC_LIST_NEXT(ifp, link)) {
Bob Halley's avatar
Bob Halley committed
433
		if (isc_sockaddr_equal(&ifp->addr, addr))
434 435 436 437 438 439 440 441 442 443 444 445
			break;
	}
        return (ifp);
}

/*
 * Remove any interfaces whose generation number is not the current one.
 */
static void
purge_old_interfaces(ns_interfacemgr_t *mgr) {
        ns_interface_t *ifp, *next;
        for (ifp = ISC_LIST_HEAD(mgr->interfaces); ifp != NULL; ifp = next) {
446
		INSIST(NS_INTERFACE_VALID(ifp));
447
		next = ISC_LIST_NEXT(ifp, link);
448 449 450
		if (ifp->generation != mgr->generation) {
			ISC_LIST_UNLINK(ifp->mgr->interfaces, ifp, link);
			ns_interface_detach(&ifp);
451 452 453 454
		}
	}
}

455
static void
456
do_ipv4(ns_interfacemgr_t *mgr) {
457
	isc_interfaceiter_t *iter = NULL;
458
	isc_result_t result;
459

460 461 462
	result = isc_interfaceiter_create(mgr->mctx, &iter);
	if (result != ISC_R_SUCCESS)
		return;
463 464 465 466 467

	for (result = isc_interfaceiter_first(iter);
	     result == ISC_R_SUCCESS;
	     result = isc_interfaceiter_next(iter))
	{
468 469
		ns_interface_t *ifp;
		isc_interface_t interface;
470 471
		ns_listenelt_t *le;
		
472
		/*
473 474 475
		 * XXX insert code to match against named.conf
		 * "listen-on" statements here.  Also build list of
		 * local addresses and local networks.
476
		 */
477 478 479
		result = isc_interfaceiter_current(iter, &interface);
		if (result != ISC_R_SUCCESS)
			break;
480

481 482 483
		if (interface.address.family != AF_INET)
			continue;

484 485 486 487 488 489
		for (le = ISC_LIST_HEAD(mgr->listenon->elts);
		     le != NULL;
		     le = ISC_LIST_NEXT(le, link))
		{
			int match;
			isc_sockaddr_t listen_addr;
490 491
			char buf[128];
			const char *addrstr;
492

493 494 495 496 497 498 499 500 501 502 503
			/*
			 * Construct a socket address for this IP/port
			 * combination.
			 */
			isc_sockaddr_fromin(&listen_addr,
					    &interface.address.type.in,
					    le->port);

			/*
			 * Construct a human-readable version of same.
			 */
Bob Halley's avatar
Bob Halley committed
504 505 506
			addrstr = inet_ntop(listen_addr.type.sin.sin_family,
					    &listen_addr.type.sin.sin_addr,
					    buf, sizeof(buf));
507 508
			if (addrstr == NULL)
				addrstr = "(bad address)";
509 510 511 512 513 514 515 516 517 518 519 520 521 522

			/*
			 * See if the address matches the listen-on statement;
			 * if not, ignore the interface.
			 */
			result = dns_acl_match(&listen_addr, NULL,
					       le->acl, &match, NULL);
			if (match <= 0)
				continue;
			
			ifp = find_matching_interface(mgr, &listen_addr);
			if (ifp != NULL) {
				ifp->generation = mgr->generation;
			} else {
523
				isc_log_write(IFMGR_COMMON_LOGARGS,
524
					      ISC_LOG_INFO,
525 526
					      "listening on IPv4 interface "
					      "%s, %s port %u",
527
					      interface.name, addrstr,
528 529
					      ntohs(listen_addr.type.
						    sin.sin_port));
530
				
531 532
				result = ns_interface_setup(mgr,
							    &listen_addr, &ifp);
533
				if (result != DNS_R_SUCCESS) {
534 535 536 537 538
					isc_log_write(IFMGR_COMMON_LOGARGS,
						 ISC_LOG_ERROR,
						 "creating IPv4 interface %s "
						 "failed; interface ignored",
						 interface.name);
539
				}
540
				/* Continue. */
541
			}
542

543 544
		}
	}
545 546 547 548
	if (result != ISC_R_NOMORE)
		UNEXPECTED_ERROR(__FILE__, __LINE__,
				 "IPv4: interface iteration failed: %s",
				 isc_result_totext(result));
549 550

	isc_interfaceiter_destroy(&iter);
551 552 553 554 555 556 557 558 559 560
}

static void
do_ipv6(ns_interfacemgr_t *mgr) {
	isc_result_t result;
	ns_interface_t *ifp;
	isc_sockaddr_t listen_addr;
	struct in6_addr in6a;

	in6a = in6addr_any;
Bob Halley's avatar
Bob Halley committed
561
	isc_sockaddr_fromin6(&listen_addr, &in6a, ns_g_port);
562 563 564 565 566

	ifp = find_matching_interface(mgr, &listen_addr);
	if (ifp != NULL) {
		ifp->generation = mgr->generation;
	} else {
567
		isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_INFO,
Bob Halley's avatar
Bob Halley committed
568 569
			      "listening on IPv6 interfaces, port %u",
			      ns_g_port);
570 571
		result = ns_interface_setup(mgr, &listen_addr, &ifp);
		if (result != DNS_R_SUCCESS) {
572 573 574
			isc_log_write(IFMGR_COMMON_LOGARGS,
				      ISC_LOG_ERROR,			
				      "listening on IPv6 interfaces failed");
575 576
			/* Continue. */
		}
577 578 579 580 581
	}
}

void
ns_interfacemgr_scan(ns_interfacemgr_t *mgr) {
582

583
	REQUIRE(NS_INTERFACEMGR_VALID(mgr));
584 585 586

	mgr->generation++;	/* Increment the generation count. */ 

587 588 589
	if (isc_net_probeipv6() == ISC_R_SUCCESS) {
		do_ipv6(mgr);
	} else
590
		isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_INFO,
Bob Halley's avatar
Bob Halley committed
591
			      "no IPv6 interfaces found");
592
	if (isc_net_probeipv4() == ISC_R_SUCCESS)
593
		do_ipv4(mgr);
594
	else
595
		isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_INFO,
Bob Halley's avatar
Bob Halley committed
596
			      "no IPv4 interfaces found");
597 598 599 600 601 602 603 604 605 606

        /*
         * Now go through the interface list and delete anything that
         * does not have the current generation number.  This is
         * how we catch interfaces that go away or change their
         * addresses.
	 */
	purge_old_interfaces(mgr);

	if (ISC_LIST_EMPTY(mgr->interfaces)) {
607
		isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_WARNING,
Bob Halley's avatar
Bob Halley committed
608 609 610 611
			      "not listening on any interfaces");
		/*
		 * Continue anyway.
		 */
612 613
	}
}
614 615 616 617 618 619 620 621 622 623

void
ns_interfacemgr_setlistenon(ns_interfacemgr_t *mgr,
			    ns_listenlist_t *value)
{
	LOCK(&mgr->lock);
	ns_listenlist_detach(&mgr->listenon);
	ns_listenlist_attach(value, &mgr->listenon);
	UNLOCK(&mgr->lock);
}
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642

isc_result_t
ns_interfacemgr_findudpdispatcher(ns_interfacemgr_t *mgr,
				  isc_sockaddr_t *address,
				  dns_dispatch_t **dispatchp)
{
	ns_interface_t *ifp;

	/*
	 * Find a UDP dispatcher matching 'address', if it exists.
	 */

	ifp = find_matching_interface(mgr, address);
	if (ifp == NULL || ifp->udpdispatch == NULL)
		return (ISC_R_NOTFOUND);
	dns_dispatch_attach(ifp->udpdispatch, dispatchp);

	return (ISC_R_SUCCESS);
}