client.c revision dc9870de5554a8cbd5f4ad44a4e97012e44aaf60
e20788e1216ed720aefa84f3295f7899d9f28c22Mark Andrews * Copyright (C) 1999-2001 Internet Software Consortium.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Permission to use, copy, modify, and distribute this software for any
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * purpose with or without fee is hereby granted, provided that the above
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * copyright notice and this permission notice appear in all copies.
e20788e1216ed720aefa84f3295f7899d9f28c22Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
e20788e1216ed720aefa84f3295f7899d9f28c22Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
e20788e1216ed720aefa84f3295f7899d9f28c22Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
e20788e1216ed720aefa84f3295f7899d9f28c22Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
e20788e1216ed720aefa84f3295f7899d9f28c22Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
e20788e1216ed720aefa84f3295f7899d9f28c22Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
e20788e1216ed720aefa84f3295f7899d9f28c22Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt/* $Id: client.c,v 1.153 2001/02/22 23:39:11 gson Exp $ */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#endif /* DNS_OPT_NEWCODES */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Important note!
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * All client state changes, other than that from idle to listening, occur
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * as a result of events. This guarantees serialization and avoids the
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * need for locking.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * If a routine is ever created that allows someone other than the client's
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * task to change the client, then the client will have to be locked.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#define CTRACE(m) ((void)(m))
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#define MTRACE(m) ((void)(m))
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#define TCP_CLIENT(c) (((c)->attributes & NS_CLIENTATTR_TCP) != 0)
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Unlocked. */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt unsigned int magic;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Locked by lock. */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Client object states. Ordering is significant: higher-numbered
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * states are generally "more active", meaning that the client can
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * have more dynamically allocated data, outstanding events, etc.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * In the list below, any such properties listed for state N
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * also apply to any state > N.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * To force the client into a less active state, set client->newstate
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * to that state and call exit_check(). This will cause any
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * activities defined for higher-numbered states to be aborted.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * The client object no longer exists.
1b255a0c4eaccf0feff70328a8c108a22abfbf3cEvan Hunt * The client object exists and has a task and timer.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Its "query" struct and sendbuf are initialized.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * It is on the client manager's list of inactive clients.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * It has a message and OPT, both in the reset state.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * The client object is either a TCP or a UDP one, and
1b255a0c4eaccf0feff70328a8c108a22abfbf3cEvan Hunt * it is associated with a network interface. It is on the
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * client manager's list of active clients.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * If it is a TCP client object, it has a TCP listener socket
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * and an outstanding TCP listen request.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * If it is a UDP client object, it has a UDP listener socket
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * and an outstanding UDP receive request.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * The client object is a TCP client object that has received
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * a connection. It has a tcpsocket, tcpmsg, TCP quota, and an
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * outstanding TCP read request. This state is not used for
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * UDP client objects.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * The client object has received a request and is working
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * on it. It has a view, and it may have any of a non-reset OPT,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * recursion quota, and an outstanding write request.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Sentinel value used to indicate "no state". When client->newstate
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * has this value, we are not attempting to exit the current state.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Must be greater than any valid state.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntstatic void clientmgr_destroy(ns_clientmgr_t *manager);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntstatic isc_boolean_t exit_check(ns_client_t *client);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntstatic void ns_client_endrequest(ns_client_t *client);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntstatic void ns_client_checkactive(ns_client_t *client);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntstatic void client_start(isc_task_t *task, isc_event_t *event);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntstatic void client_request(isc_task_t *task, isc_event_t *event);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Enter the inactive state.
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt * No requests are outstanding.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ISC_LIST_UNLINK(client->manager->active, client, link);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ISC_LIST_APPEND(client->manager->inactive, client, link);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Clean up a client object and free its memory.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * The client is in the inactive state.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * When "shuttingdown" is true, either the task has received
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * its shutdown event or no shutdown event has ever been
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * set up. Thus, we have no outstanding shutdown
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * event at this point.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt REQUIRE(client->state == NS_CLIENTSTATE_INACTIVE);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_mem_put(client->mctx, client->sendbuf, SEND_BUFFER_SIZE);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_mem_put(client->mctx, client->recvbuf, RECV_BUFFER_SIZE);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_event_free((isc_event_t **)&client->sendevent);
1b255a0c4eaccf0feff70328a8c108a22abfbf3cEvan Hunt isc_event_free((isc_event_t **)&client->recvevent);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_mem_put(client->mctx, client->tcpbuf, TCP_BUFFER_SIZE);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt dns_message_puttemprdataset(client->message, &client->opt);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#endif /* DNS_OPT_NEWCODES */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Detaching the task must be done after unlinking from
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * the manager's lists because the manager accesses
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * client->task.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_mem_put(client->mctx, client, sizeof *client);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntns_client_settimeout(ns_client_t *client, unsigned int seconds) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = isc_timer_reset(client->timer, isc_timertype_once, NULL,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "setting timeout: %s",
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Continue anyway. */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Check for a deactivation or shutdown request and take appropriate
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * action. Returns ISC_TRUE if either is in progress; in this case
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * the caller must no longer use the client object as it may have been
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt INSIST(client->newstate < NS_CLIENTSTATE_WORKING);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * We need to detach from the view early when shutting down
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt * the server to break the following vicious circle:
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * - The resolver will not shut down until the view refcount is zero
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * - The view refcount does not go to zero until all clients detach
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * - The client does not detach from the view until references is zero
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * - references does not go to zero until the resolver has shut down
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (client->newstate == NS_CLIENTSTATE_FREED && client->view != NULL)
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt INSIST(client->newstate <= NS_CLIENTSTATE_READING);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * We are trying to abort request processing.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (! (client->nsends == 0 && client->nrecvs == 0 &&
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Still waiting for I/O cancel completion.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * or lingering references.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * I/O cancel is complete. Burn down all state
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * related to the current request.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * We are trying to abort the current TCP connection,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Still waiting for read cancel completion. */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Now the client is ready to accept a new TCP connection
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * or UDP request, but we may have enough clients doing
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * that already. Check whether this client needs to remain
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * active and force it to go inactive if not.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt INSIST(client->newstate <= NS_CLIENTSTATE_INACTIVE);
1b255a0c4eaccf0feff70328a8c108a22abfbf3cEvan Hunt * We are trying to enter the inactive state.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_socket_cancel(client->tcplistener, client->task,
1b255a0c4eaccf0feff70328a8c108a22abfbf3cEvan Hunt /* Still waiting for accept cancel completion. */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Accept cancel is complete. */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_socket_cancel(client->udpsocket, client->task,
1b255a0c4eaccf0feff70328a8c108a22abfbf3cEvan Hunt /* Still waiting for recv cancel completion. */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* Recv cancel is complete. */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * We are trying to free the client.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * The client's task has received the client's control event
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * as part of the startup process.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntclient_start(isc_task_t *task, isc_event_t *event) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt ns_client_t *client = (ns_client_t *) event->ev_arg;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * The client's task has received a shutdown event.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntclient_shutdown(isc_task_t *task, isc_event_t *event) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt REQUIRE(event->ev_type == ISC_TASKEVENT_SHUTDOWN);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt (client->shutdown)(client->shutdown_arg, ISC_R_SHUTTINGDOWN);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt dns_message_puttemprdataset(client->message, &client->opt);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt dns_message_reset(client->message, DNS_MESSAGE_INTENTPARSE);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Clear all client attributes that are specific to
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * the request; that's all except the TCP flag.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * This client object should normally go inactive
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * at this point, but if we have fewer active client
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * objects than desired due to earlier quota exhaustion,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * keep it active to make up for the shortage.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * The UDP client quota is enforced by making
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * requests fail rather than by not listening
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * for new ones. Therefore, there is always a
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * full set of UDP clients listening.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * We don't need this client object. Recycle it.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntns_client_next(ns_client_t *client, isc_result_t result) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * An error processing a TCP request may have left
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * the connection out of sync. To be safe, we always
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * sever the connection when result != ISC_R_SUCCESS.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (result == ISC_R_SUCCESS && TCP_CLIENT(client))
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntclient_senddone(isc_task_t *task, isc_event_t *event) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_socketevent_t *sevent = (isc_socketevent_t *) event;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt REQUIRE(sevent->ev_type == ISC_SOCKEVENT_SENDDONE);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt "error sending response: %s",
ce9f893e21d2ffc6f6a78bf226c038c396740aebEvan Hunt isc_mem_put(client->mctx, client->tcpbuf, TCP_BUFFER_SIZE);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntclient_allocsendbuf(ns_client_t *client, isc_buffer_t *buffer,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt unsigned char **datap)
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt unsigned char *data;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (tcpbuffer == NULL && length + 2 > TCP_BUFFER_SIZE) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt client->tcpbuf = isc_mem_get(client->mctx, TCP_BUFFER_SIZE);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_buffer_init(tcpbuffer, data, TCP_BUFFER_SIZE);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_buffer_init(buffer, data + 2, TCP_BUFFER_SIZE - 2);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntclient_sendpkg(ns_client_t *client, isc_buffer_t *buffer) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_netaddr_fromsockaddr(&netaddr, &client->peeraddr);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if ((client->attributes & NS_CLIENTATTR_PKTINFO) != 0)
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = isc_socket_sendto2(socket, &r, client->task,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (result == ISC_R_SUCCESS || result == ISC_R_INPROGRESS) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntns_client_sendraw(ns_client_t *client, dns_message_t *message) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt unsigned char *data;
ce9f893e21d2ffc6f6a78bf226c038c396740aebEvan Hunt result = client_allocsendbuf(client, &buffer, NULL, mr->length, &data);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Copy message to buffer and fixup id.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_mem_put(client->mctx, client->tcpbuf, TCP_BUFFER_SIZE);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt unsigned char *data;
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * XXXRTH The following doesn't deal with TCP buffer resizing.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = client_allocsendbuf(client, &buffer, &tcpbuffer, 0, &data);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = dns_message_renderbegin(client->message, &buffer);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = dns_message_setopt(client->message, client->opt);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * XXXRTH dns_message_setopt() should probably do this...
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = dns_message_rendersection(client->message,
ce9f893e21d2ffc6f6a78bf226c038c396740aebEvan Hunt result = dns_message_rendersection(client->message,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = dns_message_rendersection(client->message,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = dns_message_rendersection(client->message,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt if (result != ISC_R_SUCCESS && result != ISC_R_NOSPACE)
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_buffer_putuint16(&tcpbuffer, (isc_uint16_t) r.length);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt isc_mem_put(client->mctx, client->tcpbuf, TCP_BUFFER_SIZE);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntns_client_error(ns_client_t *client, isc_result_t result) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Message may be an in-progress reply that we had trouble
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * with, in which case QR will be set. We need to clear QR before
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * calling dns_message_reply() to avoid triggering an assertion.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * AA and AD shouldn't be set.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt message->flags &= ~(DNS_MESSAGEFLAG_AA | DNS_MESSAGEFLAG_AD);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * It could be that we've got a query with a good header,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * but a bad question section, so we try again with
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * want_question_section set to ISC_FALSE.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntclient_addoptattrs(ns_client_t *client, dns_rdata_t *rdata) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = dns_compress_init(&cctx, 0, client->mctx);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt for (i=0; i<CLIENT_NUMATTRS; i++) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = isc_buffer_allocate(client->mctx, &zonebuf,
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = dns_name_towire(dns_fixedname_name(client->opt_zone),
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt attrs[attrlist.used].value.base = isc_buffer_base(zonebuf);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt sizeneeded += 4 + isc_buffer_usedlength(client->opt_view);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = isc_buffer_allocate(client->mctx, &buf, sizeneeded+1);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#endif /* DNS_OPT_NEWCODES */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt REQUIRE(client->opt == NULL); /* XXXRTH free old. */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = dns_message_gettemprdatalist(client->message, &rdatalist);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = dns_message_gettemprdata(client->message, &rdata);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt result = dns_message_gettemprdataset(client->message, &rdataset);
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Set the maximum UDP buffer size.
dbb012765c735ee0d82dedb116cdc7cf18957814Evan Hunt * Set EXTENDED-RCODE, VERSION, and Z to 0.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * No ENDS options in the default case.
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Set the attributes
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#endif /* DNS_OPT_NEWCODES */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Huntclient_getoptattrs(ns_client_t *client, dns_rdataset_t *opt) {
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt /* If an old set of opts are still around, free them. */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * If there are any options, extract them here
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt#endif /* DNS_OPT_NEWCODES */
ba751492fcc4f161a18b983d4f018a1a52938cb9Evan Hunt * Handle an incoming request event from the socket (UDP case)
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
unsigned int version;
#ifdef DNS_OPT_NEWCODES
goto cleanup;
if (version != 0) {
goto cleanup;
goto cleanup;
int match;
match > 0))
isc_buffer_t b;
isc_region_t *r;
sizeof(classname));
goto cleanup;
goto cleanup;
goto cleanup;
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;
sizeof(isc_socketevent_t));
goto cleanup_sendbuf;
goto cleanup_sendevent;
sizeof(isc_socketevent_t));
goto cleanup_recvbuf;
#ifdef DNS_OPT_NEWCODES
goto cleanup_recvevent;
return (ISC_R_SUCCESS);
return (result);
goto fail;
fail:
goto freeevent;
int match;
match > 0)
goto freeevent;
isc_region_t r;
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 (ISC_R_SUCCESS);
deny:
return (DNS_R_REFUSED);