Skip to content
Snippets Groups Projects
Commit dd54723b authored by Daniel Salzman's avatar Daniel Salzman
Browse files

pkt: make private parsing functions static

parent c6f4b294
No related branches found
No related tags found
No related merge requests found
......@@ -561,30 +561,9 @@ int knot_pkt_put_rotate(knot_pkt_t *pkt, uint16_t compr_hint, const knot_rrset_t
return KNOT_EOK;
}
_public_
int knot_pkt_parse(knot_pkt_t *pkt, unsigned flags)
{
if (pkt == NULL) {
return KNOT_EINVAL;
}
/* Reset parse state. */
sections_reset(pkt);
int ret = knot_pkt_parse_question(pkt);
if (ret == KNOT_EOK) {
ret = knot_pkt_parse_payload(pkt, flags);
}
return ret;
}
_public_
int knot_pkt_parse_question(knot_pkt_t *pkt)
static int parse_question(knot_pkt_t *pkt)
{
if (pkt == NULL) {
return KNOT_EINVAL;
}
assert(pkt);
/* Check at least header size. */
if (pkt->size < KNOT_WIRE_HEADER_SIZE) {
......@@ -665,12 +644,9 @@ static int check_rr_constraints(knot_pkt_t *pkt, knot_rrset_t *rr, size_t rr_siz
return KNOT_EOK;
}
_public_
int knot_pkt_parse_rr(knot_pkt_t *pkt, unsigned flags)
static int parse_rr(knot_pkt_t *pkt, unsigned flags)
{
if (pkt == NULL) {
return KNOT_EINVAL;
}
assert(pkt);
if (pkt->parsed >= pkt->size) {
return KNOT_EFEWDATA;
......@@ -716,7 +692,7 @@ static int parse_section(knot_pkt_t *pkt, unsigned flags)
/* Parse all RRs belonging to the section. */
for (rr_parsed = 0; rr_parsed < rr_count; ++rr_parsed) {
int ret = knot_pkt_parse_rr(pkt, flags);
int ret = parse_rr(pkt, flags);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -725,14 +701,10 @@ static int parse_section(knot_pkt_t *pkt, unsigned flags)
return KNOT_EOK;
}
_public_
int knot_pkt_parse_payload(knot_pkt_t *pkt, unsigned flags)
static int parse_payload(knot_pkt_t *pkt, unsigned flags)
{
if (pkt == NULL) {
return KNOT_EINVAL;
}
assert(pkt->wire != NULL);
assert(pkt);
assert(pkt->wire);
assert(pkt->size > 0);
/* Reserve memory in advance to avoid resizing. */
......@@ -777,6 +749,24 @@ int knot_pkt_parse_payload(knot_pkt_t *pkt, unsigned flags)
return KNOT_EOK;
}
_public_
int knot_pkt_parse(knot_pkt_t *pkt, unsigned flags)
{
if (pkt == NULL) {
return KNOT_EINVAL;
}
/* Reset parse state. */
sections_reset(pkt);
int ret = parse_question(pkt);
if (ret == KNOT_EOK) {
ret = parse_payload(pkt, flags);
}
return ret;
}
_public_
uint16_t knot_pkt_ext_rcode(const knot_pkt_t *pkt)
{
......
......@@ -292,44 +292,18 @@ static inline uint16_t knot_pkt_rr_offset(const knot_pktsection_t *section,
* Parses both QUESTION and all packet sections,
* includes semantic checks over specific RRs (TSIG, OPT).
*
* \note For KNOT_PF_KEEPWIRE see note for \fn knot_pkt_parse_rr
* \note If KNOT_PF_KEEPWIRE is set, TSIG RR is not stripped from the wire
* and is processed as any other RR.
*
* \param pkt Given packet.
* \param flags Parsing flags (allowed KNOT_PF_KEEPWIRE)
*
* \param pkt Given packet.
* \param flags Parsing flags (allowed KNOT_PF_KEEPWIRE)
* \retval KNOT_EOK if success.
* \retval KNOT_ETRAIL if success but with some trailing data.
* \retval KNOT_EMALF and other errors.
*/
int knot_pkt_parse(knot_pkt_t *pkt, unsigned flags);
/*!
* \brief Parse packet header and a QUESTION section.
*/
int knot_pkt_parse_question(knot_pkt_t *pkt);
/*!
* \brief Parse single resource record.
*
* \note When KNOT_PF_KEEPWIRE is set, TSIG RR is not stripped from the wire
* and is processed as any other RR.
*
* \param pkt
* \param flags
* \return KNOT_EOK, KNOT_EFEWDATA if not enough data or various errors
*/
int knot_pkt_parse_rr(knot_pkt_t *pkt, unsigned flags);
/*!
* \brief Parse whole packet payload.
*
* \note For KNOT_PF_KEEPWIRE see note for \fn knot_pkt_parse_rr
*
* \param pkt
* \param flags
* \return KNOT_EOK, KNOT_EFEWDATA if not enough data or various errors
*/
int knot_pkt_parse_payload(knot_pkt_t *pkt, unsigned flags);
/*!
* \brief Get packet extended RCODE.
*
......
......@@ -17,11 +17,7 @@
#include <tap/basic.h>
#include "libknot/libknot.h"
#include "libknot/descriptor.h"
#include "libknot/libknot.h"
#include "libknot/packet/pkt.h"
#include "libknot/rrtype/tsig.h"
#include "contrib/mempattern.h"
#include "libknot/packet/pkt.c"
#include "contrib/ucw/mempool.h"
#define TTL 7200
......@@ -167,11 +163,11 @@ int main(int argc, char *argv[])
ok(in != NULL, "pkt: create packet for parsing");
/* Read packet header. */
ret = knot_pkt_parse_question(in);
ret = parse_question(in);
is_int(KNOT_EOK, ret, "pkt: read header");
/* Read packet payload. */
ret = knot_pkt_parse_payload(in, 0);
ret = parse_payload(in, 0);
is_int(KNOT_EOK, ret, "pkt: read payload");
/* Compare parsed packet to written packet. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment