]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- For #762: relocate RFC 1982 serial number arithmetic functions to their own
authorGeorge Thessalonikefs <george@nlnetlabs.nl>
Tue, 1 Aug 2023 15:26:14 +0000 (17:26 +0200)
committerGeorge Thessalonikefs <george@nlnetlabs.nl>
Tue, 1 Aug 2023 15:26:14 +0000 (17:26 +0200)
  file in util/rfc_1982.[ch].

Makefile.in
util/data/msgparse.c
util/rfc_1982.c [new file with mode: 0644]
util/rfc_1982.h [new file with mode: 0644]
validator/val_sigcrypt.c

index ef18d120adbb9e2a592f78a8fe2e91c1500ac4cf..66141846e2576cbe8178df6710e9d8fe45663dc2 100644 (file)
@@ -122,7 +122,7 @@ iterator/iter_delegpt.c iterator/iter_donotq.c iterator/iter_fwd.c \
 iterator/iter_hints.c iterator/iter_priv.c iterator/iter_resptype.c \
 iterator/iter_scrub.c iterator/iter_utils.c services/listen_dnsport.c \
 services/localzone.c services/mesh.c services/modstack.c services/view.c \
-services/rpz.c \
+services/rpz.c util/rfc_1982.c \
 services/outbound_list.c services/outside_network.c util/alloc.c \
 util/config_file.c util/configlexer.c util/configparser.c \
 util/shm_side/shm_main.c services/authzone.c \
@@ -148,7 +148,7 @@ outbound_list.lo alloc.lo config_file.lo configlexer.lo configparser.lo \
 fptr_wlist.lo siphash.lo edns.lo locks.lo log.lo mini_event.lo module.lo net_help.lo \
 random.lo rbtree.lo regional.lo rtt.lo dnstree.lo lookup3.lo lruhash.lo \
 slabhash.lo tcp_conn_limit.lo timehist.lo tube.lo winsock_event.lo \
-autotrust.lo val_anchor.lo rpz.lo proxy_protocol.lo \
+autotrust.lo val_anchor.lo rpz.lo rfc_1982.lo proxy_protocol.lo \
 validator.lo val_kcache.lo val_kentry.lo val_neg.lo val_nsec3.lo val_nsec.lo \
 val_secalgo.lo val_sigcrypt.lo val_utils.lo dns64.lo $(CACHEDB_OBJ) authzone.lo \
 $(SUBNET_OBJ) $(PYTHONMOD_OBJ) $(CHECKLOCK_OBJ) $(DNSTAP_OBJ) $(DNSCRYPT_OBJ) \
@@ -1008,6 +1008,7 @@ rtt.lo rtt.o: $(srcdir)/util/rtt.c config.h $(srcdir)/util/rtt.h $(srcdir)/itera
  $(srcdir)/util/locks.h $(srcdir)/util/log.h $(srcdir)/util/data/packed_rrset.h $(srcdir)/util/module.h \
  $(srcdir)/util/data/msgparse.h $(srcdir)/sldns/pkthdr.h $(srcdir)/sldns/rrdef.h
 siphash.lo siphash.o: $(srcdir)/util/siphash.c
+rfc_1982.lo rfc_1982.o: $(srcdir)/util/rfc_1982.c
 edns.lo edns.o: $(srcdir)/util/edns.c config.h $(srcdir)/util/edns.h $(srcdir)/util/storage/dnstree.h \
  $(srcdir)/util/rbtree.h $(srcdir)/util/config_file.h $(srcdir)/util/netevent.h $(srcdir)/dnscrypt/dnscrypt.h \
   $(srcdir)/util/net_help.h $(srcdir)/util/log.h $(srcdir)/util/regional.h \
index 221ff5dfda01330bfc776c1f57ee2645d2a9ba6f..1a7754c3d87fe6adbf54b2df48fda01e8807a922 100644 (file)
@@ -46,6 +46,7 @@
 #include "util/siphash.h"
 #include "util/storage/lookup3.h"
 #include "util/regional.h"
+#include "util/rfc_1982.h"
 #include "sldns/rrdef.h"
 #include "sldns/sbuffer.h"
 #include "sldns/parseutil.h"
@@ -941,43 +942,43 @@ parse_packet(sldns_buffer* pkt, struct msg_parse* msg, struct regional* region)
        return 0;
 }
 
