debug.c 4.79 KB
Newer Older
1
#include <config.h>
Lubos Slovak's avatar
Lubos Slovak committed
2 3 4
#include <stdio.h>
#include <stdint.h>
#include <assert.h>
Lubos Slovak's avatar
Lubos Slovak committed
5
#include <stdlib.h>
Lubos Slovak's avatar
Lubos Slovak committed
6

7
#include "dnslib/utils.h"
8
#include "dnslib/debug.h"
Lubos Slovak's avatar
Lubos Slovak committed
9
#include "dnslib/dnslib.h"
10
#include "common/print.h"
Lubos Slovak's avatar
Lubos Slovak committed
11

12
void knot_rdata_dump(knot_rdata_t *rdata, uint32_t type, char loaded_zone)
Lubos Slovak's avatar
Lubos Slovak committed
13
{
14
#if defined(DNSLIB_ZONE_DEBUG) || defined(DNSLIB_RDATA_DEBUG)
Lubos Slovak's avatar
Lubos Slovak committed
15 16 17 18 19 20
	printf("      ------- RDATA -------\n");
	if (rdata == NULL) {
		printf("      There are no rdata in this RRset!\n");
		printf("      ------- RDATA -------\n");
		return;
	}
21
	knot_rrtype_descriptor_t *desc = knot_rrtype_descriptor_by_type(type);
Lubos Slovak's avatar
Lubos Slovak committed
22 23 24 25 26 27 28 29
	assert(desc != NULL);
	char *name;

	for (int i = 0; i < rdata->count; i++) {
		if (desc->wireformat[i] == DNSLIB_RDATA_WF_COMPRESSED_DNAME ||
		    desc->wireformat[i] == DNSLIB_RDATA_WF_UNCOMPRESSED_DNAME ||
		    desc->wireformat[i] == DNSLIB_RDATA_WF_LITERAL_DNAME ) {
			assert(rdata->items[i].dname != NULL);
30
			name = knot_dname_to_str(rdata->items[i].dname);
Lubos Slovak's avatar
Lubos Slovak committed
31 32
			printf("      DNAME: %d: %s\n",
			       i, name);
33
			free(name);
34 35 36
			if (loaded_zone) {
				if (rdata->items[i].dname->node) {
					name =
37
					knot_dname_to_str(rdata->items[i].dname->node->owner);
38 39 40 41 42
					printf("      Has node owner: %s\n", name);
					free(name);
				} else {
					printf("      No node set\n");
				}
43
			}
Jan Kadlec's avatar
Jan Kadlec committed
44
			printf("      labels: ");
45
			hex_print((char *)rdata->items[i].dname->labels,
46
			                 rdata->items[i].dname->label_count);
Lubos Slovak's avatar
Lubos Slovak committed
47 48 49 50 51

		} else {
			assert(rdata->items[i].raw_data != NULL);
			printf("      %d: raw_data: length: %d\n", i,
			       *(rdata->items[i].raw_data));
Jan Kadlec's avatar
Jan Kadlec committed
52
			printf("      ");
53
			hex_print(((char *)(
54 55
				rdata->items[i].raw_data + 1)),
				rdata->items[i].raw_data[0]);
Lubos Slovak's avatar
Lubos Slovak committed
56 57 58
		}
	}
	printf("      ------- RDATA -------\n");
59
#endif
60
}
Lubos Slovak's avatar
Lubos Slovak committed
61

62
void knot_rrset_dump(knot_rrset_t *rrset, char loaded_zone)
Lubos Slovak's avatar
Lubos Slovak committed
63
{
64
#if defined(DNSLIB_ZONE_DEBUG) || defined(DNSLIB_RRSET_DEBUG)
Lubos Slovak's avatar
Lubos Slovak committed
65 66
	printf("  ------- RRSET -------\n");
	printf("  %p\n", rrset);
67
        char *name = knot_dname_to_str(rrset->owner);
Jan Kadlec's avatar
Jan Kadlec committed
68 69
        printf("  owner: %s\n", name);
        free(name);
70
	printf("  type: %s\n", knot_rrtype_to_string(rrset->type));
Lubos Slovak's avatar
Lubos Slovak committed
71 72 73
	printf("  class: %d\n", rrset->rclass);
	printf("  ttl: %d\n", rrset->ttl);

Jan Kadlec's avatar
Jan Kadlec committed
74 75
        printf("  RRSIGs:\n");
        if (rrset->rrsigs != NULL) {
76
                knot_rrset_dump(rrset->rrsigs, loaded_zone);
Jan Kadlec's avatar
Jan Kadlec committed
77 78 79
        } else {
                printf("  none\n");
        }
Lubos Slovak's avatar
Lubos Slovak committed
80 81 82 83 84 85 86

	if (rrset->rdata == NULL) {
		printf("  NO RDATA!\n");
		printf("  ------- RRSET -------\n");
		return;
	}

87
	knot_rdata_t *tmp = rrset->rdata;
Lubos Slovak's avatar
Lubos Slovak committed
88 89

	while (tmp->next != rrset->rdata) {
90
		knot_rdata_dump(tmp, rrset->type, loaded_zone);
Lubos Slovak's avatar
Lubos Slovak committed
91 92 93
		tmp = tmp->next;
	}

94
	knot_rdata_dump(tmp, rrset->type, loaded_zone);
Lubos Slovak's avatar
Lubos Slovak committed
95 96

	printf("  ------- RRSET -------\n");
97
#endif
98
}
Lubos Slovak's avatar
Lubos Slovak committed
99

