dispatch.c revision 2a0d4c4d6ba5addb33cd1bccecc55ca4a095f191
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * Copyright (C) 1999-2003 Internet Software Consortium.
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * Permission to use, copy, modify, and/or distribute this software for any
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * purpose with or without fee is hereby granted, provided that the above
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * copyright notice and this permission notice appear in all copies.
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * PERFORMANCE OF THIS SOFTWARE.
94e25967cda41b886e33ec254b917d21df21a187Bob Halley/* $Id: dispatch.c,v 1.168 2009/12/02 23:15:14 marka Exp $ */
94e25967cda41b886e33ec254b917d21df21a187Bob Halley/* ARC4 Random generator state */
94e25967cda41b886e33ec254b917d21df21a187Bob Halleytypedef struct arc4ctx {
94e25967cda41b886e33ec254b917d21df21a187Bob Halley isc_entropy_t *entropy; /*%< entropy source for ARC4 */
94e25967cda41b886e33ec254b917d21df21a187Bob Halleytypedef struct dns_qid {
94e25967cda41b886e33ec254b917d21df21a187Bob Halley unsigned int magic;
94e25967cda41b886e33ec254b917d21df21a187Bob Halley unsigned int qid_nbuckets; /*%< hash table size */
94e25967cda41b886e33ec254b917d21df21a187Bob Halley unsigned int qid_increment; /*%< id increment on collision */
94e25967cda41b886e33ec254b917d21df21a187Bob Halley dns_displist_t *qid_table; /*%< the table itself */
94e25967cda41b886e33ec254b917d21df21a187Bob Halley dispsocketlist_t *sock_table; /*%< socket table */
94e25967cda41b886e33ec254b917d21df21a187Bob Halley /* Unlocked. */
94e25967cda41b886e33ec254b917d21df21a187Bob Halley unsigned int magic;
94e25967cda41b886e33ec254b917d21df21a187Bob Halley /* Locked by "lock". */
unsigned int state;
struct dns_dispentry {
unsigned int magic;
unsigned int bucket;
void *arg;
#ifndef DNS_DISPATCH_POOLSOCKS
#ifndef DNS_DISPATCH_SOCKSQUOTA
struct dispsocket {
unsigned int magic;
unsigned int bucket;
struct dispportentry {
unsigned int refs;
#ifndef DNS_DISPATCH_PORTTABLESIZE
struct dns_dispatch {
int ntasks;
unsigned int attributes;
unsigned int nsockets;
unsigned int maxrequests,
unsigned int attributes,
msgbuf);
#ifdef BIND9
actx->s[n] = n;
actx->i = 0;
actx->j = 0;
actx->i--;
static inline isc_uint8_t
static inline isc_uint16_t
return (val);
} rnd;
static isc_uint16_t
return (result);
static isc_uint16_t
isc_uint32_t r;
isc_random_get(&r);
static isc_uint16_t
if (r >= min)
return (r % upper_bound);
static isc_uint32_t
unsigned int ret;
return (ret);
static dns_dispentry_t *
unsigned int bucket;
bucket = 0;
return (ret);
bucket++;
return (NULL);
static dns_dispentry_t *
unsigned int bucket;
return (ret);
bucket++;
return (ret);
bucket++;
return (NULL);
static isc_boolean_t
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
if (killmgr)
static dispportentry_t *
return (portentry);
return (NULL);
static dispportentry_t *
return (portentry);
return (portentry);
static dispsocket_t *
unsigned int bucket)
return (dispsock);
return (NULL);
static isc_result_t
isc_uint32_t r;
unsigned int bucket = 0;
unsigned int nports;
unsigned int bindoptions;
if (nports == 0)
return (ISC_R_ADDRNOTAVAIL);
return (ISC_R_NOMEMORY);
isc_random_get(&r);
nports)];
bindoptions = 0;
return (result);
blink);
#ifdef BIND9
blink);
static dns_dispentry_t *
return (res);
return (NULL);
case isc_sockettype_tcp:
case isc_sockettype_udp:
INSIST(0);
void *temp;
return (temp);
static inline dns_dispatchevent_t *
return (NULL);
return (ev);
unsigned int flags;
unsigned int bucket;
int match;
int result;
if (killit)
goto sendresponse;
match > 0)
sizeof(netaddrstr));
goto restart;
goto restart;
goto restart;
bucket);
goto unlock;
goto unlock;
goto unlock;
goto unlock;
goto unlock;
goto unlock;
if (queue_response) {
if (qidlocked)
unsigned int flags;
unsigned int bucket;
int level;
case ISC_R_CANCELED:
case ISC_R_EOF:
case ISC_R_CONNECTIONRESET:
goto logit;
if (killit)
goto restart;
goto restart;
goto unlock;
goto unlock;
if (queue_response) {
static isc_result_t
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
case isc_sockettype_udp:
return (ISC_R_NOMEMORY);
dispsock);
return (res);
case isc_sockettype_tcp:
INSIST(0);
return (ISC_R_SUCCESS);
static isc_boolean_t
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
#ifdef BIND9
static isc_result_t
return (result);
#ifdef BIND9
return (result);
INSIST(0);
#ifndef ISC_ALLOW_MAPPED
#ifdef BIND9
INSIST(0);
return (result);
return (ISC_R_SUCCESS);
static isc_result_t
return (result);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
goto deallocate;
goto kill_lock;
goto kill_arc4_lock;
goto kill_buffer_lock;
goto kill_pool_lock;
goto kill_epool;
goto kill_rpool;
goto kill_dpool;
#ifdef BIND9
return (ISC_R_SUCCESS);
return (result);
if (nv4ports != 0) {
return (ISC_R_NOMEMORY);
if (nv6ports != 0) {
sizeof(in_port_t) *
return (ISC_R_NOMEMORY);
i4 = 0;
i6 = 0;
return (ISC_R_SUCCESS);
static isc_result_t
unsigned int increment)
return (result);
return (ISC_R_SUCCESS);
goto cleanup;
goto cleanup;
return (ISC_R_SUCCESS);
return (result);
if (killit)
static isc_boolean_t
unsigned int nports;
goto unlock;
goto unlock;
return (available);
static isc_boolean_t
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
static isc_result_t
goto out;
out:
return (result);
static isc_result_t
return (ISC_R_NOMEMORY);
return (ISC_R_NOMEMORY);
if (needsocktable) {
sizeof(dispsocketlist_t));
return (ISC_R_NOMEMORY);
return (result);
for (i = 0; i < buckets; i++) {
return (ISC_R_SUCCESS);
static isc_result_t
return (ISC_R_NOMEMORY);
goto deallocate;
goto kill_lock;
return (ISC_R_SUCCESS);
return (result);
for (i = 0; i < DNS_DISPATCH_PORTTABLESIZE; i++)
return (result);
goto deallocate_dispatch;
goto kill_socket;
sizeof(isc_event_t));
goto kill_task;
return (ISC_R_SUCCESS);
return (result);
unsigned int buffersize,
return (result);
goto createudp;
return (ISC_R_SUCCESS);
return (result);
return (ISC_R_SUCCESS);
#ifndef DNS_DISPATCH_HELD
static isc_result_t
if (anyport) {
unsigned int nports;
if (nports == 0)
return (ISC_R_ADDRNOTAVAIL);
nports)];
0, &sock);
return (result);
return (result);
goto end;
else if (!anyport)
if (i == DNS_DISPATCH_HELD)
goto end;
end:
for (i = 0; i < DNS_DISPATCH_HELD; i++) {
return (result);
static isc_result_t
unsigned int maxrequests,
unsigned int attributes,
return (result);
goto deallocate_dispatch;
goto deallocate_dispatch;
goto deallocate_dispatch;
for (i = 0; i < DNS_DISPATCH_PORTTABLESIZE; i++)
goto deallocate_dispatch;
goto kill_socket;
sizeof(isc_event_t));
goto kill_task;
return (result);
return (result);
if (killit)
unsigned int bucket;
return (ISC_R_SHUTTINGDOWN);
return (ISC_R_QUOTA);
&localport);
return (result);
if (!ok) {
return (ISC_R_NOMORE);
return (ISC_R_NOMEMORY);
return (result);
return (ISC_R_SUCCESS);
unsigned int bucket;
if (killit)
goto unlock;
return (NULL);
return (ISC_R_SUCCESS);
return (ISC_R_NOTIMPLEMENTED);
void *buf;