-/** RFC 1982 comparison, uses unsigned integers, and tries to avoid
- * compiler optimization (eg. by avoiding a-b<0 comparisons),
- * this routine matches compare_serial(), for SOA serial number checks */
-static int
-compare_1982(uint32_t a, uint32_t b)
-{
-       /* for 32 bit values */
-       const uint32_t cutoff = ((uint32_t) 1 << (32 - 1));
-
-       if (a == b) {
-               return 0;
-       } else if ((a < b && b - a < cutoff) || (a > b && a - b > cutoff)) {
-               return -1;
-       } else {
-               return 1;
-       }
-}
-
-/** if we know that b is larger than a, return the difference between them,
- * that is the distance between them. in RFC1982 arith */
-static uint32_t
-subtract_1982(uint32_t a, uint32_t b)
-{
-       /* for 32 bit values */
-       const uint32_t cutoff = ((uint32_t) 1 << (32 - 1));
-
-       if(a == b)
-               return 0;
-       if(a < b && b - a < cutoff) {
-               return b-a;
-       }
-       if(a > b && a - b > cutoff) {
-               return ((uint32_t)0xffffffff) - (a-b-1);
-       }
-       /* wrong case, b smaller than a */
-       return 0;
-}
+///** RFC 1982 comparison, uses unsigned integers, and tries to avoid
+// * compiler optimization (eg. by avoiding a-b<0 comparisons),
+// * this routine matches compare_serial(), for SOA serial number checks */
+//static int
+//compare_1982(uint32_t a, uint32_t b)
+//{
+//     /* for 32 bit values */
+//     const uint32_t cutoff = ((uint32_t) 1 << (32 - 1));
+//
+//     if (a == b) {
+//             return 0;
+//     } else if ((a < b && b - a < cutoff) || (a > b && a - b > cutoff)) {
+//             return -1;
+//     } else {
+//             return 1;
+//     }
+//}
+//
+///** if we know that b is larger than a, return the difference between them,
+// * that is the distance between them. in RFC1982 arith */
+//static uint32_t
+//subtract_1982(uint32_t a, uint32_t b)
+//{
+//     /* for 32 bit values */
+//     const uint32_t cutoff = ((uint32_t) 1 << (32 - 1));
+//
+//     if(a == b)
+//             return 0;
+//     if(a < b && b - a < cutoff) {
+//             return b-a;
+//     }
+//     if(a > b && a - b > cutoff) {
+//             return ((uint32_t)0xffffffff) - (a-b-1);
+//     }
+//     /* wrong case, b smaller than a */
+//     return 0;
+//}
 
 
 static uint8_t *
diff --git a/util/rfc_1982.c b/util/rfc_1982.c
new file mode 100644 (file)
index 0000000..c28dede
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * util/rfc_1982.c - RFC 1982 Serial Number Arithmetic
+ *
+ * Copyright (c) 2023, NLnet Labs. All rights reserved.
+ *
+ * This software is open source.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of the NLNET LABS nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * \file
+ *
+ * This file contains functions for RFC 1982 serial number arithmetic.
+ */
+#include "config.h"
+
+int
+compare_1982(uint32_t a, uint32_t b)
+{
+       /* for 32 bit values */
+       const uint32_t cutoff = ((uint32_t) 1 << (32 - 1));
+
+       if (a == b) {
+               return 0;
+       } else if ((a < b && b - a < cutoff) || (a > b && a - b > cutoff)) {
+               return -1;
+       } else {
+               return 1;
+       }
+}
+
+uint32_t
+subtract_1982(uint32_t a, uint32_t b)
+{
+       /* for 32 bit values */
+       const uint32_t cutoff = ((uint32_t) 1 << (32 - 1));
+
+       if(a == b)
+               return 0;
+       if(a < b && b - a < cutoff) {
+               return b-a;
+       }
+       if(a > b && a - b > cutoff) {
+               return ((uint32_t)0xffffffff) - (a-b-1);
+       }
+       /* wrong case, b smaller than a */
+       return 0;
+}
diff --git a/util/rfc_1982.h b/util/rfc_1982.h
new file mode 100644 (file)
index 0000000..bae383d
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * util/rfc_1982.h - RFC 1982 Serial Number Arithmetic
+ *
+ * Copyright (c) 2023, NLnet Labs. All rights reserved.
+ *
+ * This software is open source.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of the NLNET LABS nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * \file
+ *
+ * This file contains functions for RFC 1982 serial number arithmetic.
+ */
+#ifndef RFC_1982_H
+#define RFC_1982_H
+
+/**
+ * RFC 1982 comparison, uses unsigned integers, and tries to avoid
+ * compiler optimization (eg. by avoiding a-b<0 comparisons).
+ * @param a: value to compare.
+ * @param b: value to compare.
+ * @return 0 if equal, 1 if a > b, else -1.
+ */
+int compare_1982(uint32_t a, uint32_t b);
+
+/**
+ * RFC 1982 subtraction, uses unsigned integers, and tries to avoid
+ * compiler optimization (eg. by avoiding a-b<0 comparisons).
+ * @param a: value to subtract from.
+ * @param b: value to subtract.
+ * @return the difference between them if we know that b is larger than a,
+ *     that is the distance between them in serial number arithmetic.
+ */
+uint32_t subtract_1982(uint32_t a, uint32_t b);
+
+#endif /* RFC_1982_H */
index 5ab21e20e7356f2514e1c5a6371e8329759f6ee4..8f05591e50faf7fbecddd6713e593c8ed3336245 100644 (file)
@@ -48,6 +48,7 @@
 #include "util/data/msgparse.h"
 #include "util/data/dname.h"
 #include "util/rbtree.h"
