static inline isc_result_t fromstruct_keydata(ARGS_FROMSTRUCT) { dns_rdata_keydata_t *keydata = source; REQUIRE(type == 65533); REQUIRE(source != NULL); REQUIRE(keydata->common.rdtype == type); REQUIRE(keydata->common.rdclass == rdclass); UNUSED(type); UNUSED(rdclass); /* Refresh timer */ RETERR(uint32_tobuffer(keydata->refresh, target)); /* Add hold-down */ RETERR(uint32_tobuffer(keydata->addhd, target)); /* Remove hold-down */ RETERR(uint32_tobuffer(keydata->removehd, target)); /* Flags */ RETERR(uint16_tobuffer(keydata->flags, target)); /* Protocol */ RETERR(uint8_tobuffer(keydata->protocol, target)); /* Algorithm */ RETERR(uint8_tobuffer(keydata->algorithm, target)); /* Data */ return (mem_tobuffer(target, keydata->data, keydata->datalen)); }
static inline isc_result_t fromtext_keydata(ARGS_FROMTEXT) { isc_token_t token; dns_secalg_t alg; dns_secproto_t proto; dns_keyflags_t flags; isc_uint32_t refresh, addhd, removehd; REQUIRE(type == 65533); UNUSED(type); UNUSED(rdclass); UNUSED(origin); UNUSED(options); UNUSED(callbacks); /* refresh timer */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &refresh)); RETERR(uint32_tobuffer(refresh, target)); /* add hold-down */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &addhd)); RETERR(uint32_tobuffer(addhd, target)); /* remove hold-down */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &removehd)); RETERR(uint32_tobuffer(removehd, target)); /* flags */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); RETTOK(dns_keyflags_fromtext(&flags, &token.value.as_textregion)); RETERR(uint16_tobuffer(flags, target)); /* protocol */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); RETTOK(dns_secproto_fromtext(&proto, &token.value.as_textregion)); RETERR(mem_tobuffer(target, &proto, 1)); /* algorithm */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); RETTOK(dns_secalg_fromtext(&alg, &token.value.as_textregion)); RETERR(mem_tobuffer(target, &alg, 1)); /* No Key? */ if ((flags & 0xc000) == 0xc000) return (ISC_R_SUCCESS); return (isc_base64_tobuffer(lexer, target, -1)); }
static inline isc_result_t fromstruct_sig(ARGS_FROMSTRUCT) { dns_rdata_sig_t *sig = source; REQUIRE(type == dns_rdatatype_sig); REQUIRE(source != NULL); REQUIRE(sig->common.rdtype == type); REQUIRE(sig->common.rdclass == rdclass); REQUIRE(sig->signature != NULL || sig->siglen == 0); UNUSED(type); UNUSED(rdclass); /* * Type covered. */ RETERR(uint16_tobuffer(sig->covered, target)); /* * Algorithm. */ RETERR(uint8_tobuffer(sig->algorithm, target)); /* * Labels. */ RETERR(uint8_tobuffer(sig->labels, target)); /* * Original TTL. */ RETERR(uint32_tobuffer(sig->originalttl, target)); /* * Expire time. */ RETERR(uint32_tobuffer(sig->timeexpire, target)); /* * Time signed. */ RETERR(uint32_tobuffer(sig->timesigned, target)); /* * Key ID. */ RETERR(uint16_tobuffer(sig->keyid, target)); /* * Signer name. */ RETERR(name_tobuffer(&sig->signer, target)); /* * Signature. */ return (mem_tobuffer(target, sig->signature, sig->siglen)); }
static inline isc_result_t fromstruct_tkey(ARGS_FROMSTRUCT) { dns_rdata_tkey_t *tkey = source; REQUIRE(type == 249); REQUIRE(source != NULL); REQUIRE(tkey->common.rdtype == type); REQUIRE(tkey->common.rdclass == rdclass); UNUSED(type); UNUSED(rdclass); /* * Algorithm Name. */ RETERR(name_tobuffer(&tkey->algorithm, target)); /* * Inception: 32 bits. */ RETERR(uint32_tobuffer(tkey->inception, target)); /* * Expire: 32 bits. */ RETERR(uint32_tobuffer(tkey->expire, target)); /* * Mode: 16 bits. */ RETERR(uint16_tobuffer(tkey->mode, target)); /* * Error: 16 bits. */ RETERR(uint16_tobuffer(tkey->error, target)); /* * Key size: 16 bits. */ RETERR(uint16_tobuffer(tkey->keylen, target)); /* * Key. */ RETERR(mem_tobuffer(target, tkey->key, tkey->keylen)); /* * Other size: 16 bits. */ RETERR(uint16_tobuffer(tkey->otherlen, target)); /* * Other data. */ return (mem_tobuffer(target, tkey->other, tkey->otherlen)); }
static inline isc_result_t fromtext_soa(ARGS_FROMTEXT) { isc_token_t token; dns_name_t name; isc_buffer_t buffer; int i; isc_uint32_t n; isc_boolean_t ok; REQUIRE(type == 6); UNUSED(type); UNUSED(rdclass); UNUSED(callbacks); origin = (origin != NULL) ? origin : dns_rootname; for (i = 0; i < 2; i++) { RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = ISC_TRUE; if ((options & DNS_RDATA_CHECKNAMES) != 0) switch (i) { case 0: ok = dns_name_ishostname(&name, ISC_FALSE); break; case 1: ok = dns_name_ismailbox(&name); break; } if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) RETTOK(DNS_R_BADNAME); if (!ok && callbacks != NULL) warn_badname(&name, lexer, callbacks); } RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); RETERR(uint32_tobuffer(token.value.as_ulong, target)); for (i = 0; i < 4; i++) { RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); RETTOK(dns_counter_fromtext(&token.value.as_textregion, &n)); RETERR(uint32_tobuffer(n, target)); } return (ISC_R_SUCCESS); }
static inline isc_result_t fromstruct_soa(ARGS_FROMSTRUCT) { dns_rdata_soa_t *soa = source; isc_region_t region; REQUIRE(type == 6); REQUIRE(source != NULL); REQUIRE(soa->common.rdtype == type); REQUIRE(soa->common.rdclass == rdclass); UNUSED(type); UNUSED(rdclass); dns_name_toregion(&soa->origin, ®ion); RETERR(isc_buffer_copyregion(target, ®ion)); dns_name_toregion(&soa->contact, ®ion); RETERR(isc_buffer_copyregion(target, ®ion)); RETERR(uint32_tobuffer(soa->serial, target)); RETERR(uint32_tobuffer(soa->refresh, target)); RETERR(uint32_tobuffer(soa->retry, target)); RETERR(uint32_tobuffer(soa->expire, target)); return (uint32_tobuffer(soa->minimum, target)); }
static inline isc_result_t fromstruct_l32(ARGS_FROMSTRUCT) { dns_rdata_l32_t *l32 = source; isc_uint32_t n; REQUIRE(type == 105); REQUIRE(source != NULL); REQUIRE(l32->common.rdtype == type); REQUIRE(l32->common.rdclass == rdclass); UNUSED(type); UNUSED(rdclass); RETERR(uint16_tobuffer(l32->pref, target)); n = ntohl(l32->l32.s_addr); return (uint32_tobuffer(n, target)); }
static inline isc_result_t fromstruct_hs_a(ARGS_FROMSTRUCT) { dns_rdata_hs_a_t *a = source; isc_uint32_t n; REQUIRE(type == 1); REQUIRE(rdclass == 4); REQUIRE(source != NULL); REQUIRE(a->common.rdtype == type); REQUIRE(a->common.rdclass == rdclass); UNUSED(type); UNUSED(rdclass); n = ntohl(a->in_addr.s_addr); return (uint32_tobuffer(n, target)); }
static inline isc_result_t fromstruct_ipseckey(ARGS_FROMSTRUCT) { dns_rdata_ipseckey_t *ipseckey = source; isc_region_t region; isc_uint32_t n; REQUIRE(type == 45); REQUIRE(source != NULL); REQUIRE(ipseckey->common.rdtype == type); REQUIRE(ipseckey->common.rdclass == rdclass); UNUSED(type); UNUSED(rdclass); if (ipseckey->gateway_type > 3U) return (ISC_R_NOTIMPLEMENTED); RETERR(uint8_tobuffer(ipseckey->precedence, target)); RETERR(uint8_tobuffer(ipseckey->gateway_type, target)); RETERR(uint8_tobuffer(ipseckey->algorithm, target)); switch (ipseckey->gateway_type) { case 0: break; case 1: n = ntohl(ipseckey->in_addr.s_addr); RETERR(uint32_tobuffer(n, target)); break; case 2: RETERR(mem_tobuffer(target, ipseckey->in6_addr.s6_addr, 16)); break; case 3: dns_name_toregion(&ipseckey->gateway, ®ion); RETERR(isc_buffer_copyregion(target, ®ion)); break; } return (mem_tobuffer(target, ipseckey->key, ipseckey->keylength)); }
static inline isc_result_t fromtext_tkey(ARGS_FROMTEXT) { isc_token_t token; dns_rcode_t rcode; dns_name_t name; isc_buffer_t buffer; long i; char *e; REQUIRE(type == 249); UNUSED(type); UNUSED(rdclass); UNUSED(callbacks); /* * Algorithm. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); origin = (origin != NULL) ? origin : dns_rootname; RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); /* * Inception. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); RETERR(uint32_tobuffer(token.value.as_ulong, target)); /* * Expiration. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); RETERR(uint32_tobuffer(token.value.as_ulong, target)); /* * Mode. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); if (token.value.as_ulong > 0xffffU) RETTOK(ISC_R_RANGE); RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* * Error. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); if (dns_tsigrcode_fromtext(&rcode, &token.value.as_textregion) != ISC_R_SUCCESS) { i = strtol(DNS_AS_STR(token), &e, 10); if (*e != 0) RETTOK(DNS_R_UNKNOWN); if (i < 0 || i > 0xffff) RETTOK(ISC_R_RANGE); rcode = (dns_rcode_t)i; } RETERR(uint16_tobuffer(rcode, target)); /* * Key Size. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); if (token.value.as_ulong > 0xffffU) RETTOK(ISC_R_RANGE); RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* * Key Data. */ RETERR(isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong)); /* * Other Size. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); if (token.value.as_ulong > 0xffffU) RETTOK(ISC_R_RANGE); RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* * Other Data. */ return (isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong)); }
static inline isc_result_t fromtext_sig(ARGS_FROMTEXT) { isc_token_t token; unsigned char c; long i; dns_rdatatype_t covered; char *e; isc_result_t result; dns_name_t name; isc_buffer_t buffer; isc_uint32_t time_signed, time_expire; REQUIRE(type == dns_rdatatype_sig); UNUSED(type); UNUSED(rdclass); UNUSED(callbacks); /* * Type covered. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); result = dns_rdatatype_fromtext(&covered, &token.value.as_textregion); if (result != ISC_R_SUCCESS && result != ISC_R_NOTIMPLEMENTED) { i = strtol(DNS_AS_STR(token), &e, 10); if (i < 0 || i > 65535) RETTOK(ISC_R_RANGE); if (*e != 0) RETTOK(result); covered = (dns_rdatatype_t)i; } RETERR(uint16_tobuffer(covered, target)); /* * Algorithm. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); RETTOK(dns_secalg_fromtext(&c, &token.value.as_textregion)); RETERR(mem_tobuffer(target, &c, 1)); /* * Labels. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); if (token.value.as_ulong > 0xffU) RETTOK(ISC_R_RANGE); c = (unsigned char)token.value.as_ulong; RETERR(mem_tobuffer(target, &c, 1)); /* * Original ttl. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); RETERR(uint32_tobuffer(token.value.as_ulong, target)); /* * Signature expiration. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &time_expire)); RETERR(uint32_tobuffer(time_expire, target)); /* * Time signed. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &time_signed)); RETERR(uint32_tobuffer(time_signed, target)); /* * Key footprint. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* * Signer. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); if (origin == NULL) origin = dns_rootname; RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); /* * Sig. */ return (isc_base64_tobuffer(lexer, target, -1)); }