]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
libknot/edns: unify option length data type to uint16_t
authorDaniel Salzman <daniel.salzman@nic.cz>
Thu, 8 Feb 2018 13:28:24 +0000 (14:28 +0100)
committerDaniel Salzman <daniel.salzman@nic.cz>
Thu, 8 Feb 2018 13:28:36 +0000 (14:28 +0100)
src/libknot/rrtype/opt.c
src/libknot/rrtype/opt.h
src/utils/kdig/kdig_exec.c
tests/libknot/test_edns.c

index fcace7eb6a40e39741ad5f0fda35505153a5a2e7..c03ad9f10f2c0c297aecb3d6952eedf52e839950 100644 (file)
@@ -292,8 +292,6 @@ int knot_edns_default_padding_size(const knot_pkt_t *pkt,
        }
 }
 
-/*----------------------------------------------------------------------------*/
-
 /*!
  * \brief EDNS Client Subnet family data.
  */
@@ -351,7 +349,7 @@ static const ecs_family_t *ecs_family_by_iana(uint16_t family)
 /*!
  * \brief Get ECS address prefix size in bytes.
  */
-static size_t ecs_prefix_size(uint8_t prefix)
+static uint16_t ecs_prefix_size(uint8_t prefix)
 {
        return (prefix + 7) / 8;
 }
@@ -403,7 +401,7 @@ static bool ecs_is_valid(const knot_edns_client_subnet_t *ecs)
 }
 
 _public_
