}
}
-/*----------------------------------------------------------------------------*/
-
/*!
* \brief EDNS Client Subnet family data.
*/
/*!
* \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;
}
}
_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;
}
_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) {
}
_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;
}
_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) {
_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;
return KNOT_EMALF;
}
- *point = knot_dname_copy(option, NULL);
+ *point = knot_dname_copy(option, mm);
if (*point == NULL) {
return KNOT_ENOMEM;
}
}
_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)
{
*
* \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.
*
* \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);
/*!
*
* \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.
*
* \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.
*
* \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.
*
* \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);
/*!
* \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.
*
* \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);
/* 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);
/* 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);
};
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 };
};
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 };
__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);
"%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__);
}