Blame
Date:
Sat Aug 1 09:01:52 2020 UTC
Message:
move extended RCODE's out of the RCODE section those are only 0x00 through 0x0F make a section that shows extended RCODE's that are added to a EDNS0 tag.
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-07-20
pjp
* $Id: cache.c,v 1.10 2020/07/20 08:41:31 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-07-08
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-07-20
pjp
if (rrtype == DNS_TYPE_ANY || rrtype == DNS_TYPE_RRSIG) {
276
2020-07-08
pjp
return -1;
277
2020-07-08
pjp
}
278
2020-07-08
pjp
279
2020-07-08
pjp
pb += 4; /* skip type and class */
280
2020-07-08
pjp
281
2020-07-08
pjp
for (x = 0; x < ntohs(dh->answer); x++) {
282
2020-07-10
pjp
printf("%d out of %d\n", x, ntohs(dh->answer));
283
2020-07-08
pjp
elen = 0;
284
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
285
2020-07-08
pjp
pb = expand_compression(pb, estart, end, (u_char *)&expand, &elen, sizeof(expand));
286
2020-07-08
pjp
if (pb == NULL) {
287
2020-07-08
pjp
dolog(LOG_INFO, "expand_compression() failed in cacheit 3");
288
2020-07-08
pjp
return (-1);
289
2020-07-08
pjp
}
290
2020-07-08
pjp
291
2020-07-08
pjp
i = (pb - estart);
292
2020-07-08
pjp
293
2020-07-08
pjp
if (i > rlen) {
294
2020-07-08
pjp
dolog(LOG_INFO, "expand_compression() failed in cacheit 4");
295
2020-07-08
pjp
return (-1);
296
2020-07-08
pjp
}
297
2020-07-08
pjp
298
2020-07-08
pjp
/* bounds check the rest of the RR to the RDATA */
299
2020-07-08
pjp
if (pb + 10 >= end) {
300
2020-07-08
pjp
dolog(LOG_INFO, "malformed reply, drop\n");
301
2020-07-08
pjp
return -1;
302
2020-07-08
pjp
}
303
2020-07-08
pjp
304
2020-07-08
pjp
rrtype = ntohs(unpack16(pb));
305
2020-07-08
pjp
/* class in here not parsed */
306
2020-07-08
pjp
rrttl = ntohl(unpack32(pb + 4));
307
2020-07-08
pjp
rdlen = ntohs(unpack16(pb + 8));
308
2020-07-08
pjp
309
2020-07-08
pjp
pb += 10; /* skip answerd */
310
2020-07-08
pjp
311
2020-07-18
pjp
scache = build_cache(pb, estart, end, rdlen, expand, elen, rrttl, rrtype, imsgbuf, bimsgbuf, cfg, authentic);
312
2020-07-08
pjp
313
2020-07-08
pjp
for (cr = supported_cache; cr->rrtype != 0; cr++) {
314
2020-07-08
pjp
if (rrtype == cr->rrtype) {
315
2020-07-08
pjp
if ((*cr->cacheit)(scache) < 0) {
316
2020-07-08
pjp
dolog(LOG_INFO, "error parsing cache with rrtype %d\n", rrtype);
317
2020-07-08
pjp
}
318
2020-07-08
pjp
319
2020-07-08
pjp
break;
320
2020-07-08
pjp
}
321
2020-07-08
pjp
}
322
2020-07-15
pjp
if (cr->rrtype == 0) {
323
2020-07-15
pjp
cache_generic(scache);
324
2020-07-15
pjp
}
325
2020-07-08
pjp
326
2020-07-08
pjp
pb += rdlen;
327
2020-07-08
pjp
328
2020-07-08
pjp
} /* for(x ... */
329
2020-07-08
pjp
330
2020-07-10
pjp
i = 42;
331
2020-07-10
pjp
if (imsg_compose(bimsgbuf, IMSG_RR_ATTACHED, 0, 0, -1, &i, sizeof(int)) != 1) {
332
2020-07-10
pjp
dolog(LOG_INFO, "imsg_compose failed: %s\n", strerror(errno));
333
2020-07-10
pjp
}
334
2020-07-10
pjp
335
2020-07-10
pjp
if (msgbuf_write(&bimsgbuf->w) == -1)
336
2020-07-10
pjp
dolog(LOG_ERR, "msgbuf_write: %s\n", strerror(errno));
337
2020-07-08
pjp
338
2020-07-08
pjp
return (0);
339
2020-07-08
pjp
}
340
2020-07-08
pjp
341
2020-07-08
pjp
int
342
2020-07-08
pjp
cache_rrsig(struct scache *scache)
343
2020-07-08
pjp
{
344
2020-07-08
pjp
struct rrsig rs;
345
2020-07-08
pjp
char *save;
346
2020-07-08
pjp
u_char *q = scache->payload;
347
2020-07-08
pjp
u_char expand[256];
348
2020-07-08
pjp
int max = sizeof(expand);
349
2020-07-08
pjp
int elen = 0;
350
2020-07-08
pjp
u_int16_t tmp;
351
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
352
2020-07-08
pjp
u_int32_t tmp4;
353
2020-07-08
pjp
u_char *p = q;
354
2020-07-08
pjp
355
2020-07-10
pjp
memset(&rs, 0, sizeof(struct rrsig));
356
2020-07-10
pjp
357
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
358
2020-07-08
pjp
tmp = unpack16(q);
359
2020-07-08
pjp
rs.type_covered = ntohs(tmp);
360
2020-07-08
pjp
q += 2;
361
2020-07-08
pjp
BOUNDS_CHECK((q + 1), scache->payload, scache->rdlen, scache->end);
362
2020-07-08
pjp
rs.algorithm = *q++;
363
2020-07-08
pjp
BOUNDS_CHECK((q + 1), scache->payload, scache->rdlen, scache->end);
364
2020-07-08
pjp
rs.labels = *q++;
365
2020-07-08
pjp
BOUNDS_CHECK((q + 4), scache->payload, scache->rdlen, scache->end);
366
2020-07-08
pjp
tmp4 = unpack32(q);
367
2020-07-08
pjp
rs.original_ttl = ntohl(tmp4);
368
2020-07-08
pjp
q += 4;
369
2020-07-08
pjp
BOUNDS_CHECK((q + 4), scache->payload, scache->rdlen, scache->end);
370
2020-07-08
pjp
tmp4 = unpack32(q);
371
2020-07-08
pjp
rs.signature_expiration = ntohl(tmp4);
372
2020-07-08
pjp
q += 4;
373
2020-07-08
pjp
BOUNDS_CHECK((q + 4), scache->payload, scache->rdlen, scache->end);
374
2020-07-08
pjp
tmp4 = unpack32(q);
375
2020-07-08
pjp
rs.signature_inception = ntohl(tmp4);
376
2020-07-08
pjp
q += 4;
377
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
378
2020-07-08
pjp
tmp = unpack16(q);
379
2020-07-08
pjp
rs.key_tag = ntohs(tmp);
380
2020-07-08
pjp
q += 2;
381
2020-07-08
pjp
382
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
383
2020-07-08
pjp
save = expand_compression(q, scache->estart, scache->end, (u_char *)&expand, &elen, max);
384
2020-07-08
pjp
if (save == NULL) {
385
2020-07-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
386
2020-07-08
pjp
return -1;
387
2020-07-08
pjp
} else {
388
2020-07-08
pjp
q = save;
389
2020-07-08
pjp
}
390
2020-07-08
pjp
391
2020-07-08
pjp
memcpy(&rs.signers_name, expand, elen);
392
2020-07-08
pjp
rs.signame_len = elen;
393
2020-07-08
pjp
394
2020-07-08
pjp
rs.signature_len = (rdlen - (q - p));
395
2020-07-08
pjp
396
2020-07-08
pjp
if (rs.signature_len > sizeof(rs.signature))
397
2020-07-08
pjp
return -1;
398
2020-07-08
pjp
memcpy(&rs.signature, q, rs.signature_len);
399
2020-07-08
pjp
q += rs.signature_len;
400
2020-07-08
pjp
401
2020-07-10
pjp
transmit_rr(scache, (void *)&rs, sizeof(rs));
402
2020-07-08
pjp
403
2020-07-08
pjp
return (q - scache->estart);
404
2020-07-08
pjp
}
405
2020-07-08
pjp
406
2020-07-08
pjp
int
407
2020-07-08
pjp
cache_ds(struct scache *scache)
408
2020-07-08
pjp
{
409
2020-07-08
pjp
struct ds d;
410
2020-07-08
pjp
u_int16_t tmpshort;
411
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
412
2020-07-08
pjp
u_char *p = scache->payload;
413
2020-07-08
pjp
u_char *q = p;
414
2020-07-08
pjp
415
2020-07-10
pjp
memset(&d, 0, sizeof(struct ds));
416
2020-07-10
pjp
417
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 2), q, scache->rdlen, scache->end);
418
2020-07-08
pjp
tmpshort = unpack16(p);
419
2020-07-08
pjp
d.key_tag = ntohs(tmpshort);
420
2020-07-08
pjp
p += 2;
421
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
422
2020-07-08
pjp
d.algorithm = *p++;
423
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
424
2020-07-08
pjp
d.digest_type = *p++;
425
2020-07-08
pjp
426
2020-07-08
pjp
if ((rdlen - 4) < 0)
427
2020-07-08
pjp
return -1;
428
2020-07-08
pjp
d.digestlen = (rdlen - 4);
429
2020-07-08
pjp
if (d.digestlen > sizeof(d.digest))
430
2020-07-08
pjp
return -1;
431
2020-07-08
pjp
memcpy(&d.digest, p, d.digestlen);
432
2020-07-08
pjp
p += d.digestlen;
433
2020-07-08
pjp
434
2020-07-08
pjp
435
2020-07-08
pjp
transmit_rr(scache, &d, sizeof(d));
436
2020-07-08
pjp
437
2020-07-08
pjp
return (p - scache->estart);
438
2020-07-08
pjp
}
439
2020-07-08
pjp
440
2020-07-08
pjp
int
441
2020-07-08
pjp
cache_sshfp(struct scache *scache)
442
2020-07-08
pjp
{
443
2020-07-08
pjp
struct sshfp s;
444
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
445
2020-07-08
pjp
u_char *p = scache->payload;
446
2020-07-08
pjp
u_char *q = p;
447
2020-07-08
pjp
448
2020-07-10
pjp
memset(&s, 0, sizeof(struct sshfp));
449
2020-07-10
pjp
450
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
451
2020-07-08
pjp
s.algorithm = *p++;
452
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
453
2020-07-08
pjp
s.fptype = *p++;
454
2020-07-08
pjp
455
2020-07-08
pjp
if (rdlen - 2 < 0)
456
2020-07-08
pjp
return -1;
457
2020-07-08
pjp
458
2020-07-08
pjp
s.fplen = (rdlen - 2);
459
2020-07-08
pjp
if (s.fplen > sizeof(s.fingerprint))
460
2020-07-08
pjp
return -1;
461
2020-07-08
pjp
462
2020-07-08
pjp
memcpy(&s.fingerprint, p, s.fplen);
463
2020-07-08
pjp
p += s.fplen;
464
2020-07-08
pjp
465
2020-07-08
pjp
transmit_rr(scache, &s, sizeof(s));
466
2020-07-08
pjp
467
2020-07-08
pjp
return (p - scache->estart);
468
2020-07-08
pjp
}
469
2020-07-08
pjp
470
2020-07-08
pjp
int
471
2020-07-08
pjp
cache_dnskey(struct scache *scache)
472
2020-07-08
pjp
{
473
2020-07-08
pjp
struct dnskey dk;
474
2020-07-08
pjp
u_int16_t tmpshort;
475
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
476
2020-07-08
pjp
u_char *p = scache->payload;
477
2020-07-08
pjp
u_char *q = p;
478
2020-07-08
pjp
479
2020-07-10
pjp
480
2020-07-10
pjp
memset(&dk, 0, sizeof(struct dnskey));
481
2020-07-10
pjp
482
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 2), q, scache->rdlen, scache->end);
483
2020-07-08
pjp
tmpshort = unpack16(p);
484
2020-07-08
pjp
dk.flags = ntohs(tmpshort);
485
2020-07-08
pjp
p += 2;
486
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
487
2020-07-08
pjp
dk.protocol = *p++;
488
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
489
2020-07-08
pjp
dk.algorithm = *p++;
490
2020-07-08
pjp
491
2020-07-08
pjp
if (rdlen - 4 < 0)
492
2020-07-08
pjp
return -1;
493
2020-07-08
pjp
dk.publickey_len = (rdlen - 4);
494
2020-07-08
pjp
if (dk.publickey_len > sizeof(dk.public_key))
495
2020-07-08
pjp
return -1;
496
2020-07-08
pjp
497
2020-07-08
pjp
memcpy(&dk.public_key, p, dk.publickey_len);
498
2020-07-08
pjp
p += dk.publickey_len;
499
2020-07-08
pjp
500
2020-07-08
pjp
transmit_rr(scache, &dk, sizeof(dk));
501
2020-07-08
pjp
502
2020-07-08
pjp
return (p - scache->estart);
503
2020-07-08
pjp
}
504
2020-07-08
pjp
505
2020-07-08
pjp
506
2020-07-08
pjp
int
507
2020-07-08
pjp
cache_mx(struct scache *scache)
508
2020-07-08
pjp
{
509
2020-07-08
pjp
struct smx mx;
510
2020-07-08
pjp
u_int16_t mxpriority;
511
2020-07-08
pjp
char *save;
512
2020-07-08
pjp
u_char *p = scache->payload;
513
2020-07-08
pjp
u_char *q = p;
514
2020-07-08
pjp
u_char expand[256];
515
2020-07-08
pjp
int max = sizeof(expand);
516
2020-07-08
pjp
int elen = 0;
517
2020-07-08
pjp
518
2020-07-10
pjp
memset(&mx, 0, sizeof(struct smx));
519
2020-07-10
pjp
520
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
521
2020-07-08
pjp
mxpriority = unpack16(q);
522
2020-07-08
pjp
523
2020-07-08
pjp
q += 2;
524
2020-07-08
pjp
525
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
526
2020-07-08
pjp
save = expand_compression(q, scache->estart, scache->end, (u_char *)&expand, &elen, max);
527
2020-07-08
pjp
if (save == NULL) {
528
2020-07-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
529
2020-07-08
pjp
return -1;
530
2020-07-08
pjp
} else {
531
2020-07-08
pjp
q = save;
532
2020-07-08
pjp
}
533
2020-07-08
pjp
534
2020-07-08
pjp
memcpy(&mx.exchange, expand, sizeof(mx.exchange));
535
2020-07-08
pjp
mx.exchangelen = elen;
536
2020-07-08
pjp
mx.preference = mxpriority;
537
2020-07-08
pjp
538
2020-07-08
pjp
transmit_rr(scache, &mx, sizeof(mx));
539
2020-07-08
pjp
540
2020-07-08
pjp
return (q - scache->estart);
541
2020-07-08
pjp
}
542
2020-07-08
pjp
543
2020-07-08
pjp
int
544
2020-07-08
pjp
cache_ptr(struct scache *scache)
545
2020-07-08
pjp
{
546
2020-07-08
pjp
return (cache_ns(scache));
547
2020-07-08
pjp
}
548
2020-07-08
pjp
549
2020-07-08
pjp
int
550
2020-07-08
pjp
cache_nsec3(struct scache *scache)
551
2020-07-08
pjp
{
552
2020-07-08
pjp
struct nsec3 n;
553
2020-07-08
pjp
u_char *p = scache->payload;
554
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
555
2020-07-08
pjp
u_int16_t iter;
556
2020-07-08
pjp
u_char *brr = scache->payload; /* begin of rd record :-) */
557
2020-07-08
pjp
558
2020-07-10
pjp
memset(&n, 0, sizeof(struct nsec3));
559
2020-07-10
pjp
560
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), brr, scache->rdlen, scache->end);
561
2020-07-08
pjp
n.algorithm = *p++;
562
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), brr, scache->rdlen, scache->end);
563
2020-07-08
pjp
n.flags = *p++;
564
2020-07-08
pjp
565
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 2), brr, scache->rdlen, scache->end);
566
2020-07-08
pjp
iter = unpack16(p);
567
2020-07-08
pjp
n.iterations = ntohs(iter);
568
2020-07-08
pjp
p += 2;
569
2020-07-08
pjp
570
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), brr, scache->rdlen, scache->end);
571
2020-07-08
pjp
n.saltlen = *p++;
572
2020-07-08
pjp
memcpy(&n.salt, p, n.saltlen);
573
2020-07-08
pjp
p += n.saltlen;
574
2020-07-08
pjp
575
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), brr, scache->rdlen, scache->end);
576
2020-07-08
pjp
n.nextlen = *p++;
577
2020-07-08
pjp
memcpy(&n.next, p, n.nextlen);
578
2020-07-08
pjp
p += n.nextlen;
579
2020-07-08
pjp
580
2020-07-08
pjp
581
2020-07-08
pjp
if (((rdlen - (p - brr)) + 1) < 0)
582
2020-07-08
pjp
return -1;
583
2020-07-08
pjp
584
2020-07-08
pjp
/* XXX */
585
2020-07-08
pjp
n.bitmap_len = (rdlen - (p - brr));
586
2020-07-08
pjp
if (n.bitmap_len > sizeof(n.bitmap))
587
2020-07-08
pjp
return -1;
588
2020-07-08
pjp
589
2020-07-08
pjp
memcpy(&n.bitmap, p, n.bitmap_len);
590
2020-07-08
pjp
p += n.bitmap_len;
591
2020-07-08
pjp
592
2020-07-08
pjp
transmit_rr(scache, &n, sizeof(n));
593
2020-07-08
pjp
594
2020-07-08
pjp
return (p - scache->estart);
595
2020-07-08
pjp
}
596
2020-07-08
pjp
597
2020-07-08
pjp
int
598
2020-07-08
pjp
cache_nsec3param(struct scache *scache)
599
2020-07-08
pjp
{
600
2020-07-08
pjp
struct nsec3param np;
601
2020-07-08
pjp
u_int16_t iter;
602
2020-07-08
pjp
u_char *p = scache->payload;
603
2020-07-08
pjp
u_char *q = scache->payload;
604
2020-07-08
pjp
605
2020-07-10
pjp
606
2020-07-10
pjp
memset(&np, 0, sizeof(struct nsec3param));
607
2020-07-10
pjp
608
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
609
2020-07-08
pjp
np.algorithm = *p++;
610
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
611
2020-07-08
pjp
np.flags = *p++;
612
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 2), q, scache->rdlen, scache->end);
613
2020-07-08
pjp
iter = unpack16(p);
614
2020-07-08
pjp
np.iterations = ntohs(iter);
615
2020-07-08
pjp
p += 2;
616
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
617
2020-07-08
pjp
np.saltlen = *p++;
618
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + np.saltlen), q, scache->rdlen, scache->end);
619
2020-07-08
pjp
memcpy(&np.salt, p, np.saltlen);
620
2020-07-08
pjp
p += np.saltlen;
621
2020-07-08
pjp
622
2020-07-08
pjp
transmit_rr(scache, &np, sizeof(np));
623
2020-07-08
pjp
624
2020-07-08
pjp
return (p - scache->estart);
625
2020-07-08
pjp
}
626
2020-07-08
pjp
627
2020-07-08
pjp
628
2020-07-08
pjp
int
629
2020-07-08
pjp
cache_txt(struct scache *scache)
630
2020-07-08
pjp
{
631
2020-07-08
pjp
u_int8_t len;
632
2020-07-08
pjp
int i;
633
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
634
2020-07-08
pjp
u_char *p = scache->payload;
635
2020-07-08
pjp
u_char *q = p;
636
2020-07-08
pjp
637
2020-07-08
pjp
/* we won't cache txts, for now */
638
2020-07-08
pjp
return -1;
639
2020-07-08
pjp
640
2020-07-08
pjp
BOUNDS_CHECK(scache->payload, q, scache->rdlen, scache->end);
641
2020-07-08
pjp
len = rdlen;
642
2020-07-08
pjp
643
2020-07-08
pjp
for (i = 0; i < rdlen; i++) {
644
2020-07-08
pjp
if (i % 256 == 0)
645
2020-07-08
pjp
continue;
646
2020-07-08
pjp
647
2020-07-08
pjp
}
648
2020-07-08
pjp
649
2020-07-08
pjp
p += i;
650
2020-07-08
pjp
651
2020-07-08
pjp
return (p - scache->estart);
652
2020-07-08
pjp
}
653
2020-07-08
pjp
654
2020-07-08
pjp
int
655
2020-07-08
pjp
cache_ns(struct scache *scache)
656
2020-07-08
pjp
{
657
2020-07-08
pjp
struct ns nsi;
658
2020-07-08
pjp
char *save;
659
2020-07-08
pjp
u_char *p = scache->payload;
660
2020-07-08
pjp
u_char *q = p;
661
2020-07-08
pjp
u_char expand[256];
662
2020-07-08
pjp
int max = sizeof(expand);
663
2020-07-08
pjp
int elen = 0;
664
2020-07-08
pjp
665
2020-07-10
pjp
memset(&nsi, 0, sizeof(struct ns));
666
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
667
2020-07-08
pjp
save = expand_compression(q, scache->estart, scache->end, (u_char *)&expand, &elen, max);
668
2020-07-08
pjp
if (save == NULL) {
669
2020-07-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
670
2020-07-08
pjp
return -1;
671
2020-07-08
pjp
} else {
672
2020-07-08
pjp
q = save;
673
2020-07-08
pjp
}
674
2020-07-08
pjp
675
2020-07-08
pjp
memcpy(&nsi.nsserver, expand, sizeof(nsi.nsserver));
676
2020-07-08
pjp
nsi.nslen = elen;
677
2020-07-08
pjp
678
2020-07-08
pjp
transmit_rr(scache, &nsi, sizeof(nsi));
679
2020-07-08
pjp
680
2020-07-08
pjp
return (q - scache->estart);
681
2020-07-08
pjp
}
682
2020-07-08
pjp
683
2020-07-08
pjp
int
684
2020-07-08
pjp
cache_cname(struct scache *scache)
685
2020-07-08
pjp
{
686
2020-07-08
pjp
return (cache_ns(scache));
687
2020-07-08
pjp
}
688
2020-07-08
pjp
689
2020-07-08
pjp
690
2020-07-08
pjp
int
691
2020-07-08
pjp
cache_aaaa(struct scache *scache)
692
2020-07-08
pjp
{
693
2020-07-08
pjp
struct aaaa aaaa;
694
2020-07-08
pjp
struct in6_addr ia;
695
2020-07-08
pjp
u_char *p = scache->payload;
696
2020-07-08
pjp
u_char *q = p;
697
2020-07-08
pjp
698
2020-07-10
pjp
memset(&aaaa, 0, sizeof(struct aaaa));
699
2020-07-10
pjp
700
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + sizeof(ia)), q, scache->rdlen, scache->end);
701
2020-07-08
pjp
unpack((char *)&ia, p, sizeof(struct in6_addr));
702
2020-07-08
pjp
p += sizeof(ia);
703
2020-07-08
pjp
704
2020-07-08
pjp
705
2020-07-08
pjp
memcpy(&aaaa.aaaa, &ia, sizeof(aaaa.aaaa));
706
2020-07-08
pjp
transmit_rr(scache, &aaaa, sizeof(aaaa));
707
2020-07-08
pjp
708
2020-07-08
pjp
return (p - scache->estart);
709
2020-07-08
pjp
}
710
2020-07-08
pjp
711
2020-07-08
pjp
int
712
2020-07-08
pjp
cache_a(struct scache *scache)
713
2020-07-08
pjp
{
714
2020-07-08
pjp
struct in_addr ia;
715
2020-07-08
pjp
u_char *p = scache->payload;
716
2020-07-08
pjp
u_char *q = p;
717
2020-07-08
pjp
struct a ar;
718
2020-07-08
pjp
719
2020-07-10
pjp
memset(&ar, 0, sizeof(ar));
720
2020-07-10
pjp
721
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + sizeof(ia)), q, scache->rdlen, scache->end);
722
2020-07-08
pjp
ar.a = unpack32(p);
723
2020-07-08
pjp
p += sizeof(ia);
724
2020-07-08
pjp
725
2020-07-08
pjp
// memcpy(&ar.a, &ia, sizeof(ar.a));
726
2020-07-08
pjp
727
2020-07-08
pjp
transmit_rr(scache, &ar, sizeof(ar));
728
2020-07-08
pjp
729
2020-07-08
pjp
return (p - scache->estart);
730
2020-07-08
pjp
}
731
2020-07-08
pjp
732
2020-07-08
pjp
int
733
2020-07-08
pjp
cache_tlsa(struct scache *scache)
734
2020-07-08
pjp
{
735
2020-07-08
pjp
struct tlsa t;
736
2020-07-08
pjp
u_char *p = scache->payload;
737
2020-07-08
pjp
u_char *q = p;
738
2020-07-08
pjp
uint16_t rdlen = scache->rdlen;
739
2020-07-08
pjp
740
2020-07-10
pjp
memset(&t, 0, sizeof(struct tlsa));
741
2020-07-10
pjp
742
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
743
2020-07-08
pjp
t.usage = *p++;
744
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
745
2020-07-08
pjp
t.selector = *p++;
746
2020-07-08
pjp
BOUNDS_CHECK((scache->payload + 1), q, scache->rdlen, scache->end);
747
2020-07-08
pjp
t.matchtype = *p++;
748
2020-07-08
pjp
749
2020-07-08
pjp
if (rdlen - 3 < 0)
750
2020-07-08
pjp
return -1;
751
2020-07-08
pjp
752
2020-07-08
pjp
t.datalen = (rdlen - 3);
753
2020-07-08
pjp
754
2020-07-08
pjp
if (t.datalen > sizeof(t.data))
755
2020-07-08
pjp
return -1;
756
2020-07-08
pjp
757
2020-07-08
pjp
memcpy(&t.data, p, t.datalen);
758
2020-07-08
pjp
p += t.datalen;
759
2020-07-08
pjp
760
2020-07-08
pjp
761
2020-07-08
pjp
transmit_rr(scache, &t, sizeof(t));
762
2020-07-08
pjp
763
2020-07-08
pjp
return (p - scache->estart);
764
2020-07-08
pjp
}
765
2020-07-08
pjp
766
2020-07-08
pjp
int
767
2020-07-08
pjp
cache_srv(struct scache *scache)
768
2020-07-08
pjp
{
769
2020-07-08
pjp
u_int16_t tmp16;
770
2020-07-08
pjp
struct srv s;
771
2020-07-08
pjp
char *save;
772
2020-07-08
pjp
u_char *p = scache->payload;
773
2020-07-08
pjp
u_char *q = p;
774
2020-07-08
pjp
u_char expand[256];
775
2020-07-08
pjp
int max = sizeof(expand);
776
2020-07-08
pjp
int elen = 0;
777
2020-07-08
pjp
778
2020-07-10
pjp
memset(&s, 0, sizeof(struct srv));
779
2020-07-10
pjp
780
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
781
2020-07-08
pjp
tmp16 = unpack16(q);
782
2020-07-08
pjp
s.priority = ntohs(tmp16);
783
2020-07-08
pjp
q += 2;
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.weight = 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.port = ntohs(tmp16);
791
2020-07-08
pjp
q += 2;
792
2020-07-08
pjp
793
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
794
2020-07-08
pjp
save = expand_compression(q, scache->estart, scache->end, (u_char *)&expand, &elen, max);
795
2020-07-08
pjp
if (save == NULL) {
796
2020-07-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
797
2020-07-08
pjp
return -1;
798
2020-07-08
pjp
} else {
799
2020-07-08
pjp
q = save;
800
2020-07-08
pjp
}
801
2020-07-08
pjp
802
2020-07-08
pjp
memcpy(&s.target, expand, sizeof(s.target));
803
2020-07-08
pjp
804
2020-07-10
pjp
transmit_rr(scache, (void*)&s, sizeof(s));
805
2020-07-08
pjp
806
2020-07-08
pjp
return (q - scache->estart);
807
2020-07-08
pjp
}
808
2020-07-08
pjp
809
2020-07-08
pjp
int
810
2020-07-08
pjp
cache_naptr(struct scache *scache)
811
2020-07-08
pjp
{
812
2020-07-08
pjp
u_int16_t tmp16;
813
2020-07-08
pjp
struct naptr n;
814
2020-07-08
pjp
char *save;;
815
2020-07-08
pjp
u_char *p = scache->payload;
816
2020-07-08
pjp
u_char *q = p;
817
2020-07-08
pjp
u_char expand[256];
818
2020-07-08
pjp
int max = sizeof(expand);
819
2020-07-08
pjp
int elen = 0;
820
2020-07-08
pjp
int len, i;
821
2020-07-08
pjp
822
2020-07-08
pjp
/* we won't cache naptr either for now */
823
2020-07-08
pjp
return -1;
824
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
825
2020-07-08
pjp
tmp16 = unpack16(q);
826
2020-07-08
pjp
n.order = ntohs(tmp16);
827
2020-07-08
pjp
q += 2;
828
2020-07-08
pjp
BOUNDS_CHECK((q + 2), scache->payload, scache->rdlen, scache->end);
829
2020-07-08
pjp
tmp16 = unpack16(q);
830
2020-07-08
pjp
n.preference = ntohs(tmp16);
831
2020-07-08
pjp
q += 2;
832
2020-07-08
pjp
833
2020-07-08
pjp
834
2020-07-08
pjp
/* flags */
835
2020-07-08
pjp
BOUNDS_CHECK((q + 1), scache->payload, scache->rdlen, scache->end);
836
2020-07-08
pjp
len = *q;
837
2020-07-08
pjp
q++;
838
2020-07-08
pjp
839
2020-07-08
pjp
/* services */
840
2020-07-08
pjp
BOUNDS_CHECK((q + 1), scache->payload, scache->rdlen, scache->end);
841
2020-07-08
pjp
len = *q;
842
2020-07-08
pjp
q++;
843
2020-07-08
pjp
844
2020-07-08
pjp
/* regexp */
845
2020-07-08
pjp
BOUNDS_CHECK((q + 1), scache->payload, scache->rdlen, scache->end);
846
2020-07-08
pjp
len = *q;
847
2020-07-08
pjp
q++;
848
2020-07-08
pjp
849
2020-07-08
pjp
for (i = 0; i < len; i++) {
850
2020-07-08
pjp
BOUNDS_CHECK((q + 1), scache->payload, scache->rdlen, scache->end);
851
2020-07-08
pjp
}
852
2020-07-08
pjp
853
2020-07-08
pjp
memset(&expand, 0, sizeof(expand));
854
2020-07-08
pjp
save = expand_compression(q, scache->estart, scache->end, (u_char *)&expand, &elen, max);
855
2020-07-08
pjp
if (save == NULL) {
856
2020-07-08
pjp
fprintf(stderr, "expanding compression failure 2\n");
857
2020-07-08
pjp
return -1;
858
2020-07-08
pjp
} else {
859
2020-07-08
pjp
q = save;
860
2020-07-08
pjp
}
861
2020-07-08
pjp
862
2020-07-15
pjp
return (q - scache->estart);
863
2020-07-15
pjp
}
864
2020-07-15
pjp
865
2020-07-15
pjp
int
866
2020-07-15
pjp
cache_generic(struct scache *scache)
867
2020-07-15
pjp
{
868
2020-07-15
pjp
u_char *p = scache->payload;
869
2020-07-15
pjp
u_char *q = p;
870
2020-07-15
pjp
871
2020-07-15
pjp
switch (scache->rrtype) {
872
2020-07-15
pjp
case 18: /* AFSDB */ case 42: /* APL */ case 257: /* CAA */
873
2020-07-15
pjp
case 60: /* CDNSKEY */ case 59: /* CDS */ case 37: /* CERT */
874
2020-07-15
pjp
case 62: /* CSYNC */ case 49: /* DHCID */ case 39: /* DNAME */
875
2020-07-15
pjp
case 108: /* EUI48 */ case 109: /* EUI64 */ case 13: /* HINFO */
876
2020-07-15
pjp
case 55: /* HIP */ case 45: /* IPSECKEY */ case 25: /* KEY */
877
2020-07-15
pjp
case 36: /* KX */ case 29: /* LOC */ case 61: /* OPENPGPKEY */
878
2020-07-15
pjp
case 17: /* RP */ case 24: /* SIG */ case 53: /* SMIMEA */
879
2020-07-15
pjp
case 249: /* TKEY */ case 256: /* URI */
880
2020-07-15
pjp
break;
881
2020-07-15
pjp
default:
882
2020-07-15
pjp
/* we don't cache unsupported types */
883
2020-07-15
pjp
return -1;
884
2020-07-15
pjp
}
885
2020-07-15
pjp
886
2020-07-15
pjp
transmit_rr(scache, (void*)scache->payload, scache->rdlen);
887
2020-07-15
pjp
888
2020-07-15
pjp
q += scache->rdlen;
889
2020-07-08
pjp
return (q - scache->estart);
890
2020-07-08
pjp
}
repomaster@centroid.eu