-size_t knot_edns_client_subnet_size(const knot_edns_client_subnet_t *ecs)
+uint16_t knot_edns_client_subnet_size(const knot_edns_client_subnet_t *ecs)
 {
        if (!ecs_is_valid(ecs)) {
                return 0;
@@ -416,7 +414,7 @@ size_t knot_edns_client_subnet_size(const knot_edns_client_subnet_t *ecs)
 }
 
 _public_
-int knot_edns_client_subnet_write(uint8_t *option, size_t option_len,
+int knot_edns_client_subnet_write(uint8_t *option, uint16_t option_len,
                                   const knot_edns_client_subnet_t *ecs)
 {
        if (option == NULL || ecs == NULL) {
@@ -523,13 +521,13 @@ int knot_edns_client_subnet_get_addr(struct sockaddr_storage *addr,
 }
 
 _public_
-size_t knot_edns_keepalive_size(uint16_t timeout)
+uint16_t knot_edns_keepalive_size(uint16_t timeout)
 {
        return (timeout > 0) ? sizeof(uint16_t) : 0;
 }
 
 _public_
-int knot_edns_keepalive_write(uint8_t *option, size_t option_len, uint16_t timeout)
+int knot_edns_keepalive_write(uint8_t *option, uint16_t option_len, uint16_t timeout)
 {
        if (option == NULL) {
                return KNOT_EINVAL;
@@ -568,13 +566,13 @@ int knot_edns_keepalive_parse(uint16_t *timeout, const uint8_t *option,
 }
 
 _public_
-size_t knot_edns_chain_size(const knot_dname_t *point)
+uint16_t knot_edns_chain_size(const knot_dname_t *point)
 {
        return knot_dname_size(point);
 }
 
 _public_
-int knot_edns_chain_write(uint8_t *option, size_t option_len,
+int knot_edns_chain_write(uint8_t *option, uint16_t option_len,
                           const knot_dname_t *point)
 {
        if (option == NULL || point == NULL) {
@@ -589,7 +587,7 @@ int knot_edns_chain_write(uint8_t *option, size_t option_len,
 
 _public_
 int knot_edns_chain_parse(knot_dname_t **point, const uint8_t *option,
-                          uint16_t option_len)
+                          uint16_t option_len, knot_mm_t *mm)
 {
        if (point == NULL || option == NULL) {
                return KNOT_EINVAL;
@@ -600,7 +598,7 @@ int knot_edns_chain_parse(knot_dname_t **point, const uint8_t *option,
                return KNOT_EMALF;
        }
 
-       *point = knot_dname_copy(option, NULL);
+       *point = knot_dname_copy(option, mm);
        if (*point == NULL) {
                return KNOT_ENOMEM;
        }
@@ -625,7 +623,7 @@ uint16_t knot_edns_cookie_size(const knot_edns_cookie_t *cc,
 }
 
 _public_
-int knot_edns_cookie_write(uint8_t *option, size_t option_len,
+int knot_edns_cookie_write(uint8_t *option, uint16_t option_len,
                            const knot_edns_cookie_t *cc,
                            const knot_edns_cookie_t *sc)
 {
index 2e11232af064deec0368a1ea0b855daea77d61e8..5bc1312263d375983583b8e71e2515fe740a3fd7 100644 (file)
@@ -433,7 +433,7 @@ typedef struct {
  *
  * \return Size of the EDNS option data.
  */
-size_t knot_edns_client_subnet_size(const knot_edns_client_subnet_t *ecs);
+uint16_t knot_edns_client_subnet_size(const knot_edns_client_subnet_t *ecs);
 
 /*!
  * \brief Write EDNS Client Subnet data from the ECS structure to wire.
@@ -444,7 +444,7 @@ size_t knot_edns_client_subnet_size(const knot_edns_client_subnet_t *ecs);
  *
  * \return Error code, KNOT_EOK if successful.
  */
-int knot_edns_client_subnet_write(uint8_t *option, size_t option_len,
+int knot_edns_client_subnet_write(uint8_t *option, uint16_t option_len,
                                   const knot_edns_client_subnet_t *ecs);
 
 /*!
@@ -491,7 +491,7 @@ int knot_edns_client_subnet_get_addr(struct sockaddr_storage *addr,
  *
  * \return Size of the EDNS option data.
  */
-size_t knot_edns_keepalive_size(uint16_t timeout);
+uint16_t knot_edns_keepalive_size(uint16_t timeout);
 
 /*!
  * \brief Writes EDNS TCP Keepalive wire data.
@@ -502,7 +502,7 @@ size_t knot_edns_keepalive_size(uint16_t timeout);
  *
  * \return Error code, KNOT_EOK if successful.
  */
-int knot_edns_keepalive_write(uint8_t *option, size_t option_len, uint16_t timeout);
+int knot_edns_keepalive_write(uint8_t *option, uint16_t uint16_len, uint16_t timeout);
 
 /*!
  * \brief Parses EDNS TCP Keepalive wire data.
@@ -523,7 +523,7 @@ int knot_edns_keepalive_parse(uint16_t *timeout, const uint8_t *option,
  *
  * \return Size of the EDNS option data or 0 if invalid input.
  */
-size_t knot_edns_chain_size(const knot_dname_t *point);
+uint16_t knot_edns_chain_size(const knot_dname_t *point);
 
 /*!
  * \brief Writes EDNS Chain wire data.
@@ -534,7 +534,7 @@ size_t knot_edns_chain_size(const knot_dname_t *point);
  *
  * \return Error code, KNOT_EOK if successful.
  */
-int knot_edns_chain_write(uint8_t *option, size_t option_len,
+int knot_edns_chain_write(uint8_t *option, uint16_t option_len,
                           const knot_dname_t *point);
 
 /*!
@@ -543,11 +543,12 @@ int knot_edns_chain_write(uint8_t *option, size_t option_len,
  * \param[out] point       EDNS Chain closest trusted point.
  * \param[in]  option      EDNS option data.
  * \param[in]  option_len  EDNS option size.
+ * \param[in]  mm          Memory context.
  *
  * \return Error code, KNOT_EOK if successful.
  */
 int knot_edns_chain_parse(knot_dname_t **point, const uint8_t *option,
-                          uint16_t option_len);
+                          uint16_t option_len, knot_mm_t *mm);
 
 /*!
  * \brief DNS Cookie content.
@@ -578,7 +579,7 @@ uint16_t knot_edns_cookie_size(const knot_edns_cookie_t *cc,
  *
  * \return Error code, KNOT_EOK if successful.
  */
-int knot_edns_cookie_write(uint8_t *option, size_t option_len,
+int knot_edns_cookie_write(uint8_t *option, uint16_t option_len,
                            const knot_edns_cookie_t *cc,
                            const knot_edns_cookie_t *sc);
 
index 95e8bb65301047011671397d1a6c9ec26a1b0f60..202828a832069d15af1a7b803814fd14f754abdc 100644 (file)
@@ -267,7 +267,7 @@ static int add_query_edns(knot_pkt_t *packet, const query_t *query, uint16_t max
 
        /* Append EDNS-client-subnet. */
        if (query->subnet.family != AF_UNSPEC) {
-               size_t size = knot_edns_client_subnet_size(&query->subnet);
+               uint16_t size = knot_edns_client_subnet_size(&query->subnet);
                uint8_t data[size];
 
                ret = knot_edns_client_subnet_write(data, size, &query->subnet);
@@ -286,7 +286,7 @@ static int add_query_edns(knot_pkt_t *packet, const query_t *query, uint16_t max
 
        /* Append a cookie option if present. */
        if (query->cc.len > 0) {
-               size_t size = knot_edns_cookie_size(&query->cc, &query->sc);
+               uint16_t size = knot_edns_cookie_size(&query->cc, &query->sc);
                uint8_t data[size];
 
                ret = knot_edns_cookie_write(data, size, &query->cc, &query->sc);
index 0932c61a1dcf2aed61d1429285fb6c41b30cc9c8..d8210556d6018e8b8d6c85e4d3e70ea8428905c7 100644 (file)
@@ -307,7 +307,7 @@ static void test_keepalive(void)
        };
 
        for (const test_t *t = TESTS; t->msg != NULL; t++) {
-               size_t len = knot_edns_keepalive_size(t->val);
+               uint16_t len = knot_edns_keepalive_size(t->val);
                ok(len == t->opt_len, "%s: %s, size", __func__, t->msg);
 
                uint8_t wire[8] = { 0 };
@@ -356,7 +356,7 @@ static void test_chain(void)
        };
 
        for (const test_t *t = TESTS; t->msg != NULL; t++) {
-               size_t len = knot_edns_chain_size(t->dname);
+               uint16_t len = knot_edns_chain_size(t->dname);
                ok(len == t->opt_len, "%s: dname %s, size", __func__, t->msg);
 
                uint8_t wire[8] = { 0 };
@@ -366,7 +366,7 @@ static void test_chain(void)
                                                            __func__, t->msg);
 
                knot_dname_t *dname = NULL;
-               ret = knot_edns_chain_parse(&dname, (uint8_t *)t->dname, t->opt_len);
+               ret = knot_edns_chain_parse(&dname, (uint8_t *)t->dname, t->opt_len, NULL);
                is_int(KNOT_EOK, ret, "%s: dname %s, parse, return", __func__, t->msg);
                ok(knot_dname_is_equal(dname, t->dname), "%s: dname %s, parse, value",
                                                         __func__, t->msg);
@@ -386,11 +386,11 @@ static void test_chain(void)
           "%s: write, no room", __func__);
 
        knot_dname_t *dname = NULL;
-       ok(knot_edns_chain_parse(NULL, wire, 0) == KNOT_EINVAL && dname == NULL,
+       ok(knot_edns_chain_parse(NULL, wire, 0, NULL) == KNOT_EINVAL && dname == NULL,
           "%s: parse, NULL", __func__);
-       ok(knot_edns_chain_parse(&dname, NULL, 0) == KNOT_EINVAL && dname == NULL,
+       ok(knot_edns_chain_parse(&dname, NULL, 0, NULL) == KNOT_EINVAL && dname == NULL,
           "%s: parse, NULL", __func__);
-       ok(knot_edns_chain_parse(&dname, (const uint8_t *)"\x01", 1) == KNOT_EMALF &&
+       ok(knot_edns_chain_parse(&dname, (const uint8_t *)"\x01", 1, NULL) == KNOT_EMALF &&
           dname == NULL, "%s: parse, malformed", __func__);
 }