line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#define RR_CLASSNAME_MAX_LEN 34 |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#ifdef USE_ITHREADS |
6
|
|
|
|
|
|
|
#define RESOLVER_HASH_NAME "Zonemaster::LDNS::__resolvers__" |
7
|
|
|
|
|
|
|
#define RR_HASH_NAME "Zonemaster::LDNS::__rrs__" |
8
|
|
|
|
|
|
|
#define RRLIST_HASH_NAME "Zonemaster::LDNS::__rrlists__" |
9
|
|
|
|
|
|
|
#define PACKET_HASH_NAME "Zonemaster::LDNS::__packets__" |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
void |
12
|
|
|
|
|
|
|
net_ldns_forget() |
13
|
|
|
|
|
|
|
{ |
14
|
|
|
|
|
|
|
int i; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
const char *names[] = { |
17
|
|
|
|
|
|
|
RESOLVER_HASH_NAME, |
18
|
|
|
|
|
|
|
RR_HASH_NAME, |
19
|
|
|
|
|
|
|
RRLIST_HASH_NAME, |
20
|
|
|
|
|
|
|
PACKET_HASH_NAME, |
21
|
|
|
|
|
|
|
NULL |
22
|
|
|
|
|
|
|
}; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
for(i=0; names[i]; i++) |
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
HV *hash; |
27
|
|
|
|
|
|
|
HE *entry; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
hash = get_hv(names[i], GV_ADD); |
30
|
|
|
|
|
|
|
while ( (entry = hv_iternext(hash)) != NULL ) |
31
|
|
|
|
|
|
|
{ |
32
|
|
|
|
|
|
|
SV *val = hv_iterval(hash, entry); |
33
|
|
|
|
|
|
|
if(!SvOK(val)) |
34
|
|
|
|
|
|
|
{ |
35
|
|
|
|
|
|
|
SV *key = hv_iterkeysv(entry); |
36
|
|
|
|
|
|
|
hv_delete_ent(hash, key, G_DISCARD, 0); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
void |
43
|
|
|
|
|
|
|
net_ldns_remember_resolver(SV *rv) |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
net_ldns_remember(rv, RESOLVER_HASH_NAME); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
void |
49
|
|
|
|
|
|
|
net_ldns_remember_rr(SV *rv) |
50
|
|
|
|
|
|
|
{ |
51
|
|
|
|
|
|
|
net_ldns_remember(rv, RR_HASH_NAME); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
void |
55
|
|
|
|
|
|
|
net_ldns_remember_rrlist(SV *rv) |
56
|
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
net_ldns_remember(rv, RRLIST_HASH_NAME); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
void |
61
|
|
|
|
|
|
|
net_ldns_remember_packet(SV *rv) |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
net_ldns_remember(rv, PACKET_HASH_NAME); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
void |
67
|
|
|
|
|
|
|
net_ldns_remember(SV *rv, const char *hashname) |
68
|
|
|
|
|
|
|
{ |
69
|
|
|
|
|
|
|
HV *hash; |
70
|
|
|
|
|
|
|
SV *val; |
71
|
|
|
|
|
|
|
STRLEN keylen; |
72
|
|
|
|
|
|
|
char *keystr; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
hash = get_hv(hashname, GV_ADD); |
75
|
|
|
|
|
|
|
val = newRV_inc(SvRV(rv)); |
76
|
|
|
|
|
|
|
keystr = SvPV(val,keylen); |
77
|
|
|
|
|
|
|
sv_rvweaken(val); |
78
|
|
|
|
|
|
|
hv_store(hash, keystr, keylen, val, 0); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
void |
82
|
|
|
|
|
|
|
net_ldns_clone_resolvers() |
83
|
|
|
|
|
|
|
{ |
84
|
|
|
|
|
|
|
HV *hash; |
85
|
|
|
|
|
|
|
HE *entry; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
hash = get_hv(RESOLVER_HASH_NAME, GV_ADD); |
88
|
|
|
|
|
|
|
hv_iterinit(hash); |
89
|
|
|
|
|
|
|
while ( (entry = hv_iternext(hash)) != NULL ) |
90
|
|
|
|
|
|
|
{ |
91
|
|
|
|
|
|
|
SV *val = hv_iterval(hash, entry); |
92
|
|
|
|
|
|
|
if(SvOK(val)) |
93
|
|
|
|
|
|
|
{ |
94
|
|
|
|
|
|
|
ldns_resolver *old = INT2PTR(ldns_resolver *, SvIV((SV *)SvRV(val))); |
95
|
|
|
|
|
|
|
ldns_resolver *new = ldns_resolver_clone(old); |
96
|
|
|
|
|
|
|
sv_setiv_mg(SvRV(val), PTR2IV(new)); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else |
99
|
|
|
|
|
|
|
{ |
100
|
|
|
|
|
|
|
SV *key = hv_iterkeysv(entry); |
101
|
|
|
|
|
|
|
hv_delete_ent(hash, key, G_DISCARD, 0); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
void |
107
|
|
|
|
|
|
|
net_ldns_clone_rrs() |
108
|
|
|
|
|
|
|
{ |
109
|
|
|
|
|
|
|
HV *hash; |
110
|
|
|
|
|
|
|
HE *entry; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
hash = get_hv(RR_HASH_NAME, GV_ADD); |
113
|
|
|
|
|
|
|
hv_iterinit(hash); |
114
|
|
|
|
|
|
|
while ( (entry = hv_iternext(hash)) != NULL ) |
115
|
|
|
|
|
|
|
{ |
116
|
|
|
|
|
|
|
SV *val = hv_iterval(hash, entry); |
117
|
|
|
|
|
|
|
SV *key = hv_iterkeysv(entry); |
118
|
|
|
|
|
|
|
if(SvOK(val)) |
119
|
|
|
|
|
|
|
{ |
120
|
|
|
|
|
|
|
ldns_rr *old = INT2PTR(ldns_rr *, SvIV((SV *)SvRV(val))); |
121
|
|
|
|
|
|
|
ldns_rr *new = ldns_rr_clone(old); |
122
|
|
|
|
|
|
|
sv_setiv_mg(SvRV(val), PTR2IV(new)); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
else |
125
|
|
|
|
|
|
|
{ |
126
|
|
|
|
|
|
|
hv_delete_ent(hash, key, G_DISCARD, 0); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
void |
132
|
|
|
|
|
|
|
net_ldns_clone_rrlists() |
133
|
|
|
|
|
|
|
{ |
134
|
|
|
|
|
|
|
HV *hash; |
135
|
|
|
|
|
|
|
HE *entry; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
hash = get_hv(RRLIST_HASH_NAME, GV_ADD); |
138
|
|
|
|
|
|
|
hv_iterinit(hash); |
139
|
|
|
|
|
|
|
while ( (entry = hv_iternext(hash)) != NULL ) |
140
|
|
|
|
|
|
|
{ |
141
|
|
|
|
|
|
|
SV *val = hv_iterval(hash, entry); |
142
|
|
|
|
|
|
|
if(SvOK(val)) |
143
|
|
|
|
|
|
|
{ |
144
|
|
|
|
|
|
|
ldns_rr_list *old = INT2PTR(ldns_rr_list *, SvIV((SV *)SvRV(val))); |
145
|
|
|
|
|
|
|
ldns_rr_list *new = ldns_rr_list_clone(old); |
146
|
|
|
|
|
|
|
sv_setiv_mg(SvRV(val), PTR2IV(new)); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
else |
149
|
|
|
|
|
|
|
{ |
150
|
|
|
|
|
|
|
SV *key = hv_iterkeysv(entry); |
151
|
|
|
|
|
|
|
hv_delete_ent(hash, key, G_DISCARD, 0); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
void |
157
|
|
|
|
|
|
|
net_ldns_clone_packets() |
158
|
|
|
|
|
|
|
{ |
159
|
|
|
|
|
|
|
HV *hash; |
160
|
|
|
|
|
|
|
HE *entry; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
hash = get_hv(PACKET_HASH_NAME, GV_ADD); |
163
|
|
|
|
|
|
|
hv_iterinit(hash); |
164
|
|
|
|
|
|
|
while ( (entry = hv_iternext(hash)) != NULL ) |
165
|
|
|
|
|
|
|
{ |
166
|
|
|
|
|
|
|
SV *val = hv_iterval(hash, entry); |
167
|
|
|
|
|
|
|
if(SvOK(val)) |
168
|
|
|
|
|
|
|
{ |
169
|
|
|
|
|
|
|
ldns_pkt *old = INT2PTR(ldns_pkt *, SvIV((SV *)SvRV(val))); |
170
|
|
|
|
|
|
|
ldns_pkt *new = ldns_pkt_clone(old); |
171
|
|
|
|
|
|
|
sv_setiv_mg(SvRV(val), PTR2IV(new)); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
else |
174
|
|
|
|
|
|
|
{ |
175
|
|
|
|
|
|
|
SV *key = hv_iterkeysv(entry); |
176
|
|
|
|
|
|
|
hv_delete_ent(hash, key, G_DISCARD, 0); |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
#endif |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
char * |
184
|
18
|
|
|
|
|
|
randomize_capitalization(char *in) |
185
|
|
|
|
|
|
|
{ |
186
|
|
|
|
|
|
|
#ifdef RANDOMIZE |
187
|
|
|
|
|
|
|
char *str; |
188
|
|
|
|
|
|
|
str = in; |
189
|
|
|
|
|
|
|
while(*str) { |
190
|
|
|
|
|
|
|
if(Drand01() < 0.5) |
191
|
|
|
|
|
|
|
{ |
192
|
|
|
|
|
|
|
*str = tolower(*str); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
else |
195
|
|
|
|
|
|
|
{ |
196
|
|
|
|
|
|
|
*str = toupper(*str); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
str++; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
#endif |
201
|
18
|
|
|
|
|
|
return in; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
SV * |
205
|
73
|
|
|
|
|
|
rr2sv(ldns_rr *rr) |
206
|
|
|
|
|
|
|
{ |
207
|
|
|
|
|
|
|
char rrclass[RR_CLASSNAME_MAX_LEN]; |
208
|
|
|
|
|
|
|
char *type; |
209
|
|
|
|
|
|
|
|
210
|
73
|
|
|
|
|
|
type = ldns_rr_type2str(ldns_rr_get_type(rr)); |
211
|
73
|
|
|
|
|
|
snprintf(rrclass, RR_CLASSNAME_MAX_LEN, "Zonemaster::LDNS::RR::%s", type); |
212
|
|
|
|
|
|
|
|
213
|
73
|
|
|
|
|
|
SV* rr_sv = newSV(0); |
214
|
73
|
50
|
|
|
|
|
if (strncmp(type, "TYPE", 4)==0) |
215
|
|
|
|
|
|
|
{ |
216
|
0
|
|
|
|
|
|
sv_setref_pv(rr_sv, "Zonemaster::LDNS::RR", rr); |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
else |
219
|
|
|
|
|
|
|
{ |
220
|
73
|
|
|
|
|
|
sv_setref_pv(rr_sv, rrclass, rr); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
73
|
|
|
|
|
|
free(type); |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
#ifdef USE_ITHREADS |
226
|
|
|
|
|
|
|
net_ldns_remember_rr(rr_sv); |
227
|
|
|
|
|
|
|
#endif |
228
|
|
|
|
|
|
|
|
229
|
73
|
|
|
|
|
|
return rr_sv; |
230
|
|
|
|
|
|
|
} |