/contrib/bind9/bin/named/lwdnoop.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 87 lines · 47 code · 19 blank · 21 comment · 7 complexity · 8f7d41e32d93a60ce162ccb1e4bd0e22 MD5 · raw file

  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. /* $Id: lwdnoop.c,v 1.13 2008/01/22 23:28:04 tbox Exp $ */
  18. /*! \file */
  19. #include <config.h>
  20. #include <isc/socket.h>
  21. #include <isc/util.h>
  22. #include <named/types.h>
  23. #include <named/lwdclient.h>
  24. void
  25. ns_lwdclient_processnoop(ns_lwdclient_t *client, lwres_buffer_t *b) {
  26. lwres_nooprequest_t *req;
  27. lwres_noopresponse_t resp;
  28. isc_result_t result;
  29. lwres_result_t lwres;
  30. isc_region_t r;
  31. lwres_buffer_t lwb;
  32. REQUIRE(NS_LWDCLIENT_ISRECVDONE(client));
  33. INSIST(client->byaddr == NULL);
  34. req = NULL;
  35. result = lwres_nooprequest_parse(client->clientmgr->lwctx,
  36. b, &client->pkt, &req);
  37. if (result != LWRES_R_SUCCESS)
  38. goto send_error;
  39. client->pkt.recvlength = LWRES_RECVLENGTH;
  40. client->pkt.authtype = 0; /* XXXMLG */
  41. client->pkt.authlength = 0;
  42. client->pkt.result = LWRES_R_SUCCESS;
  43. resp.datalength = req->datalength;
  44. resp.data = req->data;
  45. lwres = lwres_noopresponse_render(client->clientmgr->lwctx, &resp,
  46. &client->pkt, &lwb);
  47. if (lwres != LWRES_R_SUCCESS)
  48. goto cleanup_req;
  49. r.base = lwb.base;
  50. r.length = lwb.used;
  51. client->sendbuf = r.base;
  52. client->sendlength = r.length;
  53. result = ns_lwdclient_sendreply(client, &r);
  54. if (result != ISC_R_SUCCESS)
  55. goto cleanup_lwb;
  56. /*
  57. * We can now destroy request.
  58. */
  59. lwres_nooprequest_free(client->clientmgr->lwctx, &req);
  60. NS_LWDCLIENT_SETSEND(client);
  61. return;
  62. cleanup_lwb:
  63. lwres_context_freemem(client->clientmgr->lwctx, lwb.base, lwb.length);
  64. cleanup_req:
  65. lwres_nooprequest_free(client->clientmgr->lwctx, &req);
  66. send_error:
  67. ns_lwdclient_errorpktsend(client, LWRES_R_FAILURE);
  68. }