42 static const char* rrset_str =
"rrset";
50 log_rr(ldns_rr* rr,
const char* pre,
int level)
58 str = ldns_rr2str(rr);
60 ods_log_error(
"[%s] %s: Error converting RR to string", rrset_str,
64 str[(strlen(str))-1] =
'\0';
66 for (i=0; i < strlen(str); i++) {
102 log_rrset(ldns_rdf* dname, ldns_rr_type type,
const char* pre,
int level)
110 str = ldns_rdf2str(dname);
114 str[(strlen(str))-1] =
'\0';
116 for (i=0; i < strlen(str); i++) {
117 if (str[i] ==
'\t') {
125 ods_log_alert(
"[%s] %s: <%s,%s>", rrset_str, pre?pre:
"", str,
128 ods_log_crit(
"[%s] %s: <%s,%s>", rrset_str, pre?pre:
"", str,
131 ods_log_error(
"[%s] %s: <%s,%s>", rrset_str, pre?pre:
"", str,
137 ods_log_info(
"[%s] %s: <%s,%s>", rrset_str, pre?pre:
"", str,
143 ods_log_debug(
"[%s] %s: <%s,%s>", rrset_str, pre?pre:
"", str,
164 const ldns_rr_descriptor* descriptor;
165 descriptor = ldns_rr_descript(type);
166 if (descriptor && descriptor->_name) {
167 return descriptor->_name;
168 }
else if (type == LDNS_RR_TYPE_AXFR) {
170 }
else if (type == LDNS_RR_TYPE_IXFR) {
186 if (!type || !zoneptr) {
192 ods_log_error(
"[%s] unable to create RRset %u: allocator_alloc() "
193 "failed", rrset_str, (
unsigned) type);
200 rrset->
zone = zoneptr;
216 ldns_status lstatus = LDNS_STATUS_OK;
220 if (!rrset || !rr || rrset->
rr_count <= 0) {
223 for (i=0; i < rrset->
rr_count; i++) {
225 if (lstatus != LDNS_STATUS_OK) {
226 ods_log_error(
"[%s] unable to lookup RR: compare failed (%s)",
227 rrset_str, ldns_get_errorstr_by_id(lstatus));
231 return &rrset->
rrs[i];
250 for (i=0; i < rrset->
rr_count; i++) {
274 rrs_old = rrset->
rrs;
278 ods_fatal_exit(
"[%s] fatal unable to add RR: allocator_alloc() failed",
313 rrset->
rrs[rrnum].
rr = NULL;
314 while (rrnum < rrset->rr_count-1) {
315 rrset->
rrs[rrnum] = rrset->
rrs[rrnum+1];
319 rrs_orig = rrset->
rrs;
323 ods_fatal_exit(
"[%s] fatal unable to delete RR: allocator_alloc() failed",
343 uint8_t del_sigs = 0;
348 for (i=0; i < rrset->
rr_count; i++) {
358 if ((rrset->
rrtype == LDNS_RR_TYPE_DNSKEY ||
359 rrset->
rrtype == LDNS_RR_TYPE_NSEC3PARAMS) && more_coming) {
396 const char* locator, uint32_t flags)
404 rrsigs_old = rrset->
rrsigs;
408 ods_fatal_exit(
"[%s] fatal unable to add RRSIG: allocator_alloc() failed",
412 memcpy(rrset->
rrsigs, rrsigs_old,
441 while (rrnum < rrset->rrsig_count-1) {
446 rrsigs_orig = rrset->
rrsigs;
450 ods_fatal_exit(
"[%s] fatal unable to delete RRSIG: allocator_alloc() failed",
453 memcpy(rrset->
rrsigs, rrsigs_orig,
466 rrset_recycle(
rrset_type* rrset, time_t signtime, ldns_rr_type dstatus,
467 ldns_rr_type delegpt)
469 uint32_t refresh = 0;
470 uint32_t expiration = 0;
471 uint32_t inception = 0;
472 uint32_t reusedsigs = 0;
473 unsigned drop_sig = 0;
484 refresh = (uint32_t) (signtime +
491 if (dstatus != LDNS_RR_TYPE_SOA || (delegpt != LDNS_RR_TYPE_SOA &&
492 rrset->
rrtype != LDNS_RR_TYPE_DS)) {
494 goto recycle_drop_sig;
497 (delegpt == LDNS_RR_TYPE_SOA || rrset->
rrtype == LDNS_RR_TYPE_DS));
500 if (rrset->
needs_signing || refresh <= (uint32_t) signtime) {
502 goto recycle_drop_sig;
505 expiration = ldns_rdf2native_int32(
506 ldns_rr_rrsig_expiration(rrset->
rrsigs[i].
rr));
507 if (expiration < refresh) {
509 goto recycle_drop_sig;
512 inception = ldns_rdf2native_int32(
513 ldns_rr_rrsig_inception(rrset->
rrsigs[i].
rr));
514 if (inception > (uint32_t) signtime) {
516 goto recycle_drop_sig;
548 rrset_sigalgo(
rrset_type* rrset, uint8_t algorithm)
555 if (algorithm == ldns_rdf2native_int8(
556 ldns_rr_rrsig_algorithm(rrset->
rrsigs[i].
rr))) {
569 rrset_siglocator(
rrset_type* rrset,
const char* locator)
591 ldns_rr_list* rr_list = NULL;
594 rr_list = ldns_rr_list_new();
595 for (i=0; i < rrset->
rr_count; i++) {
601 ldns_rr2canonical(rrset->
rrs[i].
rr);
602 ret = (int) ldns_rr_list_push_rr(rr_list, rrset->
rrs[i].
rr);
604 ldns_rr_list_free(rr_list);
607 if (rrset->
rrtype == LDNS_RR_TYPE_CNAME ||
608 rrset->
rrtype == LDNS_RR_TYPE_DNAME) {
613 ldns_rr_list_sort(rr_list);
623 rrset_sigvalid_period(
signconf_type* sc, ldns_rr_type rrtype, time_t signtime,
624 time_t* inception, time_t* expiration)
629 time_t random_jitter = 0;
630 if (!sc || !rrtype || !signtime) {
638 if (rrtype == LDNS_RR_TYPE_NSEC || rrtype == LDNS_RR_TYPE_NSEC3) {
643 *inception = signtime - offset;
644 *expiration = (signtime + validity + random_jitter) - jitter;
657 uint32_t newsigs = 0;
658 uint32_t reusedsigs = 0;
659 ldns_rr* rrsig = NULL;
660 ldns_rr_list* rr_list = NULL;
662 const char* locator = NULL;
663 time_t inception = 0;
664 time_t expiration = 0;
667 ldns_rr_type dstatus = LDNS_RR_TYPE_FIRST;
668 ldns_rr_type delegpt = LDNS_RR_TYPE_FIRST;
676 if (rrset->
rrtype == LDNS_RR_TYPE_NSEC ||
677 rrset->
rrtype == LDNS_RR_TYPE_NSEC3) {
678 dstatus = LDNS_RR_TYPE_SOA;
679 delegpt = LDNS_RR_TYPE_SOA;
685 reusedsigs = rrset_recycle(rrset, signtime, dstatus, delegpt);
692 if (dstatus != LDNS_RR_TYPE_SOA) {
697 if (delegpt != LDNS_RR_TYPE_SOA && rrset->
rrtype != LDNS_RR_TYPE_DS) {
706 (delegpt == LDNS_RR_TYPE_SOA || rrset->
rrtype == LDNS_RR_TYPE_DS));
708 rr_list = rrset2rrlist(rrset);
710 ods_log_error(
"[%s] unable to sign RRset[%i]: rrset2rrlist() failed",
711 rrset_str, rrset->
rrtype);
714 if (ldns_rr_list_rr_count(rr_list) <= 0) {
716 ldns_rr_list_free(rr_list);
721 &inception, &expiration);
726 rrset->
rrtype != LDNS_RR_TYPE_DNSKEY) {
731 rrset->
rrtype == LDNS_RR_TYPE_DNSKEY) {
738 if (rrset->
rrtype != LDNS_RR_TYPE_DNSKEY &&
752 zone->
apex, inception, expiration);
754 ods_log_crit(
"[%s] unable to sign RRset[%i]: lhsm_sign() failed",
755 rrset_str, rrset->
rrtype);
756 ldns_rr_list_free(rr_list);
772 ldns_rr_list_free(rr_list);
774 if (rrset->
rrtype == LDNS_RR_TYPE_SOA) {
796 ods_log_crit(
"[%s] unable to print RRset: rrset or fd missing",
803 for (i=0; i < rrset->
rr_count; i++) {
806 if (rrset->
rrtype == LDNS_RR_TYPE_CNAME ||
807 rrset->
rrtype == LDNS_RR_TYPE_DNAME) {
855 for (i=0; i < rrset->
rr_count; i++) {
856 ldns_rr_free(rrset->
rrs[i].
rr);
885 str = ldns_rr2str(rrset->
rrsigs[i].
rr);
889 str[(strlen(str))-1] =
'\0';
890 fprintf(fd,
"%s; {locator %s flags %u}\n", str,
void ods_log_alert(const char *format,...)
rr_type * rrset_lookup_rr(rrset_type *rrset, ldns_rr *rr)
duration_type * sig_inception_offset
void rrset_cleanup(rrset_type *rrset)
key_type * keylist_lookup_by_locator(keylist_type *kl, const char *locator)
const char * rrset_type2str(ldns_rr_type type)
void ods_log_debug(const char *format,...)
void * allocator_alloc(allocator_type *allocator, size_t size)
duration_type * sig_validity_default
ldns_status util_dnssec_rrs_compare(ldns_rr *rr1, ldns_rr *rr2, int *cmp)
ldns_rr * lhsm_sign(hsm_ctx_t *ctx, ldns_rr_list *rrset, key_type *key_id, ldns_rdf *owner, time_t inception, time_t expiration)
size_t rrset_count_rr_is_added(rrset_type *rrset)
void ods_fatal_exit(const char *format,...)
void ixfr_add_rr(ixfr_type *ixfr, ldns_rr *rr)
rrset_type * rrset_create(void *zoneptr, ldns_rr_type type)
duration_type * sig_validity_denial
void ixfr_del_rr(ixfr_type *ixfr, ldns_rr *rr)
void ods_log_info(const char *format,...)
enum ods_enum_status ods_status
rr_type * rrset_add_rr(rrset_type *rrset, ldns_rr *rr)
void ods_log_error(const char *format,...)
rrsig_type * rrset_add_rrsig(rrset_type *rrset, ldns_rr *rr, const char *locator, uint32_t flags)
lock_basic_type stats_lock
int ods_strcmp(const char *s1, const char *s2)
adapter_type * adoutbound
ods_status util_rr_print(FILE *fd, const ldns_rr *rr)
void log_rr(ldns_rr *rr, const char *pre, int level)
void ods_log_crit(const char *format,...)
duration_type * sig_refresh_interval
#define lock_basic_lock(lock)
void log_rrset(ldns_rdf *dname, ldns_rr_type type, const char *pre, int level)
ldns_rr_type domain_is_delegpt(domain_type *domain)
ldns_rr_type domain_is_occluded(domain_type *domain)
char * allocator_strdup(allocator_type *allocator, const char *string)
void rrset_del_rrsig(rrset_type *rrset, uint16_t rrnum)
void rrset_backup2(FILE *fd, rrset_type *rrset)
allocator_type * allocator
void rrset_del_rr(rrset_type *rrset, uint16_t rrnum)
time_t duration2time(duration_type *duration)
void ods_log_verbose(const char *format,...)
struct rrsig_struct rrsig_type
lock_basic_type ixfr_lock
duration_type * sig_jitter
void ods_log_deeebug(const char *format,...)
ods_status rrset_sign(hsm_ctx_t *ctx, rrset_type *rrset, time_t signtime)
void allocator_deallocate(allocator_type *allocator, void *data)
void rrset_diff(rrset_type *rrset, unsigned is_ixfr, unsigned more_coming)
#define ods_log_assert(x)
time_t ods_rand(time_t mod)
#define lock_basic_unlock(lock)
void ods_log_warning(const char *format,...)
void rrset_print(FILE *fd, rrset_type *rrset, int skip_rrsigs, ods_status *status)