1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
|
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: peer.c,v 1.3 2019/12/17 01:46:32 sthen Exp $ */
/*! \file */
#include <config.h>
#include <isc/mem.h>
#include <isc/string.h>
#include <isc/util.h>
#include <isc/sockaddr.h>
#include <dns/bit.h>
#include <dns/fixedname.h>
#include <dns/name.h>
#include <dns/peer.h>
/*%
* Bit positions in the dns_peer_t structure flags field
*/
#define BOGUS_BIT 0
#define SERVER_TRANSFER_FORMAT_BIT 1
#define TRANSFERS_BIT 2
#define PROVIDE_IXFR_BIT 3
#define REQUEST_IXFR_BIT 4
#define SUPPORT_EDNS_BIT 5
#define SERVER_UDPSIZE_BIT 6
#define SERVER_MAXUDP_BIT 7
#define REQUEST_NSID_BIT 8
#define REQUEST_SIT_BIT 9
#define NOTIFY_DSCP_BIT 10
#define TRANSFER_DSCP_BIT 11
#define QUERY_DSCP_BIT 12
#define FORCE_TCP_BIT 13
static void
peerlist_delete(dns_peerlist_t **list);
static void
peer_delete(dns_peer_t **peer);
isc_result_t
dns_peerlist_new(isc_mem_t *mem, dns_peerlist_t **list) {
dns_peerlist_t *l;
REQUIRE(list != NULL);
l = isc_mem_get(mem, sizeof(*l));
if (l == NULL)
return (ISC_R_NOMEMORY);
ISC_LIST_INIT(l->elements);
l->mem = mem;
l->refs = 1;
l->magic = DNS_PEERLIST_MAGIC;
*list = l;
return (ISC_R_SUCCESS);
}
void
dns_peerlist_attach(dns_peerlist_t *source, dns_peerlist_t **target) {
REQUIRE(DNS_PEERLIST_VALID(source));
REQUIRE(target != NULL);
REQUIRE(*target == NULL);
source->refs++;
ENSURE(source->refs != 0xffffffffU);
*target = source;
}
void
dns_peerlist_detach(dns_peerlist_t **list) {
dns_peerlist_t *plist;
REQUIRE(list != NULL);
REQUIRE(*list != NULL);
REQUIRE(DNS_PEERLIST_VALID(*list));
plist = *list;
*list = NULL;
REQUIRE(plist->refs > 0);
plist->refs--;
if (plist->refs == 0)
peerlist_delete(&plist);
}
static void
peerlist_delete(dns_peerlist_t **list) {
dns_peerlist_t *l;
dns_peer_t *server, *stmp;
REQUIRE(list != NULL);
REQUIRE(DNS_PEERLIST_VALID(*list));
l = *list;
REQUIRE(l->refs == 0);
server = ISC_LIST_HEAD(l->elements);
while (server != NULL) {
stmp = ISC_LIST_NEXT(server, next);
ISC_LIST_UNLINK(l->elements, server, next);
dns_peer_detach(&server);
server = stmp;
}
l->magic = 0;
isc_mem_put(l->mem, l, sizeof(*l));
*list = NULL;
}
void
dns_peerlist_addpeer(dns_peerlist_t *peers, dns_peer_t *peer) {
dns_peer_t *p = NULL;
dns_peer_attach(peer, &p);
/*
* More specifics to front of list.
*/
for (p = ISC_LIST_HEAD(peers->elements);
p != NULL;
p = ISC_LIST_NEXT(p, next))
if (p->prefixlen < peer->prefixlen)
break;
if (p != NULL)
ISC_LIST_INSERTBEFORE(peers->elements, p, peer, next);
else
ISC_LIST_APPEND(peers->elements, peer, next);
}
isc_result_t
dns_peerlist_peerbyaddr(dns_peerlist_t *servers,
isc_netaddr_t *addr, dns_peer_t **retval)
{
dns_peer_t *server;
isc_result_t res;
REQUIRE(retval != NULL);
REQUIRE(DNS_PEERLIST_VALID(servers));
server = ISC_LIST_HEAD(servers->elements);
while (server != NULL) {
if (isc_netaddr_eqprefix(addr, &server->address,
server->prefixlen))
break;
server = ISC_LIST_NEXT(server, next);
}
if (server != NULL) {
*retval = server;
res = ISC_R_SUCCESS;
} else {
res = ISC_R_NOTFOUND;
}
return (res);
}
isc_result_t
dns_peerlist_currpeer(dns_peerlist_t *peers, dns_peer_t **retval) {
dns_peer_t *p = NULL;
p = ISC_LIST_TAIL(peers->elements);
dns_peer_attach(p, retval);
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_new(isc_mem_t *mem, isc_netaddr_t *addr, dns_peer_t **peerptr) {
unsigned int prefixlen = 0;
REQUIRE(peerptr != NULL);
switch(addr->family) {
case AF_INET:
prefixlen = 32;
break;
case AF_INET6:
prefixlen = 128;
break;
default:
INSIST(0);
}
return (dns_peer_newprefix(mem, addr, prefixlen, peerptr));
}
isc_result_t
dns_peer_newprefix(isc_mem_t *mem, isc_netaddr_t *addr, unsigned int prefixlen,
dns_peer_t **peerptr)
{
dns_peer_t *peer;
REQUIRE(peerptr != NULL);
peer = isc_mem_get(mem, sizeof(*peer));
if (peer == NULL)
return (ISC_R_NOMEMORY);
peer->magic = DNS_PEER_MAGIC;
peer->address = *addr;
peer->prefixlen = prefixlen;
peer->mem = mem;
peer->bogus = ISC_FALSE;
peer->transfer_format = dns_one_answer;
peer->transfers = 0;
peer->request_ixfr = ISC_FALSE;
peer->provide_ixfr = ISC_FALSE;
peer->key = NULL;
peer->refs = 1;
peer->transfer_source = NULL;
peer->notify_source = NULL;
peer->query_source = NULL;
memset(&peer->bitflags, 0x0, sizeof(peer->bitflags));
ISC_LINK_INIT(peer, next);
*peerptr = peer;
return (ISC_R_SUCCESS);
}
void
dns_peer_attach(dns_peer_t *source, dns_peer_t **target) {
REQUIRE(DNS_PEER_VALID(source));
REQUIRE(target != NULL);
REQUIRE(*target == NULL);
source->refs++;
ENSURE(source->refs != 0xffffffffU);
*target = source;
}
void
dns_peer_detach(dns_peer_t **peer) {
dns_peer_t *p;
REQUIRE(peer != NULL);
REQUIRE(*peer != NULL);
REQUIRE(DNS_PEER_VALID(*peer));
p = *peer;
REQUIRE(p->refs > 0);
*peer = NULL;
p->refs--;
if (p->refs == 0)
peer_delete(&p);
}
static void
peer_delete(dns_peer_t **peer) {
dns_peer_t *p;
isc_mem_t *mem;
REQUIRE(peer != NULL);
REQUIRE(DNS_PEER_VALID(*peer));
p = *peer;
REQUIRE(p->refs == 0);
mem = p->mem;
p->mem = NULL;
p->magic = 0;
if (p->key != NULL) {
dns_name_free(p->key, mem);
isc_mem_put(mem, p->key, sizeof(dns_name_t));
}
if (p->query_source != NULL)
isc_mem_put(mem, p->query_source, sizeof(*p->query_source));
if (p->notify_source != NULL)
isc_mem_put(mem, p->notify_source, sizeof(*p->notify_source));
if (p->transfer_source != NULL)
isc_mem_put(mem, p->transfer_source,
sizeof(*p->transfer_source));
isc_mem_put(mem, p, sizeof(*p));
*peer = NULL;
}
isc_result_t
dns_peer_setbogus(dns_peer_t *peer, isc_boolean_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags);
peer->bogus = newval;
DNS_BIT_SET(BOGUS_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getbogus(dns_peer_t *peer, isc_boolean_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags)) {
*retval = peer->bogus;
return (ISC_R_SUCCESS);
} else
return (ISC_R_NOTFOUND);
}
isc_result_t
dns_peer_setprovideixfr(dns_peer_t *peer, isc_boolean_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags);
peer->provide_ixfr = newval;
DNS_BIT_SET(PROVIDE_IXFR_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getprovideixfr(dns_peer_t *peer, isc_boolean_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(PROVIDE_IXFR_BIT, &peer->bitflags)) {
*retval = peer->provide_ixfr;
return (ISC_R_SUCCESS);
} else {
return (ISC_R_NOTFOUND);
}
}
isc_result_t
dns_peer_setrequestixfr(dns_peer_t *peer, isc_boolean_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags);
peer->request_ixfr = newval;
DNS_BIT_SET(REQUEST_IXFR_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getrequestixfr(dns_peer_t *peer, isc_boolean_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags)) {
*retval = peer->request_ixfr;
return (ISC_R_SUCCESS);
} else
return (ISC_R_NOTFOUND);
}
isc_result_t
dns_peer_setsupportedns(dns_peer_t *peer, isc_boolean_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags);
peer->support_edns = newval;
DNS_BIT_SET(SUPPORT_EDNS_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getsupportedns(dns_peer_t *peer, isc_boolean_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags)) {
*retval = peer->support_edns;
return (ISC_R_SUCCESS);
} else
return (ISC_R_NOTFOUND);
}
isc_result_t
dns_peer_setrequestnsid(dns_peer_t *peer, isc_boolean_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags);
peer->request_nsid = newval;
DNS_BIT_SET(REQUEST_NSID_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getrequestnsid(dns_peer_t *peer, isc_boolean_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags)) {
*retval = peer->request_nsid;
return (ISC_R_SUCCESS);
} else
return (ISC_R_NOTFOUND);
}
isc_result_t
dns_peer_setrequestsit(dns_peer_t *peer, isc_boolean_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(REQUEST_SIT_BIT, &peer->bitflags);
peer->request_sit = newval;
DNS_BIT_SET(REQUEST_SIT_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getrequestsit(dns_peer_t *peer, isc_boolean_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(REQUEST_SIT_BIT, &peer->bitflags)) {
*retval = peer->request_sit;
return (ISC_R_SUCCESS);
} else
return (ISC_R_NOTFOUND);
}
isc_result_t
dns_peer_setforcetcp(dns_peer_t *peer, isc_boolean_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(FORCE_TCP_BIT, &peer->bitflags);
peer->force_tcp = newval;
DNS_BIT_SET(FORCE_TCP_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getforcetcp(dns_peer_t *peer, isc_boolean_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(FORCE_TCP_BIT, &peer->bitflags)) {
*retval = peer->force_tcp;
return (ISC_R_SUCCESS);
} else
return (ISC_R_NOTFOUND);
}
isc_result_t
dns_peer_settransfers(dns_peer_t *peer, isc_uint32_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags);
peer->transfers = newval;
DNS_BIT_SET(TRANSFERS_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_gettransfers(dns_peer_t *peer, isc_uint32_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(TRANSFERS_BIT, &peer->bitflags)) {
*retval = peer->transfers;
return (ISC_R_SUCCESS);
} else {
return (ISC_R_NOTFOUND);
}
}
isc_result_t
dns_peer_settransferformat(dns_peer_t *peer, dns_transfer_format_t newval) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT,
&peer->bitflags);
peer->transfer_format = newval;
DNS_BIT_SET(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_gettransferformat(dns_peer_t *peer, dns_transfer_format_t *retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (DNS_BIT_CHECK(SERVER_TRANSFER_FORMAT_BIT, &peer->bitflags)) {
*retval = peer->transfer_format;
return (ISC_R_SUCCESS);
} else {
return (ISC_R_NOTFOUND);
}
}
isc_result_t
dns_peer_getkey(dns_peer_t *peer, dns_name_t **retval) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(retval != NULL);
if (peer->key != NULL) {
*retval = peer->key;
}
return (peer->key == NULL ? ISC_R_NOTFOUND : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_setkey(dns_peer_t *peer, dns_name_t **keyval) {
isc_boolean_t exists = ISC_FALSE;
if (peer->key != NULL) {
dns_name_free(peer->key, peer->mem);
isc_mem_put(peer->mem, peer->key, sizeof(dns_name_t));
exists = ISC_TRUE;
}
peer->key = *keyval;
*keyval = NULL;
return (exists ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_setkeybycharp(dns_peer_t *peer, const char *keyval) {
isc_buffer_t b;
dns_fixedname_t fname;
dns_name_t *name;
isc_result_t result;
dns_fixedname_init(&fname);
isc_buffer_constinit(&b, keyval, strlen(keyval));
isc_buffer_add(&b, strlen(keyval));
result = dns_name_fromtext(dns_fixedname_name(&fname), &b,
dns_rootname, 0, NULL);
if (result != ISC_R_SUCCESS)
return (result);
name = isc_mem_get(peer->mem, sizeof(dns_name_t));
if (name == NULL)
return (ISC_R_NOMEMORY);
dns_name_init(name, NULL);
result = dns_name_dup(dns_fixedname_name(&fname), peer->mem, name);
if (result != ISC_R_SUCCESS) {
isc_mem_put(peer->mem, name, sizeof(dns_name_t));
return (result);
}
result = dns_peer_setkey(peer, &name);
if (result != ISC_R_SUCCESS)
isc_mem_put(peer->mem, name, sizeof(dns_name_t));
return (result);
}
isc_result_t
dns_peer_settransfersource(dns_peer_t *peer,
const isc_sockaddr_t *transfer_source)
{
REQUIRE(DNS_PEER_VALID(peer));
if (peer->transfer_source != NULL) {
isc_mem_put(peer->mem, peer->transfer_source,
sizeof(*peer->transfer_source));
peer->transfer_source = NULL;
}
if (transfer_source != NULL) {
peer->transfer_source = isc_mem_get(peer->mem,
sizeof(*peer->transfer_source));
if (peer->transfer_source == NULL)
return (ISC_R_NOMEMORY);
*peer->transfer_source = *transfer_source;
}
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_gettransfersource(dns_peer_t *peer, isc_sockaddr_t *transfer_source) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(transfer_source != NULL);
if (peer->transfer_source == NULL)
return (ISC_R_NOTFOUND);
*transfer_source = *peer->transfer_source;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_setnotifysource(dns_peer_t *peer,
const isc_sockaddr_t *notify_source)
{
REQUIRE(DNS_PEER_VALID(peer));
if (peer->notify_source != NULL) {
isc_mem_put(peer->mem, peer->notify_source,
sizeof(*peer->notify_source));
peer->notify_source = NULL;
}
if (notify_source != NULL) {
peer->notify_source = isc_mem_get(peer->mem,
sizeof(*peer->notify_source));
if (peer->notify_source == NULL)
return (ISC_R_NOMEMORY);
*peer->notify_source = *notify_source;
}
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getnotifysource(dns_peer_t *peer, isc_sockaddr_t *notify_source) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(notify_source != NULL);
if (peer->notify_source == NULL)
return (ISC_R_NOTFOUND);
*notify_source = *peer->notify_source;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_setquerysource(dns_peer_t *peer, const isc_sockaddr_t *query_source) {
REQUIRE(DNS_PEER_VALID(peer));
if (peer->query_source != NULL) {
isc_mem_put(peer->mem, peer->query_source,
sizeof(*peer->query_source));
peer->query_source = NULL;
}
if (query_source != NULL) {
peer->query_source = isc_mem_get(peer->mem,
sizeof(*peer->query_source));
if (peer->query_source == NULL)
return (ISC_R_NOMEMORY);
*peer->query_source = *query_source;
}
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getquerysource(dns_peer_t *peer, isc_sockaddr_t *query_source) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(query_source != NULL);
if (peer->query_source == NULL)
return (ISC_R_NOTFOUND);
*query_source = *peer->query_source;
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_setudpsize(dns_peer_t *peer, isc_uint16_t udpsize) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags);
peer->udpsize = udpsize;
DNS_BIT_SET(SERVER_UDPSIZE_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getudpsize(dns_peer_t *peer, isc_uint16_t *udpsize) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(udpsize != NULL);
if (DNS_BIT_CHECK(SERVER_UDPSIZE_BIT, &peer->bitflags)) {
*udpsize = peer->udpsize;
return (ISC_R_SUCCESS);
} else {
return (ISC_R_NOTFOUND);
}
}
isc_result_t
dns_peer_setmaxudp(dns_peer_t *peer, isc_uint16_t maxudp) {
isc_boolean_t existed;
REQUIRE(DNS_PEER_VALID(peer));
existed = DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags);
peer->maxudp = maxudp;
DNS_BIT_SET(SERVER_MAXUDP_BIT, &peer->bitflags);
return (existed ? ISC_R_EXISTS : ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getmaxudp(dns_peer_t *peer, isc_uint16_t *maxudp) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(maxudp != NULL);
if (DNS_BIT_CHECK(SERVER_MAXUDP_BIT, &peer->bitflags)) {
*maxudp = peer->maxudp;
return (ISC_R_SUCCESS);
} else {
return (ISC_R_NOTFOUND);
}
}
isc_result_t
dns_peer_setnotifydscp(dns_peer_t *peer, isc_dscp_t dscp) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(dscp < 64);
peer->notify_dscp = dscp;
DNS_BIT_SET(NOTIFY_DSCP_BIT, &peer->bitflags);
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getnotifydscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(dscpp != NULL);
if (DNS_BIT_CHECK(NOTIFY_DSCP_BIT, &peer->bitflags)) {
*dscpp = peer->notify_dscp;
return (ISC_R_SUCCESS);
}
return (ISC_R_NOTFOUND);
}
isc_result_t
dns_peer_settransferdscp(dns_peer_t *peer, isc_dscp_t dscp) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(dscp < 64);
peer->transfer_dscp = dscp;
DNS_BIT_SET(TRANSFER_DSCP_BIT, &peer->bitflags);
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_gettransferdscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(dscpp != NULL);
if (DNS_BIT_CHECK(TRANSFER_DSCP_BIT, &peer->bitflags)) {
*dscpp = peer->transfer_dscp;
return (ISC_R_SUCCESS);
}
return (ISC_R_NOTFOUND);
}
isc_result_t
dns_peer_setquerydscp(dns_peer_t *peer, isc_dscp_t dscp) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(dscp < 64);
peer->query_dscp = dscp;
DNS_BIT_SET(QUERY_DSCP_BIT, &peer->bitflags);
return (ISC_R_SUCCESS);
}
isc_result_t
dns_peer_getquerydscp(dns_peer_t *peer, isc_dscp_t *dscpp) {
REQUIRE(DNS_PEER_VALID(peer));
REQUIRE(dscpp != NULL);
if (DNS_BIT_CHECK(QUERY_DSCP_BIT, &peer->bitflags)) {
*dscpp = peer->query_dscp;
return (ISC_R_SUCCESS);
}
return (ISC_R_NOTFOUND);
}
|