host2str.c
Go to the documentation of this file.
1/*
2 * host2str.c
3 *
4 * conversion routines from the host format
5 * to the presentation format (strings)
6 *
7 * a Net::DNS like library for C
8 *
9 * (c) NLnet Labs, 2004-2006
10 *
11 * See the file LICENSE for the license
12 */
13#include <ldns/config.h>
14
15#include <ldns/ldns.h>
16
17#include <limits.h>
18
19#ifdef HAVE_SYS_SOCKET_H
20#include <sys/socket.h>
21#endif
22#ifdef HAVE_ARPA_INET_H
23#include <arpa/inet.h>
24#endif
25#ifdef HAVE_NETDB_H
26#include <netdb.h>
27#endif
28#include <time.h>
29#include <sys/time.h>
30
31#ifdef HAVE_SSL
32#include <openssl/bn.h>
33#include <openssl/rsa.h>
34#ifdef USE_DSA
35#include <openssl/dsa.h>
36#endif
37#endif
38
39#ifndef INET_ADDRSTRLEN
40#define INET_ADDRSTRLEN 16
41#endif
42#ifndef INET6_ADDRSTRLEN
43#define INET6_ADDRSTRLEN 46
44#endif
45
46/* Internal helper function */
49
50/* lookup tables for standard DNS stuff */
51
52/* Taken from RFC 2535, section 7. */
54 { LDNS_RSAMD5, "RSAMD5" },
55 { LDNS_DH, "DH" },
56 { LDNS_DSA, "DSA" },
57 { LDNS_ECC, "ECC" },
58 { LDNS_RSASHA1, "RSASHA1" },
59 { LDNS_DSA_NSEC3, "DSA-NSEC3-SHA1" },
60 { LDNS_RSASHA1_NSEC3, "RSASHA1-NSEC3-SHA1" },
61 { LDNS_RSASHA256, "RSASHA256"},
62 { LDNS_RSASHA512, "RSASHA512"},
63 { LDNS_ECC_GOST, "ECC-GOST"},
64 { LDNS_ECDSAP256SHA256, "ECDSAP256SHA256"},
65 { LDNS_ECDSAP384SHA384, "ECDSAP384SHA384"},
66 { LDNS_ED25519, "ED25519"},
67 { LDNS_ED448, "ED448"},
68 { LDNS_INDIRECT, "INDIRECT" },
69 { LDNS_PRIVATEDNS, "PRIVATEDNS" },
70 { LDNS_PRIVATEOID, "PRIVATEOID" },
71 { 0, NULL }
72};
73
74/* Hashing algorithms used in the DS record */
76 {LDNS_SHA1 , "SHA1" }, /* RFC 4034 */
77 {LDNS_SHA256 , "SHA256" }, /* RFC 4509 */
78 {LDNS_HASH_GOST, "HASH-GOST" }, /* RFC 5933 */
79 {LDNS_SHA384 , "SHA384" }, /* RFC 6605 */
80 { 0, NULL }
81};
82
83/* Taken from RFC 4398 */
85 { LDNS_CERT_PKIX, "PKIX" },
86 { LDNS_CERT_SPKI, "SPKI" },
87 { LDNS_CERT_PGP, "PGP" },
88 { LDNS_CERT_IPKIX, "IPKIX" },
89 { LDNS_CERT_ISPKI, "ISPKI" },
90 { LDNS_CERT_IPGP, "IPGP" },
91 { LDNS_CERT_ACPKIX, "ACPKIX" },
92 { LDNS_CERT_IACPKIX, "IACPKIX" },
93 { LDNS_CERT_URI, "URI" },
94 { LDNS_CERT_OID, "OID" },
95 { 0, NULL }
96};
97
98/* classes */
100 { LDNS_RR_CLASS_IN, "IN" },
101 { LDNS_RR_CLASS_CH, "CH" },
102 { LDNS_RR_CLASS_HS, "HS" },
103 { LDNS_RR_CLASS_NONE, "NONE" },
104 { LDNS_RR_CLASS_ANY, "ANY" },
105 { 0, NULL }
106};
107
108/* if these are used elsewhere */
110 { LDNS_RCODE_NOERROR, "NOERROR" },
111 { LDNS_RCODE_FORMERR, "FORMERR" },
112 { LDNS_RCODE_SERVFAIL, "SERVFAIL" },
113 { LDNS_RCODE_NXDOMAIN, "NXDOMAIN" },
114 { LDNS_RCODE_NOTIMPL, "NOTIMPL" },
115 { LDNS_RCODE_REFUSED, "REFUSED" },
116 { LDNS_RCODE_YXDOMAIN, "YXDOMAIN" },
117 { LDNS_RCODE_YXRRSET, "YXRRSET" },
118 { LDNS_RCODE_NXRRSET, "NXRRSET" },
119 { LDNS_RCODE_NOTAUTH, "NOTAUTH" },
120 { LDNS_RCODE_NOTZONE, "NOTZONE" },
121 { 0, NULL }
122};
123
125 { LDNS_PACKET_QUERY, "QUERY" },
126 { LDNS_PACKET_IQUERY, "IQUERY" },
127 { LDNS_PACKET_STATUS, "STATUS" },
128 { LDNS_PACKET_NOTIFY, "NOTIFY" },
129 { LDNS_PACKET_UPDATE, "UPDATE" },
130 { 0, NULL }
131};
132
143
149
150static bool
151ldns_output_format_covers_type(const ldns_output_format* fmt, ldns_rr_type t)
152{
153 return fmt && (fmt->flags & LDNS_FMT_RFC3597) &&
154 ((ldns_output_format_storage*)fmt)->bitmap &&
156 ((ldns_output_format_storage*)fmt)->bitmap, t);
157}
158
161{
163 ldns_status s;
164
165 assert(fmt != NULL);
166
167 if (!(fmt_st->flags & LDNS_FMT_RFC3597)) {
168 ldns_output_format_set(fmt, LDNS_FMT_RFC3597);
169 }
170 if (! fmt_st->bitmap) {
172 if (s != LDNS_STATUS_OK) {
173 return s;
174 }
175 }
176 return ldns_nsec_bitmap_set_type(fmt_st->bitmap, t);
177}
178
181{
183 ldns_status s;
184
185 assert(fmt != NULL);
186
187 if (!(fmt_st->flags & LDNS_FMT_RFC3597)) {
188 ldns_output_format_set(fmt, LDNS_FMT_RFC3597);
189 }
190 if (! fmt_st->bitmap) {
192 if (s != LDNS_STATUS_OK) {
193 return s;
194 }
195 }
196 return ldns_nsec_bitmap_clear_type(fmt_st->bitmap, t);
197}
198
201{
203 if (lt && lt->name) {
204 ldns_buffer_printf(output, "%s", lt->name);
205 } else {
206 ldns_buffer_printf(output, "OPCODE%u", opcode);
207 }
208 return ldns_buffer_status(output);
209}
210
213{
215 if (lt && lt->name) {
216 ldns_buffer_printf(output, "%s", lt->name);
217 } else {
218 ldns_buffer_printf(output, "RCODE%u", rcode);
219 }
220 return ldns_buffer_status(output);
221}
222
225 ldns_algorithm algorithm)
226{
228 algorithm);
229 if (lt && lt->name) {
230 ldns_buffer_printf(output, "%s", lt->name);
231 } else {
232 ldns_buffer_printf(output, "ALG%u", algorithm);
233 }
234 return ldns_buffer_status(output);
235}
236
239 ldns_cert_algorithm cert_algorithm)
240{
242 cert_algorithm);
243 if (lt && lt->name) {
244 ldns_buffer_printf(output, "%s", lt->name);
245 } else {
246 ldns_buffer_printf(output, "CERT_ALG%u",
247 cert_algorithm);
248 }
249 return ldns_buffer_status(output);
250}
251
252char *
254{
255 char *str;
256 ldns_buffer *buf;
257
258 buf = ldns_buffer_new(12);
259 if (!buf) {
260 return NULL;
261 }
262
263 str = NULL;
264 if (ldns_pkt_opcode2buffer_str(buf, opcode) == LDNS_STATUS_OK) {
265 str = ldns_buffer_export2str(buf);
266 }
267
268 ldns_buffer_free(buf);
269 return str;
270}
271
272char *
274{
275 char *str;
276 ldns_buffer *buf;
277
278 buf = ldns_buffer_new(10);
279 if (!buf) {
280 return NULL;
281 }
282
283 str = NULL;
284 if (ldns_pkt_rcode2buffer_str(buf, rcode) == LDNS_STATUS_OK) {
285 str = ldns_buffer_export2str(buf);
286 }
287
288 ldns_buffer_free(buf);
289 return str;
290}
291
292char *
294{
295 char *str;
296 ldns_buffer *buf;
297
298 buf = ldns_buffer_new(10);
299 if (!buf) {
300 return NULL;
301 }
302
303 str = NULL;
304 if (ldns_algorithm2buffer_str(buf, algorithm)
305 == LDNS_STATUS_OK) {
306 str = ldns_buffer_export2str(buf);
307 }
308
309 ldns_buffer_free(buf);
310 return str;
311}
312
313char *
315{
316 char *str;
317 ldns_buffer *buf;
318
319 buf = ldns_buffer_new(10);
320 if (!buf) {
321 return NULL;
322 }
323
324 str = NULL;
325 if (ldns_cert_algorithm2buffer_str(buf, cert_algorithm)
326 == LDNS_STATUS_OK) {
327 str = ldns_buffer_export2str(buf);
328 }
329
330 ldns_buffer_free(buf);
331 return str;
332}
333
334
335/* do NOT pass compressed data here :p */
338{
339 /* can we do with 1 pos var? or without at all? */
340 uint8_t src_pos = 0;
341 uint8_t len;
342 uint8_t *data;
343 uint8_t i;
344 unsigned char c;
345
346 data = (uint8_t*)ldns_rdf_data(dname);
347 len = data[src_pos];
348
349 if (ldns_rdf_size(dname) > LDNS_MAX_DOMAINLEN) {
350 /* too large, return */
352 }
353
354 /* special case: root label */
355 if (1 == ldns_rdf_size(dname)) {
356 ldns_buffer_printf(output, ".");
357 } else {
358 while ((len > 0) && src_pos < ldns_rdf_size(dname)) {
359 src_pos++;
360 for(i = 0; i < len; i++) {
361 /* paranoia check for various 'strange'
362 characters in dnames
363 */
364 c = (unsigned char) data[src_pos];
365 if(c == '.' || c == ';' ||
366 c == '(' || c == ')' ||
367 c == '\\') {
368 ldns_buffer_printf(output, "\\%c",
369 data[src_pos]);
370 } else if (!(isascii(c) && isgraph(c))) {
371 ldns_buffer_printf(output, "\\%03u",
372 data[src_pos]);
373 } else {
374 ldns_buffer_printf(output, "%c", data[src_pos]);
375 }
376 src_pos++;
377 }
378
379 if (src_pos < ldns_rdf_size(dname)) {
380 ldns_buffer_printf(output, ".");
381 }
382 len = data[src_pos];
383 }
384 }
385 return ldns_buffer_status(output);
386}
387
390{
391 uint8_t data = ldns_rdf_data(rdf)[0];
392 ldns_buffer_printf(output, "%lu", (unsigned long) data);
393 return ldns_buffer_status(output);
394}
395
398{
399 uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
400 ldns_buffer_printf(output, "%lu", (unsigned long) data);
401 return ldns_buffer_status(output);
402}
403
406{
407 uint32_t data = ldns_read_uint32(ldns_rdf_data(rdf));
408 ldns_buffer_printf(output, "%lu", (unsigned long) data);
409 return ldns_buffer_status(output);
410}
411
414{
415 /* create a YYYYMMDDHHMMSS string if possible */
416 struct tm tm;
417 char date_buf[16];
418
419 memset(&tm, 0, sizeof(tm));
421 && strftime(date_buf, 15, "%Y%m%d%H%M%S", &tm)) {
422 ldns_buffer_printf(output, "%s", date_buf);
423 }
424 return ldns_buffer_status(output);
425}
426
429{
430 char str[INET_ADDRSTRLEN];
431
432 if (inet_ntop(AF_INET, ldns_rdf_data(rdf), str, INET_ADDRSTRLEN)) {
433 ldns_buffer_printf(output, "%s", str);
434 }
435 return ldns_buffer_status(output);
436}
437
440{
441 char str[INET6_ADDRSTRLEN];
442
443 if (inet_ntop(AF_INET6, ldns_rdf_data(rdf), str, INET6_ADDRSTRLEN)) {
444 ldns_buffer_printf(output, "%s", str);
445 }
446
447 return ldns_buffer_status(output);
448}
449
450static void
451ldns_characters2buffer_str(ldns_buffer* output,
452 size_t amount, const uint8_t* characters)
453{
454 uint8_t ch;
455 while (amount > 0) {
456 ch = *characters++;
457 if (isprint((int)ch) || ch == '\t') {
458 if (ch == '\"' || ch == '\\')
459 ldns_buffer_printf(output, "\\%c", ch);
460 else
461 ldns_buffer_printf(output, "%c", ch);
462 } else {
463 ldns_buffer_printf(output, "\\%03u",
464 (unsigned)(uint8_t) ch);
465 }
466 amount--;
467 }
468}
469
472{
473 if(ldns_rdf_size(rdf) < 1) {
475 }
476 if((int)ldns_rdf_size(rdf) < (int)ldns_rdf_data(rdf)[0] + 1) {
478 }
479 ldns_buffer_printf(output, "\"");
480 ldns_characters2buffer_str(output,
481 ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf) + 1);
482 ldns_buffer_printf(output, "\"");
483 return ldns_buffer_status(output);
484}
485
488{
489 size_t size;
490 char *b64;
491
492 if (ldns_rdf_size(rdf) == 0) {
493 ldns_buffer_printf(output, "0");
494 return ldns_buffer_status(output);
495 } else
496 size = ldns_b64_ntop_calculate_size(ldns_rdf_size(rdf));
497
498 if (!(b64 = LDNS_XMALLOC(char, size)))
499 return LDNS_STATUS_MEM_ERR;
500
501 if (ldns_b64_ntop(ldns_rdf_data(rdf), ldns_rdf_size(rdf), b64, size)) {
502 ldns_buffer_printf(output, "%s", b64);
503 }
504 LDNS_FREE(b64);
505 return ldns_buffer_status(output);
506}
507
510{
511 size_t size;
512 char *b32;
513 if(ldns_rdf_size(rdf) == 0)
514 return LDNS_STATUS_OK;
515 /* remove -1 for the b32-hash-len octet */
516 size = ldns_b32_ntop_calculate_size(ldns_rdf_size(rdf) - 1);
517 /* add one for the end nul for the string */
518 b32 = LDNS_XMALLOC(char, size + 1);
519 if(!b32) return LDNS_STATUS_MEM_ERR;
520 size = (size_t) ldns_b32_ntop_extended_hex(ldns_rdf_data(rdf) + 1,
521 ldns_rdf_size(rdf) - 1, b32, size+1);
522 if (size > 0) {
523 ldns_buffer_printf(output, "%s", b32);
524 }
525 LDNS_FREE(b32);
526 return ldns_buffer_status(output);
527}
528
531{
532 size_t i;
533 for (i = 0; i < ldns_rdf_size(rdf); i++) {
534 ldns_buffer_printf(output, "%02x", ldns_rdf_data(rdf)[i]);
535 }
536
537 return ldns_buffer_status(output);
538}
539
540static ldns_status
541ldns_rdf2buffer_str_type_fmt(ldns_buffer *output,
542 const ldns_output_format* fmt, const ldns_rdf *rdf)
543{
544 uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
545
546 if (! ldns_output_format_covers_type(fmt, data) &&
547 ldns_rr_descript(data) &&
548 ldns_rr_descript(data)->_name) {
549
550 ldns_buffer_printf(output, "%s",ldns_rr_descript(data)->_name);
551 } else {
552 ldns_buffer_printf(output, "TYPE%u", data);
553 }
554 return ldns_buffer_status(output);
555}
556
559{
560 return ldns_rdf2buffer_str_type_fmt(output,
562}
563
566{
567 uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
569
570 lt = ldns_lookup_by_id(ldns_rr_classes, (int) data);
571 if (lt) {
572 ldns_buffer_printf(output, "\t%s", lt->name);
573 } else {
574 ldns_buffer_printf(output, "\tCLASS%d", data);
575 }
576 return ldns_buffer_status(output);
577}
578
581{
582 uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
584 lt = ldns_lookup_by_id(ldns_cert_algorithms, (int) data);
585 if (lt) {
586 ldns_buffer_printf(output, "%s", lt->name);
587 } else {
588 ldns_buffer_printf(output, "%d", data);
589 }
590 return ldns_buffer_status(output);
591}
592
595{
596 return ldns_rdf2buffer_str_int8(output, rdf);
597}
598
599static void
600loc_cm_print(ldns_buffer *output, uint8_t mantissa, uint8_t exponent)
601{
602 uint8_t i;
603 /* is it 0.<two digits> ? */
604 if(exponent < 2) {
605 if(exponent == 1)
606 mantissa *= 10;
607 ldns_buffer_printf(output, "0.%02ld", (long)mantissa);
608 return;
609 }
610 /* always <digit><string of zeros> */
611 ldns_buffer_printf(output, "%d", (int)mantissa);
612 for(i=0; i<exponent-2; i++)
613 ldns_buffer_printf(output, "0");
614}
615
618{
619 const ldns_rr_descriptor *descriptor;
620
621 descriptor = ldns_rr_descript(type);
622
623 switch (type) {
625 ldns_buffer_printf(output, "IXFR");
626 break;
628 ldns_buffer_printf(output, "AXFR");
629 break;
631 ldns_buffer_printf(output, "MAILA");
632 break;
634 ldns_buffer_printf(output, "MAILB");
635 break;
636 case LDNS_RR_TYPE_ANY:
637 ldns_buffer_printf(output, "ANY");
638 break;
639 default:
640 if (descriptor && descriptor->_name) {
641 ldns_buffer_printf(output, "%s", descriptor->_name);
642 } else {
643 ldns_buffer_printf(output, "TYPE%u", type);
644 }
645 }
646 return ldns_buffer_status(output);
647}
648
649char *
651{
652 char *str;
653 ldns_buffer *buf;
654
655 buf = ldns_buffer_new(10);
656 if (!buf) {
657 return NULL;
658 }
659
660 str = NULL;
661 if (ldns_rr_type2buffer_str(buf, type) == LDNS_STATUS_OK) {
662 str = ldns_buffer_export2str(buf);
663 }
664
665 ldns_buffer_free(buf);
666 return str;
667}
668
669
672 const ldns_rr_class klass)
673{
675
677 if (lt) {
678 ldns_buffer_printf(output, "%s", lt->name);
679 } else {
680 ldns_buffer_printf(output, "CLASS%d", klass);
681 }
682 return ldns_buffer_status(output);
683}
684
685char *
687{
688 ldns_buffer *buf;
689 char *str;
690
691 buf = ldns_buffer_new(10);
692 if (!buf) {
693 return NULL;
694 }
695
696 str = NULL;
697 if (ldns_rr_class2buffer_str(buf, klass) == LDNS_STATUS_OK) {
698 str = ldns_buffer_export2str(buf);
699 }
700 ldns_buffer_free(buf);
701 return str;
702}
703
706{
707 /* we could do checking (ie degrees < 90 etc)? */
708 uint8_t version;
709 uint8_t size;
710 uint8_t horizontal_precision;
711 uint8_t vertical_precision;
712 uint32_t longitude;
713 uint32_t latitude;
714 uint32_t altitude;
715 char latitude_hemisphere;
716 char longitude_hemisphere;
717 uint32_t h;
718 uint32_t m;
719 double s;
720
721 uint32_t equator = (uint32_t) ldns_power(2, 31);
722
723 if(ldns_rdf_size(rdf) < 1) {
725 }
726 version = ldns_rdf_data(rdf)[0];
727 if (version == 0) {
728 if(ldns_rdf_size(rdf) < 16) {
730 }
731 size = ldns_rdf_data(rdf)[1];
732 horizontal_precision = ldns_rdf_data(rdf)[2];
733 vertical_precision = ldns_rdf_data(rdf)[3];
734
735 latitude = ldns_read_uint32(&ldns_rdf_data(rdf)[4]);
736 longitude = ldns_read_uint32(&ldns_rdf_data(rdf)[8]);
737 altitude = ldns_read_uint32(&ldns_rdf_data(rdf)[12]);
738
739 if (latitude > equator) {
740 latitude_hemisphere = 'N';
741 latitude = latitude - equator;
742 } else {
743 latitude_hemisphere = 'S';
744 latitude = equator - latitude;
745 }
746 h = latitude / (1000 * 60 * 60);
747 latitude = latitude % (1000 * 60 * 60);
748 m = latitude / (1000 * 60);
749 latitude = latitude % (1000 * 60);
750 s = (double) latitude / 1000.0;
751 ldns_buffer_printf(output, "%02u %02u %0.3f %c ",
752 h, m, s, latitude_hemisphere);
753
754 if (longitude > equator) {
755 longitude_hemisphere = 'E';
756 longitude = longitude - equator;
757 } else {
758 longitude_hemisphere = 'W';
759 longitude = equator - longitude;
760 }
761 h = longitude / (1000 * 60 * 60);
762 longitude = longitude % (1000 * 60 * 60);
763 m = longitude / (1000 * 60);
764 longitude = longitude % (1000 * 60);
765 s = (double) longitude / (1000.0);
766 ldns_buffer_printf(output, "%02u %02u %0.3f %c ",
767 h, m, s, longitude_hemisphere);
768
769 s = ((double) altitude) / 100;
770 s -= 100000;
771
772 if(altitude%100 != 0)
773 ldns_buffer_printf(output, "%.2f", s);
774 else
775 ldns_buffer_printf(output, "%.0f", s);
776
777 ldns_buffer_printf(output, "m ");
778
779 loc_cm_print(output, (size & 0xf0) >> 4, size & 0x0f);
780 ldns_buffer_printf(output, "m ");
781
782 loc_cm_print(output, (horizontal_precision & 0xf0) >> 4,
783 horizontal_precision & 0x0f);
784 ldns_buffer_printf(output, "m ");
785
786 loc_cm_print(output, (vertical_precision & 0xf0) >> 4,
787 vertical_precision & 0x0f);
788 ldns_buffer_printf(output, "m");
789
790 return ldns_buffer_status(output);
791 } else {
792 return ldns_rdf2buffer_str_hex(output, rdf);
793 }
794}
795
798{
799 ldns_buffer_printf(output, "\\# %u ", ldns_rdf_size(rdf));
800 return ldns_rdf2buffer_str_hex(output, rdf);
801}
802
805{
806 ldns_buffer_printf(output, "0x");
807 return ldns_rdf2buffer_str_hex(output, rdf);
808}
809
812{
813 return ldns_rdf2buffer_str_hex(output, rdf);
814}
815
818{
819 /* protocol, followed by bitmap of services */
820 struct protoent *protocol;
821 char *proto_name = NULL;
822 uint8_t protocol_nr;
823 struct servent *service;
824 uint16_t current_service;
825
826 if(ldns_rdf_size(rdf) < 1) {
828 }
829 protocol_nr = ldns_rdf_data(rdf)[0];
830 protocol = getprotobynumber((int) protocol_nr);
831 if (protocol && (protocol->p_name != NULL)) {
832 proto_name = protocol->p_name;
833 ldns_buffer_printf(output, "%s ", protocol->p_name);
834 } else {
835 ldns_buffer_printf(output, "%u ", protocol_nr);
836 }
837
838 for (current_service = 0;
839 current_service < (ldns_rdf_size(rdf)-1)*8; current_service++) {
840 if (ldns_get_bit(&(ldns_rdf_data(rdf)[1]), current_service)) {
841 service = getservbyport((int) htons(current_service),
842 proto_name);
843 if (service && service->s_name) {
844 ldns_buffer_printf(output, "%s ", service->s_name);
845 } else {
846 ldns_buffer_printf(output, "%u ", current_service);
847 }
848#ifdef HAVE_ENDSERVENT
849 endservent();
850#endif
851 }
852 /* exit from loop before integer overflow */
853 if(current_service == 65535) { break; }
854 }
855
856#ifdef HAVE_ENDPROTOENT
857 endprotoent();
858#endif
859
860 return ldns_buffer_status(output);
861}
862
863static ldns_status
864ldns_rdf2buffer_str_nsec_fmt(ldns_buffer *output,
865 const ldns_output_format* fmt, const ldns_rdf *rdf)
866{
867 /* Note: this code is duplicated in higher.c in
868 * ldns_nsec_type_check() function
869 */
870 uint8_t window_block_nr;
871 uint8_t bitmap_length;
872 uint16_t type;
873 uint16_t pos = 0;
874 uint16_t bit_pos;
875 uint8_t *data = ldns_rdf_data(rdf);
876
877 while((size_t)(pos + 2) < ldns_rdf_size(rdf)) {
878 window_block_nr = data[pos];
879 bitmap_length = data[pos + 1];
880 pos += 2;
881 if (ldns_rdf_size(rdf) < pos + bitmap_length) {
883 }
884 for (bit_pos = 0; bit_pos < (bitmap_length) * 8; bit_pos++) {
885 if (! ldns_get_bit(&data[pos], bit_pos)) {
886 continue;
887 }
888 type = 256 * (uint16_t) window_block_nr + bit_pos;
889
890 if (! ldns_output_format_covers_type(fmt, type) &&
891 ldns_rr_descript(type) &&
892 ldns_rr_descript(type)->_name){
893
894 ldns_buffer_printf(output, "%s ",
895 ldns_rr_descript(type)->_name);
896 } else {
897 ldns_buffer_printf(output, "TYPE%u ", type);
898 }
899 }
900 pos += (uint16_t) bitmap_length;
901 }
902 return ldns_buffer_status(output);
903}
904
907{
908 return ldns_rdf2buffer_str_nsec_fmt(output,
910}
911
914{
915 uint8_t salt_length;
916 uint8_t salt_pos;
917
918 uint8_t *data = ldns_rdf_data(rdf);
919
920 if(ldns_rdf_size(rdf) < 1) {
922 }
923 salt_length = data[0];
924 /* from now there are variable length entries so remember pos */
925 if (salt_length == 0 || ((size_t)salt_length)+1 > ldns_rdf_size(rdf)) {
926 ldns_buffer_printf(output, "- ");
927 } else {
928 for (salt_pos = 0; salt_pos < salt_length; salt_pos++) {
929 ldns_buffer_printf(output, "%02x", data[1 + salt_pos]);
930 }
931 ldns_buffer_printf(output, " ");
932 }
933
934 return ldns_buffer_status(output);
935}
936
939{
940 /* period is the number of seconds */
941 if (ldns_rdf_size(rdf) != 4) {
943 }
944 ldns_buffer_printf(output, "%u", ldns_read_uint32(ldns_rdf_data(rdf)));
945 return ldns_buffer_status(output);
946}
947
950{
951 /* tsigtime is 48 bits network order unsigned integer */
952 uint64_t tsigtime = 0;
953 uint8_t *data = ldns_rdf_data(rdf);
954 uint64_t d0, d1, d2, d3, d4, d5;
955
956 if (ldns_rdf_size(rdf) < 6) {
958 }
959 d0 = data[0]; /* cast to uint64 for shift operations */
960 d1 = data[1];
961 d2 = data[2];
962 d3 = data[3];
963 d4 = data[4];
964 d5 = data[5];
965 tsigtime = (d0<<40) | (d1<<32) | (d2<<24) | (d3<<16) | (d4<<8) | d5;
966
967 ldns_buffer_printf(output, "%llu ", (long long)tsigtime);
968
969 return ldns_buffer_status(output);
970}
971
974{
975 uint8_t *data = ldns_rdf_data(rdf);
976 uint16_t address_family;
977 uint8_t prefix;
978 bool negation;
979 uint8_t adf_length;
980 size_t i;
981 size_t pos = 0;
982
983 while (pos < (unsigned int) ldns_rdf_size(rdf)) {
984 if(pos + 3 >= (unsigned)ldns_rdf_size(rdf))
986 address_family = ldns_read_uint16(&data[pos]);
987 prefix = data[pos + 2];
988 negation = data[pos + 3] & LDNS_APL_NEGATION;
989 adf_length = data[pos + 3] & LDNS_APL_MASK;
990 if (address_family == LDNS_APL_IP4) {
991 /* check if prefix < 32? */
992 if (negation) {
993 ldns_buffer_printf(output, "!");
994 }
995 ldns_buffer_printf(output, "%u:", address_family);
996 /* address is variable length 0 - 4 */
997 for (i = 0; i < 4; i++) {
998 if (i > 0) {
999 ldns_buffer_printf(output, ".");
1000 }
1001 if (i < (unsigned short) adf_length) {
1002 if(pos+i+4 >= ldns_rdf_size(rdf))
1004 ldns_buffer_printf(output, "%d",
1005 data[pos + i + 4]);
1006 } else {
1007 ldns_buffer_printf(output, "0");
1008 }
1009 }
1010 ldns_buffer_printf(output, "/%u ", prefix);
1011 } else if (address_family == LDNS_APL_IP6) {
1012 /* check if prefix < 128? */
1013 if (negation) {
1014 ldns_buffer_printf(output, "!");
1015 }
1016 ldns_buffer_printf(output, "%u:", address_family);
1017 /* address is variable length 0 - 16 */
1018 for (i = 0; i < 16; i++) {
1019 if (i % 2 == 0 && i > 0) {
1020 ldns_buffer_printf(output, ":");
1021 }
1022 if (i < (unsigned short) adf_length) {
1023 if(pos+i+4 >= ldns_rdf_size(rdf))
1025 ldns_buffer_printf(output, "%02x",
1026 data[pos + i + 4]);
1027 } else {
1028 ldns_buffer_printf(output, "00");
1029 }
1030 }
1031 ldns_buffer_printf(output, "/%u ", prefix);
1032
1033 } else {
1034 /* unknown address family */
1035 ldns_buffer_printf(output,
1036 "Unknown address family: %u data: ",
1037 address_family);
1038 for (i = 1; i < (unsigned short) (4 + adf_length); i++) {
1039 if(pos+i >= ldns_rdf_size(rdf))
1041 ldns_buffer_printf(output, "%02x", data[i]);
1042 }
1043 }
1044 pos += 4 + adf_length;
1045 }
1046 return ldns_buffer_status(output);
1047}
1048
1051{
1052 size_t size;
1053 char *b64;
1054 if (ldns_rdf_size(rdf) < 2) {
1056 }
1057 /* Subtract the size (2) of the number that specifies the length */
1058 size = ldns_b64_ntop_calculate_size(ldns_rdf_size(rdf) - 2);
1059 ldns_buffer_printf(output, "%u ", ldns_rdf_size(rdf) - 2);
1060 if (ldns_rdf_size(rdf) > 2) {
1061 b64 = LDNS_XMALLOC(char, size);
1062 if(!b64)
1063 return LDNS_STATUS_MEM_ERR;
1064
1065 if (ldns_rdf_size(rdf) > 2 &&
1067 ldns_rdf_size(rdf) - 2,
1068 b64, size)) {
1069 ldns_buffer_printf(output, "%s", b64);
1070 }
1071 LDNS_FREE(b64);
1072 }
1073 return ldns_buffer_status(output);
1074}
1075
1078{
1079 /* wire format from
1080 http://www.ietf.org/internet-drafts/draft-ietf-ipseckey-rr-12.txt
1081 */
1082 uint8_t *data = ldns_rdf_data(rdf);
1083 uint8_t precedence;
1084 uint8_t gateway_type;
1085 uint8_t algorithm;
1086
1087 ldns_rdf *gateway = NULL;
1088 uint8_t *gateway_data;
1089
1090 size_t public_key_size;
1091 uint8_t *public_key_data;
1092 ldns_rdf *public_key;
1093
1094 size_t offset = 0;
1095 ldns_status status;
1096
1097 if (ldns_rdf_size(rdf) < 3) {
1099 }
1100 precedence = data[0];
1101 gateway_type = data[1];
1102 algorithm = data[2];
1103 offset = 3;
1104
1105 switch (gateway_type) {
1106 case 0:
1107 /* no gateway */
1108 break;
1109 case 1:
1110 if (ldns_rdf_size(rdf) < offset + LDNS_IP4ADDRLEN) {
1111 return LDNS_STATUS_ERR;
1112 }
1113 gateway_data = LDNS_XMALLOC(uint8_t, LDNS_IP4ADDRLEN);
1114 if(!gateway_data)
1115 return LDNS_STATUS_MEM_ERR;
1116 memcpy(gateway_data, &data[offset], LDNS_IP4ADDRLEN);
1117 gateway = ldns_rdf_new(LDNS_RDF_TYPE_A,
1118 LDNS_IP4ADDRLEN , gateway_data);
1119 offset += LDNS_IP4ADDRLEN;
1120 if(!gateway) {
1121 LDNS_FREE(gateway_data);
1122 return LDNS_STATUS_MEM_ERR;
1123 }
1124 break;
1125 case 2:
1126 if (ldns_rdf_size(rdf) < offset + LDNS_IP6ADDRLEN) {
1127 return LDNS_STATUS_ERR;
1128 }
1129 gateway_data = LDNS_XMALLOC(uint8_t, LDNS_IP6ADDRLEN);
1130 if(!gateway_data)
1131 return LDNS_STATUS_MEM_ERR;
1132 memcpy(gateway_data, &data[offset], LDNS_IP6ADDRLEN);
1133 offset += LDNS_IP6ADDRLEN;
1134 gateway =
1136 LDNS_IP6ADDRLEN, gateway_data);
1137 if(!gateway) {
1138 LDNS_FREE(gateway_data);
1139 return LDNS_STATUS_MEM_ERR;
1140 }
1141 break;
1142 case 3:
1143 status = ldns_wire2dname(&gateway, data,
1144 ldns_rdf_size(rdf), &offset);
1145 if(status != LDNS_STATUS_OK)
1146 return status;
1147 break;
1148 default:
1149 /* error? */
1150 break;
1151 }
1152
1153 if (ldns_rdf_size(rdf) <= offset) {
1154 ldns_rdf_deep_free(gateway);
1155 return LDNS_STATUS_ERR;
1156 }
1157 public_key_size = ldns_rdf_size(rdf) - offset;
1158 public_key_data = LDNS_XMALLOC(uint8_t, public_key_size);
1159 if(!public_key_data) {
1160 ldns_rdf_deep_free(gateway);
1161 return LDNS_STATUS_MEM_ERR;
1162 }
1163 memcpy(public_key_data, &data[offset], public_key_size);
1164 public_key = ldns_rdf_new(LDNS_RDF_TYPE_B64,
1165 public_key_size, public_key_data);
1166 if(!public_key) {
1167 LDNS_FREE(public_key_data);
1168 ldns_rdf_deep_free(gateway);
1169 return LDNS_STATUS_MEM_ERR;
1170 }
1171
1172 ldns_buffer_printf(output, "%u %u %u ", precedence, gateway_type, algorithm);
1173 if (gateway)
1174 (void) ldns_rdf2buffer_str(output, gateway);
1175 else
1176 ldns_buffer_printf(output, ".");
1177 ldns_buffer_printf(output, " ");
1178 (void) ldns_rdf2buffer_str(output, public_key);
1179
1180 ldns_rdf_deep_free(gateway);
1181 ldns_rdf_deep_free(public_key);
1182
1183 return ldns_buffer_status(output);
1184}
1185
1188{
1189 if (ldns_rdf_size(rdf) != 8) {
1191 }
1192 ldns_buffer_printf(output,"%.4x:%.4x:%.4x:%.4x",
1193 ldns_read_uint16(ldns_rdf_data(rdf)),
1194 ldns_read_uint16(ldns_rdf_data(rdf)+2),
1195 ldns_read_uint16(ldns_rdf_data(rdf)+4),
1196 ldns_read_uint16(ldns_rdf_data(rdf)+6));
1197 return ldns_buffer_status(output);
1198}
1199
1202{
1203 if (ldns_rdf_size(rdf) != 6) {
1205 }
1206 ldns_buffer_printf(output,"%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
1207 ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf)[1],
1208 ldns_rdf_data(rdf)[2], ldns_rdf_data(rdf)[3],
1209 ldns_rdf_data(rdf)[4], ldns_rdf_data(rdf)[5]);
1210 return ldns_buffer_status(output);
1211}
1212
1215{
1216 if (ldns_rdf_size(rdf) != 8) {
1218 }
1219 ldns_buffer_printf(output,"%.2x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x-%.2x",
1220 ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf)[1],
1221 ldns_rdf_data(rdf)[2], ldns_rdf_data(rdf)[3],
1222 ldns_rdf_data(rdf)[4], ldns_rdf_data(rdf)[5],
1223 ldns_rdf_data(rdf)[6], ldns_rdf_data(rdf)[7]);
1224 return ldns_buffer_status(output);
1225}
1226
1229{
1230 size_t nchars;
1231 const uint8_t* chars;
1232 char ch;
1233 if (ldns_rdf_size(rdf) < 2) {
1235 }
1236 nchars = ldns_rdf_data(rdf)[0];
1237 if (nchars >= ldns_rdf_size(rdf) || /* should be rdf_size - 1 */
1238 nchars < 1) {
1240 }
1241 chars = ldns_rdf_data(rdf) + 1;
1242 while (nchars > 0) {
1243 ch = (char)*chars++;
1244 if (! isalnum((unsigned char)ch)) {
1246 }
1247 ldns_buffer_printf(output, "%c", ch);
1248 nchars--;
1249 }
1250 return ldns_buffer_status(output);
1251}
1252
1255{
1256
1257 ldns_buffer_printf(output, "\"");
1258 ldns_characters2buffer_str(output,
1259 ldns_rdf_size(rdf), ldns_rdf_data(rdf));
1260 ldns_buffer_printf(output, "\"");
1261 return ldns_buffer_status(output);
1262}
1263
1266{
1267 uint8_t *data = ldns_rdf_data(rdf);
1268 size_t rdf_size = ldns_rdf_size(rdf);
1269 uint8_t hit_size;
1270 uint16_t pk_size;
1271 int written;
1272
1273 if (rdf_size < 6) {
1275 }
1276 if ((hit_size = data[0]) == 0 ||
1277 (pk_size = ldns_read_uint16(data + 2)) == 0 ||
1278 rdf_size < (size_t) hit_size + pk_size + 4) {
1279
1281 }
1282
1283 ldns_buffer_printf(output, "%d ", (int) data[1]);
1284
1285 for (data += 4; hit_size > 0; hit_size--, data++) {
1286
1287 ldns_buffer_printf(output, "%02x", (int) *data);
1288 }
1289 ldns_buffer_write_char(output, (uint8_t) ' ');
1290
1291 if (ldns_buffer_reserve(output,
1292 ldns_b64_ntop_calculate_size(pk_size))) {
1293
1294 written = ldns_b64_ntop(data, pk_size,
1295 (char *) ldns_buffer_current(output),
1296 ldns_buffer_remaining(output));
1297
1298 if (written > 0 &&
1299 written < (int) ldns_buffer_remaining(output)) {
1300
1301 output->_position += written;
1302 }
1303 }
1304 return ldns_buffer_status(output);
1305}
1306
1307/* implementation mimicked from ldns_rdf2buffer_str_ipseckey */
1310{
1311 /* wire format from
1312 * draft-ietf-mboned-driad-amt-discovery Section 4.2
1313 */
1314 uint8_t *data = ldns_rdf_data(rdf);
1315 uint8_t precedence;
1316 uint8_t discovery_optional;
1317 uint8_t relay_type;
1318
1319 ldns_rdf *relay = NULL;
1320 uint8_t *relay_data;
1321
1322 size_t offset = 0;
1323 ldns_status status;
1324
1325 if (ldns_rdf_size(rdf) < 2) {
1327 }
1328 precedence = data[0];
1329 discovery_optional = ((data[1] & 0x80) >> 7);
1330 relay_type = data[1] & 0x7F;
1331 offset = 2;
1332
1333 switch (relay_type) {
1334 case 0:
1335 /* no relay */
1336 break;
1337 case 1:
1338 if (ldns_rdf_size(rdf) < offset + LDNS_IP4ADDRLEN) {
1339 return LDNS_STATUS_ERR;
1340 }
1341 relay_data = LDNS_XMALLOC(uint8_t, LDNS_IP4ADDRLEN);
1342 if(!relay_data)
1343 return LDNS_STATUS_MEM_ERR;
1344 memcpy(relay_data, &data[offset], LDNS_IP4ADDRLEN);
1346 LDNS_IP4ADDRLEN , relay_data);
1347 offset += LDNS_IP4ADDRLEN;
1348 if(!relay) {
1349 LDNS_FREE(relay_data);
1350 return LDNS_STATUS_MEM_ERR;
1351 }
1352 break;
1353 case 2:
1354 if (ldns_rdf_size(rdf) < offset + LDNS_IP6ADDRLEN) {
1355 return LDNS_STATUS_ERR;
1356 }
1357 relay_data = LDNS_XMALLOC(uint8_t, LDNS_IP6ADDRLEN);
1358 if(!relay_data)
1359 return LDNS_STATUS_MEM_ERR;
1360 memcpy(relay_data, &data[offset], LDNS_IP6ADDRLEN);
1361 offset += LDNS_IP6ADDRLEN;
1362 relay =
1364 LDNS_IP6ADDRLEN, relay_data);
1365 if(!relay) {
1366 LDNS_FREE(relay_data);
1367 return LDNS_STATUS_MEM_ERR;
1368 }
1369 break;
1370 case 3:
1371 status = ldns_wire2dname(&relay, data,
1372 ldns_rdf_size(rdf), &offset);
1373 if(status != LDNS_STATUS_OK)
1374 return status;
1375 break;
1376 default:
1377 /* error? */
1378 break;
1379 }
1380
1381 if (ldns_rdf_size(rdf) != offset) {
1382 ldns_rdf_deep_free(relay);
1383 return LDNS_STATUS_ERR;
1384 }
1385 ldns_buffer_printf(output, "%u %u %u ",
1386 precedence, discovery_optional, relay_type);
1387 if (relay)
1388 (void) ldns_rdf2buffer_str(output, relay);
1389
1390 ldns_rdf_deep_free(relay);
1391 return ldns_buffer_status(output);
1392}
1393
1394#ifdef RRTYPE_SVCB_HTTPS
1395ldns_status svcparam_key2buffer_str(ldns_buffer *output, uint16_t key);
1396
1397static ldns_status
1398svcparam_mandatory2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1399{
1400 if (sz % 2)
1402
1403 svcparam_key2buffer_str(output, ldns_read_uint16(data));
1404 for (data += 2, sz -= 2; sz; data += 2, sz -= 2) {
1405 ldns_buffer_write_char(output, ',');
1406 svcparam_key2buffer_str(output, ldns_read_uint16(data));
1407 }
1408 return ldns_buffer_status(output);
1409}
1410
1411static ldns_status
1412svcparam_alpn2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1413{
1414 uint8_t *eod = data + sz, *dp;
1415 bool quote = false;
1416 size_t i;
1417
1418 for (dp = data; dp < eod && !quote; dp += 1 + *dp) {
1419 if (dp + 1 + *dp > eod)
1421
1422 for (i = 0; i < *dp; i++)
1423 if (isspace(dp[i + 1]))
1424 break;
1425 quote = i < *dp;
1426 }
1427 if (quote)
1428 ldns_buffer_write_char(output, '"');
1429 while (data < eod) {
1430 uint8_t *eot = data + 1 + *data;
1431
1432 if (eot > eod)
1434
1435 if (eod - data < (int)sz)
1436 ldns_buffer_write_char(output, ',');
1437
1438 for (data += 1; data < eot; data += 1) {
1439 uint8_t ch = *data;
1440
1441 if (isprint(ch) || ch == '\t') {
1442 if (ch == '"' || ch == ',' || ch == '\\')
1443 ldns_buffer_write_char(output, '\\');
1444 ldns_buffer_write_char(output, ch);
1445 } else
1446 ldns_buffer_printf(output, "\\%03u"
1447 , (unsigned)ch);
1448 }
1449 }
1450 if (quote)
1451 ldns_buffer_write_char(output, '"');
1452 return ldns_buffer_status(output);
1453}
1454
1455static ldns_status
1456svcparam_port2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1457{
1458 if (sz != 2)
1460 ldns_buffer_printf(output, "%d", (int)ldns_read_uint16(data));
1461 return ldns_buffer_status(output);
1462}
1463
1464static ldns_status
1465svcparam_ipv4hint2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1466{
1467 char str[INET_ADDRSTRLEN];
1468
1469 if (sz % 4 || !inet_ntop(AF_INET, data, str, INET_ADDRSTRLEN))
1471
1472 ldns_buffer_write_chars(output, str);
1473
1474 for (data += 4, sz -= 4; sz ; data += 4, sz -= 4 ) {
1475 ldns_buffer_write_char(output, ',');
1476 if (!inet_ntop(AF_INET, data, str, INET_ADDRSTRLEN))
1478
1479 ldns_buffer_write_chars(output, str);
1480 }
1481 return ldns_buffer_status(output);
1482}
1483
1484static ldns_status
1485svcparam_ech2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1486{
1487 size_t str_sz = ldns_b64_ntop_calculate_size(sz);
1488 int written;
1489
1490 if (!ldns_buffer_reserve(output, str_sz))
1491 return LDNS_STATUS_MEM_ERR;
1492
1493 written = ldns_b64_ntop( data, sz
1494 , (char *)ldns_buffer_current(output), str_sz);
1495 if (written > 0)
1496 ldns_buffer_skip(output, written);
1497 else
1499
1500 return ldns_buffer_status(output);
1501}
1502
1503static ldns_status
1504svcparam_ipv6hint2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1505{
1506 char str[INET6_ADDRSTRLEN];
1507
1508 if (sz % 16 || !inet_ntop(AF_INET6, data, str, INET6_ADDRSTRLEN))
1510
1511 ldns_buffer_write_chars(output, str);
1512
1513 for (data += 16, sz -= 16; sz ; data += 16, sz -= 16) {
1514 ldns_buffer_write_char(output, ',');
1515 if (!inet_ntop(AF_INET6, data, str, INET6_ADDRSTRLEN))
1517
1518 ldns_buffer_write_chars(output, str);
1519 }
1520 return ldns_buffer_status(output);
1521}
1522
1523static ldns_status
1524svcparam_value2buffer_str(ldns_buffer *output, size_t sz, uint8_t *data)
1525{
1526 uint8_t *eod = data + sz, *dp;
1527 bool quote = false;
1528
1529 for (dp = data; dp < eod && !isspace(*dp); dp++)
1530 ; /* pass */
1531
1532 if ((quote = dp < eod))
1533 ldns_buffer_write_char(output, '"');
1534
1535 for (dp = data; dp < eod; dp++) {
1536 uint8_t ch = *dp;
1537
1538 if (isprint(ch) || ch == '\t') {
1539 if (ch == '"' || ch == '\\')
1540 ldns_buffer_write_char(output, '\\');
1541 ldns_buffer_write_char(output, ch);
1542 } else
1543 ldns_buffer_printf(output, "\\%03u", (unsigned)ch);
1544 }
1545 if (quote)
1546 ldns_buffer_write_char(output, '"');
1547 return ldns_buffer_status(output);
1548}
1549
1552{
1553 uint8_t *data, *dp, *next_dp = NULL;
1554 size_t sz;
1555 ldns_status st;
1556
1557 if (!output)
1558 return LDNS_STATUS_NULL;
1559
1560 if (!rdf || !(data = ldns_rdf_data(rdf)) || !(sz = ldns_rdf_size(rdf)))
1561 /* No svcparams is just fine. Just nothing to print. */
1562 return LDNS_STATUS_OK;
1563
1564 for (dp = data; dp + 4 <= data + sz; dp = next_dp) {
1565 ldns_svcparam_key key = ldns_read_uint16(dp);
1566 uint16_t val_sz = ldns_read_uint16(dp + 2);
1567
1568 if ((next_dp = dp + 4 + val_sz) > data + sz)
1570
1571 if (dp > data)
1572 ldns_buffer_write_char(output, ' ');
1573
1574 if ((st = svcparam_key2buffer_str(output, key)))
1575 return st;
1576
1577 if (val_sz == 0)
1578 continue;
1579 dp += 4;
1580 ldns_buffer_write_char(output, '=');
1581 switch (key) {
1583 st = svcparam_mandatory2buffer_str(output, val_sz, dp);
1584 break;
1586 st = svcparam_alpn2buffer_str(output, val_sz, dp);
1587 break;
1591 st = svcparam_port2buffer_str(output, val_sz, dp);
1592 break;
1594 st = svcparam_ipv4hint2buffer_str(output, val_sz, dp);
1595 break;
1597 st = svcparam_ech2buffer_str(output, val_sz, dp);
1598 break;
1600 st = svcparam_ipv6hint2buffer_str(output, val_sz, dp);
1601 break;
1602 default:
1603 st = svcparam_value2buffer_str(output, val_sz, dp);
1604 break;
1605 }
1606 if (st)
1607 return st;
1608 }
1609 return ldns_buffer_status(output);
1610}
1611#else /* #ifdef RRTYPE_SVCB_HTTPS */
1614{
1615 (void)output; (void)rdf;
1616 return LDNS_STATUS_NOT_IMPL;
1617}
1618#endif /* #ifdef RRTYPE_SVCB_HTTPS */
1619
1620static ldns_status
1621ldns_rdf2buffer_str_fmt(ldns_buffer *buffer,
1622 const ldns_output_format* fmt, const ldns_rdf *rdf)
1623{
1625
1626 /*ldns_buffer_printf(buffer, "%u:", ldns_rdf_get_type(rdf));*/
1627 if (rdf) {
1628 switch(ldns_rdf_get_type(rdf)) {
1629 case LDNS_RDF_TYPE_NONE:
1630 break;
1632 res = ldns_rdf2buffer_str_dname(buffer, rdf);
1633 break;
1634 case LDNS_RDF_TYPE_INT8: /* Don't output mnemonics for these */
1635 case LDNS_RDF_TYPE_ALG:
1639 res = ldns_rdf2buffer_str_int8(buffer, rdf);
1640 break;
1642 res = ldns_rdf2buffer_str_int16(buffer, rdf);
1643 break;
1645 res = ldns_rdf2buffer_str_int32(buffer, rdf);
1646 break;
1648 res = ldns_rdf2buffer_str_period(buffer, rdf);
1649 break;
1651 res = ldns_rdf2buffer_str_tsigtime(buffer, rdf);
1652 break;
1653 case LDNS_RDF_TYPE_A:
1654 res = ldns_rdf2buffer_str_a(buffer, rdf);
1655 break;
1656 case LDNS_RDF_TYPE_AAAA:
1657 res = ldns_rdf2buffer_str_aaaa(buffer, rdf);
1658 break;
1659 case LDNS_RDF_TYPE_STR:
1660 res = ldns_rdf2buffer_str_str(buffer, rdf);
1661 break;
1662 case LDNS_RDF_TYPE_APL:
1663 res = ldns_rdf2buffer_str_apl(buffer, rdf);
1664 break;
1666 res = ldns_rdf2buffer_str_b32_ext(buffer, rdf);
1667 break;
1668 case LDNS_RDF_TYPE_B64:
1669 res = ldns_rdf2buffer_str_b64(buffer, rdf);
1670 break;
1671 case LDNS_RDF_TYPE_HEX:
1672 res = ldns_rdf2buffer_str_hex(buffer, rdf);
1673 break;
1674 case LDNS_RDF_TYPE_NSEC:
1675 res = ldns_rdf2buffer_str_nsec_fmt(buffer, fmt, rdf);
1676 break;
1678 res = ldns_rdf2buffer_str_nsec3_salt(buffer, rdf);
1679 break;
1680 case LDNS_RDF_TYPE_TYPE:
1681 res = ldns_rdf2buffer_str_type_fmt(buffer, fmt, rdf);
1682 break;
1684 res = ldns_rdf2buffer_str_class(buffer, rdf);
1685 break;
1687 res = ldns_rdf2buffer_str_cert_alg(buffer, rdf);
1688 break;
1690 res = ldns_rdf2buffer_str_unknown(buffer, rdf);
1691 break;
1692 case LDNS_RDF_TYPE_TIME:
1693 res = ldns_rdf2buffer_str_time(buffer, rdf);
1694 break;
1695 case LDNS_RDF_TYPE_HIP:
1696 res = ldns_rdf2buffer_str_hip(buffer, rdf);
1697 break;
1698 case LDNS_RDF_TYPE_LOC:
1699 res = ldns_rdf2buffer_str_loc(buffer, rdf);
1700 break;
1701 case LDNS_RDF_TYPE_WKS:
1703 res = ldns_rdf2buffer_str_wks(buffer, rdf);
1704 break;
1705 case LDNS_RDF_TYPE_NSAP:
1706 res = ldns_rdf2buffer_str_nsap(buffer, rdf);
1707 break;
1708 case LDNS_RDF_TYPE_ATMA:
1709 res = ldns_rdf2buffer_str_atma(buffer, rdf);
1710 break;
1712 res = ldns_rdf2buffer_str_ipseckey(buffer, rdf);
1713 break;
1715 res = ldns_rdf2buffer_str_int16_data(buffer, rdf);
1716 break;
1718 res = ldns_rdf2buffer_str_b32_ext(buffer, rdf);
1719 break;
1721 res = ldns_rdf2buffer_str_ilnp64(buffer, rdf);
1722 break;
1724 res = ldns_rdf2buffer_str_eui48(buffer, rdf);
1725 break;
1727 res = ldns_rdf2buffer_str_eui64(buffer, rdf);
1728 break;
1729 case LDNS_RDF_TYPE_TAG:
1730 res = ldns_rdf2buffer_str_tag(buffer, rdf);
1731 break;
1733 res = ldns_rdf2buffer_str_long_str(buffer, rdf);
1734 break;
1736 res = ldns_rdf2buffer_str_amtrelay(buffer, rdf);
1737 break;
1739 res = ldns_rdf2buffer_str_svcparams(buffer, rdf);
1740 break;
1741 }
1742 } else {
1744 ldns_buffer_printf(buffer, "(null) ");
1745 res = LDNS_STATUS_ERR;
1746 }
1747 return res;
1748}
1749
1752{
1753 return ldns_rdf2buffer_str_fmt(buffer,ldns_output_format_default,rdf);
1754}
1755
1756static ldns_rdf *
1757ldns_b32_ext2dname(const ldns_rdf *rdf)
1758{
1759 size_t size;
1760 char *b32;
1761 ldns_rdf *out;
1762 if(ldns_rdf_size(rdf) == 0)
1763 return NULL;
1764 /* remove -1 for the b32-hash-len octet */
1765 size = ldns_b32_ntop_calculate_size(ldns_rdf_size(rdf) - 1);
1766 /* add one for the end nul for the string */
1767 b32 = LDNS_XMALLOC(char, size + 2);
1768 if (b32) {
1770 ldns_rdf_size(rdf) - 1, b32, size+1) > 0) {
1771 b32[size] = '.';
1772 b32[size+1] = '\0';
1773 if (ldns_str2rdf_dname(&out, b32) == LDNS_STATUS_OK) {
1774 LDNS_FREE(b32);
1775 return out;
1776 }
1777 }
1778 LDNS_FREE(b32);
1779 }
1780 return NULL;
1781}
1782
1783static ldns_status
1784ldns_rr2buffer_str_rfc3597(ldns_buffer *output, const ldns_rr *rr)
1785{
1786 size_t total_rdfsize = 0;
1787 size_t i, j;
1788
1789 ldns_buffer_printf(output, "TYPE%u\t", ldns_rr_get_type(rr));
1790 for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1791 total_rdfsize += ldns_rdf_size(ldns_rr_rdf(rr, i));
1792 }
1793 if (total_rdfsize == 0) {
1794 ldns_buffer_printf(output, "\\# 0\n");
1795 return ldns_buffer_status(output);
1796 }
1797 ldns_buffer_printf(output, "\\# %d ", total_rdfsize);
1798 for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1799 for (j = 0; j < ldns_rdf_size(ldns_rr_rdf(rr, i)); j++) {
1800 ldns_buffer_printf(output, "%.2x",
1801 ldns_rdf_data(ldns_rr_rdf(rr, i))[j]);
1802 }
1803 }
1804 ldns_buffer_printf(output, "\n");
1805 return ldns_buffer_status(output);
1806}
1807
1810 const ldns_output_format *fmt, const ldns_rr *rr)
1811{
1812 uint16_t i, flags;
1813 ldns_status status = LDNS_STATUS_OK;
1815
1816 if (fmt_st == NULL) {
1817 fmt_st = (ldns_output_format_storage*)
1819 }
1820 if (!(fmt_st->flags & LDNS_FMT_SHORT)) {
1821 if (!rr) {
1822 if (LDNS_COMMENT_NULLS & fmt_st->flags) {
1823 ldns_buffer_printf(output, "; (null)\n");
1824 }
1825 return ldns_buffer_status(output);
1826 }
1827 if (ldns_rr_owner(rr)) {
1828 status = ldns_rdf2buffer_str_dname(output, ldns_rr_owner(rr));
1829 }
1830 if (status != LDNS_STATUS_OK) {
1831 return status;
1832 }
1833
1834 /* TTL should NOT be printed if it is a question */
1835 if (!ldns_rr_is_question(rr)) {
1836 ldns_buffer_printf(output, "\t%u", (unsigned)ldns_rr_ttl(rr));
1837 }
1838
1839 ldns_buffer_printf(output, "\t");
1840 status = ldns_rr_class2buffer_str(output, ldns_rr_get_class(rr));
1841 if (status != LDNS_STATUS_OK) {
1842 return status;
1843 }
1844 ldns_buffer_printf(output, "\t");
1845
1846 if (ldns_output_format_covers_type(fmt, ldns_rr_get_type(rr))) {
1847 return ldns_rr2buffer_str_rfc3597(output, rr);
1848 }
1849 status = ldns_rr_type2buffer_str(output, ldns_rr_get_type(rr));
1850 if (status != LDNS_STATUS_OK) {
1851 return status;
1852 }
1853
1854 if (ldns_rr_rd_count(rr) > 0) {
1855 ldns_buffer_printf(output, "\t");
1856 } else if (!ldns_rr_is_question(rr)) {
1857 ldns_buffer_printf(output, "\t\\# 0");
1858 }
1859 } else if (ldns_rr_rd_count(rr) == 0) {
1860 /* assert(fmt_st->flags & LDNS_FMT_SHORT); */
1861
1862 ldns_buffer_printf(output, "# 0");
1863 }
1864 for (i = 0; i < ldns_rr_rd_count(rr); i++) {
1865 /* ldns_rdf2buffer_str handles NULL input fine! */
1866 if ((fmt_st->flags & LDNS_FMT_ZEROIZE_RRSIGS) &&
1868 ((/* inception */ i == 4 &&
1869 ldns_rdf_get_type(ldns_rr_rdf(rr, 4)) ==
1871 (/* expiration */ i == 5 &&
1874 (/* signature */ i == 8 &&
1877
1878 ldns_buffer_printf(output, "(null)");
1879 status = ldns_buffer_status(output);
1880 } else if ((fmt_st->flags & LDNS_FMT_PAD_SOA_SERIAL) &&
1882 /* serial */ i == 2 &&
1885 ldns_buffer_printf(output, "%10lu",
1886 (unsigned long) ldns_read_uint32(
1887 ldns_rdf_data(ldns_rr_rdf(rr, 2))));
1888 status = ldns_buffer_status(output);
1889 } else {
1890 status = ldns_rdf2buffer_str_fmt(output,
1891 fmt, ldns_rr_rdf(rr, i));
1892 }
1893 if(status != LDNS_STATUS_OK)
1894 return status;
1895 if (i < ldns_rr_rd_count(rr) - 1) {
1896 ldns_buffer_printf(output, " ");
1897 }
1898 }
1899 /* per RR special comments - handy for DNSSEC types */
1900 /* check to prevent question sec. rr from
1901 * getting here */
1902 if (ldns_rr_rd_count(rr) > 0) {
1903 switch (ldns_rr_get_type(rr)) {
1905 /* if ldns_rr_rd_count(rr) > 0
1906 then ldns_rr_rdf(rr, 0) exists! */
1907 if (! (fmt_st->flags & LDNS_COMMENT_KEY)) {
1908 break;
1909 }
1910 flags = ldns_rdf2native_int16(ldns_rr_rdf(rr, 0));
1911 ldns_buffer_printf(output, " ;{");
1912 if (fmt_st->flags & LDNS_COMMENT_KEY_ID) {
1913 ldns_buffer_printf(output, "id = %u",
1914 (unsigned int) ldns_calc_keytag(rr));
1915 }
1916 if ((fmt_st->flags & LDNS_COMMENT_KEY_TYPE) &&
1917 (flags & LDNS_KEY_ZONE_KEY)){
1918
1919 if (flags & LDNS_KEY_SEP_KEY) {
1920 ldns_buffer_printf(output, " (ksk)");
1921 } else {
1922 ldns_buffer_printf(output, " (zsk)");
1923 }
1924 if (fmt_st->flags & LDNS_COMMENT_KEY_SIZE){
1925 ldns_buffer_printf(output, ", ");
1926 }
1927 } else if (fmt_st->flags
1930 ldns_buffer_printf( output, ", ");
1931 }
1932 if (fmt_st->flags & LDNS_COMMENT_KEY_SIZE) {
1933 ldns_buffer_printf(output, "size = %db",
1935 }
1936 ldns_buffer_printf(output, "}");
1937 break;
1938 case LDNS_RR_TYPE_RRSIG:
1939 if ((fmt_st->flags & LDNS_COMMENT_KEY)
1940 && (fmt_st->flags& LDNS_COMMENT_RRSIGS)
1941 && ldns_rr_rdf(rr, 6) != NULL) {
1942 ldns_buffer_printf(output, " ;{id = %d}",
1944 ldns_rr_rdf(rr, 6)));
1945 }
1946 break;
1947 case LDNS_RR_TYPE_DS:
1948 if ((fmt_st->flags & LDNS_COMMENT_BUBBLEBABBLE) &&
1949 ldns_rr_rdf(rr, 3) != NULL) {
1950
1951 uint8_t *data = ldns_rdf_data(
1952 ldns_rr_rdf(rr, 3));
1953 size_t len = ldns_rdf_size(ldns_rr_rdf(rr, 3));
1954 char *babble = ldns_bubblebabble(data, len);
1955 if(babble) {
1956 ldns_buffer_printf(output,
1957 " ;{%s}", babble);
1958 }
1959 LDNS_FREE(babble);
1960 }
1961 break;
1962 case LDNS_RR_TYPE_NSEC3:
1963 if (! (fmt_st->flags & LDNS_COMMENT_FLAGS) &&
1964 ! (fmt_st->flags & LDNS_COMMENT_NSEC3_CHAIN)) {
1965 break;
1966 }
1967 ldns_buffer_printf(output, " ;{");
1968 if ((fmt_st->flags & LDNS_COMMENT_FLAGS)) {
1969 if (ldns_nsec3_optout(rr)) {
1970 ldns_buffer_printf(output,
1971 " flags: optout");
1972 } else {
1973 ldns_buffer_printf(output," flags: -");
1974 }
1975 if (fmt_st->flags & LDNS_COMMENT_NSEC3_CHAIN &&
1976 fmt_st->hashmap != NULL) {
1977 ldns_buffer_printf(output, ", ");
1978 }
1979 }
1980 if (fmt_st->flags & LDNS_COMMENT_NSEC3_CHAIN &&
1981 fmt_st->hashmap != NULL) {
1982 ldns_rbnode_t *node;
1984 ldns_rr_owner(rr), 0);
1985 if (key) {
1986 node = ldns_rbtree_search(
1987 fmt_st->hashmap,
1988 (void *) key);
1989 if (node->data) {
1990 ldns_buffer_printf(output,
1991 "from: ");
1992 (void) ldns_rdf2buffer_str(
1993 output,
1996 node->data
1997 ));
1998 }
1999 ldns_rdf_deep_free(key);
2000 }
2001 key = ldns_b32_ext2dname(
2003 if (key) {
2004 node = ldns_rbtree_search(
2005 fmt_st->hashmap,
2006 (void *) key);
2007 if (node->data) {
2008 ldns_buffer_printf(output,
2009 " to: ");
2010 (void) ldns_rdf2buffer_str(
2011 output,
2014 node->data
2015 ));
2016 }
2017 ldns_rdf_deep_free(key);
2018 }
2019 }
2020 ldns_buffer_printf(output, "}");
2021 break;
2022 default:
2023 break;
2024
2025 }
2026 }
2027 /* last */
2028 ldns_buffer_printf(output, "\n");
2029 return ldns_buffer_status(output);
2030}
2031
2034{
2036}
2037
2040 const ldns_output_format *fmt, const ldns_rr_list *list)
2041{
2042 uint16_t i;
2043
2044 for(i = 0; i < ldns_rr_list_rr_count(list); i++) {
2045 (void) ldns_rr2buffer_str_fmt(output, fmt,
2046 ldns_rr_list_rr(list, i));
2047 }
2048 return ldns_buffer_status(output);
2049}
2050
2053{
2055 output, ldns_output_format_default, list);
2056}
2057
2060{
2062 (int) ldns_pkt_get_opcode(pkt));
2064 (int) ldns_pkt_get_rcode(pkt));
2065
2066 ldns_buffer_printf(output, ";; ->>HEADER<<- ");
2067 if (opcode) {
2068 ldns_buffer_printf(output, "opcode: %s, ", opcode->name);
2069 } else {
2070 ldns_buffer_printf(output, "opcode: ?? (%u), ",
2071 ldns_pkt_get_opcode(pkt));
2072 }
2073 if (rcode) {
2074 ldns_buffer_printf(output, "rcode: %s, ", rcode->name);
2075 } else {
2076 ldns_buffer_printf(output, "rcode: ?? (%u), ", ldns_pkt_get_rcode(pkt));
2077 }
2078 ldns_buffer_printf(output, "id: %d\n", ldns_pkt_id(pkt));
2079 ldns_buffer_printf(output, ";; flags: ");
2080
2081 if (ldns_pkt_qr(pkt)) {
2082 ldns_buffer_printf(output, "qr ");
2083 }
2084 if (ldns_pkt_aa(pkt)) {
2085 ldns_buffer_printf(output, "aa ");
2086 }
2087 if (ldns_pkt_tc(pkt)) {
2088 ldns_buffer_printf(output, "tc ");
2089 }
2090 if (ldns_pkt_rd(pkt)) {
2091 ldns_buffer_printf(output, "rd ");
2092 }
2093 if (ldns_pkt_cd(pkt)) {
2094 ldns_buffer_printf(output, "cd ");
2095 }
2096 if (ldns_pkt_ra(pkt)) {
2097 ldns_buffer_printf(output, "ra ");
2098 }
2099 if (ldns_pkt_ad(pkt)) {
2100 ldns_buffer_printf(output, "ad ");
2101 }
2102 ldns_buffer_printf(output, "; ");
2103 ldns_buffer_printf(output, "QUERY: %u, ", ldns_pkt_qdcount(pkt));
2104 ldns_buffer_printf(output, "ANSWER: %u, ", ldns_pkt_ancount(pkt));
2105 ldns_buffer_printf(output, "AUTHORITY: %u, ", ldns_pkt_nscount(pkt));
2106 ldns_buffer_printf(output, "ADDITIONAL: %u ", ldns_pkt_arcount(pkt));
2107 return ldns_buffer_status(output);
2108}
2109
2110
2111/* print EDNS option data in the Dig format: 76 61 6c 69 ... */
2112static void
2113ldns_edns_hex_data2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2114{
2115 size_t j;
2116 for (j = 0; j < len; j++) {
2117 ldns_buffer_printf(output, " %02x", data[j]);
2118 }
2119}
2120
2121static ldns_status
2122ldns_edns_llq2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2123{
2124 /* LLQ constants */
2125 const char* llq_errors[] = {"NO-ERROR", "SERV-FULL", "STATIC",
2126 "FORMAT-ERR", "NO-SUCH-LLQ", "BAD-VERS", "UNKNOWN_ERR"};
2127 const unsigned int llq_errors_num = 7;
2128 const char* llq_opcodes[] = {"LLQ-SETUP", "LLQ-REFRESH", "LLQ-EVENT"};
2129 const unsigned int llq_opcodes_num = 3;
2130
2131 uint16_t version, llq_opcode, error_code;
2132 uint64_t llq_id;
2133 uint32_t lease_life; /* Requested or granted life of LLQ, in seconds */
2134
2135 ldns_buffer_printf(output, "; Long-Lived Query:");
2136
2137 /* read the record */
2138 if(len != 18) {
2139 ldns_buffer_printf(output, " malformed LLQ ");
2140 ldns_edns_hex_data2buffer_str(output, data, len);
2141
2142 return ldns_buffer_status(output);
2143 }
2144 version = ldns_read_uint16(data);
2145 llq_opcode = ldns_read_uint16(data+2);
2146 error_code = ldns_read_uint16(data+4);
2147 memmove(&llq_id, data+6, sizeof(uint64_t));
2148 lease_life = ldns_read_uint32(data+14);
2149
2150 /* print option field entires */
2151 ldns_buffer_printf(output, "v%d ", (int)version);
2152
2153 if(llq_opcode < llq_opcodes_num) {
2154 ldns_buffer_printf(output, "%s", llq_opcodes[llq_opcode]);
2155 } else {
2156 ldns_buffer_printf(output, "opcode %d", (int)llq_opcode);
2157 }
2158
2159 if(error_code < llq_errors_num)
2160 ldns_buffer_printf(output, " %s", llq_errors[error_code]);
2161 else {
2162 ldns_buffer_printf(output, " error %d", (int)error_code);
2163 }
2164
2165#ifndef USE_WINSOCK
2166 ldns_buffer_printf(output, " id %llx lease-life %lu",
2167 (unsigned long long)llq_id, (unsigned long)lease_life);
2168#else
2169 ldns_buffer_printf(output, " id %I64x lease-life %lu",
2170 (unsigned long long)llq_id, (unsigned long)lease_life);
2171#endif
2172 return ldns_buffer_status(output);
2173}
2174
2175
2176static ldns_status
2177ldns_edns_ul2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2178{
2179 uint32_t lease;
2180
2181 ldns_buffer_printf(output, "; Update Lease:");
2182
2183 if(len != 4) {
2184 ldns_buffer_printf(output, " malformed UL ");
2185 ldns_edns_hex_data2buffer_str(output, data, len);
2186 return ldns_buffer_status(output);
2187 }
2188 lease = ldns_read_uint32(data);
2189 ldns_buffer_printf(output, "lease %lu", (unsigned long)lease);
2190
2191 return ldns_buffer_status(output);
2192}
2193
2194static ldns_status
2195ldns_edns_nsid2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2196{
2197 size_t i, printed=0;
2198
2199 ldns_buffer_printf(output, "; NSID:");
2200 ldns_edns_hex_data2buffer_str(output, data, len);
2201
2202 /* print the human-readable text string */
2203 for(i = 0; i < len; i++) {
2204 if(isprint((unsigned char)data[i]) || data[i] == '\t') {
2205 if(!printed) {
2206 ldns_buffer_printf(output, " (");
2207 printed = 1;
2208 }
2209 ldns_buffer_printf(output, "%c", (char)data[i]);
2210 }
2211 }
2212 if(printed)
2213 ldns_buffer_printf(output, ")");
2214 return ldns_buffer_status(output);
2215}
2216
2217
2218static ldns_status
2219ldns_edns_dau2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2220{
2221 size_t i;
2223
2224 ldns_buffer_printf(output, "; DNSSEC Algorithm Understood (DAU):");
2225
2226 for(i = 0; i <len; i++) {
2227 lt = ldns_lookup_by_id(ldns_algorithms, data[i]);
2228 if (lt && lt->name) {
2229 ldns_buffer_printf(output, " %s", lt->name);
2230 } else {
2231 ldns_buffer_printf(output, " ALG%u", data[i]);
2232 }
2233 }
2234 return ldns_buffer_status(output);
2235}
2236
2237static ldns_status
2238ldns_edns_dhu2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2239{
2240 size_t i;
2242
2243 ldns_buffer_printf(output, "; DS Hash Understood (DHU):");
2244
2245 for(i = 0; i < len; i++) {
2246 lt = ldns_lookup_by_id(ldns_hashes, data[i]);
2247 if (lt && lt->name) {
2248 ldns_buffer_printf(output, " %s", lt->name);
2249 } else {
2250 ldns_buffer_printf(output, " ALG%u", data[i]);
2251 }
2252 }
2253 return ldns_buffer_status(output);
2254}
2255
2256static ldns_status
2257ldns_edns_d3u2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2258{
2259 size_t i;
2260
2261 ldns_buffer_printf(output, "; NSEC3 Hash Understood (N3U):");
2262
2263 for(i=0; i<len; i++) {
2264 if(data[i] == 1) {
2265 ldns_buffer_printf(output, " SHA1");
2266 } else {
2267 ldns_buffer_printf(output, " %d", (int)data[i]);
2268 }
2269 }
2270 return ldns_buffer_status(output);
2271}
2272
2273static ldns_status
2274ldns_edns_subnet2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2275{
2276 uint16_t family;
2277 uint8_t source, scope;
2278
2279 ldns_buffer_printf(output, "; CLIENT SUBNET: ");
2280
2281 if(len < 4) {
2282 ldns_buffer_printf(output, "malformed subnet ");
2283 ldns_edns_hex_data2buffer_str(output, data, len);
2284 return ldns_buffer_status(output);
2285 }
2286
2287
2288 family = ldns_read_uint16(data);
2289 source = data[2];
2290 scope = data[3];
2291 if(family == 1) {
2292 /* IPv4 */
2293 char buf[64];
2294 uint8_t ip4[4];
2295 memset(ip4, 0, sizeof(ip4));
2296 if(len-4 > 4) {
2297 ldns_buffer_printf(output, "trailingdata:");
2298 ldns_edns_hex_data2buffer_str(output, data+4+4, len-4-4);
2299 ldns_buffer_printf(output, " ");
2300 len = 4+4;
2301 }
2302 memmove(ip4, data+4, len-4);
2303 if(!inet_ntop(AF_INET, ip4, buf, (socklen_t) sizeof(buf))) {
2304 ldns_buffer_printf(output, "ip4ntoperror ");
2305 ldns_edns_hex_data2buffer_str(output, data+4+4, len-4-4);
2306 } else {
2307 ldns_buffer_printf(output, "%s", buf);
2308 }
2309 } else if(family == 2) {
2310 /* IPv6 */
2311 char buf[64];
2312 uint8_t ip6[16];
2313 memset(ip6, 0, sizeof(ip6));
2314 if(len-4 > 16) {
2315 ldns_buffer_printf(output, "trailingdata:");
2316 ldns_edns_hex_data2buffer_str(output, data+4+16, len-4-16);
2317 ldns_buffer_printf(output, " ");
2318 len = 4+16;
2319 }
2320 memmove(ip6, data+4, len-4);
2321#ifdef AF_INET6
2322 if(!inet_ntop(AF_INET6, ip6, buf, (socklen_t) sizeof(buf))) {
2323 ldns_buffer_printf(output, "ip6ntoperror ");
2324 ldns_edns_hex_data2buffer_str(output, data+4+4, len-4-4);
2325 } else {
2326 ldns_buffer_printf(output, "%s", buf);
2327 }
2328#else
2329 ldns_edns_hex_data2buffer_str(output, data+4+4, len-4-4);
2330#endif
2331 } else {
2332 /* unknown */
2333 ldns_buffer_printf(output, "family %d ", (int)family);
2334 ldns_edns_hex_data2buffer_str(output, data, len);
2335 }
2336 ldns_buffer_printf(output, "/%d scope /%d", (int)source, (int)scope);
2337
2338 return ldns_buffer_status(output);
2339}
2340
2341static ldns_status
2342ldns_edns_expire2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2343{
2344
2345 ldns_buffer_printf(output, "; EXPIRE:");
2346
2347 if (!(len == 0) || len == 4) {
2348 ldns_buffer_printf(output, "malformed expire ");
2349 ldns_edns_hex_data2buffer_str(output, data, len);
2350
2351 return ldns_buffer_status(output);
2352 }
2353
2354 // TODO can this output be more accurate?
2355 ldns_edns_hex_data2buffer_str(output, data, len);
2356
2357 return ldns_buffer_status(output);
2358}
2359
2360
2361static ldns_status
2362ldns_edns_cookie2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2363{
2364 ldns_buffer_printf(output, "; COOKIE:");
2365
2366 /* the size of an EDNS cookie is restricted by RFC 7873 */
2367 if (!(len == 8 || (len >= 16 && len < 40))) {
2368 ldns_buffer_printf(output, "malformed cookie ");
2369 ldns_edns_hex_data2buffer_str(output, data, len);
2370 }
2371 ldns_edns_hex_data2buffer_str(output, data, len);
2372
2373 return ldns_buffer_status(output);
2374}
2375
2376static ldns_status
2377ldns_edns_keepalive2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2378{
2379 uint16_t timeout;
2380
2381 ldns_buffer_printf(output, "; KEEPALIVE:");
2382
2383 if(!(len == 0 || len == 2)) {
2384 ldns_buffer_printf(output, "malformed keepalive ");
2385 ldns_edns_hex_data2buffer_str(output, data, len);
2386
2387 return ldns_buffer_status(output);
2388 }
2389
2390 if(len == 0) {
2391 ldns_buffer_printf(output, "no timeout value (only valid for client option)");
2392 } else {
2393 timeout = ldns_read_uint16(data);
2394 ldns_buffer_printf(output, "timeout value in units of 100ms %u", (int)timeout);
2395 }
2396 return ldns_buffer_status(output);
2397}
2398
2399static ldns_status
2400ldns_edns_padding2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2401{
2402 ldns_buffer_printf(output, "; PADDING: ");
2403 ldns_edns_hex_data2buffer_str(output, data, len);
2404
2405 return ldns_buffer_status(output);
2406}
2407
2408static ldns_status
2409ldns_edns_chain2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2410{
2411 ldns_rdf* temp = NULL;
2412
2413 ldns_buffer_printf(output, "; CHAIN: ");
2414
2415 if (ldns_str2rdf_dname(&temp, (char*) data) != LDNS_STATUS_OK) {
2416 ldns_buffer_printf(output, "malformed chain ");
2417 ldns_edns_hex_data2buffer_str(output, data, len);
2418
2419 return ldns_buffer_status(output);
2420 }
2421
2422 ldns_characters2buffer_str(output, len, data);
2423
2424 return ldns_buffer_status(output);
2425}
2426
2427static ldns_status
2428ldns_edns_key_tag2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2429{
2430 size_t i;
2431
2432 ldns_buffer_printf(output, "; KEY TAG: ");
2433
2434 if(len < 2 || len % 2 != 0) {
2435 ldns_buffer_printf(output, "malformed key tag ");
2436 ldns_edns_hex_data2buffer_str(output, data, len);
2437
2438 return ldns_buffer_status(output);
2439 }
2440
2441 for (i = 0; i < len; i += 2) {
2442 uint16_t tag = ldns_read_uint16(data);
2443
2444 ldns_buffer_printf(output, " %hu", tag);
2445 }
2446
2447 return ldns_buffer_status(output);
2448}
2449
2450static ldns_status
2451ldns_edns_ede2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2452{
2453 size_t i;
2454 uint16_t ede;
2455 ldns_buffer_printf(output, "; EDE:");
2456
2457 if(len < 2) {
2458 ldns_buffer_printf(output, "malformed ede ");
2459 ldns_edns_hex_data2buffer_str(output, data, len);
2460
2461 return ldns_buffer_status(output);
2462 }
2463
2464 ede = ldns_read_uint16(data);
2465
2466 switch (ede) {
2467 case LDNS_EDE_OTHER:
2468 ldns_buffer_printf(output, " 0 (Other): ");
2469 break;
2471 ldns_buffer_printf(output, " 1 (Unsupported DNSKEY Algorithm)");
2472 break;
2474 ldns_buffer_printf(output, " 2 (Unsupported DS Digest type)");
2475 break;
2477 ldns_buffer_printf(output, " 3 (Stale Answer)");
2478 break;
2480 ldns_buffer_printf(output, " 4 (Forged Answer)");
2481 break;
2483 ldns_buffer_printf(output, " 5 (DNSSEC Indeterminate)");
2484 break;
2486 ldns_buffer_printf(output, " 6 (DNSSEC Bogus)");
2487 break;
2489 ldns_buffer_printf(output, " 7 (Signature Expired)");
2490 break;
2492 ldns_buffer_printf(output, " 8 (Signature Not Yet Valid)");
2493 break;
2495 ldns_buffer_printf(output, " 9 (DNSKEY Missing)");
2496 break;
2498 ldns_buffer_printf(output, " 10 (RRSIGs Missing)");
2499 break;
2501 ldns_buffer_printf(output, " 11 (No Zone Key Bit Set)");
2502 break;
2504 ldns_buffer_printf(output, " 12 (NSEC Missing)");
2505 break;
2507 ldns_buffer_printf(output, " 13 (Cached Error)");
2508 break;
2509 case LDNS_EDE_NOT_READY:
2510 ldns_buffer_printf(output, " 14 (Not Ready)");
2511 break;
2512 case LDNS_EDE_BLOCKED:
2513 ldns_buffer_printf(output, " 15 (Blocked)");
2514 break;
2515 case LDNS_EDE_CENSORED:
2516 ldns_buffer_printf(output, " 16 (Censored)");
2517 break;
2518 case LDNS_EDE_FILTERED:
2519 ldns_buffer_printf(output, " 17 (Filtered)");
2520 break;
2522 ldns_buffer_printf(output, " 18 (Prohibited)");
2523 break;
2525 ldns_buffer_printf(output, " 19 (NXDOMAIN Answer)");
2526 break;
2528 ldns_buffer_printf(output, " 20 (Not Authoritative)");
2529 break;
2531 ldns_buffer_printf(output, " 21 (Not Supported)");
2532 break;
2534 ldns_buffer_printf(output, " 22 (No Reachable Authority)");
2535 break;
2537 ldns_buffer_printf(output, " 23 (Network Error)");
2538 break;
2540 ldns_buffer_printf(output, " 24 (Invalid Data)");
2541 break;
2543 ldns_buffer_printf(output, " 25 (Signature Expired Before Valid)");
2544 break;
2545 case LDNS_EDE_TOO_EARLY:
2546 ldns_buffer_printf(output, " 26 (Too Early)");
2547 break;
2548 default:
2549 ldns_buffer_printf(output, " %02x", data[0]);
2550 ldns_buffer_printf(output, " %02x", data[1]);
2551 break;
2552 }
2553
2554 /* skip the EDE code in the output */
2555 data += 2;
2556 len -= 2;
2557
2558 if (len > 2) {
2559 /* format the hex bytes */
2560 ldns_buffer_printf(output, ":");
2561 for (i = 0; i < len; i++) {
2562 ldns_buffer_printf(output, " %02x", data[i]);
2563 }
2564
2565 /* format the human-readable string */
2566 ldns_buffer_printf(output, " (");
2567 ldns_characters2buffer_str(output, len, data);
2568 ldns_buffer_printf(output, ")");
2569 }
2570
2571 return ldns_buffer_status(output);
2572}
2573
2574static ldns_status
2575ldns_edns_client_tag2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2576{
2577 ldns_buffer_printf(output, "; CLIENT-TAG:");
2578
2579 if (len > 2) {
2580 ldns_buffer_printf(output, "malformed client-tag ");
2581 ldns_edns_hex_data2buffer_str(output, data, len);
2582
2583 return ldns_buffer_status(output);
2584 }
2585
2586 ldns_edns_hex_data2buffer_str(output, data, len);
2587
2588 return ldns_buffer_status(output);
2589}
2590
2591static ldns_status
2592ldns_edns_server_tag2buffer_str(ldns_buffer* output, uint8_t* data, size_t len)
2593{
2594 ldns_buffer_printf(output, "; SERVER-TAG:");
2595
2596 if (len > 2) {
2597 ldns_buffer_printf(output, "malformed server-tag ");
2598 ldns_edns_hex_data2buffer_str(output, data, len);
2599
2600 return ldns_buffer_status(output);
2601 }
2602
2603 ldns_edns_hex_data2buffer_str(output, data, len);
2604
2605 return ldns_buffer_status(output);
2606}
2607
2610{
2611 size_t count = ldns_edns_option_list_get_count(edns_list);
2612 size_t i, size;
2613 uint8_t* data;
2614
2615 for (i = 0; i < count; i++) {
2618
2619 if (!edns) {
2620 break;
2621 }
2622
2623 code = ldns_edns_get_code(edns);
2624 size = ldns_edns_get_size(edns);
2625 data = ldns_edns_get_data(edns);
2626
2627 switch(code) {
2628 case LDNS_EDNS_LLQ:
2629 ldns_edns_llq2buffer_str(output, data, size);
2630 break;
2631 case LDNS_EDNS_UL:
2632 ldns_edns_ul2buffer_str(output, data, size);
2633 break;
2634 case LDNS_EDNS_NSID:
2635 ldns_edns_nsid2buffer_str(output, data, size);
2636 break;
2637 case LDNS_EDNS_DAU:
2638 ldns_edns_dau2buffer_str(output, data, size);
2639 break;
2640 case LDNS_EDNS_DHU:
2641 ldns_edns_dhu2buffer_str(output, data, size);
2642 break;
2643 case LDNS_EDNS_N3U:
2644 ldns_edns_d3u2buffer_str(output, data, size);
2645 break;
2647 ldns_edns_subnet2buffer_str(output, data, size);
2648 break;
2649 case LDNS_EDNS_EXPIRE:
2650 ldns_edns_expire2buffer_str(output, data, size);
2651 break;
2652 case LDNS_EDNS_COOKIE:
2653 ldns_edns_cookie2buffer_str(output, data, size);
2654 break;
2656 ldns_edns_keepalive2buffer_str(output, data, size);
2657 break;
2658 case LDNS_EDNS_PADDING:
2659 ldns_edns_padding2buffer_str(output, data, size);
2660 break;
2661 case LDNS_EDNS_CHAIN:
2662 ldns_edns_chain2buffer_str(output, data, size);
2663 break;
2664 case LDNS_EDNS_KEY_TAG:
2665 ldns_edns_key_tag2buffer_str(output, data, size);
2666 break;
2667 case LDNS_EDNS_EDE:
2668 ldns_edns_ede2buffer_str(output, data, size);
2669 break;
2671 ldns_edns_client_tag2buffer_str(output, data, size);
2672 break;
2674 ldns_edns_server_tag2buffer_str(output, data, size);
2675 break;
2676 default:
2677 ldns_buffer_printf(output, "; OPT=%d:", code);
2678 ldns_edns_hex_data2buffer_str(output, data, size);
2679 break;
2680 }
2681 ldns_buffer_printf(output, "\n");
2682 }
2683
2684 return ldns_buffer_status(output);
2685}
2686
2687
2690 const ldns_output_format *fmt, const ldns_pkt *pkt)
2691{
2692 uint16_t i;
2693 ldns_status status = LDNS_STATUS_OK;
2694 char *tmp;
2695 struct timeval time;
2696 time_t time_tt;
2697 int short_fmt = fmt && (fmt->flags & LDNS_FMT_SHORT);
2698
2699 if (!pkt) {
2700 ldns_buffer_printf(output, "null");
2701 return LDNS_STATUS_OK;
2702 }
2703
2704 if (!ldns_buffer_status_ok(output)) {
2705 return ldns_buffer_status(output);
2706 }
2707
2708 if (!short_fmt) {
2709 status = ldns_pktheader2buffer_str(output, pkt);
2710 if (status != LDNS_STATUS_OK) {
2711 return status;
2712 }
2713
2714 ldns_buffer_printf(output, "\n");
2715
2716 ldns_buffer_printf(output, ";; QUESTION SECTION:\n;; ");
2717
2718
2719 for (i = 0; i < ldns_pkt_qdcount(pkt); i++) {
2720 status = ldns_rr2buffer_str_fmt(output, fmt,
2722 ldns_pkt_question(pkt), i));
2723 if (status != LDNS_STATUS_OK) {
2724 return status;
2725 }
2726 }
2727 ldns_buffer_printf(output, "\n");
2728
2729 ldns_buffer_printf(output, ";; ANSWER SECTION:\n");
2730 }
2731 for (i = 0; i < ldns_pkt_ancount(pkt); i++) {
2732 status = ldns_rr2buffer_str_fmt(output, fmt,
2734 ldns_pkt_answer(pkt), i));
2735 if (status != LDNS_STATUS_OK) {
2736 return status;
2737 }
2738 }
2739 if (!short_fmt) {
2740 ldns_buffer_printf(output, "\n");
2741
2742 ldns_buffer_printf(output, ";; AUTHORITY SECTION:\n");
2743
2744 for (i = 0; i < ldns_pkt_nscount(pkt); i++) {
2745 status = ldns_rr2buffer_str_fmt(output, fmt,
2747 ldns_pkt_authority(pkt), i));
2748 if (status != LDNS_STATUS_OK) {
2749 return status;
2750 }
2751 }
2752 ldns_buffer_printf(output, "\n");
2753
2754 ldns_buffer_printf(output, ";; ADDITIONAL SECTION:\n");
2755
2756 for (i = 0; i < ldns_pkt_arcount(pkt); i++) {
2757 status = ldns_rr2buffer_str_fmt(output, fmt,
2759 ldns_pkt_additional(pkt), i));
2760 if (status != LDNS_STATUS_OK) {
2761 return status;
2762 }
2763
2764 }
2765 ldns_buffer_printf(output, "\n");
2766 /* add some further fields */
2767 ldns_buffer_printf(output, ";; Query time: %d msec\n",
2768 ldns_pkt_querytime(pkt));
2769 if (ldns_pkt_edns(pkt)) {
2770 ldns_buffer_printf(output,
2771 ";; EDNS: version %u; flags:",
2773 if (ldns_pkt_edns_do(pkt)) {
2774 ldns_buffer_printf(output, " do");
2775 }
2776 /* the extended rcode is the value set, shifted four bits,
2777 * and or'd with the original rcode */
2779 ldns_buffer_printf(output, " ; ext-rcode: %d",
2781 }
2782 ldns_buffer_printf(output, " ; udp: %u\n",
2784
2785 if (pkt->_edns_list)
2787
2788 else if (ldns_pkt_edns_data(pkt)) {
2789 ldns_edns_option_list* edns_list;
2790 /* parse the EDNS data into separate EDNS options
2791 * and add them to the list */
2792 if ((edns_list = pkt_edns_data2edns_option_list(ldns_pkt_edns_data(pkt)))) {
2793 ldns_edns_option_list2buffer_str(output, edns_list);
2795 } else {
2796 ldns_buffer_printf(output, ";; Data: ");
2797 (void)ldns_rdf2buffer_str(output, ldns_pkt_edns_data(pkt));
2798 ldns_buffer_printf(output, "\n");
2799 }
2800 }
2801 }
2802 if (ldns_pkt_tsig(pkt)) {
2803 ldns_buffer_printf(output, ";; TSIG:\n;; ");
2805 output, fmt, ldns_pkt_tsig(pkt));
2806 ldns_buffer_printf(output, "\n");
2807 }
2808 if (ldns_pkt_answerfrom(pkt)) {
2810 ldns_buffer_printf(output, ";; SERVER: %s\n", tmp);
2811 LDNS_FREE(tmp);
2812 }
2813 time = ldns_pkt_timestamp(pkt);
2814 time_tt = (time_t)time.tv_sec;
2815 ldns_buffer_printf(output, ";; WHEN: %s",
2816 (char*)ctime(&time_tt));
2817
2818 ldns_buffer_printf(output, ";; MSG SIZE rcvd: %d\n",
2819 (int)ldns_pkt_size(pkt));
2820 }
2821 return status;
2822}
2823
2826{
2828}
2829
2830
2831#ifdef HAVE_SSL
2832static ldns_status
2833ldns_hmac_key2buffer_str(ldns_buffer *output, const ldns_key *k)
2834{
2835 ldns_status status;
2836 size_t i;
2837 ldns_rdf *b64_bignum;
2838
2839 ldns_buffer_printf(output, "Key: ");
2840
2841 i = ldns_key_hmac_size(k);
2843 status = ldns_rdf2buffer_str(output, b64_bignum);
2844 ldns_rdf_deep_free(b64_bignum);
2845 ldns_buffer_printf(output, "\n");
2846 return status;
2847}
2848#endif
2849
2850#if defined(HAVE_SSL) && defined(USE_GOST)
2851static ldns_status
2852ldns_gost_key2buffer_str(ldns_buffer *output, EVP_PKEY *p)
2853{
2854 unsigned char* pp = NULL;
2855 int ret;
2856 ldns_rdf *b64_bignum;
2857 ldns_status status;
2858
2859 ldns_buffer_printf(output, "GostAsn1: ");
2860
2861 ret = i2d_PrivateKey(p, &pp);
2862 b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, (size_t)ret, pp);
2863 status = ldns_rdf2buffer_str(output, b64_bignum);
2864
2865 ldns_rdf_deep_free(b64_bignum);
2866 OPENSSL_free(pp);
2867 ldns_buffer_printf(output, "\n");
2868 return status;
2869}
2870#endif
2871
2872#if defined(HAVE_SSL) && defined(USE_ED25519)
2873static ldns_status
2874ldns_ed25519_key2buffer_str(ldns_buffer *output, EVP_PKEY *p)
2875{
2876 unsigned char* pp = NULL;
2877 int ret;
2878 ldns_rdf *b64_bignum;
2879 ldns_status status;
2880
2881 ldns_buffer_printf(output, "PrivateKey: ");
2882
2883 ret = i2d_PrivateKey(p, &pp);
2884 /* 16 byte asn (302e020100300506032b657004220420) + 32byte key */
2885 if(ret != 16 + 32) {
2886 OPENSSL_free(pp);
2887 return LDNS_STATUS_ERR;
2888 }
2890 (size_t)ret-16, pp+16);
2891 status = ldns_rdf2buffer_str(output, b64_bignum);
2892
2893 ldns_rdf_deep_free(b64_bignum);
2894 OPENSSL_free(pp);
2895 ldns_buffer_printf(output, "\n");
2896 return status;
2897}
2898#endif
2899
2900#if defined(HAVE_SSL) && defined(USE_ED448)
2901static ldns_status
2902ldns_ed448_key2buffer_str(ldns_buffer *output, EVP_PKEY *p)
2903{
2904 unsigned char* pp = NULL;
2905 int ret;
2906 ldns_rdf *b64_bignum;
2907 ldns_status status;
2908
2909 ldns_buffer_printf(output, "PrivateKey: ");
2910
2911 ret = i2d_PrivateKey(p, &pp);
2912 /* some-ASN + 57byte key */
2913 if(ret != 16 + 57) {
2914 OPENSSL_free(pp);
2915 return LDNS_STATUS_ERR;
2916 }
2918 (size_t)ret-16, pp+16);
2919 status = ldns_rdf2buffer_str(output, b64_bignum);
2920
2921 ldns_rdf_deep_free(b64_bignum);
2922 OPENSSL_free(pp);
2923 ldns_buffer_printf(output, "\n");
2924 return status;
2925}
2926#endif
2927
2928#if defined(HAVE_SSL)
2930static int
2931ldns_print_bignum_b64_line(ldns_buffer* output, const char* label, const BIGNUM* num)
2932{
2933 unsigned char *bignumbuf = LDNS_XMALLOC(unsigned char, LDNS_MAX_KEYLEN);
2934 if(!bignumbuf) return 0;
2935
2936 ldns_buffer_printf(output, "%s: ", label);
2937 if(num) {
2938 ldns_rdf *b64_bignum = NULL;
2939 int i = BN_bn2bin(num, bignumbuf);
2940 if (i > LDNS_MAX_KEYLEN) {
2941 LDNS_FREE(bignumbuf);
2942 return 0;
2943 }
2944 b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, (size_t)i, bignumbuf);
2945 if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) {
2946 ldns_rdf_deep_free(b64_bignum);
2947 LDNS_FREE(bignumbuf);
2948 return 0;
2949 }
2950 ldns_rdf_deep_free(b64_bignum);
2951 ldns_buffer_printf(output, "\n");
2952 } else {
2953 ldns_buffer_printf(output, "(Not available)\n");
2954 }
2955 LDNS_FREE(bignumbuf);
2956 return 1;
2957}
2958#endif
2959
2962{
2963 ldns_status status = LDNS_STATUS_OK;
2964 unsigned char *bignum;
2965#ifdef HAVE_SSL
2966 RSA *rsa;
2967#ifdef USE_DSA
2968 DSA *dsa;
2969#endif /* USE_DSA */
2970#endif /* HAVE_SSL */
2971
2972 if (!k) {
2973 return LDNS_STATUS_ERR;
2974 }
2975
2976 bignum = LDNS_XMALLOC(unsigned char, LDNS_MAX_KEYLEN);
2977 if (!bignum) {
2978 return LDNS_STATUS_ERR;
2979 }
2980
2981 if (ldns_buffer_status_ok(output)) {
2982#ifdef HAVE_SSL
2983 switch(ldns_key_algorithm(k)) {
2984 case LDNS_SIGN_RSASHA1:
2988 case LDNS_SIGN_RSAMD5:
2989 /* copied by looking at dnssec-keygen output */
2990 /* header */
2991 rsa = ldns_key_rsa_key(k);
2992
2993 ldns_buffer_printf(output,"Private-key-format: v1.2\n");
2994 switch(ldns_key_algorithm(k)) {
2995 case LDNS_SIGN_RSAMD5:
2996 ldns_buffer_printf(output,
2997 "Algorithm: %u (RSA)\n",
2998 LDNS_RSAMD5);
2999 break;
3000 case LDNS_SIGN_RSASHA1:
3001 ldns_buffer_printf(output,
3002 "Algorithm: %u (RSASHA1)\n",
3003 LDNS_RSASHA1);
3004 break;
3006 ldns_buffer_printf(output,
3007 "Algorithm: %u (RSASHA1_NSEC3)\n",
3009 break;
3010#ifdef USE_SHA2
3012 ldns_buffer_printf(output,
3013 "Algorithm: %u (RSASHA256)\n",
3015 break;
3017 ldns_buffer_printf(output,
3018 "Algorithm: %u (RSASHA512)\n",
3020 break;
3021#endif
3022 default:
3023#ifdef STDERR_MSGS
3024 fprintf(stderr, "Warning: unknown signature ");
3025 fprintf(stderr,
3026 "algorithm type %u\n",
3028#endif
3029 ldns_buffer_printf(output,
3030 "Algorithm: %u (Unknown)\n",
3032 break;
3033 }
3034
3035 /* print to buf, convert to bin, convert to b64,
3036 * print to buf */
3037
3038#ifndef S_SPLINT_S
3039 if(1) {
3040 const BIGNUM *n=NULL, *e=NULL, *d=NULL,
3041 *p=NULL, *q=NULL, *dmp1=NULL,
3042 *dmq1=NULL, *iqmp=NULL;
3043#if OPENSSL_VERSION_NUMBER < 0x10100000 || (defined(HAVE_LIBRESSL) && LIBRESSL_VERSION_NUMBER < 0x20700000)
3044 n = rsa->n;
3045 e = rsa->e;
3046 d = rsa->d;
3047 p = rsa->p;
3048 q = rsa->q;
3049 dmp1 = rsa->dmp1;
3050 dmq1 = rsa->dmq1;
3051 iqmp = rsa->iqmp;
3052#else
3053 RSA_get0_key(rsa, &n, &e, &d);
3054 RSA_get0_factors(rsa, &p, &q);
3055 RSA_get0_crt_params(rsa, &dmp1,
3056 &dmq1, &iqmp);
3057#endif
3058 if(!ldns_print_bignum_b64_line(output, "Modulus", n))
3059 goto error;
3060 if(!ldns_print_bignum_b64_line(output, "PublicExponent", e))
3061 goto error;
3062 if(!ldns_print_bignum_b64_line(output, "PrivateExponent", d))
3063 goto error;
3064 if(!ldns_print_bignum_b64_line(output, "Prime1", p))
3065 goto error;
3066 if(!ldns_print_bignum_b64_line(output, "Prime2", q))
3067 goto error;
3068 if(!ldns_print_bignum_b64_line(output, "Exponent1", dmp1))
3069 goto error;
3070 if(!ldns_print_bignum_b64_line(output, "Exponent2", dmq1))
3071 goto error;
3072 if(!ldns_print_bignum_b64_line(output, "Coefficient", iqmp))
3073 goto error;
3074 }
3075#endif /* splint */
3076
3077 RSA_free(rsa);
3078 break;
3079#ifdef USE_DSA
3080 case LDNS_SIGN_DSA:
3082 dsa = ldns_key_dsa_key(k);
3083
3084 ldns_buffer_printf(output,"Private-key-format: v1.2\n");
3086 ldns_buffer_printf(output,"Algorithm: 3 (DSA)\n");
3087 } else if (ldns_key_algorithm(k) == LDNS_SIGN_DSA_NSEC3) {
3088 ldns_buffer_printf(output,"Algorithm: 6 (DSA_NSEC3)\n");
3089 }
3090
3091 /* print to buf, convert to bin, convert to b64,
3092 * print to buf */
3093 if(1) {
3094 const BIGNUM *p=NULL, *q=NULL, *g=NULL,
3095 *priv_key=NULL, *pub_key=NULL;
3096#if OPENSSL_VERSION_NUMBER < 0x10100000 || (defined(HAVE_LIBRESSL) && LIBRESSL_VERSION_NUMBER < 0x20700000)
3097#ifndef S_SPLINT_S
3098 p = dsa->p;
3099 q = dsa->q;
3100 g = dsa->g;
3101 priv_key = dsa->priv_key;
3102 pub_key = dsa->pub_key;
3103#endif /* splint */
3104#else
3105 DSA_get0_pqg(dsa, &p, &q, &g);
3106 DSA_get0_key(dsa, &pub_key, &priv_key);
3107#endif
3108 if(!ldns_print_bignum_b64_line(output, "Prime(p)", p))
3109 goto error;
3110 if(!ldns_print_bignum_b64_line(output, "Subprime(q)", q))
3111 goto error;
3112 if(!ldns_print_bignum_b64_line(output, "Base(g)", g))
3113 goto error;
3114 if(!ldns_print_bignum_b64_line(output, "Private_value(x)", priv_key))
3115 goto error;
3116 if(!ldns_print_bignum_b64_line(output, "Public_value(y)", pub_key))
3117 goto error;
3118 }
3119 break;
3120#endif /* USE_DSA */
3121 case LDNS_SIGN_ECC_GOST:
3122 /* no format defined, use blob */
3123#if defined(HAVE_SSL) && defined(USE_GOST)
3124 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3125 ldns_buffer_printf(output, "Algorithm: %d (ECC-GOST)\n", LDNS_SIGN_ECC_GOST);
3126 status = ldns_gost_key2buffer_str(output,
3127#ifndef S_SPLINT_S
3128 k->_key.key
3129#else
3130 NULL
3131#endif
3132 );
3133#else
3134 goto error;
3135#endif /* GOST */
3136 break;
3139#ifdef USE_ECDSA
3140 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3141 ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
3143#ifndef S_SPLINT_S
3144 ldns_buffer_printf(output, ")\n");
3145 if(k->_key.key) {
3146 EC_KEY* ec = EVP_PKEY_get1_EC_KEY(k->_key.key);
3147 const BIGNUM* b = EC_KEY_get0_private_key(ec);
3148 if(!ldns_print_bignum_b64_line(output, "PrivateKey", b))
3149 goto error;
3150 /* down reference count in EC_KEY
3151 * its still assigned to the PKEY */
3152 EC_KEY_free(ec);
3153 }
3154#endif /* splint */
3155#else
3156 goto error;
3157#endif /* ECDSA */
3158 break;
3159#ifdef USE_ED25519
3160 case LDNS_SIGN_ED25519:
3161 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3162 ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
3164 ldns_buffer_printf(output, ")\n");
3165 if (status) break;
3166 status = ldns_ed25519_key2buffer_str(output,
3167 k->_key.key);
3168 break;
3169#endif /* USE_ED25519 */
3170#ifdef USE_ED448
3171 case LDNS_SIGN_ED448:
3172 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3173 ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
3175 ldns_buffer_printf(output, ")\n");
3176 if (status) break;
3177 status = ldns_ed448_key2buffer_str(output,
3178 k->_key.key);
3179 break;
3180#endif /* USE_ED448 */
3181 case LDNS_SIGN_HMACMD5:
3182 /* there's not much of a format defined for TSIG */
3183 /* It's just a binary blob, Same for all algorithms */
3184 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3185 ldns_buffer_printf(output, "Algorithm: 157 (HMAC_MD5)\n");
3186 status = ldns_hmac_key2buffer_str(output, k);
3187 break;
3188 case LDNS_SIGN_HMACSHA1:
3189 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3190 ldns_buffer_printf(output, "Algorithm: 158 (HMAC_SHA1)\n");
3191 status = ldns_hmac_key2buffer_str(output, k);
3192 break;
3194 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3195 ldns_buffer_printf(output, "Algorithm: 162 (HMAC_SHA224)\n");
3196 status = ldns_hmac_key2buffer_str(output, k);
3197 break;
3199 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3200 ldns_buffer_printf(output, "Algorithm: 159 (HMAC_SHA256)\n");
3201 status = ldns_hmac_key2buffer_str(output, k);
3202 break;
3204 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3205 ldns_buffer_printf(output, "Algorithm: 164 (HMAC_SHA384)\n");
3206 status = ldns_hmac_key2buffer_str(output, k);
3207 break;
3209 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
3210 ldns_buffer_printf(output, "Algorithm: 165 (HMAC_SHA512)\n");
3211 status = ldns_hmac_key2buffer_str(output, k);
3212 break;
3213 }
3214#endif /* HAVE_SSL */
3215 } else {
3216 LDNS_FREE(bignum);
3217 return ldns_buffer_status(output);
3218 }
3219 LDNS_FREE(bignum);
3220 return status;
3221
3222#ifdef HAVE_SSL
3223 /* compiles warn the label isn't used */
3224error:
3225 LDNS_FREE(bignum);
3226 return LDNS_STATUS_ERR;
3227#endif /* HAVE_SSL */
3228
3229}
3230
3231/*
3232 * Zero terminate the buffer and copy data.
3233 */
3234char *
3236{
3237 char *str;
3238
3239 /* check if buffer ends with \0, if not, and
3240 if there is space, add it */
3241 if (*(ldns_buffer_at(buffer, ldns_buffer_position(buffer))) != 0) {
3242 if (!ldns_buffer_reserve(buffer, 1)) {
3243 return NULL;
3244 }
3245 ldns_buffer_write_char(buffer, (uint8_t) '\0');
3246 if (!ldns_buffer_set_capacity(buffer, ldns_buffer_position(buffer))) {
3247 return NULL;
3248 }
3249 }
3250
3251 str = strdup((const char *)ldns_buffer_begin(buffer));
3252 if(!str) {
3253 return NULL;
3254 }
3255 return str;
3256}
3257
3258/*
3259 * Zero terminate the buffer and export data.
3260 */
3261char *
3263{
3264 /* Append '\0' as string terminator */
3265 if (! ldns_buffer_reserve(buffer, 1)) {
3266 return NULL;
3267 }
3268 ldns_buffer_write_char(buffer, 0);
3269
3270 /* reallocate memory to the size of the string and export */
3271 ldns_buffer_set_capacity(buffer, ldns_buffer_position(buffer));
3272 return ldns_buffer_export(buffer);
3273}
3274
3275char *
3277{
3278 char *result = NULL;
3280
3281 if (!tmp_buffer) {
3282 return NULL;
3283 }
3284 if (ldns_rdf2buffer_str(tmp_buffer, rdf) == LDNS_STATUS_OK) {
3285 /* export and return string, destroy rest */
3286 result = ldns_buffer_export2str(tmp_buffer);
3287 }
3288 ldns_buffer_free(tmp_buffer);
3289 return result;
3290}
3291
3292char *
3294{
3295 char *result = NULL;
3297
3298 if (!tmp_buffer) {
3299 return NULL;
3300 }
3301 if (ldns_rr2buffer_str_fmt(tmp_buffer, fmt, rr)
3302 == LDNS_STATUS_OK) {
3303 /* export and return string, destroy rest */
3304 result = ldns_buffer_export2str(tmp_buffer);
3305 }
3306 ldns_buffer_free(tmp_buffer);
3307 return result;
3308}
3309
3310char *
3312{
3314}
3315
3316char *
3318{
3319 char *result = NULL;
3321
3322 if (!tmp_buffer) {
3323 return NULL;
3324 }
3325 if (ldns_pkt2buffer_str_fmt(tmp_buffer, fmt, pkt)
3326 == LDNS_STATUS_OK) {
3327 /* export and return string, destroy rest */
3328 result = ldns_buffer_export2str(tmp_buffer);
3329 }
3330
3331 ldns_buffer_free(tmp_buffer);
3332 return result;
3333}
3334
3335char *
3337{
3339}
3340
3341char *
3343{
3344 char *result = NULL;
3346
3347 if (!tmp_buffer) {
3348 return NULL;
3349 }
3350 if (ldns_key2buffer_str(tmp_buffer, k) == LDNS_STATUS_OK) {
3351 /* export and return string, destroy rest */
3352 result = ldns_buffer_export2str(tmp_buffer);
3353 }
3354 ldns_buffer_free(tmp_buffer);
3355 return result;
3356}
3357
3358char *
3360{
3361 char *result = NULL;
3363
3364 if (!tmp_buffer) {
3365 return NULL;
3366 }
3367 if (list) {
3369 tmp_buffer, fmt, list)
3370 == LDNS_STATUS_OK) {
3371 }
3372 } else {
3373 if (fmt == NULL) {
3375 }
3376 if (fmt->flags & LDNS_COMMENT_NULLS) {
3377 ldns_buffer_printf(tmp_buffer, "; (null)\n");
3378 }
3379 }
3380
3381 /* export and return string, destroy rest */
3382 result = ldns_buffer_export2str(tmp_buffer);
3383 ldns_buffer_free(tmp_buffer);
3384 return result;
3385}
3386
3387char *
3392
3393void
3394ldns_rdf_print(FILE *output, const ldns_rdf *rdf)
3395{
3396 char *str = ldns_rdf2str(rdf);
3397 if (str) {
3398 fprintf(output, "%s", str);
3399 } else {
3400 fprintf(output, ";Unable to convert rdf to string\n");
3401 }
3402 LDNS_FREE(str);
3403}
3404
3405void
3407 const ldns_output_format *fmt, const ldns_rr *rr)
3408{
3409 char *str = ldns_rr2str_fmt(fmt, rr);
3410 if (str) {
3411 fprintf(output, "%s", str);
3412 } else {
3413 fprintf(output, ";Unable to convert rr to string\n");
3414 }
3415 LDNS_FREE(str);
3416}
3417
3418void
3419ldns_rr_print(FILE *output, const ldns_rr *rr)
3420{
3422}
3423
3424void
3426 const ldns_output_format *fmt, const ldns_pkt *pkt)
3427{
3428 char *str = ldns_pkt2str_fmt(fmt, pkt);
3429 if (str) {
3430 fprintf(output, "%s", str);
3431 } else {
3432 fprintf(output, ";Unable to convert packet to string\n");
3433 }
3434 LDNS_FREE(str);
3435}
3436
3437void
3438ldns_pkt_print(FILE *output, const ldns_pkt *pkt)
3439{
3441}
3442
3443void
3445 const ldns_output_format *fmt, const ldns_rr_list *lst)
3446{
3447 size_t i;
3448 for (i = 0; i < ldns_rr_list_rr_count(lst); i++) {
3449 ldns_rr_print_fmt(output, fmt, ldns_rr_list_rr(lst, i));
3450 }
3451}
3452
3453void
3454ldns_rr_list_print(FILE *output, const ldns_rr_list *lst)
3455{
3457}
3458
3459void
3461 const ldns_output_format *fmt, const ldns_resolver *r)
3462{
3463 uint16_t i;
3464 ldns_rdf **n;
3465 ldns_rdf **s;
3466 size_t *rtt;
3467 if (!r) {
3468 return;
3469 }
3472 rtt = ldns_resolver_rtt(r);
3473
3474 fprintf(output, "port: %d\n", (int)ldns_resolver_port(r));
3475 fprintf(output, "edns0 size: %d\n", (int)ldns_resolver_edns_udp_size(r));
3476 fprintf(output, "use ip6: %d\n", (int)ldns_resolver_ip6(r));
3477
3478 fprintf(output, "recursive: %d\n", ldns_resolver_recursive(r));
3479 fprintf(output, "usevc: %d\n", ldns_resolver_usevc(r));
3480 fprintf(output, "igntc: %d\n", ldns_resolver_igntc(r));
3481 fprintf(output, "fail: %d\n", ldns_resolver_fail(r));
3482 fprintf(output, "retry: %d\n", (int)ldns_resolver_retry(r));
3483 fprintf(output, "retrans: %d\n", (int)ldns_resolver_retrans(r));
3484 fprintf(output, "fallback: %d\n", ldns_resolver_fallback(r));
3485 fprintf(output, "random: %d\n", ldns_resolver_random(r));
3486 fprintf(output, "timeout: %d\n", (int)ldns_resolver_timeout(r).tv_sec);
3487 fprintf(output, "dnssec: %d\n", ldns_resolver_dnssec(r));
3488 fprintf(output, "dnssec cd: %d\n", ldns_resolver_dnssec_cd(r));
3489 fprintf(output, "trust anchors (%d listed):\n",
3492 fprintf(output, "tsig: %s %s\n",
3495 fprintf(output, "debug: %d\n", ldns_resolver_debug(r));
3496
3497 fprintf(output, "default domain: ");
3499 fprintf(output, "\n");
3500 fprintf(output, "apply default domain: %d\n", ldns_resolver_defnames(r));
3501
3502 fprintf(output, "searchlist (%d listed):\n", (int)ldns_resolver_searchlist_count(r));
3503 for (i = 0; i < ldns_resolver_searchlist_count(r); i++) {
3504 fprintf(output, "\t");
3505 ldns_rdf_print(output, s[i]);
3506 fprintf(output, "\n");
3507 }
3508 fprintf(output, "apply search list: %d\n", ldns_resolver_dnsrch(r));
3509
3510 fprintf(output, "nameservers (%d listed):\n", (int)ldns_resolver_nameserver_count(r));
3511 for (i = 0; i < ldns_resolver_nameserver_count(r); i++) {
3512 fprintf(output, "\t");
3513 ldns_rdf_print(output, n[i]);
3514
3515 switch ((int)rtt[i]) {
3517 fprintf(output, " - reachable\n");
3518 break;
3520 fprintf(output, " - unreachable\n");
3521 break;
3522 }
3523 }
3524}
3525
3526void
3527ldns_resolver_print(FILE *output, const ldns_resolver *r)
3528{
3530}
3531
3532void
3534 const ldns_output_format *fmt, const ldns_zone *z)
3535{
3536 if(ldns_zone_soa(z))
3537 ldns_rr_print_fmt(output, fmt, ldns_zone_soa(z));
3538 ldns_rr_list_print_fmt(output, fmt, ldns_zone_rrs(z));
3539}
3540void
3541ldns_zone_print(FILE *output, const ldns_zone *z)
3542{
3544}
void ldns_buffer_free(ldns_buffer *buffer)
frees the buffer.
Definition buffer.c:137
ldns_buffer * ldns_buffer_new(size_t capacity)
creates a new buffer with the specified capacity.
Definition buffer.c:16
void * ldns_buffer_export(ldns_buffer *buffer)
Makes the buffer fixed and returns a pointer to the data.
Definition buffer.c:150
signed char ldns_buffer_set_capacity(ldns_buffer *buffer, size_t capacity)
changes the buffer's capacity.
Definition buffer.c:60
signed char ldns_buffer_reserve(ldns_buffer *buffer, size_t amount)
ensures BUFFER can contain at least AMOUNT more bytes.
Definition buffer.c:80
int ldns_buffer_printf(ldns_buffer *buffer, const char *format,...)
prints to the buffer, increasing the capacity if required using buffer_reserve().
Definition buffer.c:99
int ldns_b64_ntop(uint8_t const *src, size_t srclength, char *target, size_t targsize)
ldns_rdf * ldns_dname_label(const ldns_rdf *rdf, uint8_t labelpos)
look inside the rdf and if it is an LDNS_RDF_TYPE_DNAME try and retrieve a specific label.
Definition dname.c:560
ldns_rdf * ldns_nsec3_next_owner(const ldns_rr *nsec3_rr)
Returns the first label of the next ownername in the NSEC3 chain (ie.
Definition dnssec.c:1348
signed char ldns_nsec_bitmap_covers_type(const ldns_rdf *bitmap, ldns_rr_type type)
Check if RR type t is enumerated and set in the RR type bitmap rdf.
Definition dnssec.c:1393
#define LDNS_MAX_KEYLEN
Definition dnssec.h:41
uint16_t ldns_calc_keytag(const ldns_rr *key)
calculates a keytag of a key for use in DNSSEC.
Definition dnssec.c:277
signed char ldns_nsec3_optout(const ldns_rr *nsec3_rr)
Returns true if the opt-out flag has been set in the given NSEC3 RR.
Definition dnssec.c:1286
ldns_status ldns_nsec_bitmap_set_type(ldns_rdf *bitmap, ldns_rr_type type)
Checks if RR type t is enumerated in the type bitmap rdf and sets the bit.
Definition dnssec.c:1430
ldns_status ldns_nsec_bitmap_clear_type(ldns_rdf *bitmap, ldns_rr_type type)
Checks if RR type t is enumerated in the type bitmap rdf and clears the bit.
Definition dnssec.c:1468
ldns_rdf * ldns_dnssec_name_name(const ldns_dnssec_name *name)
Returns the domain name of the given dnssec_name structure.
@ LDNS_EDE_DNSSEC_INDETERMINATE
Definition edns.h:58
@ LDNS_EDE_NOT_SUPPORTED
Definition edns.h:74
@ LDNS_EDE_PROHIBITED
Definition edns.h:71
@ LDNS_EDE_NOT_READY
Definition edns.h:67
@ LDNS_EDE_UNSUPPORTED_DNSKEY_ALG
Definition edns.h:54
@ LDNS_EDE_RRSIGS_MISSING
Definition edns.h:63
@ LDNS_EDE_NO_REACHABLE_AUTHORITY
Definition edns.h:75
@ LDNS_EDE_SIGNATURE_EXPIRED
Definition edns.h:60
@ LDNS_EDE_DNSSEC_BOGUS
Definition edns.h:59
@ LDNS_EDE_CENSORED
Definition edns.h:69
@ LDNS_EDE_STALE_NXDOMAIN_ANSWER
Definition edns.h:72
@ LDNS_EDE_NO_ZONE_KEY_BIT_SET
Definition edns.h:64
@ LDNS_EDE_DNSKEY_MISSING
Definition edns.h:62
@ LDNS_EDE_NETWORK_ERROR
Definition edns.h:76
@ LDNS_EDE_FILTERED
Definition edns.h:70
@ LDNS_EDE_BLOCKED
Definition edns.h:68
@ LDNS_EDE_FORGED_ANSWER
Definition edns.h:57
@ LDNS_EDE_SIGNATURE_EXPIRED_BEFORE_VALID
Definition edns.h:78
@ LDNS_EDE_STALE_ANSWER
Definition edns.h:56
@ LDNS_EDE_NOT_AUTHORITATIVE
Definition edns.h:73
@ LDNS_EDE_CACHED_ERROR
Definition edns.h:66
@ LDNS_EDE_NSEC_MISSING
Definition edns.h:65
@ LDNS_EDE_OTHER
Definition edns.h:53
@ LDNS_EDE_INVALID_DATA
Definition edns.h:77
@ LDNS_EDE_SIGNATURE_NOT_YET_VALID
Definition edns.h:61
@ LDNS_EDE_UNSUPPORTED_DS_DIGEST
Definition edns.h:55
@ LDNS_EDE_TOO_EARLY
Definition edns.h:79
enum ldns_enum_edns_option ldns_edns_option_code
Definition edns.h:46
uint8_t * ldns_edns_get_data(const ldns_edns_option *edns)
returns the EDNS option data.
Definition edns.c:39
ldns_edns_option_code ldns_edns_get_code(const ldns_edns_option *edns)
returns the option code of the EDNS data.
Definition edns.c:32
void ldns_edns_option_list_deep_free(ldns_edns_option_list *options_list)
Definition edns.c:264
size_t ldns_edns_get_size(const ldns_edns_option *edns)
returns the size of the EDNS data.
Definition edns.c:25
ldns_edns_option * ldns_edns_option_list_get_option(const ldns_edns_option_list *options_list, size_t index)
returns the EDNS option as the specified index in the list of EDNS options.
Definition edns.c:287
size_t ldns_edns_option_list_get_count(const ldns_edns_option_list *options_list)
returns the number of options in the EDNS options list.
Definition edns.c:277
@ LDNS_EDNS_NSID
Definition edns.h:30
@ LDNS_EDNS_KEEPALIVE
Definition edns.h:38
@ LDNS_EDNS_DHU
Definition edns.h:33
@ LDNS_EDNS_PADDING
Definition edns.h:39
@ LDNS_EDNS_COOKIE
Definition edns.h:37
@ LDNS_EDNS_DAU
Definition edns.h:32
@ LDNS_EDNS_N3U
Definition edns.h:34
@ LDNS_EDNS_UL
Definition edns.h:29
@ LDNS_EDNS_CLIENT_SUBNET
Definition edns.h:35
@ LDNS_EDNS_KEY_TAG
Definition edns.h:41
@ LDNS_EDNS_CHAIN
Definition edns.h:40
@ LDNS_EDNS_CLIENT_TAG
Definition edns.h:43
@ LDNS_EDNS_EDE
Definition edns.h:42
@ LDNS_EDNS_LLQ
Definition edns.h:28
@ LDNS_EDNS_SERVER_TAG
Definition edns.h:44
@ LDNS_EDNS_EXPIRE
Definition edns.h:36
@ LDNS_STATUS_WIRE_RDATA_ERR
Definition error.h:125
@ LDNS_STATUS_NO_SVCPARAM_VALUE_EXPECTED
Definition error.h:142
@ LDNS_STATUS_NULL
Definition error.h:51
@ LDNS_STATUS_ERR
Definition error.h:37
@ LDNS_STATUS_MEM_ERR
Definition error.h:34
@ LDNS_STATUS_INVALID_SVCPARAM_VALUE
Definition error.h:144
@ LDNS_STATUS_OK
Definition error.h:26
@ LDNS_STATUS_DOMAINNAME_OVERFLOW
Definition error.h:29
@ LDNS_STATUS_RDATA_OVERFLOW
Definition error.h:129
@ LDNS_STATUS_NOT_IMPL
Definition error.h:50
enum ldns_enum_status ldns_status
Definition error.h:148
char * ldns_pkt2str_fmt(const ldns_output_format *fmt, const ldns_pkt *pkt)
Converts the data in the DNS packet to presentation format and returns that as a char *.
Definition host2str.c:3317
ldns_status ldns_rr2buffer_str(ldns_buffer *output, const ldns_rr *rr)
Converts the data in the resource record to presentation format (as char *) and appends it to the giv...
Definition host2str.c:2033
ldns_status ldns_rdf2buffer_str_hip(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_HIP rdata element to presentation format for the algorithm,...
Definition host2str.c:1265
ldns_status ldns_rdf2buffer_str_wks(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_WKS rdata element to string format and adds it to the output buffer.
Definition host2str.c:817
const ldns_output_format * ldns_output_format_nocomments
Standard output format record that disables commenting in the textual representation of Resource Reco...
Definition host2str.c:135
ldns_edns_option_list * pkt_edns_data2edns_option_list(const ldns_rdf *edns_data)
Definition packet.c:764
char * ldns_key2str(const ldns_key *k)
Converts a private key to the test presentation fmt and returns that as a char *.
Definition host2str.c:3342
char * ldns_pkt_cert_algorithm2str(ldns_cert_algorithm cert_algorithm)
Converts a cert algorithm to its mnemonic and returns that as an allocated null-terminated string.
Definition host2str.c:314
ldns_status ldns_key2buffer_str(ldns_buffer *output, const ldns_key *k)
Converts the data in the DNS packet to presentation format (as char *) and appends it to the given bu...
Definition host2str.c:2961
ldns_status ldns_rdf2buffer_str_int32(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_INT32 rdata element to string format and adds it to the output buffer.
Definition host2str.c:405
ldns_status ldns_edns_option_list2buffer_str(ldns_buffer *output, ldns_edns_option_list *edns_list)
Converts the list of EDNS options to presentation format (as char *) and appends it to the given buff...
Definition host2str.c:2609
ldns_status ldns_rdf2buffer_str_hex(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_HEX rdata element to string format and adds it to the output buffer.
Definition host2str.c:530
char * ldns_pkt_opcode2str(ldns_pkt_opcode opcode)
Converts a packet opcode to its mnemonic and returns that as an allocated null-terminated string.
Definition host2str.c:253
ldns_status ldns_rdf2buffer_str_str(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_STR rdata element to string format and adds it to the output buffer.
Definition host2str.c:471
ldns_status ldns_pkt_rcode2buffer_str(ldns_buffer *output, ldns_pkt_rcode rcode)
Converts an ldns packet rcode value to its mnemonic, and adds that to the output buffer.
Definition host2str.c:212
char * ldns_rr2str(const ldns_rr *rr)
Converts the data in the resource record to presentation format and returns that as a char *.
Definition host2str.c:3311
ldns_status ldns_rdf2buffer_str_loc(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_LOC rdata element to string format and adds it to the output buffer.
Definition host2str.c:705
ldns_status ldns_rdf2buffer_str_apl(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_APL rdata element to string format and adds it to the output buffer.
Definition host2str.c:973
ldns_status ldns_rdf2buffer_str_nsap(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_NSAP rdata element to string format and adds it to the output buffer.
Definition host2str.c:804
void ldns_rr_list_print_fmt(FILE *output, const ldns_output_format *fmt, const ldns_rr_list *lst)
print a rr_list to output
Definition host2str.c:3444
ldns_lookup_table ldns_rcodes[]
Response codes.
Definition host2str.c:109
ldns_status ldns_rdf2buffer_str_b64(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_B64 rdata element to string format and adds it to the output buffer.
Definition host2str.c:487
ldns_status ldns_rdf2buffer_str_type(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_TYPE rdata element to string format and adds it to the output buffer.
Definition host2str.c:558
char * ldns_buffer_export2str(ldns_buffer *buffer)
Exports and returns the data in the buffer as a null terminated char * string.
Definition host2str.c:3262
ldns_status ldns_rdf2buffer_str(ldns_buffer *buffer, const ldns_rdf *rdf)
Converts the data in the rdata field to presentation format (as char *) and appends it to the given b...
Definition host2str.c:1751
void ldns_pkt_print_fmt(FILE *output, const ldns_output_format *fmt, const ldns_pkt *pkt)
Prints the data in the DNS packet to the given file stream (in presentation format)
Definition host2str.c:3425
char * ldns_pkt2str(const ldns_pkt *pkt)
Converts the data in the DNS packet to presentation format and returns that as a char *.
Definition host2str.c:3336
char * ldns_rr_list2str_fmt(const ldns_output_format *fmt, const ldns_rr_list *list)
Converts a list of resource records to presentation format and returns that as a char *.
Definition host2str.c:3359
ldns_status ldns_pkt2buffer_str_fmt(ldns_buffer *output, const ldns_output_format *fmt, const ldns_pkt *pkt)
Converts the data in the DNS packet to presentation format (as char *) and appends it to the given bu...
Definition host2str.c:2689
char * ldns_buffer2str(ldns_buffer *buffer)
Returns a copy of the data in the buffer as a null terminated char * string.
Definition host2str.c:3235
char * ldns_rr_type2str(const ldns_rr_type type)
Converts an ldns_rr_type value to its string representation, and returns that string.
Definition host2str.c:650
ldns_status ldns_rr2buffer_str_fmt(ldns_buffer *output, const ldns_output_format *fmt, const ldns_rr *rr)
Converts the data in the resource record to presentation format (as char *) and appends it to the giv...
Definition host2str.c:1809
const ldns_output_format ldns_output_format_nocomments_record
Definition host2str.c:133
void ldns_zone_print_fmt(FILE *output, const ldns_output_format *fmt, const ldns_zone *z)
Print a zone structure * to output.
Definition host2str.c:3533
ldns_status ldns_pktheader2buffer_str(ldns_buffer *output, const ldns_pkt *pkt)
Converts the header of a packet to presentation format and appends it to the output buffer.
Definition host2str.c:2059
const ldns_output_format * ldns_output_format_onlykeyids
Standard output format record that annotated only DNSKEY RR's with comment text.
Definition host2str.c:140
ldns_status ldns_rdf2buffer_str_tag(ldns_buffer *output, const ldns_rdf *rdf)
Adds the LDNS_RDF_TYPE_TAG rdata to the output buffer, provided it contains only alphanumeric charact...
Definition host2str.c:1228
const ldns_output_format ldns_output_format_onlykeyids_record
Definition host2str.c:136
ldns_status ldns_rr_list2buffer_str(ldns_buffer *output, const ldns_rr_list *list)
Converts a rr_list to presentation format and appends it to the output buffer.
Definition host2str.c:2052
char * ldns_rr_class2str(const ldns_rr_class klass)
Converts an ldns_rr_class value to its string representation, and returns that string.
Definition host2str.c:686
ldns_status ldns_rr_class2buffer_str(ldns_buffer *output, const ldns_rr_class klass)
Converts an ldns_rr_class value to its string representation, and places it in the given buffer.
Definition host2str.c:671
void ldns_rdf_print(FILE *output, const ldns_rdf *rdf)
Prints the data in the rdata field to the given file stream (in presentation format)
Definition host2str.c:3394
char * ldns_pkt_rcode2str(ldns_pkt_rcode rcode)
Converts a packet rcode to its mnemonic and returns that as an allocated null-terminated string.
Definition host2str.c:273
ldns_lookup_table ldns_algorithms[]
Taken from RFC 2535, section 7.
Definition host2str.c:53
ldns_status ldns_algorithm2buffer_str(ldns_buffer *output, ldns_algorithm algorithm)
Converts an ldns algorithm type to its mnemonic, and adds that to the output buffer.
Definition host2str.c:224
ldns_status ldns_rdf2buffer_str_time(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_TIME rdata element to string format and adds it to the output buffer.
Definition host2str.c:413
void ldns_rr_print(FILE *output, const ldns_rr *rr)
Prints the data in the resource record to the given file stream (in presentation format)
Definition host2str.c:3419
ldns_status svcparam_key2buffer_str(ldns_buffer *output, uint16_t key)
Definition str2host.c:2201
ldns_status ldns_cert_algorithm2buffer_str(ldns_buffer *output, ldns_cert_algorithm cert_algorithm)
Converts an ldns certificate algorithm type to its mnemonic, and adds that to the output buffer.
Definition host2str.c:238
#define INET_ADDRSTRLEN
Definition host2str.c:40
void ldns_resolver_print_fmt(FILE *output, const ldns_output_format *fmt, const ldns_resolver *r)
Print a resolver (in sofar that is possible) state to output.
Definition host2str.c:3460
ldns_lookup_table ldns_opcodes[]
Operation codes.
Definition host2str.c:124
char * ldns_rdf2str(const ldns_rdf *rdf)
Converts the data in the rdata field to presentation format and returns that as a char *.
Definition host2str.c:3276
ldns_status ldns_rdf2buffer_str_tsigtime(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_TSIGTIME rdata element to string format and adds it to the output buffer.
Definition host2str.c:949
ldns_status ldns_rdf2buffer_str_eui48(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_EUI48 rdata element to 6 hexadecimal numbers separated by dashes and adds i...
Definition host2str.c:1201
ldns_status ldns_rdf2buffer_str_int8(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_INT8 rdata element to string format and adds it to the output buffer.
Definition host2str.c:389
ldns_status ldns_rdf2buffer_str_alg(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_ALG rdata element to string format and adds it to the output buffer.
Definition host2str.c:594
ldns_status ldns_rdf2buffer_str_svcparams(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_SVCPARAMS rdata element to presentation format.
Definition host2str.c:1551
ldns_status ldns_rdf2buffer_str_eui64(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_EUI64 rdata element to 8 hexadecimal numbers separated by dashes and adds i...
Definition host2str.c:1214
ldns_status ldns_rdf2buffer_str_amtrelay(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_AMTRELAY rdata element to presentation format for the precedence,...
Definition host2str.c:1309
ldns_status ldns_rdf2buffer_str_ilnp64(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_ILNP64 rdata element to 4 hexadecimal numbers separated by colons and adds ...
Definition host2str.c:1187
ldns_status ldns_rdf2buffer_str_nsec(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_NSEC rdata element to string format and adds it to the output buffer.
Definition host2str.c:906
void ldns_resolver_print(FILE *output, const ldns_resolver *r)
Print a resolver (in sofar that is possible) state to output.
Definition host2str.c:3527
ldns_status ldns_rdf2buffer_str_long_str(ldns_buffer *output, const ldns_rdf *rdf)
Adds the LDNS_RDF_TYPE_LONG_STR rdata to the output buffer, in-between double quotes and all non prin...
Definition host2str.c:1254
ldns_status ldns_output_format_clear_type(ldns_output_format *fmt, ldns_rr_type t)
Makes sure the LDNS_FMT_RFC3597 is set in the output format.
Definition host2str.c:180
ldns_status ldns_rdf2buffer_str_b32_ext(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_B32_EXT rdata element to string format and adds it to the output buffer.
Definition host2str.c:509
char * ldns_rr2str_fmt(const ldns_output_format *fmt, const ldns_rr *rr)
Converts the data in the resource record to presentation format and returns that as a char *.
Definition host2str.c:3293
ldns_status ldns_rdf2buffer_str_unknown(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_UNKNOWN rdata element to string format and adds it to the output buffer.
Definition host2str.c:797
void ldns_zone_print(FILE *output, const ldns_zone *z)
Print a zone structure * to output.
Definition host2str.c:3541
ldns_status ldns_rdf2buffer_str_cert_alg(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_CERT rdata element to string format and adds it to the output buffer.
Definition host2str.c:580
void ldns_rr_list_print(FILE *output, const ldns_rr_list *lst)
print a rr_list to output
Definition host2str.c:3454
ldns_status ldns_rdf2buffer_str_class(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_CLASS rdata element to string format and adds it to the output buffer.
Definition host2str.c:565
ldns_lookup_table ldns_rr_classes[]
rr types
Definition host2str.c:99
ldns_status ldns_rdf2buffer_str_int16(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_INT16 rdata element to string format and adds it to the output buffer.
Definition host2str.c:397
char * ldns_rr_list2str(const ldns_rr_list *list)
Converts a list of resource records to presentation format and returns that as a char *.
Definition host2str.c:3388
ldns_status ldns_rdf2buffer_str_ipseckey(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_IPSECKEY rdata element to string format and adds it to the output buffer.
Definition host2str.c:1077
ldns_status ldns_pkt_opcode2buffer_str(ldns_buffer *output, ldns_pkt_opcode opcode)
Converts an ldns packet opcode value to its mnemonic, and adds that to the output buffer.
Definition host2str.c:200
const ldns_output_format * ldns_output_format_default
The default output format record.
Definition host2str.c:142
ldns_status ldns_rdf2buffer_str_period(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_PERIOD rdata element to string format and adds it to the output buffer.
Definition host2str.c:938
void ldns_pkt_print(FILE *output, const ldns_pkt *pkt)
Prints the data in the DNS packet to the given file stream (in presentation format)
Definition host2str.c:3438
ldns_status ldns_rr_list2buffer_str_fmt(ldns_buffer *output, const ldns_output_format *fmt, const ldns_rr_list *list)
Converts a rr_list to presentation format and appends it to the output buffer.
Definition host2str.c:2039
ldns_status ldns_rdf2buffer_str_dname(ldns_buffer *output, const ldns_rdf *dname)
Print the ldns_rdf containing a dname to the buffer.
Definition host2str.c:337
ldns_lookup_table ldns_hashes[]
Definition host2str.c:75
ldns_lookup_table ldns_cert_algorithms[]
Taken from RFC 2538.
Definition host2str.c:84
ldns_status ldns_rdf2buffer_str_a(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_A rdata element to string format and adds it to the output buffer.
Definition host2str.c:428
ldns_status ldns_output_format_set_type(ldns_output_format *fmt, ldns_rr_type t)
Makes sure the LDNS_FMT_RFC3597 is set in the output format.
Definition host2str.c:160
ldns_status ldns_rdf2buffer_str_nsec3_salt(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_NSEC3_SALT rdata element to string format and adds it to the output buffer.
Definition host2str.c:913
const ldns_output_format ldns_output_format_bubblebabble_record
Definition host2str.c:144
const ldns_output_format * ldns_output_format_bubblebabble
Standard output format record that shows all DNSKEY related information in the comment text,...
Definition host2str.c:148
ldns_status ldns_rr_type2buffer_str(ldns_buffer *output, const ldns_rr_type type)
Converts an ldns_rr_type value to its string representation, and places it in the given buffer.
Definition host2str.c:617
ldns_status ldns_pkt2buffer_str(ldns_buffer *output, const ldns_pkt *pkt)
Converts the data in the DNS packet to presentation format (as char *) and appends it to the given bu...
Definition host2str.c:2825
char * ldns_pkt_algorithm2str(ldns_algorithm algorithm)
Converts a signing algorithms to its mnemonic and returns that as an allocated null-terminated string...
Definition host2str.c:293
#define INET6_ADDRSTRLEN
Definition host2str.c:43
ldns_status ldns_rdf2buffer_str_int16_data(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_INT16_DATA rdata element to string format and adds it to the output buffer.
Definition host2str.c:1050
ldns_status ldns_rdf2buffer_str_aaaa(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_AAAA rdata element to string format and adds it to the output buffer.
Definition host2str.c:439
ldns_status ldns_rdf2buffer_str_atma(ldns_buffer *output, const ldns_rdf *rdf)
Converts an LDNS_RDF_TYPE_ATMA rdata element to string format and adds it to the output buffer.
Definition host2str.c:811
void ldns_rr_print_fmt(FILE *output, const ldns_output_format *fmt, const ldns_rr *rr)
Prints the data in the resource record to the given file stream (in presentation format)
Definition host2str.c:3406
#define LDNS_COMMENT_KEY_SIZE
Show DNSKEY key size as comment.
Definition host2str.h:54
#define LDNS_APL_IP4
Definition host2str.h:37
#define LDNS_COMMENT_RRSIGS
Also comment KEY_ID with RRSIGS.
Definition host2str.h:64
#define LDNS_APL_MASK
Definition host2str.h:39
#define LDNS_FMT_PAD_SOA_SERIAL
Definition host2str.h:66
#define LDNS_COMMENT_BUBBLEBABBLE
Provide bubblebabble representation for DS RR's as comment.
Definition host2str.h:56
#define LDNS_FMT_ZEROIZE_RRSIGS
Definition host2str.h:65
#define LDNS_FMT_RFC3597
Definition host2str.h:67
#define LDNS_COMMENT_FLAGS
Show when a NSEC3 RR has the optout flag set as comment.
Definition host2str.h:58
#define LDNS_APL_IP6
Definition host2str.h:38
#define LDNS_COMMENT_NULLS
Represent a NULL pointer (instead of a pointer to a ldns_rr as "; (null)" as opposed to outputting no...
Definition host2str.h:48
#define LDNS_COMMENT_KEY_ID
Show key id with DNSKEY RR's as comment.
Definition host2str.h:50
#define LDNS_APL_NEGATION
Definition host2str.h:40
#define LDNS_FMT_SHORT
Prints only answer section of packets and only rdata of RRs.
Definition host2str.h:69
#define LDNS_COMMENT_KEY_TYPE
Show if a DNSKEY is a ZSK or KSK as comment.
Definition host2str.h:52
#define LDNS_COMMENT_KEY
Show key id, type and size as comment for DNSKEY RR's.
Definition host2str.h:74
#define LDNS_COMMENT_NSEC3_CHAIN
Show the unhashed owner and next owner names for NSEC3 RR's as comment.
Definition host2str.h:60
RSA * ldns_key_rsa_key(const ldns_key *k)
returns the (openssl) RSA struct contained in the key
Definition keys.c:1494
#define LDNS_KEY_SEP_KEY
Definition keys.h:38
@ LDNS_ED448
Definition keys.h:59
@ LDNS_RSAMD5
Definition keys.h:46
@ LDNS_ECDSAP384SHA384
Definition keys.h:57
@ LDNS_RSASHA1_NSEC3
Definition keys.h:52
@ LDNS_DSA_NSEC3
Definition keys.h:51
@ LDNS_DSA
Definition keys.h:48
@ LDNS_ECDSAP256SHA256
Definition keys.h:56
@ LDNS_ECC_GOST
Definition keys.h:55
@ LDNS_PRIVATEOID
Definition keys.h:62
@ LDNS_PRIVATEDNS
Definition keys.h:61
@ LDNS_DH
Definition keys.h:47
@ LDNS_INDIRECT
Definition keys.h:60
@ LDNS_ECC
Definition keys.h:49
@ LDNS_RSASHA1
Definition keys.h:50
@ LDNS_RSASHA512
Definition keys.h:54
@ LDNS_RSASHA256
Definition keys.h:53
@ LDNS_ED25519
Definition keys.h:58
size_t ldns_key_hmac_size(const ldns_key *k)
return the hmac key size
Definition keys.c:1531
DSA * ldns_key_dsa_key(const ldns_key *k)
returns the (openssl) DSA struct contained in the key
Definition keys.c:1504
ldns_signing_algorithm ldns_key_algorithm(const ldns_key *k)
return the signing alg of the key
Definition keys.c:1463
@ LDNS_SIGN_RSASHA1
Definition keys.h:84
@ LDNS_SIGN_ECDSAP256SHA256
Definition keys.h:95
@ LDNS_SIGN_DSA_NSEC3
Definition keys.h:92
@ LDNS_SIGN_ECC_GOST
Definition keys.h:94
@ LDNS_SIGN_ED448
Definition keys.h:101
@ LDNS_SIGN_ED25519
Definition keys.h:98
@ LDNS_SIGN_RSASHA1_NSEC3
Definition keys.h:88
@ LDNS_SIGN_HMACSHA224
Definition keys.h:106
@ LDNS_SIGN_ECDSAP384SHA384
Definition keys.h:96
@ LDNS_SIGN_HMACMD5
Definition keys.h:103
@ LDNS_SIGN_RSAMD5
Definition keys.h:83
@ LDNS_SIGN_RSASHA512
Definition keys.h:90
@ LDNS_SIGN_DSA
Definition keys.h:86
@ LDNS_SIGN_RSASHA256
Definition keys.h:89
@ LDNS_SIGN_HMACSHA384
Definition keys.h:107
@ LDNS_SIGN_HMACSHA1
Definition keys.h:104
@ LDNS_SIGN_HMACSHA512
Definition keys.h:108
@ LDNS_SIGN_HMACSHA256
Definition keys.h:105
unsigned char * ldns_key_hmac_key(const ldns_key *k)
return the hmac key data
Definition keys.c:1521
@ LDNS_HASH_GOST
Definition keys.h:73
@ LDNS_SHA256
Definition keys.h:72
@ LDNS_SHA1
Definition keys.h:71
@ LDNS_SHA384
Definition keys.h:74
#define LDNS_KEY_ZONE_KEY
Definition keys.h:37
enum ldns_enum_algorithm ldns_algorithm
Definition keys.h:64
Including this file will include all ldns files, and define some lookup tables.
#define LDNS_IP4ADDRLEN
Definition ldns.h:132
#define LDNS_IP6ADDRLEN
Definition ldns.h:133
#define LDNS_MAX_PACKETLEN
Definition packet.h:24
signed char ldns_pkt_edns(const ldns_pkt *packet)
returns true if this packet needs and EDNS rr to be sent.
Definition packet.c:750
uint8_t ldns_pkt_edns_version(const ldns_pkt *packet)
return the packet's edns version
Definition packet.c:219
signed char ldns_pkt_aa(const ldns_pkt *p)
Read the packet's aa bit.
Definition packet.c:52
size_t ldns_pkt_size(const ldns_pkt *p)
Return the packet's size in bytes.
Definition packet.c:183
ldns_rr_list * ldns_pkt_additional(const ldns_pkt *p)
Return the packet's additional section.
Definition packet.c:142
ldns_rr_list * ldns_pkt_authority(const ldns_pkt *p)
Return the packet's authority section.
Definition packet.c:136
ldns_rdf * ldns_pkt_answerfrom(const ldns_pkt *p)
Return the packet's answerfrom.
Definition packet.c:195
uint32_t ldns_pkt_querytime(const ldns_pkt *p)
Return the packet's querytime.
Definition packet.c:189
ldns_rr_list * ldns_pkt_question(const ldns_pkt *p)
Return the packet's question section.
Definition packet.c:124
uint16_t ldns_pkt_ancount(const ldns_pkt *p)
Return the packet's an count.
Definition packet.c:106
uint16_t ldns_pkt_nscount(const ldns_pkt *p)
Return the packet's ns count.
Definition packet.c:112
enum ldns_enum_pkt_rcode ldns_pkt_rcode
Definition packet.h:69
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *p)
Return the packet's answer section.
Definition packet.c:130
uint16_t ldns_pkt_id(const ldns_pkt *p)
Read the packet id.
Definition packet.c:40
@ LDNS_PACKET_IQUERY
Definition packet.h:48
@ LDNS_PACKET_NOTIFY
Definition packet.h:50
@ LDNS_PACKET_QUERY
Definition packet.h:47
@ LDNS_PACKET_STATUS
Definition packet.h:49
@ LDNS_PACKET_UPDATE
Definition packet.h:51
signed char ldns_pkt_tc(const ldns_pkt *p)
Read the packet's tc bit.
Definition packet.c:58
signed char ldns_pkt_ra(const ldns_pkt *p)
Read the packet's ra bit.
Definition packet.c:76
enum ldns_enum_pkt_opcode ldns_pkt_opcode
Definition packet.h:53
ldns_rdf * ldns_pkt_edns_data(const ldns_pkt *packet)
return the packet's EDNS data
Definition packet.c:260
uint8_t ldns_pkt_edns_extended_rcode(const ldns_pkt *packet)
return the packet's edns extended rcode
Definition packet.c:213
uint16_t ldns_pkt_qdcount(const ldns_pkt *p)
Return the packet's qd count.
Definition packet.c:100
signed char ldns_pkt_cd(const ldns_pkt *p)
Read the packet's cd bit.
Definition packet.c:70
ldns_rr * ldns_pkt_tsig(const ldns_pkt *p)
Return the packet's tsig pseudo rr's.
Definition packet.c:465
ldns_pkt_opcode ldns_pkt_get_opcode(const ldns_pkt *p)
Read the packet's code.
Definition packet.c:88
signed char ldns_pkt_edns_do(const ldns_pkt *packet)
return the packet's edns do bit
Definition packet.c:231
uint16_t ldns_pkt_arcount(const ldns_pkt *p)
Return the packet's ar count.
Definition packet.c:118
signed char ldns_pkt_qr(const ldns_pkt *p)
Read the packet's qr bit.
Definition packet.c:46
struct timeval ldns_pkt_timestamp(const ldns_pkt *p)
Return the packet's timestamp.
Definition packet.c:201
signed char ldns_pkt_rd(const ldns_pkt *p)
Read the packet's rd bit.
Definition packet.c:64
signed char ldns_pkt_ad(const ldns_pkt *p)
Read the packet's ad bit.
Definition packet.c:82
@ LDNS_RCODE_REFUSED
Definition packet.h:62
@ LDNS_RCODE_YXDOMAIN
Definition packet.h:63
@ LDNS_RCODE_FORMERR
Definition packet.h:58
@ LDNS_RCODE_YXRRSET
Definition packet.h:64
@ LDNS_RCODE_SERVFAIL
Definition packet.h:59
@ LDNS_RCODE_NOTIMPL
Definition packet.h:61
@ LDNS_RCODE_NXRRSET
Definition packet.h:65
@ LDNS_RCODE_NOTZONE
Definition packet.h:67
@ LDNS_RCODE_NXDOMAIN
Definition packet.h:60
@ LDNS_RCODE_NOTAUTH
Definition packet.h:66
@ LDNS_RCODE_NOERROR
Definition packet.h:57
ldns_pkt_rcode ldns_pkt_get_rcode(const ldns_pkt *p)
Return the packet's response code.
Definition packet.c:94
uint16_t ldns_pkt_edns_udp_size(const ldns_pkt *packet)
return the packet's edns udp size
Definition packet.c:207
ldns_rbnode_t * ldns_rbtree_search(ldns_rbtree_t *rbtree, const void *key)
Find key in tree.
Definition rbtree.c:294
enum ldns_enum_cert_algorithm ldns_cert_algorithm
Definition rdata.h:169
uint8_t * ldns_rdf_data(const ldns_rdf *rd)
returns the data of the rdf.
Definition rdata.c:38
ldns_rdf_type ldns_rdf_get_type(const ldns_rdf *rd)
returns the type of the rdf.
Definition rdata.c:31
ldns_rdf * ldns_rdf_new_frm_data(ldns_rdf_type type, size_t size, const void *data)
allocates a new rdf structure and fills it.
Definition rdata.c:193
void ldns_rdf_deep_free(ldns_rdf *rd)
frees a rdf structure and frees the data.
Definition rdata.c:230
uint32_t ldns_rdf2native_int32(const ldns_rdf *rd)
returns the native uint32_t representation from the rdf.
Definition rdata.c:98
uint16_t ldns_rdf2native_int16(const ldns_rdf *rd)
returns the native uint16_t representation from the rdf.
Definition rdata.c:84
enum ldns_enum_svcparam_key ldns_svcparam_key
Definition rdata.h:187
@ LDNS_RDF_TYPE_INT32
32 bits
Definition rdata.h:56
@ LDNS_RDF_TYPE_TAG
A non-zero sequence of US-ASCII letters and numbers in lower case.
Definition rdata.h:126
@ LDNS_RDF_TYPE_NSAP
NSAP.
Definition rdata.h:103
@ LDNS_RDF_TYPE_HIP
Represents the Public Key Algorithm, HIT and Public Key fields for the HIP RR types.
Definition rdata.h:92
@ LDNS_RDF_TYPE_B32_EXT
b32 string
Definition rdata.h:66
@ LDNS_RDF_TYPE_NSEC3_NEXT_OWNER
nsec3 base32 string (with length byte on wire
Definition rdata.h:111
@ LDNS_RDF_TYPE_CERT_ALG
certificate algorithm
Definition rdata.h:78
@ LDNS_RDF_TYPE_EUI48
6 * 8 bit hex numbers separated by dashes.
Definition rdata.h:119
@ LDNS_RDF_TYPE_SERVICE
protocol and port bitmaps
Definition rdata.h:97
@ LDNS_RDF_TYPE_EUI64
8 * 8 bit hex numbers separated by dashes.
Definition rdata.h:121
@ LDNS_RDF_TYPE_PERIOD
period
Definition rdata.h:86
@ LDNS_RDF_TYPE_B64
b64 string
Definition rdata.h:68
@ LDNS_RDF_TYPE_AAAA
AAAA record.
Definition rdata.h:60
@ LDNS_RDF_TYPE_UNKNOWN
unknown types
Definition rdata.h:82
@ LDNS_RDF_TYPE_WKS
well known services
Definition rdata.h:101
@ LDNS_RDF_TYPE_DNAME
domain name
Definition rdata.h:50
@ LDNS_RDF_TYPE_TIME
time (32 bits)
Definition rdata.h:84
@ LDNS_RDF_TYPE_SVCPARAMS
draft-ietf-dnsop-svcb-https
Definition rdata.h:146
@ LDNS_RDF_TYPE_NSEC
nsec type codes
Definition rdata.h:72
@ LDNS_RDF_TYPE_SELECTOR
Definition rdata.h:139
@ LDNS_RDF_TYPE_NSEC3_SALT
nsec3 hash salt
Definition rdata.h:109
@ LDNS_RDF_TYPE_APL
apl data
Definition rdata.h:64
@ LDNS_RDF_TYPE_A
A record.
Definition rdata.h:58
@ LDNS_RDF_TYPE_LONG_STR
A <character-string> encoding of the value field as specified [RFC1035], Section 5....
Definition rdata.h:132
@ LDNS_RDF_TYPE_LOC
location data
Definition rdata.h:99
@ LDNS_RDF_TYPE_INT16_DATA
variable length any type rdata where the length is specified by the first 2 bytes
Definition rdata.h:95
@ LDNS_RDF_TYPE_ILNP64
4 shorts represented as 4 * 16 bit hex numbers separated by colons.
Definition rdata.h:116
@ LDNS_RDF_TYPE_ATMA
ATMA.
Definition rdata.h:105
@ LDNS_RDF_TYPE_HEX
hex string
Definition rdata.h:70
@ LDNS_RDF_TYPE_NONE
none
Definition rdata.h:48
@ LDNS_RDF_TYPE_CLASS
a class
Definition rdata.h:76
@ LDNS_RDF_TYPE_INT8
8 bits
Definition rdata.h:52
@ LDNS_RDF_TYPE_MATCHING_TYPE
Definition rdata.h:140
@ LDNS_RDF_TYPE_IPSECKEY
IPSECKEY.
Definition rdata.h:107
@ LDNS_RDF_TYPE_CERTIFICATE_USAGE
Since RFC7218 TLSA records can be given with mnemonics, hence these rdata field types.
Definition rdata.h:138
@ LDNS_RDF_TYPE_STR
txt string
Definition rdata.h:62
@ LDNS_RDF_TYPE_INT16
16 bits
Definition rdata.h:54
@ LDNS_RDF_TYPE_ALG
a key algorithm
Definition rdata.h:80
@ LDNS_RDF_TYPE_AMTRELAY
draft-ietf-mboned-driad-amt-discovery
Definition rdata.h:143
@ LDNS_RDF_TYPE_TSIGTIME
tsig time 48 bits
Definition rdata.h:88
@ LDNS_RDF_TYPE_TYPE
a RR type
Definition rdata.h:74
size_t ldns_rdf_size(const ldns_rdf *rd)
returns the size of the rdf.
Definition rdata.c:24
ldns_rdf * ldns_rdf_new(ldns_rdf_type type, size_t size, void *data)
allocates a new rdf structure and fills it.
Definition rdata.c:179
@ LDNS_SVCPARAM_KEY_PORT
Definition rdata.h:179
@ LDNS_SVCPARAM_KEY_ALPN
Definition rdata.h:177
@ LDNS_SVCPARAM_KEY_ECH
Definition rdata.h:181
@ LDNS_SVCPARAM_KEY_MANDATORY
Definition rdata.h:176
@ LDNS_SVCPARAM_KEY_IPV4HINT
Definition rdata.h:180
@ LDNS_SVCPARAM_KEY_IPV6HINT
Definition rdata.h:182
@ LDNS_SVCPARAM_KEY_NO_DEFAULT_ALPN
Definition rdata.h:178
@ LDNS_CERT_SPKI
Definition rdata.h:159
@ LDNS_CERT_URI
Definition rdata.h:166
@ LDNS_CERT_ISPKI
Definition rdata.h:162
@ LDNS_CERT_IPGP
Definition rdata.h:163
@ LDNS_CERT_ACPKIX
Definition rdata.h:164
@ LDNS_CERT_IACPKIX
Definition rdata.h:165
@ LDNS_CERT_IPKIX
Definition rdata.h:161
@ LDNS_CERT_OID
Definition rdata.h:167
@ LDNS_CERT_PGP
Definition rdata.h:160
@ LDNS_CERT_PKIX
Definition rdata.h:158
size_t * ldns_resolver_rtt(const ldns_resolver *r)
Return the used round trip times for the nameservers.
Definition resolver.c:177
ldns_rr_list * ldns_resolver_dnssec_anchors(const ldns_resolver *r)
Get the resolver's DNSSEC anchors.
Definition resolver.c:132
#define LDNS_RESOLV_RTT_MIN
Definition resolver.h:54
signed char ldns_resolver_dnssec_cd(const ldns_resolver *r)
Does the resolver set the CD bit.
Definition resolver.c:126
signed char ldns_resolver_fail(const ldns_resolver *r)
Does the resolver only try the first nameserver.
Definition resolver.c:84
ldns_rdf ** ldns_resolver_searchlist(const ldns_resolver *r)
What is the searchlist as used by the resolver.
Definition resolver.c:102
#define LDNS_RESOLV_RTT_INF
Definition resolver.h:53
signed char ldns_resolver_recursive(const ldns_resolver *r)
Is the resolver set to recurse.
Definition resolver.c:66
size_t ldns_resolver_searchlist_count(const ldns_resolver *r)
Return the resolver's searchlist count.
Definition resolver.c:231
const char * ldns_resolver_tsig_keyname(const ldns_resolver *r)
Return the tsig keyname as used by the nameserver.
Definition resolver.c:207
signed char ldns_resolver_dnsrch(const ldns_resolver *r)
Does the resolver apply search list.
Definition resolver.c:78
signed char ldns_resolver_fallback(const ldns_resolver *r)
Get the truncation fallback status.
Definition resolver.c:54
size_t ldns_resolver_nameserver_count(const ldns_resolver *r)
How many nameserver are configured in the resolver.
Definition resolver.c:114
ldns_rdf ** ldns_resolver_nameservers(const ldns_resolver *r)
Return the configured nameserver ip address.
Definition resolver.c:108
uint8_t ldns_resolver_retrans(const ldns_resolver *r)
Get the retransmit interval.
Definition resolver.c:48
ldns_rdf * ldns_resolver_domain(const ldns_resolver *r)
What is the default dname to add to relative queries.
Definition resolver.c:96
signed char ldns_resolver_defnames(const ldns_resolver *r)
Does the resolver apply default domain name.
Definition resolver.c:90
uint16_t ldns_resolver_edns_udp_size(const ldns_resolver *r)
Get the resolver's udp size.
Definition resolver.c:36
signed char ldns_resolver_dnssec(const ldns_resolver *r)
Does the resolver do DNSSEC.
Definition resolver.c:120
struct timeval ldns_resolver_timeout(const ldns_resolver *r)
What is the timeout on socket connections.
Definition resolver.c:201
uint8_t ldns_resolver_ip6(const ldns_resolver *r)
Does the resolver use ip6 or ip4.
Definition resolver.c:60
signed char ldns_resolver_random(const ldns_resolver *r)
Does the resolver randomize the nameserver before usage.
Definition resolver.c:225
uint8_t ldns_resolver_retry(const ldns_resolver *r)
Get the number of retries.
Definition resolver.c:42
signed char ldns_resolver_usevc(const ldns_resolver *r)
Does the resolver use tcp or udp.
Definition resolver.c:171
signed char ldns_resolver_igntc(const ldns_resolver *r)
Does the resolver ignore the TC bit (truncated)
Definition resolver.c:165
const char * ldns_resolver_tsig_algorithm(const ldns_resolver *r)
Return the tsig algorithm as used by the nameserver.
Definition resolver.c:213
uint16_t ldns_resolver_port(const ldns_resolver *r)
Get the port the resolver should use.
Definition resolver.c:24
signed char ldns_resolver_debug(const ldns_resolver *r)
Get the debug status of the resolver.
Definition resolver.c:72
uint32_t ldns_rr_ttl(const ldns_rr *rr)
returns the ttl of an rr structure.
Definition rr.c:935
enum ldns_enum_rr_type ldns_rr_type
Definition rr.h:251
@ LDNS_RR_TYPE_RRSIG
DNSSEC.
Definition rr.h:170
@ LDNS_RR_TYPE_IXFR
Definition rr.h:217
@ LDNS_RR_TYPE_DNSKEY
Definition rr.h:172
@ LDNS_RR_TYPE_SOA
marks the start of a zone of authority
Definition rr.h:90
@ LDNS_RR_TYPE_DS
RFC4034, RFC3658.
Definition rr.h:164
@ LDNS_RR_TYPE_NSEC3
Definition rr.h:176
@ LDNS_RR_TYPE_MAILA
A request for mail agent RRs (Obsolete - see MX)
Definition rr.h:222
@ LDNS_RR_TYPE_AXFR
Definition rr.h:218
@ LDNS_RR_TYPE_ANY
any type (wildcard)
Definition rr.h:224
@ LDNS_RR_TYPE_MAILB
A request for mailbox-related records (MB, MG or MR)
Definition rr.h:220
signed char ldns_rr_is_question(const ldns_rr *rr)
returns the question flag of an rr structure.
Definition rr.c:929
size_t ldns_rr_rd_count(const ldns_rr *rr)
returns the rd_count of an rr structure.
Definition rr.c:941
ldns_rdf * ldns_rr_rdf(const ldns_rr *rr, size_t nr)
returns the rdata field member counter.
Definition rr.c:913
size_t ldns_rr_list_rr_count(const ldns_rr_list *rr_list)
returns the number of rr's in an rr_list.
Definition rr.c:961
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
Definition rr.c:947
ldns_rr_class ldns_rr_get_class(const ldns_rr *rr)
returns the class of the rr.
Definition rr.c:953
enum ldns_enum_rr_class ldns_rr_class
Definition rr.h:61
ldns_rr * ldns_rr_list_rr(const ldns_rr_list *rr_list, size_t nr)
returns a specific rr of an rrlist.
Definition rr.c:994
ldns_status ldns_rdf_bitmap_known_rr_types_space(ldns_rdf **rdf)
Create a rr type bitmap rdf providing enough space to set all known (to ldns) rr types.
Definition rr.c:2629
ldns_rdf * ldns_rr_owner(const ldns_rr *rr)
returns the owner name of an rr structure.
Definition rr.c:923
#define LDNS_MAX_DOMAINLEN
Maximum length of a complete dname.
Definition rr.h:33
@ LDNS_RR_CLASS_NONE
None class, dynamic update.
Definition rr.h:53
@ LDNS_RR_CLASS_IN
the Internet
Definition rr.h:47
@ LDNS_RR_CLASS_CH
Chaos class.
Definition rr.h:49
@ LDNS_RR_CLASS_HS
Hesiod (Dyer 87)
Definition rr.h:51
@ LDNS_RR_CLASS_ANY
Any class.
Definition rr.h:55
const ldns_rr_descriptor * ldns_rr_descript(uint16_t type)
returns the resource record descriptor for the given rr type.
Definition rr.c:2644
ldns_status ldns_rdf_bitmap_known_rr_types(ldns_rdf **rdf)
Create a rr type bitmap rdf with at least all known (to ldns) rr types set.
Definition rr.c:2635
size_t ldns_rr_dnskey_key_size(const ldns_rr *key)
get the length of the keydata in bits
ldns_status ldns_str2rdf_dname(ldns_rdf **rd, const char *str)
convert a dname string into wireformat
Definition str2host.c:311
The rbnode_t struct definition.
Definition rbtree.h:60
const void * data
pointer to data
Definition rbtree.h:70
implementation of buffers to ease operations
Definition buffer.h:51
size_t _position
The current position used for reading/writing.
Definition buffer.h:53
The struct that stores an ordered EDNS option.
Definition edns.h:97
General key structure, can contain all types of keys that are used in DNSSEC.
Definition keys.h:122
EVP_PKEY * key
Definition keys.h:133
struct ldns_struct_key::@0 _key
Storage pointers for the types of keys supported.
A general purpose lookup table.
Definition util.h:156
const char * name
Definition util.h:158
Output format struct with additional data for flags that use them.
Definition host2str.h:103
Output format specifier.
Definition host2str.h:89
int flags
Specification of how RR's should be formatted in text.
Definition host2str.h:91
DNS packet.
Definition packet.h:235
ldns_edns_option_list * _edns_list
Structed EDNS data.
Definition packet.h:262
Resource record data field.
Definition rdata.h:197
DNS stub resolver structure.
Definition resolver.h:60
Contains all information about resource record types.
Definition rr.h:359
const char * _name
Textual name of the RR type.
Definition rr.h:363
List or Set of Resource Records.
Definition rr.h:346
Resource Record.
Definition rr.h:318
DNS Zone.
Definition zone.h:43
struct tm * ldns_serial_arithmetics_gmtime_r(int32_t time, time_t now, struct tm *result)
The function interprets time as the number of seconds since epoch with respect to now using serial ar...
Definition util.c:304
int ldns_b32_ntop_extended_hex(const uint8_t *src_data, size_t src_data_length, char *target_text_buffer, size_t target_text_buffer_size)
Definition util.c:606
#define LDNS_FREE(ptr)
Definition util.h:60
ldns_lookup_table * ldns_lookup_by_id(ldns_lookup_table table[], int id)
Looks up the table entry by id, returns NULL if not found.
char * ldns_bubblebabble(uint8_t *data, size_t len)
Encode data as BubbleBabble.
Definition util.c:430
#define LDNS_XMALLOC(type, count)
Definition util.h:51
int ldns_get_bit(uint8_t bits[], size_t index)
Returns the value of the specified bit The bits are counted from left to right, so bit #0 is the left...
Definition util.c:52
ldns_status ldns_wire2dname(ldns_rdf **dname, const uint8_t *wire, size_t max, size_t *pos)
converts the data on the uint8_t bytearray (in wire format) to a DNS dname rdata field.
Definition wire2host.c:56
ldns_rr * ldns_zone_soa(const ldns_zone *z)
Return the soa record of a zone.
Definition zone.c:17
ldns_rr_list * ldns_zone_rrs(const ldns_zone *z)
Get a list of a zone's content.
Definition zone.c:35