Commit 5159c427 authored by Mark Andrews's avatar Mark Andrews
Browse files

153. [func] dns_rdata_tostruct() 'mxtc' is now optional. If 'mctx'

                      is NULL then you need to preserve the 'rdata' until
                      you have finished using the structure as there may be
                      references to the associated memory.  If 'mctx' is non
                      NULL it is guarenteed that there are no references to
                      to memory addsociated with 'rdata'.

                      dns_rdata_freestruct() must be called if 'mctx' was
                      non NULL and may safely be called if 'mctx' was NULL.

Finish implementing 153 for IN specific types.
naptr_35.h some of the lengths should be 8 bits.
parent 3364cad7
153. [func] dns_rdata_tostruct() 'mxtc' is now optional. If 'mctx'
is NULL then you need to preserve the 'rdata' until
you have finished using the structure as there may be
references to the associated memory. If 'mctx' is non
NULL it is guarenteed that there are no references to
to memory addsociated with 'rdata'.
dns_rdata_freestruct() must be called if 'mctx' was
non NULL and may safely be called if 'mctx' was NULL.
152. [bug] keygen dumped core if domain name argument was omitted
from command line.
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: a6_38.c,v 1.27 2000/05/04 22:19:29 gson Exp $ */
/* $Id: a6_38.c,v 1.28 2000/05/05 23:19:58 marka Exp $ */
/* draft-ietf-ipngwg-dns-lookups-03.txt */
......@@ -284,24 +284,59 @@ fromstruct_in_a6(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_in_a6(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)
{
dns_rdata_in_a6_t *a6 = target;
unsigned char octets;
dns_name_t name;
isc_region_t r;
REQUIRE(rdata->type == 38);
REQUIRE(rdata->rdclass == 1);
REQUIRE(target != NULL);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
a6->common.rdclass = rdata->rdclass;
a6->common.rdtype = rdata->type;
ISC_LINK_INIT(&a6->common, link);
return (ISC_R_NOTIMPLEMENTED);
dns_rdata_toregion(rdata, &r);
a6->prefixlen = uint8_fromregion(&r);
isc_region_consume(&r, 1);
memset(a6->in6_addr.s6_addr, 0, sizeof(a6->in6_addr.s6_addr));
/* suffix */
if (a6->prefixlen != 128) {
octets = 16 - a6->prefixlen / 8;
INSIST(r.length >= octets);
memcpy(a6->in6_addr.s6_addr + 16 - octets, r.base, octets);
isc_region_consume(&r, octets);
}
/* prefix */
dns_name_init(&a6->prefix, NULL);
if (a6->prefixlen != 0) {
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &r);
RETERR(name_duporclone(&name, mctx, &a6->prefix));
}
a6->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
freestruct_in_a6(void *source)
{
dns_rdata_in_a6_t *a6 = source;
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE); /*XXX*/
REQUIRE(a6->common.rdclass == 1);
REQUIRE(a6->common.rdtype == 38);
if (a6->mctx == NULL)
return;
UNUSED(source);
if (dns_name_dynamic(&a6->prefix))
dns_name_free(&a6->prefix, a6->mctx);
a6->mctx = NULL;
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: a_1.c,v 1.30 2000/04/28 01:24:13 gson Exp $ */
/* $Id: a_1.c,v 1.31 2000/05/05 23:19:59 marka Exp $ */
/* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
......@@ -172,10 +172,11 @@ tostruct_in_a(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
static inline void
freestruct_in_a(void *source) {
dns_rdata_in_a_t *a = source;
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE); /*XXX*/
UNUSED(source);
REQUIRE(a->common.rdtype = 1);
REQUIRE(a->common.rdclass = 1);
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: aaaa_28.c,v 1.21 2000/04/28 01:24:14 gson Exp $ */
/* $Id: aaaa_28.c,v 1.22 2000/05/05 23:20:01 marka Exp $ */
/* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
......@@ -152,22 +152,33 @@ fromstruct_in_aaaa(dns_rdataclass_t rdclass, dns_rdatatype_t type,
static inline isc_result_t
tostruct_in_aaaa(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
dns_rdata_in_aaaa_t *aaaa = target;
isc_region_t r;
REQUIRE(rdata->type == 28);
REQUIRE(rdata->rdclass == 1);
REQUIRE(target != NULL);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
return (ISC_R_NOTIMPLEMENTED);
aaaa->common.rdclass = rdata->rdclass;
aaaa->common.rdtype = rdata->type;
ISC_LINK_INIT(&aaaa->common, link);
dns_rdata_toregion(rdata, &r);
INSIST(r.length == 16);
memcpy(aaaa->in6_addr.s6_addr, r.base, 16);
return (ISC_R_SUCCESS);
}
static inline void
freestruct_in_aaaa(void *source) {
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE); /*XXX*/
dns_rdata_in_aaaa_t *aaaa = source;
UNUSED(source);
REQUIRE(source != NULL);
REQUIRE(aaaa->common.rdclass == 1);
REQUIRE(aaaa->common.rdtype == 28);
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: kx_36.c,v 1.23 2000/05/04 22:19:30 gson Exp $ */
/* $Id: kx_36.c,v 1.24 2000/05/05 23:20:02 marka Exp $ */
/* Reviewed: Thu Mar 16 17:24:54 PST 2000 by explorer */
......@@ -178,12 +178,10 @@ tostruct_in_kx(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)
isc_region_t region;
dns_rdata_in_kx_t *kx = target;
dns_name_t name;
isc_result_t result;
REQUIRE(rdata->type == 36);
REQUIRE(rdata->rdclass == 1);
REQUIRE(target != NULL);
REQUIRE(mctx != NULL);
kx->common.rdclass = rdata->rdclass;
kx->common.rdtype = rdata->type;
......@@ -196,12 +194,10 @@ tostruct_in_kx(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)
isc_region_consume(&region, 2);
dns_name_fromregion(&name, &region);
kx->mctx = mctx;
dns_name_init(&kx->exchange, NULL);
result = dns_name_dup(&name, kx->mctx, &kx->exchange);
if (result != ISC_R_SUCCESS)
kx->mctx = NULL;
return (result);
RETERR(name_duporclone(&name, mctx, &kx->exchange));
kx->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
......@@ -210,6 +206,11 @@ freestruct_in_kx(void *source)
dns_rdata_in_kx_t *kx = source;
REQUIRE(source != NULL);
REQUIRE(kx->common.rdclass == 1);
REQUIRE(kx->common.rdtype == 36);
if (kx->mctx == NULL)
return;
dns_name_free(&kx->exchange, kx->mctx);
kx->mctx = NULL;
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: naptr_35.c,v 1.23 2000/05/04 22:19:31 gson Exp $ */
/* $Id: naptr_35.c,v 1.24 2000/05/05 23:20:03 marka Exp $ */
/* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
......@@ -256,22 +256,94 @@ fromstruct_in_naptr(dns_rdataclass_t rdclass, dns_rdatatype_t type,
static inline isc_result_t
tostruct_in_naptr(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
dns_rdata_in_naptr_t *naptr = target;
isc_region_t r;
isc_result_t result;
dns_name_t name;
REQUIRE(rdata->type == 35);
REQUIRE(rdata->rdclass == 1);
REQUIRE(target != NULL);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
naptr->common.rdclass = rdata->rdclass;
naptr->common.rdtype = rdata->type;
ISC_LINK_INIT(&naptr->common, link);
naptr->flags = NULL;
naptr->service = NULL;
naptr->regexp = NULL;
dns_rdata_toregion(rdata, &r);
naptr->order = uint16_fromregion(&r);
isc_region_consume(&r, 2);
naptr->preference = uint16_fromregion(&r);
isc_region_consume(&r, 2);
naptr->flags_len = uint8_fromregion(&r);
isc_region_consume(&r, 1);
if (naptr->flags_len != 0) {
naptr->flags = mem_maybedup(mctx, r.base, naptr->flags_len);
if (naptr->flags == NULL)
goto cleanup;
isc_region_consume(&r, naptr->flags_len);
}
naptr->service_len = uint8_fromregion(&r);
isc_region_consume(&r, 1);
if (naptr->service_len != 0) {
naptr->service = mem_maybedup(mctx, r.base,
naptr->service_len);
if (naptr->service == NULL)
goto cleanup;
isc_region_consume(&r, naptr->service_len);
}
naptr->regexp_len = uint8_fromregion(&r);
isc_region_consume(&r, 1);
if (naptr->regexp_len != 0) {
naptr->regexp = mem_maybedup(mctx, r.base, naptr->regexp_len);
if (naptr->regexp == NULL)
goto cleanup;
isc_region_consume(&r, naptr->regexp_len);
}
result = name_duporclone(&name, mctx, &naptr->replacement);
if (result != ISC_R_SUCCESS)
goto cleanup;
naptr->mctx = mctx;
return (ISC_R_NOTIMPLEMENTED);
cleanup:
if (mctx != NULL && naptr->flags != NULL)
isc_mem_free(mctx, naptr->flags);
if (mctx != NULL && naptr->service != NULL)
isc_mem_free(mctx, naptr->service);
if (mctx != NULL && naptr->regexp != NULL)
isc_mem_free(mctx, naptr->regexp);
return (ISC_R_NOMEMORY);
}
static inline void
freestruct_in_naptr(void *source) {
dns_rdata_in_naptr_t *naptr = source;
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE);
UNUSED(source);
REQUIRE(naptr->common.rdclass == 1);
REQUIRE(naptr->common.rdtype == 35);
if (naptr->mctx == NULL)
return;
if (naptr->flags != NULL)
isc_mem_free(naptr->mctx, naptr->flags);
if (naptr->service != NULL)
isc_mem_free(naptr->mctx, naptr->service);
if (naptr->regexp != NULL)
isc_mem_free(naptr->mctx, naptr->regexp);
dns_name_free(&naptr->replacement, naptr->mctx);
naptr->mctx = NULL;
}
static inline isc_result_t
......
......@@ -18,7 +18,7 @@
#ifndef IN_1_NAPTR_35_H
#define IN_1_NAPTR_35_H 1
/* $Id: naptr_35.h,v 1.13 2000/04/29 02:01:56 tale Exp $ */
/* $Id: naptr_35.h,v 1.14 2000/05/05 23:20:04 marka Exp $ */
/* RFC 2168 */
......@@ -28,11 +28,11 @@ typedef struct dns_rdata_in_naptr {
isc_uint16_t order;
isc_uint16_t preference;
char *flags;
isc_uint16_t flags_len;
isc_uint8_t flags_len;
char *service;
isc_uint16_t service_len;
isc_uint8_t service_len;
char *regexp;
isc_uint16_t regexp_len;
isc_uint8_t regexp_len;
dns_name_t replacement;
} dns_rdata_in_naptr_t;
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: nsap-ptr_23.c,v 1.19 2000/05/04 22:19:32 gson Exp $ */
/* $Id: nsap-ptr_23.c,v 1.20 2000/05/05 23:20:06 marka Exp $ */
/* Reviewed: Fri Mar 17 10:16:02 PST 2000 by gson */
......@@ -143,23 +143,40 @@ fromstruct_in_nsap_ptr(dns_rdataclass_t rdclass, dns_rdatatype_t type,
static inline isc_result_t
tostruct_in_nsap_ptr(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
isc_region_t region;
dns_rdata_in_nsap_ptr_t *nsap_ptr = target;
dns_name_t name;
REQUIRE(rdata->type == 23);
REQUIRE(rdata->rdclass == 1);
REQUIRE(target != NULL);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
nsap_ptr->common.rdclass = rdata->rdclass;
nsap_ptr->common.rdtype = rdata->type;
ISC_LINK_INIT(&nsap_ptr->common, link);
return (ISC_R_NOTIMPLEMENTED);
dns_name_init(&name, NULL);
dns_rdata_toregion(rdata, &region);
dns_name_fromregion(&name, &region);
dns_name_init(&nsap_ptr->owner, NULL);
RETERR(name_duporclone(&name, mctx, &nsap_ptr->owner));
nsap_ptr->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
freestruct_in_nsap_ptr(void *source) {
dns_rdata_in_nsap_ptr_t *nsap_ptr = source;
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE);
REQUIRE(nsap_ptr->common.rdclass == 1);
REQUIRE(nsap_ptr->common.rdtype == 23);
UNUSED(source);
if (nsap_ptr->mctx == NULL)
return;
dns_name_free(&nsap_ptr->owner, nsap_ptr->mctx);
nsap_ptr->mctx = NULL;
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: nsap_22.c,v 1.18 2000/04/28 01:24:15 gson Exp $ */
/* $Id: nsap_22.c,v 1.19 2000/05/05 23:20:07 marka Exp $ */
/* Reviewed: Fri Mar 17 10:41:07 PST 2000 by gson */
......@@ -161,22 +161,44 @@ fromstruct_in_nsap(dns_rdataclass_t rdclass, dns_rdatatype_t type,
static inline isc_result_t
tostruct_in_nsap(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
dns_rdata_in_nsap_t *nsap = target;
isc_region_t r;
REQUIRE(rdata->type == 22);
REQUIRE(rdata->rdclass == 1);
REQUIRE(target != NULL);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
nsap->common.rdclass = rdata->rdclass;
nsap->common.rdtype = rdata->type;
ISC_LINK_INIT(&nsap->common, link);
return (ISC_R_NOTIMPLEMENTED);
dns_rdata_toregion(rdata, &r);
nsap->nsap_len = r.length;
if (nsap->nsap_len != 0) {
nsap->nsap = mem_maybedup(mctx, r.base, r.length);
if (nsap->nsap == NULL)
return (ISC_R_NOMEMORY);
} else
nsap->nsap = NULL;
nsap->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
freestruct_in_nsap(void *source) {
dns_rdata_in_nsap_t *nsap = source;
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE);
REQUIRE(nsap->common.rdclass == 1);
REQUIRE(nsap->common.rdtype == 22);
UNUSED(source);
if (nsap->mctx == NULL)
return;
if (nsap->nsap != NULL)
isc_mem_free(nsap->mctx, nsap->nsap);
nsap->mctx = NULL;
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: px_26.c,v 1.20 2000/05/04 22:19:33 gson Exp $ */
/* $Id: px_26.c,v 1.21 2000/05/05 23:20:08 marka Exp $ */
/* Reviewed: Mon Mar 20 10:44:27 PST 2000 */
......@@ -214,16 +214,14 @@ fromstruct_in_px(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_in_px(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
isc_region_t region;
isc_region_t nr;
dns_rdata_in_px_t *px = target;
dns_name_t name;
isc_region_t region;
isc_result_t result;
REQUIRE(rdata->type == 26);
REQUIRE(rdata->rdclass == 1);
REQUIRE(target != NULL);
REQUIRE(mctx != NULL);
px->common.rdclass = rdata->rdclass;
px->common.rdtype = rdata->type;
......@@ -236,23 +234,22 @@ tostruct_in_px(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
isc_region_consume(&region, 2);
dns_name_fromregion(&name, &region);
dns_name_toregion(&name, &nr);
isc_region_consume(&region, nr.length);
px->mctx = mctx;
dns_name_init(&px->map822, NULL);
result = dns_name_dup(&name, px->mctx, &px->map822);
if (result != ISC_R_SUCCESS) {
px->mctx = NULL;
return (result);
}
RETERR(name_duporclone(&name, mctx, &px->map822));
isc_region_consume(&region, name_length(&px->map822));
dns_name_init(&px->mapx400, NULL);
result = dns_name_dup(&name, px->mctx, &px->map822);
if (result != ISC_R_SUCCESS) {
dns_name_free(&px->map822, px->mctx);
px->mctx = NULL;
}
result = name_duporclone(&name, mctx, &px->mapx400);
if (result != ISC_R_SUCCESS)
goto cleanup;
px->mctx = mctx;
return (result);
cleanup:
dns_name_free(&px->map822, mctx);
return (ISC_R_NOMEMORY);
}
static inline void
......@@ -260,6 +257,11 @@ freestruct_in_px(void *source) {
dns_rdata_in_px_t *px = source;
REQUIRE(source != NULL);
REQUIRE(px->common.rdclass == 1);
REQUIRE(px->common.rdtype == 26);
if (px->mctx == NULL)
return;
dns_name_free(&px->map822, px->mctx);
dns_name_free(&px->mapx400, px->mctx);
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: srv_33.c,v 1.21 2000/05/04 22:19:34 gson Exp $ */
/* $Id: srv_33.c,v 1.22 2000/05/05 23:20:09 marka Exp $ */
/* Reviewed: Fri Mar 17 13:01:00 PST 2000 by bwelling */
......@@ -197,22 +197,46 @@ fromstruct_in_srv(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_in_srv(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
REQUIRE(rdata->type == 33);
isc_region_t region;
dns_rdata_in_srv_t *srv = target;
dns_name_t name;
REQUIRE(rdata->rdclass == 1);
REQUIRE(rdata->type == 33);
REQUIRE(target != NULL);
UNUSED(rdata);
UNUSED(target);
UNUSED(mctx);
srv->common.rdclass = rdata->rdclass;
srv->common.rdtype = rdata->type;
ISC_LINK_INIT(&srv->common, link);
return (ISC_R_NOTIMPLEMENTED);
dns_name_init(&name, NULL);
dns_rdata_toregion(rdata, &region);
srv->priority = uint16_fromregion(&region);
isc_region_consume(&region, 2);
srv->weight = uint16_fromregion(&region);
isc_region_consume(&region, 2);
srv->port = uint16_fromregion(&region);
isc_region_consume(&region, 2);
dns_name_fromregion(&name, &region);
dns_name_init(&srv->target, NULL);
RETERR(name_duporclone(&name, mctx, &srv->target));
srv->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
freestruct_in_srv(void *source) {
dns_rdata_in_srv_t *srv = source;
REQUIRE(source != NULL);
REQUIRE(ISC_FALSE); /*XXX*/
REQUIRE(srv->common.rdclass == 1);
REQUIRE(srv->common.rdtype == 33);
UNUSED(source);
if (srv->mctx == NULL)
return;
dns_name_free(&srv->target, srv->mctx);
srv->mctx = NULL;
}
static inline isc_result_t
......
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: wks_11.c,v 1.26 2000/04/28 01:24:17 gson Exp $ */
/* $Id: wks_11.c,v 1.27 2000/05/05 23:20:10 marka Exp $ */
/* Reviewed: Fri Mar 17 15:01:49 PST 2000 by explorer */
......@@ -234,23 +234,49 @@ fromstruct_in_wks(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
static inline isc_result_t
tostruct_in_wks(dns_rdata_t *rdata, void *target, isc_mem_t *mctx)