Ripples 1.0
High Performant Software Architecture For Transaction Processing
Loading...
Searching...
No Matches
rip_ns_utils.h
Go to the documentation of this file.
1
46#ifndef RIP_NS_UTILS_H
47#define RIP_NS_UTILS_H
48
49#include <endian.h>
50#include <stdbool.h>
51#include <stddef.h>
52#include <stdint.h>
53
55#define RIP_NS_PACKETSZ 512
56#define RIP_NS_UDP_MAXMSG 4096
57#define RIP_NS_MAXMSG 65535
58#define RIP_NS_MAXCDNAME 255
59#define RIP_NS_MAXLABEL 63
60#define RIP_NS_QFIXEDSZ 4
61#define RIP_NS_RRFIXEDSZ 10
62#define RIP_NS_INT32SZ 4
63#define RIP_NS_INT16SZ 2
64#define RIP_NS_INT8SZ 1
65#define RIP_NS_INADDRSZ 4
66#define RIP_NS_IN6ADDRSZ 16
67#define RIP_NS_CMPRSFLGS 0xc0
70#define RIP_NS_RESP_MAX_ANSW 128
71
73#define RIP_NS_RESP_MAX_NS 16
74
78#define RIP_NS_RESP_MAX_ADDL 128
79
80#define RIP_NS_CDNAME_COMP_BUF_LEN 256
97
99typedef enum rip_ns_opcode_e {
103 /* Opcode 3 is undefined/reserved. */
106 rip_ns_o_max = 6
108
110typedef enum rip_ns_rcode_e {
111 rip_ns_r_noerror = 0, /*< No error occurred. */
117 /* these are for BIND_UPDATE */
123 rip_ns_r_max = 11,
124 /* The following are EDNS extended rcodes */
125 rip_ns_r_badvers = 16,
126 /* The following are TSIG errors */
127 rip_ns_r_badsig = 16,
128 rip_ns_r_badkey = 17,
129 rip_ns_r_badtime = 18,
130
131 /* Custom codes used for internal processing. */
132 rip_ns_r_rip_unknown = -1,
133 rip_ns_r_rip_shortheader = -2,
134 rip_ns_r_rip_toolarge = -3,
135 rip_ns_r_rip_query_tc = -4,
136 rip_ns_r_rip_pack_rr_err = -5,
140
142typedef enum rip_ns_type_e {
143 rip_ns_t_invalid = 0,
144 rip_ns_t_a = 1,
145 rip_ns_t_ns = 2,
146 rip_ns_t_md = 3,
147 rip_ns_t_mf = 4,
148 rip_ns_t_cname = 5,
149 rip_ns_t_soa = 6,
150 rip_ns_t_mb = 7,
151 rip_ns_t_mg = 8,
152 rip_ns_t_mr = 9,
153 rip_ns_t_null = 10,
154 rip_ns_t_wks = 11,
155 rip_ns_t_ptr = 12,
156 rip_ns_t_hinfo = 13,
157 rip_ns_t_minfo = 14,
158 rip_ns_t_mx = 15,
159 rip_ns_t_txt = 16,
160 rip_ns_t_rp = 17,
161 rip_ns_t_afsdb = 18,
162 rip_ns_t_x25 = 19,
163 rip_ns_t_isdn = 20,
164 rip_ns_t_rt = 21,
165 rip_ns_t_nsap = 22,
166 rip_ns_t_nsap_ptr = 23,
167 rip_ns_t_sig = 24,
168 rip_ns_t_key = 25,
169 rip_ns_t_px = 26,
170 rip_ns_t_gpos = 27,
171 rip_ns_t_aaaa = 28,
172 rip_ns_t_loc = 29,
173 rip_ns_t_nxt = 30,
174 rip_ns_t_eid = 31,
175 rip_ns_t_nimloc = 32,
176 rip_ns_t_srv = 33,
177 rip_ns_t_atma = 34,
178 rip_ns_t_naptr = 35,
179 rip_ns_t_kx = 36,
180 rip_ns_t_cert = 37,
181 rip_ns_t_a6 = 38,
182 rip_ns_t_dname = 39,
183 rip_ns_t_sink = 40,
184 rip_ns_t_opt = 41,
185 rip_ns_t_apl = 42,
186 rip_ns_t_ds = 43,
187 rip_ns_t_sshfp = 44,
188 rip_ns_t_ipseckey = 45,
189 rip_ns_t_rrsig = 46,
190 rip_ns_t_nsec = 47,
191 rip_ns_t_dnskey = 48,
192 rip_ns_t_dhcid = 49,
193 rip_ns_t_nsec3 = 50,
194 rip_ns_t_nsec3param = 51,
195 rip_ns_t_tlsa = 52,
196 rip_ns_t_smimea = 53,
197 rip_ns_t_hip = 55,
198 rip_ns_t_ninfo = 56,
199 rip_ns_t_rkey = 57,
200 rip_ns_t_talink = 58,
201 rip_ns_t_cds = 59,
202 rip_ns_t_cdnskey = 60,
203 rip_ns_t_openpgpkey = 61,
204 rip_ns_t_csync = 62,
205 rip_ns_t_spf = 99,
206 rip_ns_t_uinfo = 100,
207 rip_ns_t_uid = 101,
208 rip_ns_t_gid = 102,
209 rip_ns_t_unspec = 103,
210 rip_ns_t_nid = 104,
211 rip_ns_t_l32 = 105,
212 rip_ns_t_l64 = 106,
213 rip_ns_t_lp = 107,
214 rip_ns_t_eui48 = 108,
215 rip_ns_t_eui64 = 109,
216 rip_ns_t_tkey = 249,
217 rip_ns_t_tsig = 250,
218 rip_ns_t_ixfr = 251,
219 rip_ns_t_axfr = 252,
220 rip_ns_t_mailb = 253,
221 rip_ns_t_maila = 254,
222 rip_ns_t_any = 255,
223 rip_ns_t_uri = 256,
224 rip_ns_t_caa = 257,
225 rip_ns_t_avc = 258,
226 rip_ns_t_ta = 32768,
227 rip_ns_t_dlv = 32769,
228
229 rip_ns_t_max = 65536
231
233typedef enum rip_ns_class_e {
239 /* Query class values which do not appear in resource records */
242 rip_ns_c_max = 65536
244
247 rip_ns_ext_opt_c_cs = 8,
249
255typedef struct rip_ns_header_s {
256 unsigned id :16;
257#if __BYTE_ORDER == __BIG_ENDIAN
258 /* fields in third byte */
259 unsigned qr: 1;
260 unsigned opcode: 4;
261 unsigned aa: 1;
262 unsigned tc: 1;
263 unsigned rd: 1;
264 /* fields in fourth byte */
265 unsigned ra: 1;
266 unsigned unused :1;
267 unsigned ad: 1;
268 unsigned cd: 1;
269 unsigned rcode :4;
270#endif
271#if __BYTE_ORDER == __LITTLE_ENDIAN || __BYTE_ORDER == __PDP_ENDIAN
272 /* fields in third byte */
273 unsigned rd :1;
274 unsigned tc :1;
275 unsigned aa :1;
276 unsigned opcode :4;
277 unsigned qr :1;
278 /* fields in fourth byte */
279 unsigned rcode :4;
280 unsigned cd: 1;
281 unsigned ad: 1;
282 unsigned unused :1;
283 unsigned ra :1;
284#endif
285 /* remaining bytes */
286 unsigned qdcount :16;
287 unsigned ancount :16;
288 unsigned nscount :16;
289 unsigned arcount :16;
291
296#define RIP_NS_QUERY_SET_END_CODE_AND_RETURN(q, c) do { \
297 (q)->end_code = c; \
298 return; \
299} while (0)
300
304#define RIP_NS_GET16(s, cp) do { \
305 const unsigned char *t_cp = (const unsigned char *)(cp); \
306 (s) = ((uint16_t)t_cp[0] << 8) \
307 | ((uint16_t)t_cp[1]) \
308 ; \
309 (cp) += RIP_NS_INT16SZ; \
310} while (0)
311
315#define RIP_NS_PUT16(s, cp) do { \
316 uint16_t t_s = (uint16_t)(s); \
317 unsigned char *t_cp = (unsigned char *)(cp); \
318 *t_cp++ = t_s >> 8; \
319 *t_cp = t_s; \
320 (cp) += RIP_NS_INT16SZ; \
321} while (0)
322
326#define RIP_NS_GET32(l, cp) do { \
327 const unsigned char *t_cp = (const unsigned char *)(cp); \
328 (l) = ((uint32_t)t_cp[0] << 24) \
329 | ((uint32_t)t_cp[1] << 16) \
330 | ((uint32_t)t_cp[2] << 8) \
331 | ((uint32_t)t_cp[3]) \
332 ; \
333 (cp) += RIP_NS_INT32SZ; \
334} while (0)
335
339#define RIP_NS_PUT32(l, cp) do { \
340 uint32_t t_l = (uint32_t)(l); \
341 unsigned char *t_cp = (unsigned char *)(cp); \
342 *t_cp++ = t_l >> 24; \
343 *t_cp++ = t_l >> 16; \
344 *t_cp++ = t_l >> 8; \
345 *t_cp = t_l; \
346 (cp) += RIP_NS_INT32SZ; \
347} while (0)
348
349const char * rip_ns_class_to_str(rip_ns_class_t class);
350const char * rip_ns_rr_type_to_str(rip_ns_type_t type);
351
352bool rip_ns_rr_type_supported(uint16_t query_type);
353
354bool rip_ns_rr_class_supported(uint16_t query_class);
355
356void rip_ns_put16(unsigned char *dst, uint16_t num);
357
358int rip_ns_name_unpack(const unsigned char *msg, const unsigned char *eom,
359 const unsigned char *src, unsigned char *dst,
360 size_t dstsiz);
361
362int rip_ns_name_pack(const unsigned char *src, unsigned char *dst, int dstsiz,
363 const unsigned char **dnptrs,
364 const unsigned char **lastdnptr);
365
366int rip_ns_name_pton(const unsigned char *src, unsigned char *dst, size_t dstsiz);
367int rip_ns_name_ntop(const unsigned char *src, char *dst, size_t dstsiz);
368
369int rip_rr_name_get(const unsigned char *msg, const unsigned char *eom,
370 const unsigned char *src, unsigned char *dst,
371 size_t dstsiz, uint16_t *query_label_len);
372
373int rip_ns_name_put(const unsigned char *src, unsigned char *dst, int dstsiz,
374 const unsigned char **dnptrs,
375 const unsigned char **lastdnptr);
376
377#endif /* End of CONNS_UTILS_HN_H */
378
enum rip_ns_class_e rip_ns_class_t
enum rip_ns_ext_opt_code_e rip_ns_ext_opt_code_t
int rip_ns_name_put(const unsigned char *src, unsigned char *dst, int dstsiz, const unsigned char **dnptrs, const unsigned char **lastdnptr)
Definition rip_ns_utils.c:209
bool rip_ns_rr_type_supported(uint16_t query_type)
Definition rip_ns_utils.c:137
int rip_ns_name_pack(const unsigned char *src, unsigned char *dst, int dstsiz, const unsigned char **dnptrs, const unsigned char **lastdnptr)
Definition rip_ns_utils.c:563
bool rip_ns_rr_class_supported(uint16_t query_class)
Definition rip_ns_utils.c:161
enum rip_ns_opcode_e rip_ns_opcode_t
rip_ns_flag_e
Definition rip_ns_utils.h:84
int rip_ns_name_ntop(const unsigned char *src, char *dst, size_t dstsiz)
Definition rip_ns_utils.c:709
enum rip_ns_flag_e rip_ns_flag_t
const char * rip_ns_rr_type_to_str(rip_ns_type_t type)
Definition rip_ns_utils.c:101
int rip_ns_name_unpack(const unsigned char *msg, const unsigned char *eom, const unsigned char *src, unsigned char *dst, size_t dstsiz)
Definition rip_ns_utils.c:284
int rip_rr_name_get(const unsigned char *msg, const unsigned char *eom, const unsigned char *src, unsigned char *dst, size_t dstsiz, uint16_t *query_label_len)
Definition rip_ns_utils.c:244
rip_ns_class_e
Definition rip_ns_utils.h:233
enum rip_ns_type_e rip_ns_type_t
void rip_ns_put16(unsigned char *dst, uint16_t num)
Definition rip_ns_utils.c:177
rip_ns_rcode_e
Definition rip_ns_utils.h:110
const char * rip_ns_class_to_str(rip_ns_class_t class)
Definition rip_ns_utils.c:116
rip_ns_type_e
Definition rip_ns_utils.h:142
rip_ns_opcode_e
Definition rip_ns_utils.h:99
enum rip_ns_rcode_e rip_ns_rcode_t
rip_ns_ext_opt_code_e
Definition rip_ns_utils.h:246
int rip_ns_name_pton(const unsigned char *src, unsigned char *dst, size_t dstsiz)
Definition rip_ns_utils.c:440
struct rip_ns_header_s rip_ns_header_t
@ rip_ns_f_tc
Definition rip_ns_utils.h:88
@ rip_ns_f_z
Definition rip_ns_utils.h:91
@ rip_ns_f_rcode
Definition rip_ns_utils.h:94
@ rip_ns_f_qr
Definition rip_ns_utils.h:85
@ rip_ns_f_rd
Definition rip_ns_utils.h:89
@ rip_ns_f_aa
Definition rip_ns_utils.h:87
@ rip_ns_f_opcode
Definition rip_ns_utils.h:86
@ rip_ns_f_ra
Definition rip_ns_utils.h:90
@ rip_ns_f_ad
Definition rip_ns_utils.h:92
@ rip_ns_f_cd
Definition rip_ns_utils.h:93
@ rip_ns_c_hs
Definition rip_ns_utils.h:238
@ rip_ns_c_any
Definition rip_ns_utils.h:241
@ rip_ns_c_chaos
Definition rip_ns_utils.h:237
@ rip_ns_c_in
Definition rip_ns_utils.h:235
@ rip_ns_c_2
Definition rip_ns_utils.h:236
@ rip_ns_c_none
Definition rip_ns_utils.h:240
@ rip_ns_c_invalid
Definition rip_ns_utils.h:234
@ rip_ns_r_refused
Definition rip_ns_utils.h:116
@ rip_ns_r_notzone
Definition rip_ns_utils.h:122
@ rip_ns_r_yxdomain
Definition rip_ns_utils.h:118
@ rip_ns_r_notimpl
Definition rip_ns_utils.h:115
@ rip_ns_r_nxrrset
Definition rip_ns_utils.h:120
@ rip_ns_r_formerr
Definition rip_ns_utils.h:112
@ rip_ns_r_rip_tcp_write_close
Definition rip_ns_utils.h:138
@ rip_ns_r_nxdomain
Definition rip_ns_utils.h:114
@ rip_ns_r_notauth
Definition rip_ns_utils.h:121
@ rip_ns_r_servfail
Definition rip_ns_utils.h:113
@ rip_ns_r_rip_tcp_write_err
Definition rip_ns_utils.h:137
@ rip_ns_r_yxrrset
Definition rip_ns_utils.h:119
@ rip_ns_o_iquery
Definition rip_ns_utils.h:101
@ rip_ns_o_update
Definition rip_ns_utils.h:105
@ rip_ns_o_query
Definition rip_ns_utils.h:100
@ rip_ns_o_status
Definition rip_ns_utils.h:102
@ rip_ns_o_notify
Definition rip_ns_utils.h:104
Definition rip_ns_utils.h:255
unsigned id
Definition rip_ns_utils.h:256
unsigned ancount
Definition rip_ns_utils.h:287
unsigned ra
Definition rip_ns_utils.h:265
unsigned unused
Definition rip_ns_utils.h:266
unsigned cd
Definition rip_ns_utils.h:268
unsigned rcode
Definition rip_ns_utils.h:269
unsigned nscount
Definition rip_ns_utils.h:288
unsigned opcode
Definition rip_ns_utils.h:260
unsigned ad
Definition rip_ns_utils.h:267
unsigned aa
Definition rip_ns_utils.h:261
unsigned arcount
Definition rip_ns_utils.h:289
unsigned tc
Definition rip_ns_utils.h:262
unsigned qr
Definition rip_ns_utils.h:259
unsigned rd
Definition rip_ns_utils.h:263
unsigned qdcount
Definition rip_ns_utils.h:286