Commit 20dbb03b authored by Bob Halley's avatar Bob Halley
Browse files

compare did not handle some cases; add digest support

parent d692d999
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: a6_38.c,v 1.13 1999/08/12 01:32:32 halley Exp $ */
/* $Id: a6_38.c,v 1.14 1999/08/31 22:03:59 halley Exp $ */
/* draft-ietf-ipngwg-dns-lookups-03.txt */
......@@ -26,10 +26,6 @@
#include <isc/net.h>
#ifndef MAX
#define MAX(A, B) ((A > B) ? (A) : (B))
#endif
static inline dns_result_t
fromtext_in_a6(dns_rdataclass_t rdclass, dns_rdatatype_t type,
isc_lex_t *lexer, dns_name_t *origin,
......@@ -213,7 +209,7 @@ towire_in_a6(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
static inline int
compare_in_a6(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
int result;
unsigned char prefixlen;
unsigned char prefixlen1, prefixlen2;
unsigned char octets;
dns_name_t name1;
dns_name_t name2;
......@@ -227,15 +223,33 @@ compare_in_a6(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
dns_rdata_toregion(rdata1, &region1);
dns_rdata_toregion(rdata2, &region2);
prefixlen = MAX(region1.base[0], region2.base[0]);
octets = 1 + 16 - prefixlen / 8;
result = memcmp(region1.base, region2.base, octets);
if (result != 0)
result = (result < 0) ? -1 : 1;
isc_region_consume(&region1, octets);
isc_region_consume(&region2, octets);
prefixlen1 = region1.base[0];
prefixlen2 = region2.base[0];
isc_region_consume(&region1, 1);
isc_region_consume(&region2, 1);
if (prefixlen1 < prefixlen2)
return (-1);
else if (prefixlen1 > prefixlen2)
return (1);
/*
* Prefix lengths are equal.
*/
octets = 16 - prefixlen1 / 8;
if (octets > 0) {
result = memcmp(region1.base, region2.base, octets);
if (result < 0)
return (-1);
else if (result > 0)
return (1);
/*
* Address suffixes are equal.
*/
if (prefixlen1 == 0)
return (result);
isc_region_consume(&region1, octets);
isc_region_consume(&region2, octets);
}
dns_name_init(&name1, NULL);
dns_name_init(&name2, NULL);
......@@ -289,4 +303,32 @@ additionaldata_in_a6(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
return (DNS_R_SUCCESS);
}
static inline dns_result_t
digest_in_a6(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
isc_region_t r1, r2;
unsigned char prefixlen, octets;
dns_result_t result;
dns_name_t name;
REQUIRE(rdata->type == 38);
REQUIRE(rdata->rdclass == 1);
dns_rdata_toregion(rdata, &r1);
r2 = r1;
prefixlen = r1.base[0];
octets = 1 + 16 - prefixlen / 8;
r1.length = octets;
result = (digest)(arg, &r1);
if (result != DNS_R_SUCCESS)
return (result);
if (prefixlen == 0)
return (DNS_R_SUCCESS);
isc_region_consume(&r2, octets);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &r2);
return (dns_name_digest(&name, digest, arg));
}
#endif /* RDATA_IN_1_A6_38_C */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: a_1.c,v 1.18 1999/08/12 01:32:32 halley Exp $ */
/* $Id: a_1.c,v 1.19 1999/08/31 22:03:59 halley Exp $ */
#ifndef RDATA_IN_1_A_1_C
#define RDATA_IN_1_A_1_C
......@@ -179,4 +179,16 @@ additionaldata_in_a(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
return (DNS_R_SUCCESS);
}
static inline dns_result_t
digest_in_a(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
isc_region_t r;
REQUIRE(rdata->type == 1);
REQUIRE(rdata->rdclass == 1);
dns_rdata_toregion(rdata, &r);
return ((digest)(arg, &r));
}
#endif /* RDATA_IN_1_A_1_C */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: aaaa_28.c,v 1.12 1999/08/12 01:32:32 halley Exp $ */
/* $Id: aaaa_28.c,v 1.13 1999/08/31 22:03:59 halley Exp $ */
/* RFC 1886 */
......@@ -180,4 +180,16 @@ additionaldata_in_aaaa(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
return (DNS_R_SUCCESS);
}
static inline dns_result_t
digest_in_aaaa(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
isc_region_t r;
REQUIRE(rdata->type == 28);
REQUIRE(rdata->rdclass == 1);
dns_rdata_toregion(rdata, &r);
return ((digest)(arg, &r));
}
#endif /* RDATA_IN_1_AAAA_28_C */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: kx_36.c,v 1.11 1999/08/12 01:32:32 halley Exp $ */
/* $Id: kx_36.c,v 1.12 1999/08/31 22:03:59 halley Exp $ */
/* RFC 2230 */
......@@ -206,4 +206,25 @@ additionaldata_in_kx(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
return ((add)(arg, &name, dns_rdatatype_a));
}
static inline dns_result_t
digest_in_kx(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
isc_region_t r1, r2;
isc_result_t result;
dns_name_t name;
REQUIRE(rdata->type == 36);
REQUIRE(rdata->rdclass == 1);
dns_rdata_toregion(rdata, &r1);
r2 = r1;
isc_region_consume(&r2, 2);
r1.length = 2;
result = (digest)(arg, &r1);
if (result != ISC_R_SUCCESS)
return (result);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &r2);
return (dns_name_digest(&name, digest, arg));
}
#endif /* RDATA_GENERIC_KX_15_C */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: naptr_35.c,v 1.11 1999/08/12 01:32:32 halley Exp $ */
/* $Id: naptr_35.c,v 1.12 1999/08/31 22:04:00 halley Exp $ */
/* RFC 2168 */
......@@ -291,4 +291,53 @@ additionaldata_in_naptr(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
return (DNS_R_SUCCESS);
}
static inline dns_result_t
digest_in_naptr(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
isc_region_t r1, r2;
unsigned int length, n;
dns_result_t result;
dns_name_t name;
REQUIRE(rdata->type == 35);
REQUIRE(rdata->rdclass == 1);
dns_rdata_toregion(rdata, &r1);
r2 = r1;
length = 0;
/* priority, weight */
length += 4;
isc_region_consume(&r2, 4);
/* flags */
n = r2.base[0] + 1;
length += n;
isc_region_consume(&r2, n);
/* service */
n = r2.base[0] + 1;
length += n;
isc_region_consume(&r2, n);
/* regexp */
n = r2.base[0] + 1;
length += n;
isc_region_consume(&r2, n);
/*
* Digest the RR up to the replacement name.
*/
r1.length = length;
result = (digest)(arg, &r1);
if (result != DNS_R_SUCCESS)
return (result);
/* replacement */
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &r2);
return (dns_name_digest(&name, digest, arg));
}
#endif /* RDATA_IN_1_NAPTR_35_C */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: nsap-ptr_23.c,v 1.9 1999/08/12 01:32:32 halley Exp $ */
/* $Id: nsap-ptr_23.c,v 1.10 1999/08/31 22:04:00 halley Exp $ */
/* RFC 1348 */
......@@ -176,4 +176,19 @@ additionaldata_in_nsap_ptr(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
return (DNS_R_SUCCESS);
}
static inline dns_result_t
digest_in_nsap_ptr(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
isc_region_t r;
dns_name_t name;
REQUIRE(rdata->type == 23);
REQUIRE(rdata->rdclass == 1);
dns_rdata_toregion(rdata, &r);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &r);
return (dns_name_digest(&name, digest, arg));
}
#endif /* RDATA_IN_1_NSAP_PTR_23_C */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: nsap_22.c,v 1.8 1999/08/12 01:32:32 halley Exp $ */
/* $Id: nsap_22.c,v 1.9 1999/08/31 22:04:00 halley Exp $ */
/* RFC 1706 */
......@@ -185,4 +185,16 @@ additionaldata_in_nsap(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
return (DNS_R_SUCCESS);
}
static inline dns_result_t
digest_in_nsap(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
isc_region_t r;
REQUIRE(rdata->type == 22);
REQUIRE(rdata->rdclass == 1);
dns_rdata_toregion(rdata, &r);
return ((digest)(arg, &r));
}
#endif /* RDATA_IN_1_NSAP_22_C */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: px_26.c,v 1.9 1999/08/12 01:32:32 halley Exp $ */
/* $Id: px_26.c,v 1.10 1999/08/31 22:04:00 halley Exp $ */
/* RFC 2163 */
......@@ -243,4 +243,32 @@ additionaldata_in_px(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
return (DNS_R_SUCCESS);
}
static inline dns_result_t
digest_in_px(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
isc_region_t r1, r2;
dns_name_t name;
dns_result_t result;
REQUIRE(rdata->type == 26);
REQUIRE(rdata->rdclass == 1);
dns_rdata_toregion(rdata, &r1);
r2 = r1;
isc_region_consume(&r2, 2);
r1.length = 2;
result = (digest)(arg, &r1);
if (result != DNS_R_SUCCESS)
return (result);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &r2);
result = dns_name_digest(&name, digest, arg);
if (result != DNS_R_SUCCESS)
return (result);
isc_region_consume(&r2, name_length(&name));
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &r2);
return (dns_name_digest(&name, digest, arg));
}
#endif /* RDATA_IN_1_PX_26_C */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: srv_33.c,v 1.10 1999/08/12 01:32:33 halley Exp $ */
/* $Id: srv_33.c,v 1.11 1999/08/31 22:04:00 halley Exp $ */
/* RFC 2052 bis */
......@@ -236,4 +236,25 @@ additionaldata_in_srv(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
return ((add)(arg, &name, dns_rdatatype_a));
}
static inline dns_result_t
digest_in_srv(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
isc_region_t r1, r2;
isc_result_t result;
dns_name_t name;
REQUIRE(rdata->type == 33);
REQUIRE(rdata->rdclass == 1);
dns_rdata_toregion(rdata, &r1);
r2 = r1;
isc_region_consume(&r2, 6);
r1.length = 6;
result = (digest)(arg, &r1);
if (result != ISC_R_SUCCESS)
return (result);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &r2);
return (dns_name_digest(&name, digest, arg));
}
#endif /* RDATA_IN_1_SRV_33_C */
......@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: wks_11.c,v 1.15 1999/08/12 01:32:33 halley Exp $ */
/* $Id: wks_11.c,v 1.16 1999/08/31 22:04:00 halley Exp $ */
#ifndef RDATA_IN_1_WKS_11_C
#define RDATA_IN_1_WKS_11_C
......@@ -252,4 +252,16 @@ additionaldata_in_wks(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
return (DNS_R_SUCCESS);
}
static inline dns_result_t
digest_in_wks(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
isc_region_t r;
REQUIRE(rdata->type == 11);
REQUIRE(rdata->rdclass == 1);
dns_rdata_toregion(rdata, &r);
return ((digest)(arg, &r));
}
#endif /* RDATA_IN_1_WKS_11_C */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment