From: Willem Toorop Date: Sat, 17 Nov 2012 23:22:53 +0000 (+0000) Subject: Support for RFC6742 Resource Records for the Identifier-Locator Network Protocol... X-Git-Tag: release-1.6.17rc1~166 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0851fd1d6d988e4c0719d742198907fc124e79e;p=thirdparty%2Fldns.git Support for RFC6742 Resource Records for the Identifier-Locator Network Protocol (ILNP): NID, L32, L64 and LP. There was a need to add a new rdf type representing 64bits represented as 4 hexidecimal shorts seperated by colons. Proper testing still pending. --- diff --git a/contrib/python/ldns_rdf.i b/contrib/python/ldns_rdf.i index edff4d62..8305f26b 100644 --- a/contrib/python/ldns_rdf.i +++ b/contrib/python/ldns_rdf.i @@ -216,6 +216,7 @@ case LDNS_RDF_TYPE_NSEC3_SALT: return "NSEC3_SALT"; case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER: return "NSEC3_NEXT_OWNER"; + case LDNS_RDF_TYPE_4_SHORTS: return "4_SHORTS"; } } return 0; diff --git a/error.c b/error.c index 80b0c47f..2ebc10e7 100644 --- a/error.c +++ b/error.c @@ -125,6 +125,8 @@ ldns_lookup_table ldns_error_str[] = { { LDNS_STATUS_DANE_PKIX_NO_SELF_SIGNED_TRUST_ANCHOR, "The validation path " "did not end in a self-signed certificate" }, + { LDNS_STATUS_INVALID_4_SHORTS, + "Conversion error, 4 colon seperated hex numbers expected" }, { 0, NULL } }; diff --git a/host2str.c b/host2str.c index 521e2468..fd763f49 100644 --- a/host2str.c +++ b/host2str.c @@ -1049,6 +1049,16 @@ ldns_rdf2buffer_str_tsig(ldns_buffer *output, const ldns_rdf *rdf) return ldns_rdf2buffer_str_unknown(output, rdf); } +ldns_status +ldns_rdf2buffer_str_4_shorts(ldns_buffer *output, const ldns_rdf *rdf) +{ + ldns_buffer_printf(output,"%.4x:%.4x:%.4d:%.4x", + ldns_read_uint16(ldns_rdf_data(rdf)), + ldns_read_uint16(ldns_rdf_data(rdf)+2), + ldns_read_uint16(ldns_rdf_data(rdf)+4), + ldns_read_uint16(ldns_rdf_data(rdf)+6)); + return ldns_buffer_status(output); +} ldns_status ldns_rdf2buffer_str(ldns_buffer *buffer, const ldns_rdf *rdf) @@ -1148,6 +1158,9 @@ ldns_rdf2buffer_str(ldns_buffer *buffer, const ldns_rdf *rdf) case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER: res = ldns_rdf2buffer_str_b32_ext(buffer, rdf); break; + case LDNS_RDF_TYPE_4_SHORTS: + res = ldns_rdf2buffer_str_4_shorts(buffer, rdf); + break; } } else { /** This will write mangled RRs */ diff --git a/ldns/error.h b/ldns/error.h index fee69a12..9d1ca946 100644 --- a/ldns/error.h +++ b/ldns/error.h @@ -118,7 +118,8 @@ enum ldns_enum_status { LDNS_STATUS_DANE_NON_CA_CERTIFICATE, LDNS_STATUS_DANE_PKIX_DID_NOT_VALIDATE, LDNS_STATUS_DANE_PKIX_NO_SELF_SIGNED_TRUST_ANCHOR, - LDNS_STATUS_EXISTS_ERR + LDNS_STATUS_EXISTS_ERR, + LDNS_STATUS_INVALID_4_SHORTS }; typedef enum ldns_enum_status ldns_status; diff --git a/ldns/host2str.h b/ldns/host2str.h index bbf93276..b3046c29 100644 --- a/ldns/host2str.h +++ b/ldns/host2str.h @@ -518,6 +518,16 @@ ldns_status ldns_rdf2buffer_str_int32(ldns_buffer *output, const ldns_rdf *rdf); */ ldns_status ldns_rdf2buffer_str_time(ldns_buffer *output, const ldns_rdf *rdf); +/** + * Converts an LDNS_RDF_TYPE_4_SHORTS rdata element to 4 hexadecimal numbers + * seperated by colons and adds it to the output buffer + * \param[in] *rdf The rdata to convert + * \param[in] *output The buffer to add the data to + * \return LDNS_STATUS_OK on success, and error status on failure + */ +ldns_status ldns_rdf2buffer_str_4_shorts(ldns_buffer *output, + const ldns_rdf *rdf); + /** * Converts the data in the rdata field to presentation format and * returns that as a char *. diff --git a/ldns/rdata.h b/ldns/rdata.h index 229a4d4c..2fa080de 100644 --- a/ldns/rdata.h +++ b/ldns/rdata.h @@ -34,6 +34,7 @@ extern "C" { #define LDNS_RDF_SIZE_WORD 2 #define LDNS_RDF_SIZE_DOUBLEWORD 4 #define LDNS_RDF_SIZE_6BYTES 6 +#define LDNS_RDF_SIZE_8BYTES 8 #define LDNS_RDF_SIZE_16BYTES 16 #define LDNS_NSEC3_VARS_OPTOUT_MASK 0x01 @@ -104,7 +105,9 @@ enum ldns_enum_rdf_type /** nsec3 hash salt */ LDNS_RDF_TYPE_NSEC3_SALT, /** nsec3 base32 string (with length byte on wire */ - LDNS_RDF_TYPE_NSEC3_NEXT_OWNER + LDNS_RDF_TYPE_NSEC3_NEXT_OWNER, + /** 4 shorts represented as 4 * 16 bit hex numbers seperated by colons */ + LDNS_RDF_TYPE_4_SHORTS }; typedef enum ldns_enum_rdf_type ldns_rdf_type; diff --git a/ldns/rr.h b/ldns/rr.h index 0520dcfe..e29bba9e 100644 --- a/ldns/rr.h +++ b/ldns/rr.h @@ -192,6 +192,11 @@ enum ldns_enum_rr_type LDNS_RR_TYPE_GID = 102, LDNS_RR_TYPE_UNSPEC = 103, + LDNS_RR_TYPE_NID = 104, /* RFC 6742 */ + LDNS_RR_TYPE_L32 = 105, /* RFC 6742 */ + LDNS_RR_TYPE_L64 = 106, /* RFC 6742 */ + LDNS_RR_TYPE_LP = 107, /* RFC 6742 */ + LDNS_RR_TYPE_TSIG = 250, LDNS_RR_TYPE_IXFR = 251, LDNS_RR_TYPE_AXFR = 252, diff --git a/ldns/str2host.h b/ldns/str2host.h index 09416cd2..d62412ab 100644 --- a/ldns/str2host.h +++ b/ldns/str2host.h @@ -244,6 +244,14 @@ ldns_status ldns_str2rdf_ipseckey(ldns_rdf **rd, const char *str); */ ldns_status ldns_str2rdf_dname(ldns_rdf **rd, const char *str); +/** + * convert 4 * 16bit hex seperated by colons into wireformat + * \param[in] rd the rdf where to put the data + * \param[in] str the string to be converted + * \return ldns_status + */ +ldns_status ldns_str2rdf_4_shorts(ldns_rdf **rd, const char *str); + #ifdef __cplusplus } #endif diff --git a/rdata.c b/rdata.c index 8af16a13..19b20793 100644 --- a/rdata.c +++ b/rdata.c @@ -336,6 +336,9 @@ ldns_rdf_new_frm_str(ldns_rdf_type type, const char *str) case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER: status = ldns_str2rdf_b32_ext(&rdf, str); break; + case LDNS_RDF_TYPE_4_SHORTS: + status = ldns_str2rdf_4_shorts(&rdf, str); + break; case LDNS_RDF_TYPE_NONE: default: /* default default ??? */ diff --git a/rr.c b/rr.c index 72076d40..5eba7d6f 100644 --- a/rr.c +++ b/rr.c @@ -1958,6 +1958,22 @@ static const ldns_rdf_type type_tlsa_wireformat[] = { LDNS_RDF_TYPE_INT8, LDNS_RDF_TYPE_HEX }; +static const ldns_rdf_type type_nid_wireformat[] = { + LDNS_RDF_TYPE_INT16, + LDNS_RDF_TYPE_4_SHORTS +}; +static const ldns_rdf_type type_l32_wireformat[] = { + LDNS_RDF_TYPE_INT16, + LDNS_RDF_TYPE_A +}; +static const ldns_rdf_type type_l64_wireformat[] = { + LDNS_RDF_TYPE_INT16, + LDNS_RDF_TYPE_4_SHORTS +}; +static const ldns_rdf_type type_lp_wireformat[] = { + LDNS_RDF_TYPE_INT16, + LDNS_RDF_TYPE_DNAME +}; /** \endcond */ /** \cond */ @@ -2125,10 +2141,14 @@ static ldns_rr_descriptor rdata_field_descriptors[] = { {LDNS_RR_TYPE_NULL, "TYPE101", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, {LDNS_RR_TYPE_NULL, "TYPE102", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, {LDNS_RR_TYPE_NULL, "TYPE103", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, -{LDNS_RR_TYPE_NULL, "TYPE104", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, -{LDNS_RR_TYPE_NULL, "TYPE105", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, -{LDNS_RR_TYPE_NULL, "TYPE106", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, -{LDNS_RR_TYPE_NULL, "TYPE107", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, + /* 104 */ +{LDNS_RR_TYPE_NID, "NID", 2, 2, type_nid_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, + /* 105 */ +{LDNS_RR_TYPE_NID, "L32", 2, 2, type_l32_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, + /* 106 */ +{LDNS_RR_TYPE_NID, "L64", 2, 2, type_l64_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, + /* 107 */ +{LDNS_RR_TYPE_NID, "LP", 2, 2, type_lp_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 1 }, {LDNS_RR_TYPE_NULL, "TYPE108", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, {LDNS_RR_TYPE_NULL, "TYPE109", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, {LDNS_RR_TYPE_NULL, "TYPE110", 1, 1, type_0_wireformat, LDNS_RDF_TYPE_NONE, LDNS_RR_NO_COMPRESS, 0 }, diff --git a/str2host.c b/str2host.c index 51357cc3..bb097537 100644 --- a/str2host.c +++ b/str2host.c @@ -1317,3 +1317,22 @@ ldns_str2rdf_ipseckey(ldns_rdf **rd, const char *str) if(!*rd) return LDNS_STATUS_MEM_ERR; return LDNS_STATUS_OK; } + +ldns_status +ldns_str2rdf_4_shorts(ldns_rdf **rd, const char *str) +{ + unsigned int a, b, c, d; + uint16_t shorts[4]; + + if (sscanf(str, "%x:%x:%x:%x", &a, &b, &c, &d) == EOF) { + return LDNS_STATUS_INVALID_4_SHORTS; + } else { + shorts[0] = htons(shorts[0]); + shorts[1] = htons(shorts[1]); + shorts[2] = htons(shorts[2]); + shorts[3] = htons(shorts[3]); + *rd = ldns_rdf_new_frm_data( + LDNS_RDF_TYPE_4_SHORTS, 4 * sizeof(uint16_t), &shorts); + } + return *rd ? LDNS_STATUS_OK : LDNS_STATUS_MEM_ERR; +} diff --git a/wire2host.c b/wire2host.c index e87fcdf5..ef6e5c3b 100644 --- a/wire2host.c +++ b/wire2host.c @@ -212,6 +212,9 @@ ldns_wire2rdf(ldns_rr *rr, const uint8_t *wire, size_t max, size_t *pos) case LDNS_RDF_TYPE_TSIGTIME: cur_rdf_length = LDNS_RDF_SIZE_6BYTES; break; + case LDNS_RDF_TYPE_4_SHORTS: + cur_rdf_length = LDNS_RDF_SIZE_8BYTES; + break; case LDNS_RDF_TYPE_AAAA: cur_rdf_length = LDNS_RDF_SIZE_16BYTES; break;