1 /*------------------------------------------------------------------------------
2  *
3  * Copyright (c) 2011-2021, EURid vzw. All rights reserved.
4  * The YADIFA TM software product is provided under the BSD 3-clause license:
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *        * Redistributions in binary form must reproduce the above copyright
13  *          notice, this list of conditions and the following disclaimer in the
14  *          documentation and/or other materials provided with the distribution.
15  *        * Neither the name of EURid nor the names of its contributors may be
16  *          used to endorse or promote products derived from this software
17  *          without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  *------------------------------------------------------------------------------
32  *
33  */
34 
35 /** @defgroup
36  *  @ingroup
37  *  @brief
38  *
39  * @{
40  */
41 #pragma once
42 
43 #include <dnscore/dnskey.h>
44 #include <dnscore/packet_reader.h>
45 #include <dnscore/packet_writer.h>
46 
47 struct dynupdate_message
48 {
49     u8 *packet;
50     u32 size;
51     u16 rclass;
52     packet_writer pw;
53 };
54 
55 typedef struct dynupdate_message dynupdate_message;
56 
57 /**
58  * Initialises a simple update buffer
59  *
60  * @param dmsg
61  */
62 
63 void dynupdate_message_init(dynupdate_message *dmsg, const u8 *origin, u16 rclass);
64 
65 /**
66  * Clears a simple update buffer
67  *
68  * @param dmsg
69  */
70 
71 void dynupdate_message_reset(dynupdate_message *dmsg, const u8 *origin, u16 rclass);
72 
73 /**
74  * Releases resources.
75  *
76  * @param dmsg
77  */
78 
79 void dynupdate_message_finalize(dynupdate_message *dmsg);
80 
81 /**
82  * Sets a reader up for the buffer.
83  *
84  * @param dmsg
85  * @param purd
86  */
87 
88 void dynupdate_message_set_reader(dynupdate_message *dmsg, packet_unpack_reader_data *purd);
89 
90 /**
91  * Return the number of update records.
92  *
93  * @param dmsg
94  * @return
95  */
96 
97 u16 dynupdate_message_get_count(dynupdate_message *dmsg);
98 
99 /**
100  * Adds a dnskey record to the buffer
101  *
102  * @param dmsg
103  * @param ttl
104  * @param key
105  * @return
106  */
107 
108 ya_result dynupdate_message_add_dnskey(dynupdate_message *dmsg, s32 ttl, const dnssec_key *key);
109 
110 /**
111  * Deletes a dnskey record to the buffer
112  *
113  * @param dmsg
114  * @param ttl
115  * @param key
116  * @return
117  */
118 
119 ya_result dynupdate_message_del_dnskey(dynupdate_message *dmsg, const dnssec_key *key);
120 
121 /**
122  * Appends a "add RR" command to the buffer.
123  *
124  * @param dmsg
125  * @param fqdn
126  * @param rtype
127  * @param ttl
128  * @param rdata_size
129  * @param rdata
130  * @return
131  */
132 
133 ya_result dynupdate_message_add_record(dynupdate_message *dmsg, const u8 *fqdn, u16 rtype, s32 ttl, u16 rdata_size, void *rdata);
134 
135 /**
136  * Appends a "delete RR" command to the buffer.
137  *
138  * @param dmsg
139  * @param fqdn
140  * @param rtype
141  * @param ttl
142  * @param rdata_size
143  * @param rdata
144  * @return
145  */
146 
147 ya_result dynupdate_message_del_record(dynupdate_message *dmsg, const u8 *fqdn, u16 rtype, s32 ttl, u16 rdata_size, void *rdata);
148 
149 /**
150  *
151  * Appends a "delete RRSET" command to the buffer.
152  *
153  * @param dmsg
154  * @param fqdn
155  * @param rtype
156  * @return
157  */
158 
159 ya_result dynupdate_message_del_record_set(dynupdate_message *dmsg, const u8 *fqdn, u16 rtype);
160 
161 /**
162  * Appends a "delete fqdn" command to the buffer.
163  *
164  * @param dmsg
165  * @param fqdn
166  * @return
167  */
168 
169 ya_result dynupdate_message_del_fqdn(dynupdate_message *dmsg, const u8 *fqdn);
170 
171 /** @} */
172 
173