100
void knot_node_dump(knot_node_t *node, void *loaded_zone)
Lubos Slovak's avatar
Lubos Slovak committed
101
{
102
#if defined(DNSLIB_ZONE_DEBUG) || defined(DNSLIB_NODE_DEBUG)
103
	//char loaded_zone = *((char*) data);
Lubos Slovak's avatar
Lubos Slovak committed
104 105
	char *name;

Lubos Slovak's avatar
Lubos Slovak committed
106
	printf("------- NODE --------\n");
107
	name = knot_dname_to_str(node->owner);
Lubos Slovak's avatar
Lubos Slovak committed
108 109
	printf("owner: %s\n", name);
	free(name);
Jan Kadlec's avatar
Jan Kadlec committed
110
	printf("labels: ");
111
	hex_print((char *)node->owner->labels, node->owner->label_count);
Lubos Slovak's avatar
Lubos Slovak committed
112
	printf("node/id: %p\n", node->owner->node);
113
	if (loaded_zone && node->prev != NULL) {
114
		name = knot_dname_to_str(node->prev->owner);
Lubos Slovak's avatar
Lubos Slovak committed
115 116
		printf("previous node: %s\n", name);
		free(name);
117
	}
Lubos Slovak's avatar
Lubos Slovak committed
118

119
	if (knot_node_is_deleg_point(node)) {
120 121 122
		printf("delegation point\n");
	}

123
	if (knot_node_is_non_auth(node)) {
124 125 126
		printf("non-authoritative node\n");
	}

Lubos Slovak's avatar
Lubos Slovak committed
127
	if (node->parent != NULL) {
128
		name = knot_dname_to_str(node->parent->owner);
Lubos Slovak's avatar
Lubos Slovak committed
129 130 131 132 133 134
		printf("parent: %s\n", name);
		free(name);
	} else {
		printf("no parent\n");
	}

135
	if (node->prev != NULL) {
136
		name = knot_dname_to_str(node->prev->owner);
137 138 139 140 141 142
		printf("previous node: %s\n", name);
		free(name);
	} else {
		printf("previous node: none\n");
	}

143
	knot_rrset_t **rrsets = knot_node_get_rrsets(node);
Lubos Slovak's avatar
Lubos Slovak committed
144 145 146 147

	printf("Wildcard child: ");

	if (node->wildcard_child != NULL) {
148
		name = knot_dname_to_str(node->wildcard_child->owner);
Lubos Slovak's avatar
Lubos Slovak committed
149 150 151 152 153 154
		printf("%s\n", name);
		free(name);
	} else {
		printf("none\n");
	}

155 156 157
	printf("NSEC3 node: ");

	if (node->nsec3_node != NULL) {
158
		name = knot_dname_to_str(node->nsec3_node->owner);
159 160 161 162 163 164
		printf("%s\n", name);
		free(name);
	} else {
		printf("none\n");
	}

165 166
	printf("RRSet count: %d\n", node->rrset_count);

Jan Kadlec's avatar
Jan Kadlec committed
167
	for (int i = 0; i < node->rrset_count; i++) {
168
		knot_rrset_dump(rrsets[i], (int) loaded_zone);
Lubos Slovak's avatar
Lubos Slovak committed
169 170 171
	}
	//assert(node->owner->node == node);
	printf("------- NODE --------\n");
172
#endif
173
}
Lubos Slovak's avatar
Lubos Slovak committed
174

175
void knot_zone_contents_dump(knot_zone_contents_t *zone, char loaded_zone)
Lubos Slovak's avatar
Lubos Slovak committed
176
{
177
#if defined(DNSLIB_ZONE_DEBUG)
Lubos Slovak's avatar
Lubos Slovak committed
178 179
	printf("------- ZONE --------\n");

180
	knot_zone_contents_tree_apply_inorder(zone, knot_node_dump, (void *)&loaded_zone);
Lubos Slovak's avatar
Lubos Slovak committed
181 182 183 184 185

	printf("------- ZONE --------\n");
	
	printf("------- NSEC 3 tree -\n");

186
	knot_zone_contents_nsec3_apply_inorder(zone, knot_node_dump, (void *)&loaded_zone);
Lubos Slovak's avatar
Lubos Slovak committed
187 188

	printf("------- NSEC 3 tree -\n");
189
#endif
190
}