/contrib/bind9/bin/named/lwderror.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 80 lines · 34 code · 11 blank · 35 comment · 4 complexity · 78f9d9d0907be581b7a02b29a4952024 MD5 · raw file

  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. /* $Id: lwderror.c,v 1.12 2007/06/19 23:46:59 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. /*%
  25. * Generate an error packet for the client, schedule a send, and put us in
  26. * the SEND state.
  27. *
  28. * The client->pkt structure will be modified to form an error return.
  29. * The receiver needs to verify that it is in fact an error, and do the
  30. * right thing with it. The opcode will be unchanged. The result needs
  31. * to be set before calling this function.
  32. *
  33. * The only change this code makes is to set the receive buffer size to the
  34. * size we use, set the reply bit, and recompute any security information.
  35. */
  36. void
  37. ns_lwdclient_errorpktsend(ns_lwdclient_t *client, isc_uint32_t _result) {
  38. isc_result_t result;
  39. int lwres;
  40. isc_region_t r;
  41. lwres_buffer_t b;
  42. REQUIRE(NS_LWDCLIENT_ISRUNNING(client));
  43. /*
  44. * Since we are only sending the packet header, we can safely toss
  45. * the receive buffer. This means we won't need to allocate space
  46. * for sending an error reply. This is a Good Thing.
  47. */
  48. client->pkt.length = LWRES_LWPACKET_LENGTH;
  49. client->pkt.pktflags |= LWRES_LWPACKETFLAG_RESPONSE;
  50. client->pkt.recvlength = LWRES_RECVLENGTH;
  51. client->pkt.authtype = 0; /* XXXMLG */
  52. client->pkt.authlength = 0;
  53. client->pkt.result = _result;
  54. lwres_buffer_init(&b, client->buffer, LWRES_RECVLENGTH);
  55. lwres = lwres_lwpacket_renderheader(&b, &client->pkt);
  56. if (lwres != LWRES_R_SUCCESS) {
  57. ns_lwdclient_stateidle(client);
  58. return;
  59. }
  60. r.base = client->buffer;
  61. r.length = b.used;
  62. client->sendbuf = client->buffer;
  63. result = ns_lwdclient_sendreply(client, &r);
  64. if (result != ISC_R_SUCCESS) {
  65. ns_lwdclient_stateidle(client);
  66. return;
  67. }
  68. NS_LWDCLIENT_SETSEND(client);
  69. }