2 * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.
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.
18 /* $Id: lwderror.c,v 1.8.18.2 2005/04/29 00:15:24 marka Exp $ */
24 #include <isc/socket.h>
27 #include <named/types.h>
28 #include <named/lwdclient.h>
31 * Generate an error packet for the client, schedule a send, and put us in
34 * The client->pkt structure will be modified to form an error return.
35 * The receiver needs to verify that it is in fact an error, and do the
36 * right thing with it. The opcode will be unchanged. The result needs
37 * to be set before calling this function.
39 * The only change this code makes is to set the receive buffer size to the
40 * size we use, set the reply bit, and recompute any security information.
43 ns_lwdclient_errorpktsend(ns_lwdclient_t *client, isc_uint32_t _result) {
49 REQUIRE(NS_LWDCLIENT_ISRUNNING(client));
52 * Since we are only sending the packet header, we can safely toss
53 * the receive buffer. This means we won't need to allocate space
54 * for sending an error reply. This is a Good Thing.
56 client->pkt.length = LWRES_LWPACKET_LENGTH;
57 client->pkt.pktflags |= LWRES_LWPACKETFLAG_RESPONSE;
58 client->pkt.recvlength = LWRES_RECVLENGTH;
59 client->pkt.authtype = 0; /* XXXMLG */
60 client->pkt.authlength = 0;
61 client->pkt.result = _result;
63 lwres_buffer_init(&b, client->buffer, LWRES_RECVLENGTH);
64 lwres = lwres_lwpacket_renderheader(&b, &client->pkt);
65 if (lwres != LWRES_R_SUCCESS) {
66 ns_lwdclient_stateidle(client);
70 r.base = client->buffer;
72 client->sendbuf = client->buffer;
73 result = ns_lwdclient_sendreply(client, &r);
74 if (result != ISC_R_SUCCESS) {
75 ns_lwdclient_stateidle(client);
79 NS_LWDCLIENT_SETSEND(client);