/contrib/bind9/lib/dns/rdata/in_1/aaaa_28.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 237 lines · 162 code · 56 blank · 19 comment · 43 complexity · 1aa8c4071468fe3ec40693b940c54eda MD5 · raw file

  1. /*
  2. * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 1999-2002 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: aaaa_28.c,v 1.47 2009/12/04 22:06:37 tbox Exp $ */
  18. /* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
  19. /* RFC1886 */
  20. #ifndef RDATA_IN_1_AAAA_28_C
  21. #define RDATA_IN_1_AAAA_28_C
  22. #include <isc/net.h>
  23. #define RRTYPE_AAAA_ATTRIBUTES (0)
  24. static inline isc_result_t
  25. fromtext_in_aaaa(ARGS_FROMTEXT) {
  26. isc_token_t token;
  27. unsigned char addr[16];
  28. isc_region_t region;
  29. REQUIRE(type == 28);
  30. REQUIRE(rdclass == 1);
  31. UNUSED(type);
  32. UNUSED(origin);
  33. UNUSED(options);
  34. UNUSED(rdclass);
  35. UNUSED(callbacks);
  36. RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
  37. ISC_FALSE));
  38. if (inet_pton(AF_INET6, DNS_AS_STR(token), addr) != 1)
  39. RETTOK(DNS_R_BADAAAA);
  40. isc_buffer_availableregion(target, &region);
  41. if (region.length < 16)
  42. return (ISC_R_NOSPACE);
  43. memcpy(region.base, addr, 16);
  44. isc_buffer_add(target, 16);
  45. return (ISC_R_SUCCESS);
  46. }
  47. static inline isc_result_t
  48. totext_in_aaaa(ARGS_TOTEXT) {
  49. isc_region_t region;
  50. UNUSED(tctx);
  51. REQUIRE(rdata->type == 28);
  52. REQUIRE(rdata->rdclass == 1);
  53. REQUIRE(rdata->length == 16);
  54. dns_rdata_toregion(rdata, &region);
  55. return (inet_totext(AF_INET6, &region, target));
  56. }
  57. static inline isc_result_t
  58. fromwire_in_aaaa(ARGS_FROMWIRE) {
  59. isc_region_t sregion;
  60. isc_region_t tregion;
  61. REQUIRE(type == 28);
  62. REQUIRE(rdclass == 1);
  63. UNUSED(type);
  64. UNUSED(dctx);
  65. UNUSED(options);
  66. UNUSED(rdclass);
  67. isc_buffer_activeregion(source, &sregion);
  68. isc_buffer_availableregion(target, &tregion);
  69. if (sregion.length < 16)
  70. return (ISC_R_UNEXPECTEDEND);
  71. if (tregion.length < 16)
  72. return (ISC_R_NOSPACE);
  73. memcpy(tregion.base, sregion.base, 16);
  74. isc_buffer_forward(source, 16);
  75. isc_buffer_add(target, 16);
  76. return (ISC_R_SUCCESS);
  77. }
  78. static inline isc_result_t
  79. towire_in_aaaa(ARGS_TOWIRE) {
  80. isc_region_t region;
  81. UNUSED(cctx);
  82. REQUIRE(rdata->type == 28);
  83. REQUIRE(rdata->rdclass == 1);
  84. REQUIRE(rdata->length == 16);
  85. isc_buffer_availableregion(target, &region);
  86. if (region.length < rdata->length)
  87. return (ISC_R_NOSPACE);
  88. memcpy(region.base, rdata->data, rdata->length);
  89. isc_buffer_add(target, 16);
  90. return (ISC_R_SUCCESS);
  91. }
  92. static inline int
  93. compare_in_aaaa(ARGS_COMPARE) {
  94. isc_region_t r1;
  95. isc_region_t r2;
  96. REQUIRE(rdata1->type == rdata2->type);
  97. REQUIRE(rdata1->rdclass == rdata2->rdclass);
  98. REQUIRE(rdata1->type == 28);
  99. REQUIRE(rdata1->rdclass == 1);
  100. REQUIRE(rdata1->length == 16);
  101. REQUIRE(rdata2->length == 16);
  102. dns_rdata_toregion(rdata1, &r1);
  103. dns_rdata_toregion(rdata2, &r2);
  104. return (isc_region_compare(&r1, &r2));
  105. }
  106. static inline isc_result_t
  107. fromstruct_in_aaaa(ARGS_FROMSTRUCT) {
  108. dns_rdata_in_aaaa_t *aaaa = source;
  109. REQUIRE(type == 28);
  110. REQUIRE(rdclass == 1);
  111. REQUIRE(source != NULL);
  112. REQUIRE(aaaa->common.rdtype == type);
  113. REQUIRE(aaaa->common.rdclass == rdclass);
  114. UNUSED(type);
  115. UNUSED(rdclass);
  116. return (mem_tobuffer(target, aaaa->in6_addr.s6_addr, 16));
  117. }
  118. static inline isc_result_t
  119. tostruct_in_aaaa(ARGS_TOSTRUCT) {
  120. dns_rdata_in_aaaa_t *aaaa = target;
  121. isc_region_t r;
  122. REQUIRE(rdata->type == 28);
  123. REQUIRE(rdata->rdclass == 1);
  124. REQUIRE(target != NULL);
  125. REQUIRE(rdata->length == 16);
  126. UNUSED(mctx);
  127. aaaa->common.rdclass = rdata->rdclass;
  128. aaaa->common.rdtype = rdata->type;
  129. ISC_LINK_INIT(&aaaa->common, link);
  130. dns_rdata_toregion(rdata, &r);
  131. INSIST(r.length == 16);
  132. memcpy(aaaa->in6_addr.s6_addr, r.base, 16);
  133. return (ISC_R_SUCCESS);
  134. }
  135. static inline void
  136. freestruct_in_aaaa(ARGS_FREESTRUCT) {
  137. dns_rdata_in_aaaa_t *aaaa = source;
  138. REQUIRE(source != NULL);
  139. REQUIRE(aaaa->common.rdclass == 1);
  140. REQUIRE(aaaa->common.rdtype == 28);
  141. UNUSED(aaaa);
  142. }
  143. static inline isc_result_t
  144. additionaldata_in_aaaa(ARGS_ADDLDATA) {
  145. REQUIRE(rdata->type == 28);
  146. REQUIRE(rdata->rdclass == 1);
  147. UNUSED(rdata);
  148. UNUSED(add);
  149. UNUSED(arg);
  150. return (ISC_R_SUCCESS);
  151. }
  152. static inline isc_result_t
  153. digest_in_aaaa(ARGS_DIGEST) {
  154. isc_region_t r;
  155. REQUIRE(rdata->type == 28);
  156. REQUIRE(rdata->rdclass == 1);
  157. dns_rdata_toregion(rdata, &r);
  158. return ((digest)(arg, &r));
  159. }
  160. static inline isc_boolean_t
  161. checkowner_in_aaaa(ARGS_CHECKOWNER) {
  162. REQUIRE(type == 28);
  163. REQUIRE(rdclass == 1);
  164. UNUSED(type);
  165. UNUSED(rdclass);
  166. return (dns_name_ishostname(name, wildcard));
  167. }
  168. static inline isc_boolean_t
  169. checknames_in_aaaa(ARGS_CHECKNAMES) {
  170. REQUIRE(rdata->type == 28);
  171. REQUIRE(rdata->rdclass == 1);
  172. UNUSED(rdata);
  173. UNUSED(owner);
  174. UNUSED(bad);
  175. return (ISC_TRUE);
  176. }
  177. static inline int
  178. casecompare_in_aaaa(ARGS_COMPARE) {
  179. return (compare_in_aaaa(rdata1, rdata2));
  180. }
  181. #endif /* RDATA_IN_1_AAAA_28_C */