+#include "util/rfc_1982.h"
 #include "util/module.h"
 #include "util/net_help.h"
 #include "util/regional.h"
@@ -1378,43 +1379,43 @@ sigdate_error(const char* str, int32_t expi, int32_t incep, int32_t now)
                        (unsigned)incep, (unsigned)now);
 }
 
-/** RFC 1982 comparison, uses unsigned integers, and tries to avoid
- * compiler optimization (eg. by avoiding a-b<0 comparisons),
- * this routine matches compare_serial(), for SOA serial number checks */
-static int
-compare_1982(uint32_t a, uint32_t b)
-{
-       /* for 32 bit values */
-        const uint32_t cutoff = ((uint32_t) 1 << (32 - 1));
-
-        if (a == b) {
-                return 0;
-        } else if ((a < b && b - a < cutoff) || (a > b && a - b > cutoff)) {
-                return -1;
-        } else {
-                return 1;
-        }
-}
-
-/** if we know that b is larger than a, return the difference between them,
- * that is the distance between them. in RFC1982 arith */
-static uint32_t
-subtract_1982(uint32_t a, uint32_t b)
-{
-       /* for 32 bit values */
-        const uint32_t cutoff = ((uint32_t) 1 << (32 - 1));
-
-       if(a == b)
-               return 0;
-       if(a < b && b - a < cutoff) {
-               return b-a;
-       }
-       if(a > b && a - b > cutoff) {
-               return ((uint32_t)0xffffffff) - (a-b-1);
-       }
-       /* wrong case, b smaller than a */
-       return 0;
-}
+///** RFC 1982 comparison, uses unsigned integers, and tries to avoid
+// * compiler optimization (eg. by avoiding a-b<0 comparisons),
+// * this routine matches compare_serial(), for SOA serial number checks */
+//static int
+//compare_1982(uint32_t a, uint32_t b)
+//{
+//     /* for 32 bit values */
+//        const uint32_t cutoff = ((uint32_t) 1 << (32 - 1));
+//
+//        if (a == b) {
+//                return 0;
+//        } else if ((a < b && b - a < cutoff) || (a > b && a - b > cutoff)) {
+//                return -1;
+//        } else {
+//                return 1;
+//        }
+//}
+//
+///** if we know that b is larger than a, return the difference between them,
+// * that is the distance between them. in RFC1982 arith */
+//static uint32_t
+//subtract_1982(uint32_t a, uint32_t b)
+//{
+//     /* for 32 bit values */
+//        const uint32_t cutoff = ((uint32_t) 1 << (32 - 1));
+//
+//     if(a == b)
+//             return 0;
+//     if(a < b && b - a < cutoff) {
+//             return b-a;
+//     }
+//     if(a > b && a - b > cutoff) {
+//             return ((uint32_t)0xffffffff) - (a-b-1);
+//     }
+//     /* wrong case, b smaller than a */
+//     return 0;
+//}
 
 /** check rrsig dates */
 static int