]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/utils: naive refactoring of kr_dname_lf()
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 2 Jul 2018 12:13:19 +0000 (14:13 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 14 Aug 2018 08:36:10 +0000 (10:36 +0200)
It's not optimal; we can improve performance later.

lib/cache/impl.h
lib/utils.h

index da1c75a7fee253cd591ec5d521133e644f713915..88513d030b1c2284958b90d0800b93edd8079fff 100644 (file)
@@ -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)
index c121bd0ea6fa0dac2461790bb0650a91656e5bd3..ba60ce46481081e49b6802bd428c6ff7c336d6d6 100644 (file)
@@ -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);