1/* 2 * Copyright (C) 2004, 2005, 2007, 2008 Internet Systems Consortium, Inc. ("ISC") 3 * Copyright (C) 2000, 2001 Internet Software Consortium. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15 * PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18/* $Id: lwdnoop.c,v 1.13 2008/01/22 23:28:04 tbox Exp $ */ 19 20/*! \file */ 21 22#include <config.h> 23 24#include <isc/socket.h> 25#include <isc/util.h> 26 27#include <named/types.h> 28#include <named/lwdclient.h> 29 30void 31ns_lwdclient_processnoop(ns_lwdclient_t *client, lwres_buffer_t *b) { 32 lwres_nooprequest_t *req; 33 lwres_noopresponse_t resp; 34 isc_result_t result; 35 lwres_result_t lwres; 36 isc_region_t r; 37 lwres_buffer_t lwb; 38 39 REQUIRE(NS_LWDCLIENT_ISRECVDONE(client)); 40 INSIST(client->byaddr == NULL); 41 42 req = NULL; 43 44 result = lwres_nooprequest_parse(client->clientmgr->lwctx, 45 b, &client->pkt, &req); 46 if (result != LWRES_R_SUCCESS) 47 goto send_error; 48 49 client->pkt.recvlength = LWRES_RECVLENGTH; 50 client->pkt.authtype = 0; /* XXXMLG */ 51 client->pkt.authlength = 0; 52 client->pkt.result = LWRES_R_SUCCESS; 53 54 resp.datalength = req->datalength; 55 resp.data = req->data; 56 57 lwres = lwres_noopresponse_render(client->clientmgr->lwctx, &resp, 58 &client->pkt, &lwb); 59 if (lwres != LWRES_R_SUCCESS) 60 goto cleanup_req; 61 62 r.base = lwb.base; 63 r.length = lwb.used; 64 client->sendbuf = r.base; 65 client->sendlength = r.length; 66 result = ns_lwdclient_sendreply(client, &r); 67 if (result != ISC_R_SUCCESS) 68 goto cleanup_lwb; 69 70 /* 71 * We can now destroy request. 72 */ 73 lwres_nooprequest_free(client->clientmgr->lwctx, &req); 74 75 NS_LWDCLIENT_SETSEND(client); 76 77 return; 78 79 cleanup_lwb: 80 lwres_context_freemem(client->clientmgr->lwctx, lwb.base, lwb.length); 81 82 cleanup_req: 83 lwres_nooprequest_free(client->clientmgr->lwctx, &req); 84 85 send_error: 86 ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE); 87} 88