client.c revision 50f93634353f94a3bf54d10c42fe0eb1c7f35a68
ddad35552931651426ad70912d29d9ab7d2a8d80Automatic Updater * Copyright (C) 1999 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#define TCP_CLIENT(c) (((c)->attributes & NS_CLIENTATTR_TCP) != 0)
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews /* Unlocked. */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein unsigned int magic;
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews /* Locked by lock. */
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington#define MANAGER_MAGIC 0x4E53436DU /* NSCm */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graffstatic void clientmgr_destroy(ns_clientmgr_t *manager);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Important note!
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews * All client state changes, other than that from idle to listening, occur
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews * as a result of events. This guarantees serialization and avoids the
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * need for locking.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * If a routine is ever created that allows someone other than the client's
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff * task to change the client, then the client will have to be locked.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinstatic inline void
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_dispatch_removerequest(client->dispatch,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (client->state == ns_clientstate_reading)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mem_put(client->mctx, client, sizeof *client);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_boolean_t need_clientmgr_destroy = ISC_FALSE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (manager->nclients == 0 && manager->exiting)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ISC_LIST_UNLINK(manager->clients, client, link);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉client_shutdown(isc_task_t *task, isc_event_t *event) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(event->type == ISC_TASKEVENT_SHUTDOWN);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static void client_read(ns_client_t *client);
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graffstatic void client_accept(ns_client_t *client);
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graffns_client_next(ns_client_t *client, isc_result_t result) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(client->state == ns_clientstate_listening ||
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 client->state == ns_clientstate_working);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * XXXRTH If result != ISC_R_SUCCESS:
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Log result if there is interest in doing so.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 INSIST(dns_rdataset_isassociated(client->opt));
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington dns_message_puttemprdataset(client->message, &client->opt);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff dns_message_reset(client->message, DNS_MESSAGE_INTENTPARSE);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff dns_dispatch_freeevent(client->dispatch, client->dispentry,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinclient_senddone(isc_task_t *task, isc_event_t *event) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_socketevent_t *sevent = (isc_socketevent_t *)event;
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews REQUIRE(sevent->type == ISC_SOCKEVENT_SENDDONE);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_mempool_put(client->sendbufs, sevent->region.base);
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * If all of its sendbufs buffers were busy, the client might be
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews * waiting for one to become available.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (client->state == ns_clientstate_waiting) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /* XXXRTH need to add exit draining mode. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 unsigned char *data;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 data = isc_mempool_get(client->sendbufs);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * We couldn't get memory, but there is at least one
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * send outstanding. We arrange to be restarted when a
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff * send completes.
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff INSIST(client->state == ns_clientstate_working);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * XXXRTH The following doesn't deal with TSIGs, TCP buffer resizing,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * or ENDS1 more data packets.
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff * XXXRTH "tcpbuffer" is a hack to get things working.
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff isc_buffer_init(&tcpbuffer, data, SEND_BUFFER_SIZE,
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff isc_buffer_init(&buffer, data + 2, SEND_BUFFER_SIZE - 2,
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews isc_buffer_init(&buffer, data, bufsize, ISC_BUFFERTYPE_BINARY);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_renderbegin(client->message, &buffer);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = dns_message_setopt(client->message, client->opt);
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson * XXXRTH dns_message_setopt() should probably do this...
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff result = dns_message_rendersection(client->message,
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington result = dns_message_rendersection(client->message,
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff result = dns_message_rendersection(client->message,
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson client->message->flags |= DNS_MESSAGEFLAG_TC;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff result = dns_message_rendersection(client->message,
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (result != ISC_R_SUCCESS && result != ISC_R_NOSPACE)
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence result = dns_message_renderend(client->message);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff isc_buffer_putuint16(&tcpbuffer, (isc_uint16_t)r.length);
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson socket = dns_dispatch_getsocket(client->dispatch);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff result = isc_socket_sendto(socket, &r, client->task, client_senddone,
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graffns_client_error(ns_client_t *client, isc_result_t result) {
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff * message may be an in-progress reply that we had trouble
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff * with, in which case QR will be set. We need to clear QR before
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * calling dns_message_reply() to avoid triggering an assertion.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * AA and AD shouldn't be set.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 message->flags &= ~(DNS_MESSAGEFLAG_AA | DNS_MESSAGEFLAG_AD);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_reply(message, ISC_TRUE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * It could be that we've got a query with a good header,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * but a bad question section, so we try again with
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * want_question_section set to ISC_FALSE.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_reply(message, ISC_FALSE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * There's no hope of replying to this request.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * XXXRTH Mark this client to that if it is a
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * TCP session, the session will be closed.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(client->opt == NULL); /* XXXRTH free old. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_gettemprdatalist(client->message, &rdatalist);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_gettemprdata(client->message, &rdata);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_gettemprdataset(client->message, &rdataset);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Set Maximum UDP buffer size.
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews * Set EXTENDED-RCODE, VERSION, and Z to 0.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * No ENDS options.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_rdatalist_tordataset(rdatalist, rdataset);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉client_request(isc_task_t *task, isc_event_t *event) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(event->type == DNS_EVENT_TCPMSG);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(event->sender == &client->tcpmsg);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (isc_stdtime_get(&client->requesttime) != ISC_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_message_parse(client->message, buffer, ISC_FALSE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 INSIST((client->message->flags & DNS_MESSAGEFLAG_QR) == 0);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Deal with EDNS.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 opt = dns_message_getopt(client->message);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Set the client's UDP buffer size.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Create an OPT for our reply.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Do we understand this version of ENDS?
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * XXXRTH need library support for this!
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff * XXXRTH View list management code will be moving to its own module
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 RWLOCK(&ns_g_viewlock, isc_rwlocktype_read);
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews * XXXRTH View matching will become more powerful later.
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews if (client->message->rdclass == view->rdclass) {
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson RWUNLOCK(&ns_g_viewlock, isc_rwlocktype_read);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * Dispatch the request.
c17c59662f0969a5e52e8b7529cbde1a7c746095Andreas Gustafssonclient_timeout(isc_task_t *task, isc_event_t *event) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graffclient_create(ns_clientmgr_t *manager, ns_clienttype_t type,
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff * Caller must be holding the manager lock.
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff * Note: creating a client does not add the client to the manager's
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff * client list. The caller is responsible for that.
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff client = isc_mem_get(manager->mctx, sizeof *client);
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington result = isc_task_create(manager->taskmgr, manager->mctx, 0,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = isc_task_onshutdown(client->task, client_shutdown, client);
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington result = isc_timer_create(manager->timermgr, isc_timertype_inactive,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = dns_message_create(manager->mctx, DNS_MESSAGE_INTENTPARSE,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /* XXXRTH Hardwired constants */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = isc_mempool_create(manager->mctx, SEND_BUFFER_SIZE,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mempool_setfreemax(client->sendbufs, 3);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mempool_setmaxalloc(client->sendbufs, 3);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * We call the init routines for the various kinds of client here,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * after we have created an otherwise valid client, because some
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * of them call routines that REQUIRE(NS_CLIENT_VALID(client)).
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mem_put(manager->mctx, client, sizeof *client);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_tcpmsg_readmessage(&client->tcpmsg, client->task,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉client_newconn(isc_task_t *task, isc_event_t *event) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_socket_newconnev_t *nevent = (isc_socket_newconnev_t *)event;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(event->type == ISC_SOCKEVENT_NEWCONN);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_tcpmsg_init(client->mctx, client->tcpsocket,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * XXXRTH What should we do? We're trying to accept but
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * it didn't work. If we just give up, then TCP
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * service may eventually stop.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * For now, we just go idle.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Going idle is probably the right thing if the
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * I/O was canceled.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = isc_socket_accept(client->tcplistener, client->task,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "isc_socket_accept() failed: %s",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * XXXRTH What should we do? We're trying to accept but
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * it didn't work. If we just give up, then TCP
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * service may eventually stop.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * For now, we just go idle.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *** Client Manager
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉clientmgr_destroy(ns_clientmgr_t *manager) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(ISC_LIST_EMPTY(manager->clients));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mem_put(manager->mctx, manager, sizeof *manager);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉ns_clientmgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_timermgr_t *timermgr, ns_clientmgr_t **managerp)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 manager = isc_mem_get(mctx, sizeof *manager);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mem_put(manager->mctx, manager, sizeof *manager);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graffns_clientmgr_destroy(ns_clientmgr_t **managerp) {
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff for (client = ISC_LIST_HEAD(manager->clients);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffns_clientmgr_addtodispatch(ns_clientmgr_t *manager, unsigned int n,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff unsigned int i;
3d181bc9f12154a56bfbb536198a6c481cbcd525David Lawrence * We MUST lock the manager lock for the entire client creation
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * process. If we didn't do this, then a client could get a
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * shutdown event and disappear out from under us.
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff for (i = 0; i < n; i++) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = client_create(manager, ns_clienttype_basic,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dns_dispatch_attach(dispatch, &client->dispatch);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff result = dns_dispatch_addrequest(dispatch, client->task,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ISC_LIST_APPEND(manager->clients, client, link);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * We managed to create at least one client, so we
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * declare victory.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉ns_clientmgr_accepttcp(ns_clientmgr_t *manager, isc_socket_t *socket,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 unsigned int n)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 unsigned int i;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * This does not represent the planned method for TCP support,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * because we are dedicating a few clients to servicing TCP requests
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * instead of allocating TCP clients from a pool and applying quotas.
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff * All this will be fixed later, but this code will allow parts of
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * the server that need TCP support, e.g. IXFR and AXFR, to progress.
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff * We MUST lock the manager lock for the entire client creation
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff * process. If we didn't do this, then a client could get a
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * shutdown event and disappear out from under us.
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff for (i = 0; i < n; i++) {
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington result = client_create(manager, ns_clienttype_tcp, &client);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 client->state = ns_clientstate_listening;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_socket_attach(socket, &client->tcplistener);
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews ISC_LIST_APPEND(manager->clients, client, link);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff if (i != 0) {
f98d6edb191348477c9c5a156003df627d9bc42cBrian Wellington * We managed to create at least one client, so we
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff * declare victory.