From: Vladimír Čunát Date: Mon, 2 Jul 2018 12:13:19 +0000 (+0200) Subject: lib/utils: naive refactoring of kr_dname_lf() X-Git-Tag: v3.0.0~6^2~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e83594efe31ae2c700bb7261ef658a30c5634ba;p=thirdparty%2Fknot-resolver.git lib/utils: naive refactoring of kr_dname_lf() It's not optimal; we can improve performance later. --- diff --git a/lib/cache/impl.h b/lib/cache/impl.h index da1c75a7f..88513d030 100644 --- a/lib/cache/impl.h +++ b/lib/cache/impl.h @@ -115,6 +115,8 @@ struct key { /** The key data start at buf+1, and buf[0] contains some length. * For details see key_exact* and key_NSEC* functions. */ uint8_t buf[KR_CACHE_KEY_MAXLEN]; + /* LATER(opt.): ^^ probably change the anchoring, so that kr_dname_lf() + * doesn't need to move data after knot_dname_lf(). */ }; static inline size_t key_nwz_off(const struct key *k) diff --git a/lib/utils.h b/lib/utils.h index c121bd0ea..ba60ce464 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -420,12 +420,14 @@ int knot_dname_lf2wire(knot_dname_t *dst, uint8_t len, const uint8_t *lf); */ static inline int kr_dname_lf(uint8_t *dst, const knot_dname_t *src, bool add_wildcard) { - int ret = knot_dname_lf(dst, src, NULL); - if (ret) - return ret; - int len = dst[0]; - if (len == 1) - len = 0; + knot_dname_storage_t right_aligned_dst; + uint8_t *right_aligned_dname_start = knot_dname_lf(src, right_aligned_dst); + if (!right_aligned_dname_start) { + return kr_error(EINVAL); + } + int len = right_aligned_dname_start[0]; + assert(right_aligned_dname_start + 1 + len - KNOT_DNAME_MAXLEN == right_aligned_dst); + memcpy(dst + 1, right_aligned_dname_start + 1, len); if (add_wildcard) { if (len + 2 > KNOT_DNAME_MAXLEN) return kr_error(ENOSPC);