lwdnoop.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007, 2008  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2000, 2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: lwdnoop.c,v 1.13 2008/01/22 23:28:04 tbox Exp $ */
00019 
00020 /*! \file */
00021 
00022 #include <config.h>
00023 
00024 #include <isc/socket.h>
00025 #include <isc/util.h>
00026 
00027 #include <named/types.h>
00028 #include <named/lwdclient.h>
00029 
00030 void
00031 ns_lwdclient_processnoop(ns_lwdclient_t *client, lwres_buffer_t *b) {
00032         lwres_nooprequest_t *req;
00033         lwres_noopresponse_t resp;
00034         isc_result_t result;
00035         lwres_result_t lwres;
00036         isc_region_t r;
00037         lwres_buffer_t lwb;
00038 
00039         REQUIRE(NS_LWDCLIENT_ISRECVDONE(client));
00040         INSIST(client->byaddr == NULL);
00041 
00042         req = NULL;
00043 
00044         result = lwres_nooprequest_parse(client->clientmgr->lwctx,
00045                                          b, &client->pkt, &req);
00046         if (result != LWRES_R_SUCCESS)
00047                 goto send_error;
00048 
00049         client->pkt.recvlength = LWRES_RECVLENGTH;
00050         client->pkt.authtype = 0; /* XXXMLG */
00051         client->pkt.authlength = 0;
00052         client->pkt.result = LWRES_R_SUCCESS;
00053 
00054         resp.datalength = req->datalength;
00055         resp.data = req->data;
00056 
00057         lwres = lwres_noopresponse_render(client->clientmgr->lwctx, &resp,
00058                                           &client->pkt, &lwb);
00059         if (lwres != LWRES_R_SUCCESS)
00060                 goto cleanup_req;
00061 
00062         r.base = lwb.base;
00063         r.length = lwb.used;
00064         client->sendbuf = r.base;
00065         client->sendlength = r.length;
00066         result = ns_lwdclient_sendreply(client, &r);
00067         if (result != ISC_R_SUCCESS)
00068                 goto cleanup_lwb;
00069 
00070         /*
00071          * We can now destroy request.
00072          */
00073         lwres_nooprequest_free(client->clientmgr->lwctx, &req);
00074 
00075         NS_LWDCLIENT_SETSEND(client);
00076 
00077         return;
00078 
00079  cleanup_lwb:
00080         lwres_context_freemem(client->clientmgr->lwctx, lwb.base, lwb.length);
00081 
00082  cleanup_req:
00083         lwres_nooprequest_free(client->clientmgr->lwctx, &req);
00084 
00085  send_error:
00086         ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
00087 }

Generated on Tue Apr 28 17:40:54 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha