00001 /* 00002 * Copyright (C) 2004, 2005, 2007 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: lwderror.c,v 1.12 2007/06/19 23:46:59 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 /*% 00031 * Generate an error packet for the client, schedule a send, and put us in 00032 * the SEND state. 00033 * 00034 * The client->pkt structure will be modified to form an error return. 00035 * The receiver needs to verify that it is in fact an error, and do the 00036 * right thing with it. The opcode will be unchanged. The result needs 00037 * to be set before calling this function. 00038 * 00039 * The only change this code makes is to set the receive buffer size to the 00040 * size we use, set the reply bit, and recompute any security information. 00041 */ 00042 void 00043 ns_lwdclient_errorpktsend(ns_lwdclient_t *client, isc_uint32_t _result) { 00044 isc_result_t result; 00045 int lwres; 00046 isc_region_t r; 00047 lwres_buffer_t b; 00048 00049 REQUIRE(NS_LWDCLIENT_ISRUNNING(client)); 00050 00051 /* 00052 * Since we are only sending the packet header, we can safely toss 00053 * the receive buffer. This means we won't need to allocate space 00054 * for sending an error reply. This is a Good Thing. 00055 */ 00056 client->pkt.length = LWRES_LWPACKET_LENGTH; 00057 client->pkt.pktflags |= LWRES_LWPACKETFLAG_RESPONSE; 00058 client->pkt.recvlength = LWRES_RECVLENGTH; 00059 client->pkt.authtype = 0; /* XXXMLG */ 00060 client->pkt.authlength = 0; 00061 client->pkt.result = _result; 00062 00063 lwres_buffer_init(&b, client->buffer, LWRES_RECVLENGTH); 00064 lwres = lwres_lwpacket_renderheader(&b, &client->pkt); 00065 if (lwres != LWRES_R_SUCCESS) { 00066 ns_lwdclient_stateidle(client); 00067 return; 00068 } 00069 00070 r.base = client->buffer; 00071 r.length = b.used; 00072 client->sendbuf = client->buffer; 00073 result = ns_lwdclient_sendreply(client, &r); 00074 if (result != ISC_R_SUCCESS) { 00075 ns_lwdclient_stateidle(client); 00076 return; 00077 } 00078 00079 NS_LWDCLIENT_SETSEND(client); 00080 }