static inline isc_result_t towire_naptr(ARGS_TOWIRE) { dns_name_t name; dns_offsets_t offsets; isc_region_t sr; REQUIRE(rdata->type == 35); REQUIRE(rdata->length != 0); dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); /* * Order, preference. */ dns_rdata_toregion(rdata, &sr); RETERR(mem_tobuffer(target, sr.base, 4)); isc_region_consume(&sr, 4); /* * Flags. */ RETERR(mem_tobuffer(target, sr.base, sr.base[0] + 1)); isc_region_consume(&sr, sr.base[0] + 1); /* * Service. */ RETERR(mem_tobuffer(target, sr.base, sr.base[0] + 1)); isc_region_consume(&sr, sr.base[0] + 1); /* * Regexp. */ RETERR(mem_tobuffer(target, sr.base, sr.base[0] + 1)); isc_region_consume(&sr, sr.base[0] + 1); /* * Replacement. */ dns_name_init(&name, offsets); dns_name_fromregion(&name, &sr); return (dns_name_towire(&name, cctx, target)); }
static inline isc_result_t towire_keydata(ARGS_TOWIRE) { isc_region_t sr; REQUIRE(rdata->type == 65533); UNUSED(cctx); dns_rdata_toregion(rdata, &sr); return (mem_tobuffer(target, sr.base, sr.length)); }
static inline isc_result_t fromwire_sig(ARGS_FROMWIRE) { isc_region_t sr; dns_name_t name; REQUIRE(type == dns_rdatatype_sig); UNUSED(type); UNUSED(rdclass); dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); isc_buffer_activeregion(source, &sr); /* * type covered: 2 * algorithm: 1 * labels: 1 * original ttl: 4 * signature expiration: 4 * time signed: 4 * key footprint: 2 */ if (sr.length < 18) return (ISC_R_UNEXPECTEDEND); isc_buffer_forward(source, 18); RETERR(mem_tobuffer(target, sr.base, 18)); /* * Signer. */ dns_name_init(&name, NULL); RETERR(dns_name_fromwire(&name, source, dctx, options, target)); /* * Sig. */ isc_buffer_activeregion(source, &sr); isc_buffer_forward(source, sr.length); return (mem_tobuffer(target, sr.base, sr.length)); }
static inline isc_result_t towire_uri(ARGS_TOWIRE) { isc_region_t region; REQUIRE(rdata->type == 256); REQUIRE(rdata->length != 0); UNUSED(cctx); dns_rdata_toregion(rdata, ®ion); return (mem_tobuffer(target, region.base, region.length)); }
static inline isc_result_t towire_nsec3param(ARGS_TOWIRE) { isc_region_t sr; REQUIRE(rdata->type == dns_rdatatype_nsec3param); REQUIRE(rdata->length != 0); UNUSED(cctx); dns_rdata_toregion(rdata, &sr); return (mem_tobuffer(target, sr.base, sr.length)); }
static inline isc_result_t fromwire_cdnskey(ARGS_FROMWIRE) { unsigned char algorithm; isc_region_t sr; REQUIRE(type == dns_rdatatype_cdnskey); UNUSED(type); UNUSED(rdclass); UNUSED(dctx); UNUSED(options); isc_buffer_activeregion(source, &sr); if (sr.length < 4) return (ISC_R_UNEXPECTEDEND); algorithm = sr.base[3]; RETERR(mem_tobuffer(target, sr.base, 4)); isc_region_consume(&sr, 4); isc_buffer_forward(source, 4); if (algorithm == DNS_KEYALG_PRIVATEDNS) { dns_name_t name; dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); dns_name_init(&name, NULL); RETERR(dns_name_fromwire(&name, source, dctx, options, target)); } /* * RSAMD5 computes key ID differently from other * algorithms: we need to ensure there's enough data * present for the computation */ if (algorithm == DST_ALG_RSAMD5 && sr.length < 3) return (ISC_R_UNEXPECTEDEND); isc_buffer_activeregion(source, &sr); isc_buffer_forward(source, sr.length); return (mem_tobuffer(target, sr.base, sr.length)); }
static inline isc_result_t towire_in_dhcid (ARGS_TOWIRE) { isc_region_t sr; REQUIRE (rdata->type == 49); REQUIRE (rdata->rdclass == 1); REQUIRE (rdata->length != 0); UNUSED (cctx); dns_rdata_toregion (rdata, &sr); return (mem_tobuffer (target, sr.base, sr.length)); }
static inline isc_result_t fromtext_dnskey(ARGS_FROMTEXT) { isc_token_t token; dns_secalg_t alg; dns_secproto_t proto; dns_keyflags_t flags; REQUIRE(type == 48); UNUSED(type); UNUSED(rdclass); UNUSED(origin); UNUSED(options); UNUSED(callbacks); /* 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_eui64(ARGS_FROMSTRUCT) { dns_rdata_eui64_t *eui64 = source; REQUIRE(type == 109); REQUIRE(source != NULL); REQUIRE(eui64->common.rdtype == type); REQUIRE(eui64->common.rdclass == rdclass); UNUSED(type); UNUSED(rdclass); return (mem_tobuffer(target, eui64->eui64, sizeof(eui64->eui64))); }
static inline isc_result_t fromwire_in_apl(ARGS_FROMWIRE) { isc_region_t sr, sr2; isc_region_t tr; isc_uint16_t afi; isc_uint8_t prefix; isc_uint8_t len; REQUIRE(type == dns_rdatatype_apl); REQUIRE(rdclass == dns_rdataclass_in); UNUSED(type); UNUSED(dctx); UNUSED(rdclass); UNUSED(options); isc_buffer_activeregion(source, &sr); isc_buffer_availableregion(target, &tr); if (sr.length > tr.length) return (ISC_R_NOSPACE); sr2 = sr; /* Zero or more items */ while (sr.length > 0) { if (sr.length < 4) return (ISC_R_UNEXPECTEDEND); afi = uint16_fromregion(&sr); isc_region_consume(&sr, 2); prefix = *sr.base; isc_region_consume(&sr, 1); len = (*sr.base & 0x7f); isc_region_consume(&sr, 1); if (len > sr.length) return (ISC_R_UNEXPECTEDEND); switch (afi) { case 1: if (prefix > 32 || len > 4) return (ISC_R_RANGE); break; case 2: if (prefix > 128 || len > 16) return (ISC_R_RANGE); } if (len > 0 && sr.base[len - 1] == 0) return (DNS_R_FORMERR); isc_region_consume(&sr, len); } isc_buffer_forward(source, sr2.length); return (mem_tobuffer(target, sr2.base, sr2.length)); }
static inline isc_result_t fromwire_unspec(ARGS_FROMWIRE) { isc_region_t sr; REQUIRE(type == dns_rdatatype_unspec); UNUSED(type); UNUSED(rdclass); UNUSED(dctx); UNUSED(options); isc_buffer_activeregion(source, &sr); isc_buffer_forward(source, sr.length); return (mem_tobuffer(target, sr.base, sr.length)); }
static inline isc_result_t towire_sig(ARGS_TOWIRE) { isc_region_t sr; dns_name_t name; dns_offsets_t offsets; REQUIRE(rdata->type == dns_rdatatype_sig); REQUIRE(rdata->length != 0); dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); dns_rdata_toregion(rdata, &sr); /* * type covered: 2 * algorithm: 1 * labels: 1 * original ttl: 4 * signature expiration: 4 * time signed: 4 * key footprint: 2 */ RETERR(mem_tobuffer(target, sr.base, 18)); isc_region_consume(&sr, 18); /* * Signer. */ dns_name_init(&name, offsets); dns_name_fromregion(&name, &sr); isc_region_consume(&sr, name_length(&name)); RETERR(dns_name_towire(&name, cctx, target)); /* * Signature. */ return (mem_tobuffer(target, sr.base, sr.length)); }
static inline isc_result_t fromstruct_nid(ARGS_FROMSTRUCT) { dns_rdata_nid_t *nid = source; REQUIRE(type == 104); REQUIRE(source != NULL); REQUIRE(nid->common.rdtype == type); REQUIRE(nid->common.rdclass == rdclass); UNUSED(type); UNUSED(rdclass); RETERR(uint16_tobuffer(nid->pref, target)); return (mem_tobuffer(target, nid->nid, sizeof(nid->nid))); }
static inline isc_result_t fromstruct_null(ARGS_FROMSTRUCT) { dns_rdata_null_t *null = source; REQUIRE(type == 10); REQUIRE(source != NULL); REQUIRE(null->common.rdtype == type); REQUIRE(null->common.rdclass == rdclass); REQUIRE(null->data != NULL || null->length == 0); UNUSED(type); UNUSED(rdclass); return (mem_tobuffer(target, null->data, null->length)); }
static inline isc_result_t fromstruct_unspec(ARGS_FROMSTRUCT) { dns_rdata_unspec_t *unspec = source; REQUIRE(type == dns_rdatatype_unspec); REQUIRE(source != NULL); REQUIRE(unspec->common.rdtype == type); REQUIRE(unspec->common.rdclass == rdclass); REQUIRE(unspec->data != NULL || unspec->datalen == 0); UNUSED(type); UNUSED(rdclass); return (mem_tobuffer(target, unspec->data, unspec->datalen)); }
static inline isc_result_t fromstruct_l64(ARGS_FROMSTRUCT) { dns_rdata_l64_t *l64 = source; REQUIRE(type == 106); REQUIRE(source != NULL); REQUIRE(l64->common.rdtype == type); REQUIRE(l64->common.rdclass == rdclass); UNUSED(type); UNUSED(rdclass); RETERR(uint16_tobuffer(l64->pref, target)); return (mem_tobuffer(target, l64->l64, sizeof(l64->l64))); }
static inline isc_result_t fromstruct_in_aaaa (ARGS_FROMSTRUCT) { dns_rdata_in_aaaa_t *aaaa = source; REQUIRE (type == 28); REQUIRE (rdclass == 1); REQUIRE (source != NULL); REQUIRE (aaaa->common.rdtype == type); REQUIRE (aaaa->common.rdclass == rdclass); UNUSED (type); UNUSED (rdclass); return (mem_tobuffer (target, aaaa->in6_addr.s6_addr, 16)); }
static inline isc_result_t fromwire_ds(ARGS_FROMWIRE) { isc_region_t sr; REQUIRE(type == 43); UNUSED(type); UNUSED(rdclass); UNUSED(dctx); UNUSED(options); isc_buffer_activeregion(source, &sr); /* * Check digest lengths if we know them. */ if (sr.length < 4 || (sr.base[3] == DNS_DSDIGEST_SHA1 && sr.length < 4 + ISC_SHA1_DIGESTLENGTH) || (sr.base[3] == DNS_DSDIGEST_SHA256 && sr.length < 4 + ISC_SHA256_DIGESTLENGTH) || #ifdef ISC_GOST_DIGESTLENGTH (sr.base[3] == DNS_DSDIGEST_GOST && sr.length < 4 + ISC_GOST_DIGESTLENGTH) || #endif (sr.base[3] == DNS_DSDIGEST_SHA384 && sr.length < 4 + ISC_SHA384_DIGESTLENGTH)) return (ISC_R_UNEXPECTEDEND); /* * Only copy digest lengths if we know them. * If there is extra data dns_rdata_fromwire() will * detect that. */ if (sr.base[3] == DNS_DSDIGEST_SHA1) sr.length = 4 + ISC_SHA1_DIGESTLENGTH; else if (sr.base[3] == DNS_DSDIGEST_SHA256) sr.length = 4 + ISC_SHA256_DIGESTLENGTH; #ifdef ISC_GOST_DIGESTLENGTH else if (sr.base[3] == DNS_DSDIGEST_GOST) sr.length = 4 + ISC_GOST_DIGESTLENGTH; #endif else if (sr.base[3] == DNS_DSDIGEST_SHA384) sr.length = 4 + ISC_SHA384_DIGESTLENGTH; isc_buffer_forward(source, sr.length); return (mem_tobuffer(target, sr.base, sr.length)); }
static inline isc_result_t fromstruct_in_dhcid (ARGS_FROMSTRUCT) { dns_rdata_in_dhcid_t *dhcid = source; REQUIRE (type == 49); REQUIRE (rdclass == 1); REQUIRE (source != NULL); REQUIRE (dhcid->common.rdtype == type); REQUIRE (dhcid->common.rdclass == rdclass); REQUIRE (dhcid->length != 0); UNUSED (type); UNUSED (rdclass); return (mem_tobuffer (target, dhcid->dhcid, dhcid->length)); }
static inline isc_result_t fromstruct_in_nsap(ARGS_FROMSTRUCT) { dns_rdata_in_nsap_t *nsap = source; REQUIRE(type == 22); REQUIRE(rdclass == 1); REQUIRE(source != NULL); REQUIRE(nsap->common.rdtype == type); REQUIRE(nsap->common.rdclass == rdclass); REQUIRE(nsap->nsap != NULL || nsap->nsap_len == 0); UNUSED(type); UNUSED(rdclass); return (mem_tobuffer(target, nsap->nsap, nsap->nsap_len)); }
static inline isc_result_t fromtext_in_nsap(ARGS_FROMTEXT) { isc_token_t token; isc_textregion_t *sr; int n; int digits; unsigned char c = 0; REQUIRE(type == 22); REQUIRE(rdclass == 1); UNUSED(type); UNUSED(origin); UNUSED(options); UNUSED(rdclass); UNUSED(callbacks); /* 0x<hex.string.with.periods> */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); sr = &token.value.as_textregion; if (sr->length < 2) RETTOK(ISC_R_UNEXPECTEDEND); if (sr->base[0] != '0' || (sr->base[1] != 'x' && sr->base[1] != 'X')) RETTOK(DNS_R_SYNTAX); isc_textregion_consume(sr, 2); digits = 0; n = 0; while (sr->length > 0) { if (sr->base[0] == '.') { isc_textregion_consume(sr, 1); continue; } if ((n = hexvalue(sr->base[0])) == -1) RETTOK(DNS_R_SYNTAX); c <<= 4; c += n; if (++digits == 2) { RETERR(mem_tobuffer(target, &c, 1)); digits = 0; } isc_textregion_consume(sr, 1); } if (digits) RETTOK(ISC_R_UNEXPECTEDEND); return (ISC_R_SUCCESS); }
static inline isc_result_t fromwire_naptr(ARGS_FROMWIRE) { dns_name_t name; isc_region_t sr; unsigned char *regex; REQUIRE(type == dns_rdatatype_naptr); UNUSED(type); UNUSED(rdclass); dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); dns_name_init(&name, NULL); /* * Order, preference. */ isc_buffer_activeregion(source, &sr); if (sr.length < 4) return (ISC_R_UNEXPECTEDEND); RETERR(mem_tobuffer(target, sr.base, 4)); isc_buffer_forward(source, 4); /* * Flags. */ RETERR(txt_fromwire(source, target)); /* * Service. */ RETERR(txt_fromwire(source, target)); /* * Regexp. */ regex = isc_buffer_used(target); RETERR(txt_fromwire(source, target)); RETERR(txt_valid_regex(regex)); /* * Replacement. */ return (dns_name_fromwire(&name, source, dctx, options, target)); }
static inline isc_result_t fromwire_l64(ARGS_FROMWIRE) { isc_region_t sregion; REQUIRE(type == 106); UNUSED(type); UNUSED(options); UNUSED(rdclass); UNUSED(dctx); isc_buffer_activeregion(source, &sregion); if (sregion.length != 10) return (DNS_R_FORMERR); isc_buffer_forward(source, sregion.length); return (mem_tobuffer(target, sregion.base, sregion.length)); }
static inline isc_result_t fromstruct_sshfp(ARGS_FROMSTRUCT) { dns_rdata_sshfp_t *sshfp = source; REQUIRE(type == 44); REQUIRE(source != NULL); REQUIRE(sshfp->common.rdtype == type); REQUIRE(sshfp->common.rdclass == rdclass); UNUSED(type); UNUSED(rdclass); RETERR(uint8_tobuffer(sshfp->algorithm, target)); RETERR(uint8_tobuffer(sshfp->digest_type, target)); return (mem_tobuffer(target, sshfp->digest, sshfp->length)); }
static inline isc_result_t fromtext_caa(ARGS_FROMTEXT) { isc_token_t token; isc_textregion_t tr; isc_uint8_t flags; unsigned int i; REQUIRE(type == 257); UNUSED(type); UNUSED(rdclass); UNUSED(origin); UNUSED(options); UNUSED(callbacks); /* Flags. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, ISC_FALSE)); if (token.value.as_ulong > 255U) RETTOK(ISC_R_RANGE); flags = token.value.as_ulong & 255U; RETERR(uint8_tobuffer(flags, target)); /* * Tag */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, ISC_FALSE)); tr = token.value.as_textregion; for (i = 0; i < tr.length; i++) if (!alphanumeric[(unsigned char) tr.base[i]]) RETTOK(DNS_R_SYNTAX); RETERR(uint8_tobuffer(tr.length, target)); RETERR(mem_tobuffer(target, tr.base, tr.length)); /* * Value */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, ISC_FALSE)); if (token.type != isc_tokentype_qstring && token.type != isc_tokentype_string) RETERR(DNS_R_SYNTAX); RETERR(multitxt_fromtext(&token.value.as_textregion, target)); return (ISC_R_SUCCESS); }
/* * Arguments: ..., [membuf_udata] */ void sys_buffer_write_init (lua_State *L, int idx, struct sys_buffer *sb, char *buf, const size_t buflen) { struct membuf *mb = buf ? mem_tobuffer(L, idx) : checkudata(L, idx, MEM_TYPENAME); if (mb) { sb->ptr.w = mb->data + mb->offset; sb->size = mb->len - mb->offset; sb->mb = mb; } else { sb->ptr.w = buf; sb->size = buflen; sb->mb = NULL; } }
static inline isc_result_t fromwire_keydata(ARGS_FROMWIRE) { isc_region_t sr; REQUIRE(type == 65533); UNUSED(type); UNUSED(rdclass); UNUSED(dctx); UNUSED(options); isc_buffer_activeregion(source, &sr); if (sr.length < 16) return (ISC_R_UNEXPECTEDEND); isc_buffer_forward(source, sr.length); return (mem_tobuffer(target, sr.base, sr.length)); }
/* * Arguments: ..., {string | membuf_udata} */ int sys_buffer_read_init (lua_State *L, int idx, struct sys_buffer *sb) { struct membuf *mb = mem_tobuffer(L, idx); if (mb) { sb->ptr.r = mb->data; sb->size = mb->offset; sb->mb = mb; return 1; } else { sb->ptr.r = lua_tolstring(L, idx, &sb->size); sb->mb = NULL; if (sb->ptr.r) return 1; } return 0; }
static inline isc_result_t fromstruct_cert(ARGS_FROMSTRUCT) { dns_rdata_cert_t *cert = source; REQUIRE(type == 37); REQUIRE(source != NULL); REQUIRE(cert->common.rdtype == type); REQUIRE(cert->common.rdclass == rdclass); UNUSED(type); UNUSED(rdclass); RETERR(uint16_tobuffer(cert->type, target)); RETERR(uint16_tobuffer(cert->key_tag, target)); RETERR(uint8_tobuffer(cert->algorithm, target)); return (mem_tobuffer(target, cert->certificate, cert->length)); }
static inline isc_result_t fromstruct_tlsa(ARGS_FROMSTRUCT) { dns_rdata_tlsa_t *tlsa = source; REQUIRE(type == 52); REQUIRE(source != NULL); REQUIRE(tlsa->common.rdtype == type); REQUIRE(tlsa->common.rdclass == rdclass); UNUSED(type); UNUSED(rdclass); RETERR(uint8_tobuffer(tlsa->usage, target)); RETERR(uint8_tobuffer(tlsa->selector, target)); RETERR(uint8_tobuffer(tlsa->match, target)); return (mem_tobuffer(target, tlsa->data, tlsa->length)); }