]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Clean up remaining references to global compression
authorTony Finch <fanf@isc.org>
Thu, 5 May 2022 17:36:48 +0000 (18:36 +0100)
committerTony Finch <fanf@isc.org>
Wed, 1 Jun 2022 12:00:40 +0000 (13:00 +0100)
It is simply called "compression" now, without any qualifiers. Also,
improve some variable names in dns_name_towire2() so they are not two
letter abbreviations for global something.

lib/dns/compress.c
lib/dns/include/dns/compress.h
lib/dns/include/dns/name.h
lib/dns/include/dns/rdata.h
lib/dns/name.c

index f195e98b064477761f43f3e7a4d84c462e3b0b6c..607c7c273a836a8d30ce23b4887889237554d356 100644 (file)
@@ -205,8 +205,8 @@ dns_compress_getsensitive(dns_compress_t *cctx) {
  * If no match is found return false.
  */
 bool
-dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name,
-                       dns_name_t *prefix, uint16_t *offset) {
+dns_compress_find(dns_compress_t *cctx, const dns_name_t *name,
+                 dns_name_t *prefix, uint16_t *offset) {
        dns_name_t tname;
        dns_compressnode_t *node = NULL;
        unsigned int labels, i, n;
index 151a860fbe4327664a8d6ad8191864ac7d0c0385..81e70f9e76710fb0247a7e50f8a9869f3bc73b94 100644 (file)
@@ -61,7 +61,7 @@ struct dns_compress {
        bool         permitted;
        bool         disabled;
        bool         sensitive;
-       /*% Global compression table. */
+       /*% Compression pointer table. */
        dns_compressnode_t *table[DNS_COMPRESS_TABLESIZE];
        /*% Preallocated arena for names. */
        unsigned char arena[DNS_COMPRESS_ARENA_SIZE];
@@ -91,7 +91,8 @@ dns_compress_init(dns_compress_t *cctx, isc_mem_t *mctx);
  *     \li     'cctx' is a valid dns_compress_t structure.
  *     \li     'mctx' is an initialized memory context.
  *     Ensures:
- *     \li     cctx->global is initialized.
+ *     \li     'cctx' is initialized.
+ *     \li     'cctx->permitted' is true.
  *
  *     Returns:
  *     \li     #ISC_R_SUCCESS
@@ -162,10 +163,10 @@ dns_compress_getsensitive(dns_compress_t *cctx);
  */
 
 bool
-dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name,
-                       dns_name_t *prefix, uint16_t *offset);
+dns_compress_find(dns_compress_t *cctx, const dns_name_t *name,
+                 dns_name_t *prefix, uint16_t *offset);
 /*%<
- *     Finds longest possible match of 'name' in the global compression table.
+ *     Finds longest possible match of 'name' in the compression table.
  *
  *     Requires:
  *\li          'cctx' to be initialized.
@@ -194,13 +195,13 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name,
  *             valid until the message compression is complete.
  *
  *\li          'prefix' must be a prefix returned by
- *             dns_compress_findglobal(), or the same as 'name'.
+ *             dns_compress_find(), or the same as 'name'.
  */
 
 void
 dns_compress_rollback(dns_compress_t *cctx, uint16_t offset);
 /*%<
- *     Remove any compression pointers from global table >= offset.
+ *     Remove any compression pointers from the table that are >= offset.
  *
  *     Requires:
  *\li          'cctx' is initialized.
index e294b9068bc09f5d87c45161c86a95fc8dd70fb7..0f140876c847e5e89fcdbd1e5ca9aa69d06830a6 100644 (file)
@@ -757,8 +757,7 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx,
  * compression context 'cctx', and storing the result in 'target'.
  *
  * Notes:
- * \li If the compression context allows global compression, then the
- *     global compression table may be updated.
+ * \li If compression is permitted, then the cctx table may be updated.
  *
  * Requires:
  * \li 'name' is a valid name
@@ -769,8 +768,7 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx,
  *
  * \li target is a valid buffer.
  *
- * \li Any offsets specified in a global compression table are valid
- *     for buffer.
+ * \li Any offsets in the compression table are valid for buffer.
  *
  * Ensures:
  *
index 029685a6ef8a32aee95f494be24b50273520bbfc..8603fa81b989da5daff159dcc99f4d4216b97c66 100644 (file)
@@ -328,16 +328,14 @@ dns_rdata_towire(dns_rdata_t *rdata, dns_compress_t *cctx,
  * compression context 'cctx', and storing the result in 'target'.
  *
  * Notes:
- *\li  If the compression context allows global compression, then the
- *     global compression table may be updated.
+ *\li  If compression is permitted, then the cctx table may be updated.
  *
  * Requires:
  *\li  'rdata' is a valid, non-empty rdata
  *
  *\li  target is a valid buffer
  *
- *\li  Any offsets specified in a global compression table are valid
- *     for target.
+ *\li  Any offsets in the compression table are valid for target.
  *
  * Ensures,
  *     if the result is success:
index 26114fde3006aecf09ad741af27bcbaa2e2ce1f6..cde940e8269dd99696012303bc878d112e9c7f09 100644 (file)
@@ -1919,10 +1919,10 @@ isc_result_t
 dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx,
                 isc_buffer_t *target, uint16_t *comp_offsetp) {
        bool compress;
-       uint16_t offset;
-       dns_name_t gp; /* Global compression prefix */
-       bool gf;       /* Global compression target found */
-       uint16_t go;   /* Global compression offset */
+       bool found;
+       uint16_t here;  /* start of the name we are adding to the message */
+       uint16_t there; /* target of the compression pointer */
+       dns_name_t prefix;
        dns_offsets_t clo;
        dns_name_t clname;
 
@@ -1947,9 +1947,8 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx,
                if (target->length - target->used < 2) {
                        return (ISC_R_NOSPACE);
                }
-               offset = *comp_offsetp;
-               offset |= 0xc000;
-               isc_buffer_putuint16(target, offset);
+               here = *comp_offsetp;
+               isc_buffer_putuint16(target, here | 0xc000);
                return (ISC_R_SUCCESS);
        }
 
@@ -1962,52 +1961,52 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx,
                dns_name_clone(name, &clname);
                name = &clname;
        }
