Merge branch 'vendor/OPENSSH'
[dragonfly.git] / contrib / bind / bin / named / lwderror.c
1 /*
2  * Copyright (C) 2004, 2005, 2007  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: lwderror.c,v 1.12 2007/06/19 23:46:59 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
30 /*%
31  * Generate an error packet for the client, schedule a send, and put us in
32  * the SEND state.
33  *
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.
38  *
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.
41  */
42 void
43 ns_lwdclient_errorpktsend(ns_lwdclient_t *client, isc_uint32_t _result) {
44         isc_result_t result;
45         int lwres;
46         isc_region_t r;
47         lwres_buffer_t b;
48
49         REQUIRE(NS_LWDCLIENT_ISRUNNING(client));
50
51         /*
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.
55          */
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;
62
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);
67                 return;
68         }
69
70         r.base = client->buffer;
71         r.length = b.used;
72         client->sendbuf = client->buffer;
73         result = ns_lwdclient_sendreply(client, &r);
74         if (result != ISC_R_SUCCESS) {
75                 ns_lwdclient_stateidle(client);
76                 return;
77         }
78
79         NS_LWDCLIENT_SETSEND(client);
80 }