]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
treewide: remove duplicate contrib/wire.h
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 6 Apr 2021 15:26:12 +0000 (17:26 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Wed, 14 Apr 2021 14:04:16 +0000 (16:04 +0200)
libknot >= 2.9 provides it and their version is less buggy :-)
In particular, it works with unaligned pointers.

contrib/wire.h [deleted file]
contrib/wire.spdx [deleted file]
daemon/worker.c
lib/cookies/nonce.c
lib/dnssec.c
lib/dnssec/signature.c

diff --git a/contrib/wire.h b/contrib/wire.h
deleted file mode 100644 (file)
index bec6db5..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-/*  Copyright (C) 2011-2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
- *  SPDX-License-Identifier: GPL-3.0-or-later
- */
-/*!
- * \file
- *
- * \brief Wire integer operations.
- *
- * \addtogroup contrib
- * @{
- */
-
-#pragma once
-
-#include <stdint.h>
-#include <string.h>
-
-#if defined(__linux__) || defined(__gnu_hurd__) || \
-    (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
-#       include <endian.h>
-#  ifndef be64toh
-#       include <arpa/inet.h>
-#       include <byteswap.h>
-#    if BYTE_ORDER == LITTLE_ENDIAN
-#       define be16toh(x) ntohs(x)
-#       define be32toh(x) ntohl(x)
-#       define be64toh(x) bswap_64 (x)
-#       define le16toh(x) (x)
-#       define le32toh(x) (x)
-#       define le64toh(x) (x)
-#    else
-#       define be16toh(x) (x)
-#       define be32toh(x) (x)
-#       define be64toh(x) (x)
-#       define le16toh(x) ntohs(x)
-#       define le32toh(x) ntohl(x)
-#       define le64toh(x) bswap_64 (x)
-#    endif
-#  endif
-#elif defined(__FreeBSD__) || defined(__NetBSD__)
-#       include <sys/endian.h>
-#elif defined(__OpenBSD__)
-#       include <endian.h>
-#elif defined(__APPLE__)
-#       include <libkern/OSByteOrder.h>
-#       define be16toh(x) OSSwapBigToHostInt16(x)
-#       define be32toh(x) OSSwapBigToHostInt32(x)
-#       define be64toh(x) OSSwapBigToHostInt64(x)
-#       define htobe16(x) OSSwapHostToBigInt16(x)
-#       define htobe32(x) OSSwapHostToBigInt32(x)
-#       define htobe64(x) OSSwapHostToBigInt64(x)
-#       define le16toh(x) OSSwapLittleToHostInt16(x)
-#       define le32toh(x) OSSwapLittleToHostInt32(x)
-#       define le64toh(x) OSSwapLittleToHostInt64(x)
-#       define htole16(x) OSSwapHostToLittleInt16(x)
-#       define htole32(x) OSSwapHostToLittleInt32(x)
-#       define htole64(x) OSSwapHostToLittleInt64(x)
-#endif
-
-/*!
- * \brief Reads 2 bytes from the wireformat data.
- *
- * \param pos Data to read the 2 bytes from.
- *
- * \return The 2 bytes read, in host byte order.
- */
-inline static uint16_t wire_read_u16(const uint8_t *pos)
-{
-       return be16toh(*(uint16_t *)pos);
-}
-
-/*!
- * \brief Reads 4 bytes from the wireformat data.
- *
- * \param pos Data to read the 4 bytes from.
- *
- * \return The 4 bytes read, in host byte order.
- */
-inline static uint32_t wire_read_u32(const uint8_t *pos)
-{
-       return be32toh(*(uint32_t *)pos);
-}
-
-/*!
- * \brief Reads 6 bytes from the wireformat data.
- *
- * \param pos Data to read the 6 bytes from.
- *
- * \return The 6 bytes read, in host byte order.
- */
-inline static uint64_t wire_read_u48(const uint8_t *pos)
-{
-       uint64_t input = 0;
-       memcpy((uint8_t *)&input + 1, pos, 6);
-       return be64toh(input) >> 8;
-}
-
-/*!
- * \brief Read 8 bytes from the wireformat data.
- *
- * \param pos Data to read the 8 bytes from.
- *
- * \return The 8 bytes read, in host byte order.
- */
-inline static uint64_t wire_read_u64(const uint8_t *pos)
-{
-       return be64toh(*(uint64_t *)pos);
-}
-
-/*!
- * \brief Writes 2 bytes in wireformat.
- *
- * The data are stored in network byte order (big endian).
- *
- * \param pos Position where to put the 2 bytes.
- * \param data Data to put.
- */
-inline static void wire_write_u16(uint8_t *pos, uint16_t data)
-{
-       *(uint16_t *)pos = htobe16(data);
-}
-
-/*!
- * \brief Writes 4 bytes in wireformat.
- *
- * The data are stored in network byte order (big endian).
- *
- * \param pos Position where to put the 4 bytes.
- * \param data Data to put.
- */
-inline static void wire_write_u32(uint8_t *pos, uint32_t data)
-{
-       *(uint32_t *)pos = htobe32(data);
-}
-
-/*!
- * \brief Writes 6 bytes in wireformat.
- *
- * The data are stored in network byte order (big endian).
- *
- * \param pos Position where to put the 4 bytes.
- * \param data Data to put.
- */
-inline static void wire_write_u48(uint8_t *pos, uint64_t data)
-{
-       uint64_t swapped = htobe64(data << 8);
-       memcpy(pos, (uint8_t *)&swapped + 1, 6);
-}
-
-/*!
- * \brief Writes 8 bytes in wireformat.
- *
- * The data are stored in network byte order (big endian).
- *
- * \param pos Position where to put the 8 bytes.
- * \param data Data to put.
- */
-inline static void wire_write_u64(uint8_t *pos, uint64_t data)
-{
-       *(uint64_t *)pos = htobe64(data);
-}
-
-/*! @} */
diff --git a/contrib/wire.spdx b/contrib/wire.spdx
deleted file mode 100644 (file)
index 1054c55..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-SPDXVersion: SPDX-2.1
-DataLicense: CC0-1.0
-SPDXID: SPDXRef-DOCUMENT
-DocumentName: knotdns-wire
-DocumentNamespace: http://spdx.org/spdxdocs/spdx-v2.1-0f7c0ad6-ea88-44b4-a93a-850f3b6ccade
-
-PackageName: knotdns-wire
-PackageDownloadLocation: git+https://gitlab.nic.cz/knot/knot-dns.git@824ce5e81bc1a1d333de3042b2745bb2387dc2ff#src/contrib/wire.h
-PackageOriginator: Organization: Knot DNS contributors
-PackageLicenseDeclared: GPL-3.0-or-later
index b13bb3911f1ee1eff4e3588ac607bc50f2021bb6..d3e06a03499c3c1dd90f40ef35cd86687ffc5f6b 100644 (file)
@@ -13,7 +13,6 @@
 #include <contrib/cleanup.h>
 #include <contrib/ucw/lib.h>
 #include <contrib/ucw/mempool.h>
-#include <contrib/wire.h>
 #if defined(__GLIBC__) && defined(_GNU_SOURCE)
 #include <malloc.h>
 #endif
index 8e4b7549770c7448a14685a1fa654b143a4692ef..01a7d94f958ed86058b9b00eb6f6608c18157921 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <assert.h>
 
-#include "contrib/wire.h"
+#include <libknot/wire.h>
 #include "lib/cookies/nonce.h"
 
 uint16_t kr_nonce_write_wire(uint8_t *buf, uint16_t buf_len,
@@ -14,8 +14,8 @@ uint16_t kr_nonce_write_wire(uint8_t *buf, uint16_t buf_len,
                return 0;
        }
 
-       wire_write_u32(buf, input->rand);
-       wire_write_u32(buf + sizeof(uint32_t), input->time);
+       knot_wire_write_u32(buf, input->rand);
+       knot_wire_write_u32(buf + sizeof(uint32_t), input->time);
        buf_len = 2 * sizeof(uint32_t);
 
        return buf_len;
index 7490a67586c7b5740b0629f6f0d5b17e27d9e62e..7ea2920a97f789f55fa9e192e0664da3f61286d3 100644 (file)
@@ -17,7 +17,6 @@
 #include <libknot/rrtype/rrsig.h>
 
 #include "contrib/cleanup.h"
-#include "contrib/wire.h"
 #include "lib/defines.h"
 #include "lib/dnssec/nsec.h"
 #include "lib/dnssec/nsec3.h"
@@ -341,18 +340,18 @@ int kr_dnskeys_trusted(kr_rrset_validation_ctx_t *vctx, const knot_rrset_t *ta)
 
 bool kr_dnssec_key_zsk(const uint8_t *dnskey_rdata)
 {
-       return wire_read_u16(dnskey_rdata) & 0x0100;
+       return knot_wire_read_u16(dnskey_rdata) & 0x0100;
 }
 
 bool kr_dnssec_key_ksk(const uint8_t *dnskey_rdata)
 {
-       return wire_read_u16(dnskey_rdata) & 0x0001;
+       return knot_wire_read_u16(dnskey_rdata) & 0x0001;
 }
 
 /** Return true if the DNSKEY is revoked. */
 bool kr_dnssec_key_revoked(const uint8_t *dnskey_rdata)
 {
-       return wire_read_u16(dnskey_rdata) & 0x0080;
+       return knot_wire_read_u16(dnskey_rdata) & 0x0080;
 }
 
 int kr_dnssec_key_tag(uint16_t rrtype, const uint8_t *rdata, size_t rdlen)
@@ -361,7 +360,7 @@ int kr_dnssec_key_tag(uint16_t rrtype, const uint8_t *rdata, size_t rdlen)
                return kr_error(EINVAL);
        }
        if (rrtype == KNOT_RRTYPE_DS) {
-               return wire_read_u16(rdata);
+               return knot_wire_read_u16(rdata);
        } else if (rrtype == KNOT_RRTYPE_DNSKEY) {
                struct dseckey *key = NULL;
                int ret = kr_dnssec_key_from_rdata(&key, NULL, rdata, rdlen);
index fed0cf4c3853d01d7541ae11837db4ce0376c94e..2150a71c0c664dd1099adc2c60efb8f27feb8a01 100644 (file)
 #include <libknot/rrset.h>
 #include <libknot/rrtype/rrsig.h>
 #include <libknot/rrtype/ds.h>
+#include <libknot/wire.h>
 
 #include "lib/defines.h"
 #include "lib/utils.h"
 #include "lib/dnssec/signature.h"
 
-#include "contrib/wire.h"
-
 static int authenticate_ds(const dnssec_key_t *key, dnssec_binary_t *ds_rdata, uint8_t digest_type)
 {
        /* Compute DS RDATA from the DNSKEY. */
@@ -208,7 +207,7 @@ static int sign_ctx_add_records(dnssec_sign_ctx_t *ctx, const knot_rrset_t *cove
                        sizeof(uint16_t) + /* class */
                        sizeof(uint32_t);  /* OrigTTL */
                const uint8_t *rdatalen_ptr = beginp + rdatalen_offset;
-               const uint16_t rdata_size = wire_read_u16(rdatalen_ptr);
+               const uint16_t rdata_size = knot_wire_read_u16(rdatalen_ptr);
                const size_t rr_size = rdatalen_offset +
                        sizeof(uint16_t) + /* RDATA length */
                        rdata_size;        /* RDATA */