1 /**
2  *
3  * /brief getdns support functions for DNS Resource Records
4  */
5 /*
6  * Copyright (c) 2013, NLnet Labs, Verisign, Inc.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * * Redistributions of source code must retain the above copyright
12  *   notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above copyright
14  *   notice, this list of conditions and the following disclaimer in the
15  *   documentation and/or other materials provided with the distribution.
16  * * Neither the names of the copyright holders nor the
17  *   names of its contributors may be used to endorse or promote products
18  *   derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
24  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef RR_DICT_H_
33 #define RR_DICT_H_
34 
35 #include "config.h"
36 #include "getdns/getdns.h"
37 #include "gldns/gbuffer.h"
38 
39 /* rdf_end returns a pointer to the end of this rdf's data,
40  * i.e. where the next rdata field will start.
41  */
42 typedef const uint8_t *(*_getdns_rdf_end_t)(
43     const uint8_t *pkt, const uint8_t *pkt_end, const uint8_t *rdf);
44 /* Limit checks are already done with _getdns_rdf_end_t */
45 typedef getdns_return_t (*_getdns_rdf_wire2dict_t)(
46     getdns_dict *dict, const uint8_t *rdf);
47 typedef getdns_return_t (*_getdns_rdf_wire2list_t)(
48     getdns_list *list, const uint8_t *rdf);
49 typedef getdns_return_t (*_getdns_rdf_dict2wire_t)(
50     const getdns_dict *dict, uint8_t *rdata, uint8_t *rdf, size_t *rdf_len);
51 typedef getdns_return_t (*_getdns_rdf_list2wire_t)(
52     const getdns_list *list, size_t index,
53     uint8_t *rdata, uint8_t *rdf, size_t *rdf_len);
54 
55 typedef struct _getdns_rdf_special {
56 	_getdns_rdf_end_t       rdf_end;
57 	_getdns_rdf_wire2dict_t wire2dict;
58 	_getdns_rdf_wire2list_t wire2list;
59 	_getdns_rdf_dict2wire_t dict2wire;
60 	_getdns_rdf_list2wire_t list2wire;
61 } _getdns_rdf_special;
62 
63 /* draft-levine-dnsextlang'ish type rr and rdata definitions */
64 
65 #define GETDNS_RDF_INTEGER    0x010000
66 #define GETDNS_RDF_BINDATA    0x020000
67 #define GETDNS_RDF_DNAME      0x040000
68 #define GETDNS_RDF_COMPRESSED 0x080000
69 #define GETDNS_RDF_REPEAT     0x100000
70 
71 #define GETDNS_RDF_FIXEDSZ    0x0000FF
72 #define GETDNS_RDF_LEN_VAL    0x00FF00
73 
74 typedef enum _getdns_rdf_wf_type {
75 	GETDNS_RDF_N        = 0x060000,     /* N      */
76 	GETDNS_RDF_N_A      = 0x060000,     /* N[A]   */
77 	GETDNS_RDF_N_C      = 0x0E0000,     /* N[C]   */
78 	GETDNS_RDF_N_A_C    = 0x0E0000,     /* N[A,C] */
79 	GETDNS_RDF_N_M      = 0x160000,     /* N[M]   */
80 
81 	GETDNS_RDF_I1       = 0x010001,     /* I1     */
82 	GETDNS_RDF_I2       = 0x010002,     /* I2     */
83 	GETDNS_RDF_I4       = 0x010004,     /* I4     */
84 
85 	GETDNS_RDF_T        = 0x010004,     /* T      */
86 	                               /* Time values using ring arithmetics
87 	                                * (rfc1982) for TKEY['inception'],
88 	                                * TKEY['expiration'],
89 	                                * RRSIG['inception'] and
90 	                                * RRSIG['expiration']
91 	                                */
92 	GETDNS_RDF_T6       = 0x020006,     /* T6     */
93 	                               /* Absolute time values (since epoch)
94 					* for TSIG['time_signed']
95 					*/
96 
97 	GETDNS_RDF_A        = 0x020004,     /* A      */
98 	GETDNS_RDF_AA       = 0x020008,     /* AA     */
99 	GETDNS_RDF_AAAA     = 0x020010,     /* AAAA   */
100 
101 	GETDNS_RDF_S        = 0x020100,     /* S      */
102 	GETDNS_RDF_S_L      = 0x020000,     /* S[L]   */
103 	GETDNS_RDF_S_M      = 0x120100,     /* S[M]   */
104 
105 	GETDNS_RDF_B        = 0x020000,     /* B      */
106 	GETDNS_RDF_B_C      = 0x020100,     /* B[C]   */
107 
108 	GETDNS_RDF_B32_C    = 0x020100,     /* B32[C] */
109 
110 	GETDNS_RDF_X        = 0x020000,     /* X      */
111 	GETDNS_RDF_X_C      = 0x020100,     /* X[C]   */
112 	                               /* for NSEC3['salt'] and
113 	                                * NSEC3PARAM['salt'].
114 	                                */
115 	GETDNS_RDF_X_S      = 0x020200,     /* X[S]   */
116 	                               /* for OPT['option_data'],
117 	                                *    TKEY['key_data'],
118 	                                *    TKEY['other_data'],
119 	                                *    TSIG['mac'] and
120 	                                *    TSIG['other_data']
121 					* Although those do not have an
122 					* official presentation format.
123 	                                */
124 	GETDNS_RDF_X6       = 0x020006,
125 	GETDNS_RDF_X8       = 0x020008,
126 
127 	GETDNS_RDF_R        = 0x100000, /* Repeat */
128 
129 	GETDNS_RDF_SPECIAL  = 0x800000,
130 } _getdns_rdf_type;
131 
132 typedef struct _getdns_rdata_def {
133 	const char          *name;
134 	_getdns_rdf_type     type;
135 	_getdns_rdf_special *special;
136 } _getdns_rdata_def;
137 
138 typedef struct _getdns_rr_def {
139 	const char              *name;
140 	const _getdns_rdata_def *rdata;
141 	size_t                   n_rdata_fields;
142 } _getdns_rr_def;
143 
144 const _getdns_rr_def *_getdns_rr_def_lookup(uint16_t rr_type);
145 
146 getdns_return_t _getdns_rr_dict2wire(
147     const getdns_dict *rr_dict, gldns_buffer *buf);
148 
149 const char *_getdns_rr_type_name(int rr_type);
150 
151 #endif
152 
153 /* rrs.h */
154