Blame
Date:
Thu Sep 10 14:45:56 2020 UTC
Message:
I want to stick with ldns-verify-zone
001
2020-07-08
pjp
/*
002
2020-07-08
pjp
* Copyright (c) 2020 Peter J. Philipp
003
2020-07-08
pjp
* All rights reserved.
004
2020-07-08
pjp
*
005
2020-07-08
pjp
* Redistribution and use in source and binary forms, with or without
006
2020-07-08
pjp
* modification, are permitted provided that the following conditions
007
2020-07-08
pjp
* are met:
008
2020-07-08
pjp
* 1. Redistributions of source code must retain the above copyright
009
2020-07-08
pjp
* notice, this list of conditions and the following disclaimer.
010
2020-07-08
pjp
* 2. Redistributions in binary form must reproduce the above copyright
011
2020-07-08
pjp
* notice, this list of conditions and the following disclaimer in the
012
2020-07-08
pjp
* documentation and/or other materials provided with the distribution.
013
2020-07-08
pjp
* 3. The name of the author may not be used to endorse or promote products
014
2020-07-08
pjp
* derived from this software without specific prior written permission
015
2020-07-08
pjp
*
016
2020-07-08
pjp
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
017
2020-07-08
pjp
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
018
2020-07-08
pjp
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
019
2020-07-08
pjp
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
020
2020-07-08
pjp
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
021
2020-07-08
pjp
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
022
2020-07-08
pjp
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
023
2020-07-08
pjp
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
024
2020-07-08
pjp
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
025
2020-07-08
pjp
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
026
2020-07-08
pjp
*
027
2020-07-08
pjp
*/
028
2020-07-08
pjp
029
2020-07-08
pjp
/*
030
2020-08-08
pjp
* $Id: cache.c,v 1.13 2020/08/08 05:51:48 pjp Exp $
031
2020-07-08
pjp
*/
032
2020-07-08
pjp
033
2020-07-08
pjp
#include <sys/types.h>
034
2020-07-08
pjp
#include <sys/socket.h>
035
2020-07-08
pjp
#include <sys/uio.h>
036
2020-07-08
pjp
#include <sys/select.h>
037
2020-07-08
pjp
038
2020-07-08
pjp
#include <netinet/in.h>
039
2020-07-08
pjp
#include <arpa/inet.h>
040
2020-07-08
pjp
#include <netdb.h>
041
2020-07-08
pjp
042
2020-07-08
pjp
#include <stdio.h>
043
2020-07-08
pjp
#include <stdlib.h>
044
2020-07-08
pjp
#include <stdint.h>
045
2020-07-08
pjp
#include <string.h>
046
2020-07-08
pjp
#include <errno.h>
047
2020-07-08
pjp
#include <syslog.h>
048
2020-07-08
pjp
049
2020-07-08
pjp
#include <unistd.h>
050
2020-07-08
pjp
051
2020-07-08
pjp
#ifdef __linux__
052
2020-07-08
pjp
#include <grp.h>
053
2020-07-08
pjp
#define __USE_BSD 1
054
2020-07-08
pjp
#include <endian.h>
055
2020-07-08
pjp
#include <bsd/stdlib.h>
056
2020-07-08
pjp
#include <bsd/string.h>
057
2020-07-08
pjp
#include <bsd/unistd.h>
058
2020-07-08
pjp
#include <bsd/sys/queue.h>
059
2020-07-08
pjp
#define __unused
060
2020-07-08
pjp
#include <bsd/sys/tree.h>
061
2020-07-08
pjp
#include <bsd/sys/endian.h>
062
2020-07-08
pjp
#include "imsg.h"
063
2020-07-08
pjp
#else /* not linux */
064
2020-07-08
pjp
#include <sys/queue.h>
065
2020-07-08
pjp
#include <sys/tree.h>
066
2020-07-08
pjp
#ifdef __FreeBSD__
067
2020-07-08
pjp
#include <sys/endian.h>
068
2020-07-08
pjp
#include "imsg.h"
069
2020-07-08
pjp
#else
070
2020-07-08
pjp
#include <imsg.h>
071
2020-07-08
pjp
#endif /* __FreeBSD__ */
072
2020-07-08
pjp
#endif /* __linux__ */
073
2020-07-08
pjp
074
2020-07-08
pjp
#ifndef NTOHS
075
2020-07-08
pjp
#include "endian.h"
076
2020-07-08
pjp
#endif
077
2020-07-08
pjp
078
2020-07-08
pjp
#include <openssl/hmac.h>
079
2020-07-08
pjp
080
2020-07-08
pjp
#include "ddd-dns.h"
081
2020-07-08
pjp
#include "ddd-db.h"
082
2020-07-08
pjp
083
2020-07-08
pjp
084
2020-07-08
pjp
extern void dolog(int, char *, ...);
085
2020-07-08
pjp
extern char * expand_compression(u_char *, u_char *, u_char *, u_char *, int *, int);
086
2020-07-08
pjp
extern void pack(char *, char *, int);
087
2020-07-08
pjp
extern void pack16(char *, u_int16_t);
088
2020-07-10
pjp
extern void pack32(char *, u_int32_t);
089
2020-07-08
pjp
extern void unpack(char *, char *, int);
090
2020-07-08
pjp
extern uint16_t unpack16(char *);
091
2020-07-08
pjp
extern uint32_t unpack32(char *);
092
2020-07-16
pjp
extern int lower_dnsname(char *, int);
093
2020-07-08
pjp
094
2020-07-08
pjp
095
2020-07-08
pjp
extern int debug, verbose;
096
2020-07-08
pjp
extern int tsig;
097
2020-07-08
pjp
extern int dnssec;
098
2020-07-08
pjp
extern int cache;
099
2020-07-08
pjp
100
2020-07-12
pjp
int cacheit(u_char *, u_char *, u_char *, struct imsgbuf *, struct imsgbuf *, struct cfg *);
101
2020-07-18
pjp
struct scache * build_cache(u_char *, u_char *, u_char *, uint16_t, char *, int, uint32_t, uint16_t, struct imsgbuf *, struct imsgbuf *, struct cfg *, int);
102
2020-07-08
pjp
void transmit_rr(struct scache *, void *, int);
103
2020-07-08
pjp
104
2020-07-08
pjp
105
2020-07-08
pjp
int cache_a(struct scache *);
106
2020-07-08
pjp
int cache_aaaa(struct scache *);
107
2020-07-08
pjp
int cache_cname(struct scache *);
108
2020-07-08
pjp
int cache_ns(struct scache *);
109
2020-07-08
pjp
int cache_ptr(struct scache *);
110
2020-07-08
pjp
int cache_mx(struct scache *);
111
2020-07-08
pjp
int cache_txt(struct scache *);
112
2020-07-08
pjp
int cache_dnskey(struct scache *);
113
2020-07-08
pjp
int cache_rrsig(struct scache *);
114
2020-07-08
pjp
int cache_nsec3param(struct scache *);
115
2020-07-08
pjp
int cache_nsec3(struct scache *);
116
2020-07-08
pjp
int cache_ds(struct scache *);
117
2020-07-08
pjp
int cache_sshfp(struct scache *);
118
2020-07-08
pjp
int cache_tlsa(struct scache *);
119
2020-07-08
pjp
int cache_srv(struct scache *);
120
2020-07-08
pjp
int cache_naptr(struct scache *);
121
2020-07-08
pjp
int cache_soa(struct scache *);
122
2020-07-15
pjp
int cache_generic(struct scache *);
123
2020-07-08
pjp
124
2020-07-08
pjp
125
2020-07-08
pjp
/* The following alias helps with bounds checking all input, needed! */
126
2020-07-08
pjp
127
2020-07-08
pjp
#define BOUNDS_CHECK(cur, begin, rdlen, end) do { \
128
2020-07-08
pjp
if ((cur - begin) > rdlen) { \
129
2020-07-08
pjp
return -1; \
130
2020-07-08
pjp
} \
131
2020-07-08
pjp
if (cur > end) \
132
2020-07-08
pjp
return -1; \
133
2020-07-08
pjp
} while (0)
134
2020-07-08
pjp
135
2020-07-08
pjp
static struct cache_logic supported_cache[] = {
136
2020-07-08
pjp
{ DNS_TYPE_A, 0, cache_a },
137
2020-08-03
pjp
/* { DNS_TYPE_NS, 0, cache_ns }, */
138
2020-07-08
pjp
{ DNS_TYPE_MX, 0, cache_mx },
139
2020-07-08
pjp
{ DNS_TYPE_PTR, 0, cache_ptr },
140
2020-07-08
pjp
{ DNS_TYPE_AAAA, 0, cache_aaaa },
141
2020-07-08
pjp
{ DNS_TYPE_CNAME, 0, cache_cname },
142
2020-07-08
pjp
/* { DNS_TYPE_TXT, 0, cache_txt }, */
143
2020-07-08
pjp
{ DNS_TYPE_DNSKEY, 1, cache_dnskey },
144
2020-07-08
pjp
{ DNS_TYPE_RRSIG, 1, cache_rrsig },
145
2020-07-08
pjp
{ DNS_TYPE_NSEC3PARAM, 1, cache_nsec3param },
146
2020-07-08
pjp
{ DNS_TYPE_NSEC3, 1, cache_nsec3 },
147
2020-07-08
pjp
{ DNS_TYPE_DS, 1, cache_ds },
148
2020-07-08
pjp
{ DNS_TYPE_SSHFP, 0, cache_sshfp },
149
2020-07-08
pjp
{ DNS_TYPE_TLSA, 0, cache_tlsa },
150
2020-07-08
pjp
{ DNS_TYPE_SRV, 0, cache_srv },
151
2020-07-08
pjp
/* { DNS_TYPE_NAPTR, 0, cache_naptr }, */
152
2020-07-08
pjp
{ 0, 0, NULL }
153
2020-07-08
pjp
};
154
2020-07-08
pjp
155
2020-07-08
pjp
156
2020-07-08
pjp
157
2020-07-08
pjp
158
2020-07-08
pjp
struct scache *
159
2020-07-18
pjp
build_cache(u_char *payload, u_char *estart, u_char *end, uint16_t rdlen, char *name, int namelen, uint32_t dnsttl, uint16_t dnstype, struct imsgbuf *imsgbuf, struct imsgbuf *bimsgbuf, struct cfg *cfg, int authentic)
160
2020-07-08
pjp
{
161
2020-07-08
pjp
static struct scache ret;
162
2020-07-08
pjp
163
2020-07-08
pjp
memset(&ret, 0, sizeof(ret));
164
2020-07-08
pjp
ret.payload = payload;
165
2020-07-08
pjp
ret.estart = estart;
166
2020-07-08
pjp
ret.end = end;
167
2020-07-08
pjp
ret.rdlen = rdlen;
168
2020-07-08
pjp
ret.name = name;
169
2020-07-08
pjp
ret.namelen = namelen;
170
2020-07-08
pjp
ret.dnsttl = dnsttl;
171
2020-07-08
pjp
ret.rrtype = dnstype;
172
2020-07-08
pjp
ret.imsgbuf = imsgbuf;
173
2020-07-10
pjp
ret.bimsgbuf = bimsgbuf;
174
2020-07-12
pjp
ret.cfg = cfg;
175
2020-07-18
pjp
ret.authentic = authentic;
176
2020-07-08
pjp
177
2020-07-08
pjp
return (&ret);
178
2020-07-08
pjp
}
179
2020-07-08
pjp
180
2020-07-08
pjp
void
181
2020-07-08
pjp
transmit_rr(struct scache *scache, void *rr, int rrsize)
182
2020-07-08
pjp
{
183
2020-07-10
pjp
struct rr_imsg ri, *pri;
184
2020-07-12
pjp
int i;
185
2020-07-08
pjp
186
2020-07-12
pjp
/* we don't fit */
187
2020-07-12
pjp
if (rrsize > (sizeof(struct rr_imsg) - sizeof(ri.rri_rr)))
188
2020-07-12
pjp
return;
189
2020-07-08
pjp
190
2020-07-12
pjp
memcpy(ri.rri_rr.name, scache->name, sizeof(ri.rri_rr.name));
191
2020-07-12
pjp
ri.rri_rr.namelen = scache->namelen;
192
2020-07-08
pjp
193
2020-07-16
pjp
if (lower_dnsname(ri.rri_rr.name, ri.rri_rr.namelen) == -1) {
194
2020-07-16
pjp
dolog(LOG_INFO, "lower_dnsname failed\n");
195
2020-07-16
pjp
return;
196
2020-07-16
pjp
}
197
2020-07-16
pjp
198
2020-07-12
pjp
ri.rri_rr.ttl = scache->dnsttl;
199
2020-07-12
pjp
ri.rri_rr.rrtype = scache->rrtype;
200
2020-07-18
pjp
ri.rri_rr.authentic = scache->authentic;
201
2020-07-18
pjp
202
2020-07-12
pjp
203
2020-07-12
pjp
memcpy(&ri.rri_rr.un, rr, rrsize);
204
2020-07-12
pjp
ri.rri_rr.buflen = rrsize;
205
2020-07-12
pjp
ri.u.s.read = 0;
206
2020-07-12
pjp
207
2020-07-10
pjp
/* wait for lock */
208
2020-07-12
pjp
while (scache->cfg->shptr2[scache->cfg->shptr2size - 16] == '*') {
209
2020-07-10
pjp
usleep(arc4random() % 300);
210
2020-07-10
pjp
}
211
2020-07-10
pjp
212
2020-07-12
pjp
scache->cfg->shptr2[scache->cfg->shptr2size - 16] = '*';
213
2020-07-10
pjp
214
2020-07-10
pjp
215
2020-07-12
pjp
for (pri = (struct rr_imsg *)&scache->cfg->shptr2[0], i = 0;
216
2020-07-10
pjp
i < SHAREDMEMSIZE; i++, pri++) {
217
2020-07-12
pjp
if (unpack32((char *)&pri->u.s.read) == 1) {
218
2020-07-10
pjp
memcpy(pri, &ri, sizeof(struct rr_imsg));
219
2020-07-12
pjp
pack32((char *)&pri->u.s.read, 0);
220
2020-07-10
pjp
break;
221
2020-07-10
pjp
}
222
2020-07-10
pjp
}
223
2020-07-10
pjp
224
2020-07-10
pjp
if (i == SHAREDMEMSIZE) {
225
2020-07-10
pjp
dolog(LOG_INFO, "can't find an open slot in sharedmemsize\n");
226
2020-07-10
pjp
}
227
2020-07-10
pjp
228
2020-07-12
pjp
scache->cfg->shptr2[scache->cfg->shptr2size - 16] = ' ';
229
2020-07-08
pjp
}
230
2020-07-08
pjp
231
2020-07-08
pjp
int
232
2020-07-12
pjp
cacheit(u_char *payload, u_char *estart, u_char *end, struct imsgbuf *imsgbuf, struct imsgbuf *bimsgbuf, struct cfg *cfg)
233
2020-07-08
pjp
{
234
2020-07-10
pjp
struct dns_header *dh;
235
2020-07-08
pjp
struct scache *scache;
236
2020-07-08
pjp
char expand[DNS_MAXNAME + 1];
237
2020-07-08
pjp
int elen, i, x;
238
2020-07-08
pjp
int rlen = (end - estart);
239
2020-07-08
pjp
u_char *pb, *p = payload;
240
2020-07-08
pjp
241
2020-07-08
pjp
uint16_t rrtype;
242
2020-07-08
pjp
uint16_t rdlen;
243
2020-07-08
pjp
uint32_t rrttl;
244
2020-07-08
pjp
245
2020-07-08
pjp
struct cache_logic *cr;
246
2020-07-18
pjp
int authentic = 0;
247
2020-07-08
pjp
248
2020-07-10
pjp
dh = (struct dns_header *)payload;
249
2020-07-08
pjp
p += sizeof(struct dns_header); /* skip dns_header */
250
2020-07-18
pjp
251
2020-07-18
pjp
/* if the data sent back is authentic by the resolver set dnssecok */
252
2020-07-18
pjp
if (ntohs(dh->query) & DNS_AD)
253
2020-07-18
pjp
authentic = 1;
254
2020-07-08
pjp
255
2020-07-08
pjp
elen = 0,
256
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
257
2020-07-08
pjp
258
2020-07-08
pjp
pb = expand_compression(p, estart, end, (u_char *)&expand, &elen, sizeof
259
2020-07-08
pjp
(expand));
260
2020-07-08
pjp
if (pb == NULL) {
261
2020-07-08
pjp
dolog(LOG_INFO, "expand_compression() failed in cacheit 1");
262
2020-07-08
pjp
return (-1);
263
2020-07-08
pjp
}
264
2020-07-08
pjp
265
2020-07-08
pjp
i = (pb - estart);
266
2020-07-08
pjp
267
2020-07-08
pjp
if (i > rlen) {
268
2020-07-08
pjp
dolog(LOG_INFO, "expand_compression() failed in cacheit 2");
269
2020-07-08
pjp
return (-1);
270
2020-07-08
pjp
}
271
2020-07-08
pjp
272
2020-07-08
pjp
rrtype = ntohs(unpack16(pb));
273
2020-07-08
pjp
274
2020-07-20
pjp
/* caching ANY or RRSIG is a nono */
275
2020-08-03
pjp
if (rrtype == DNS_TYPE_ANY || rrtype == DNS_TYPE_RRSIG
276
2020-08-03
pjp
|| rrtype == DNS_TYPE_NS) {
277
2020-07-08
pjp
return -1;
278
2020-07-08
pjp
}
279
2020-07-08
pjp
280
2020-07-08
pjp
pb += 4; /* skip type and class */
281
2020-07-08
pjp
282
2020-07-08
pjp
for (x = 0; x < ntohs(dh->answer); x++) {
283
2020-07-10
pjp
printf("%d out of %d\n", x, ntohs(dh->answer));
284
2020-07-08
pjp
elen = 0;
285
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
286
2020-07-08
pjp
pb = expand_compression(pb, estart, end, (u_char *)&expand, &elen, sizeof(expand));
287
2020-07-08
pjp
if (pb == NULL) {
288
2020-07-08
pjp
dolog(LOG_INFO, "expand_compression() failed in cacheit 3");
289
2020-07-08
pjp
return (-1);
290
2020-07-08
pjp
}
291
2020-07-08
pjp
292
2020-07-08
pjp
i = (pb - estart);
293
2020-07-08
pjp
294
2020-07-08
pjp
if (i > rlen) {
295
2020-07-08
pjp
dolog(LOG_INFO, "expand_compression() failed in cacheit 4");
296
2020-07-08
pjp
return (-1);
297
2020-07-08
pjp
}
298
2020-07-08
pjp
299
2020-07-08
pjp
/* bounds check the rest of the RR to the RDATA */
300
2020-07-08
pjp
if (pb + 10 >= end) {
301
2020-07-08
pjp
dolog(LOG_INFO, "malformed reply, drop\n");
302
2020-07-08
pjp
return -1;
303
2020-07-08
pjp
}
304
2020-07-08
pjp
305
2020-07-08
pjp
rrtype = ntohs(unpack16(pb));
306
2020-07-08
pjp
/* class in here not parsed */
307
2020-07-08
pjp
rrttl = ntohl(unpack32(pb + 4));
308
2020-07-08
pjp
rdlen = ntohs(unpack16(pb + 8));
309
2020-07-08
pjp
310
2020-07-08
pjp
pb += 10; /* skip answerd */
311
2020-07-08
pjp
312
2020-07-18
pjp
scache = build_cache(pb, estart, end, rdlen, expand, elen, rrttl, rrtype, imsgbuf, bimsgbuf, cfg, authentic);
313
2020-07-08
pjp
314
2020-07-08
pjp
for (cr = supported_cache; cr->rrtype != 0; cr++) {
315
2020-07-08
pjp
if (rrtype == cr->rrtype) {
316
2020-07-08
pjp
if ((*cr->cacheit)(scache) < 0) {
317
2020-07-08
pjp
dolog(LOG_INFO, "error parsing cache with rrtype %d\n", rrtype);
318
2020-07-08
pjp
}
319
2020-07-08
pjp
320
2020-07-08
pjp
break;
321
2020-07-08
pjp
}
322
2020-07-08
pjp
}
323
2020-07-15
pjp
if (cr->rrtype == 0) {
324
2020-07-15
pjp
cache_generic(scache);
325
2020-07-15
pjp
}
326
2020-07-08
pjp
327
2020-07-08
pjp
pb += rdlen;
328
2020-07-08
pjp
329
2020-07-08
pjp
} /* for(x ... */
330
2020-07-08
pjp
331
2020-07-10
pjp
i = 42;
332
2020-07-10
pjp
if (imsg_compose(bimsgbuf, IMSG_RR_ATTACHED, 0, 0, -1, &i, sizeof(int)) != 1) {
333
2020-07-10
pjp
dolog(LOG_INFO, "imsg_compose failed: %s\n", strerror(errno));
334
2020-07-10
pjp
}
335
2020-07-10
pjp
336
2020-07-10
pjp
if (msgbuf_write(&bimsgbuf->w) == -1)
337
2020-07-10
pjp
dolog(LOG_ERR, "msgbuf_write: %s\n", strerror(errno));
338
2020-07-08
pjp
339
2020-07-08
pjp
return (0);
340
2020-07-08
pjp
}
341
2020-07-08
pjp
342
2020-07-08
pjp
int
343
2020-07-08
pjp
cache_rrsig(struct scache *scache)
344
2020-07-08
pjp
{
345
2020-07-08
pjp
struct rrsig rs;
346
2020-07-08
pjp
char *save;
347
2020-07-08
pjp
u_char *q = scache->payload;
348
2020-07-08
pjp
u_char expand[256];
349
2020-07-08
pjp
int max = sizeof(expand);
350
2020-07-08
pjp
int elen = 0;
351
2020-07-08
pjp
u_int16_t tmp;
352
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
353
2020-07-08
pjp
u_int32_t tmp4;
354
2020-07-08
pjp
u_char *p = q;
355
2020-07-08
pjp
356
2020-07-10
pjp
memset(&rs, 0, sizeof(struct rrsig));
357
2020-07-10
pjp
358
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
359
2020-07-08
pjp
tmp = unpack16(q);
360
2020-07-08
pjp
rs.type_covered = ntohs(tmp);
361
2020-07-08
pjp
q += 2;
362
2020-07-08
pjp
BOUNDS_CHECK((q + 1), scache->payload, scache->rdlen, scache->end);
363
2020-07-08
pjp
rs.algorithm = *q++;
364
2020-07-08
pjp
BOUNDS_CHECK((q + 1), scache->payload, scache->rdlen, scache->end);
365
2020-07-08
pjp
rs.labels = *q++;
366
2020-07-08
pjp
BOUNDS_CHECK((q + 4), scache->payload, scache->rdlen, scache->end);
367
2020-07-08
pjp
tmp4 = unpack32(q);
368
2020-07-08
pjp
rs.original_ttl = ntohl(tmp4);
369
2020-07-08
pjp
q += 4;
370
2020-07-08
pjp
BOUNDS_CHECK((q + 4), scache->payload, scache->rdlen, scache->end);
371
2020-07-08
pjp
tmp4 = unpack32(q);
372
2020-07-08
pjp
rs.signature_expiration = ntohl(tmp4);
373
2020-07-08
pjp
q += 4;
374
2020-07-08
pjp
BOUNDS_CHECK((q + 4), scache->payload, scache->rdlen, scache->end);
375
2020-07-08
pjp
tmp4 = unpack32(q);
376
2020-07-08
pjp
rs.signature_inception = ntohl(tmp4);
377
2020-07-08
pjp
q += 4;
378
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
379
2020-07-08
pjp
tmp = unpack16(q);
380
2020-07-08
pjp
rs.key_tag = ntohs(tmp);
381
2020-07-08
pjp
q += 2;
382
2020-07-08
pjp
383
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
384
2020-07-08
pjp
save = expand_compression(q, scache->estart, scache->end, (u_char *)&expand, &elen, max);
385
2020-07-08
pjp
if (save == NULL) {
386
2020-07-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
387
2020-07-08
pjp
return -1;
388
2020-07-08
pjp
} else {
389
2020-07-08
pjp
q = save;
390
2020-07-08
pjp
}
391
2020-07-08
pjp
392
2020-07-08
pjp
memcpy(&rs.signers_name, expand, elen);
393
2020-07-08
pjp
rs.signame_len = elen;
394
2020-07-08
pjp
395
2020-07-08
pjp
rs.signature_len = (rdlen - (q - p));
396
2020-07-08
pjp
397
2020-07-08
pjp
if (rs.signature_len > sizeof(rs.signature))
398
2020-07-08
pjp
return -1;
399
2020-07-08
pjp
memcpy(&rs.signature, q, rs.signature_len);
400
2020-07-08
pjp
q += rs.signature_len;
401
2020-07-08
pjp
402
2020-07-10
pjp
transmit_rr(scache, (void *)&rs, sizeof(rs));
403
2020-07-08
pjp
404
2020-07-08
pjp
return (q - scache->estart);
405
2020-07-08
pjp
}
406
2020-07-08
pjp
407
2020-07-08
pjp
int
408
2020-07-08
pjp
cache_ds(struct scache *scache)
409
2020-07-08
pjp
{
410
2020-07-08
pjp
struct ds d;
411
2020-07-08
pjp
u_int16_t tmpshort;
412
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
413
2020-07-08
pjp
u_char *p = scache->payload;
414
2020-07-08
pjp
u_char *q = p;
415
2020-07-08
pjp
416
2020-07-10
pjp
memset(&d, 0, sizeof(struct ds));
417
2020-07-10
pjp
418
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 2), q, scache->rdlen, scache->end);
419
2020-07-08
pjp
tmpshort = unpack16(p);
420
2020-07-08
pjp
d.key_tag = ntohs(tmpshort);
421
2020-07-08
pjp
p += 2;
422
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
423
2020-07-08
pjp
d.algorithm = *p++;
424
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
425
2020-07-08
pjp
d.digest_type = *p++;
426
2020-07-08
pjp
427
2020-07-08
pjp
if ((rdlen - 4) < 0)
428
2020-07-08
pjp
return -1;
429
2020-07-08
pjp
d.digestlen = (rdlen - 4);
430
2020-07-08
pjp
if (d.digestlen > sizeof(d.digest))
431
2020-07-08
pjp
return -1;
432
2020-07-08
pjp
memcpy(&d.digest, p, d.digestlen);
433
2020-07-08
pjp
p += d.digestlen;
434
2020-07-08
pjp
435
2020-07-08
pjp
436
2020-07-08
pjp
transmit_rr(scache, &d, sizeof(d));
437
2020-07-08
pjp
438
2020-07-08
pjp
return (p - scache->estart);
439
2020-07-08
pjp
}
440
2020-07-08
pjp
441
2020-07-08
pjp
int
442
2020-07-08
pjp
cache_sshfp(struct scache *scache)
443
2020-07-08
pjp
{
444
2020-07-08
pjp
struct sshfp s;
445
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
446
2020-07-08
pjp
u_char *p = scache->payload;
447
2020-07-08
pjp
u_char *q = p;
448
2020-07-08
pjp
449
2020-07-10
pjp
memset(&s, 0, sizeof(struct sshfp));
450
2020-07-10
pjp
451
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
452
2020-07-08
pjp
s.algorithm = *p++;
453
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
454
2020-07-08
pjp
s.fptype = *p++;
455
2020-07-08
pjp
456
2020-07-08
pjp
if (rdlen - 2 < 0)
457
2020-07-08
pjp
return -1;
458
2020-07-08
pjp
459
2020-07-08
pjp
s.fplen = (rdlen - 2);
460
2020-07-08
pjp
if (s.fplen > sizeof(s.fingerprint))
461
2020-07-08
pjp
return -1;
462
2020-07-08
pjp
463
2020-07-08
pjp
memcpy(&s.fingerprint, p, s.fplen);
464
2020-07-08
pjp
p += s.fplen;
465
2020-07-08
pjp
466
2020-07-08
pjp
transmit_rr(scache, &s, sizeof(s));
467
2020-07-08
pjp
468
2020-07-08
pjp
return (p - scache->estart);
469
2020-07-08
pjp
}
470
2020-07-08
pjp
471
2020-07-08
pjp
int
472
2020-07-08
pjp
cache_dnskey(struct scache *scache)
473
2020-07-08
pjp
{
474
2020-07-08
pjp
struct dnskey dk;
475
2020-07-08
pjp
u_int16_t tmpshort;
476
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
477
2020-07-08
pjp
u_char *p = scache->payload;
478
2020-07-08
pjp
u_char *q = p;
479
2020-07-08
pjp
480
2020-07-10
pjp
481
2020-07-10
pjp
memset(&dk, 0, sizeof(struct dnskey));
482
2020-07-10
pjp
483
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 2), q, scache->rdlen, scache->end);
484
2020-07-08
pjp
tmpshort = unpack16(p);
485
2020-07-08
pjp
dk.flags = ntohs(tmpshort);
486
2020-07-08
pjp
p += 2;
487
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
488
2020-07-08
pjp
dk.protocol = *p++;
489
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
490
2020-07-08
pjp
dk.algorithm = *p++;
491
2020-07-08
pjp
492
2020-07-08
pjp
if (rdlen - 4 < 0)
493
2020-07-08
pjp
return -1;
494
2020-07-08
pjp
dk.publickey_len = (rdlen - 4);
495
2020-07-08
pjp
if (dk.publickey_len > sizeof(dk.public_key))
496
2020-07-08
pjp
return -1;
497
2020-07-08
pjp
498
2020-07-08
pjp
memcpy(&dk.public_key, p, dk.publickey_len);
499
2020-07-08
pjp
p += dk.publickey_len;
500
2020-07-08
pjp
501
2020-07-08
pjp
transmit_rr(scache, &dk, sizeof(dk));
502
2020-07-08
pjp
503
2020-07-08
pjp
return (p - scache->estart);
504
2020-07-08
pjp
}
505
2020-07-08
pjp
506
2020-07-08
pjp
507
2020-07-08
pjp
int
508
2020-07-08
pjp
cache_mx(struct scache *scache)
509
2020-07-08
pjp
{
510
2020-07-08
pjp
struct smx mx;
511
2020-07-08
pjp
u_int16_t mxpriority;
512
2020-07-08
pjp
char *save;
513
2020-07-08
pjp
u_char *p = scache->payload;
514
2020-07-08
pjp
u_char *q = p;
515
2020-07-08
pjp
u_char expand[256];
516
2020-07-08
pjp
int max = sizeof(expand);
517
2020-07-08
pjp
int elen = 0;
518
2020-07-08
pjp
519
2020-07-10
pjp
memset(&mx, 0, sizeof(struct smx));
520
2020-07-10
pjp
521
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
522
2020-07-08
pjp
mxpriority = unpack16(q);
523
2020-07-08
pjp
524
2020-07-08
pjp
q += 2;
525
2020-07-08
pjp
526
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
527
2020-08-02
pjp
elen = 0;
528
2020-07-08
pjp
save = expand_compression(q, scache->estart, scache->end, (u_char *)&expand, &elen, max);
529
2020-07-08
pjp
if (save == NULL) {
530
2020-07-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
531
2020-07-08
pjp
return -1;
532
2020-07-08
pjp
} else {
533
2020-07-08
pjp
q = save;
534
2020-07-08
pjp
}
535
2020-07-08
pjp
536
2020-07-08
pjp
memcpy(&mx.exchange, expand, sizeof(mx.exchange));
537
2020-08-02
pjp
if (lower_dnsname(mx.exchange, elen) == -1) {
538
2020-08-02
pjp
dolog(LOG_INFO, "lower_dnsname failed\n");
539
2020-08-02
pjp
return -1;
540
2020-08-02
pjp
}
541
2020-07-08
pjp
mx.exchangelen = elen;
542
2020-08-02
pjp
mx.preference = ntohs(mxpriority);
543
2020-07-08
pjp
544
2020-07-08
pjp
transmit_rr(scache, &mx, sizeof(mx));
545
2020-07-08
pjp
546
2020-07-08
pjp
return (q - scache->estart);
547
2020-07-08
pjp
}
548
2020-07-08
pjp
549
2020-07-08
pjp
int
550
2020-07-08
pjp
cache_ptr(struct scache *scache)
551
2020-07-08
pjp
{
552
2020-07-08
pjp
return (cache_ns(scache));
553
2020-07-08
pjp
}
554
2020-07-08
pjp
555
2020-07-08
pjp
int
556
2020-07-08
pjp
cache_nsec3(struct scache *scache)
557
2020-07-08
pjp
{
558
2020-07-08
pjp
struct nsec3 n;
559
2020-07-08
pjp
u_char *p = scache->payload;
560
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
561
2020-07-08
pjp
u_int16_t iter;
562
2020-07-08
pjp
u_char *brr = scache->payload; /* begin of rd record :-) */
563
2020-07-08
pjp
564
2020-07-10
pjp
memset(&n, 0, sizeof(struct nsec3));
565
2020-07-10
pjp
566
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), brr, scache->rdlen, scache->end);
567
2020-07-08
pjp
n.algorithm = *p++;
568
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), brr, scache->rdlen, scache->end);
569
2020-07-08
pjp
n.flags = *p++;
570
2020-07-08
pjp
571
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 2), brr, scache->rdlen, scache->end);
572
2020-07-08
pjp
iter = unpack16(p);
573
2020-07-08
pjp
n.iterations = ntohs(iter);
574
2020-07-08
pjp
p += 2;
575
2020-07-08
pjp
576
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), brr, scache->rdlen, scache->end);
577
2020-07-08
pjp
n.saltlen = *p++;
578
2020-07-08
pjp
memcpy(&n.salt, p, n.saltlen);
579
2020-07-08
pjp
p += n.saltlen;
580
2020-07-08
pjp
581
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), brr, scache->rdlen, scache->end);
582
2020-07-08
pjp
n.nextlen = *p++;
583
2020-07-08
pjp
memcpy(&n.next, p, n.nextlen);
584
2020-07-08
pjp
p += n.nextlen;
585
2020-07-08
pjp
586
2020-07-08
pjp
587
2020-07-08
pjp
if (((rdlen - (p - brr)) + 1) < 0)
588
2020-07-08
pjp
return -1;
589
2020-07-08
pjp
590
2020-07-08
pjp
/* XXX */
591
2020-07-08
pjp
n.bitmap_len = (rdlen - (p - brr));
592
2020-07-08
pjp
if (n.bitmap_len > sizeof(n.bitmap))
593
2020-07-08
pjp
return -1;
594
2020-07-08
pjp
595
2020-07-08
pjp
memcpy(&n.bitmap, p, n.bitmap_len);
596
2020-07-08
pjp
p += n.bitmap_len;
597
2020-07-08
pjp
598
2020-07-08
pjp
transmit_rr(scache, &n, sizeof(n));
599
2020-07-08
pjp
600
2020-07-08
pjp
return (p - scache->estart);
601
2020-07-08
pjp
}
602
2020-07-08
pjp
603
2020-07-08
pjp
int
604
2020-07-08
pjp
cache_nsec3param(struct scache *scache)
605
2020-07-08
pjp
{
606
2020-07-08
pjp
struct nsec3param np;
607
2020-07-08
pjp
u_int16_t iter;
608
2020-07-08
pjp
u_char *p = scache->payload;
609
2020-07-08
pjp
u_char *q = scache->payload;
610
2020-07-08
pjp
611
2020-07-10
pjp
612
2020-07-10
pjp
memset(&np, 0, sizeof(struct nsec3param));
613
2020-07-10
pjp
614
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
615
2020-07-08
pjp
np.algorithm = *p++;
616
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
617
2020-07-08
pjp
np.flags = *p++;
618
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 2), q, scache->rdlen, scache->end);
619
2020-07-08
pjp
iter = unpack16(p);
620
2020-07-08
pjp
np.iterations = ntohs(iter);
621
2020-07-08
pjp
p += 2;
622
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
623
2020-07-08
pjp
np.saltlen = *p++;
624
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + np.saltlen), q, scache->rdlen, scache->end);
625
2020-07-08
pjp
memcpy(&np.salt, p, np.saltlen);
626
2020-07-08
pjp
p += np.saltlen;
627
2020-07-08
pjp
628
2020-07-08
pjp
transmit_rr(scache, &np, sizeof(np));
629
2020-07-08
pjp
630
2020-07-08
pjp
return (p - scache->estart);
631
2020-07-08
pjp
}
632
2020-07-08
pjp
633
2020-07-08
pjp
634
2020-07-08
pjp
int
635
2020-07-08
pjp
cache_txt(struct scache *scache)
636
2020-07-08
pjp
{
637
2020-07-08
pjp
int i;
638
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
639
2020-07-08
pjp
u_char *p = scache->payload;
640
2020-07-08
pjp
u_char *q = p;
641
2020-07-08
pjp
642
2020-07-08
pjp
/* we won't cache txts, for now */
643
2020-07-08
pjp
return -1;
644
2020-07-08
pjp
645
2020-07-08
pjp
BOUNDS_CHECK(scache->payload, q, scache->rdlen, scache->end);
646
2020-07-08
pjp
647
2020-07-08
pjp
for (i = 0; i < rdlen; i++) {
648
2020-07-08
pjp
if (i % 256 == 0)
649
2020-07-08
pjp
continue;
650
2020-07-08
pjp
651
2020-07-08
pjp
}
652
2020-07-08
pjp
653
2020-07-08
pjp
p += i;
654
2020-07-08
pjp
655
2020-07-08
pjp
return (p - scache->estart);
656
2020-07-08
pjp
}
657
2020-07-08
pjp
658
2020-07-08
pjp
int
659
2020-07-08
pjp
cache_ns(struct scache *scache)
660
2020-07-08
pjp
{
661
2020-07-08
pjp
struct ns nsi;
662
2020-07-08
pjp
char *save;
663
2020-07-08
pjp
u_char *p = scache->payload;
664
2020-07-08
pjp
u_char *q = p;
665
2020-07-08
pjp
u_char expand[256];
666
2020-07-08
pjp
int max = sizeof(expand);
667
2020-07-08
pjp
int elen = 0;
668
2020-07-08
pjp
669
2020-07-10
pjp
memset(&nsi, 0, sizeof(struct ns));
670
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
671
2020-07-08
pjp
save = expand_compression(q, scache->estart, scache->end, (u_char *)&expand, &elen, max);
672
2020-07-08
pjp
if (save == NULL) {
673
2020-07-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
674
2020-07-08
pjp
return -1;
675
2020-07-08
pjp
} else {
676
2020-07-08
pjp
q = save;
677
2020-07-08
pjp
}
678
2020-07-08
pjp
679
2020-07-08
pjp
memcpy(&nsi.nsserver, expand, sizeof(nsi.nsserver));
680
2020-07-08
pjp
nsi.nslen = elen;
681
2020-07-08
pjp
682
2020-07-08
pjp
transmit_rr(scache, &nsi, sizeof(nsi));
683
2020-07-08
pjp
684
2020-07-08
pjp
return (q - scache->estart);
685
2020-07-08
pjp
}
686
2020-07-08
pjp
687
2020-07-08
pjp
int
688
2020-07-08
pjp
cache_cname(struct scache *scache)
689
2020-07-08
pjp
{
690
2020-07-08
pjp
return (cache_ns(scache));
691
2020-07-08
pjp
}
692
2020-07-08
pjp
693
2020-07-08
pjp
694
2020-07-08
pjp
int
695
2020-07-08
pjp
cache_aaaa(struct scache *scache)
696
2020-07-08
pjp
{
697
2020-07-08
pjp
struct aaaa aaaa;
698
2020-07-08
pjp
struct in6_addr ia;
699
2020-07-08
pjp
u_char *p = scache->payload;
700
2020-07-08
pjp
u_char *q = p;
701
2020-07-08
pjp
702
2020-07-10
pjp
memset(&aaaa, 0, sizeof(struct aaaa));
703
2020-07-10
pjp
704
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + sizeof(ia)), q, scache->rdlen, scache->end);
705
2020-07-08
pjp
unpack((char *)&ia, p, sizeof(struct in6_addr));
706
2020-07-08
pjp
p += sizeof(ia);
707
2020-07-08
pjp
708
2020-07-08
pjp
709
2020-07-08
pjp
memcpy(&aaaa.aaaa, &ia, sizeof(aaaa.aaaa));
710
2020-07-08
pjp
transmit_rr(scache, &aaaa, sizeof(aaaa));
711
2020-07-08
pjp
712
2020-07-08
pjp
return (p - scache->estart);
713
2020-07-08
pjp
}
714
2020-07-08
pjp
715
2020-07-08
pjp
int
716
2020-07-08
pjp
cache_a(struct scache *scache)
717
2020-07-08
pjp
{
718
2020-07-08
pjp
struct in_addr ia;
719
2020-07-08
pjp
u_char *p = scache->payload;
720
2020-07-08
pjp
u_char *q = p;
721
2020-07-08
pjp
struct a ar;
722
2020-07-08
pjp
723
2020-07-10
pjp
memset(&ar, 0, sizeof(ar));
724
2020-07-10
pjp
725
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + sizeof(ia)), q, scache->rdlen, scache->end);
726
2020-07-08
pjp
ar.a = unpack32(p);
727
2020-07-08
pjp
p += sizeof(ia);
728
2020-07-08
pjp
729
2020-07-08
pjp
// memcpy(&ar.a, &ia, sizeof(ar.a));
730
2020-07-08
pjp
731
2020-07-08
pjp
transmit_rr(scache, &ar, sizeof(ar));
732
2020-07-08
pjp
733
2020-07-08
pjp
return (p - scache->estart);
734
2020-07-08
pjp
}
735
2020-07-08
pjp
736
2020-07-08
pjp
int
737
2020-07-08
pjp
cache_tlsa(struct scache *scache)
738
2020-07-08
pjp
{
739
2020-07-08
pjp
struct tlsa t;
740
2020-07-08
pjp
u_char *p = scache->payload;
741
2020-07-08
pjp
u_char *q = p;
742
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
743
2020-07-08
pjp
744
2020-07-10
pjp
memset(&t, 0, sizeof(struct tlsa));
745
2020-07-10
pjp
746
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
747
2020-07-08
pjp
t.usage = *p++;
748
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
749
2020-07-08
pjp
t.selector = *p++;
750
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
751
2020-07-08
pjp
t.matchtype = *p++;
752
2020-07-08
pjp
753
2020-07-08
pjp
if (rdlen - 3 < 0)
754
2020-07-08
pjp
return -1;
755
2020-07-08
pjp
756
2020-07-08
pjp
t.datalen = (rdlen - 3);
757
2020-07-08
pjp
758
2020-07-08
pjp
if (t.datalen > sizeof(t.data))
759
2020-07-08
pjp
return -1;
760
2020-07-08
pjp
761
2020-07-08
pjp
memcpy(&t.data, p, t.datalen);
762
2020-07-08
pjp
p += t.datalen;
763
2020-07-08
pjp
764
2020-07-08
pjp
765
2020-07-08
pjp
transmit_rr(scache, &t, sizeof(t));
766
2020-07-08
pjp
767
2020-07-08
pjp
return (p - scache->estart);
768
2020-07-08
pjp
}
769
2020-07-08
pjp
770
2020-07-08
pjp
int
771
2020-07-08
pjp
cache_srv(struct scache *scache)
772
2020-07-08
pjp
{
773
2020-07-08
pjp
u_int16_t tmp16;
774
2020-07-08
pjp
struct srv s;
775
2020-07-08
pjp
char *save;
776
2020-07-08
pjp
u_char *p = scache->payload;
777
2020-07-08
pjp
u_char *q = p;
778
2020-07-08
pjp
u_char expand[256];
779
2020-07-08
pjp
int max = sizeof(expand);
780
2020-07-08
pjp
int elen = 0;
781
2020-07-08
pjp
782
2020-07-10
pjp
memset(&s, 0, sizeof(struct srv));
783
2020-07-10
pjp
784
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
785
2020-07-08
pjp
tmp16 = unpack16(q);
786
2020-07-08
pjp
s.priority = ntohs(tmp16);
787
2020-07-08
pjp
q += 2;
788
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
789
2020-07-08
pjp
tmp16 = unpack16(q);
790
2020-07-08
pjp
s.weight = ntohs(tmp16);
791
2020-07-08
pjp
q += 2;
792
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
793
2020-07-08
pjp
tmp16 = unpack16(q);
794
2020-07-08
pjp
s.port = ntohs(tmp16);
795
2020-07-08
pjp
q += 2;
796
2020-07-08
pjp
797
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
798
2020-07-08
pjp
save = expand_compression(q, scache->estart, scache->end, (u_char *)&expand, &elen, max);
799
2020-07-08
pjp
if (save == NULL) {
800
2020-07-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
801
2020-07-08
pjp
return -1;
802
2020-07-08
pjp
} else {
803
2020-07-08
pjp
q = save;
804
2020-07-08
pjp
}
805
2020-07-08
pjp
806
2020-07-08
pjp
memcpy(&s.target, expand, sizeof(s.target));
807
2020-07-08
pjp
808
2020-07-10
pjp
transmit_rr(scache, (void*)&s, sizeof(s));
809
2020-07-08
pjp
810
2020-07-08
pjp
return (q - scache->estart);
811
2020-07-08
pjp
}
812
2020-07-08
pjp
813
2020-07-08
pjp
int
814
2020-07-08
pjp
cache_naptr(struct scache *scache)
815
2020-07-08
pjp
{
816
2020-07-08
pjp
char *save;;
817
2020-07-08
pjp
u_char *p = scache->payload;
818
2020-07-08
pjp
u_char *q = p;
819
2020-07-08
pjp
u_char expand[256];
820
2020-07-08
pjp
int max = sizeof(expand);
821
2020-07-08
pjp
int elen = 0;
822
2020-07-08
pjp
int len, i;
823
2020-07-08
pjp
824
2020-07-08
pjp
/* we won't cache naptr either for now */
825
2020-07-08
pjp
return -1;
826
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
827
2020-08-08
pjp
#if 0
828
2020-07-08
pjp
tmp16 = unpack16(q);
829
2020-07-08
pjp
n.order = ntohs(tmp16);
830
2020-08-08
pjp
#endif
831
2020-07-08
pjp
q += 2;
832
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
833
2020-08-08
pjp
#if 0
834
2020-07-08
pjp
tmp16 = unpack16(q);
835
2020-07-08
pjp
n.preference = ntohs(tmp16);
836
2020-08-08
pjp
#endif
837
2020-07-08
pjp
q += 2;
838
2020-07-08
pjp
839
2020-07-08
pjp
840
2020-07-08
pjp
/* flags */
841
2020-07-08
pjp
BOUNDS_CHECK((q + 1), scache->payload, scache->rdlen, scache->end);
842
2020-07-08
pjp
len = *q;
843
2020-07-08
pjp
q++;
844
2020-07-08
pjp
845
2020-07-08
pjp
/* services */
846
2020-07-08
pjp
BOUNDS_CHECK((q + 1), scache->payload, scache->rdlen, scache->end);
847
2020-07-08
pjp
len = *q;
848
2020-07-08
pjp
q++;
849
2020-07-08
pjp
850
2020-07-08
pjp
/* regexp */
851
2020-07-08
pjp
BOUNDS_CHECK((q + 1), scache->payload, scache->rdlen, scache->end);
852
2020-07-08
pjp
len = *q;
853
2020-07-08
pjp
q++;
854
2020-07-08
pjp
855
2020-07-08
pjp
for (i = 0; i < len; i++) {
856
2020-07-08
pjp
BOUNDS_CHECK((q + 1), scache->payload, scache->rdlen, scache->end);
857
2020-07-08
pjp
}
858
2020-07-08
pjp
859
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
860
2020-07-08
pjp
save = expand_compression(q, scache->estart, scache->end, (u_char *)&expand, &elen, max);
861
2020-07-08
pjp
if (save == NULL) {
862
2020-07-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
863
2020-07-08
pjp
return -1;
864
2020-07-08
pjp
} else {
865
2020-07-08
pjp
q = save;
866
2020-07-08
pjp
}
867
2020-07-08
pjp
868
2020-07-15
pjp
return (q - scache->estart);
869
2020-07-15
pjp
}
870
2020-07-15
pjp
871
2020-07-15
pjp
int
872
2020-07-15
pjp
cache_generic(struct scache *scache)
873
2020-07-15
pjp
{
874
2020-07-15
pjp
u_char *p = scache->payload;
875
2020-07-15
pjp
u_char *q = p;
876
2020-07-15
pjp
877
2020-07-15
pjp
switch (scache->rrtype) {
878
2020-07-15
pjp
case 18: /* AFSDB */ case 42: /* APL */ case 257: /* CAA */
879
2020-07-15
pjp
case 60: /* CDNSKEY */ case 59: /* CDS */ case 37: /* CERT */
880
2020-07-15
pjp
case 62: /* CSYNC */ case 49: /* DHCID */ case 39: /* DNAME */
881
2020-07-15
pjp
case 108: /* EUI48 */ case 109: /* EUI64 */ case 13: /* HINFO */
882
2020-07-15
pjp
case 55: /* HIP */ case 45: /* IPSECKEY */ case 25: /* KEY */
883
2020-07-15
pjp
case 36: /* KX */ case 29: /* LOC */ case 61: /* OPENPGPKEY */
884
2020-07-15
pjp
case 17: /* RP */ case 24: /* SIG */ case 53: /* SMIMEA */
885
2020-07-15
pjp
case 249: /* TKEY */ case 256: /* URI */
886
2020-07-15
pjp
break;
887
2020-07-15
pjp
default:
888
2020-07-15
pjp
/* we don't cache unsupported types */
889
2020-07-15
pjp
return -1;
890
2020-07-15
pjp
}
891
2020-07-15
pjp
892
2020-07-15
pjp
transmit_rr(scache, (void*)scache->payload, scache->rdlen);
893
2020-07-15
pjp
894
2020-07-15
pjp
q += scache->rdlen;
895
2020-07-08
pjp
return (q - scache->estart);
896
2020-07-08
pjp
}
repomaster@centroid.eu