-       DNS_NAME_INIT(&gp, NULL);
+       DNS_NAME_INIT(&prefix, NULL);
 
-       offset = target->used; /*XXX*/
+       here = target->used; /*XXX*/
 
        if (compress) {
-               gf = dns_compress_findglobal(cctx, name, &gp, &go);
+               found = dns_compress_find(cctx, name, &prefix, &there);
        } else {
-               gf = false;
+               found = false;
        }
 
        /*
-        * If the offset is too high for 14 bit global compression, we're
-        * out of luck.
+        * If the offset does not fit in a 14 bit compression pointer,
+        * we're out of luck.
         */
-       if (gf && go >= 0x4000) {
-               gf = false;
+       if (found && there >= 0x4000) {
+               found = false;
        }
 
        /*
         * Will the compression pointer reduce the message size?
         */
-       if (gf && (gp.length + 2) >= name->length) {
-               gf = false;
+       if (found && (prefix.length + 2) >= name->length) {
+               found = false;
        }
 
-       if (gf) {
-               if (target->length - target->used < gp.length) {
+       if (found) {
+               if (target->length - target->used < prefix.length) {
                        return (ISC_R_NOSPACE);
                }
-               if (gp.length != 0) {
+               if (prefix.length != 0) {
                        unsigned char *base = target->base;
-                       (void)memmove(base + target->used, gp.ndata,
-                                     (size_t)gp.length);
+                       (void)memmove(base + target->used, prefix.ndata,
+                                     (size_t)prefix.length);
                }
-               isc_buffer_add(target, gp.length);
+               isc_buffer_add(target, prefix.length);
                if (target->length - target->used < 2) {
                        return (ISC_R_NOSPACE);
                }
-               isc_buffer_putuint16(target, go | 0xc000);
-               if (gp.length != 0) {
-                       dns_compress_add(cctx, name, &gp, offset);
+               isc_buffer_putuint16(target, there | 0xc000);
+               if (prefix.length != 0) {
+                       dns_compress_add(cctx, name, &prefix, here);
                        if (comp_offsetp != NULL) {
-                               *comp_offsetp = offset;
+                               *comp_offsetp = here;
                        }
                } else if (comp_offsetp != NULL) {
-                       *comp_offsetp = go;
+                       *comp_offsetp = there;
                }
        } else {
                if (target->length - target->used < name->length) {
@@ -2019,9 +2018,9 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx,
                                      (size_t)name->length);
                }
                isc_buffer_add(target, name->length);
-               dns_compress_add(cctx, name, name, offset);
+               dns_compress_add(cctx, name, name, here);
                if (comp_offsetp != NULL) {
-                       *comp_offsetp = offset;
+                       *comp_offsetp = here;
                }
        }