1 /*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
2 
3     This program is free software: you can redistribute it and/or modify
4     it under the terms of the GNU General Public License as published by
5     the Free Software Foundation, either version 3 of the License, or
6     (at your option) any later version.
7 
8     This program is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11     GNU General Public License for more details.
12 
13     You should have received a copy of the GNU General Public License
14     along with this program.  If not, see <https://www.gnu.org/licenses/>.
15  */
16 
17 /*!
18  * \file
19  *
20  * \brief RRSet from/to wire conversion functions.
21  *
22  * \addtogroup wire
23  * @{
24  */
25 
26 #pragma once
27 
28 #include "libknot/rrset.h"
29 #include "libknot/packet/compr.h"
30 
31 /*!
32  * \brief Write RR Set content to a wire.
33  *
34  * \param rrset     RRSet to be converted.
35  * \param wire      Output wire buffer.
36  * \param max_size  Capacity of wire buffer.
37  * \param rotate    Rotate the RR order by this count.
38  * \param compr     Compression context.
39  * \param flags     Flags; currently only KNOT_PF_TTL_ORIG is accepted.
40  *
41  * \return Output size, negative number on error (KNOT_E*).
42  */
43 int knot_rrset_to_wire_extra(const knot_rrset_t *rrset, uint8_t *wire,
44                              uint16_t max_size, uint16_t rotate,
45                              knot_compr_t *compr, uint16_t flags);
46 
47 /*! \brief Same as knot_rrset_to_wire_extra but without rrset rotation and flags. */
knot_rrset_to_wire(const knot_rrset_t * rrset,uint8_t * wire,uint16_t max_size,knot_compr_t * compr)48 static inline int knot_rrset_to_wire(const knot_rrset_t *rrset, uint8_t *wire,
49                                      uint16_t max_size, knot_compr_t *compr)
50 {
51 	return knot_rrset_to_wire_extra(rrset, wire, max_size, 0, compr, 0);
52 }
53 
54 /*!
55 * \brief Creates one RR from wire, stores it into \a rrset.
56 *
57 * \param wire       Source wire (the whole packet).
58 * \param pos        Position in \a wire where to start parsing.
59 * \param max_size   Total size of data in \a wire (size of the packet).
60 * \param rrset      Destination RRSet.
61 * \param mm         Memory context.
62 * \param canonical  Convert rrset to canonical format indication.
63 *
64 * \return KNOT_E*
65 */
66 int knot_rrset_rr_from_wire(const uint8_t *wire, size_t *pos, size_t max_size,
67                             knot_rrset_t *rrset, knot_mm_t *mm, bool canonical);
68 
69 /*! @} */
70