client.c revision ae8d0aedd64a7580dc2fc4a9cd61934527552f3b
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 1999, 2000 Internet Software Consortium.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Permission to use, copy, modify, and distribute this software for any
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Important note!
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * All client state changes, other than that from idle to listening, occur
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * as a result of events. This guarantees serialization and avoids the
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * need for locking.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * If a routine is ever created that allows someone other than the client's
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * task to change the client, then the client will have to be locked.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#define CTRACE(m) isc_log_write(ns_g_lctx, \
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#define MTRACE(m) isc_log_write(ns_g_lctx, \
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#define TCP_CLIENT(c) (((c)->attributes & NS_CLIENTATTR_TCP) != 0)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson /* Unlocked. */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson /* Locked by lock. */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson client_list_t active; /* Active clients */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson client_list_t inactive; /* To be recycled */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#define MANAGER_MAGIC 0x4E53436DU /* NSCm */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#define VALID_MANAGER(m) ((m) != NULL && \
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Client object states. Ordering is significant: higher-numbered
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * states are generally "more active", meaning that the client can
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * have more dynamically allocated data, outstanding events, etc.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * In the list below, any such properties listed for state N
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * also apply to any state > N.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * To force the client into a less active state, set client->newstate
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * to that state and call exit_check(). This will cause any
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * activities defined for higher-numbered states to be aborted.
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * The client object no longer exists.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * The client object exists and has a task and timer.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Its "query" struct and sendbuf are initialized.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * It is on the client manager's list of inactive clients.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * It has a message and OPT, both in the reset state.
42a5f9c8f535fb2a6d1cbfaa38533176e1f1667aBob Halley * The client object is either a TCP or a UDP one, and
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * it is associated with a network interface. It is on the
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * client manager's list of active clients.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * If it is a TCP client object, it has a TCP listener socket
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * and an outstading TCP listen request.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * If it is a UDP client object, it is associated with a
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * dispatch and has an outstanding dispatch request.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * The client object is a TCP client object that has received
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * a connection. It has a tcpsocket, tcpmsg, TCP quota, and an
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * outstanding TCP read request. This state is not used for
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * UDP client objects.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * The client object has received a request and is working
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * on it. It has a view, and it may have any of a non-reset OPT,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * recursion quota, and an outstanding write request. If it
68e4926b2262571e004b4be00b905ec776c01d9cMichael Graff * is a UDP client object, it has a dispatch event.
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson * Sentinel value used to indicate "no state". When client->newstate
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson * has this value, we are not attempting to exit the current state.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Must be greater than any valid state.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonstatic void client_read(ns_client_t *client);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic void client_accept(ns_client_t *client);
42a5f9c8f535fb2a6d1cbfaa38533176e1f1667aBob Halleystatic void clientmgr_destroy(ns_clientmgr_t *manager);
42a5f9c8f535fb2a6d1cbfaa38533176e1f1667aBob Halleystatic isc_boolean_t exit_check(ns_client_t *client);
42a5f9c8f535fb2a6d1cbfaa38533176e1f1667aBob Halleystatic void ns_client_endrequest(ns_client_t *client);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonstatic void ns_client_checkactive(ns_client_t *client);
544f5611e1fc84597db819d111c8fd98bb719de6Bob Halley * Format a human-readable representation of the socket address '*sa'
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * into the character array 'array', which is of size 'size'.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * The resulting string is guaranteed to be null-terminated.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonsockaddr_format(isc_sockaddr_t *sa, char *array, unsigned int size)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_init(&buf, array, size, ISC_BUFFERTYPE_TEXT);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Enter the inactive state.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * No requests are outstanding.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_dispatch_removerequest(client->dispatch,
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff ISC_LIST_UNLINK(client->manager->active, client, link);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ISC_LIST_APPEND(client->manager->inactive, client, link);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson client->list = &client->manager->inactive;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Clean up a client object and free its memory.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * The client is in the inactive state.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_boolean_t need_clientmgr_destroy = ISC_FALSE;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence * When "shuttingdown" is true, either the task has received
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * its shutdown event or no shutdown event has ever been
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence * set up. Thus, we have no outstanding shutdown
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * event at this point.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson REQUIRE(client->state == NS_CLIENTSTATE_INACTIVE);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_mem_put(client->mctx, client->sendbuf, SEND_BUFFER_SIZE);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson INSIST(dns_rdataset_isassociated(client->opt));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_message_puttemprdataset(client->message, &client->opt);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence ISC_LIST_UNLINK(*client->list, client, link);
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson isc_mem_put(client->mctx, client, sizeof *client);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonset_timeout(ns_client_t *client, unsigned int seconds) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson result = isc_timer_reset(client->timer, isc_timertype_once, NULL,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_log_write(dns_lctx, NS_LOGCATEGORY_CLIENT,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson "setting timouet: %s",
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson /* Continue anyway. */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Check for a deactivation or shutdown request and take appropriate
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * action. Returns ISC_TRUE if either is in progress; in this case
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * the caller must no longer use the client object as it may have been
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson return (ISC_FALSE); /* Business as usual. */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson INSIST(client->newstate < NS_CLIENTSTATE_WORKING);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * We need to detach from the view early when shutting down
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * the server to break the following vicious circle:
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * - The resolver will not shut down until the view refcount is zero
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * - The view refcount does not go to zero until all clients detach
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * - The client does not detach from the view until references is zero
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * - references does not go to zero until the resolver has shut down
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence if (client->newstate == NS_CLIENTSTATE_FREED && client->view != NULL)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson INSIST(client->newstate <= NS_CLIENTSTATE_READING);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * We are trying to abort request processing.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (! (client->nsends == 0 && client->references == 0)) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Still waiting for I/O cancel completion.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * or lingering references.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * I/O cancel is complete. Burn down all state
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * related to the current request.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (NS_CLIENTSTATE_READING == client->newstate) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (client->state == NS_CLIENTSTATE_READING) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * We are trying to abort the current TCP connection,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence INSIST(client->newstate <= NS_CLIENTSTATE_READY);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson /* Still waiting for read cancel completion. */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson (void) isc_timer_reset(client->timer, isc_timertype_inactive,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Now the client is ready to accept a new TCP connection
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * or UDP request, but we may have enough clients doing
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * that already. Check whether this client needs to remain
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * active and force it to go inactive if not.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (NS_CLIENTSTATE_READY == client->newstate) {
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * Give the processed dispatch event back to
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * the dispatch. This tells the dispatch
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * that we are ready to receive the next event.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (client->state == NS_CLIENTSTATE_READY) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson INSIST(client->newstate <= NS_CLIENTSTATE_INACTIVE);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * We are trying to enter the inactive state.
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_socket_cancel(client->tcplistener, client->task,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson /* Still waiting for accept cancel completion. */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson /* Accept cancel is complete. */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (client->state == NS_CLIENTSTATE_INACTIVE) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson INSIST(client->newstate == NS_CLIENTSTATE_FREED);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * We are trying to free the client.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * The client's task has received a shutdown event.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonclient_shutdown(isc_task_t *task, isc_event_t *event) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson REQUIRE(event->type == ISC_TASKEVENT_SHUTDOWN);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson (client->shutdown)(client->shutdown_arg, ISC_R_SHUTTINGDOWN);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonns_client_endrequest(ns_client_t *client) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson INSIST(client->state == NS_CLIENTSTATE_WORKING);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff dns_message_puttemprdataset(client->message, &client->opt);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_message_reset(client->message, DNS_MESSAGE_INTENTPARSE);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_quota_detach(&client->recursionquota);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonns_client_checkactive(ns_client_t *client) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * This client object should normally go inactive
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * at this point, but if we have fewer active client
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff * objects than desired due to earlier quota exhaustion,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * keep it active to make up for the shortage.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_boolean_t need_another_client = ISC_FALSE;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * The UDP client quota is enforced by making
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * requests fail rather than by not listening
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * for new ones. Therefore, there is always a
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * full set of UDP clients listening.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * We don't need this client object. Recycle it.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (client->newstate >= NS_CLIENTSTATE_INACTIVE)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson client->newstate = NS_CLIENTSTATE_INACTIVE;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonns_client_next(ns_client_t *client, isc_result_t result) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff REQUIRE(client->state == NS_CLIENTSTATE_WORKING);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_log_write(dns_lctx, DNS_LOGCATEGORY_SECURITY,
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff "request failed: %s", isc_result_totext(result));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * An error processing a TCP request may have left
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * the connection out of sync. To be safe, we always
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * sever the connection when result != ISC_R_SUCCESS.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (result == ISC_R_SUCCESS && TCP_CLIENT(client))
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonclient_senddone(isc_task_t *task, isc_event_t *event) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_socketevent_t *sevent = (isc_socketevent_t *) event;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson REQUIRE(sevent->type == ISC_SOCKEVENT_SENDDONE);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson unsigned char *data;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if ((client->attributes & NS_CLIENTATTR_RA) != 0)
c0d0a59d1b665423b8a0d1829d0f0da121cb3473Andreas Gustafsson client->message->flags |= DNS_MESSAGEFLAG_RA;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * XXXRTH The following doesn't deal with TSIGs, TCP buffer resizing,
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * or ENDS1 more data packets.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * XXXRTH "tcpbuffer" is a hack to get things working.
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_buffer_init(&tcpbuffer, data, SEND_BUFFER_SIZE,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_init(&buffer, data + 2, SEND_BUFFER_SIZE - 2,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_init(&buffer, data, bufsize, ISC_BUFFERTYPE_BINARY);
980dc596269e6f1ff05ab665be7d1f563befb2b8Bob Halley result = dns_message_renderbegin(client->message, &buffer);
980dc596269e6f1ff05ab665be7d1f563befb2b8Bob Halley result = dns_message_setopt(client->message, client->opt);
980dc596269e6f1ff05ab665be7d1f563befb2b8Bob Halley * XXXRTH dns_message_setopt() should probably do this...
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = dns_message_rendersection(client->message,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson result = dns_message_rendersection(client->message,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson client->message->flags |= DNS_MESSAGEFLAG_TC;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson result = dns_message_rendersection(client->message,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson client->message->flags |= DNS_MESSAGEFLAG_TC;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson result = dns_message_rendersection(client->message,
68e4926b2262571e004b4be00b905ec776c01d9cMichael Graff if (result != ISC_R_SUCCESS && result != ISC_R_NOSPACE)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson result = dns_message_renderend(client->message);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_buffer_putuint16(&tcpbuffer, (isc_uint16_t) r.length);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson socket = dns_dispatch_getsocket(client->dispatch);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if ((client->attributes & NS_CLIENTATTR_PKTINFO) != 0)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson result = isc_socket_sendto(socket, &r, client->task, client_senddone,
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graffns_client_error(ns_client_t *client, isc_result_t result) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * message may be an in-progress reply that we had trouble
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * with, in which case QR will be set. We need to clear QR before
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence * calling dns_message_reply() to avoid triggering an assertion.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * AA and AD shouldn't be set.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson message->flags &= ~(DNS_MESSAGEFLAG_AA | DNS_MESSAGEFLAG_AD);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson result = dns_message_reply(message, ISC_TRUE);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * It could be that we've got a query with a good header,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * but a bad question section, so we try again with
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * want_question_section set to ISC_FALSE.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson result = dns_message_reply(message, ISC_FALSE);
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson REQUIRE(client->opt == NULL); /* XXXRTH free old. */
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = dns_message_gettemprdatalist(client->message, &rdatalist);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson result = dns_message_gettemprdata(client->message, &rdata);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson result = dns_message_gettemprdataset(client->message, &rdataset);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * Set Maximum UDP buffer size.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Set EXTENDED-RCODE, VERSION, and Z to 0.
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * No ENDS options.
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff ISC_LIST_APPEND(rdatalist->rdata, rdata, link);
913bc4304db0c4e0613bf1404c1caa29f9530180Andreas Gustafsson dns_rdatalist_tordataset(rdatalist, rdataset);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * Handle an incoming request event from the dispatch (UDP case)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson * or tcpmsg (TCP case).
913bc4304db0c4e0613bf1404c1caa29f9530180Andreas Gustafssonclient_request(isc_task_t *task, isc_event_t *event) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_boolean_t ra; /* Recursion available. */
peerbuf);
goto cleanup_serverlock;
goto cleanup_serverlock;
goto cleanup_serverlock;
goto cleanup_serverlock;
unsigned int version;
goto cleanup_serverlock;
if (version != 0) {
goto cleanup_serverlock;
goto cleanup_serverlock;
goto cleanup_viewlock;
ISC_TRUE);
case dns_opcode_query:
case dns_opcode_update:
case dns_opcode_notify:
case dns_opcode_iquery:
static isc_result_t
return (ISC_R_NOMEMORY);
goto cleanup_client;
goto cleanup_task;
goto cleanup_task;
goto cleanup_timer;
goto cleanup_message;
goto cleanup_sendbuf;
return (ISC_R_SUCCESS);
return (result);
goto fail;
fail:
goto freeevent;
return (result);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
goto cleanup_manager;
return (ISC_R_SUCCESS);
return (result);
if (need_destroy)
REQUIRE(n > 0);
if (tcp) {
return (result);
int match;
if (default_allow)
goto allow;
goto deny;
if (match > 0)
goto allow;
return (DNS_R_SUCCESS);
deny:
return (DNS_R_REFUSED);