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