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