]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
libknot: add knot_rdata_to_canonical()
authorDaniel Salzman <daniel.salzman@nic.cz>
Sat, 7 Jun 2025 15:13:33 +0000 (17:13 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Fri, 12 Sep 2025 14:50:40 +0000 (16:50 +0200)
distro/pkg/deb/libknot16.symbols
src/libknot/rdata.h
src/libknot/rrset.c
src/libknot/rrset.h

index 026fadc79ed44fb82c14b7d3f4c34c18a50db6b1..2976c27500d08dc43fef972ef787ccf5592e2ed2 100644 (file)
@@ -145,6 +145,7 @@ libknot.so.16 libknot16 #MINVER#
  knot_quic_table_rem@Base 3.5.0
  knot_quic_table_sweep@Base 3.5.0
  knot_rcode_names@Base 3.5.0
+ knot_rdata_to_canonical@Base 3.5.0
  knot_rdataset_add@Base 3.5.0
  knot_rdataset_at@Base 3.5.0
  knot_rdataset_clear@Base 3.5.0
index 6488dda4ce7fc1987d5a3961d4195c1a93f519b9..908d1352a3ffa9b30201154ae4f0274f632ffb12 100644 (file)
@@ -87,4 +87,22 @@ inline static int knot_rdata_cmp(const knot_rdata_t *rdata1, const knot_rdata_t
        return cmp;
 }
 
+/*!
+ * \brief Converts rdata into canonical format.
+ *
+ * Rdata domain names are converted only for types listed in RFC 4034,
+ * Section 6.2, except for NSEC (updated by RFC 6840, Section 5.1) and
+ * A6 (not supported).
+ *
+ * \warning This function expects either empty rdata or full, not malformed
+ *          rdata. If malformed rdata is passed to this function, memory errors
+ *          may occur.
+ *
+ * \param rdata  Rdata to convert.
+ * \param type   Rdata type.
+ *
+ * \return Error code, KNOT_EOK if successful.
+ */
+int knot_rdata_to_canonical(knot_rdata_t *rdata, uint16_t type);
+
 /*! @} */
index 74a69fcaa44fd4e00d4893496d70d3b0938551fc..1486464873a1e558d358617e096637212126bc46 100644 (file)
@@ -126,27 +126,24 @@ bool knot_rrset_is_nsec3rel(const knot_rrset_t *rr)
 }
 
 _public_
-int knot_rrset_rr_to_canonical(knot_rrset_t *rrset)
+int knot_rdata_to_canonical(knot_rdata_t *rdata, uint16_t type)
 {
-       if (rrset == NULL || rrset->rrs.count != 1) {
+       if (rdata == NULL) {
                return KNOT_EINVAL;
        }
 
-       /* Convert owner for all RRSets. */
-       knot_dname_to_lower(rrset->owner);
-
        /* Convert DNAMEs in RDATA only for RFC4034 types. */
-       if (!knot_rrtype_should_be_lowercased(rrset->type)) {
+       if (!knot_rrtype_should_be_lowercased(type)) {
                return KNOT_EOK;
        }
 
-       const knot_rdata_descriptor_t *desc = knot_get_rdata_descriptor(rrset->type);
+       const knot_rdata_descriptor_t *desc = knot_get_rdata_descriptor(type);
        if (desc->type_name == NULL) {
-               desc = knot_get_obsolete_rdata_descriptor(rrset->type);
+               desc = knot_get_obsolete_rdata_descriptor(type);
        }
 
-       uint16_t rdlen = rrset->rrs.rdata->len;
-       uint8_t *pos = rrset->rrs.rdata->data;
+       uint16_t rdlen = rdata->len;
+       uint8_t *pos = rdata->data;
        uint8_t *endpos = pos + rdlen;
 
        /* No RDATA */
@@ -156,8 +153,8 @@ int knot_rrset_rr_to_canonical(knot_rrset_t *rrset)
 
        /* Otherwise, whole and not malformed RDATA are expected. */
        for (int i = 0; desc->block_types[i] != KNOT_RDATA_WF_END; ++i) {
-               int type = desc->block_types[i];
-               switch (type) {
+               int block_type = desc->block_types[i];
+               switch (block_type) {
                case KNOT_RDATA_WF_COMPRESSIBLE_DNAME:
                case KNOT_RDATA_WF_DECOMPRESSIBLE_DNAME:
                case KNOT_RDATA_WF_FIXED_DNAME:
@@ -176,14 +173,27 @@ int knot_rrset_rr_to_canonical(knot_rrset_t *rrset)
                        break;
                default:
                        /* Fixed size block */
-                       assert(type > 0);
-                       pos += type;
+                       assert(block_type > 0);
+                       pos += block_type;
                }
        }
 
        return KNOT_EOK;
 }
 
+_public_
+int knot_rrset_rr_to_canonical(knot_rrset_t *rrset)
+{
+       if (rrset == NULL || rrset->rrs.count != 1) {
+               return KNOT_EINVAL;
+       }
+
+       /* Convert owner for all RRSets. */
+       knot_dname_to_lower(rrset->owner);
+
+       return knot_rdata_to_canonical(rrset->rrs.rdata, rrset->type);
+}
+
 _public_
 size_t knot_rrset_size(const knot_rrset_t *rrset)
 {
index 2b874b24d43b622ecfe8a8037804172031591022..c0c897f897e9615effbe317ca3d5bdafa507428d 100644 (file)
@@ -157,19 +157,15 @@ inline static bool knot_rrset_empty(const knot_rrset_t *rrset)
 bool knot_rrset_is_nsec3rel(const knot_rrset_t *rr);
 
 /*!
- * \brief Convert one RR into canonical format.
+ * \brief Converts RRSet with one RR into canonical format.
  *
- * Owner is always converted to lowercase. RDATA domain names are converted only
- * for types listed in RFC 4034, Section 6.2, except for NSEC (updated by
- * RFC 6840, Section 5.1) and A6 (not supported).
+ * The RRSet owner is always converted to lowercase.
  *
- * \note If RRSet with more RRs is given to this function, only the first RR
- *       will be converted.
- * \warning This function expects either empty RDATA or full, not malformed
- *          RDATA. If malformed RRSet is passed to this function, memory errors
- *          may occur.
+ * \note See knot_rdata_to_canonical() for more details.
  *
- * \param rrset  RR to convert.
+ * \param rrset  RRSet to convert.
+ *
+ * \return Error code, KNOT_EOK if successful.
  */
 int knot_rrset_rr_to_canonical(knot_rrset_t *rrset);