ldns  1.7.0
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/* lookup tables for standard DNS stuff */
47
48/* Taken from RFC 2535, section 7. */
50 { LDNS_RSAMD5, "RSAMD5" },
51 { LDNS_DH, "DH" },
52#ifdef USE_DSA
53 { LDNS_DSA, "DSA" },
54#endif /* USE_DSA */
55 { LDNS_ECC, "ECC" },
56 { LDNS_RSASHA1, "RSASHA1" },
57#ifdef USE_DSA
58 { LDNS_DSA_NSEC3, "DSA-NSEC3-SHA1" },
59#endif /* USE_DSA */
60 { LDNS_RSASHA1_NSEC3, "RSASHA1-NSEC3-SHA1" },
61#ifdef USE_SHA2
62 { LDNS_RSASHA256, "RSASHA256"},
63 { LDNS_RSASHA512, "RSASHA512"},
64#endif
65#ifdef USE_GOST
66 { LDNS_ECC_GOST, "ECC-GOST"},
67#endif
68#ifdef USE_ECDSA
69 { LDNS_ECDSAP256SHA256, "ECDSAP256SHA256"},
70 { LDNS_ECDSAP384SHA384, "ECDSAP384SHA384"},
71#endif
72#ifdef USE_ED25519
73 { LDNS_ED25519, "ED25519"},
74#endif
75#ifdef USE_ED448
76 { LDNS_ED448, "ED448"},
77#endif
78 { LDNS_INDIRECT, "INDIRECT" },
79 { LDNS_PRIVATEDNS, "PRIVATEDNS" },
80 { LDNS_PRIVATEOID, "PRIVATEOID" },
81 { 0, NULL }
82};
83
84/* Taken from RFC 4398 */
86 { LDNS_CERT_PKIX, "PKIX" },
87 { LDNS_CERT_SPKI, "SPKI" },
88 { LDNS_CERT_PGP, "PGP" },
89 { LDNS_CERT_IPKIX, "IPKIX" },
90 { LDNS_CERT_ISPKI, "ISPKI" },
91 { LDNS_CERT_IPGP, "IPGP" },
92 { LDNS_CERT_ACPKIX, "ACPKIX" },
93 { LDNS_CERT_IACPKIX, "IACPKIX" },
94 { LDNS_CERT_URI, "URI" },
95 { LDNS_CERT_OID, "OID" },
96 { 0, NULL }
97};
98
99/* classes */
101 { LDNS_RR_CLASS_IN, "IN" },
102 { LDNS_RR_CLASS_CH, "CH" },
103 { LDNS_RR_CLASS_HS, "HS" },
104 { LDNS_RR_CLASS_NONE, "NONE" },
105 { LDNS_RR_CLASS_ANY, "ANY" },
106 { 0, NULL }
107};
108
109/* if these are used elsewhere */
111 { LDNS_RCODE_NOERROR, "NOERROR" },
112 { LDNS_RCODE_FORMERR, "FORMERR" },
113 { LDNS_RCODE_SERVFAIL, "SERVFAIL" },
114 { LDNS_RCODE_NXDOMAIN, "NXDOMAIN" },
115 { LDNS_RCODE_NOTIMPL, "NOTIMPL" },
116 { LDNS_RCODE_REFUSED, "REFUSED" },
117 { LDNS_RCODE_YXDOMAIN, "YXDOMAIN" },
118 { LDNS_RCODE_YXRRSET, "YXRRSET" },
119 { LDNS_RCODE_NXRRSET, "NXRRSET" },
120 { LDNS_RCODE_NOTAUTH, "NOTAUTH" },
121 { LDNS_RCODE_NOTZONE, "NOTZONE" },
122 { 0, NULL }
123};
124
126 { LDNS_PACKET_QUERY, "QUERY" },
127 { LDNS_PACKET_IQUERY, "IQUERY" },
128 { LDNS_PACKET_STATUS, "STATUS" },
129 { LDNS_PACKET_NOTIFY, "NOTIFY" },
130 { LDNS_PACKET_UPDATE, "UPDATE" },
131 { 0, NULL }
132};
133
144
150
151static bool
152ldns_output_format_covers_type(const ldns_output_format* fmt, ldns_rr_type t)
153{
154 return fmt && (fmt->flags & LDNS_FMT_RFC3597) &&
155 ((ldns_output_format_storage*)fmt)->bitmap &&
157 ((ldns_output_format_storage*)fmt)->bitmap, t);
158}
159
162{
164 ldns_status s;
165
166 assert(fmt != NULL);
167
168 if (!(fmt_st->flags & LDNS_FMT_RFC3597)) {
169 ldns_output_format_set(fmt, LDNS_FMT_RFC3597);
170 }
171 if (! fmt_st->bitmap) {
173 if (s != LDNS_STATUS_OK) {
174 return s;
175 }
176 }
177 return ldns_nsec_bitmap_set_type(fmt_st->bitmap, t);
178}
179
182{
184 ldns_status s;
185
186 assert(fmt != NULL);
187
188 if (!(fmt_st->flags & LDNS_FMT_RFC3597)) {
189 ldns_output_format_set(fmt, LDNS_FMT_RFC3597);
190 }
191 if (! fmt_st->bitmap) {
193 if (s != LDNS_STATUS_OK) {
194 return s;
195 }
196 }
197 return ldns_nsec_bitmap_clear_type(fmt_st->bitmap, t);
198}
199
202{
204 if (lt && lt->name) {
205 ldns_buffer_printf(output, "%s", lt->name);
206 } else {
207 ldns_buffer_printf(output, "OPCODE%u", opcode);
208 }
209 return ldns_buffer_status(output);
210}
211
214{
216 if (lt && lt->name) {
217 ldns_buffer_printf(output, "%s", lt->name);
218 } else {
219 ldns_buffer_printf(output, "RCODE%u", rcode);
220 }
221 return ldns_buffer_status(output);
222}
223
226 ldns_algorithm algorithm)
227{
229 algorithm);
230 if (lt && lt->name) {
231 ldns_buffer_printf(output, "%s", lt->name);
232 } else {
233 ldns_buffer_printf(output, "ALG%u", algorithm);
234 }
235 return ldns_buffer_status(output);
236}
237
240 ldns_cert_algorithm cert_algorithm)
241{
243 cert_algorithm);
244 if (lt && lt->name) {
245 ldns_buffer_printf(output, "%s", lt->name);
246 } else {
247 ldns_buffer_printf(output, "CERT_ALG%u",
248 cert_algorithm);
249 }
250 return ldns_buffer_status(output);
251}
252
253char *
255{
256 char *str;
257 ldns_buffer *buf;
258
259 buf = ldns_buffer_new(12);
260 if (!buf) {
261 return NULL;
262 }
263
264 str = NULL;
265 if (ldns_pkt_opcode2buffer_str(buf, opcode) == LDNS_STATUS_OK) {
266 str = ldns_buffer_export2str(buf);
267 }
268
269 ldns_buffer_free(buf);
270 return str;
271}
272
273char *
275{
276 char *str;
277 ldns_buffer *buf;
278
279 buf = ldns_buffer_new(10);
280 if (!buf) {
281 return NULL;
282 }
283
284 str = NULL;
285 if (ldns_pkt_rcode2buffer_str(buf, rcode) == LDNS_STATUS_OK) {
286 str = ldns_buffer_export2str(buf);
287 }
288
289 ldns_buffer_free(buf);
290 return str;
291}
292
293char *
295{
296 char *str;
297 ldns_buffer *buf;
298
299 buf = ldns_buffer_new(10);
300 if (!buf) {
301 return NULL;
302 }
303
304 str = NULL;
305 if (ldns_algorithm2buffer_str(buf, algorithm)
306 == LDNS_STATUS_OK) {
307 str = ldns_buffer_export2str(buf);
308 }
309
310 ldns_buffer_free(buf);
311 return str;
312}
313
314char *
316{
317 char *str;
318 ldns_buffer *buf;
319
320 buf = ldns_buffer_new(10);
321 if (!buf) {
322 return NULL;
323 }
324
325 str = NULL;
326 if (ldns_cert_algorithm2buffer_str(buf, cert_algorithm)
327 == LDNS_STATUS_OK) {
328 str = ldns_buffer_export2str(buf);
329 }
330
331 ldns_buffer_free(buf);
332 return str;
333}
334
335
336/* do NOT pass compressed data here :p */
339{
340 /* can we do with 1 pos var? or without at all? */
341 uint8_t src_pos = 0;
342 uint8_t len;
343 uint8_t *data;
344 uint8_t i;
345 unsigned char c;
346
347 data = (uint8_t*)ldns_rdf_data(dname);
348 len = data[src_pos];
349
350 if (ldns_rdf_size(dname) > LDNS_MAX_DOMAINLEN) {
351 /* too large, return */
353 }
354
355 /* special case: root label */
356 if (1 == ldns_rdf_size(dname)) {
357 ldns_buffer_printf(output, ".");
358 } else {
359 while ((len > 0) && src_pos < ldns_rdf_size(dname)) {
360 src_pos++;
361 for(i = 0; i < len; i++) {
362 /* paranoia check for various 'strange'
363 characters in dnames
364 */
365 c = (unsigned char) data[src_pos];
366 if(c == '.' || c == ';' ||
367 c == '(' || c == ')' ||
368 c == '\\') {
369 ldns_buffer_printf(output, "\\%c",
370 data[src_pos]);
371 } else if (!(isascii(c) && isgraph(c))) {
372 ldns_buffer_printf(output, "\\%03u",
373 data[src_pos]);
374 } else {
375 ldns_buffer_printf(output, "%c", data[src_pos]);
376 }
377 src_pos++;
378 }
379
380 if (src_pos < ldns_rdf_size(dname)) {
381 ldns_buffer_printf(output, ".");
382 }
383 len = data[src_pos];
384 }
385 }
386 return ldns_buffer_status(output);
387}
388
391{
392 uint8_t data = ldns_rdf_data(rdf)[0];
393 ldns_buffer_printf(output, "%lu", (unsigned long) data);
394 return ldns_buffer_status(output);
395}
396
399{
400 uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
401 ldns_buffer_printf(output, "%lu", (unsigned long) data);
402 return ldns_buffer_status(output);
403}
404
407{
408 uint32_t data = ldns_read_uint32(ldns_rdf_data(rdf));
409 ldns_buffer_printf(output, "%lu", (unsigned long) data);
410 return ldns_buffer_status(output);
411}
412
415{
416 /* create a YYYYMMDDHHMMSS string if possible */
417 struct tm tm;
418 char date_buf[16];
419
420 memset(&tm, 0, sizeof(tm));
422 && strftime(date_buf, 15, "%Y%m%d%H%M%S", &tm)) {
423 ldns_buffer_printf(output, "%s", date_buf);
424 }
425 return ldns_buffer_status(output);
426}
427
430{
431 char str[INET_ADDRSTRLEN];
432
433 if (inet_ntop(AF_INET, ldns_rdf_data(rdf), str, INET_ADDRSTRLEN)) {
434 ldns_buffer_printf(output, "%s", str);
435 }
436 return ldns_buffer_status(output);
437}
438
441{
442 char str[INET6_ADDRSTRLEN];
443
444 if (inet_ntop(AF_INET6, ldns_rdf_data(rdf), str, INET6_ADDRSTRLEN)) {
445 ldns_buffer_printf(output, "%s", str);
446 }
447
448 return ldns_buffer_status(output);
449}
450
451static void
452ldns_characters2buffer_str(ldns_buffer* output,
453 size_t amount, const uint8_t* characters)
454{
455 uint8_t ch;
456 while (amount > 0) {
457 ch = *characters++;
458 if (isprint((int)ch) || ch == '\t') {
459 if (ch == '\"' || ch == '\\')
460 ldns_buffer_printf(output, "\\%c", ch);
461 else
462 ldns_buffer_printf(output, "%c", ch);
463 } else {
464 ldns_buffer_printf(output, "\\%03u",
465 (unsigned)(uint8_t) ch);
466 }
467 amount--;
468 }
469}
470
473{
474 if(ldns_rdf_size(rdf) < 1) {
476 }
477 if((int)ldns_rdf_size(rdf) < (int)ldns_rdf_data(rdf)[0] + 1) {
479 }
480 ldns_buffer_printf(output, "\"");
481 ldns_characters2buffer_str(output,
482 ldns_rdf_data(rdf)[0], ldns_rdf_data(rdf) + 1);
483 ldns_buffer_printf(output, "\"");
484 return ldns_buffer_status(output);
485}
486
489{
490 size_t size;
491 char *b64;
492
493 if (ldns_rdf_size(rdf) == 0) {
494 ldns_buffer_printf(output, "0");
495 return ldns_buffer_status(output);
496 } else
497 size = ldns_b64_ntop_calculate_size(ldns_rdf_size(rdf));
498
499 if (!(b64 = LDNS_XMALLOC(char, size)))
500 return LDNS_STATUS_MEM_ERR;
501
502 if (ldns_b64_ntop(ldns_rdf_data(rdf), ldns_rdf_size(rdf), b64, size)) {
503 ldns_buffer_printf(output, "%s", b64);
504 }
505 LDNS_FREE(b64);
506 return ldns_buffer_status(output);
507}
508
511{
512 size_t size;
513 char *b32;
514 if(ldns_rdf_size(rdf) == 0)
515 return LDNS_STATUS_OK;
516 /* remove -1 for the b32-hash-len octet */
517 size = ldns_b32_ntop_calculate_size(ldns_rdf_size(rdf) - 1);
518 /* add one for the end nul for the string */
519 b32 = LDNS_XMALLOC(char, size + 1);
520 if(!b32) return LDNS_STATUS_MEM_ERR;
521 size = (size_t) ldns_b32_ntop_extended_hex(ldns_rdf_data(rdf) + 1,
522 ldns_rdf_size(rdf) - 1, b32, size+1);
523 if (size > 0) {
524 ldns_buffer_printf(output, "%s", b32);
525 }
526 LDNS_FREE(b32);
527 return ldns_buffer_status(output);
528}
529
532{
533 size_t i;
534 for (i = 0; i < ldns_rdf_size(rdf); i++) {
535 ldns_buffer_printf(output, "%02x", ldns_rdf_data(rdf)[i]);
536 }
537
538 return ldns_buffer_status(output);
539}
540
541static ldns_status
542ldns_rdf2buffer_str_type_fmt(ldns_buffer *output,
543 const ldns_output_format* fmt, const ldns_rdf *rdf)
544{
545 uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
546
547 if (! ldns_output_format_covers_type(fmt, data) &&
548 ldns_rr_descript(data) &&
549 ldns_rr_descript(data)->_name) {
550
551 ldns_buffer_printf(output, "%s",ldns_rr_descript(data)->_name);
552 } else {
553 ldns_buffer_printf(output, "TYPE%u", data);
554 }
555 return ldns_buffer_status(output);
556}
557
560{
561 return ldns_rdf2buffer_str_type_fmt(output,
563}
564
567{
568 uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
570
571 lt = ldns_lookup_by_id(ldns_rr_classes, (int) data);
572 if (lt) {
573 ldns_buffer_printf(output, "\t%s", lt->name);
574 } else {
575 ldns_buffer_printf(output, "\tCLASS%d", data);
576 }
577 return ldns_buffer_status(output);
578}
579
582{
583 uint16_t data = ldns_read_uint16(ldns_rdf_data(rdf));
585 lt = ldns_lookup_by_id(ldns_cert_algorithms, (int) data);
586 if (lt) {
587 ldns_buffer_printf(output, "%s", lt->name);
588 } else {
589 ldns_buffer_printf(output, "%d", data);
590 }
591 return ldns_buffer_status(output);
592}
593
596{
597 return ldns_rdf2buffer_str_int8(output, rdf);
598}
599
600static void
601loc_cm_print(ldns_buffer *output, uint8_t mantissa, uint8_t exponent)
602{
603 uint8_t i;
604 /* is it 0.<two digits> ? */
605 if(exponent < 2) {
606 if(exponent == 1)
607 mantissa *= 10;
608 ldns_buffer_printf(output, "0.%02ld", (long)mantissa);
609 return;
610 }
611 /* always <digit><string of zeros> */
612 ldns_buffer_printf(output, "%d", (int)mantissa);
613 for(i=0; i<exponent-2; i++)
614 ldns_buffer_printf(output, "0");
615}
616
619{
620 const ldns_rr_descriptor *descriptor;
621
622 descriptor = ldns_rr_descript(type);
623
624 switch (type) {
626 ldns_buffer_printf(output, "IXFR");
627 break;
629 ldns_buffer_printf(output, "AXFR");
630 break;
632 ldns_buffer_printf(output, "MAILA");
633 break;
635 ldns_buffer_printf(output, "MAILB");
636 break;
637 case LDNS_RR_TYPE_ANY:
638 ldns_buffer_printf(output, "ANY");
639 break;
640 default:
641 if (descriptor && descriptor->_name) {
642 ldns_buffer_printf(output, "%s", descriptor->_name);
643 } else {
644 ldns_buffer_printf(output, "TYPE%u", type);
645 }
646 }
647 return ldns_buffer_status(output);
648}
649
650char *
652{
653 char *str;
654 ldns_buffer *buf;
655
656 buf = ldns_buffer_new(10);
657 if (!buf) {
658 return NULL;
659 }
660
661 str = NULL;
662 if (ldns_rr_type2buffer_str(buf, type) == LDNS_STATUS_OK) {
663 str = ldns_buffer_export2str(buf);
664 }
665
666 ldns_buffer_free(buf);
667 return str;
668}
669
670
673 const ldns_rr_class klass)
674{
676
678 if (lt) {
679 ldns_buffer_printf(output, "%s", lt->name);
680 } else {
681 ldns_buffer_printf(output, "CLASS%d", klass);
682 }
683 return ldns_buffer_status(output);
684}
685
686char *
688{
689 ldns_buffer *buf;
690 char *str;
691
692 buf = ldns_buffer_new(10);
693 if (!buf) {
694 return NULL;
695 }
696
697 str = NULL;
698 if (ldns_rr_class2buffer_str(buf, klass) == LDNS_STATUS_OK) {
699 str = ldns_buffer_export2str(buf);
700 }
701 ldns_buffer_free(buf);
702 return str;
703}
704
707{
708 /* we could do checking (ie degrees < 90 etc)? */
709 uint8_t version;
710 uint8_t size;
711 uint8_t horizontal_precision;
712 uint8_t vertical_precision;
713 uint32_t longitude;
714 uint32_t latitude;
715 uint32_t altitude;
716 char latitude_hemisphere;
717 char longitude_hemisphere;
718 uint32_t h;
719 uint32_t m;
720 double s;
721
722 uint32_t equator = (uint32_t) ldns_power(2, 31);
723
724 if(ldns_rdf_size(rdf) < 1) {
726 }
727 version = ldns_rdf_data(rdf)[0];
728 if (version == 0) {
729 if(ldns_rdf_size(rdf) < 16) {
731 }
732 size = ldns_rdf_data(rdf)[1];
733 horizontal_precision = ldns_rdf_data(rdf)[2];
734 vertical_precision = ldns_rdf_data(rdf)[3];
735
736 latitude = ldns_read_uint32(&ldns_rdf_data(rdf)[4]);
737 longitude = ldns_read_uint32(&ldns_rdf_data(rdf)[8]);
738 altitude = ldns_read_uint32(&ldns_rdf_data(rdf)[12]);
739
740 if (latitude > equator) {
741 latitude_hemisphere = 'N';
742 latitude = latitude - equator;
743 } else {
744 latitude_hemisphere = 'S';
745 latitude = equator - latitude;
746 }
747 h = latitude / (1000 * 60 * 60);
748 latitude = latitude % (1000 * 60 * 60);
749 m = latitude / (1000 * 60);
750 latitude = latitude % (1000 * 60);
751 s = (double) latitude / 1000.0;
752 ldns_buffer_printf(output, "%02u %02u %0.3f %c ",
753 h, m, s, latitude_hemisphere);
754
755 if (longitude > equator) {
756 longitude_hemisphere = 'E';
757 longitude = longitude - equator;
758 } else {
759 longitude_hemisphere = 'W';
760 longitude = equator - longitude;
761 }
762 h = longitude / (1000 * 60 * 60);
763 longitude = longitude % (1000 * 60 * 60);
764 m = longitude / (1000 * 60);
765 longitude = longitude % (1000 * 60);
766 s = (double) longitude / (1000.0);
767 ldns_buffer_printf(output, "%02u %02u %0.3f %c ",
768 h, m, s, longitude_hemisphere);
769
770 s = ((double) altitude) / 100;
771 s -= 100000;
772
773 if(altitude%100 != 0)
774 ldns_buffer_printf(output, "%.2f", s);
775 else
776 ldns_buffer_printf(output, "%.0f", s);
777
778 ldns_buffer_printf(output, "m ");
779
780 loc_cm_print(output, (size & 0xf0) >> 4, size & 0x0f);
781 ldns_buffer_printf(output, "m ");
782
783 loc_cm_print(output, (horizontal_precision & 0xf0) >> 4,
784 horizontal_precision & 0x0f);
785 ldns_buffer_printf(output, "m ");
786
787 loc_cm_print(output, (vertical_precision & 0xf0) >> 4,
788 vertical_precision & 0x0f);
789 ldns_buffer_printf(output, "m");
790
791 return ldns_buffer_status(output);
792 } else {
793 return ldns_rdf2buffer_str_hex(output, rdf);
794 }
795}
796
799{
800 ldns_buffer_printf(output, "\\# %u ", ldns_rdf_size(rdf));
801 return ldns_rdf2buffer_str_hex(output, rdf);
802}
803
806{
807 ldns_buffer_printf(output, "0x");
808 return ldns_rdf2buffer_str_hex(output, rdf);
809}
810
813{
814 return ldns_rdf2buffer_str_hex(output, rdf);
815}
816
819{
820 /* protocol, followed by bitmap of services */
821 struct protoent *protocol;
822 char *proto_name = NULL;
823 uint8_t protocol_nr;
824 struct servent *service;
825 uint16_t current_service;
826
827 if(ldns_rdf_size(rdf) < 1) {
829 }
830 protocol_nr = ldns_rdf_data(rdf)[0];
831 protocol = getprotobynumber((int) protocol_nr);
832 if (protocol && (protocol->p_name != NULL)) {
833 proto_name = protocol->p_name;
834 ldns_buffer_printf(output, "%s ", protocol->p_name);
835 } else {
836 ldns_buffer_printf(output, "%u ", protocol_nr);
837 }
838
839#ifdef HAVE_ENDPROTOENT
840 endprotoent();
841#endif
842
843 for (current_service = 0;
844 current_service < (ldns_rdf_size(rdf)-1)*8; current_service++) {
845 if (ldns_get_bit(&(ldns_rdf_data(rdf)[1]), current_service)) {
846 service = getservbyport((int) htons(current_service),
847 proto_name);
848 if (service && service->s_name) {
849 ldns_buffer_printf(output, "%s ", service->s_name);
850 } else {
851 ldns_buffer_printf(output, "%u ", current_service);
852 }
853#ifdef HAVE_ENDSERVENT
854 endservent();
855#endif
856 }
857 /* exit from loop before integer overflow */
858 if(current_service == 65535) { break; }
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_u8(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_u8(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_u8(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_u8(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_u8(output, '\\');
1444 ldns_buffer_write_u8(output, ch);
1445 } else
1446 ldns_buffer_printf(output, "\\%03u"
1447 , (unsigned)ch);
1448 }
1449 }
1450 if (quote)
1451 ldns_buffer_write_u8(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_string(output, str);
1473
1474 for (data += 4, sz -= 4; sz ; data += 4, sz -= 4 ) {
1475 ldns_buffer_write_u8(output, ',');
1476 if (!inet_ntop(AF_INET, data, str, INET_ADDRSTRLEN))
1478
1479 ldns_buffer_write_string(output, str);
1480 }
1481 return ldns_buffer_status(output);
1482}
1483
1484static ldns_status
1485svcparam_echconfig2buffer_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_string(output, str);
1512
1513 for (data += 16, sz -= 16; sz ; data += 16, sz -= 16) {
1514 ldns_buffer_write_u8(output, ',');
1515 if (!inet_ntop(AF_INET6, data, str, INET6_ADDRSTRLEN))
1517
1518 ldns_buffer_write_string(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_u8(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_u8(output, '\\');
1541 ldns_buffer_write_u8(output, ch);
1542 } else
1543 ldns_buffer_printf(output, "\\%03u", (unsigned)ch);
1544 }
1545 if (quote)
1546 ldns_buffer_write_u8(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_u8(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_u8(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_echconfig2buffer_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
2112 const ldns_output_format *fmt, const ldns_pkt *pkt)
2113{
2114 uint16_t i;
2115 ldns_status status = LDNS_STATUS_OK;
2116 char *tmp;
2117 struct timeval time;
2118 time_t time_tt;
2119 int short_fmt = fmt && (fmt->flags & LDNS_FMT_SHORT);
2120
2121 if (!pkt) {
2122 ldns_buffer_printf(output, "null");
2123 return LDNS_STATUS_OK;
2124 }
2125
2126 if (!ldns_buffer_status_ok(output)) {
2127 return ldns_buffer_status(output);
2128 }
2129
2130 if (!short_fmt) {
2131 status = ldns_pktheader2buffer_str(output, pkt);
2132 if (status != LDNS_STATUS_OK) {
2133 return status;
2134 }
2135
2136 ldns_buffer_printf(output, "\n");
2137
2138 ldns_buffer_printf(output, ";; QUESTION SECTION:\n;; ");
2139
2140
2141 for (i = 0; i < ldns_pkt_qdcount(pkt); i++) {
2142 status = ldns_rr2buffer_str_fmt(output, fmt,
2144 ldns_pkt_question(pkt), i));
2145 if (status != LDNS_STATUS_OK) {
2146 return status;
2147 }
2148 }
2149 ldns_buffer_printf(output, "\n");
2150
2151 ldns_buffer_printf(output, ";; ANSWER SECTION:\n");
2152 }
2153 for (i = 0; i < ldns_pkt_ancount(pkt); i++) {
2154 status = ldns_rr2buffer_str_fmt(output, fmt,
2156 ldns_pkt_answer(pkt), i));
2157 if (status != LDNS_STATUS_OK) {
2158 return status;
2159 }
2160 }
2161 if (!short_fmt) {
2162 ldns_buffer_printf(output, "\n");
2163
2164 ldns_buffer_printf(output, ";; AUTHORITY SECTION:\n");
2165
2166 for (i = 0; i < ldns_pkt_nscount(pkt); i++) {
2167 status = ldns_rr2buffer_str_fmt(output, fmt,
2169 ldns_pkt_authority(pkt), i));
2170 if (status != LDNS_STATUS_OK) {
2171 return status;
2172 }
2173 }
2174 ldns_buffer_printf(output, "\n");
2175
2176 ldns_buffer_printf(output, ";; ADDITIONAL SECTION:\n");
2177 for (i = 0; i < ldns_pkt_arcount(pkt); i++) {
2178 status = ldns_rr2buffer_str_fmt(output, fmt,
2180 ldns_pkt_additional(pkt), i));
2181 if (status != LDNS_STATUS_OK) {
2182 return status;
2183 }
2184
2185 }
2186 ldns_buffer_printf(output, "\n");
2187 /* add some further fields */
2188 ldns_buffer_printf(output, ";; Query time: %d msec\n",
2189 ldns_pkt_querytime(pkt));
2190 if (ldns_pkt_edns(pkt)) {
2191 ldns_buffer_printf(output,
2192 ";; EDNS: version %u; flags:",
2194 if (ldns_pkt_edns_do(pkt)) {
2195 ldns_buffer_printf(output, " do");
2196 }
2197 /* the extended rcode is the value set, shifted four bits,
2198 * and or'd with the original rcode */
2200 ldns_buffer_printf(output, " ; ext-rcode: %d",
2202 }
2203 ldns_buffer_printf(output, " ; udp: %u\n",
2205
2206 if (ldns_pkt_edns_data(pkt)) {
2207 ldns_buffer_printf(output, ";; Data: ");
2208 (void)ldns_rdf2buffer_str(output,
2209 ldns_pkt_edns_data(pkt));
2210 ldns_buffer_printf(output, "\n");
2211 }
2212 }
2213 if (ldns_pkt_tsig(pkt)) {
2214 ldns_buffer_printf(output, ";; TSIG:\n;; ");
2216 output, fmt, ldns_pkt_tsig(pkt));
2217 ldns_buffer_printf(output, "\n");
2218 }
2219 if (ldns_pkt_answerfrom(pkt)) {
2221 ldns_buffer_printf(output, ";; SERVER: %s\n", tmp);
2222 LDNS_FREE(tmp);
2223 }
2224 time = ldns_pkt_timestamp(pkt);
2225 time_tt = (time_t)time.tv_sec;
2226 ldns_buffer_printf(output, ";; WHEN: %s",
2227 (char*)ctime(&time_tt));
2228
2229 ldns_buffer_printf(output, ";; MSG SIZE rcvd: %d\n",
2230 (int)ldns_pkt_size(pkt));
2231 }
2232 return status;
2233}
2234
2237{
2239}
2240
2241
2242#ifdef HAVE_SSL
2243static ldns_status
2244ldns_hmac_key2buffer_str(ldns_buffer *output, const ldns_key *k)
2245{
2246 ldns_status status;
2247 size_t i;
2248 ldns_rdf *b64_bignum;
2249
2250 ldns_buffer_printf(output, "Key: ");
2251
2252 i = ldns_key_hmac_size(k);
2254 status = ldns_rdf2buffer_str(output, b64_bignum);
2255 ldns_rdf_deep_free(b64_bignum);
2256 ldns_buffer_printf(output, "\n");
2257 return status;
2258}
2259#endif
2260
2261#if defined(HAVE_SSL) && defined(USE_GOST)
2262static ldns_status
2263ldns_gost_key2buffer_str(ldns_buffer *output, EVP_PKEY *p)
2264{
2265 unsigned char* pp = NULL;
2266 int ret;
2267 ldns_rdf *b64_bignum;
2268 ldns_status status;
2269
2270 ldns_buffer_printf(output, "GostAsn1: ");
2271
2272 ret = i2d_PrivateKey(p, &pp);
2273 b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, (size_t)ret, pp);
2274 status = ldns_rdf2buffer_str(output, b64_bignum);
2275
2276 ldns_rdf_deep_free(b64_bignum);
2277 OPENSSL_free(pp);
2278 ldns_buffer_printf(output, "\n");
2279 return status;
2280}
2281#endif
2282
2283#if defined(HAVE_SSL) && defined(USE_ED25519)
2284static ldns_status
2285ldns_ed25519_key2buffer_str(ldns_buffer *output, EVP_PKEY *p)
2286{
2287 unsigned char* pp = NULL;
2288 int ret;
2289 ldns_rdf *b64_bignum;
2290 ldns_status status;
2291
2292 ldns_buffer_printf(output, "PrivateKey: ");
2293
2294 ret = i2d_PrivateKey(p, &pp);
2295 /* 16 byte asn (302e020100300506032b657004220420) + 32byte key */
2296 if(ret != 16 + 32) {
2297 OPENSSL_free(pp);
2298 return LDNS_STATUS_ERR;
2299 }
2301 (size_t)ret-16, pp+16);
2302 status = ldns_rdf2buffer_str(output, b64_bignum);
2303
2304 ldns_rdf_deep_free(b64_bignum);
2305 OPENSSL_free(pp);
2306 ldns_buffer_printf(output, "\n");
2307 return status;
2308}
2309#endif
2310
2311#if defined(HAVE_SSL) && defined(USE_ED448)
2312static ldns_status
2313ldns_ed448_key2buffer_str(ldns_buffer *output, EVP_PKEY *p)
2314{
2315 unsigned char* pp = NULL;
2316 int ret;
2317 ldns_rdf *b64_bignum;
2318 ldns_status status;
2319
2320 ldns_buffer_printf(output, "PrivateKey: ");
2321
2322 ret = i2d_PrivateKey(p, &pp);
2323 /* some-ASN + 57byte key */
2324 if(ret != 16 + 57) {
2325 OPENSSL_free(pp);
2326 return LDNS_STATUS_ERR;
2327 }
2329 (size_t)ret-16, pp+16);
2330 status = ldns_rdf2buffer_str(output, b64_bignum);
2331
2332 ldns_rdf_deep_free(b64_bignum);
2333 OPENSSL_free(pp);
2334 ldns_buffer_printf(output, "\n");
2335 return status;
2336}
2337#endif
2338
2339#if defined(HAVE_SSL)
2341static int
2342ldns_print_bignum_b64_line(ldns_buffer* output, const char* label, const BIGNUM* num)
2343{
2344 unsigned char *bignumbuf = LDNS_XMALLOC(unsigned char, LDNS_MAX_KEYLEN);
2345 if(!bignumbuf) return 0;
2346
2347 ldns_buffer_printf(output, "%s: ", label);
2348 if(num) {
2349 ldns_rdf *b64_bignum = NULL;
2350 int i = BN_bn2bin(num, bignumbuf);
2351 if (i > LDNS_MAX_KEYLEN) {
2352 LDNS_FREE(bignumbuf);
2353 return 0;
2354 }
2355 b64_bignum = ldns_rdf_new_frm_data(LDNS_RDF_TYPE_B64, (size_t)i, bignumbuf);
2356 if (ldns_rdf2buffer_str(output, b64_bignum) != LDNS_STATUS_OK) {
2357 ldns_rdf_deep_free(b64_bignum);
2358 LDNS_FREE(bignumbuf);
2359 return 0;
2360 }
2361 ldns_rdf_deep_free(b64_bignum);
2362 ldns_buffer_printf(output, "\n");
2363 } else {
2364 ldns_buffer_printf(output, "(Not available)\n");
2365 }
2366 LDNS_FREE(bignumbuf);
2367 return 1;
2368}
2369#endif
2370
2373{
2374 ldns_status status = LDNS_STATUS_OK;
2375 unsigned char *bignum;
2376#ifdef HAVE_SSL
2377 RSA *rsa;
2378#ifdef USE_DSA
2379 DSA *dsa;
2380#endif /* USE_DSA */
2381#endif /* HAVE_SSL */
2382
2383 if (!k) {
2384 return LDNS_STATUS_ERR;
2385 }
2386
2387 bignum = LDNS_XMALLOC(unsigned char, LDNS_MAX_KEYLEN);
2388 if (!bignum) {
2389 return LDNS_STATUS_ERR;
2390 }
2391
2392 if (ldns_buffer_status_ok(output)) {
2393#ifdef HAVE_SSL
2394 switch(ldns_key_algorithm(k)) {
2395 case LDNS_SIGN_RSASHA1:
2399 case LDNS_SIGN_RSAMD5:
2400 /* copied by looking at dnssec-keygen output */
2401 /* header */
2402 rsa = ldns_key_rsa_key(k);
2403
2404 ldns_buffer_printf(output,"Private-key-format: v1.2\n");
2405 switch(ldns_key_algorithm(k)) {
2406 case LDNS_SIGN_RSAMD5:
2407 ldns_buffer_printf(output,
2408 "Algorithm: %u (RSA)\n",
2409 LDNS_RSAMD5);
2410 break;
2411 case LDNS_SIGN_RSASHA1:
2412 ldns_buffer_printf(output,
2413 "Algorithm: %u (RSASHA1)\n",
2414 LDNS_RSASHA1);
2415 break;
2417 ldns_buffer_printf(output,
2418 "Algorithm: %u (RSASHA1_NSEC3)\n",
2420 break;
2421#ifdef USE_SHA2
2423 ldns_buffer_printf(output,
2424 "Algorithm: %u (RSASHA256)\n",
2426 break;
2428 ldns_buffer_printf(output,
2429 "Algorithm: %u (RSASHA512)\n",
2431 break;
2432#endif
2433 default:
2434#ifdef STDERR_MSGS
2435 fprintf(stderr, "Warning: unknown signature ");
2436 fprintf(stderr,
2437 "algorithm type %u\n",
2439#endif
2440 ldns_buffer_printf(output,
2441 "Algorithm: %u (Unknown)\n",
2443 break;
2444 }
2445
2446 /* print to buf, convert to bin, convert to b64,
2447 * print to buf */
2448
2449#ifndef S_SPLINT_S
2450 if(1) {
2451 const BIGNUM *n=NULL, *e=NULL, *d=NULL,
2452 *p=NULL, *q=NULL, *dmp1=NULL,
2453 *dmq1=NULL, *iqmp=NULL;
2454#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
2455 n = rsa->n;
2456 e = rsa->e;
2457 d = rsa->d;
2458 p = rsa->p;
2459 q = rsa->q;
2460 dmp1 = rsa->dmp1;
2461 dmq1 = rsa->dmq1;
2462 iqmp = rsa->iqmp;
2463#else
2464 RSA_get0_key(rsa, &n, &e, &d);
2465 RSA_get0_factors(rsa, &p, &q);
2466 RSA_get0_crt_params(rsa, &dmp1,
2467 &dmq1, &iqmp);
2468#endif
2469 if(!ldns_print_bignum_b64_line(output, "Modulus", n))
2470 goto error;
2471 if(!ldns_print_bignum_b64_line(output, "PublicExponent", e))
2472 goto error;
2473 if(!ldns_print_bignum_b64_line(output, "PrivateExponent", d))
2474 goto error;
2475 if(!ldns_print_bignum_b64_line(output, "Prime1", p))
2476 goto error;
2477 if(!ldns_print_bignum_b64_line(output, "Prime2", q))
2478 goto error;
2479 if(!ldns_print_bignum_b64_line(output, "Exponent1", dmp1))
2480 goto error;
2481 if(!ldns_print_bignum_b64_line(output, "Exponent2", dmq1))
2482 goto error;
2483 if(!ldns_print_bignum_b64_line(output, "Coefficient", iqmp))
2484 goto error;
2485 }
2486#endif /* splint */
2487
2488 RSA_free(rsa);
2489 break;
2490#ifdef USE_DSA
2491 case LDNS_SIGN_DSA:
2493 dsa = ldns_key_dsa_key(k);
2494
2495 ldns_buffer_printf(output,"Private-key-format: v1.2\n");
2497 ldns_buffer_printf(output,"Algorithm: 3 (DSA)\n");
2498 } else if (ldns_key_algorithm(k) == LDNS_SIGN_DSA_NSEC3) {
2499 ldns_buffer_printf(output,"Algorithm: 6 (DSA_NSEC3)\n");
2500 }
2501
2502 /* print to buf, convert to bin, convert to b64,
2503 * print to buf */
2504 if(1) {
2505 const BIGNUM *p=NULL, *q=NULL, *g=NULL,
2506 *priv_key=NULL, *pub_key=NULL;
2507#if OPENSSL_VERSION_NUMBER < 0x10100000 || defined(HAVE_LIBRESSL)
2508#ifndef S_SPLINT_S
2509 p = dsa->p;
2510 q = dsa->q;
2511 g = dsa->g;
2512 priv_key = dsa->priv_key;
2513 pub_key = dsa->pub_key;
2514#endif /* splint */
2515#else
2516 DSA_get0_pqg(dsa, &p, &q, &g);
2517 DSA_get0_key(dsa, &pub_key, &priv_key);
2518#endif
2519 if(!ldns_print_bignum_b64_line(output, "Prime(p)", p))
2520 goto error;
2521 if(!ldns_print_bignum_b64_line(output, "Subprime(q)", q))
2522 goto error;
2523 if(!ldns_print_bignum_b64_line(output, "Base(g)", g))
2524 goto error;
2525 if(!ldns_print_bignum_b64_line(output, "Private_value(x)", priv_key))
2526 goto error;
2527 if(!ldns_print_bignum_b64_line(output, "Public_value(y)", pub_key))
2528 goto error;
2529 }
2530 break;
2531#endif /* USE_DSA */
2532 case LDNS_SIGN_ECC_GOST:
2533 /* no format defined, use blob */
2534#if defined(HAVE_SSL) && defined(USE_GOST)
2535 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2536 ldns_buffer_printf(output, "Algorithm: %d (ECC-GOST)\n", LDNS_SIGN_ECC_GOST);
2537 status = ldns_gost_key2buffer_str(output,
2538#ifndef S_SPLINT_S
2539 k->_key.key
2540#else
2541 NULL
2542#endif
2543 );
2544#else
2545 goto error;
2546#endif /* GOST */
2547 break;
2550#ifdef USE_ECDSA
2551 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2552 ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
2554#ifndef S_SPLINT_S
2555 ldns_buffer_printf(output, ")\n");
2556 if(k->_key.key) {
2557 EC_KEY* ec = EVP_PKEY_get1_EC_KEY(k->_key.key);
2558 const BIGNUM* b = EC_KEY_get0_private_key(ec);
2559 if(!ldns_print_bignum_b64_line(output, "PrivateKey", b))
2560 goto error;
2561 /* down reference count in EC_KEY
2562 * its still assigned to the PKEY */
2563 EC_KEY_free(ec);
2564 }
2565#endif /* splint */
2566#else
2567 goto error;
2568#endif /* ECDSA */
2569 break;
2570#ifdef USE_ED25519
2571 case LDNS_SIGN_ED25519:
2572 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2573 ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
2575 ldns_buffer_printf(output, ")\n");
2576 if (status) break;
2577 status = ldns_ed25519_key2buffer_str(output,
2578 k->_key.key);
2579 break;
2580#endif /* USE_ED25519 */
2581#ifdef USE_ED448
2582 case LDNS_SIGN_ED448:
2583 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2584 ldns_buffer_printf(output, "Algorithm: %d (", ldns_key_algorithm(k));
2586 ldns_buffer_printf(output, ")\n");
2587 if (status) break;
2588 status = ldns_ed448_key2buffer_str(output,
2589 k->_key.key);
2590 break;
2591#endif /* USE_ED448 */
2592 case LDNS_SIGN_HMACMD5:
2593 /* there's not much of a format defined for TSIG */
2594 /* It's just a binary blob, Same for all algorithms */
2595 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2596 ldns_buffer_printf(output, "Algorithm: 157 (HMAC_MD5)\n");
2597 status = ldns_hmac_key2buffer_str(output, k);
2598 break;
2599 case LDNS_SIGN_HMACSHA1:
2600 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2601 ldns_buffer_printf(output, "Algorithm: 158 (HMAC_SHA1)\n");
2602 status = ldns_hmac_key2buffer_str(output, k);
2603 break;
2605 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2606 ldns_buffer_printf(output, "Algorithm: 162 (HMAC_SHA224)\n");
2607 status = ldns_hmac_key2buffer_str(output, k);
2608 break;
2610 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2611 ldns_buffer_printf(output, "Algorithm: 159 (HMAC_SHA256)\n");
2612 status = ldns_hmac_key2buffer_str(output, k);
2613 break;
2615 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2616 ldns_buffer_printf(output, "Algorithm: 164 (HMAC_SHA384)\n");
2617 status = ldns_hmac_key2buffer_str(output, k);
2618 break;
2620 ldns_buffer_printf(output, "Private-key-format: v1.2\n");
2621 ldns_buffer_printf(output, "Algorithm: 165 (HMAC_SHA512)\n");
2622 status = ldns_hmac_key2buffer_str(output, k);
2623 break;
2624 }
2625#endif /* HAVE_SSL */
2626 } else {
2627 LDNS_FREE(bignum);
2628 return ldns_buffer_status(output);
2629 }
2630 LDNS_FREE(bignum);
2631 return status;
2632
2633#ifdef HAVE_SSL
2634 /* compiles warn the label isn't used */
2635error:
2636 LDNS_FREE(bignum);
2637 return LDNS_STATUS_ERR;
2638#endif /* HAVE_SSL */
2639
2640}
2641
2642/*
2643 * Zero terminate the buffer and copy data.
2644 */
2645char *
2647{
2648 char *str;
2649
2650 /* check if buffer ends with \0, if not, and
2651 if there is space, add it */
2652 if (*(ldns_buffer_at(buffer, ldns_buffer_position(buffer))) != 0) {
2653 if (!ldns_buffer_reserve(buffer, 1)) {
2654 return NULL;
2655 }
2656 ldns_buffer_write_u8(buffer, (uint8_t) '\0');
2657 if (!ldns_buffer_set_capacity(buffer, ldns_buffer_position(buffer))) {
2658 return NULL;
2659 }
2660 }
2661
2662 str = strdup((const char *)ldns_buffer_begin(buffer));
2663 if(!str) {
2664 return NULL;
2665 }
2666 return str;
2667}
2668
2669/*
2670 * Zero terminate the buffer and export data.
2671 */
2672char *
2674{
2675 /* Append '\0' as string terminator */
2676 if (! ldns_buffer_reserve(buffer, 1)) {
2677 return NULL;
2678 }
2679 ldns_buffer_write_u8(buffer, 0);
2680
2681 /* reallocate memory to the size of the string and export */
2682 ldns_buffer_set_capacity(buffer, ldns_buffer_position(buffer));
2683 return ldns_buffer_export(buffer);
2684}
2685
2686char *
2688{
2689 char *result = NULL;
2691
2692 if (!tmp_buffer) {
2693 return NULL;
2694 }
2695 if (ldns_rdf2buffer_str(tmp_buffer, rdf) == LDNS_STATUS_OK) {
2696 /* export and return string, destroy rest */
2697 result = ldns_buffer_export2str(tmp_buffer);
2698 }
2699 ldns_buffer_free(tmp_buffer);
2700 return result;
2701}
2702
2703char *
2705{
2706 char *result = NULL;
2708
2709 if (!tmp_buffer) {
2710 return NULL;
2711 }
2712 if (ldns_rr2buffer_str_fmt(tmp_buffer, fmt, rr)
2713 == LDNS_STATUS_OK) {
2714 /* export and return string, destroy rest */
2715 result = ldns_buffer_export2str(tmp_buffer);
2716 }
2717 ldns_buffer_free(tmp_buffer);
2718 return result;
2719}
2720
2721char *
2723{
2725}
2726
2727char *
2729{
2730 char *result = NULL;
2732
2733 if (!tmp_buffer) {
2734 return NULL;
2735 }
2736 if (ldns_pkt2buffer_str_fmt(tmp_buffer, fmt, pkt)
2737 == LDNS_STATUS_OK) {
2738 /* export and return string, destroy rest */
2739 result = ldns_buffer_export2str(tmp_buffer);
2740 }
2741
2742 ldns_buffer_free(tmp_buffer);
2743 return result;
2744}
2745
2746char *
2748{
2750}
2751
2752char *
2754{
2755 char *result = NULL;
2757
2758 if (!tmp_buffer) {
2759 return NULL;
2760 }
2761 if (ldns_key2buffer_str(tmp_buffer, k) == LDNS_STATUS_OK) {
2762 /* export and return string, destroy rest */
2763 result = ldns_buffer_export2str(tmp_buffer);
2764 }
2765 ldns_buffer_free(tmp_buffer);
2766 return result;
2767}
2768
2769char *
2771{
2772 char *result = NULL;
2774
2775 if (!tmp_buffer) {
2776 return NULL;
2777 }
2778 if (list) {
2780 tmp_buffer, fmt, list)
2781 == LDNS_STATUS_OK) {
2782 }
2783 } else {
2784 if (fmt == NULL) {
2786 }
2787 if (fmt->flags & LDNS_COMMENT_NULLS) {
2788 ldns_buffer_printf(tmp_buffer, "; (null)\n");
2789 }
2790 }
2791
2792 /* export and return string, destroy rest */
2793 result = ldns_buffer_export2str(tmp_buffer);
2794 ldns_buffer_free(tmp_buffer);
2795 return result;
2796}
2797
2798char *
2803
2804void
2805ldns_rdf_print(FILE *output, const ldns_rdf *rdf)
2806{
2807 char *str = ldns_rdf2str(rdf);
2808 if (str) {
2809 fprintf(output, "%s", str);
2810 } else {
2811 fprintf(output, ";Unable to convert rdf to string\n");
2812 }
2813 LDNS_FREE(str);
2814}
2815
2816void
2818 const ldns_output_format *fmt, const ldns_rr *rr)
2819{
2820 char *str = ldns_rr2str_fmt(fmt, rr);
2821 if (str) {
2822 fprintf(output, "%s", str);
2823 } else {
2824 fprintf(output, ";Unable to convert rr to string\n");
2825 }
2826 LDNS_FREE(str);
2827}
2828
2829void
2830ldns_rr_print(FILE *output, const ldns_rr *rr)
2831{
2833}
2834
2835void
2837 const ldns_output_format *fmt, const ldns_pkt *pkt)
2838{
2839 char *str = ldns_pkt2str_fmt(fmt, pkt);
2840 if (str) {
2841 fprintf(output, "%s", str);
2842 } else {
2843 fprintf(output, ";Unable to convert packet to string\n");
2844 }
2845 LDNS_FREE(str);
2846}
2847
2848void
2849ldns_pkt_print(FILE *output, const ldns_pkt *pkt)
2850{
2852}
2853
2854void
2856 const ldns_output_format *fmt, const ldns_rr_list *lst)
2857{
2858 size_t i;
2859 for (i = 0; i < ldns_rr_list_rr_count(lst); i++) {
2860 ldns_rr_print_fmt(output, fmt, ldns_rr_list_rr(lst, i));
2861 }
2862}
2863
2864void
2865ldns_rr_list_print(FILE *output, const ldns_rr_list *lst)
2866{
2868}
2869
2870void
2872 const ldns_output_format *fmt, const ldns_resolver *r)
2873{
2874 uint16_t i;
2875 ldns_rdf **n;
2876 ldns_rdf **s;
2877 size_t *rtt;
2878 if (!r) {
2879 return;
2880 }
2883 rtt = ldns_resolver_rtt(r);
2884
2885 fprintf(output, "port: %d\n", (int)ldns_resolver_port(r));
2886 fprintf(output, "edns0 size: %d\n", (int)ldns_resolver_edns_udp_size(r));
2887 fprintf(output, "use ip6: %d\n", (int)ldns_resolver_ip6(r));
2888
2889 fprintf(output, "recursive: %d\n", ldns_resolver_recursive(r));
2890 fprintf(output, "usevc: %d\n", ldns_resolver_usevc(r));
2891 fprintf(output, "igntc: %d\n", ldns_resolver_igntc(r));
2892 fprintf(output, "fail: %d\n", ldns_resolver_fail(r));
2893 fprintf(output, "retry: %d\n", (int)ldns_resolver_retry(r));
2894 fprintf(output, "retrans: %d\n", (int)ldns_resolver_retrans(r));
2895 fprintf(output, "fallback: %d\n", ldns_resolver_fallback(r));
2896 fprintf(output, "random: %d\n", ldns_resolver_random(r));
2897 fprintf(output, "timeout: %d\n", (int)ldns_resolver_timeout(r).tv_sec);
2898 fprintf(output, "dnssec: %d\n", ldns_resolver_dnssec(r));
2899 fprintf(output, "dnssec cd: %d\n", ldns_resolver_dnssec_cd(r));
2900 fprintf(output, "trust anchors (%d listed):\n",
2903 fprintf(output, "tsig: %s %s\n",
2906 fprintf(output, "debug: %d\n", ldns_resolver_debug(r));
2907
2908 fprintf(output, "default domain: ");
2910 fprintf(output, "\n");
2911 fprintf(output, "apply default domain: %d\n", ldns_resolver_defnames(r));
2912
2913 fprintf(output, "searchlist (%d listed):\n", (int)ldns_resolver_searchlist_count(r));
2914 for (i = 0; i < ldns_resolver_searchlist_count(r); i++) {
2915 fprintf(output, "\t");
2916 ldns_rdf_print(output, s[i]);
2917 fprintf(output, "\n");
2918 }
2919 fprintf(output, "apply search list: %d\n", ldns_resolver_dnsrch(r));
2920
2921 fprintf(output, "nameservers (%d listed):\n", (int)ldns_resolver_nameserver_count(r));
2922 for (i = 0; i < ldns_resolver_nameserver_count(r); i++) {
2923 fprintf(output, "\t");
2924 ldns_rdf_print(output, n[i]);
2925
2926 switch ((int)rtt[i]) {
2928 fprintf(output, " - reachable\n");
2929 break;
2931 fprintf(output, " - unreachable\n");
2932 break;
2933 }
2934 }
2935}
2936
2937void
2938ldns_resolver_print(FILE *output, const ldns_resolver *r)
2939{
2941}
2942
2943void
2945 const ldns_output_format *fmt, const ldns_zone *z)
2946{
2947 if(ldns_zone_soa(z))
2948 ldns_rr_print_fmt(output, fmt, ldns_zone_soa(z));
2949 ldns_rr_list_print_fmt(output, fmt, ldns_zone_rrs(z));
2950}
2951void
2952ldns_zone_print(FILE *output, const ldns_zone *z)
2953{
2955}
void ldns_buffer_free(ldns_buffer *buffer)
frees the buffer.
Definition buffer.c:137
bool ldns_buffer_set_capacity(ldns_buffer *buffer, size_t capacity)
changes the buffer's capacity.
Definition buffer.c:60
bool ldns_buffer_reserve(ldns_buffer *buffer, size_t amount)
ensures BUFFER can contain at least AMOUNT more bytes.
Definition buffer.c:80
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
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
uint16_t ldns_calc_keytag(const ldns_rr *key)
calculates a keytag of a key for use in DNSSEC.
Definition dnssec.c:277
bool 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
bool 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
#define LDNS_MAX_KEYLEN
Definition dnssec.h:41
ldns_rdf * ldns_dnssec_name_name(const ldns_dnssec_name *name)
Returns the domain name of the given dnssec_name structure.
@ 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:146
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:2728
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:818
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:136
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:2753
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:315
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:2372
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:406
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:531
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:254
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:472
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:213
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:2722
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:706
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:805
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:2855
ldns_lookup_table ldns_rcodes[]
Response codes.
Definition host2str.c:110
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:488
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:559
char * ldns_buffer_export2str(ldns_buffer *buffer)
Exports and returns the data in the buffer as a null terminated char * string.
Definition host2str.c:2673
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:2836
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:2747
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:2770
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:2111
char * ldns_buffer2str(ldns_buffer *buffer)
Returns a copy of the data in the buffer as a null terminated char * string.
Definition host2str.c:2646
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:651
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:134
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:2944
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:141
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:137
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:687
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:672
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:2805
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:274
ldns_lookup_table ldns_algorithms[]
Taken from RFC 2535, section 7.
Definition host2str.c:49
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:225
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:414
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:2830
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:239
#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:2871
ldns_lookup_table ldns_opcodes[]
Operation codes.
Definition host2str.c:125
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:2687
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:390
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:595
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:1613
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:2938
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:181
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:510
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:2704
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:798
void ldns_zone_print(FILE *output, const ldns_zone *z)
Print a zone structure * to output.
Definition host2str.c:2952
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:581
void ldns_rr_list_print(FILE *output, const ldns_rr_list *lst)
print a rr_list to output
Definition host2str.c:2865
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:566
ldns_lookup_table ldns_rr_classes[]
rr types
Definition host2str.c:100
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:398
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:2799
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:201
const ldns_output_format * ldns_output_format_default
The default output format record.
Definition host2str.c:143
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:2849
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:338
ldns_lookup_table ldns_cert_algorithms[]
Taken from RFC 2538.
Definition host2str.c:85
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:429
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:161
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:145
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:149
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:618
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:2236
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:294
#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:440
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:812
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:2817
#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
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
unsigned char * ldns_key_hmac_key(const ldns_key *k)
return the hmac key data
Definition keys.c:1521
#define LDNS_KEY_SEP_KEY
Definition keys.h:38
@ LDNS_ED448
Definition keys.h:66
@ LDNS_RSAMD5
Definition keys.h:46
@ LDNS_ECDSAP384SHA384
Definition keys.h:61
@ LDNS_RSASHA1_NSEC3
Definition keys.h:56
@ LDNS_DSA_NSEC3
Definition keys.h:54
@ LDNS_DSA
Definition keys.h:49
@ LDNS_ECDSAP256SHA256
Definition keys.h:60
@ LDNS_ECC_GOST
Definition keys.h:59
@ LDNS_PRIVATEOID
Definition keys.h:70
@ LDNS_PRIVATEDNS
Definition keys.h:69
@ LDNS_DH
Definition keys.h:47
@ LDNS_INDIRECT
Definition keys.h:68
@ LDNS_ECC
Definition keys.h:51
@ LDNS_RSASHA1
Definition keys.h:52
@ LDNS_RSASHA512
Definition keys.h:58
@ LDNS_RSASHA256
Definition keys.h:57
@ LDNS_ED25519
Definition keys.h:63
@ LDNS_SIGN_RSASHA1
Definition keys.h:92
@ LDNS_SIGN_ECDSAP256SHA256
Definition keys.h:103
@ LDNS_SIGN_DSA_NSEC3
Definition keys.h:100
@ LDNS_SIGN_ECC_GOST
Definition keys.h:102
@ LDNS_SIGN_ED448
Definition keys.h:109
@ LDNS_SIGN_ED25519
Definition keys.h:106
@ LDNS_SIGN_RSASHA1_NSEC3
Definition keys.h:96
@ LDNS_SIGN_HMACSHA224
Definition keys.h:114
@ LDNS_SIGN_ECDSAP384SHA384
Definition keys.h:104
@ LDNS_SIGN_HMACMD5
Definition keys.h:111
@ LDNS_SIGN_RSAMD5
Definition keys.h:91
@ LDNS_SIGN_RSASHA512
Definition keys.h:98
@ LDNS_SIGN_DSA
Definition keys.h:94
@ LDNS_SIGN_RSASHA256
Definition keys.h:97
@ LDNS_SIGN_HMACSHA384
Definition keys.h:115
@ LDNS_SIGN_HMACSHA1
Definition keys.h:112
@ LDNS_SIGN_HMACSHA512
Definition keys.h:116
@ LDNS_SIGN_HMACSHA256
Definition keys.h:113
#define LDNS_KEY_ZONE_KEY
Definition keys.h:37
enum ldns_enum_algorithm ldns_algorithm
Definition keys.h:72
Including this file will include all ldns files, and define some lookup tables.
#define LDNS_IP4ADDRLEN
Definition ldns.h:131
#define LDNS_IP6ADDRLEN
Definition ldns.h:132
uint8_t ldns_pkt_edns_version(const ldns_pkt *packet)
return the packet's edns version
Definition packet.c:219
ldns_pkt_opcode ldns_pkt_get_opcode(const ldns_pkt *packet)
Read the packet's code.
Definition packet.c:88
ldns_rr_list * ldns_pkt_question(const ldns_pkt *packet)
Return the packet's question section.
Definition packet.c:124
ldns_rdf * ldns_pkt_answerfrom(const ldns_pkt *packet)
Return the packet's answerfrom.
Definition packet.c:195
uint16_t ldns_pkt_id(const ldns_pkt *packet)
Read the packet id.
Definition packet.c:40
uint16_t ldns_pkt_arcount(const ldns_pkt *packet)
Return the packet's ar count.
Definition packet.c:118
struct timeval ldns_pkt_timestamp(const ldns_pkt *packet)
Return the packet's timestamp.
Definition packet.c:201
bool ldns_pkt_qr(const ldns_pkt *packet)
Read the packet's qr bit.
Definition packet.c:46
ldns_rr * ldns_pkt_tsig(const ldns_pkt *pkt)
Return the packet's tsig pseudo rr's.
Definition packet.c:465
bool ldns_pkt_edns(const ldns_pkt *pkt)
returns true if this packet needs and EDNS rr to be sent.
Definition packet.c:741
ldns_rr_list * ldns_pkt_answer(const ldns_pkt *packet)
Return the packet's answer section.
Definition packet.c:130
uint16_t ldns_pkt_ancount(const ldns_pkt *packet)
Return the packet's an count.
Definition packet.c:106
ldns_rr_list * ldns_pkt_additional(const ldns_pkt *packet)
Return the packet's additional section.
Definition packet.c:142
bool ldns_pkt_cd(const ldns_pkt *packet)
Read the packet's cd bit.
Definition packet.c:70
size_t ldns_pkt_size(const ldns_pkt *packet)
Return the packet's size in bytes.
Definition packet.c:183
bool ldns_pkt_ad(const ldns_pkt *packet)
Read the packet's ad bit.
Definition packet.c:82
uint32_t ldns_pkt_querytime(const ldns_pkt *packet)
Return the packet's querytime.
Definition packet.c:189
ldns_rdf * ldns_pkt_edns_data(const ldns_pkt *packet)
return the packet's edns data
Definition packet.c:260
bool ldns_pkt_rd(const ldns_pkt *packet)
Read the packet's rd bit.
Definition packet.c:64
uint8_t ldns_pkt_edns_extended_rcode(const ldns_pkt *packet)
return the packet's edns extended rcode
Definition packet.c:213
bool ldns_pkt_ra(const ldns_pkt *packet)
Read the packet's ra bit.
Definition packet.c:76
uint16_t ldns_pkt_nscount(const ldns_pkt *packet)
Return the packet's ns count.
Definition packet.c:112
uint16_t ldns_pkt_qdcount(const ldns_pkt *packet)
Return the packet's qd count.
Definition packet.c:100
bool ldns_pkt_edns_do(const ldns_pkt *packet)
return the packet's edns do bit
Definition packet.c:231
ldns_rr_list * ldns_pkt_authority(const ldns_pkt *packet)
Return the packet's authority section.
Definition packet.c:136
bool ldns_pkt_aa(const ldns_pkt *packet)
Read the packet's aa bit.
Definition packet.c:52
ldns_pkt_rcode ldns_pkt_get_rcode(const ldns_pkt *packet)
Return the packet's response code.
Definition packet.c:94
bool ldns_pkt_tc(const ldns_pkt *packet)
Read the packet's tc bit.
Definition packet.c:58
uint16_t ldns_pkt_edns_udp_size(const ldns_pkt *packet)
return the packet's edns udp size
Definition packet.c:207
#define LDNS_MAX_PACKETLEN
Definition packet.h:24
enum ldns_enum_pkt_rcode ldns_pkt_rcode
Definition packet.h:68
@ LDNS_PACKET_IQUERY
Definition packet.h:47
@ LDNS_PACKET_NOTIFY
Definition packet.h:49
@ LDNS_PACKET_QUERY
Definition packet.h:46
@ LDNS_PACKET_STATUS
Definition packet.h:48
@ LDNS_PACKET_UPDATE
Definition packet.h:50
enum ldns_enum_pkt_opcode ldns_pkt_opcode
Definition packet.h:52
@ LDNS_RCODE_REFUSED
Definition packet.h:61
@ LDNS_RCODE_YXDOMAIN
Definition packet.h:62
@ LDNS_RCODE_FORMERR
Definition packet.h:57
@ LDNS_RCODE_YXRRSET
Definition packet.h:63
@ LDNS_RCODE_SERVFAIL
Definition packet.h:58
@ LDNS_RCODE_NOTIMPL
Definition packet.h:60
@ LDNS_RCODE_NXRRSET
Definition packet.h:64
@ LDNS_RCODE_NOTZONE
Definition packet.h:66
@ LDNS_RCODE_NXDOMAIN
Definition packet.h:59
@ LDNS_RCODE_NOTAUTH
Definition packet.h:65
@ LDNS_RCODE_NOERROR
Definition packet.h:56
ldns_rbnode_t * ldns_rbtree_search(ldns_rbtree_t *rbtree, const void *key)
Find key in tree.
Definition rbtree.c:294
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
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
enum ldns_enum_cert_algorithm ldns_cert_algorithm
Definition rdata.h:169
enum ldns_enum_svcparam_key ldns_svcparam_key
Definition rdata.h:186
@ 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
@ LDNS_SVCPARAM_KEY_PORT
Definition rdata.h:179
@ LDNS_SVCPARAM_KEY_ALPN
Definition rdata.h:177
@ 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_SVCPARAM_KEY_ECHCONFIG
Definition rdata.h:181
@ 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
bool ldns_resolver_dnssec(const ldns_resolver *r)
Does the resolver do DNSSEC.
Definition resolver.c:120
ldns_rdf ** ldns_resolver_searchlist(const ldns_resolver *r)
What is the searchlist as used by the resolver.
Definition resolver.c:102
bool ldns_resolver_usevc(const ldns_resolver *r)
Does the resolver use tcp or udp.
Definition resolver.c:171
bool ldns_resolver_debug(const ldns_resolver *r)
Get the debug status of the resolver.
Definition resolver.c:72
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
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
bool ldns_resolver_dnssec_cd(const ldns_resolver *r)
Does the resolver set the CD bit.
Definition resolver.c:126
bool ldns_resolver_recursive(const ldns_resolver *r)
Is the resolver set to recurse.
Definition resolver.c:66
ldns_rdf * ldns_resolver_domain(const ldns_resolver *r)
What is the default dname to add to relative queries.
Definition resolver.c:96
bool ldns_resolver_dnsrch(const ldns_resolver *r)
Does the resolver apply search list.
Definition resolver.c:78
bool ldns_resolver_igntc(const ldns_resolver *r)
Does the resolver ignore the TC bit (truncated)
Definition resolver.c:165
bool 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
bool ldns_resolver_random(const ldns_resolver *r)
Does the resolver randomize the nameserver before usage.
Definition resolver.c:225
struct timeval ldns_resolver_timeout(const ldns_resolver *r)
What is the timeout on socket connections.
Definition resolver.c:201
bool ldns_resolver_fallback(const ldns_resolver *r)
Get the truncation fallback status.
Definition resolver.c:54
uint8_t ldns_resolver_ip6(const ldns_resolver *r)
Does the resolver use ip6 or ip4.
Definition resolver.c:60
uint8_t ldns_resolver_retry(const ldns_resolver *r)
Get the number of retries.
Definition resolver.c:42
bool ldns_resolver_fail(const ldns_resolver *r)
Does the resolver only try the first nameserver.
Definition resolver.c:84
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
#define LDNS_RESOLV_RTT_MIN
Definition resolver.h:54
#define LDNS_RESOLV_RTT_INF
Definition resolver.h:53
uint32_t ldns_rr_ttl(const ldns_rr *rr)
returns the ttl of an rr structure.
Definition rr.c:923
size_t ldns_rr_rd_count(const ldns_rr *rr)
returns the rd_count of an rr structure.
Definition rr.c:929
ldns_rdf * ldns_rr_rdf(const ldns_rr *rr, size_t nr)
returns the rdata field member counter.
Definition rr.c:901
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:949
ldns_rr_type ldns_rr_get_type(const ldns_rr *rr)
returns the type of the rr.
Definition rr.c:935
ldns_rr_class ldns_rr_get_class(const ldns_rr *rr)
returns the class of the rr.
Definition rr.c:941
bool ldns_rr_is_question(const ldns_rr *rr)
returns the question flag of an rr structure.
Definition rr.c:917
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:982
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:2608
ldns_rdf * ldns_rr_owner(const ldns_rr *rr)
returns the owner name of an rr structure.
Definition rr.c:911
const ldns_rr_descriptor * ldns_rr_descript(uint16_t type)
returns the resource record descriptor for the given rr type.
Definition rr.c:2623
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:2614
enum ldns_enum_rr_type ldns_rr_type
Definition rr.h:243
@ LDNS_RR_TYPE_RRSIG
DNSSEC.
Definition rr.h:170
@ LDNS_RR_TYPE_IXFR
Definition rr.h:215
@ 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:220
@ LDNS_RR_TYPE_AXFR
Definition rr.h:216
@ LDNS_RR_TYPE_ANY
any type (wildcard)
Definition rr.h:222
@ LDNS_RR_TYPE_MAILB
A request for mailbox-related records (MB, MG or MR)
Definition rr.h:218
enum ldns_enum_rr_class ldns_rr_class
Definition rr.h:61
#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
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 **d, 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
General key structure, can contain all types of keys that are used in DNSSEC.
Definition keys.h:130
EVP_PKEY * key
Definition keys.h:141
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:234
Resource record data field.
Definition rdata.h:196
DNS stub resolver structure.
Definition resolver.h:60
Contains all information about resource record types.
Definition rr.h:351
const char * _name
Textual name of the RR type.
Definition rr.h:355
List or Set of Resource Records.
Definition rr.h:338
Resource Record.
Definition rr.h:310
DNS Zone.
Definition zone.h:43
int ldns_b32_ntop_extended_hex(const uint8_t *src, size_t src_sz, char *dst, size_t dst_sz)
Definition util.c:604
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
char * ldns_bubblebabble(uint8_t *data, size_t len)
Encode data as BubbleBabble.
Definition util.c:428
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_lookup_table * ldns_lookup_by_id(ldns_lookup_table *table, int id)
Definition util.c:41
#define LDNS_FREE(ptr)
Definition util.h:60
#define LDNS_XMALLOC(type, count)
Definition util.h:51
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