File: root.c

package info (click to toggle)
ldns 1.8.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,864 kB
  • sloc: ansic: 46,986; python: 7,675; sh: 4,229; perl: 2,186; makefile: 1,231; xml: 518
file content (134 lines) | stat: -rw-r--r-- 5,795 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * root.c
 * Function to handle to the rootservers
 * and to update and prime them
 * (c) 2005 NLnet Labs
 *
 * See the file LICENSE for the license
 *
 */

#include "drill.h"
#include <ldns/ldns.h>
#include <errno.h>

/* a global list of the root-servers */
ldns_rr_list *global_dns_root = NULL;

/* put a hardcoded list in the root and
 * init the root rrlist structure */
void
init_root(void)
{
	ldns_rr *r;
	
	global_dns_root = ldns_rr_list_new();

	(void)ldns_rr_new_frm_str(&r, "A.ROOT-SERVERS.NET.      3600000      A     198.41.0.4", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "A.ROOT-SERVERS.NET.      3600000      AAAA  2001:503:BA3E::2:30", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "B.ROOT-SERVERS.NET.      3600000      A     170.247.170.2", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "B.ROOT-SERVERS.NET.      3600000      AAAA  2801:1b8:10::B", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "C.ROOT-SERVERS.NET.      3600000      A     192.33.4.12", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "C.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:2::C", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "D.ROOT-SERVERS.NET.      3600000      A     199.7.91.13", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "D.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:2D::D", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "E.ROOT-SERVERS.NET.      3600000      A     192.203.230.10", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "E.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:A8::E", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "F.ROOT-SERVERS.NET.      3600000      A     192.5.5.241", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "F.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:2F::F", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "G.ROOT-SERVERS.NET.      3600000      A     192.112.36.4", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "G.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:12::D0D", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "H.ROOT-SERVERS.NET.      3600000      A     198.97.190.53", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "H.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:1::53", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "I.ROOT-SERVERS.NET.      3600000      A     192.36.148.17", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "I.ROOT-SERVERS.NET.      3600000      AAAA  2001:7FE::53", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "J.ROOT-SERVERS.NET.      3600000      A     192.58.128.30", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "J.ROOT-SERVERS.NET.      3600000      AAAA  2001:503:C27::2:30", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "K.ROOT-SERVERS.NET.      3600000      A     193.0.14.129 ", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "K.ROOT-SERVERS.NET.      3600000      AAAA  2001:7FD::1", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "L.ROOT-SERVERS.NET.      3600000      A     199.7.83.42", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "L.ROOT-SERVERS.NET.      3600000      AAAA  2001:500:9F::42", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "M.ROOT-SERVERS.NET.      3600000      A     202.12.27.33", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
	(void)ldns_rr_new_frm_str(&r, "M.ROOT-SERVERS.NET.      3600000      AAAA  2001:DC3::35", 0, NULL, NULL);
	ldns_rr_list_push_rr(global_dns_root, r);
}

/*
 * Read a hints file as root
 *
 * The file with the given path should contain a list of NS RRs
 * for the root zone and A records for those NS RRs.
 * Read them, check them, and append the a records to the rr list given.
 */
ldns_rr_list *
read_root_hints(const char *filename)
{
	FILE *fp = NULL;
	int line_nr = 0;
	ldns_zone *z;
	ldns_status status;
	ldns_rr_list *addresses = NULL;
	ldns_rr *rr;
	size_t i;

	fp = fopen(filename, "r");
	if (!fp) {
		fprintf(stderr, "Unable to open %s for reading: %s\n", filename, strerror(errno));
		return NULL;
	}

	status = ldns_zone_new_frm_fp_l(&z, fp, NULL, 0, 0, &line_nr);
	fclose(fp);
	if (status != LDNS_STATUS_OK) {
		fprintf(stderr, "Error reading root hints file: %s\n", ldns_get_errorstr_by_id(status));
		return NULL;
	} else {
		addresses = ldns_rr_list_new();
		for (i = 0; i < ldns_rr_list_rr_count(ldns_zone_rrs(z)); i++) { 
			rr = ldns_rr_list_rr(ldns_zone_rrs(z), i);
			/*if ((address_family == 0 || address_family == 1) &&
			*/
			if ( ldns_rr_get_type(rr) == LDNS_RR_TYPE_A ) {
				ldns_rr_list_push_rr(addresses, ldns_rr_clone(rr));
			}
			/*if ((address_family == 0 || address_family == 2) &&*/
			if ( ldns_rr_get_type(rr) == LDNS_RR_TYPE_AAAA) {
				ldns_rr_list_push_rr(addresses, ldns_rr_clone(rr));
			}
		}
		ldns_zone_deep_free(z);
		return addresses;
	}
}


void
clear_root(void)
{
	ldns_rr_list_deep_free(global_dns_root);
}